libfuoten 0.8.1
Qt based library to access the ownCloud/Nextcloud News App API
Loading...
Searching...
No Matches
MarkItem Class Reference

#include <Fuoten/API/MarkItem>

Inheritance diagram for MarkItem:
Component

Properties

qint64 itemId
bool unread
Properties inherited from Component
Fuoten::AbstractConfigurationconfiguration
Fuoten::Errorerror
bool inOperation
Fuoten::AbstractNotificatornotificator
quint16 requestTimeout
Fuoten::AbstractStoragestorage
bool useStorage
Fuoten::WipeManagerwipeManager

Public Member Functions

 MarkItem (qint64 itemId, bool unread, QObject *parent=nullptr)
 MarkItem (QObject *parent=nullptr)
 ~MarkItem () override
Q_INVOKABLE void execute () override
qint64 itemId () const
void setItemId (qint64 nItemId)
void setUnread (bool nUnread)
bool unread () const
Public Member Functions inherited from Component
 Component (QObject *parent=nullptr)
 ~Component () override
AbstractConfigurationconfiguration () const
Errorerror () const
bool inOperation () const
bool isUseStorageEnabled () const
AbstractNotificatornotificator () const
quint16 requestTimeout () const
void setConfiguration (AbstractConfiguration *nAbstractConfiguration)
void setNotificator (AbstractNotificator *notificator)
void setRequestTimeout (quint16 seconds)
void setStorage (AbstractStorage *localStorage)
void setUseStorage (bool useStorage)
void setWipeManager (WipeManager *wipeManager)
AbstractStoragestorage () const
WipeManagerwipeManager () const

Signals

void itemIdChanged (qint64 itemId)
void succeeded (qint64 itemId, bool unread)
void unreadChanged (bool unread)
Signals inherited from Component
void configurationChanged (Fuoten::AbstractConfiguration *configuration)
void errorChanged (Fuoten::Error *error)
void failed (Fuoten::Error *error)
void inOperationChanged (bool inOperation)
void notificatorChanged (Fuoten::AbstractNotificator *notificator)
void requestTimeoutChanged (quint16 requestTimeout)
void sslErrors (QNetworkReply *reply, const QList< QSslError > &errors)
void storageChanged (Fuoten::AbstractStorage *storage)
void succeeded (const QJsonDocument &result)
void useStorageChanged (bool useStorage)
void wipeManagerChanged (Fuoten::WipeManager *wipeManager)

Protected Member Functions

bool checkInput () override
void extractError (QNetworkReply *reply) override
void successCallback () override
Protected Member Functions inherited from Component
void addRequestHeader (const QByteArray &headerName, const QByteArray &headerValue)
void addRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
virtual bool checkOutput ()
QJsonDocument jsonResult () const
void notify (AbstractNotificator::Type type, QtMsgType severity, const QVariant &data) const
void notify (const Error *e) const
QHash< QByteArray, QByteArray > requestHeaders () const
void sendRequest ()
void setApiRoute (const QString &route)
void setApiRoute (const QStringList &routeParts)
void setError (Error *nError)
void setExpectedJSONType (ExpectedJSONType type)
void setInOperation (bool nInOperation)
void setNetworkOperation (QNetworkAccessManager::Operation operation)
void setPayload (const QByteArray &payload)
void setPayload (const QJsonObject &payload)
void setRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
void setRequiresAuth (bool reqAuth)
void setUrlQuery (const QUrlQuery &query)

Additional Inherited Members

Public Types inherited from Component
enum  ExpectedJSONType : quint8 { Empty = 0 , Array = 1 , Object = 2 }
Static Public Member Functions inherited from Component
static AbstractConfigurationdefaultConfiguration ()
static AbstractNotificatordefaultNotificator ()
static AbstractStoragedefaultStorage ()
static WipeManagerdefaultWipeManager ()
static AbstractNamFactorynetworkAccessManagerFactory ()
static void setDefaultConfiguration (AbstractConfiguration *config)
static void setDefaultNotificator (AbstractNotificator *notificator)
static void setDefaultStorage (AbstractStorage *storage)
static void setDefaultWipeManager (WipeManager *wipeManager)
static void setNetworkAccessManagerFactory (AbstractNamFactory *factory)

Detailed Description

