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
|
/**************************** notify.h **********************************
Code for a notify client to interface with a desktop notification
server.
Copyright (C) 2013-2023
by: Andrew J. Bibb
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
***********************************************************************/
/* Usage is very similar to notify-send. Create a notifyclient instance.
* During creation the constructor will try to connect to a notification
* server. You can test if this was successful by calling the isValid()
* function. If sussessful you may also use the getxxx functions to
* return information about the server.
*
* To send a notification initialize the client using the init() function.
* Set the items you wish to send using the setxxx functions. To show
* the notification call sendNotification().
*
* This class may also be used to store the information you saved to be
* retrieved by the various getxxx functions. This information can be used
* for instance to show a popup from the systemtray icon.
*/
# ifndef NOTIFY_CLIENT
# define NOTIFY_CLIENT
# include <QObject>
# include <QString>
# include <QStringList>
# include <QtDBus/QtDBus>
# include <QtDBus/QDBusInterface>
# include <QIcon>
# include <QMap>
# include <QTemporaryFile>
// Used for enum's local to this program
namespace Nc
{
enum {
// urgency levels
UrgencyLow = 0,
UrgencyNormal = 1,
UrgencyCritical = 2
};
} // namespace
class NotifyClient : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications")
public:
NotifyClient(QObject*);
inline bool isValid() {return b_validconnection;}
inline QString getServerName() {return s_name;}
inline QString getServerVendor() {return s_vendor;}
inline QString getServerVersion() {return s_version;}
inline QString getServerSpecVersion() {return s_spec_version;}
inline QStringList getServerCapabilities() {return sl_capabilities;}
inline void setSummary(QString s) {s_summary = s;}
inline void setAppName(QString s) {s_app_name = s;}
inline void setBody(QString s) {s_body = s;}
inline void setIcon(QString s) {s_icon = s;}
inline void setUrgency(int i) {i_urgency = i;}
inline void setExpireTimeout(int i) {i_expire_timeout = i;}
inline void setOverwrite(bool b) {b_overwrite = b;}
inline QString getSummary() {return s_summary;}
inline QString getAppName() {return s_app_name;}
inline QString getBody() {return s_body;}
inline QString getIcon() {return s_icon;}
inline int getUrgency() {return i_urgency;}
inline int getExpireTimeout() {return i_expire_timeout;}
void connectToServer();
void init();
void sendNotification();
private:
// members
QDBusInterface* notifyclient;
QString s_name;
QString s_vendor;
QString s_version;
QString s_spec_version;
QStringList sl_capabilities;
bool b_validconnection;
quint32 current_id;
QString s_summary;
QString s_app_name;
QString s_body;
QString s_icon;
int i_urgency;
int i_expire_timeout;
bool b_overwrite;
QMap<quint32, QTemporaryFile*> file_map;
// functions
void getServerInformation();
void getCapabilities();
void closeNotification(quint32);
private slots:
void notificationClosed(quint32, quint32);
void actionInvoked(quint32, QString);
void cleanUp();
};
#endif
|