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 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2011-2015 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_QT_NOTIFICATOR_H
  5. #define STARWELS_QT_NOTIFICATOR_H
  6. #if defined(HAVE_CONFIG_H)
  7. #include "config/starwels-config.h"
  8. #endif
  9. #include <QIcon>
  10. #include <QObject>
  11. QT_BEGIN_NAMESPACE
  12. class QSystemTrayIcon;
  13. #ifdef USE_DBUS
  14. class QDBusInterface;
  15. #endif
  16. QT_END_NAMESPACE
  17. /** Cross-platform desktop notification client. */
  18. class Notificator: public QObject
  19. {
  20. Q_OBJECT
  21. public:
  22. /** Create a new notificator.
  23. @note Ownership of trayIcon is not transferred to this object.
  24. */
  25. Notificator(const QString &programName, QSystemTrayIcon *trayIcon, QWidget *parent);
  26. ~Notificator();
  27. // Message class
  28. enum Class
  29. {
  30. Information, /**< Informational message */
  31. Warning, /**< Notify user of potential problem */
  32. Critical /**< An error occurred */
  33. };
  34. public Q_SLOTS:
  35. /** Show notification message.
  36. @param[in] cls general message class
  37. @param[in] title title shown with message
  38. @param[in] text message content
  39. @param[in] icon optional icon to show with message
  40. @param[in] millisTimeout notification timeout in milliseconds (defaults to 10 seconds)
  41. @note Platform implementations are free to ignore any of the provided fields except for \a text.
  42. */
  43. void notify(Class cls, const QString &title, const QString &text,
  44. const QIcon &icon = QIcon(), int millisTimeout = 10000);
  45. private:
  46. QWidget *parent;
  47. enum Mode {
  48. None, /**< Ignore informational notifications, and show a modal pop-up dialog for Critical notifications. */
  49. Freedesktop, /**< Use DBus org.freedesktop.Notifications */
  50. QSystemTray, /**< Use QSystemTray::showMessage */
  51. Growl12, /**< Use the Growl 1.2 notification system (Mac only) */
  52. Growl13, /**< Use the Growl 1.3 notification system (Mac only) */
  53. UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */
  54. };
  55. QString programName;
  56. Mode mode;
  57. QSystemTrayIcon *trayIcon;
  58. #ifdef USE_DBUS
  59. QDBusInterface *interface;
  60. void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
  61. #endif
  62. void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
  63. #ifdef Q_OS_MAC
  64. void notifyGrowl(Class cls, const QString &title, const QString &text, const QIcon &icon);
  65. void notifyMacUserNotificationCenter(Class cls, const QString &title, const QString &text, const QIcon &icon);
  66. #endif
  67. };
  68. #endif // STARWELS_QT_NOTIFICATOR_H