on 4e4dafa help sign in
unity8/plugins/Unity/scopes.h
94 lines 2.4 kB history raw
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 */
20#ifndef SCOPES_H
21#define SCOPES_H
23// Qt
24#include <QAbstractListModel>
25#include <QList>
27// libunity-core
28#include <UnityCore/Scope.h>
29#include <UnityCore/GSettingsScopes.h>
31namespace unity
33namespace dash
35class Scopes;
39class Hotkey;
40class Scope;
42class Scopes : public QAbstractListModel
44 Q_OBJECT
46 Q_ENUMS(Roles)
48 Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
50public:
51 explicit Scopes(QObject *parent = 0);
52 ~Scopes() = default;
54 enum Roles {
55 RoleScope,
56 RoleId,
57 RoleVisible
58 };
60 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
61 Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const;
63 Q_INVOKABLE QVariant get(int row) const;
64 Q_INVOKABLE QVariant get(const QString& scope_id) const;
66 QHash<int, QByteArray> roleNames() const;
68 bool loaded() const;
70Q_SIGNALS:
71 void activateScopeRequested(const QString& scope_id);
72 void loadedChanged(bool loaded);
73 void scopeRemoved(const QString& scope_id, int index);
75private 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();
82private:
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;
89 void addUnityScope(const unity::dash::Scope::Ptr& unity_scope);
90 void removeUnityScope(int index);
91 int findScopeById(const QString& scope_id);
92};
94#endif // SCOPES_H