[gnome-photos] base-item, local-item: Track both the default GAppInfo and it's name



commit 996213075cb28aaae90cb44ff1fa9b874787c6d3
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 11 17:03:51 2015 +0100

    base-item, local-item: Track both the default GAppInfo and it's name
    
    ... for LocalItem. The default GAppInfo can change behind our backs and
    we don't want the actual application and the label shown in the UI to
    get out of sync.
    
    If we have a default GAppInfo, then explicitly use it to launch the
    application instead of just relying on gtk_show_uri. This defends us
    against broken defaults.
    
    Original patch from Bastien Nocera for gnome-documents.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740434

 src/photos-base-item.c  |   61 +++++++++++++++++++++++++++++++++++++++++++----
 src/photos-base-item.h  |    2 +
 src/photos-local-item.c |    5 +---
 3 files changed, 59 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 98cef17..7eb74a2 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -58,6 +58,7 @@
 struct _PhotosBaseItemPrivate
 {
   cairo_surface_t *surface;
+  GAppInfo *default_app;
   GdkPixbuf *original_icon;
   GeglNode *buffer_sink;
   GeglNode *buffer_source;
@@ -390,12 +391,35 @@ photos_base_item_default_open (PhotosBaseItem *self, GdkScreen *screen, guint32
   if (priv->default_app_name == NULL)
     return;
 
-  error = NULL;
-  gtk_show_uri (screen, priv->uri, timestamp, &error);
-  if (error != NULL)
+  /* Without a default_app, launch in the web browser, otherwise use
+   * that system application.
+   */
+
+  if (priv->default_app != NULL)
     {
-      g_warning ("Unable to show URI %s: %s", priv->uri, error->message);
-      g_error_free (error);
+      GList *uris = NULL;
+
+      uris = g_list_prepend (uris, g_strdup (priv->uri));
+
+      error = NULL;
+      g_app_info_launch_uris (priv->default_app, uris, NULL, &error);
+      if (error != NULL)
+        {
+          g_warning ("Unable to show URI %s: %s", priv->uri, error->message);
+          g_error_free (error);
+        }
+
+      g_list_free_full (uris, g_free);
+    }
+  else
+    {
+      error = NULL;
+      gtk_show_uri (screen, priv->uri, timestamp, &error);
+      if (error != NULL)
+        {
+          g_warning ("Unable to show URI %s: %s", priv->uri, error->message);
+          g_error_free (error);
+        }
     }
 }
 
@@ -1173,6 +1197,7 @@ photos_base_item_dispose (GObject *object)
   PhotosBaseItemPrivate *priv = self->priv;
 
   g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);
+  g_clear_object (&priv->default_app);
   g_clear_object (&priv->edit_graph);
   g_clear_object (&priv->load_graph);
   g_clear_object (&priv->processor);
@@ -1890,10 +1915,36 @@ photos_base_item_save_finish (PhotosBaseItem *self, GAsyncResult *res, GError **
 
 
 void
+photos_base_item_set_default_app (PhotosBaseItem *self, GAppInfo *default_app)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  const gchar *default_app_name;
+
+  if (priv->default_app == NULL && default_app == NULL)
+    return;
+
+  if (priv->default_app != NULL && default_app != NULL && g_app_info_equal (priv->default_app, default_app))
+    return;
+
+  g_clear_object (&priv->default_app);
+  g_free (priv->default_app_name);
+
+  if (default_app == NULL)
+    return;
+
+  priv->default_app = g_object_ref (default_app);
+
+  default_app_name = g_app_info_get_name (default_app);
+  priv->default_app_name = g_strdup (default_app_name);
+}
+
+
+void
 photos_base_item_set_default_app_name (PhotosBaseItem *self, const gchar *default_app_name)
 {
   PhotosBaseItemPrivate *priv = self->priv;
 
+  g_clear_object (&priv->default_app);
   g_free (priv->default_app_name);
   priv->default_app_name = g_strdup (default_app_name);
 }
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 7cf2ba8..f349610 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -216,6 +216,8 @@ gboolean            photos_base_item_save_finish             (PhotosBaseItem *se
                                                               GAsyncResult *res,
                                                               GError **error);
 
+void                photos_base_item_set_default_app         (PhotosBaseItem *self, GAppInfo *default_app);
+
 void                photos_base_item_set_default_app_name    (PhotosBaseItem *self, const gchar 
*default_app_name);
 
 void                photos_base_item_set_favorite            (PhotosBaseItem *self, gboolean favorite);
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 7534d24..3c3439c 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -177,7 +177,6 @@ photos_local_item_constructed (GObject *object)
 {
   PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (object);
   GAppInfo *default_app = NULL;
-  const gchar *default_app_name;
   const gchar *mime_type;
 
   G_OBJECT_CLASS (photos_local_item_parent_class)->constructed (object);
@@ -190,9 +189,7 @@ photos_local_item_constructed (GObject *object)
   if (default_app == NULL)
     return;
 
-  default_app_name = g_app_info_get_name (default_app);
-  photos_base_item_set_default_app_name (PHOTOS_BASE_ITEM (self), default_app_name);
-
+  photos_base_item_set_default_app (PHOTOS_BASE_ITEM (self), default_app);
   g_object_unref (default_app);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]