~ps-jenkins/unity-scopes-shell/ubuntu-rtm-14.09-proposed

« back to all changes in this revision

Viewing changes to src/categories.h

  • Committer: Michal Hruby
  • Date: 2013-11-07 17:48:16 UTC
  • Revision ID: michal.mhr@gmail.com-20131107174816-w1vqq6juarrawx23
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Michał Sawicz <michal.sawicz@canonical.com>
 
6
 *  Michal Hruby <michal.hruby@canonical.com>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; version 3.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
 
 
22
#ifndef CATEGORIES_H
 
23
#define CATEGORIES_H
 
24
 
 
25
// unity-core
 
26
#include <UnityCore/Scope.h>
 
27
 
 
28
// dee-qt
 
29
#include "deelistmodel.h"
 
30
 
 
31
#include <QPointer>
 
32
#include <QSet>
 
33
#include <QTimer>
 
34
 
 
35
// local
 
36
#include "signalslist.h"
 
37
 
 
38
class Categories : public DeeListModel
 
39
{
 
40
    Q_OBJECT
 
41
 
 
42
    Q_ENUMS(Roles)
 
43
 
 
44
public:
 
45
    explicit Categories(QObject* parent = 0);
 
46
 
 
47
    enum Roles {
 
48
        RoleCategoryId,
 
49
        RoleName,
 
50
        RoleIcon,
 
51
        RoleRenderer,
 
52
        RoleContentType,
 
53
        RoleRendererHint,
 
54
        RoleProgressSource,
 
55
        RoleHints,
 
56
        RoleResults,
 
57
        RoleCount
 
58
    };
 
59
 
 
60
    Q_INVOKABLE void overrideResults(const QString& categoryId, QAbstractItemModel* model);
 
61
 
 
62
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
 
63
 
 
64
    QHash<int, QByteArray> roleNames() const;
 
65
 
 
66
    /* setters */
 
67
    void setUnityScope(const unity::dash::Scope::Ptr& scope);
 
68
 
 
69
private Q_SLOTS:
 
70
    void onCountChanged();
 
71
    void onRowCountChanged();
 
72
    void onEmitCountChanged();
 
73
    void onOverrideModelDestroyed();
 
74
 
 
75
private:
 
76
    void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
 
77
    void onCategoryOrderChanged(const std::vector<unsigned int>& cat_order);
 
78
 
 
79
    DeeListModel* getResults(int index) const;
 
80
 
 
81
    unity::dash::Scope::Ptr m_unityScope;
 
82
    QTimer m_timer;
 
83
    QSet<int> m_updatedCategories;
 
84
    QHash<int, QByteArray> m_roles;
 
85
    QMap<QString, QAbstractItemModel*> m_overriddenCategories;
 
86
    mutable QMap<int, DeeListModel*> m_results;
 
87
    SignalsList m_signals;
 
88
 
 
89
    /* Category order array contains indices of actual categories in the underlying DeeListModel.
 
90
       It's used internally to reflect category order reported by scope.
 
91
     */
 
92
    mutable QList<unsigned int> m_categoryOrder;
 
93
};
 
94
 
 
95
#endif // CATEGORIES_H