You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notificator.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef NOTIFICATOR_H
  2. #define NOTIFICATOR_H
  3. #include <QObject>
  4. #include <QIcon>
  5. QT_BEGIN_NAMESPACE
  6. class QSystemTrayIcon;
  7. #ifdef QT_DBUS
  8. class QDBusInterface;
  9. #endif
  10. QT_END_NAMESPACE
  11. // Cross-platform desktop notification client
  12. class Notificator: public QObject
  13. {
  14. Q_OBJECT
  15. public:
  16. // Create a new notificator
  17. // Ownership of trayIcon is not transferred to this object
  18. Notificator(const QString &programName=QString(), QSystemTrayIcon *trayIcon=0, QWidget *parent=0);
  19. ~Notificator();
  20. // Message class
  21. enum Class
  22. {
  23. Information,
  24. Warning,
  25. Critical,
  26. };
  27. public slots:
  28. /* Show notification message.
  29. *
  30. * cls: general message class
  31. * title: title shown with message
  32. * text: message content
  33. * icon: optional icon to show with message
  34. * millisTimeout: notification timeout in milliseconds (default 10 seconds)
  35. */
  36. void notify(Class cls, const QString &title, const QString &text,
  37. const QIcon &icon = QIcon(), int millisTimeout = 10000);
  38. private:
  39. QWidget *parent;
  40. enum Mode {
  41. None,
  42. Freedesktop, // Use DBus org.freedesktop.Notifications
  43. QSystemTray, // Use QSystemTray::showMessage
  44. };
  45. QString programName;
  46. Mode mode;
  47. QSystemTrayIcon *trayIcon;
  48. #ifdef QT_DBUS
  49. QDBusInterface *interface;
  50. void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
  51. #endif
  52. void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
  53. };
  54. #endif // NOTIFICATOR_H