[frogr] Fix issues opening multiple images in the default viewer from frogr.



commit 76d7749c14202aa5892e9dc8e3d52614fd700a3f
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Fri Jul 8 14:51:59 2011 +0200

    Fix issues opening multiple images in the default viewer from frogr.
    
    Renamed frogr_util_open_multiple_uris into frogr_util_open_images_in_viewer.

 src/frogr-main-view.c |   22 ++++++++++----------
 src/frogr-util.c      |   54 ++++++++++++++++++++++++++++++++++++++++--------
 src/frogr-util.h      |    2 +-
 3 files changed, 57 insertions(+), 21 deletions(-)
---
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 3e720fd..b1678f6 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -984,25 +984,25 @@ _edit_selected_pictures (FrogrMainView *self)
 static void
 _open_pictures_in_external_viewer (FrogrMainView *self)
 {
-  gchar *uris = NULL;
-  GSList *pictures, *current_pic;
+  GSList *pictures = NULL;
+  GSList *current_pic = NULL;
+  GList *uris_list = NULL;
 
   if (!_pictures_selected_required_check (self))
     return;
 
-  pictures = current_pic = _get_selected_pictures (self);
-  while (current_pic)
+  pictures = _get_selected_pictures (self);
+  for (current_pic = pictures; current_pic; current_pic = g_slist_next (current_pic))
     {
       FrogrPicture *picture = FROGR_PICTURE (current_pic->data);
-      gchar *current_uris = uris;
-      uris = g_strconcat (frogr_picture_get_fileuri (picture), " ", current_uris, NULL);
-      g_free (current_uris);
-      current_pic = g_slist_next (current_pic);
+      uris_list = g_list_append (uris_list, (gchar*) frogr_picture_get_fileuri (picture));
     }
   g_slist_foreach (pictures, (GFunc) g_object_unref, NULL);
   g_slist_free (pictures);
-  frogr_util_open_multiple_uris (uris);
-  g_free (uris);
+
+  frogr_util_open_images_in_viewer (uris_list);
+
+  g_list_free (uris_list);
 }
 
 static void
@@ -1440,7 +1440,7 @@ _update_sensitiveness (FrogrMainView *self)
       gtk_widget_set_sensitive (priv->accounts_menu_item, has_accounts);
       gtk_action_set_sensitive (priv->upload_pictures_action, has_pics);
       gtk_action_set_sensitive (priv->remove_pictures_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->open_in_external_viewer_action, n_selected_pics == 1);
+      gtk_action_set_sensitive (priv->open_in_external_viewer_action, n_selected_pics > 0);
       gtk_action_set_sensitive (priv->add_tags_action, n_selected_pics > 0);
       gtk_action_set_sensitive (priv->edit_details_action, n_selected_pics > 0);
       gtk_action_set_sensitive (priv->add_to_group_action, n_selected_pics > 0);
diff --git a/src/frogr-util.c b/src/frogr-util.c
index 11afd0d..e447458 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -137,24 +137,60 @@ frogr_util_open_uri (const gchar *url)
     }
 }
 
+gchar *
+_get_uris_string_from_list (GList *uris_list)
+{
+  GList *current_uri = NULL;
+  gchar **uris_array = NULL;
+  gchar *uris_str = NULL;
+  gint n_uris = 0;
+  gint i = 0;
+
+  n_uris = g_list_length (uris_list);
+  if (n_uris == 0)
+    return NULL;
+
+  uris_array = g_new0 (gchar*, n_uris + 1);
+  for (current_uri = uris_list; current_uri; current_uri = g_list_next (current_uri))
+    uris_array[i++] = (gchar *) (current_uri->data);
+
+  uris_str = g_strjoinv (" ", uris_array);
+  g_strfreev (uris_array);
+
+  return uris_str;
+}
+
 void
-frogr_util_open_multiple_uris (const gchar *uris)
+frogr_util_open_images_in_viewer (GList *uris_list)
 {
-  gchar *command = NULL;
+  static GAppInfo *app_info = NULL;
 
   /* Early return */
-  if (uris == NULL)
+  if (uris_list == NULL)
     return;
 
+  if (!app_info)
+    app_info = g_app_info_get_default_for_type ("image/jpg", TRUE);
+
+  if (!g_app_info_launch_uris (app_info, uris_list, NULL, NULL))
+    {
+      gchar *command = NULL;
+      gchar *uris = NULL;
+
+      /* The default app didn't succeed, so try 'gnome-open' */
+      uris = _get_uris_string_from_list (uris_list);
+
 #ifdef MAC_INTEGRATION
-  /* In MacOSX neither gnome-open nor gtk_show_uri() will work */
-  command = g_strdup_printf ("open %s", uris);
+      /* In MacOSX neither gnome-open nor gtk_show_uri() will work */
+      command = g_strdup_printf ("open %s", uris);
 #else
-  command = g_strdup_printf ("gnome-open %s", uris);
-#endif /* ifdef MAC_INTEGRATION */
+      command = g_strdup_printf ("gnome-open %s", uris);
+#endif
+      _spawn_command (command);
 
-  _spawn_command (command);
-  g_free (command);
+      g_free (command);
+      g_free (uris);
+    }
 }
 
 static void
diff --git a/src/frogr-util.h b/src/frogr-util.h
index 29afeaf..a6f6ad2 100644
--- a/src/frogr-util.h
+++ b/src/frogr-util.h
@@ -31,7 +31,7 @@ const gchar *frogr_util_get_locale_dir (void);
 
 void frogr_util_open_uri (const gchar *url);
 
-void frogr_util_open_multiple_uris (const gchar *uris);
+void frogr_util_open_images_in_viewer (GList *uris_list);
 
 void frogr_util_show_info_dialog (GtkWindow *parent, const gchar *message);
 



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