File indexing completed on 2024-04-14 04:50:22

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003     Some of below codes are got from Kopete source code.
0004 
0005     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 #ifndef CHOQOKPLUGIN_H
0011 #define CHOQOKPLUGIN_H
0012 
0013 #include <QObject>
0014 
0015 #include <KXMLGUIClient>
0016 
0017 #include "choqok_export.h"
0018 
0019 class KPluginMetaData;
0020 
0021 /**
0022 * Current Choqok plugin interface version. Interfaces declare plugin version
0023 * to make sure old source (or binary) incompatible plugins are not loaded.
0024 * Increase this if it is necessary that old plugins stop working.
0025 */
0026 #define CHOQOK_PLUGIN_VERSION 1
0027 
0028 namespace Choqok
0029 {
0030 
0031 /**
0032 * @brief Base class for all plugins or microblogs.
0033 *
0034 * To create a plugin, you need to create a .desktop file which looks like that:
0035 * \verbatim
0036 [Desktop Entry]
0037 Encoding=UTF-8
0038 Type=Service
0039 X-Choqok-Version=1
0040 Icon=icon
0041 ServiceTypes=Choqok/Plugin
0042 X-KDE-Library=choqok_myplugin
0043 X-KDE-PluginInfo-Author=Your Name
0044 X-KDE-PluginInfo-Email=your@mail.com
0045 X-KDE-PluginInfo-Name=choqok_myplugin
0046 X-KDE-PluginInfo-Version=0.1
0047 X-KDE-PluginInfo-Website=http://yoursite.com
0048 X-KDE-PluginInfo-Category=Plugins
0049 X-KDE-PluginInfo-License=GPL
0050 X-KDE-PluginInfo-EnabledByDefault=false
0051 Name=MyPlugin
0052 Comment=Plugin that do some nice stuff
0053 \endverbatim
0054 *
0055 * The constructor of your plugin should looks like this:
0056 *
0057 * \code
0058 K_PLUGIN_FACTORY_WITH_JSON( MyPluginFactory, "choqok_plugin.json", registerPlugin < MyPlugin > (); )
0059 
0060 MyPlugin::MyPlugin( QObject *parent, const char *name, const QList\<QVariant\> &  args  )
0061 : Choqok::Plugin( name, parent )
0062 {
0063 //...
0064 }
0065 \endcode
0066 *
0067 * Choqok::Plugin inherits from KXMLGUIClient.  That client is added
0068 * to the Choqok's mainwindow KXMLGUIFactory. So you may add actions
0069 * on the main window.
0070 * Please note that the client is added right after the plugin is created,
0071 * so you have to create every actions in the constructor.
0072 *
0073 * @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0074 */
0075 class CHOQOK_EXPORT Plugin : public QObject, public KXMLGUIClient
0076 {
0077     Q_OBJECT
0078 public:
0079     Plugin(const QString &componentName, QObject *parent);
0080     virtual ~Plugin();
0081 
0082     /**
0083     * Returns the KPluginMetaData object associated with this plugin
0084     */
0085     KPluginMetaData pluginMetaData() const;
0086 
0087     /**
0088     * Get the name of the icon for this plugin. The icon name is taken from the
0089     * .desktop file.
0090     *
0091     * May return an empty string if the .desktop file for this plugin specifies
0092     * no icon name to use.
0093     *
0094     * This is a convenience method that simply calls @ref pluginInfo()->icon().
0095     */
0096     QString pluginIcon() const;
0097 
0098     /**
0099     * Returns the display name of this plugin.
0100     *
0101     * This is a convenience method that simply calls @ref pluginInfo()->name().
0102     */
0103     QString displayName() const;
0104 
0105     /**
0106     * @brief Returns the pluginId
0107     */
0108     QString pluginId() const;
0109 
0110     /**
0111     * @brief Prepare for unloading a plugin
0112     *
0113     * When unloading a plugin the plugin manager first calls aboutToUnload()
0114     * to indicate the pending unload. Some plugins need time to shutdown
0115     * asynchronously and thus can't be simply deleted in the destructor.
0116     *
0117     * The default implementation immediately emits the @ref readyForUnload() signal,
0118     * which basically makes the shutdown immediate and synchronous. If you need
0119     * more time you can reimplement this method and fire the signal whenever
0120     * you're ready. (you have 3 seconds)
0121     *
0122     * @ref Choqok::MicroBlog reimplement it.
0123     */
0124     virtual void aboutToUnload();
0125 
0126 Q_SIGNALS:
0127     /**
0128     * Notify that the settings of a plugin were changed.
0129     * These changes are passed on from the new KCDialog code in kdelibs/kutils.
0130     */
0131     void settingsChanged();
0132 
0133     /**
0134      * Indicate when we're ready for unload.
0135      * @see aboutToUnload()
0136      */
0137     void readyForUnload();
0138 
0139 private:
0140     class Private;
0141     Private *const d;
0142 };
0143 
0144 }
0145 
0146 #endif // PLUGIN_H