[frogr] Added the possibility to specify a list of pictures to be loaded right after starting frogr frmo the



commit ccd58ae45b2bdfc0e57b20d81fce49c4a6cf526c
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Fri Jan 21 16:13:29 2011 +0100

    Added the possibility to specify a list of pictures to be loaded right
    after starting frogr frmo the command line.

 data/manpages/frogr.1 |    5 ++++
 src/main.c            |   52 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/data/manpages/frogr.1 b/data/manpages/frogr.1
index 54fe9eb..70f5c5f 100644
--- a/data/manpages/frogr.1
+++ b/data/manpages/frogr.1
@@ -19,6 +19,7 @@
 frogr \- a flickr remote organizer for GNOME
 .SH SYNOPSIS
 .B frogr
+.I [PATHS]
 .SH DESCRIPTION
 This manual page documents briefly the
 .B frogr
@@ -29,6 +30,10 @@ is a small application for the GNOME desktop that allows users to
 manage their accounts in the Flickr image hosting website. It supports
 all the basic tasks, including uploading pictures, adding
 descriptions, setting tags and managing sets.
+.SH OPTIONS
+.TP
+.B PATHS
+Full paths for pictures to be loaded along with the application.
 .SH FILES
 .TP
 .I ~/.config/frogr/accounts.xml
diff --git a/src/main.c b/src/main.c
index 565b183..f41f81e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,10 +27,51 @@
 #include <gtk/gtk.h>
 #include <libxml/parser.h>
 
+static GSList *
+_get_paths_list_from_array (char **paths_str, int n_paths)
+{
+  GSList *filepaths = NULL;
+  GError *err = NULL;
+  int i = 0;
+
+  for (i = 0; i < n_paths; i++)
+    {
+      gchar *uri = NULL;
+      gchar *filepath = NULL;
+
+      /* Add the 'file://' schema if not present */
+      if (g_str_has_prefix (paths_str[i], "/"))
+        uri = g_strdup_printf ("file://%s", paths_str[i]);
+      else
+        uri = g_strdup (paths_str[i]);
+
+      filepath = g_filename_from_uri (uri, NULL, &err);
+      if (err)
+        {
+          g_print ("Error loading picture %s: %s\n", uri, err->message);
+          g_error_free (err);
+          err = NULL;
+        }
+      else
+        {
+          filepaths = g_slist_append (filepaths, filepath);
+          g_print ("Arg %d added: '%s'\n", i, filepath);
+        }
+      g_free (uri);
+    }
+
+  return filepaths;
+}
+
 int
 main (int argc, char **argv)
 {
   FrogrController *fcontroller = NULL;
+  GSList *filepaths = NULL;
+
+  /* Check optional command line parameters */
+  if (argc > 1)
+    filepaths = _get_paths_list_from_array (&argv[1], argc - 1);
 
   gtk_init (&argc, &argv);
   g_set_application_name(PACKAGE);
@@ -43,10 +84,19 @@ main (int argc, char **argv)
   /* Init libxml2 library */
   xmlInitParser ();
 
-  /* Run app */
+  /* Run app (and load pictures if present) */
   fcontroller = frogr_controller_get_instance ();
+  if (filepaths)
+    frogr_controller_load_pictures (fcontroller, filepaths);
+
   frogr_controller_run_app (fcontroller);
 
+  if (filepaths)
+    {
+      g_slist_foreach (filepaths, (GFunc)g_free, NULL);
+      g_slist_free (filepaths);
+    }
+
   /* cleanup libxml2 library */
   xmlCleanupParser();
 



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