Fix #1184: Put main menu items into one hamburger menu
[geeqie.git] / src / main.cc
index 4c29e17..69881d0 100644 (file)
@@ -76,7 +76,7 @@ gchar *desktop_file_template;
 gchar *instance_identifier;
 
 #if defined(SA_SIGINFO)
-void sig_handler_cb(int signo, siginfo_t *info, void *UNUSED(context))
+void sig_handler_cb(int signo, siginfo_t *info, void *)
 {
        gchar hex_char[16];
        const gchar *signal_name = nullptr;
@@ -175,10 +175,13 @@ void sig_handler_cb(int signo, siginfo_t *info, void *UNUSED(context))
        backtrace_symbols_fd(bt, bt_size, STDERR_FILENO);
 #endif
 
+       /* Avoid "not used" warning */
+       len++;
+
        exit(EXIT_FAILURE);
 }
 #else /* defined(SA_SIGINFO) */
-void sig_handler_cb(int UNUSED(signo))
+void sig_handler_cb(int)
 {
 #ifdef HAVE_EXECINFO_H
        gint bt_size;
@@ -270,8 +273,7 @@ static void parse_command_line_add_file(const gchar *file_path, gchar **path, gc
                }
 }
 
-static void parse_command_line_add_dir(const gchar *dir, gchar **UNUSED(path), gchar **UNUSED(file),
-                                      GList **UNUSED(list))
+static void parse_command_line_add_dir(const gchar *dir, gchar **, gchar **, GList **)
 {
 #if 0
        /* This is broken because file filter is not initialized yet.
@@ -501,12 +503,6 @@ static void parse_command_line(gint argc, gchar *argv[])
                                printf_term(FALSE, "%s %s GTK%d\n", GQ_APPNAME, VERSION, gtk_major_version);
                                exit(0);
                                }
-                       else if (strcmp(cmd_line, "--alternate") == 0)
-                               {
-                               /* enable faster experimental algorithm */
-                               log_printf("Alternate similarity algorithm enabled\n");
-                               image_sim_alternate_set(TRUE);
-                               }
                        else if (strcmp(cmd_line, "-h") == 0 ||
                                 strcmp(cmd_line, "--help") == 0)
                                {
@@ -520,8 +516,8 @@ static void parse_command_line(gint argc, gchar *argv[])
                                print_term(FALSE, _("      --geometry=WxH+XOFF+YOFF     set main window location\n"));
                                print_term(FALSE, _("  -h, --help                       show this message\n"));
                                print_term(FALSE, _("  -l, --list [files] [collections] open collection window for command line\n"));
-                               print_term(FALSE, _("  -n, --new-instance               open a new instance of Geeqie\n"));
-                               print_term(FALSE, _("  -o:, --log-file:<file>     save log data to file\n"));
+                               print_term(FALSE, _("  -n, --new-instance               open a new instance of Geeqie *\n"));
+                               print_term(FALSE, _("  -o:, --log-file:<file>           save log data to file\n"));
                                print_term(FALSE, _("  -r, --remote                     send following commands to open window\n"));
                                print_term(FALSE, _("  -rh, --remote-help               print remote command list\n"));
                                print_term(FALSE, _("  -s, --slideshow                  start in slideshow mode\n"));
@@ -531,15 +527,11 @@ static void parse_command_line(gint argc, gchar *argv[])
                                print_term(FALSE, _("  +w, --show-log-window            show log window\n"));
 #ifdef DEBUG
                                print_term(FALSE, _("      --debug[=level]              turn on debug output\n"));
-                               print_term(FALSE, _("  -g:, --grep:<regexp>     filter debug output\n"));
+                               print_term(FALSE, _("  -g:, --grep:<regexp>             filter debug output\n"));
 #endif
 
-#if 0
-                               /* these options are not officially supported!
-                                * only for testing new features, no need to translate them */
-                               print_term(FALSE, "  --alternate                use alternate similarity algorithm\n");
-#endif
                                print_term(FALSE, "\n");
+                               print_term(FALSE, "* Normally a single set of configuration files is used for all instances.\nHowever, the environment variables XDG_CONFIG_HOME, XDG_CACHE_HOME, XDG_DATA_HOME\ncan be used to modify this behavior on an individual basis e.g.\n\nXDG_CONFIG_HOME=/tmp/a XDG_CACHE_HOME=/tmp/b geeqie\n\n");
 
                                remote_help();
 
@@ -562,9 +554,9 @@ static void parse_command_line(gint argc, gchar *argv[])
                        dialog_warning = gtk_message_dialog_new(nullptr, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", "Invalid parameter(s):");
                        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog_warning), "%s", command_line_errors->str);
                        gtk_window_set_title(GTK_WINDOW(dialog_warning), GQ_APPNAME);
-                       gtk_window_set_keep_above(GTK_WINDOW(dialog_warning), TRUE);
+                       gq_gtk_window_set_keep_above(GTK_WINDOW(dialog_warning), TRUE);
                        gtk_dialog_run(GTK_DIALOG(dialog_warning));
