File indexing completed on 2024-05-19 16:38:21

0001 /*
0002     SPDX-FileCopyrightText: 2015, 2016 Ivan Cukic <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef KACTIVITIES_STATS_RESULTWATCHER
0008 #define KACTIVITIES_STATS_RESULTWATCHER
0009 
0010 #include <QObject>
0011 
0012 #include "query.h"
0013 #include "resultset.h"
0014 
0015 namespace KActivities
0016 {
0017 namespace Stats
0018 {
0019 class ResultWatcherPrivate;
0020 
0021 /**
0022  * @class KActivities::Stats::ResultWatcher resultwatcher.h <KActivities/Stats/ResultWatcher>
0023  *
0024  * A very thin class that sends signals when new resources matching
0025  * a predefined query are available.
0026  */
0027 class KACTIVITIESSTATS_EXPORT ResultWatcher : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit ResultWatcher(Query query, QObject *parent = nullptr);
0033     ~ResultWatcher() override;
0034 
0035 Q_SIGNALS:
0036     /**
0037      * Emitted when a result has been added or updated. This either means
0038      * a new resource has appeared in the result set, or that
0039      * a previously existing one has some of the attributes changed.
0040      * @param result new data for the resource defined by result.resource
0041      */
0042     void resultScoreUpdated(const QString &resource, double score, uint lastUpdate, uint firstUpdate);
0043 
0044     /**
0045      * Emitted when a result has been added or updated. This either means
0046      * a new resource has appeared in the result set, or that
0047      * a previously existing one has some of the attributes changed.
0048      * @param result new data for the resource defined by result.resource
0049      */
0050     void resultRemoved(const QString &resource);
0051 
0052     /**
0053      * Emitted when a result has been linked to the activity
0054      */
0055     void resultLinked(const QString &resource);
0056 
0057     /**
0058      * Emitted when a result has been linked to the activity
0059      */
0060     void resultUnlinked(const QString &resource);
0061 
0062     /**
0063      * Emitted when the title of a resource has been changed.
0064      * @param resource URL of the resource that has a new title
0065      * @param title new title of the resource
0066      * @note This signal will be emitted even for the resources that
0067      * do not match the specified query. This is because the class is
0068      * lightweight, and it does not keep track of which resources match
0069      * the query to be able to filter this signal.
0070      */
0071     void resourceTitleChanged(const QString &resource, const QString &title);
0072 
0073     /**
0074      * Emitted when the mimetype of a resource has been changed.
0075      * @param resource URL of the resource that has a new mimetype
0076      * @param mimetype new mimetype of the resource
0077      * @note This signal will be emitted even for the resources that
0078      * do not match the specified query. This is because the class is
0079      * lightweight, and it does not keep track of which resources match
0080      * the query to be able to filter this signal.
0081      */
0082     void resourceMimetypeChanged(const QString &resource, const QString &mimetype);
0083 
0084     /**
0085      * Emitted when the client should forget about all the results it
0086      * knew about and reload them. This can happen when the user clears
0087      * the history, or when there are more significant changes to the data.
0088      */
0089     void resultsInvalidated();
0090 
0091 public:
0092     void linkToActivity(const QUrl &resource,
0093                         const Terms::Activity &activity = Terms::Activity(QStringList()),
0094                         const Terms::Agent &agent = Terms::Agent(QStringList()));
0095 
0096     void unlinkFromActivity(const QUrl &resource,
0097                             const Terms::Activity &activity = Terms::Activity(QStringList()),
0098                             const Terms::Agent &agent = Terms::Agent(QStringList()));
0099 
0100 private:
0101     ResultWatcherPrivate *const d;
0102 };
0103 
0104 } // namespace Stats
0105 } // namespace KActivities
0106 
0107 #endif // KACTIVITIES_STATS_RESULTWATCHER