2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authors: Nick Dedekind <nick.dedekind@canonical.com>
19#include "unitymenumodel.h"
22 LabelRole = Qt::DisplayRole + 1,
27 ExtendedAttributesRole,
35UnityMenuModel::UnityMenuModel(QObject *parent)
36: QAbstractListModel(parent)
40UnityMenuModel::~UnityMenuModel()
44QVariant UnityMenuModel::modelData() const
49void UnityMenuModel::setModelData(const QVariant& data)
54 m_modelData = data.toList();
60void UnityMenuModel::insertRow(int row, const QVariant& data)
62 row = qMin(row, rowCount());
64 beginInsertRows(QModelIndex(), row, row);
66 m_modelData.insert(row, data);
71void UnityMenuModel::appendRow(const QVariant& data)
73 insertRow(rowCount(), data);
76void UnityMenuModel::removeRow(int row)
78 if (row < 0 || rowCount() <= row) {
82 beginRemoveRows(QModelIndex(), row, row);
84 m_modelData.removeAt(row);
89QByteArray UnityMenuModel::busName() const
94void UnityMenuModel::setBusName(const QByteArray &busName)
96 this->m_busName = busName;
99QVariantMap UnityMenuModel::actions() const
104void UnityMenuModel::setActions(const QVariantMap &actions)
106 this->m_actions = actions;
109QByteArray UnityMenuModel::menuObjectPath() const
111 return m_menuObjectPath;
114void UnityMenuModel::setMenuObjectPath(const QByteArray &path)
116 this->m_menuObjectPath = path;
119ActionStateParser* UnityMenuModel::actionStateParser() const
124void UnityMenuModel::setActionStateParser(ActionStateParser*)
128QString UnityMenuModel::nameOwner() const
133int UnityMenuModel::rowCount(const QModelIndex&) const
135 return m_modelData.count();
138int UnityMenuModel::columnCount(const QModelIndex&) const
143QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
145 return rowData(index.row())[roleNames()[role]];
148QVariantMap UnityMenuModel::rowData(int row) const
150 if (m_modelData.count() <= row) {
151 return QVariantMap();
153 return m_modelData[row].toMap()["rowData"].toMap();
156QVariant UnityMenuModel::subMenuData(int row) const
158 return m_modelData[row].toMap()["submenu"];
161QModelIndex UnityMenuModel::index(int row, int column, const QModelIndex&) const
163 return createIndex(row, column);
166QModelIndex UnityMenuModel::parent(const QModelIndex &) const
168 return QModelIndex();
171QHash<int, QByteArray> UnityMenuModel::roleNames() const
173 QHash<int, QByteArray> names;
175 names[LabelRole] = "label";
176 names[SensitiveRole] = "sensitive";
177 names[IsSeparatorRole] = "isSeparator";
178 names[IconRole] = "icon";
179 names[TypeRole] = "type";
180 names[ExtendedAttributesRole] = "ext";
181 names[ActionRole] = "action";
182 names[ActionStateRole] = "actionState";
183 names[IsCheckRole] = "isCheck";
184 names[IsRadioRole] = "isRadio";
185 names[IsToggledRole] = "isToggled";
190QObject * UnityMenuModel::submenu(int position, QQmlComponent*)
192 if (position < 0 || m_modelData.count() < position) {
196 while (submenus.count() <= position) {
197 submenus.append(nullptr);
200 QVariant submenuData = subMenuData(position);
201 if (submenuData.type() == (int)QMetaType::QVariantList) {
202 UnityMenuModel*& model = submenus[position];
204 model = new UnityMenuModel(this);
206 if (model->modelData() != submenuData) {
207 model->setModelData(submenuData);
215bool UnityMenuModel::loadExtendedAttributes(int, const QVariantMap &)
220QVariant UnityMenuModel::get(int row, const QByteArray &role)
222 static QHash<QByteArray, int> roles;
223 if (roles.isEmpty()) {
224 QHash<int, QByteArray> names = roleNames();
225 Q_FOREACH (int role, names.keys())
226 roles.insert(names[role], role);
229 return this->data(this->index(row, 0), roles[role]);
232void UnityMenuModel::activate(int, const QVariant&)
236void UnityMenuModel::changeState(int, const QVariant&)
240void UnityMenuModel::registerAction(UnityMenuAction*)
244void UnityMenuModel::unregisterAction(UnityMenuAction*)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list