-                       gtk_widget_destroy(dialog_warning);
+                       g_object_unref(dialog_warning);
                        g_string_free(command_line_errors, TRUE);
 
                        exit(EXIT_FAILURE);
@@ -623,9 +615,9 @@ static void parse_command_line(gint argc, gchar *argv[])
                        dialog_warning = gtk_message_dialog_new(nullptr, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", "Invalid parameter(s):");
                        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog_warning), "%s", command_line_errors->str);
                        gtk_window_set_title(GTK_WINDOW(dialog_warning), GQ_APPNAME);
-                       gtk_window_set_keep_above(GTK_WINDOW(dialog_warning), TRUE);
+                       gq_gtk_window_set_keep_above(GTK_WINDOW(dialog_warning), TRUE);
                        gtk_dialog_run(GTK_DIALOG(dialog_warning));
-                       gtk_widget_destroy(dialog_warning);
+                       g_object_unref(dialog_warning);
                        g_string_free(command_line_errors, TRUE);
 
                        exit(EXIT_FAILURE);
@@ -653,7 +645,7 @@ static void parse_command_line(gint argc, gchar *argv[])
                }
        else
                {
-               string_list_free(list);
+               g_list_free_full(list, g_free);
                command_line->cmd_list = nullptr;
                }
 
@@ -665,7 +657,7 @@ static void parse_command_line(gint argc, gchar *argv[])
                command_line->file = nullptr;
                filelist_free(command_line->cmd_list);
                command_line->cmd_list = nullptr;
-               string_list_free(command_line->collection_list);
+               g_list_free_full(command_line->collection_list, g_free);
                command_line->collection_list = nullptr;
                }
 }
@@ -1066,13 +1058,13 @@ static void exit_program_final()
 
 static GenericDialog *exit_dialog = nullptr;
 
-static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer UNUSED(data))
+static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer)
 {
        exit_dialog = nullptr;
        generic_dialog_close(gd);
 }
 
-static void exit_confirm_exit_cb(GenericDialog *gd, gpointer UNUSED(data))
+static void exit_confirm_exit_cb(GenericDialog *gd, gpointer)
 {
        exit_dialog = nullptr;
        generic_dialog_close(gd);
@@ -1084,6 +1076,7 @@ static gint exit_confirm_dlg()
        GtkWidget *parent;
        LayoutWindow *lw;
        gchar *msg;
+       GString *message;
 
        if (exit_dialog)
                {
@@ -1091,7 +1084,7 @@ static gint exit_confirm_dlg()
                return TRUE;
                }
 
-       if (!collection_window_modified_exists()) return FALSE;
+       if (!collection_window_modified_exists() && (layout_window_count() == 1)) return FALSE;
 
        parent = nullptr;
        lw = nullptr;
@@ -1106,17 +1099,33 @@ static gint exit_confirm_dlg()
                                exit_confirm_cancel_cb, nullptr);
        g_free(msg);
        msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME);
-       generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION,
-                                  msg, _("Collections have been modified. Quit anyway?"), TRUE);
+
+       message = g_string_new(NULL);
+
+       if (collection_window_modified_exists())
+               {
+               message = g_string_append(message, _("Collections have been modified.\n"));
+               }
+
+       if (layout_window_count() > 1)
+               {
+               g_string_append_printf(message, _("%d windows are open.\n\n"), layout_window_count());
+               }
+
+       message = g_string_append(message, _("Quit anyway?"));
+
+       generic_dialog_add_message(exit_dialog, GQ_ICON_DIALOG_QUESTION, msg, message->str, TRUE);
        g_free(msg);
-       generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, nullptr, exit_confirm_exit_cb, TRUE);
+       generic_dialog_add_button(exit_dialog, GQ_ICON_QUIT, _("Quit"), exit_confirm_exit_cb, TRUE);
 
        gtk_widget_show(exit_dialog->dialog);
 
+       g_string_free(message, TRUE);
+
        return TRUE;
 }
 
-static void exit_program_write_metadata_cb(gint success, const gchar *UNUSED(dest_path), gpointer UNUSED(data))
+static void exit_program_write_metadata_cb(gint success, const gchar *, gpointer)
 {
        if (success) exit_program();
 }
@@ -1147,9 +1156,12 @@ void exit_program()
  * an alternative approach.
  */
 /** @FIXME this probably needs some better ifdefs. Please report any compilation problems */
+/** @FIXME This section needs revising */
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
 #if defined(SIGBUS) && defined(SA_SIGINFO)
