~ubuntu-branches/ubuntu/saucy/kactivities/saucy-proposed

« back to all changes in this revision

Viewing changes to service/plugins/nepomuk/Rankings.h

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Scott Kitterman
  • Date: 2012-11-20 13:47:27 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121120134727-vqzk04slqjoay3de
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Scott Kitterman ]
* Add new libkactivities-models1 library package (debian/control, .install,
  and .symbols)
* Add nepomuk-core-dev to build-depends
* Wildcard libkactivities6.install so that soversion changes don't cause
  build failures
* Update libkactivities6.symbols
* Update libkactivities-dev.install for new files for libkactivies-models
* Add new files to libkactivities-bin.install, including Activities kcm

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Copyright (C) 2011 Ivan Cukic <ivan.cukic@kde.org>
3
 
 *
4
 
 *   This program is free software; you can redistribute it and/or
5
 
 *   modify it under the terms of the GNU General Public License as
6
 
 *   published by the Free Software Foundation; either version 2 of
7
 
 *   the License, or (at your option) any later version.
8
 
 *
9
 
 *   This program is distributed in the hope that it will be useful,
10
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 *   GNU General Public License for more details.
13
 
 *
14
 
 *   You should have received a copy of the GNU General Public License
15
 
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#ifndef PLUGINS_NEPOMUK_RANKINGS_H
19
 
#define PLUGINS_NEPOMUK_RANKINGS_H
20
 
 
21
 
#include <QHash>
22
 
#include <QObject>
23
 
#include <QString>
24
 
#include <QStringList>
25
 
#include <QUrl>
26
 
#include <QThread>
27
 
 
28
 
#include <Nepomuk/Resource>
29
 
 
30
 
class Rankings: public QObject
31
 
{
32
 
    Q_OBJECT
33
 
    Q_CLASSINFO("D-Bus Interface", "org.kde.ActivityManager.Rankings")
34
 
 
35
 
public:
36
 
    static void init(QObject * parent = 0);
37
 
    static Rankings * self();
38
 
 
39
 
    void resourceScoreUpdated(const QString & activity,
40
 
            const QString & application, const QUrl & uri, qreal score);
41
 
 
42
 
    ~Rankings();
43
 
 
44
 
public Q_SLOTS:
45
 
    /**
46
 
     * Registers a new client for the specified activity and application
47
 
     * @param client d-bus name
48
 
     * @param activity activity to track. If empty, uses the default activity.
49
 
     * @param application application to track. If empty, all applications are aggregated
50
 
     * @param type resource type that the client is interested in
51
 
     * @note If the activity is left empty - the results are always related to the current activity,
52
 
     *     not the activity that was current when calling this method.
53
 
     */
54
 
    void registerClient(const QString & client,
55
 
            const QString & activity = QString(),
56
 
            const QString & type = QString()
57
 
        );
58
 
 
59
 
    /**
60
 
     * Deregisters a client
61
 
     */
62
 
    void deregisterClient(const QString & client);
63
 
 
64
 
    /**
65
 
     * Don't use this, will be removed
66
 
     */
67
 
    void requestScoreUpdate(const QString & activity, const QString & application, const QString & resource);
68
 
 
69
 
private Q_SLOTS:
70
 
    void setCurrentActivity(const QString & activityId);
71
 
 
72
 
private:
73
 
    Rankings(QObject * parent = 0);
74
 
    void updateScoreTrashold(const QString & activity);
75
 
 
76
 
    static Rankings * s_instance;
77
 
 
78
 
public:
79
 
    class ResultItem {
80
 
    public:
81
 
        ResultItem(
82
 
                const QUrl & _uri,
83
 
                qreal _score
84
 
            )
85
 
            : uri(_uri), score(_score)
86
 
        {
87
 
        }
88
 
 
89
 
        QUrl uri;
90
 
        qreal score;
91
 
 
92
 
    };
93
 
 
94
 
    typedef QString Activity;
95
 
    typedef QString Client;
96
 
 
97
 
private Q_SLOTS:
98
 
    void initResults(const QString & activity);
99
 
    void notifyResultsUpdated(const QString & activity, QStringList clients = QStringList());
100
 
 
101
 
private:
102
 
    QHash < Activity, QStringList > m_clients;
103
 
    QHash < Activity, QList < ResultItem > > m_results;
104
 
    QHash < Activity, qreal > m_resultScoreTreshold;
105
 
};
106
 
 
107
 
class RankingsUpdateThread: public QThread {
108
 
    Q_OBJECT
109
 
 
110
 
public:
111
 
    RankingsUpdateThread(const QString & activity, QList < Rankings::ResultItem > * listptr,
112
 
            QHash < Rankings::Activity, qreal > * scoreTrashold);
113
 
    virtual ~RankingsUpdateThread();
114
 
 
115
 
    void run();
116
 
 
117
 
Q_SIGNALS:
118
 
    void loaded(const QString & activity);
119
 
 
120
 
private:
121
 
    static QUrl urlFor(const Nepomuk::Resource & resource);
122
 
 
123
 
    QString m_activity;
124
 
    QList < Rankings::ResultItem > * m_listptr;
125
 
    QHash < Rankings::Activity, qreal > * m_scoreTrashold;
126
 
};
127
 
 
128
 
#endif // PLUGINS_NEPOMUK_RANKINGS_H