Documentation: Use G_SOURCE_CONTINUE and G_SOURCE_REMOVE
[geeqie.git] / src / preferences.cc
index bc801aa..bce3d50 100644 (file)
 
 #include "bar-keywords.h"
 #include "cache.h"
+//~ #include "authors.h"
+//~ #include "authors.c"
+//~ #include "translators.h"
+//~ #include "translators.c"
 #include "editors.h"
 #include "filedata.h"
 #include "filefilter.h"
@@ -669,7 +673,7 @@ static void add_quality_menu(GtkWidget *table, gint column, gint row, const gcha
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(quality_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -696,7 +700,7 @@ static void add_dnd_default_action_selection_menu(GtkWidget *table, gint column,
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(dnd_default_action_selection_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -724,7 +728,7 @@ static void add_clipboard_selection_menu(GtkWidget *table, gint column, gint row
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(clipboard_selection_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -765,7 +769,7 @@ static void add_zoom_style_selection_menu(GtkWidget *table, gint column, gint ro
 
        g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(zoom_style_selection_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -905,7 +909,7 @@ static void add_mouse_selection_menu(GtkWidget *table, gint column, gint row, co
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(mouse_buttons_selection_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -972,7 +976,7 @@ static void add_thumb_size_menu(GtkWidget *table, gint column, gint row, gchar *
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(thumb_size_menu_cb), NULL);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -1091,7 +1095,7 @@ static void add_stereo_mode_menu(GtkWidget *table, gint column, gint row, const
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(stereo_mode_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -1132,7 +1136,7 @@ static void add_video_menu(GtkWidget *table, gint column, gint row, const gchar
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(video_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 
@@ -1198,7 +1202,7 @@ static void filter_store_class_edit_cb(GtkCellRendererText *UNUSED(cell), gchar
                {
                if (strcmp(new_text, _(format_class_list[i])) == 0)
                        {
-                       fe->file_class = i;
+                       fe->file_class = static_cast<FileFormatClass>(i);
                        break;
                        }
                }
@@ -1363,7 +1367,7 @@ static gboolean filter_add_scroll(gpointer data)
        gtk_tree_path_free(path);
        g_list_free(list_cells);
 
-       return(FALSE);
+       return(G_SOURCE_REMOVE);
 }
 
 static void filter_add_cb(GtkWidget *UNUSED(widget), gpointer data)
@@ -1408,7 +1412,7 @@ static gboolean filter_default_ok_scroll(GtkTreeView *data)
 
        gtk_tree_path_free(path);
 
-       return(FALSE);
+       return(G_SOURCE_REMOVE);
 }
 
 static void filter_default_ok_cb(GenericDialog *gd, gpointer UNUSED(data))
@@ -1729,7 +1733,7 @@ static gboolean accel_default_scroll(GtkTreeView *data)
 
        gtk_tree_path_free(path);
 
-       return(FALSE);
+       return(G_SOURCE_REMOVE);
 }
 
 static void accel_default_cb(GtkWidget *UNUSED(widget), gpointer data)
@@ -1739,10 +1743,10 @@ static void accel_default_cb(GtkWidget *UNUSED(widget), gpointer data)
        g_idle_add((GSourceFunc)accel_default_scroll, data);
 }
 
-//void accel_remove_selection(GtkTreeModel *UNUSED(model), GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer UNUSED(data))
-//{
-       //gtk_tree_store_set(accel_store, iter, AE_KEY, "", -1);
-//}
+void accel_clear_selection(GtkTreeModel *UNUSED(model), GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer UNUSED(data))
+{
+       gtk_tree_store_set(accel_store, iter, AE_KEY, "", -1);
+}
 
 void accel_reset_selection(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer UNUSED(data))
 {
@@ -1760,6 +1764,15 @@ void accel_reset_selection(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTr
        g_free(accel);
 }
 
+static void accel_clear_cb(GtkWidget *UNUSED(widget), gpointer data)
+{
+       GtkTreeSelection *selection;
+
+       if (!accel_store) return;
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data));
+       gtk_tree_selection_selected_foreach(selection, &accel_clear_selection, NULL);
+}
+
 static void accel_reset_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
        GtkTreeSelection *selection;
@@ -1901,7 +1914,7 @@ static guint star_rating_symbol_test(GtkWidget *UNUSED(widget), gpointer data)
                hex_value = 0x003F; // Unicode 'Question Mark'
                }
        str = g_string_append_unichar(str, (gunichar)hex_value);
-       gtk_label_set_text(g_list_nth_data(list, 1), str->str);
+       gtk_label_set_text(static_cast<GtkLabel *>(g_list_nth_data(list, 1)), str->str);
 
        g_strfreev(hex_code);
        g_string_free(str, TRUE);
@@ -3086,7 +3099,7 @@ static gboolean keywords_find_file(gpointer data)
                while (keywords)
                        {
                        gtk_text_buffer_get_end_iter(buffer, &iter);
-                       tmp = g_strconcat(keywords->data, "\n", NULL);
+                       tmp = g_strconcat(static_cast<const gchar *>(keywords->data), "\n", NULL);
                        gtk_text_buffer_insert(buffer, &iter, tmp, -1);
                        g_free(tmp);
                        keywords = keywords->next;
@@ -3096,7 +3109,7 @@ static gboolean keywords_find_file(gpointer data)
                file_data_unref(fd);
                string_list_free(keywords);
 
-               return (TRUE);
+               return (G_SOURCE_CONTINUE);
                }
        else if (kfd->list_dir)
                {
@@ -3109,12 +3122,12 @@ static gboolean keywords_find_file(gpointer data)
 
                file_data_unref(fd);
 
-               return TRUE;
+               return G_SOURCE_CONTINUE;
                }
 
        keywords_find_finish(kfd);
 
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static void keywords_find_start_cb(GenericDialog *UNUSED(fd), gpointer data)
@@ -3239,7 +3252,7 @@ static void config_tab_keywords_save()
                found = FALSE;
                while (work)
                        {
-                       if (g_strcmp0(work->data, kw_split) == 0)
+                       if (g_strcmp0(static_cast<const gchar *>(work->data), kw_split) == 0)
                                {
                                found = TRUE;
                                break;
@@ -3319,7 +3332,7 @@ static void config_tab_keywords(GtkWidget *notebook)
        while (kwl)
        {
                gtk_text_buffer_get_end_iter (buffer, &iter);
-           tmp = g_strconcat(kwl->data, "\n", NULL);
+           tmp = g_strconcat(static_cast<const gchar *>(kwl->data), "\n", NULL);
                gtk_text_buffer_insert(buffer, &iter, tmp, -1);
                kwl = kwl->next;
                g_free(tmp);
@@ -3382,7 +3395,7 @@ static void add_intent_menu(GtkWidget *table, gint column, gint row, const gchar
        g_signal_connect(G_OBJECT(combo), "changed",
                         G_CALLBACK(intent_menu_cb), option_c);
 
-       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, static_cast<GtkAttachOptions>(0), 0, 0);
        gtk_widget_show(combo);
 }
 #endif
@@ -3431,7 +3444,7 @@ static void config_tab_color(GtkWidget *notebook)
                        gtk_entry_set_text(GTK_ENTRY(entry), options->color_profile.input_name[i]);
                        }
                gtk_table_attach(GTK_TABLE(table), entry, 1, 2, i + 1, i + 2,
-                                GTK_FILL | GTK_EXPAND, 0, 0, 0);
+                                static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), static_cast<GtkAttachOptions>(0), 0, 0);
                gtk_widget_show(entry);
                color_profile_input_name_entry[i] = entry;
 
@@ -3439,7 +3452,7 @@ static void config_tab_color(GtkWidget *notebook)
                tab_completion_add_select_button(entry, _("Select color profile"), FALSE);
                gtk_widget_set_size_request(entry, 160, -1);
                gtk_table_attach(GTK_TABLE(table), tabcomp, 2, 3, i + 1, i + 2,
-                                GTK_FILL | GTK_EXPAND, 0, 0, 0);
+                                static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), static_cast<GtkAttachOptions>(0), 0, 0);
                gtk_widget_show(tabcomp);
                color_profile_input_file_entry[i] = entry;
                }
@@ -3463,7 +3476,7 @@ static void config_tab_color(GtkWidget *notebook)
 #endif
        gtk_table_attach(GTK_TABLE(table), tabcomp, 1, 2,
                         0, 1,
-                        GTK_FILL | GTK_EXPAND, 0, 0, 0);
+                        static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), static_cast<GtkAttachOptions>(0), 0, 0);
 
        gtk_widget_show(tabcomp);
 }
@@ -3762,6 +3775,12 @@ static void config_tab_accelerators(GtkWidget *notebook)
 
        button = pref_button_new(NULL, NULL, _("Reset selected"), FALSE,
                                 G_CALLBACK(accel_reset_cb), accel_view);
+       gtk_widget_set_tooltip_text(button, _("Will only reset changes made before the settings are saved"));
+       gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+       gtk_widget_show(button);
+
+       button = pref_button_new(NULL, NULL, _("Clear selected"), FALSE,
+                                G_CALLBACK(accel_clear_cb), accel_view);
        gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
 }
@@ -4092,18 +4111,27 @@ void show_config_window(LayoutWindow *lw)
 
 void show_about_window(LayoutWindow *lw)
 {
-       GdkPixbuf *pixbuf_logo;
+       GDataInputStream *data_stream;
+       GInputStream *in_stream_authors;
+       GInputStream *in_stream_translators;
+       GString *copyright;
        GdkPixbuf *pixbuf_icon;
+       GdkPixbuf *pixbuf_logo;
+       ZoneDetect *cd;
+       gchar *artists[2];
+       gchar *author_line;
        gchar *authors[1000];
+       gchar *authors_path;
        gchar *comment;
-       gint i_authors = 0;
-       gchar *path;
-       GString *copyright;
        gchar *timezone_path;
-       ZoneDetect *cd;
-       FILE *fp = NULL;
-#define LINE_LENGTH 1000
-       gchar line[LINE_LENGTH];
+       gchar *translators;
+       gchar *translators_path;
+       gint i_authors = 0;
+       gint n = 0;
+       gsize bytes_read;
+       gsize length;
+       gsize size;
+       guint32 flags;
 
        copyright = g_string_new(NULL);
        copyright = g_string_append(copyright, "This program comes with absolutely no warranty.\nGNU General Public License, version 2 or later.\nSee https://www.gnu.org/licenses/old-licenses/gpl-2.0.html\n\n");
@@ -4124,25 +4152,36 @@ void show_about_window(LayoutWindow *lw)
                }
        g_free(timezone_path);
 
+       authors_path = g_build_filename(GQ_RESOURCE_PATH_CREDITS, "authors", NULL);
+
+       in_stream_authors = g_resources_open_stream(authors_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+
+       data_stream = g_data_input_stream_new(in_stream_authors);
+
        authors[0] = NULL;
-       path = g_build_filename(gq_helpdir, "AUTHORS", NULL);
-       fp = fopen(path, "r");
-       if (fp)
+       while ((author_line = g_data_input_stream_read_line(G_DATA_INPUT_STREAM(data_stream), &length, NULL, NULL)))
                {
-               while(fgets(line, LINE_LENGTH, fp))
-                       {
-                       /* get rid of ending \n from fgets */
-                       line[strlen(line) - 1] = '\0';
-                       authors[i_authors] = g_strdup(line);
-                       i_authors++;
-                       }
-               authors[i_authors] = NULL;
-               fclose(fp);
+               authors[i_authors] = g_strdup(author_line);
+               i_authors++;
+               g_free(author_line);
                }
-       g_free(path);
+       authors[i_authors] = NULL;
+
+       g_input_stream_close(in_stream_authors, NULL, NULL);
+
+       translators_path = g_build_filename(GQ_RESOURCE_PATH_CREDITS, "translators", NULL);
+
+       g_resources_get_info(translators_path, G_RESOURCE_LOOKUP_FLAGS_NONE, &size, &flags, NULL);
 
-       comment = g_strconcat("Development and bug reports:\n", GQ_EMAIL_ADDRESS,
-                                               "\nhttps://github.com/BestImageViewer/geeqie/issues",NULL);
+       in_stream_translators = g_resources_open_stream(translators_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+       translators = static_cast<gchar *>(g_malloc0(size));
+       g_input_stream_read_all(in_stream_translators, translators, size, &bytes_read, NULL, NULL);
+       g_input_stream_close(in_stream_translators, NULL, NULL);
+
+       comment = g_strconcat("Project created by John Ellis\nGQview 1998\nGeeqie 2007\n\n\nDevelopment and bug reports:\n", GQ_EMAIL_ADDRESS, "\nhttps://github.com/BestImageViewer/geeqie/issues",NULL);
+
+       artists[0] = g_strdup("Néstor Díaz Valencia <nestor@estudionexos.com>");
+       artists[1] = NULL;
 
        pixbuf_logo = pixbuf_inline(PIXBUF_INLINE_LOGO);
        pixbuf_icon = pixbuf_inline(PIXBUF_INLINE_ICON);
@@ -4156,21 +4195,29 @@ void show_about_window(LayoutWindow *lw)
                "website", GQ_WEBSITE,
                "website-label", "Website",
                "comments", comment,
+               "artists", artists,
                "authors", authors,
-               "translator-credits", _("translator-credits"),
+               "translator-credits", translators,
                "wrap-license", TRUE,
                "license", copyright->str,
                NULL);
 
        g_string_free(copyright, TRUE);
 
-       gint n = 0;
        while(n < i_authors)
                {
                g_free(authors[n]);
                n++;
                }
+
+       g_free(artists[0]);
+       g_free(authors_path);
        g_free(comment);
+       g_free(translators);
+       g_free(translators_path);
+       g_object_unref(data_stream);
+       g_object_unref(in_stream_authors);
+       g_object_unref(in_stream_translators);
 
        return;
 }