Marks an item/article as read/unread on the News App server.

To mark an article as read or unread, you have to set a valid MakrItem::itemId and Component::configuration. Use MarkItem::unread to define if the article should be marked as read or unread. After setting the mandatory properties, call execute() to perform the API request.

If a valid AbstractStorage object is set to the Component::storage property, AbstractStorage::itemMarked() will be called in the successCallback() to update the local storage. If the request succeeded, the MarkItem::succeeded() signal will be emitted, containing the itemId and the unread status. If something failed, the Component::failed() signal will be emitted and Component::error will contain a valid pointer to an Error object.

Mandatory properties
MarkItem::itemId, Component::configuration
API route
/folders/{itemId}/{read|unread}
Method
PUT

Property Documentation

◆ itemId

qint64 itemId
readwrite

ID of the item that should be marked as read or unread.

This property can not be changed while Component::inOperation() returns true.

Access functions:
qint64itemId() const
voidsetItemId(qint64 nItemId)
Notifier signal:
voiditemIdChanged(qint64 itemId)

◆ unread

bool unread
readwrite

If true, the item will be marked as unread, otherwise as read.

Defaults to false. This property can not be changed while Component::inOperation() returns true.

Access functions:
boolunread() const
voidsetUnread(bool nUnread)
Notifier signal:
voidunreadChanged(bool unread)

Constructor & Destructor Documentation

◆ MarkItem() [1/2]

MarkItem ( QObject * parent = nullptr)
explicit

Constructs a new MarkItem object with default values and the given parent.

◆ MarkItem() [2/2]

MarkItem ( qint64 itemId,
bool unread,
QObject * parent = nullptr )

Constructs a new MarkItem object with the given arguments and parent.

◆ ~MarkItem()

~MarkItem ( )
override

Destroys the MarkItem object.

Member Function Documentation

◆ checkInput()

bool checkInput ( )
overrideprotectedvirtual

Will check for valid itemId.

Will at first perform the checks of Component::checkInput(). Will than simply check if the ID is not lower or equal to 0.

Reimplemented from Component.

◆ execute()

void execute ( )
overridevirtual

Executes the API request.

To perform a successful API request to mark an article as read, MarkItem::itemId has to be a valid ID and there has to be an AbstractConfiguration object set to Component::configuration.

Execution will not run while Component::inOperation returns true and will itself set that property to true when the request starts.

Implements Component.

◆ extractError()

void extractError ( QNetworkReply * reply)
overrideprotectedvirtual

Extracts possible errors replied by the News App API.

Reimplemented from Component.

◆ itemId()

qint64 itemId ( ) const

Getter function for the itemId property.

See also
MarkItem::setItemId(), MarkItem::itemIdChanged()

◆ itemIdChanged

void itemIdChanged ( qint64 itemId)
signal

This is emitted if the value of the itemId property changes.

See also
MarkItem::itemId(), MarkItem::setItemId()

◆ setItemId()

void setItemId ( qint64 nItemId)

Setter function for the itemId property. Emits the itemIdChanged() signal if nItemId is not equal to the stored value.

See also
MarkItem::itemId(), MarkItem::itemIdChanged()

◆ setUnread()

void setUnread ( bool nUnread)

Setter function for the unread property. Emits the unreadChanged() signal if nUnread is not equal to the stored value.

See also
MarkItem::unread(), MarkItem::unreadChanged()

◆ succeeded

void succeeded ( qint64 itemId,
bool unread )
signal

This signal is emitted if the request to mark an article as read was successful.

Parameters
itemIdID of the item that has been marked as read or unread
unreadtrue if the item has been marked as unread, otherwise false

◆ successCallback()

void successCallback ( )
overrideprotectedvirtual

Finishes the item marking if the request was successful.

If Component::storage contains a valid pointer, the AbstractStorage::itemMarked() function will be called to update the local storage. After that the Component::inOperation property will be set to false and the succeeded() signal will be emitted.

Implements Component.

◆ unread()

bool unread ( ) const

Getter function for the unread property.

See also
MarkItem::setUnread(), MarkItem::unreadChanged()

◆ unreadChanged

void unreadChanged ( bool unread)
signal

This is emitted if the value of the unread property changes.

See also
MarkItem::unread(), MarkItem::setUnread()