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 return m_modelData[row].toMap()["rowData"].toMap();
149QVariant UnityMenuModel::subMenuData(int row) const
151 return m_modelData[row].toMap()["submenu"];
154QModelIndex UnityMenuModel::index(int row, int column, const QModelIndex&) const
156 return createIndex(row, column);
159QModelIndex UnityMenuModel::parent(const QModelIndex &) const
161 return QModelIndex();
164QHash<int, QByteArray> UnityMenuModel::roleNames() const
166 QHash<int, QByteArray> names;
168 names[LabelRole] = "label";
169 names[SensitiveRole] = "sensitive";
170 names[IsSeparatorRole] = "isSeparator";
171 names[IconRole] = "icon";
172 names[TypeRole] = "type";
173 names[ExtendedAttributesRole] = "ext";
174 names[ActionRole] = "action";
175 names[ActionStateRole] = "actionState";
176 names[IsCheckRole] = "isCheck";
177 names[IsRadioRole] = "isRadio";
178 names[IsToggledRole] = "isToggled";
183QObject * UnityMenuModel::submenu(int position, QQmlComponent*)
185 if (position < 0 || m_modelData.count() < position) {
189 while (submenus.count() <= position) {
190 submenus.append(NULL);
193 QVariant submenuData = subMenuData(position);
194 if (submenuData.type() == (int)QMetaType::QVariantList) {
195 UnityMenuModel*& model = submenus[position];
197 model = new UnityMenuModel(this);
199 if (model->modelData() != submenuData) {
200 model->setModelData(submenuData);
208bool UnityMenuModel::loadExtendedAttributes(int, const QVariantMap &)
213QVariant UnityMenuModel::get(int row, const QByteArray &role)
215 static QHash<QByteArray, int> roles;
216 if (roles.isEmpty()) {
217 QHash<int, QByteArray> names = roleNames();
218 Q_FOREACH (int role, names.keys())
219 roles.insert(names[role], role);
222 return this->data(this->index(row, 0), roles[role]);
225void UnityMenuModel::activate(int, const QVariant&)
229void UnityMenuModel::changeState(int, const QVariant&)
233void UnityMenuModel::registerAction(UnityMenuAction*)
237void 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