File indexing completed on 2024-04-28 04:44:14
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 SNORESERVER_H 0020 #define SNORESERVER_H 0021 0022 #include "snore_exports.h" 0023 #include "snoreglobals.h" 0024 #include "application.h" 0025 #include "notification/notification.h" 0026 #include "plugins/plugins.h" 0027 #include "hint.h" 0028 0029 #include <QStringList> 0030 0031 /** 0032 * Snore is a platform independent Qt notification framework. 0033 * 0034 * Environment variable | Effect 0035 * ---------------------------------|------------------------------- 0036 * LIBSNORE_DEBUG_LVL | Value betwene 0 and 3 @see SnoreDebugLevels 0037 * LIBSNORE_LOG_TO_FILE | If 1 write to a logfile in tmp/libsnore/appname-log.txt 0038 * LIBSNORE_LOGFILE | Use with LIBSNORE_LOG_TO_FILE, sets the file to log to 0039 * 0040 * 0041 * @author Hannah von Reth \<vonreth at kde.org\> 0042 */ 0043 0044 namespace Snore 0045 { 0046 class SnoreCorePrivate; 0047 0048 /** 0049 * SnoreCore is used to manage and emit Notifications 0050 * 0051 * @author Hannah von Reth \<vonreth at kde.org\> 0052 */ 0053 0054 class SNORE_EXPORT SnoreCore : public QObject 0055 { 0056 Q_DECLARE_PRIVATE(SnoreCore) 0057 Q_OBJECT 0058 public: 0059 /** 0060 * Creates a Notification Manager SnoreCore 0061 */ 0062 static SnoreCore &instance(); 0063 ~SnoreCore(); 0064 0065 /** 0066 * Load a set of plugins 0067 * 0068 * @param types the type of tha plugin 0069 * @see Snore::SnorePlugin::PluginType 0070 */ 0071 Q_INVOKABLE void loadPlugins(Snore::SnorePlugin::PluginTypes types); 0072 0073 /** 0074 * Broadcast a notification. 0075 * @param notification the Notification 0076 */ 0077 void broadcastNotification(Notification notification); 0078 0079 /** 0080 * Displays a example notification. 0081 */ 0082 void displayExampleNotification(); 0083 0084 /** 0085 * Register an application. 0086 * Each application should only be registered once. 0087 * An application must be registered before a notification can be broadcasted. 0088 * @see deregisterApplication 0089 * @see broadcastNotification 0090 * @param application the application 0091 */ 0092 void registerApplication(const Application &application); 0093 0094 /** 0095 * Deregisters an application. 0096 * Should be called if an application is no loger used. 0097 * Is called automatically if the backend changes. 0098 * @see registerApplication 0099 * @see setPrimaryNotificationBackend 0100 * @param application the application 0101 */ 0102 void deregisterApplication(const Application &application); 0103 0104 /** 0105 * 0106 * @return a QHash of all registered applications 0107 */ 0108 const QHash<QString, Application> &aplications() const; 0109 0110 /** 0111 * 0112 * @return a list of plugins 0113 */ 0114 const QStringList pluginNames(SnorePlugin::PluginTypes type = SnorePlugin::All) const; 0115 0116 /** 0117 * 0118 * @return the name of the active primary backend 0119 */ 0120 const QString primaryNotificationBackend() const; 0121 0122 /** 0123 * Sets the primary notification backend. 0124 * @param backend the name of the backend. 0125 * @return whether the backend was set successful. 0126 */ 0127 bool setPrimaryNotificationBackend(const QString &backend); 0128 0129 /** 0130 * Try to close a Notification if the backend supports the action. 0131 * @see SnoreBackend::canCloseNotification 0132 */ 0133 void requestCloseNotification(Notification, Notification::CloseReasons); 0134 0135 /** 0136 * Sets the default application used for internal notifications. 0137 * @param app The default application. 0138 */ 0139 void setDefaultApplication(Application app); 0140 0141 QVariant settingsValue(const SettingsKey &key) const; 0142 void setSettingsValue(const SettingsKey &key, const QVariant &value); 0143 void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue); 0144 0145 Notification getActiveNotificationByID(uint id) const; 0146 0147 Q_SIGNALS: 0148 /** 0149 * This signal is emitted when an action on the Notification was performed. 0150 * Some notification systems don't support actions but will report one if the notification was clicked, 0151 * in this case the Action will be invalid. 0152 * @todo maybe introduce a special action state for this case 0153 * @see Action 0154 */ 0155 void actionInvoked(const Snore::Notification ¬ification); 0156 0157 /** 0158 * This signal is emitted when a Notification is closed. 0159 * @see Notification::CloseReasons 0160 */ 0161 void notificationClosed(const Snore::Notification ¬ification); 0162 0163 /** 0164 * This signal is emitted in case the Primary backend encountered an error. 0165 */ 0166 void primaryNotificationBackendError(const QString &error); 0167 0168 /** 0169 * This signal is emitted in case the Primary backend changed. 0170 */ 0171 void primaryNotificationBackendChanged(const QString &error); 0172 0173 private: 0174 SnoreCore(QObject *parent); 0175 SnoreCorePrivate *d_ptr; 0176 0177 }; 0178 0179 } 0180 0181 #endif // SNORESERVER_H