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

« back to all changes in this revision

Viewing changes to src/scopes.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) 2011 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Florian Boucault <florian.boucault@canonical.com>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#ifndef SCOPES_H
 
21
#define SCOPES_H
 
22
 
 
23
// Qt
 
24
#include <QAbstractListModel>
 
25
#include <QList>
 
26
 
 
27
// libunity-core
 
28
#include <UnityCore/Scope.h>
 
29
#include <UnityCore/GSettingsScopes.h>
 
30
 
 
31
namespace unity
 
32
{
 
33
namespace dash
 
34
{
 
35
class Scopes;
 
36
}
 
37
}
 
38
 
 
39
class Hotkey;
 
40
class Scope;
 
41
 
 
42
class Scopes : public QAbstractListModel
 
43
{
 
44
    Q_OBJECT
 
45
 
 
46
    Q_ENUMS(Roles)
 
47
 
 
48
    Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
 
49
 
 
50
public:
 
51
    explicit Scopes(QObject *parent = 0);
 
52
    ~Scopes() = default;
 
53
 
 
54
    enum Roles {
 
55
        RoleScope,
 
56
        RoleId,
 
57
        RoleVisible
 
58
    };
 
59
 
 
60
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
 
61
    Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const;
 
62
 
 
63
    Q_INVOKABLE QVariant get(int row) const;
 
64
    Q_INVOKABLE QVariant get(const QString& scope_id) const;
 
65
 
 
66
    QHash<int, QByteArray> roleNames() const;
 
67
 
 
68
    bool loaded() const;
 
69
 
 
70
Q_SIGNALS:
 
71
    void activateScopeRequested(const QString& scope_id);
 
72
    void loadedChanged(bool loaded);
 
73
    void scopeRemoved(const QString& scope_id, int index);
 
74
 
 
75
private Q_SLOTS:
 
76
    void onScopesLoaded();
 
77
    void onScopeAdded(const unity::dash::Scope::Ptr& scope, int position);
 
78
    void onScopeRemoved(const unity::dash::Scope::Ptr& scope);
 
79
    void onScopesReordered(const unity::dash::Scopes::ScopeList& scopes);
 
80
    void onScopePropertyChanged();
 
81
 
 
82
private:
 
83
    unity::dash::GSettingsScopesReader::Ptr m_scopesReader;
 
84
    unity::dash::Scopes::Ptr m_unityScopes;
 
85
    QList<Scope*> m_scopes;
 
86
    QHash<int, QByteArray> m_roles;
 
87
    bool m_loaded;
 
88
 
 
89
    void addUnityScope(const unity::dash::Scope::Ptr& unity_scope);
 
90
    void removeUnityScope(int index);
 
91
    int findScopeById(const QString& scope_id);
 
92
};
 
93
 
 
94
#endif // SCOPES_H