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

#include <Fuoten/API/StarItem>

Inheritance diagram for StarItem:
Component

Properties

qint64 feedId
QString guidHash
bool starred
Properties inherited from Component
Fuoten::AbstractConfigurationconfiguration
Fuoten::Errorerror
bool inOperation
Fuoten::AbstractNotificatornotificator
quint16 requestTimeout
Fuoten::AbstractStoragestorage
bool useStorage
Fuoten::WipeManagerwipeManager

Public Member Functions

 StarItem (qint64 feedId, const QString &guidHash, bool starred, QObject *parent=nullptr)
 StarItem (QObject *parent=nullptr)
 ~StarItem () override
Q_INVOKABLE void execute () override
qint64 feedId () const
QString guidHash () const
void setFeedId (qint64 nFeedId)
void setGuidHash (const QString &nGuidHash)
void setStarred (bool nStarred)
bool starred () 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 feedIdChanged (qint64 feedId)
void guidHashChanged (const QString &guidHash)
void starredChanged (bool starred)
void succeeded (qint64 feedId, const QString &guidHash, bool starred)
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

Stars or unstars an item/article on the remote News App.

To star or unstar an item/article, you have to set StarItem::feedId to a valid feed ID, StarItem::guidHash to a valid item/article guid hash and Component::configuration to a valid AbstractConfiguration derived object that provides the authentication credentials and server information. 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::itemStarred() will be called in the successCallback() to update the local storage. If the request succeeded, the StarItem::succeeded() signal will be emitted, containing the feedId, the guidHash and the starred 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
StarItem::feedId, StarItem::guidHash, Component::configuration
API route
/folders/{feedId}/{guidHash}/{star|unstar}
Method
PUT

Property Documentation

◆ feedId

qint64 feedId
readwrite

ID of the feed the item/article to star/unstar belongs to.

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

Access functions:
qint64feedId() const
voidsetFeedId(qint64 nFeedId)
Notifier signal:
voidfeedIdChanged(qint64 feedId)

◆ guidHash

QString guidHash
readwrite

GUID hash of the item/article to star/unstar.

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

Access functions:
QStringguidHash() const
voidsetGuidHash(const QString &nGuidHash)
Notifier signal:
voidguidHashChanged(const QString &guidHash)

◆ starred

bool starred
readwrite

True if the item/article should be starred, otherwise false.

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

Access functions:
boolstarred() const
voidsetStarred(bool nStarred)
Notifier signal:
voidstarredChanged(bool starred)

Constructor & Destructor Documentation

◆ StarItem() [1/2]

StarItem ( QObject * parent = nullptr)
explicit

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

◆ StarItem() [2/2]

StarItem ( qint64 feedId,
const QString & guidHash,
bool starred,
QObject * parent = nullptr )

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

◆ ~StarItem()

~StarItem ( )
override

Destroys the StarItem object.

Member Function Documentation

◆ checkInput()

bool checkInput ( )
overrideprotectedvirtual

Will check for valid feedId and non-empty guidHash.

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

Reimplemented from Component.

◆ execute()

void execute ( )
overridevirtual

Executes the API request.

To perform a successful API request to star or unstar an article/item, StarItem::feedId has to be a valid feed ID, StarItem::guidHash has to be an valid item/article guid hash 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.

◆ feedId()

qint64 feedId ( ) const

Getter function for the feedId property.

See also
StarItem::setFeedId(), StarItem::feedIdChanged()
Returns
the ID of the feed the item/article that should be starred/unstarred belongs to

◆ feedIdChanged

void feedIdChanged ( qint64 feedId)
signal

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

See also
StarItem::feedId(), StarItem::setFeedId()
Parameters
feedIdID of the feed the item that should be starred/unstarred belongs to

◆ guidHash()

QString guidHash ( ) const

Getter function for the guidHash property.

See also
StarItem::setGuidHash(), StarItem::guidHashChanged()
Returns
the GUID hash of the item/article that should be starred/ustarred

◆ guidHashChanged

void guidHashChanged ( const QString & guidHash)
signal

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

See also
StarItem::guidHash(), StarItem::setGuidHash()
Parameters
guidHashthe GUID hash of the article that should be starred/unstarred

◆ setFeedId()

void setFeedId ( qint64 nFeedId)

Setter function for the feedId property. Emits the feedIdChanged() signal if nFeedId is not equal to the stored value. Can not be changed while Component::inOperation returns true.

See also
StarItem::feedId(), StarItem::feedIdChanged()
Parameters
nFeedIdID of the feed the item that should be starred/unstarred belongs to

◆ setGuidHash()

void setGuidHash ( const QString & nGuidHash)

Setter function for the guidHash property. Emits the guidHashChanged() signal if nGuidHash is not equal to the stored value. Can not be changed while Component::inOperation returns true.

See also
StarItem::guidHash(), StarItem::guidHashChanged()
Parameters
nGuidHashthe GUID hash of the article that should be starred/unstarred

◆ setStarred()

void setStarred ( bool nStarred)

Setter function for the starred property. Emits the starredChanged() signal if nStarred is not equal to the stored value. Can not be changed while Component::inOperation returns true.

See also
StarItem::starred(), StarItem::starredChanged()
Parameters
nStarredtrue if the article should be starred, false if it should be unstarred

◆ starred()

bool starred ( ) const

Getter function for the starred property.

See also
StarItem::setStarred(), StarItem::starredChanged()
Returns
true if the item/article should be starred, false if it should be unstarred

◆ starredChanged

void starredChanged ( bool starred)
signal

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

See also
StarItem::starred(), StarItem::setStarred()
Parameters
starredtrue if the article should be starred, false if it should be unstarred

◆ succeeded

void succeeded ( qint64 feedId,
const QString & guidHash,
bool starred )
signal

This signal is emitted if the request to star/unstar an item/article was successful.

Parameters
feedIdID of the feed the starred/unstarred item/article belongs to
guidHashGUID hash of the item/article that has been starred/unstarred
starredtrue if the article has been starred, false if it has been unstarred

◆ successCallback()

void successCallback ( )
overrideprotectedvirtual

Finishes the article starring/unstarring if the request was successful.

If Component::storage contains a valid pointer, the AbstractStorage::itemStarred() 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.