-static void sigbus_handler_cb(int UNUSED(signum), siginfo_t *info, void *UNUSED(context))
+static void sigbus_handler_cb_unused(int, siginfo_t *info, void *)
 {
        /*
         * @FIXME Design and implement a POSIX-acceptable approach,
@@ -1162,18 +1174,20 @@ static void sigbus_handler_cb(int UNUSED(signum), siginfo_t *info, void *UNUSED(
 }
 #endif
 
-//static void setup_sigbus_handler(void)
-//{
-//#if defined(SIGBUS) && defined(SA_SIGINFO)
-       //struct sigaction sigbus_action;
-       //sigfillset(&sigbus_action.sa_mask);
-       //sigbus_action.sa_sigaction = sigbus_handler_cb;
-       //sigbus_action.sa_flags = SA_SIGINFO;
+static void setup_sigbus_handler_unused(void)
+{
+#if defined(SIGBUS) && defined(SA_SIGINFO)
+       struct sigaction sigbus_action;
+       sigfillset(&sigbus_action.sa_mask);
+       sigbus_action.sa_sigaction = sigbus_handler_cb_unused;
+       sigbus_action.sa_flags = SA_SIGINFO;
 
-       //sigaction(SIGBUS, &sigbus_action, NULL);
-//#endif
-//}
+       sigaction(SIGBUS, &sigbus_action, NULL);
+#endif
+}
+#pragma GCC diagnostic pop
 
+#ifndef HAVE_DEVELOPER
 static void setup_sig_handler()
 {
        struct sigaction sigsegv_action;
@@ -1188,11 +1202,12 @@ static void setup_sig_handler()
        sigaction(SIGIOT, &sigsegv_action, nullptr);
        sigaction(SIGSEGV, &sigsegv_action, nullptr);
 }
+#endif
 
 static void set_theme_bg_color()
 {
        GdkRGBA bg_color;
-       GdkColor theme_color;
+       GdkRGBA theme_color;
        GtkStyleContext *style_context;
        GList *work;
        LayoutWindow *lw;
@@ -1205,9 +1220,9 @@ static void set_theme_bg_color()
                style_context = gtk_widget_get_style_context(lw->window);
                gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
 
-               theme_color.red = bg_color.red * 65535;
-               theme_color.green = bg_color.green * 65535;
-               theme_color.blue = bg_color.blue * 65535;
+               theme_color.red = bg_color.red  ;
+               theme_color.green = bg_color.green  ;
+               theme_color.blue = bg_color.blue ;
 
                while (work)
                        {
@@ -1220,7 +1235,7 @@ static void set_theme_bg_color()
        view_window_colors_update();
 }
 
-static gboolean theme_change_cb(GObject *UNUSED(gobject), GParamSpec *UNUSED(pspec), gpointer UNUSED(data))
+static gboolean theme_change_cb(GObject *, GParamSpec *, gpointer)
 {
        set_theme_bg_color();
 
@@ -1256,7 +1271,7 @@ static void create_application_paths()
        gq_htmldir = g_build_filename(gq_prefix, GQ_HTMLDIR, NULL);
        gq_appdir = g_build_filename(gq_prefix, GQ_APPDIR, NULL);
        gq_bindir = g_build_filename(gq_prefix, GQ_BINDIR, NULL);
-       desktop_file_template = g_build_filename(gq_appdir, "template.desktop", NULL);
+       desktop_file_template = g_build_filename(gq_appdir, "org.geeqie.template.desktop", NULL);
 
        g_free(dirname);
        g_free(path);
@@ -1264,13 +1279,15 @@ static void create_application_paths()
 
 gint main(gint argc, gchar *argv[])
 {
-       CollectionData *first_collection = nullptr;
-       gchar *buf;
        CollectionData *cd = nullptr;
+       CollectionData *first_collection = nullptr;
        gboolean disable_clutter = FALSE;
        gboolean single_dir = TRUE;
-       LayoutWindow *lw;
+       gchar *buf;
+       GdkScreen *screen;
+       GtkCssProvider *provider;
        GtkSettings *default_settings;
+       LayoutWindow *lw;
 
        gdk_set_allowed_backends("x11,*");
 
@@ -1378,6 +1395,11 @@ gint main(gint argc, gchar *argv[])
 
        setup_env_path();
 
+       screen = gdk_screen_get_default();
+       provider = gtk_css_provider_new();
+       gtk_css_provider_load_from_resource(provider, GQ_RESOURCE_PATH_UI "/custom.css");
+       gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
        if (parse_command_line_for_cache_maintenance_option(argc, argv))
                {
                process_command_line_for_cache_maintenance_option(argc, argv);
@@ -1573,9 +1595,17 @@ gint main(gint argc, gchar *argv[])
                }
 
        /* Show a fade-out notification window if the server has a newer AppImage version */
-       if (options->appimage_notifications && g_getenv("APPDIR") && strstr(g_getenv("APPDIR"), "/tmp/.mount_Geeqie"))
+       if (options->appimage_notifications)
                {
-               appimage_notification();
+               if (g_getenv("APPDIR") && strstr(g_getenv("APPDIR"), "/tmp/.mount_Geeqie"))
+                       {
+                       appimage_notification();
+                       }
+               else if (g_strstr_len(gq_executable_path, -1, "AppRun"))
+                       {
+                       /* Probably running an extracted AppImage */
+                       appimage_notification();
+                       }
                }
 
        DEBUG_1("%s main: gtk_main", get_exec_time());