2006-08-21 [colin] 2.4.0cvs67
[claws.git] / src / gtk / inputdialog.c
index 5c3d49df37f164d60aa8d38afb9398e36859744e..c1bb718a406adccc2d8e32d3953c88923e97067d 100644 (file)
@@ -38,6 +38,8 @@
 #include <gtk/gtkhbbox.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtkimage.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkcheckbutton.h>
 
 #include "inputdialog.h"
 #include "manage_window.h"
@@ -63,13 +65,15 @@ static GtkWidget *msg_title;
 static GtkWidget *msg_label;
 static GtkWidget *entry;
 static GtkWidget *combo;
+static GtkWidget *remember_chkbtn;
 static GtkWidget *ok_button;
 static GtkWidget *icon_q, *icon_p;
-
+static gboolean is_pass = FALSE;
 static void input_dialog_create        (gboolean is_password);
 static gchar *input_dialog_open        (const gchar    *title,
                                 const gchar    *message,
-                                const gchar    *default_string);
+                                const gchar    *default_string,
+                                gboolean       *remember);
 static void input_dialog_set   (const gchar    *title,
                                 const gchar    *message,
                                 const gchar    *default_string);
@@ -102,9 +106,10 @@ gchar *input_dialog(const gchar *title, const gchar *message,
 
        gtk_widget_show(icon_q);
        gtk_widget_hide(icon_p);
+       is_pass = FALSE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
 
-       return input_dialog_open(title, message, default_string);
+       return input_dialog_open(title, message, default_string, NULL);
 }
 
 gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
@@ -121,14 +126,23 @@ gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
 
        gtk_widget_hide(icon_q);
        gtk_widget_show(icon_p);
+       is_pass = TRUE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
 
-       return input_dialog_open(title, message, default_string);
+       return input_dialog_open(title, message, default_string, NULL);
 }
 
 gchar *input_dialog_combo(const gchar *title, const gchar *message,
                          const gchar *default_string, GList *list,
                          gboolean case_sensitive)
+{
+       return input_dialog_combo_remember(title, message, 
+               default_string, list, case_sensitive, NULL);
+}
+
+gchar *input_dialog_combo_remember(const gchar *title, const gchar *message,
+                         const gchar *default_string, GList *list,
+                         gboolean case_sensitive, gboolean *remember)
 {
        if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
 
@@ -139,8 +153,15 @@ gchar *input_dialog_combo(const gchar *title, const gchar *message,
        gtk_widget_hide(entry);
        gtk_widget_show(combo);
 
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_chkbtn), FALSE);
+       if (remember)
+               gtk_widget_show(remember_chkbtn);
+       else
+               gtk_widget_hide(remember_chkbtn);
+
        gtk_widget_show(icon_q);
        gtk_widget_hide(icon_p);
+       is_pass = FALSE;
 
        if (!list) {
                GList empty_list;
@@ -154,7 +175,7 @@ gchar *input_dialog_combo(const gchar *title, const gchar *message,
 
        gtk_combo_set_case_sensitive(GTK_COMBO(combo), case_sensitive);
 
-       return input_dialog_open(title, message, default_string);
+       return input_dialog_open(title, message, default_string, remember);
 }
 
 gchar *input_dialog_query_password(const gchar *server, const gchar *user)
@@ -250,6 +271,9 @@ static void input_dialog_create(gboolean is_password)
        g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "activate",
                         G_CALLBACK(combo_activated), NULL);
 
+       remember_chkbtn = gtk_check_button_new_with_label(_("Remember this"));
+       gtk_box_pack_start(GTK_BOX(vbox), remember_chkbtn, FALSE, FALSE, 0);
+
        hbox = gtk_hbox_new(TRUE, 0);
 
        gtkut_stock_button_set_create(&confirm_area,
@@ -257,17 +281,23 @@ static void input_dialog_create(gboolean is_password)
                                      &ok_button, GTK_STOCK_OK,
                                      NULL, NULL);
 
+       gtk_widget_set_size_request(confirm_area, 375, -1);
+
        gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
                         confirm_area, FALSE, FALSE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
 
        gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
        
+       gtk_widget_hide(remember_chkbtn);
+
        if (is_password)
                gtk_widget_hide(icon_q);
        else
                gtk_widget_hide(icon_p);
 
+       is_pass = is_password;
+
        gtk_widget_grab_default(ok_button);
 
        g_signal_connect(G_OBJECT(ok_button), "clicked",
@@ -277,7 +307,7 @@ static void input_dialog_create(gboolean is_password)
 }
 
 static gchar *input_dialog_open(const gchar *title, const gchar *message,
-                               const gchar *default_string)
+                               const gchar *default_string, gboolean *remember)
 {
        gchar *str;
 
@@ -309,7 +339,7 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
                        editable = GTK_EDITABLE(entry);
 
                str = gtk_editable_get_chars(editable, 0, -1);
-               if (str && *str == '\0') {
+               if (str && *str == '\0' && !is_pass) {
                        g_free(str);
                        str = NULL;
                }
@@ -318,6 +348,9 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
 
        GTK_EVENTS_FLUSH();
 
+       if (remember) {
+               *remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(remember_chkbtn));
+       }
        debug_print("return string = %s\n", str ? str : "(none)");
        return str;
 }