2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "rootstateparser.h"
24RootStateParser::RootStateParser(QObject* parent)
25 : ActionStateParser(parent)
29static QString iconUri(GIcon *icon)
33 if (G_IS_THEMED_ICON (icon)) {
34 const gchar* const* iconNames = g_themed_icon_get_names (G_THEMED_ICON (icon));
36 QStringList iconNameList;
37 for (uint index = 0; iconNames[index] != nullptr; index++) {
38 iconNameList << iconNames[index];
41 if (!iconNameList.empty()) {
42 uri = QStringLiteral("image://theme/%1").arg(iconNameList.join(QStringLiteral(",")));
45 else if (G_IS_FILE_ICON (icon)) {
48 file = g_file_icon_get_file (G_FILE_ICON (icon));
49 if (g_file_is_native (file)) {
52 fileuri = g_file_get_path (file);
53 uri = QString(fileuri);
58 else if (G_IS_BYTES_ICON (icon)) {
63 data = g_bytes_get_data (g_bytes_icon_get_bytes (G_BYTES_ICON (icon)), &size);
64 base64 = g_base64_encode ((const guchar *) data, size);
66 uri = QStringLiteral("data://");
75QVariant RootStateParser::toQVariant(GVariant* state) const
81 if (g_variant_is_of_type(state, G_VARIANT_TYPE_VARDICT)) {
87 g_variant_iter_init (&iter, state);
88 while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue))
90 QString str = QString::fromUtf8(key);
91 if (str == QLatin1String("icon") && !qmap.contains(QStringLiteral("icons"))) {
94 // FIXME - should be sending a url.
95 GIcon *gicon = g_icon_deserialize (vvalue);
97 icons << iconUri(gicon);
98 g_object_unref (gicon);
100 qmap.insert(QStringLiteral("icons"), icons);
102 } else if (str == QLatin1String("icons")) {
106 if (g_variant_is_of_type(vvalue, G_VARIANT_TYPE("av"))) {
109 g_variant_iter_init (&iter, vvalue);
110 while (g_variant_iter_loop (&iter, "v", &val))
112 // FIXME - should be sending a url.
113 GIcon *gicon = g_icon_deserialize (val);
115 icons << iconUri(gicon);
116 g_object_unref (gicon);
120 // will overwrite icon.
121 qmap.insert(QStringLiteral("icons"), icons);
124 qmap.insert(str, ActionStateParser::toQVariant(vvalue));
128 return QVariant::fromValue(qmap);
130 } else if (g_variant_is_of_type (state, G_VARIANT_TYPE ("(sssb)"))) {
135 char* accessible_name;
139 g_variant_get(state, "(sssb)", &label,
144 qmap[QStringLiteral("label")] = label ? QString::fromUtf8(label) : QLatin1String("");
145 qmap[QStringLiteral("accessible-desc")] = accessible_name ? QString::fromUtf8(accessible_name) : QLatin1String("");
146 qmap[QStringLiteral("visible")] = visible;
148 gicon = g_icon_new_for_string (icon, nullptr);
150 qmap[QStringLiteral("icons")] = QStringList() << iconUri(gicon);
151 g_object_unref (gicon);
154 if (label) g_free(label);
155 if (icon) g_free(icon);
156 if (accessible_name) g_free(accessible_name);
158 return QVariant::fromValue(qmap);
160 return ActionStateParser::toQVariant(state);
164RootStateObject::RootStateObject(QObject* parent)
169QString RootStateObject::title() const
171 if (!valid()) return QString();
173 return m_currentState.value(QStringLiteral("title"), QVariant::fromValue(QString())).toString();
176QString RootStateObject::leftLabel() const
178 if (!valid()) return QString();
180 return m_currentState.value(QStringLiteral("pre-label"), QVariant::fromValue(QString())).toString();
183QString RootStateObject::rightLabel() const
185 if (!valid()) return QString();
187 return m_currentState.value(QStringLiteral("label"), QVariant::fromValue(QString())).toString();
190QStringList RootStateObject::icons() const
192 if (!valid()) return QStringList();
194 return m_currentState.value(QStringLiteral("icons"), QVariant::fromValue(QStringList())).toStringList();
197QString RootStateObject::accessibleName() const
199 if (!valid()) return QString();
201 return m_currentState.value(QStringLiteral("accessible-desc"), QVariant::fromValue(QString())).toString();
204bool RootStateObject::indicatorVisible() const
206 if (!valid()) return false;
208 return m_currentState.value(QStringLiteral("visible"), QVariant::fromValue(true)).toBool();
211void RootStateObject::setCurrentState(const QVariantMap& newState)
213 QString oldTitle = title();
214 QString oldLeftLabel = leftLabel();
215 QString oldRightLabel = rightLabel();
216 QStringList oldIcons = icons();
217 QString oldAccessibleName = accessibleName();
218 bool oldIndicatorVisible = indicatorVisible();
220 if (m_currentState != newState) {
221 m_currentState = newState;
224 if (oldTitle != title()) Q_EMIT titleChanged();
225 if (oldLeftLabel != leftLabel()) Q_EMIT leftLabelChanged();
226 if (oldRightLabel != rightLabel()) Q_EMIT rightLabelChanged();
227 if (oldIcons != icons()) Q_EMIT iconsChanged();
228 if (oldAccessibleName != accessibleName()) Q_EMIT accessibleNameChanged();
229 if (oldIndicatorVisible != indicatorVisible()) Q_EMIT indicatorVisibleChanged();
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