Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / ui_utildlg.c
index 4b2a00c..9548a8a 100644 (file)
@@ -1,12 +1,22 @@
 /*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2004 John Ellis
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifdef HAVE_CONFIG_H
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
+#include "main.h"
 #include "ui_utildlg.h"
 
+#include "filedata.h"
 #include "ui_fileops.h"
 #include "ui_misc.h"
 #include "ui_pathsel.h"
 #include "ui_tabcomp.h"
-
+#include "window.h"
 
 /*
  *-----------------------------------------------------------------------------
  * generic dialog
  *-----------------------------------------------------------------------------
- */ 
+ */
 
 void generic_dialog_close(GenericDialog *gd)
 {
@@ -46,7 +58,7 @@ static void generic_dialog_click_cb(GtkWidget *widget, gpointer data)
 {
        GenericDialog *gd = data;
        void (*func)(GenericDialog *, gpointer);
-       gint auto_close;
+       gboolean auto_close;
 
        func = g_object_get_data(G_OBJECT(widget), "dialog_function");
        auto_close = gd->auto_close;
@@ -55,14 +67,14 @@ static void generic_dialog_click_cb(GtkWidget *widget, gpointer data)
        if (auto_close) generic_dialog_close(gd);
 }
 
-static gint generic_dialog_default_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean generic_dialog_default_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        GenericDialog *gd = data;
 
-       if (event->keyval == GDK_Return && GTK_WIDGET_HAS_FOCUS(widget)
+       if (event->keyval == GDK_KEY_Return && gtk_widget_has_focus(widget)
            && gd->default_cb)
                {
-               gint auto_close;
+               gboolean auto_close;
 
                auto_close = gd->auto_close;
                gd->default_cb(gd, gd->data);
@@ -80,23 +92,24 @@ void generic_dialog_attach_default(GenericDialog *gd, GtkWidget *widget)
                         G_CALLBACK(generic_dialog_default_key_press_cb), gd);
 }
 
-static gint generic_dialog_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean generic_dialog_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        GenericDialog *gd = data;
+       gboolean auto_close = gd->auto_close;
 
-       if (event->keyval == GDK_Escape)
+       if (event->keyval == GDK_KEY_Escape)
                {
                if (gd->cancel_cb) gd->cancel_cb(gd, gd->data);
-               if (gd->auto_close) generic_dialog_click_cb(widget, data);
+               else if (auto_close) generic_dialog_click_cb(widget, data);
                return TRUE;
                }
        return FALSE;
 }
 
-static gint generic_dialog_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
+static gboolean generic_dialog_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
 {
        GenericDialog *gd = data;
-       gint auto_close;
+       gboolean auto_close;
 
        auto_close = gd->auto_close;
 
@@ -110,7 +123,7 @@ static void generic_dialog_show_cb(GtkWidget *widget, gpointer data)
 {
        GenericDialog *gd = data;
        if (gd->cancel_button)
-               {
+               {
                gtk_box_reorder_child(GTK_BOX(gd->hbox), gd->cancel_button, -1);
                }
 
@@ -118,11 +131,11 @@ static void generic_dialog_show_cb(GtkWidget *widget, gpointer data)
                                             G_CALLBACK(generic_dialog_show_cb), gd);
 }
 
-gint generic_dialog_get_alternative_button_order(GtkWidget *widget)
+gboolean generic_dialog_get_alternative_button_order(GtkWidget *widget)
 {
        GtkSettings *settings;
        GObjectClass *klass;
-       gint alternative_order = FALSE;
+       gboolean alternative_order = FALSE;
 
        settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
        klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings));
@@ -135,15 +148,15 @@ gint generic_dialog_get_alternative_button_order(GtkWidget *widget)
 }
 
 GtkWidget *generic_dialog_add_button(GenericDialog *gd, const gchar *stock_id, const gchar *text,
-                                    void (*func_cb)(GenericDialog *, gpointer), gint is_default)
+                                    void (*func_cb)(GenericDialog *, gpointer), gboolean is_default)
 {
        GtkWidget *button;
-       gint alternative_order;
+       gboolean alternative_order;
 
        button = pref_button_new(NULL, stock_id, text, FALSE,
                                 G_CALLBACK(generic_dialog_click_cb), gd);
 
-       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button, TRUE);
        g_object_set_data(G_OBJECT(button), "dialog_function", func_cb);
 
        gtk_container_add(GTK_CONTAINER(gd->hbox), button);
