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/>.
17 * Michal Hruby <michal.hruby@canonical.com>
28#define BASE_THEME_ICON_URI "image://theme/"
29#define BASE_THUMBNAILER_URI "image://thumbnailer/"
30#define BASE_ALBUMART_URI "image://albumart/"
32QString gIconToDeclarativeImageProviderString(QString const &giconString)
34 if (giconString.isEmpty()) return giconString;
36 if (giconString.startsWith('/') || giconString.startsWith(QLatin1String("http")) ||
37 giconString.startsWith(QLatin1String("file:")) || giconString.startsWith(QLatin1String("image:"))) {
41 if (!giconString.startsWith(QLatin1String(". "))) {
42 // must be a themed icon
43 QString themedIcon(BASE_THEME_ICON_URI);
44 themedIcon.append(giconString);
48 // special case annotated icon
49 if (giconString.startsWith(QLatin1String(". UnityProtocolAnnotatedIcon "))) {
50 QString annotatedIcon;
51 QString serializedData(QUrl::fromPercentEncoding(giconString.mid(29).toUtf8()));
52 GVariant *variant = g_variant_parse(G_VARIANT_TYPE_VARDICT, serializedData.toUtf8().constData(), NULL, NULL, NULL);
54 if (variant != NULL && g_variant_lookup(variant, "base-icon", "&s", &baseUri)) {
55 annotatedIcon = gIconToDeclarativeImageProviderString(QString(baseUri));
56 // FIXME: enclose in image://annotated/... once unity supports that
58 if (variant != NULL) g_variant_unref(variant);
63 // handle real gicon strings
66 GIcon *icon = g_icon_new_for_string(giconString.toLocal8Bit().constData(), &error);
67 if (error != NULL || icon == NULL) {
68 qWarning("Unable to deserialize icon: %s", giconString.toLocal8Bit().constData());
69 g_clear_error(&error);
73 if (G_IS_THEMED_ICON(icon)) {
74 QString themedIcon(BASE_THEME_ICON_URI);
76 const char* const *iconNames = g_themed_icon_get_names(G_THEMED_ICON(icon));
77 if (iconNames != NULL) {
78 for (const char * const *iter = iconNames; *iter != NULL; ++iter) {
79 list << QLatin1String(*iter);
82 themedIcon.append(list.join(QString(",")));
84 } else if (G_IS_FILE_ICON(icon)) {
85 GFile *file = g_file_icon_get_file(G_FILE_ICON(icon));
86 gchar *uri = g_file_get_uri(file);
97QString uriToThumbnailerProviderString(QString const &uri, QString const &mimetype, QVariantHash const &metadata)
99 if (uri.startsWith(QLatin1String("file:///"))) {
100 bool isAudio = mimetype.startsWith(QLatin1String("audio/"));
101 QString thumbnailerUri;
103 thumbnailerUri = BASE_ALBUMART_URI;
104 if (metadata.contains("content")) {
105 QVariantHash contentHash = metadata["content"].toHash();
106 if (contentHash.contains("content")) { // nested content in Home?
107 contentHash = contentHash["content"].toHash();
109 if (contentHash.contains("album") && contentHash.contains("artist")) {
111 query.addQueryItem(QStringLiteral("artist"), contentHash["artist"].toString());
112 query.addQueryItem(QStringLiteral("album"), contentHash["album"].toString());
113 thumbnailerUri.append(query.toString());
117 thumbnailerUri = BASE_THUMBNAILER_URI;
118 thumbnailerUri.append(uri.midRef(7));
120 return thumbnailerUri;
123 return QString::null;
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