File: plugin.h

package info (click to toggle)
ktorrent 25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,104 kB
  • sloc: cpp: 40,482; xml: 1,163; python: 182; sh: 10; makefile: 5
file content (144 lines) | stat: -rw-r--r-- 3,337 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
    SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef KTPLUGIN_H
#define KTPLUGIN_H

#include <ktcore_export.h>
#include <ktversion.h>

#include <QObject>

#include <KPluginMetaData>
#include <KXMLGUIClient>

namespace bt
{
class WaitJob;
}

namespace kt
{
class CoreInterface;
class GUIInterface;

/**
 * @author Joris Guisson
 * @brief Base class for all plugins
 *
 * This is the base class for all plugins. Plugins should implement
 * the load and unload methods, any changes made in load must be undone in
 * unload.
 *
 * It's also absolutely forbidden to do any complex initialization in the constructor
 * (setting an int to 0 is ok, creating widgets isn't).
 * Only the name, author and description may be set in the constructor.
 */
class KTCORE_EXPORT Plugin : public QObject, public KXMLGUIClient
{
    Q_OBJECT
public:
    Plugin(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
    ~Plugin() override;

    /**
     * This gets called, when the plugin gets loaded by KTorrent.
     * Any changes made here must be later made undone, when unload is
     * called.
     * Upon error a bt::Error should be thrown. And the plugin should remain
     * in an uninitialized state. The Error contains an error message, which will
     * get show to the user.
     */
    virtual void load() = 0;

    /**
     * Gets called when the plugin gets unloaded.
     * Should undo anything load did.
     */
    virtual void unload() = 0;

    /**
     * For plugins who need to update something, the same time as the
     * GUI updates.
     */
    virtual void guiUpdate();

    /**
     * This should be implemented by plugins who need finish of some stuff which might take some time.
     * These operations must be finished or killed by a timeout before we can proceed with unloading the plugin.
     * @param job The WaitJob which monitors the plugin
     */
    virtual void shutdown(bt::WaitJob *job);

    /// Get a pointer to the CoreInterface
    CoreInterface *getCore()
    {
        return core;
    }

    /// Get a const pointer to the CoreInterface
    const CoreInterface *getCore() const
    {
        return core;
    }

    /**
     * Set the core, used by PluginManager to set the pointer
     * to the core.
     * @param c Pointer to the core
     */
    void setCore(CoreInterface *c)
    {
        core = c;
    }

    /// Get a pointer to the CoreInterface
    GUIInterface *getGUI()
    {
        return gui;
    }

    /// Get a const pointer to the CoreInterface
    const GUIInterface *getGUI() const
    {
        return gui;
    }

    /**
     * Set the core, used by PluginManager to set the pointer
     * to the core.
     * @param c Pointer to the core
     */
    void setGUI(GUIInterface *c)
    {
        gui = c;
    }

    /// See if the plugin is loaded
    bool isLoaded() const
    {
        return loaded;
    }

    void setIsLoaded(bool isLoaded)
    {
        loaded = isLoaded;
    }

    /// Returns the name of the parent part the GUI of the plugin should be created in
    virtual QString parentPart() const
    {
        return QStringLiteral("ktorrent");
    }

private:
    CoreInterface *core = nullptr;
    GUIInterface *gui = nullptr;
    bool loaded = false;
};

}

#endif