@@ -175,7 +188,7 @@ GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock
        GtkWidget *vbox;
        GtkWidget *label;
 
-       hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
+       hbox = pref_box_new(gd->vbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
        if (icon_stock_id)
                {
                GtkWidget *image;
@@ -197,6 +210,7 @@ GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock
                {
                label = pref_label_new(vbox, text);
                gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+               gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
                }
 
        return vbox;
@@ -204,8 +218,8 @@ GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock
 
 static void generic_dialog_setup(GenericDialog *gd,
                                 const gchar *title,
-                                const gchar *wmclass, const gchar *wmsubclass,
-                                GtkWidget *parent, gint auto_close,
+                                const gchar *role,
+                                GtkWidget *parent, gboolean auto_close,
                                 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
 {
        GtkWidget *vbox;
@@ -214,9 +228,9 @@ static void generic_dialog_setup(GenericDialog *gd,
        gd->data = data;
        gd->cancel_cb = cancel_cb;
 
-       gd->dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gd->dialog = window_new(GTK_WINDOW_TOPLEVEL, role, NULL, NULL, title);
        gtk_window_set_type_hint(GTK_WINDOW(gd->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
-       gtk_window_set_wmclass(GTK_WINDOW(gd->dialog), wmsubclass, wmclass);
+
        if (parent)
                {
                GtkWindow *window = NULL;
@@ -230,7 +244,7 @@ static void generic_dialog_setup(GenericDialog *gd,
                        GtkWidget *top;
 
                        top = gtk_widget_get_toplevel(parent);
-                       if (GTK_IS_WINDOW(top) && GTK_WIDGET_TOPLEVEL(top)) window = GTK_WINDOW(top);
+                       if (GTK_IS_WINDOW(top) && gtk_widget_is_toplevel(top)) window = GTK_WINDOW(top);
                        }
 
                if (window) gtk_window_set_transient_for(GTK_WINDOW(gd->dialog), window);
@@ -242,7 +256,6 @@ static void generic_dialog_setup(GenericDialog *gd,
                         G_CALLBACK(generic_dialog_key_press_cb), gd);
 
        gtk_window_set_resizable(GTK_WINDOW(gd->dialog), TRUE);
-       gtk_window_set_title(GTK_WINDOW (gd->dialog), title);
        gtk_container_set_border_width(GTK_CONTAINER(gd->dialog), PREF_PAD_BORDER);
 
        vbox = gtk_vbox_new(FALSE, PREF_PAD_BUTTON_SPACE);
@@ -260,7 +273,7 @@ static void generic_dialog_setup(GenericDialog *gd,
        gtk_widget_show(gd->hbox);
 
        if (gd->cancel_cb)
-               {
+               {
                gd->cancel_button = generic_dialog_add_button(gd, GTK_STOCK_CANCEL, NULL, gd->cancel_cb, TRUE);
                }
        else
@@ -278,14 +291,14 @@ static void generic_dialog_setup(GenericDialog *gd,
 }
 
 GenericDialog *generic_dialog_new(const gchar *title,
-                                 const gchar *wmclass, const gchar *wmsubclass,
-                                 GtkWidget *parent, gint auto_close,
+                                 const gchar *role,
+                                 GtkWidget *parent, gboolean auto_close,
                                  void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
 {
        GenericDialog *gd;
 
        gd = g_new0(GenericDialog, 1);
-       generic_dialog_setup(gd, title, wmclass, wmsubclass,
+       generic_dialog_setup(gd, title, role,
                             parent, auto_close, cancel_cb, data);
        return gd;
 }
@@ -293,7 +306,7 @@ GenericDialog *generic_dialog_new(const gchar *title,
  *-----------------------------------------------------------------------------
  * simple warning dialog
  *-----------------------------------------------------------------------------
- */ 
+ */
 
 static void warning_dialog_ok_cb(GenericDialog *gd, gpointer data)
 {
@@ -305,7 +318,7 @@ GenericDialog *warning_dialog(const gchar *heading, const gchar *text,
 {
        GenericDialog *gd;
 
-       gd = generic_dialog_new(heading, PACKAGE, "warning", parent, TRUE, NULL, NULL);
+       gd = generic_dialog_new(heading, "warning", parent, TRUE, NULL, NULL);
        generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, warning_dialog_ok_cb, TRUE);
 
        generic_dialog_add_message(gd, icon_stock_id, heading, text);
@@ -319,45 +332,45 @@ GenericDialog *warning_dialog(const gchar *heading, const gchar *text,
  *-----------------------------------------------------------------------------
  * generic file ops dialog routines
  *-----------------------------------------------------------------------------
- */ 
+ */
 
-void file_dialog_close(FileDialog *fd)
+void file_dialog_close(FileDialog *fdlg)
 {
-       g_free(fd->source_path);
-       g_free(fd->dest_path);
-       if (fd->source_list) path_list_free(fd->source_list);
+       file_data_unref(fdlg->source_fd);
+       g_free(fdlg->dest_path);
+       if (fdlg->source_list) filelist_free(fdlg->source_list);
 
-       generic_dialog_close(GENERIC_DIALOG(fd));
+       generic_dialog_close(GENERIC_DIALOG(fdlg));
 }
 
 FileDialog *file_dialog_new(const gchar *title,
-                           const gchar *wmclass, const gchar *wmsubclass,
+                           const gchar *role,
                            GtkWidget *parent,
                            void (*cancel_cb)(FileDialog *, gpointer), gpointer data)
 {
-       FileDialog *fd = NULL;
+       FileDialog *fdlg = NULL;
 
-       fd = g_new0(FileDialog, 1);
+       fdlg = g_new0(FileDialog, 1);
 
-       generic_dialog_setup(GENERIC_DIALOG(fd), title,
-                            wmclass, wmsubclass, parent, FALSE,
-                            (void *)cancel_cb, data);
+       generic_dialog_setup(GENERIC_DIALOG(fdlg), title,
+                            role, parent, FALSE,
+                            (gpointer)cancel_cb, data);
 
-       return fd;
+       return fdlg;
 }
 
-GtkWidget *file_dialog_add_button(FileDialog *fd, const gchar *stock_id, const gchar *text,
-                                 void (*func_cb)(FileDialog *, gpointer), gint is_default)
+GtkWidget *file_dialog_add_button(FileDialog *fdlg, const gchar *stock_id, const gchar *text,
+                                 void (*func_cb)(FileDialog *, gpointer), gboolean is_default)
 {
-       return generic_dialog_add_button(GENERIC_DIALOG(fd), stock_id, text,
-                                        (void *)func_cb, is_default);
+       return generic_dialog_add_button(GENERIC_DIALOG(fdlg), stock_id, text,
+                                        (gpointer)func_cb, is_default);
 }
 
 static void file_dialog_entry_cb(GtkWidget *widget, gpointer data)
 {
-       FileDialog *fd = data;
-       g_free(fd->dest_path);
-       fd->dest_path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(fd->entry)));
+       FileDialog *fdlg = data;
+       g_free(fdlg->dest_path);
+       fdlg->dest_path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(fdlg->entry)));
 }
 
 static void file_dialog_entry_enter_cb(const gchar *path, gpointer data)
@@ -369,86 +382,85 @@ static void file_dialog_entry_enter_cb(const gchar *path, gpointer data)
        if (gd->default_cb) gd->default_cb(gd, gd->data);
 }
 
-void file_dialog_add_path_widgets(FileDialog *fd, const gchar *default_path, const gchar *path,
+void file_dialog_add_path_widgets(FileDialog *fdlg, const gchar *default_path, const gchar *path,
                                  const gchar *history_key, const gchar *filter, const gchar *filter_desc)
 {
        GtkWidget *tabcomp;
        GtkWidget *list;
 
-       if (fd->entry) return;
+       if (fdlg->entry) return;
 
-       tabcomp = tab_completion_new_with_history(&fd->entry, NULL,
-                 history_key, -1, file_dialog_entry_enter_cb, fd);
-       gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fd)->vbox), tabcomp, FALSE, FALSE, 0);
-       generic_dialog_attach_default(GENERIC_DIALOG(fd), fd->entry);
+       tabcomp = tab_completion_new_with_history(&fdlg->entry, NULL,
+                 history_key, -1, file_dialog_entry_enter_cb, fdlg);
+       gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), tabcomp, FALSE, FALSE, 0);
+       generic_dialog_attach_default(GENERIC_DIALOG(fdlg), fdlg->entry);
        gtk_widget_show(tabcomp);
 
-       if (path && path[0] == '/')
+       if (path && path[0] == G_DIR_SEPARATOR)
                {
-               fd->dest_path = g_strdup(path);
+               fdlg->dest_path = g_strdup(path);
                }
        else
                {
                const gchar *base;
 
-               base = tab_completion_set_to_last_history(fd->entry);
+               base = tab_completion_set_to_last_history(fdlg->entry);
 
                if (!base) base = default_path;
                if (!base) base = homedir();
 
                if (path)
                        {
-                       fd->dest_path = concat_dir_and_file(base, path);
+                       fdlg->dest_path = g_build_filename(base, path, NULL);
                        }
                else
                        {
-                       fd->dest_path = g_strdup(base);
+                       fdlg->dest_path = g_strdup(base);
                        }
                }
 
-       list = path_selection_new_with_files(fd->entry, fd->dest_path, filter, filter_desc);
-       path_selection_add_select_func(fd->entry, file_dialog_entry_enter_cb, fd);
-       gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fd)->vbox), list, TRUE, TRUE, 0);
+       list = path_selection_new_with_files(fdlg->entry, fdlg->dest_path, filter, filter_desc);
+       path_selection_add_select_func(fdlg->entry, file_dialog_entry_enter_cb, fdlg);
+       gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), list, TRUE, TRUE, 0);
        gtk_widget_show(list);
 
-       gtk_widget_grab_focus(fd->entry);
-       if (fd->dest_path)
+       gtk_widget_grab_focus(fdlg->entry);
+       if (fdlg->dest_path)
                {
-               gtk_entry_set_text(GTK_ENTRY(fd->entry), fd->dest_path);
-               gtk_editable_set_position(GTK_EDITABLE(fd->entry), strlen(fd->dest_path));
+               gtk_entry_set_text(GTK_ENTRY(fdlg->entry), fdlg->dest_path);
+               gtk_editable_set_position(GTK_EDITABLE(fdlg->entry), strlen(fdlg->dest_path));
                }
 
-       g_signal_connect(G_OBJECT(fd->entry), "changed",
-                        G_CALLBACK(file_dialog_entry_cb), fd);
+       g_signal_connect(G_OBJECT(fdlg->entry), "changed",
+                        G_CALLBACK(file_dialog_entry_cb), fdlg);
 }
 
-void file_dialog_add_filter(FileDialog *fd, const gchar *filter, const gchar *filter_desc, gint set)
+void file_dialog_add_filter(FileDialog *fdlg, const gchar *filter, const gchar *filter_desc, gboolean set)
 {
-       if (!fd->entry) return;
-       path_selection_add_filter(fd->entry, filter, filter_desc, set);
+       if (!fdlg->entry) return;
+       path_selection_add_filter(fdlg->entry, filter, filter_desc, set);
 }
 
-void file_dialog_clear_filter(FileDialog *fd)
+void file_dialog_clear_filter(FileDialog *fdlg)
 {
-       if (!fd->entry) return;
-       path_selection_clear_filter(fd->entry);
+       if (!fdlg->entry) return;
+       path_selection_clear_filter(fdlg->entry);
 }
 
-void file_dialog_sync_history(FileDialog *fd, gint dir_only)
+void file_dialog_sync_history(FileDialog *fdlg, gboolean dir_only)
 {
-       if (!fd->dest_path) return;
+       if (!fdlg->dest_path) return;
 
        if (!dir_only ||
-           (dir_only && isdir(fd->dest_path)) )
+           (dir_only && isdir(fdlg->dest_path)) )
                {
-               tab_completion_append_to_history(fd->entry, fd->dest_path);
+               tab_completion_append_to_history(fdlg->entry, fdlg->dest_path);
                }
        else
                {
-               gchar *buf = remove_level_from_path(fd->dest_path);
-               tab_completion_append_to_history(fd->entry, buf);
+               gchar *buf = remove_level_from_path(fdlg->dest_path);
+               tab_completion_append_to_history(fdlg->entry, buf);
                g_free(buf);
                }
 }
-
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */