[gnome-flashback] desktop: launch .desktop files
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] desktop: launch .desktop files
- Date: Wed, 13 Nov 2019 22:33:51 +0000 (UTC)
commit 084287e2121568474f511025b6133601e5a510a5
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Nov 14 00:21:16 2019 +0200
desktop: launch .desktop files
gnome-flashback/libdesktop/gf-icon-view.c | 1 +
gnome-flashback/libdesktop/gf-icon.c | 97 +++++++++++++++++++++++++------
gnome-flashback/libdesktop/gf-utils.c | 7 +++
gnome-flashback/libdesktop/gf-utils.h | 12 ++--
4 files changed, 94 insertions(+), 23 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index d93ee6d..c56a05d 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -109,6 +109,7 @@ get_required_attributes (void)
return build_attributes_list (G_FILE_ATTRIBUTE_STANDARD_NAME,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_ATTRIBUTE_STANDARD_ICON,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP,
NULL);
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index 024fcf4..9a33333 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -18,6 +18,7 @@
#include "config.h"
#include "gf-icon.h"
+#include <gio/gdesktopappinfo.h>
#include <glib/gi18n.h>
#include "gf-desktop-enums.h"
@@ -26,21 +27,23 @@
typedef struct
{
- GtkGesture *multi_press;
+ GtkGesture *multi_press;
- GfIconView *icon_view;
- GFile *file;
- GFileInfo *info;
+ GfIconView *icon_view;
+ GFile *file;
+ GFileInfo *info;
- GfIconSize icon_size;
- guint extra_text_width;
+ GfIconSize icon_size;
+ guint extra_text_width;
- char *css_class;
+ char *css_class;
- GtkWidget *image;
- GtkWidget *label;
+ GtkWidget *image;
+ GtkWidget *label;
- gboolean selected;
+ gboolean selected;
+
+ GDesktopAppInfo *app_info;
} GfIconPrivate;
enum
@@ -91,14 +94,25 @@ static void
icon_open (GfIcon *self)
{
GfIconPrivate *priv;
- char *uri;
GError *error;
+ char *uri;
priv = gf_icon_get_instance_private (self);
+ error = NULL;
+
+ if (priv->app_info != NULL)
+ {
+ if (!gf_launch_app_info (priv->app_info, &error))
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ return;
+ }
uri = g_file_get_uri (priv->file);
- error = NULL;
if (!gf_launch_uri (uri, &error))
{
g_warning ("%s", error->message);
@@ -280,26 +294,69 @@ set_icon_size (GfIcon *self,
}
static void
-gf_icon_constructed (GObject *object)
+update_icon (GfIcon *self)
{
- GfIcon *self;
GfIconPrivate *priv;
GIcon *icon;
- const char *name;
- self = GF_ICON (object);
priv = gf_icon_get_instance_private (self);
- G_OBJECT_CLASS (gf_icon_parent_class)->constructed (object);
+ icon = NULL;
+ if (priv->app_info != NULL)
+ icon = g_app_info_get_icon (G_APP_INFO (priv->app_info));
+
+ if (icon == NULL)
+ icon = g_file_info_get_icon (priv->info);
- icon = g_file_info_get_icon (priv->info);
gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_DIALOG);
gtk_image_set_pixel_size (GTK_IMAGE (priv->image), priv->icon_size);
+}
+
+static void
+update_text (GfIcon *self)
+{
+ GfIconPrivate *priv;
+ const char *name;
+
+ priv = gf_icon_get_instance_private (self);
+
+ name = NULL;
+ if (priv->app_info != NULL)
+ name = g_app_info_get_name (G_APP_INFO (priv->app_info));
+
+ if (name == NULL)
+ name = g_file_info_get_display_name (priv->info);
- name = g_file_info_get_display_name (priv->info);
gtk_label_set_text (GTK_LABEL (priv->label), name);
}
+static void
+gf_icon_constructed (GObject *object)
+{
+ GfIcon *self;
+ GfIconPrivate *priv;
+ const char *content_type;
+
+ self = GF_ICON (object);
+ priv = gf_icon_get_instance_private (self);
+
+ G_OBJECT_CLASS (gf_icon_parent_class)->constructed (object);
+
+ content_type = g_file_info_get_content_type (priv->info);
+
+ if (g_strcmp0 (content_type, "application/x-desktop") == 0)
+ {
+ char *path;
+
+ path = g_file_get_path (priv->file);
+ priv->app_info = g_desktop_app_info_new_from_filename (path);
+ g_free (path);
+ }
+
+ update_icon (self);
+ update_text (self);
+}
+
static void
gf_icon_dispose (GObject *object)
{
@@ -314,6 +371,8 @@ gf_icon_dispose (GObject *object)
g_clear_object (&priv->file);
g_clear_object (&priv->info);
+ g_clear_object (&priv->app_info);
+
G_OBJECT_CLASS (gf_icon_parent_class)->dispose (object);
}
diff --git a/gnome-flashback/libdesktop/gf-utils.c b/gnome-flashback/libdesktop/gf-utils.c
index 3ca8baa..85a32f2 100644
--- a/gnome-flashback/libdesktop/gf-utils.c
+++ b/gnome-flashback/libdesktop/gf-utils.c
@@ -106,6 +106,13 @@ get_app_info_for_uri (const gchar *uri,
return app_info;
}
+gboolean
+gf_launch_app_info (GDesktopAppInfo *app_info,
+ GError **error)
+{
+ return app_info_launch_uris (app_info, NULL, error);
+}
+
gboolean
gf_launch_desktop_file (const char *desktop_file,
GError **error)
diff --git a/gnome-flashback/libdesktop/gf-utils.h b/gnome-flashback/libdesktop/gf-utils.h
index e07e91a..52d370a 100644
--- a/gnome-flashback/libdesktop/gf-utils.h
+++ b/gnome-flashback/libdesktop/gf-utils.h
@@ -18,15 +18,19 @@
#ifndef GF_UTILS_H
#define GF_UTILS_H
+#include <gio/gdesktopappinfo.h>
#include <glib.h>
G_BEGIN_DECLS
-gboolean gf_launch_desktop_file (const char *desktop_file,
- GError **error);
+gboolean gf_launch_app_info (GDesktopAppInfo *app_info,
+ GError **error);
-gboolean gf_launch_uri (const char *uri,
- GError **error);
+gboolean gf_launch_desktop_file (const char *desktop_file,
+ GError **error);
+
+gboolean gf_launch_uri (const char *uri,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]