| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef NOTIFICATION_H |
| 4 | #define NOTIFICATION_H |
| 5 | |
| 6 | #include "definitions/definitions.h" |
| 7 | |
| 8 | #include <QString> |
| 9 | |
| 10 | class Application; |
| 11 | |
| 12 | class Notification { |
| 13 | public: |
| 14 | enum class Event { |
| 15 | // Is here to provide "empty" events - events which should |
| 16 | // not trigger any notifications. |
| 17 | NoEvent = 0, |
| 18 | |
| 19 | // Used for many events which happen throught application lifecycle. |
| 20 | GeneralEvent = 1, |
| 21 | |
| 22 | // New (unread) messages were downloaded for some feed. |
| 23 | NewUnreadArticlesFetched = 2, |
| 24 | |
| 25 | // RSS Guard started downloading messages for some feed. |
| 26 | ArticlesFetchingStarted = 3, |
| 27 | |
| 28 | // Login tokens were successfuly refreshed. |
| 29 | // NOTE: This is primarily used in accounts which use |
| 30 | // OAuth or similar mechanism. |
| 31 | LoginDataRefreshed = 4, |
| 32 | |
| 33 | // New RSS Guard version available. |
| 34 | NewAppVersionAvailable = 5, |
| 35 | |
| 36 | // Some service failed to login. |
| 37 | LoginFailure = 6, |
| 38 | |
| 39 | // Node.js - package updated. |
| 40 | NodePackageUpdated = 7, |
| 41 | |
| 42 | // Node.js - package failde to update. |
| 43 | NodePackageFailedToUpdate = 8, |
| 44 | |
| 45 | // There was at least one error during fetching articles. |
| 46 | ArticlesFetchingError = 9 |
| 47 | }; |
| 48 | |
| 49 | explicit Notification(Event event = Event::NoEvent, |
| 50 | bool balloon = false, |
| 51 | bool dialog = false, |
| 52 | bool play_sound = true, |
| 53 | const QString& sound_path = {}, |
| 54 | int volume = DEFAULT_NOTIFICATION_VOLUME); |
| 55 | |
| 56 | bool balloonEnabled() const; |
| 57 | bool dialogEnabled() const; |
| 58 | |
| 59 | Event event() const; |
| 60 | void setEvent(Event event); |
| 61 | |
| 62 | int volume() const; |
| 63 | qreal fractionalVolume() const; |
| 64 | void setVolume(int volume); |
| 65 | |
| 66 | bool soundEnabled() const; |
| 67 | void setSoundEnabled(bool play_sound); |
| 68 | |
| 69 | // Returns full path to audio file which should be played when notification |
| 70 | // is launched. |
| 71 | // NOTE: This property supports "%data%" placeholder. |
| 72 | QString soundPath() const; |
| 73 | void setSoundPath(const QString& sound_path); |
| 74 | |
| 75 | void playSound(Application* app) const; |
| 76 | |
| 77 | static QList<Event> allEvents(); |
| 78 | static QString nameForEvent(Event event); |
| 79 | |
| 80 | private: |
| 81 | Event m_event; |
| 82 | bool m_balloonEnabled; |
| 83 | bool m_dialogEnabled; |
| 84 | bool m_soundEnabled; |
| 85 | QString m_soundPath; |
| 86 | qreal m_volume; |
| 87 | }; |
| 88 | |
| 89 | Q_DECLARE_METATYPE(Notification::Event) |
| 90 | |
| 91 | #endif // NOTIFICATION_H |