Fix #753: Various cleanups based on gcc warnings
[geeqie.git] / src / main.c
index e53684f..776154e 100644 (file)
@@ -221,6 +221,9 @@ static void parse_command_line(gint argc, gchar *argv[])
        GList *remote_errors = NULL;
        gboolean remote_do = FALSE;
        gchar *first_dir = NULL;
+       gchar *app_lock;
+       gchar *pwd;
+       gchar *current_dir;
 
        command_line = g_new0(CommandLine, 1);
 
@@ -256,6 +259,9 @@ 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 (download_web_file(cmd_line, FALSE, NULL))
+                               {
+                               }
                        else if (is_collection(cmd_line))
                                {
                                gchar *path = NULL;
@@ -332,6 +338,14 @@ static void parse_command_line(gint argc, gchar *argv[])
                                {
                                set_regexp(g_strdup(cmd_line+3));
                                }
+                       else if (strncmp(cmd_line, "-n", 2) == 0)
+                               {
+                               command_line->new_instance = TRUE;
+                               }
+                       else if (strncmp(cmd_line, "--new-instance", 14) == 0)
+                               {
+                               command_line->new_instance = TRUE;
+                               }
                        else if (strcmp(cmd_line, "-rh") == 0 ||
                                 strcmp(cmd_line, "--remote-help") == 0)
                                {
@@ -345,7 +359,7 @@ static void parse_command_line(gint argc, gchar *argv[])
                        else if (strcmp(cmd_line, "-v") == 0 ||
                                 strcmp(cmd_line, "--version") == 0)
                                {
-                               printf_term("%s %s\n", GQ_APPNAME, VERSION);
+                               printf_term(FALSE, "%s %s\n", GQ_APPNAME, VERSION);
                                exit(0);
                                }
                        else if (strcmp(cmd_line, "--alternate") == 0)
@@ -357,31 +371,32 @@ static void parse_command_line(gint argc, gchar *argv[])
                        else if (strcmp(cmd_line, "-h") == 0 ||
                                 strcmp(cmd_line, "--help") == 0)
                                {
-                               printf_term("%s %s\n", GQ_APPNAME, VERSION);
-                               printf_term(_("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
-                               print_term(_("valid options are:\n"));
-                               print_term(_("  +t, --with-tools                 force show of tools\n"));
-                               print_term(_("  -t, --without-tools              force hide of tools\n"));
-                               print_term(_("  -f, --fullscreen                 start in full screen mode\n"));
-                               print_term(_("  -s, --slideshow                  start in slideshow mode\n"));
-                               print_term(_("  -l, --list [files] [collections] open collection window for command line\n"));
-                               print_term(_("      --blank                      start with blank file list\n"));
-                               print_term(_("      --geometry=XxY+XOFF+YOFF     set main window location\n"));
-                               print_term(_("  -r, --remote                     send following commands to open window\n"));
-                               print_term(_("  -rh,--remote-help                print remote command list\n"));
+                               printf_term(FALSE, "%s %s\n", GQ_APPNAME, VERSION);
+                               printf_term(FALSE, _("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
+                               print_term(FALSE, _("valid options are:\n"));
+                               print_term(FALSE, _("  +t, --with-tools                 force show of tools\n"));
+                               print_term(FALSE, _("  -t, --without-tools              force hide of tools\n"));
+                               print_term(FALSE, _("  -f, --fullscreen                 start in full screen mode\n"));
+                               print_term(FALSE, _("  -s, --slideshow                  start in slideshow mode\n"));
+                               print_term(FALSE, _("  -l, --list [files] [collections] open collection window for command line\n"));
+                               print_term(FALSE, _("      --blank                      start with blank file list\n"));
+                               print_term(FALSE, _("      --geometry=XxY+XOFF+YOFF     set main window location\n"));
+                               print_term(FALSE, _("  -n, --new-instance               open a new instance of Geeqie\n"));
+                               print_term(FALSE, _("  -r, --remote                     send following commands to open window\n"));
+                               print_term(FALSE, _("  -rh,--remote-help                print remote command list\n"));
 #ifdef DEBUG
-                               print_term(_("      --debug[=level]              turn on debug output\n"));
-                               print_term(_("  -g:<regexp>, --grep:<regexp>     filter debug output\n"));
+                               print_term(FALSE, _("      --debug[=level]              turn on debug output\n"));
+                               print_term(FALSE, _("  -g:<regexp>, --grep:<regexp>     filter debug output\n"));
 #endif
-                               print_term(_("  +w, --show-log-window            show log window\n"));
-                               print_term(_("  -o:<file>, --log-file:<file>     save log data to file\n"));
-                               print_term(_("  -v, --version                    print version info\n"));
-                               print_term(_("  -h, --help                       show this message\n\n"));
+                               print_term(FALSE, _("  +w, --show-log-window            show log window\n"));
+                               print_term(FALSE, _("  -o:<file>, --log-file:<file>     save log data to file\n"));
+                               print_term(FALSE, _("  -v, --version                    print version info\n"));
+                               print_term(FALSE, _("  -h, --help                       show this message\n\n"));
 
 #if 0
                                /* these options are not officially supported!
                                 * only for testing new features, no need to translate them */
-                               print_term(  "  --alternate                use alternate similarity algorithm\n");
+                               print_term(FALSE, "  --alternate                use alternate similarity algorithm\n");
 #endif
 
 
@@ -389,7 +404,7 @@ static void parse_command_line(gint argc, gchar *argv[])
                                }
                        else if (!remote_do)
                                {
-                               printf_term(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
+                               printf_term(TRUE, _("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
                                }
 
                        g_free(cmd_all);
@@ -412,25 +427,48 @@ static void parse_command_line(gint argc, gchar *argv[])
                }
        g_free(first_dir);
 
+       if (!command_line->new_instance)
+               {
+               /* If Geeqie is already running, prevent a second instance
+                * from being started. Open a new window instead.
+                */
+               app_lock = g_build_filename(get_rc_dir(), ".command", NULL);
+               if (remote_server_exists(app_lock) && !remote_do)
+                       {
+                       remote_do = TRUE;
+                       remote_list = g_list_append(remote_list, "--new-window");
+               }
+               g_free(app_lock);
+               }
+
        if (remote_do)
                {
                if (remote_errors)
                        {
                        GList *work = remote_errors;
 
-                       printf_term(_("Invalid or ignored remote options: "));
+                       printf_term(TRUE,_("Invalid or ignored remote options: "));
                        while (work)
                                {
                                gchar *opt = work->data;
 
-                               printf_term("%s%s", (work == remote_errors) ? "" : ", ", opt);
+                               printf_term(TRUE, "%s%s", (work == remote_errors) ? "" : ", ", opt);
                                work = work->next;
                                }
 
-                       printf_term(_("\nUse --remote-help for valid remote options.\n"));
+                       printf_term(TRUE, _("\nUse --remote-help for valid remote options.\n"));
                        }
 
+               /* prepend the current dir the remote command was made from,
+                * for use by any remote command that needs it
+                */
+               current_dir = g_get_current_dir();
+               pwd = g_strconcat("--PWD:", current_dir, NULL);
+               remote_list = g_list_prepend(remote_list, pwd);
+
                remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list);
+               g_free(pwd);
+               g_free(current_dir);
                }
        g_list_free(remote_list);
 
@@ -498,6 +536,7 @@ static void parse_command_line_for_debug_option(gint argc, gchar *argv[])
  */
 
 #define RC_HISTORY_NAME "history"
+#define RC_MARKS_NAME "marks"
 
 static void setup_env_path(void)
 {
@@ -525,6 +564,24 @@ static void keys_save(void)
        g_free(path);
 }
 
+static void marks_load(void)
+{
+       gchar *path;
+
+       path = g_build_filename(get_rc_dir(), RC_MARKS_NAME, NULL);
+       marks_list_load(path);
+       g_free(path);
+}
+
+static void marks_save(gboolean save)
+{
+       gchar *path;
+
+       path = g_build_filename(get_rc_dir(), RC_MARKS_NAME, NULL);
+       marks_list_save(path, save);
+       g_free(path);
+}
+
 static void mkdir_if_not_exists(const gchar *path)
 {
        if (isdir(path)) return;
@@ -741,6 +798,8 @@ void exit_program(void)
 
        if (metadata_write_queue_confirm(FALSE, exit_program_write_metadata_cb, NULL)) return;
 
+       options->marks_save ? marks_save(TRUE) : marks_save(FALSE);
+
        if (exit_confirm_dlg()) return;
 
        exit_program_final();
@@ -863,6 +922,7 @@ gint main(gint argc, gchar *argv[])
        mkdir_if_not_exists(get_collections_dir());
        mkdir_if_not_exists(get_thumbnails_cache_dir());
        mkdir_if_not_exists(get_metadata_cache_dir());
+       mkdir_if_not_exists(get_window_layouts_dir());
 
        setup_env_path();
 
@@ -975,6 +1035,8 @@ gint main(gint argc, gchar *argv[])
        remote_connection = remote_server_init(buf, cd);
        g_free(buf);
 
+       marks_load();
+
        DEBUG_1("%s main: gtk_main", get_exec_time());
        gtk_main();
 #ifdef HAVE_GTHREAD