File indexing completed on 2024-05-12 04:45:34
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2013-2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef SNORE_PLUGINS_H 0020 #define SNORE_PLUGINS_H 0021 #include "libsnore/snore_exports.h" 0022 #include "libsnore/snoreglobals.h" 0023 #include "libsnore/notification/notification.h" 0024 #include "libsnore/hint.h" 0025 0026 #include <QHash> 0027 0028 namespace Snore 0029 { 0030 0031 class PluginContainer; 0032 0033 /** 0034 * SnorePlugin represents the base class for the plugins. 0035 * 0036 * @author Hannah von Reth \<vonreth at kde.org\> 0037 */ 0038 0039 class SNORE_EXPORT SnorePlugin : public QObject 0040 { 0041 Q_OBJECT 0042 public: 0043 /** 0044 * The PluginType Flags. 0045 */ 0046 enum PluginType { 0047 /** 0048 * Flag for loading no plugins. 0049 */ 0050 None = 0, 0051 0052 /** 0053 * Backends are those plugins that are capable of reporting user interaction. 0054 */ 0055 Backend = 1 << 0, 0056 0057 /** 0058 * Secondary backaends are non interactive. 0059 * Redirection or playback of a sound file. 0060 */ 0061 SecondaryBackend = 1 << 1, 0062 0063 /** 0064 * Frontends are capable of recieving notifications. 0065 */ 0066 Frontend = 1 << 2, 0067 0068 /** 0069 * General plugins, currently there are no plugins implemented. 0070 */ 0071 Plugin = 1 << 3, 0072 0073 /** 0074 * A settings page for a Plugin. 0075 */ 0076 Settings = 1 << 4, 0077 0078 /** 0079 * Flag for loading all plugins. 0080 */ 0081 All = ~0 0082 }; 0083 0084 Q_DECLARE_FLAGS(PluginTypes, PluginType) 0085 Q_ENUMS(PluginType) 0086 0087 static PluginTypes typeFromString(const QString &t); 0088 static QString typeToString(const PluginTypes t); 0089 static const QList<Snore::SnorePlugin::PluginTypes> &types(); 0090 0091 SnorePlugin(); 0092 virtual ~SnorePlugin(); 0093 0094 /** 0095 * Sets the enabled state of the plugin to @param enabled . 0096 */ 0097 void setEnabled(bool enabled); 0098 0099 /** 0100 * Enables the plugin. 0101 */ 0102 void enable(); 0103 0104 /** 0105 * Disables the plugin. 0106 */ 0107 void disable(); 0108 0109 /** 0110 * Returns whether the Plugin is enabled. 0111 */ 0112 bool isEnabled() const; 0113 0114 /** 0115 * Returns the name of the plugin. 0116 */ 0117 const QString &name() const; 0118 0119 /** 0120 * Returns the plugin type. 0121 */ 0122 virtual PluginTypes type() const = 0; 0123 0124 /** 0125 * Returns the name of the plugin type. 0126 */ 0127 const QString typeName() const; 0128 0129 virtual bool isReady(); 0130 0131 /** 0132 * Returns the error string or an empty string. 0133 */ 0134 QString errorString() const; 0135 0136 QVariant settingsValue(const SettingsKey &key) const; 0137 void setSettingsValue(const SettingsKey &key, const QVariant &settingsValue); 0138 void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue); 0139 0140 const Hint &constHints() const; 0141 0142 Q_SIGNALS: 0143 void enabledChanged(bool enabled); 0144 void error(const QString &error); 0145 0146 protected: 0147 /** 0148 * Returns the version suffix used for the plugin settings. 0149 */ 0150 virtual QString settingsVersion() const; 0151 0152 /** 0153 * Set default setting values for the Plugin. 0154 */ 0155 virtual void setDefaultSettings(); 0156 0157 void setErrorString(const QString &error); 0158 0159 Hint &hints(); 0160 private: 0161 SettingsKey normaliseKey(const SettingsKey &key) const; 0162 void setDefaultSettingsPlugin(); 0163 0164 bool m_enabled = false; 0165 QString m_name; 0166 QString m_error; 0167 Hint m_hints; 0168 0169 friend class PluginContainer; 0170 0171 }; 0172 0173 } 0174 Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes) 0175 Q_DECLARE_METATYPE(Snore::SnorePlugin::PluginTypes) 0176 0177 Q_DECLARE_INTERFACE(Snore::SnorePlugin, 0178 "org.Snore.SnorePlugin/1.0") 0179 0180 SNORE_EXPORT QDebug operator<< (QDebug, const Snore::SnorePlugin::PluginTypes &); 0181 SNORE_EXPORT QDebug operator<< (QDebug, const Snore::SnorePlugin *); 0182 0183 SNORE_EXPORT QDataStream &operator<< (QDataStream &out, const Snore::SnorePlugin::PluginTypes &type); 0184 SNORE_EXPORT QDataStream &operator>> (QDataStream &in, Snore::SnorePlugin::PluginTypes &type); 0185 0186 #endif//SNORE_PLUGINS_H