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"
23 LabelRole = Qt::DisplayRole + 1,
28 ExtendedAttributesRole,
36UnityMenuModel::UnityMenuModel(QObject *parent)
37: QAbstractListModel(parent)
41QVariant UnityMenuModel::modelData() const
46void UnityMenuModel::setModelData(const QVariant& data)
51 m_modelData = data.toList();
57void UnityMenuModel::insertRow(int row, const QVariant& data)
59 row = qMin(row, rowCount());
61 beginInsertRows(QModelIndex(), row, row);
63 m_modelData.insert(row, data);
68void UnityMenuModel::appendRow(const QVariant& data)
70 insertRow(rowCount(), data);
73void UnityMenuModel::removeRow(int row)
75 if (row < 0 || rowCount() <= row) {
79 beginRemoveRows(QModelIndex(), row, row);
81 m_modelData.removeAt(row);
86UnityMenuModel::~UnityMenuModel()
90QByteArray UnityMenuModel::busName() const
95void UnityMenuModel::setBusName(const QByteArray &busName)
97 this->m_busName = busName;
100QVariantMap UnityMenuModel::actions() const
105void UnityMenuModel::setActions(const QVariantMap &actions)
107 this->m_actions = actions;
110QByteArray UnityMenuModel::menuObjectPath() const
112 return m_menuObjectPath;
115void UnityMenuModel::setMenuObjectPath(const QByteArray &path)
117 this->m_menuObjectPath = path;
120ActionStateParser* UnityMenuModel::actionStateParser() const
125void UnityMenuModel::setActionStateParser(ActionStateParser*)
129int UnityMenuModel::rowCount(const QModelIndex&) const
131 return m_modelData.count();
134int UnityMenuModel::columnCount(const QModelIndex&) const
139QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
141 return rowData(index.row())[roleNames()[role]];
144QVariantMap UnityMenuModel::rowData(int row) const
146 if (m_modelData.count() <= row) {
147 return QVariantMap();
149 return m_modelData[row].toMap()["rowData"].toMap();
152QVariant UnityMenuModel::subMenuData(int row) const
154 return m_modelData[row].toMap()["submenu"];
157QModelIndex UnityMenuModel::index(int row, int column, const QModelIndex&) const
159 return createIndex(row, column);
162QModelIndex UnityMenuModel::parent(const QModelIndex &) const
164 return QModelIndex();
167QHash<int, QByteArray> UnityMenuModel::roleNames() const
169 QHash<int, QByteArray> names;
171 names[LabelRole] = "label";
172 names[SensitiveRole] = "sensitive";
173 names[IsSeparatorRole] = "isSeparator";
174 names[IconRole] = "icon";
175 names[TypeRole] = "type";
176 names[ExtendedAttributesRole] = "ext";
177 names[ActionRole] = "action";
178 names[ActionStateRole] = "actionState";
179 names[IsCheckRole] = "isCheck";
180 names[IsRadioRole] = "isRadio";
181 names[IsToggledRole] = "isToggled";
186QObject * UnityMenuModel::submenu(int position, QQmlComponent*)
188 if (position < 0 || m_modelData.count() < position) {
192 while (submenus.count() <= position) {
193 submenus.append(NULL);
196 QVariant submenuData = subMenuData(position);
197 if (submenuData.type() == (int)QMetaType::QVariantList) {
198 UnityMenuModel*& model = submenus[position];
200 model = new UnityMenuModel(this);
202 if (model->modelData() != submenuData) {
203 model->setModelData(submenuData);
211bool UnityMenuModel::loadExtendedAttributes(int, const QVariantMap &)
216QVariant UnityMenuModel::get(int row, const QByteArray &role)
218 static QHash<QByteArray, int> roles;
219 if (roles.isEmpty()) {
220 QHash<int, QByteArray> names = roleNames();
221 Q_FOREACH (int role, names.keys())
222 roles.insert(names[role], role);
225 return this->data(this->index(row, 0), roles[role]);
228void UnityMenuModel::activate(int, const QVariant&)
232void UnityMenuModel::changeState(int, const QVariant&)
236void UnityMenuModel::registerAction(UnityMenuAction*)
240void 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