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>
26#define BASE_THEME_ICON_URI "image://theme/"
27#define BASE_THUMBNAILER_URI "image://thumbnailer/"
28#define BASE_ALBUMART_URI "image://albumart/"
30QString gIconToDeclarativeImageProviderString(QString const &giconString)
32 if (giconString.isEmpty()) return giconString;
34 if (giconString.startsWith('/') || giconString.startsWith(QLatin1String("http")) ||
35 giconString.startsWith(QLatin1String("file:")) || giconString.startsWith(QLatin1String("image:"))) {
39 if (!giconString.startsWith(QLatin1String(". "))) {
40 // must be a themed icon
41 QString themedIcon(BASE_THEME_ICON_URI);
42 themedIcon.append(giconString);
46 // special case annotated icon
47 if (giconString.startsWith(QLatin1String(". UnityProtocolAnnotatedIcon "))) {
48 QString annotatedIcon;
49 QString serializedData(QUrl::fromPercentEncoding(giconString.mid(29).toUtf8()));
50 GVariant *variant = g_variant_parse(G_VARIANT_TYPE_VARDICT, serializedData.toUtf8().constData(), NULL, NULL, NULL);
52 if (variant != NULL && g_variant_lookup(variant, "base-icon", "&s", &baseUri)) {
53 annotatedIcon = gIconToDeclarativeImageProviderString(QString(baseUri));
54 // FIXME: enclose in image://annotated/... once unity supports that
56 if (variant != NULL) g_variant_unref(variant);
61 // handle real gicon strings
64 GIcon *icon = g_icon_new_for_string(giconString.toLocal8Bit().constData(), &error);
65 if (error != NULL || icon == NULL) {
66 qWarning("Unable to deserialize icon: %s", giconString.toLocal8Bit().constData());
67 g_clear_error(&error);
71 if (G_IS_THEMED_ICON(icon)) {
72 QString themedIcon(BASE_THEME_ICON_URI);
74 const char* const *iconNames = g_themed_icon_get_names(G_THEMED_ICON(icon));
75 if (iconNames != NULL) {
76 for (const char * const *iter = iconNames; *iter != NULL; ++iter) {
77 list << QLatin1String(*iter);
80 themedIcon.append(list.join(QString(",")));
82 } else if (G_IS_FILE_ICON(icon)) {
83 GFile *file = g_file_icon_get_file(G_FILE_ICON(icon));
84 gchar *uri = g_file_get_uri(file);
95QString uriToThumbnailerProviderString(QString const &uri, QString const &mimetype, QVariantHash const &metadata)
97 if (uri.startsWith(QLatin1String("file:///"))) {
98 bool isAudio = mimetype.startsWith(QLatin1String("audio/"));
99 QString thumbnailerUri;
101 thumbnailerUri = BASE_ALBUMART_URI;
102 if (metadata.contains("content")) {
103 QVariantHash contentHash = metadata["content"].toHash();
104 if (contentHash.contains("content")) { // nested content in Home?
105 contentHash = contentHash["content"].toHash();
107 if (contentHash.contains("album") &&
108 contentHash.contains("artist")) {
109 const QString album = contentHash["album"].toString();
110 const QString artist = contentHash["artist"].toString();
111 thumbnailerUri.append(QUrl::toPercentEncoding(artist));
112 thumbnailerUri.append("/");
113 thumbnailerUri.append(QUrl::toPercentEncoding(album));
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