Collections on command line
authorColin Clark <colin.clark@cclark.uk>
Thu, 20 Jul 2017 08:57:57 +0000 (09:57 +0100)
committerColin Clark <colin.clark@cclark.uk>
Thu, 20 Jul 2017 08:57:57 +0000 (09:57 +0100)
In the current implementation, the complete path must be used when
opening a collection from the command line.
This commit permits just the collection name, with or without extension,
to be used.

doc/docbook/GuideReferenceCommandLine.xml
src/main.c

index 0076433..6c22371 100644 (file)
@@ -3,7 +3,9 @@
   <title>Command Line Options</title>\r
   <para>\r
     Geeqie is called by the command:\r
-    <programlisting>geeqie [options] [path_to_file]</programlisting>\r
+    <programlisting>\r
+      geeqie [options] [path_to_file_or_collection] <footnote id='ref1'>The name of a collection, with or without either path or extension (.gqv) may be used. If a path is not used and there is a name conflict with a file or folder, that will take precedence.</footnote>\r
+    </programlisting>\r
   </para>\r
   <para>These are the command line options available to Geeqie:</para>\r
   <table frame="all">\r
index 5f8c81e..97246f7 100644 (file)
@@ -214,6 +214,32 @@ static void parse_command_line_process_file(const gchar *file_path, gchar **path
        parse_command_line_add_file(file_path, path, file, list, collection_list);
 }
 
+static gboolean is_collection(gchar *cmd_param)
+{
+       gchar *path = NULL;
+       gchar *full_name = NULL;
+       gboolean result = FALSE;
+
+       if (file_extension_match(cmd_param, GQ_COLLECTION_EXT))
+               {
+               path = g_build_filename(get_collections_dir(), cmd_param, NULL);
+               }
+       else if (file_extension_match(cmd_param, NULL))
+               {
+               full_name = g_strconcat(cmd_param, GQ_COLLECTION_EXT, NULL);
+               path = g_build_filename(get_collections_dir(), full_name, NULL);
+               }
+
+       if (isfile(path))
+               {
+               result = TRUE;
+               }
+
+       g_free(path);
+       g_free(full_name);
+       return result;
+}
+
 static void parse_command_line(gint argc, gchar *argv[])
 {
        GList *list = NULL;
@@ -256,6 +282,25 @@ static void parse_command_line(gint argc, gchar *argv[])
                                parse_command_line_process_file(cmd_all, &command_line->path, &command_line->file,
                                                                &list, &command_line->collection_list, &first_dir);
                                }
+                       else if (is_collection(cmd_line))
+                               {
+                               gchar *path = NULL;
+                               gchar *full_name = NULL;
+
+                               if (file_extension_match(cmd_line, GQ_COLLECTION_EXT))
+                                       {
+                                       path = g_build_filename(get_collections_dir(), cmd_line, NULL);
+                                       }
+                               else
+                                       {
+                                       full_name = g_strconcat(cmd_line, GQ_COLLECTION_EXT, NULL);
+                                       path = g_build_filename(get_collections_dir(), full_name, NULL);
+                                       }
+                               parse_command_line_process_file(path, &command_line->path, &command_line->file,
+                                                               &list, &command_line->collection_list, &first_dir);
+                               g_free(path);
+                               g_free(full_name);
+                               }
                        else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '='))
                                {
                                /* do nothing but do not produce warnings */