aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src/unitymenumodel.cpp
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-06-25 15:39:11 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-06-25 15:39:11 -0400
commit6aaafd55328c1860fd1b734fa29ff77673538a2b (patch)
treeb2c54591354672c6c15b959160a5d013345329b7 /libqmenumodel/src/unitymenumodel.cpp
parent050958c58924934b10cf3a6272cff3ebe867f1dd (diff)
downloadqmenumodel-6aaafd55328c1860fd1b734fa29ff77673538a2b.tar.gz
qmenumodel-6aaafd55328c1860fd1b734fa29ff77673538a2b.tar.bz2
qmenumodel-6aaafd55328c1860fd1b734fa29ff77673538a2b.zip
unitymenumodel: add support for icons
For now, this includes themed icons, file icons, and icons send as raw data.
Diffstat (limited to 'libqmenumodel/src/unitymenumodel.cpp')
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 81f5121..db70936 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -31,7 +31,8 @@ enum MenuRoles {
ActionRole = Qt::DisplayRole + 1,
LabelRole,
SensitiveRole,
- IsSeparatorRole
+ IsSeparatorRole,
+ IconRole
};
class UnityMenuModelPrivate
@@ -279,6 +280,47 @@ int UnityMenuModel::columnCount(const QModelIndex &parent) const
return 1;
}
+static QString iconUri(GIcon *icon)
+{
+ QString uri;
+
+ if (G_IS_THEMED_ICON (icon)) {
+ const gchar * const *names;
+
+ names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+ if (names && names[0] && *names[0])
+ uri = QString("image://theme/") + names[0];
+ }
+ else if (G_IS_FILE_ICON (icon)) {
+ GFile *file;
+
+ file = g_file_icon_get_file (G_FILE_ICON (icon));
+ if (g_file_is_native (file)) {
+ gchar *fileuri;
+
+ fileuri = g_file_get_path (file);
+ uri = QString(fileuri);
+
+ g_free (fileuri);
+ }
+ }
+ else if (G_IS_BYTES_ICON (icon)) {
+ gsize size;
+ gconstpointer data;
+ gchar *base64;
+
+ data = g_bytes_get_data (g_bytes_icon_get_bytes (G_BYTES_ICON (icon)), &size);
+ base64 = g_base64_encode ((const guchar *) data, size);
+
+ uri = QString("data://");
+ uri.append (base64);
+
+ g_free (base64);
+ }
+
+ return uri;
+}
+
QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
{
GtkMenuTrackerItem *item;
@@ -295,6 +337,17 @@ QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
case IsSeparatorRole:
return gtk_menu_tracker_item_get_is_separator (item);
+ case IconRole: {
+ GIcon *icon = gtk_menu_tracker_item_get_icon (item);
+ if (icon) {
+ QString uri = iconUri(icon);
+ g_object_unref (icon);
+ return uri;
+ }
+ else
+ return QString();
+ }
+
default:
return QVariant();
}
@@ -318,6 +371,7 @@ QHash<int, QByteArray> UnityMenuModel::roleNames() const
names[ActionRole] = "action";
names[SensitiveRole] = "sensitive";
names[IsSeparatorRole] = "isSeparator";
+ names[IconRole] = "icon";
return names;
}