|
libfuoten 0.8.1
Qt based library to access the ownCloud/Nextcloud News App API
|
#include <Fuoten/Helpers/AbstractNotificator>
Public Types | |
| enum | Type { GeneralError = 0 , RequestError , ParsingError , InputError , OutputError , ServerError , ApplicationError , StorageError , AuthorizationError , SyncComplete , FoldersRequested , FolderCreated , FolderDeleted , FolderRenamed , FolderMarkedRead , FeedsRequested , FeedCreated , FeedDeleted , FeedMoved , FeedRenamed , FeedMarkedRead , ItemsRequested , AuthorizationSucceeded , AppPasswordRequested , RemoteWipeRequested , RemoteWipeDone } |
Public Member Functions | |
| AbstractNotificator (QObject *parent=nullptr) | |
| ~AbstractNotificator () override | |
| virtual QString | appIcon () const |
| virtual QString | appName () const |
| virtual bool | checkForPublishing (const Article *article) const |
| virtual bool | checkForPublishing (const QJsonObject &article) const |
| virtual bool | isArticlePublishingEnabled () const |
| virtual bool | isEnabled () const |
| virtual void | notify (const Error *error) const |
| virtual void | notify (Type type, QtMsgType severity, const QVariant &data) const =0 |
| virtual void | publishArticle (const Article *article) const |
| virtual void | publishArticle (const QJsonObject &article, const QString &feedName=QString()) const |
| void | setAppIcon (const QString &appIcon) |
| void | setAppName (const QString &appName) |
| void | setArticlePublishingEnabled (bool enabled) |
| void | setEnabled (bool enabled) |
Signals | |
| void | appIconChanged (const QString &appIcon) |
| void | appNameChanged (const QString &appName) |
| void | articlePublishingChanged (bool enabled) |
| void | enabledChanged (bool enabled) |
Abstract class to implement platform specific notifications about errors and successful operations.
Reimplement this class if you want to have notifications specific for your target platform. All API class can notify about occured errors - but not about success. Sucess notifications should be done by the a storage class derived from AbstractStorage, or separate from the API classes after processing the API results.
You can set a notificator via different methods. For all API classes there is the Component::notificator property, the same is true for storage classes via the AbstractStorage::notificator property and for the synchronizer via Synchronizer::notificator property. Beside these instance based properties there is also Component::setDefaultNotificator() to set a global default notificator that is used if no notificator is set for the current object. If no notificator has been set, there will be no notifications but programm will run normal. So notifications are totally optional.
Notifications are platform dependent, so you should create notificators for your target platform by creating a new class derived from AbstractNotificator. The main method for notifications you have to reimplement in your class is notify(Type type, QtMsgType severity, const QVariant &data). This method handles all the default notifications about occured errors and success notifications.
When reimplementing the default notification method, you can use appIcon() and appName() to populate default fields, optionally you can use isEnabled() to enable or disable notifications globally. You could for example disable notifications if your application is currently active and visible to the user and there are places in the application that show the same information. But it is on you how you implement it. You can also simply rely on the notification type and severity to decide when and how to show notifications.
Only the error notification types will provide ready to display error strings in the data argument. All other types will have meta data in the data argument that can be used to create custom notification messages. See the type enum description to learn what data you can expect for the different types.
The severity argument is an additional hint for displaying the notifications. Most error types will have QtCriticalMsg as their severity, only a few will have QtFatalMsg, some other might have QtWarningMsg. Informational notifications - like success notifications - will have a severity of QtInfoMsg.
| enum Type |
The type of the notification.
| Enumerator | |
|---|---|
| GeneralError | A general error, normally not used, only there as fallback. The data will contain a null QVariant. |
| RequestError | The request was not setup correctly or failed. The data will contain an error string. |
| ParsingError | There was an error when parsing the JSON response. The data will contain an error string. |
| InputError | An error occurred while providing data to the library methods. The data will conatin an error string. |
| OutputError | An error occurred while processing the returned data from the API. The data will contain an error string. |
| ServerError | An error occurred on the server. The data will contain an error string. |
| ApplicationError | An error occurred in the local application. The data will contain an error string. |
| StorageError | An error occurred on the storage layer. The data will contain an error string. |
| AuthorizationError | Authentication credentials missing or not valid. The data will contain an error string. |
| SyncComplete | Synchronization with the server was successful performed. The data will contain the number of seconds needed to perform the sync as an integer. |
| FoldersRequested | Folders have been requested from the server. The data will contain a QVariantList of QStringList that contains the following data: 0: names of new folders, 1: names of updated folders, 2: names of deleted folders |
| FolderCreated | A new folder has succesfully been created on the server. The data will contain the name of the folder as a QString. |
| FolderDeleted | A Folder has been successfully deleted on the server. The data will contain the name of the deleted folder as a QString. |
| FolderRenamed | A folder has successfully been renamed on the server. The data will contain a QStringList with two entries. 0: older folder name, 1: new folder name |
| FolderMarkedRead | A folder has successfully been marked as read. The data will contain the name of the folder as a QString. |
| FeedsRequested | Feeds have been requested from the server. The data will contain a QVariantList of QStringList that conatins the following data: 0: titles of new feeds, 1: titles of updated feeds, 2: titles of deleted feeds |
| FeedCreated | A new feed has successfully been created on the server. The data will contain the title of the new feed as a QString. |
| FeedDeleted | A feed has successfully been deleted on the server. The data will contain the title of the deleted feed ad a QString. |
| FeedMoved | A feed has successfully been moved on the server. The data will contain a QVariantList containing the following information as QString: 0: title of the feed, 1: name of the old folder, 2: name of the new folder |
| FeedRenamed | A feed has successfully been renamed on the server. The data will contain a QVariantList containing the following information as QString: 0: old title, 1: new title |
| FeedMarkedRead | A feed has been marked as read. The data will contain the title of the feed as a QString. |
| ItemsRequested | Items have been requested from the server. The data will contain the amount of new unread items as an integer value. |
| AuthorizationSucceeded | Requesting an application password from the Nextcloud API was successful. The data will contain a QVariantMap containing username and host. |
| AppPasswordRequested | A normal password has been successfully upgraded to an application password. The data will conatin a QVariantMap containing username, useragent and host. |
| RemoteWipeRequested | A remote wipe has been requested by the server. |
| RemoteWipeDone | A remote wipe requested by the server has been performed. |
|
explicit |
Constructs a new AbstractNotifier object with the given parent.
|
override |
Destroys the AbstractNotifier object.
|
virtual |
Returns the path to the currently set application icon. The default is an empty string.
|
signal |
This signal is emitted if the path to the application icon changes.
|
virtual |
Returns the currently set application name. The default is an empty string.
|
signal |
This signal is emitted if the application name changes.
|
signal |
This signal is emitted if the article publishing changes.
|
virtual |
Returns true if the article should be published to notifications. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
virtual |
Returns true if the article should be published to notifications.
You can reimplement this to decide if an article should be published to the notifications system via publishArticle(). The default implementation returns always false. You have to reimplement your own checks, for example based on the feedId the article belongs to or on some keywords in the article title. Best place to use is in a class derived from AbstractStorage, when you iterate over new articles. In the SQLiteStorage class it is for example used in the worker that processes requested items from the API.
|
signal |
This signal is emitted if the enabled status changes.
|
virtual |
Returns true if article publishing is enabled. The default is false.
|
virtual |
Returns true if notifications are enabled. The default is false.
|
virtual |
Creates a new notification from an error object.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The default implementation converts the error information like type, severity and error text into data that will be used by the main notify method. So to use the default implementation, you have to reimplement the main notify method.
|
pure virtual |
Creates a new notification.
Reimplement this in your derived class to create platform specific notifications.
The type will define the message type, have a look at the enum description to learn more about it - it will also provide information about the provided data. The severity can be used to further decide when and how to display the notification.
|
virtual |
Publishes information about an article to the notification system.
Some platforms - like Meego 1.2 Harmattan - provide global notification streams for different services and news. You can reimplement this method to publish received articles to this streams.
The default implementation does nothing.
|
virtual |
Publishes information about an article to the notification system.
Some platforms - like Meego 1.2 Harmattan - provide global notification streams for different services and news. You can reimplement this method to publish received articles to this streams.
The default implementation does nothing.
| void setAppIcon | ( | const QString & | appIcon | ) |
Sets the path to an application icon. The default is an empty string.
| void setAppName | ( | const QString & | appName | ) |
Sets the application name. The default is an empty string.
| void setArticlePublishingEnabled | ( | bool | enabled | ) |
Set to true to enable article publishing. The default is false.
| void setEnabled | ( | bool | enabled | ) |
Set to true to enable notifications The default is false.