2004-04-26 18:06:48 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2013-06-11 14:39:45 +02:00
|
|
|
* Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
|
2004-04-26 18:06:48 +02:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-04-26 18:06:48 +02:00
|
|
|
* (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
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2004-04-26 18:06:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
2012-07-07 09:09:39 +02:00
|
|
|
#include "claws-features.h"
|
2004-04-26 18:06:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2004-04-26 18:06:48 +02:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2008-09-09 18:40:59 +02:00
|
|
|
#include <gtk/gtk.h>
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
#include "inputdialog.h"
|
|
|
|
#include "manage_window.h"
|
|
|
|
#include "gtkutils.h"
|
|
|
|
#include "utils.h"
|
2007-10-19 08:50:41 +02:00
|
|
|
#include "combobox.h"
|
2008-06-13 11:21:20 +02:00
|
|
|
#include "prefs_common.h"
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
#define INPUT_DIALOG_WIDTH 420
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
INPUT_DIALOG_NORMAL,
|
|
|
|
INPUT_DIALOG_INVISIBLE,
|
|
|
|
INPUT_DIALOG_COMBO
|
|
|
|
} InputDialogType;
|
|
|
|
|
|
|
|
static gboolean ack;
|
|
|
|
static gboolean fin;
|
|
|
|
|
|
|
|
static InputDialogType type;
|
|
|
|
|
|
|
|
static GtkWidget *dialog;
|
2005-05-18 05:07:23 +02:00
|
|
|
static GtkWidget *msg_title;
|
2004-04-26 18:06:48 +02:00
|
|
|
static GtkWidget *msg_label;
|
|
|
|
static GtkWidget *entry;
|
|
|
|
static GtkWidget *combo;
|
2007-02-09 12:54:39 +01:00
|
|
|
static GtkWidget *remember_checkbtn;
|
2004-04-26 18:06:48 +02:00
|
|
|
static GtkWidget *ok_button;
|
2005-11-18 08:54:56 +01:00
|
|
|
static GtkWidget *icon_q, *icon_p;
|
2006-03-07 09:00:22 +01:00
|
|
|
static gboolean is_pass = FALSE;
|
2005-10-14 19:18:43 +02:00
|
|
|
static void input_dialog_create (gboolean is_password);
|
2004-04-26 18:06:48 +02:00
|
|
|
static gchar *input_dialog_open (const gchar *title,
|
|
|
|
const gchar *message,
|
2008-06-13 11:21:20 +02:00
|
|
|
const gchar *checkbtn_label,
|
2006-08-17 18:46:14 +02:00
|
|
|
const gchar *default_string,
|
2008-06-13 11:21:20 +02:00
|
|
|
gboolean default_checkbtn_state,
|
2006-08-17 18:46:14 +02:00
|
|
|
gboolean *remember);
|
2004-04-26 18:06:48 +02:00
|
|
|
static void input_dialog_set (const gchar *title,
|
|
|
|
const gchar *message,
|
|
|
|
const gchar *default_string);
|
|
|
|
|
|
|
|
static void ok_clicked (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void cancel_clicked (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static gint delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event,
|
|
|
|
gpointer data);
|
2004-05-10 12:22:28 +02:00
|
|
|
static gboolean key_pressed (GtkWidget *widget,
|
2004-04-26 18:06:48 +02:00
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
|
|
|
static void entry_activated (GtkEditable *editable);
|
|
|
|
static void combo_activated (GtkEditable *editable);
|
|
|
|
|
|
|
|
|
|
|
|
gchar *input_dialog(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
2005-10-14 19:18:43 +02:00
|
|
|
input_dialog_create(FALSE);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
type = INPUT_DIALOG_NORMAL;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
2005-11-18 08:54:56 +01:00
|
|
|
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_hide(remember_checkbtn);
|
2006-09-23 15:31:18 +02:00
|
|
|
|
2005-11-18 08:54:56 +01:00
|
|
|
gtk_widget_show(icon_q);
|
|
|
|
gtk_widget_hide(icon_p);
|
2006-03-07 09:00:22 +01:00
|
|
|
is_pass = FALSE;
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
|
|
|
|
|
2008-06-13 11:21:20 +02:00
|
|
|
return input_dialog_open(title, message, NULL, default_string, FALSE, NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
2005-10-14 19:18:43 +02:00
|
|
|
input_dialog_create(TRUE);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
type = INPUT_DIALOG_INVISIBLE;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_hide(remember_checkbtn);
|
2005-11-18 08:54:56 +01:00
|
|
|
|
|
|
|
gtk_widget_hide(icon_q);
|
|
|
|
gtk_widget_show(icon_p);
|
2006-03-07 09:00:22 +01:00
|
|
|
is_pass = TRUE;
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
|
|
|
|
|
2008-06-13 11:21:20 +02:00
|
|
|
return input_dialog_open(title, message, NULL, default_string, FALSE, NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 11:11:21 +02:00
|
|
|
gchar *input_dialog_with_invisible_checkbtn(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string, const gchar *checkbtn_label,
|
|
|
|
gboolean *checkbtn_state)
|
|
|
|
{
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2008-09-16 11:11:21 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create(TRUE);
|
|
|
|
|
|
|
|
type = INPUT_DIALOG_INVISIBLE;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
|
|
|
|
|
|
|
if (checkbtn_label && checkbtn_state) {
|
|
|
|
gtk_widget_show(remember_checkbtn);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn), *checkbtn_state);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn), FALSE);
|
|
|
|
gtk_widget_hide(remember_checkbtn);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_hide(icon_q);
|
|
|
|
gtk_widget_show(icon_p);
|
|
|
|
is_pass = TRUE;
|
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
|
|
|
|
|
2009-02-22 19:47:11 +01:00
|
|
|
return input_dialog_open(title, message, checkbtn_label, default_string, (checkbtn_state? *checkbtn_state:FALSE), checkbtn_state);
|
2008-09-16 11:11:21 +02:00
|
|
|
}
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
gchar *input_dialog_combo(const gchar *title, const gchar *message,
|
2007-10-19 08:50:41 +02:00
|
|
|
const gchar *default_string, GList *list)
|
2006-08-17 18:46:14 +02:00
|
|
|
{
|
|
|
|
return input_dialog_combo_remember(title, message,
|
2007-10-19 08:50:41 +02:00
|
|
|
default_string, list, FALSE);
|
2006-08-17 18:46:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_combo_remember(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string, GList *list,
|
2007-10-19 08:50:41 +02:00
|
|
|
gboolean *remember)
|
2004-04-26 18:06:48 +02:00
|
|
|
{
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
2005-10-14 19:18:43 +02:00
|
|
|
input_dialog_create(FALSE);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
type = INPUT_DIALOG_COMBO;
|
|
|
|
gtk_widget_hide(entry);
|
|
|
|
gtk_widget_show(combo);
|
|
|
|
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn), FALSE);
|
2006-08-17 18:46:14 +02:00
|
|
|
if (remember)
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_show(remember_checkbtn);
|
2006-08-17 18:46:14 +02:00
|
|
|
else
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_hide(remember_checkbtn);
|
2006-08-17 18:46:14 +02:00
|
|
|
|
2005-11-18 08:54:56 +01:00
|
|
|
gtk_widget_show(icon_q);
|
|
|
|
gtk_widget_hide(icon_p);
|
2006-03-07 09:00:22 +01:00
|
|
|
is_pass = FALSE;
|
2013-06-11 14:39:45 +02:00
|
|
|
#if !GTK_CHECK_VERSION(2, 24, 0)
|
2007-10-19 08:50:41 +02:00
|
|
|
combobox_unset_popdown_strings(GTK_COMBO_BOX(combo));
|
|
|
|
combobox_set_popdown_strings(GTK_COMBO_BOX(combo), list);
|
2013-06-11 14:39:45 +02:00
|
|
|
#else
|
|
|
|
combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(combo));
|
|
|
|
combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(combo), list);
|
|
|
|
#endif
|
2008-06-13 11:21:20 +02:00
|
|
|
return input_dialog_open(title, message, NULL, default_string, FALSE, remember);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_with_checkbtn(const gchar *title,
|
|
|
|
const gchar *message,
|
|
|
|
const gchar *default_string,
|
|
|
|
const gchar *checkbtn_label,
|
|
|
|
gboolean *checkbtn_state)
|
|
|
|
{
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2008-06-13 11:21:20 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create(FALSE);
|
|
|
|
|
|
|
|
type = INPUT_DIALOG_NORMAL;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
|
|
|
|
2008-06-16 08:11:10 +02:00
|
|
|
if (checkbtn_label && checkbtn_state)
|
2008-06-13 11:21:20 +02:00
|
|
|
gtk_widget_show(remember_checkbtn);
|
|
|
|
else
|
|
|
|
gtk_widget_hide(remember_checkbtn);
|
|
|
|
|
|
|
|
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, checkbtn_label, default_string,
|
|
|
|
prefs_common.inherit_folder_props, checkbtn_state);
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_query_password(const gchar *server, const gchar *user)
|
|
|
|
{
|
|
|
|
gchar *message;
|
|
|
|
gchar *pass;
|
|
|
|
|
2008-07-03 22:31:33 +02:00
|
|
|
if (server && user)
|
|
|
|
message = g_strdup_printf(_("Input password for %s on %s:"),
|
2004-04-26 18:06:48 +02:00
|
|
|
user, server);
|
2008-07-03 22:31:33 +02:00
|
|
|
else if (server)
|
|
|
|
message = g_strdup_printf(_("Input password for %s:"),
|
|
|
|
server);
|
|
|
|
else if (user)
|
|
|
|
message = g_strdup_printf(_("Input password for %s:"),
|
|
|
|
user);
|
|
|
|
else
|
|
|
|
message = g_strdup_printf(_("Input password:"));
|
2004-04-26 18:06:48 +02:00
|
|
|
pass = input_dialog_with_invisible(_("Input password"), message, NULL);
|
|
|
|
g_free(message);
|
|
|
|
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:39:10 +02:00
|
|
|
gchar *input_dialog_query_password_keep(const gchar *server, const gchar *user, gchar **keep)
|
2008-09-16 11:11:21 +02:00
|
|
|
{
|
|
|
|
gchar *message;
|
|
|
|
gchar *pass;
|
|
|
|
|
|
|
|
if (server && user)
|
|
|
|
message = g_strdup_printf(_("Input password for %s on %s:"),
|
|
|
|
user, server);
|
|
|
|
else if (server)
|
|
|
|
message = g_strdup_printf(_("Input password for %s:"),
|
|
|
|
server);
|
|
|
|
else if (user)
|
|
|
|
message = g_strdup_printf(_("Input password for %s:"),
|
|
|
|
user);
|
|
|
|
else
|
|
|
|
message = g_strdup_printf(_("Input password:"));
|
2008-09-16 19:15:56 +02:00
|
|
|
if (keep) {
|
2008-09-16 11:11:21 +02:00
|
|
|
if (*keep != NULL) {
|
2008-09-16 18:39:10 +02:00
|
|
|
pass = g_strdup (*keep);
|
2008-09-16 11:11:21 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-09-16 19:15:56 +02:00
|
|
|
gboolean state = prefs_common.session_passwords;
|
2008-09-16 11:11:21 +02:00
|
|
|
pass = input_dialog_with_invisible_checkbtn(_("Input password"),
|
|
|
|
message, NULL,
|
|
|
|
_("Remember password for this session"),
|
|
|
|
&state);
|
|
|
|
if (state) {
|
|
|
|
*keep = g_strdup (pass);
|
|
|
|
debug_print("keeping session password for account\n");
|
|
|
|
}
|
2008-09-16 19:15:56 +02:00
|
|
|
prefs_common.session_passwords = state;
|
2008-09-16 11:11:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pass = input_dialog_with_invisible(_("Input password"), message, NULL);
|
|
|
|
}
|
|
|
|
g_free(message);
|
|
|
|
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2005-10-14 19:18:43 +02:00
|
|
|
static void input_dialog_create(gboolean is_password)
|
2004-04-26 18:06:48 +02:00
|
|
|
{
|
2005-05-18 05:07:23 +02:00
|
|
|
static PangoFontDescription *font_desc;
|
2004-04-26 18:06:48 +02:00
|
|
|
GtkWidget *hbox;
|
2005-05-18 05:07:23 +02:00
|
|
|
GtkWidget *vbox;
|
2004-04-26 18:06:48 +02:00
|
|
|
GtkWidget *cancel_button;
|
2005-05-18 05:07:23 +02:00
|
|
|
GtkWidget *confirm_area;
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
dialog = gtk_dialog_new();
|
2005-05-18 05:07:23 +02:00
|
|
|
|
2004-07-28 09:51:10 +02:00
|
|
|
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
|
2006-08-24 23:38:11 +02:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 375, 100);
|
2005-05-19 15:10:23 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(dialog), "");
|
2005-05-18 05:07:23 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
g_signal_connect(G_OBJECT(dialog), "delete_event",
|
|
|
|
G_CALLBACK(delete_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(dialog), "key_press_event",
|
|
|
|
G_CALLBACK(key_pressed), NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
MANAGE_WINDOW_SIGNALS_CONNECT(dialog);
|
|
|
|
|
2011-10-07 11:08:57 +02:00
|
|
|
vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
|
|
gtk_box_set_spacing (GTK_BOX (vbox), 14);
|
2005-05-18 05:07:23 +02:00
|
|
|
hbox = gtk_hbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
|
|
|
|
gtk_widget_show (hbox);
|
2011-10-07 11:08:57 +02:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox,
|
2005-05-18 05:07:23 +02:00
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* for title label */
|
2005-11-18 08:54:56 +01:00
|
|
|
icon_q = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
|
|
|
|
GTK_ICON_SIZE_DIALOG);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (icon_q), 0.5, 0.0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), icon_q, FALSE, FALSE, 0);
|
|
|
|
icon_p = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION,
|
|
|
|
GTK_ICON_SIZE_DIALOG);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (icon_p), 0.5, 0.0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), icon_p, FALSE, FALSE, 0);
|
2005-05-18 05:07:23 +02:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
msg_title = gtk_label_new("");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(msg_title), 0, 0.5);
|
|
|
|
gtk_label_set_justify(GTK_LABEL(msg_title), GTK_JUSTIFY_LEFT);
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (msg_title), TRUE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), msg_title, FALSE, FALSE, 0);
|
|
|
|
gtk_label_set_line_wrap(GTK_LABEL(msg_title), TRUE);
|
|
|
|
if (!font_desc) {
|
|
|
|
gint size;
|
|
|
|
|
|
|
|
size = pango_font_description_get_size
|
2011-10-07 11:08:57 +02:00
|
|
|
(gtk_widget_get_style(msg_title)->font_desc);
|
2005-05-18 05:07:23 +02:00
|
|
|
font_desc = pango_font_description_new();
|
|
|
|
pango_font_description_set_weight
|
|
|
|
(font_desc, PANGO_WEIGHT_BOLD);
|
|
|
|
pango_font_description_set_size
|
|
|
|
(font_desc, size * PANGO_SCALE_LARGE);
|
|
|
|
}
|
|
|
|
if (font_desc)
|
|
|
|
gtk_widget_modify_font(msg_title, font_desc);
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
msg_label = gtk_label_new("");
|
2005-05-18 05:07:23 +02:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(msg_label), 0, 0.5);
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_LEFT);
|
2005-05-18 05:07:23 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), msg_label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(msg_label);
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
entry = gtk_entry_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
|
2004-05-10 12:22:28 +02:00
|
|
|
g_signal_connect(G_OBJECT(entry), "activate",
|
|
|
|
G_CALLBACK(entry_activated), NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
2012-11-15 14:41:07 +01:00
|
|
|
#if !GTK_CHECK_VERSION(2, 24, 0)
|
2011-04-10 19:19:05 +02:00
|
|
|
combo = gtk_combo_box_entry_new_text();
|
2012-11-15 14:41:07 +01:00
|
|
|
#else
|
|
|
|
combo = gtk_combo_box_text_new_with_entry();
|
|
|
|
#endif
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
|
2008-08-07 18:39:17 +02:00
|
|
|
g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "activate",
|
2004-05-10 12:22:28 +02:00
|
|
|
G_CALLBACK(combo_activated), NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
2007-02-09 12:54:39 +01:00
|
|
|
remember_checkbtn = gtk_check_button_new_with_label(_("Remember this"));
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), remember_checkbtn, FALSE, FALSE, 0);
|
2006-08-17 18:46:14 +02:00
|
|
|
|
2005-01-29 17:53:23 +01:00
|
|
|
gtkut_stock_button_set_create(&confirm_area,
|
2004-12-30 16:28:43 +01:00
|
|
|
&cancel_button, GTK_STOCK_CANCEL,
|
2006-01-14 10:45:39 +01:00
|
|
|
&ok_button, GTK_STOCK_OK,
|
2004-12-30 16:28:43 +01:00
|
|
|
NULL, NULL);
|
2005-05-18 05:07:23 +02:00
|
|
|
|
2011-10-07 11:08:57 +02:00
|
|
|
gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
|
2005-05-18 05:07:23 +02:00
|
|
|
confirm_area, FALSE, FALSE, 0);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
|
|
|
|
|
2011-10-07 11:08:57 +02:00
|
|
|
gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
|
2005-05-18 05:07:23 +02:00
|
|
|
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_hide(remember_checkbtn);
|
2006-08-17 18:46:14 +02:00
|
|
|
|
2005-11-18 08:54:56 +01:00
|
|
|
if (is_password)
|
|
|
|
gtk_widget_hide(icon_q);
|
|
|
|
else
|
|
|
|
gtk_widget_hide(icon_p);
|
|
|
|
|
2006-03-07 09:00:22 +01:00
|
|
|
is_pass = is_password;
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_widget_grab_default(ok_button);
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
g_signal_connect(G_OBJECT(ok_button), "clicked",
|
|
|
|
G_CALLBACK(ok_clicked), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(cancel_button), "clicked",
|
|
|
|
G_CALLBACK(cancel_clicked), NULL);
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *input_dialog_open(const gchar *title, const gchar *message,
|
2008-06-13 11:21:20 +02:00
|
|
|
const gchar *checkbtn_label,
|
|
|
|
const gchar *default_string,
|
|
|
|
gboolean default_checkbtn_state,
|
|
|
|
gboolean *remember)
|
2004-04-26 18:06:48 +02:00
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
2011-10-22 19:09:05 +02:00
|
|
|
if (dialog && gtk_widget_get_visible(dialog)) return NULL;
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
if (!dialog)
|
2005-10-14 19:18:43 +02:00
|
|
|
input_dialog_create(FALSE);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
2008-06-16 08:11:10 +02:00
|
|
|
if (checkbtn_label)
|
2008-06-13 11:21:20 +02:00
|
|
|
gtk_button_set_label(GTK_BUTTON(remember_checkbtn), checkbtn_label);
|
|
|
|
else
|
|
|
|
gtk_button_set_label(GTK_BUTTON(remember_checkbtn), _("Remember this"));
|
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
input_dialog_set(title, message, default_string);
|
2012-11-16 17:10:09 +01:00
|
|
|
gtk_window_present(GTK_WINDOW(dialog));
|
2005-11-18 08:54:56 +01:00
|
|
|
|
2008-06-13 11:21:20 +02:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn),
|
|
|
|
default_checkbtn_state);
|
2006-09-23 15:31:18 +02:00
|
|
|
if (remember)
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_show(remember_checkbtn);
|
2006-09-23 15:31:18 +02:00
|
|
|
else
|
2007-02-09 12:54:39 +01:00
|
|
|
gtk_widget_hide(remember_checkbtn);
|
2006-09-23 15:31:18 +02:00
|
|
|
|
2004-04-26 18:06:48 +02:00
|
|
|
manage_window_set_transient(GTK_WINDOW(dialog));
|
2016-02-11 00:47:07 +01:00
|
|
|
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
|
2004-04-26 18:06:48 +02:00
|
|
|
|
|
|
|
ack = fin = FALSE;
|
|
|
|
|
|
|
|
while (fin == FALSE)
|
|
|
|
gtk_main_iteration();
|
|
|
|
|
|
|
|
manage_window_focus_out(dialog, NULL, NULL);
|
|
|
|
|
|
|
|
if (ack) {
|
|
|
|
GtkEditable *editable;
|
|
|
|
|
|
|
|
if (type == INPUT_DIALOG_COMBO)
|
2008-08-07 18:39:17 +02:00
|
|
|
editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((combo))));
|
2004-04-26 18:06:48 +02:00
|
|
|
else
|
|
|
|
editable = GTK_EDITABLE(entry);
|
|
|
|
|
|
|
|
str = gtk_editable_get_chars(editable, 0, -1);
|
2006-03-07 09:00:22 +01:00
|
|
|
if (str && *str == '\0' && !is_pass) {
|
2004-04-26 18:06:48 +02:00
|
|
|
g_free(str);
|
|
|
|
str = NULL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
|
2006-08-17 18:46:14 +02:00
|
|
|
if (remember) {
|
2007-02-09 12:54:39 +01:00
|
|
|
*remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(remember_checkbtn));
|
2006-08-17 18:46:14 +02:00
|
|
|
}
|
2012-11-16 17:10:09 +01:00
|
|
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
dialog = NULL;
|
|
|
|
|
2007-01-14 18:20:18 +01:00
|
|
|
if (is_pass)
|
|
|
|
debug_print("return string = %s\n", str ? "********": ("none"));
|
|
|
|
else
|
|
|
|
debug_print("return string = %s\n", str ? str : "(none)");
|
2004-04-26 18:06:48 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_dialog_set(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
|
|
|
GtkWidget *entry_;
|
|
|
|
|
|
|
|
if (type == INPUT_DIALOG_COMBO)
|
2008-08-07 18:39:17 +02:00
|
|
|
entry_ = gtk_bin_get_child(GTK_BIN((combo)));
|
2004-04-26 18:06:48 +02:00
|
|
|
else
|
|
|
|
entry_ = entry;
|
|
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(dialog), title);
|
2005-05-18 05:07:23 +02:00
|
|
|
gtk_label_set_text(GTK_LABEL(msg_title), title);
|
2004-04-26 18:06:48 +02:00
|
|
|
gtk_label_set_text(GTK_LABEL(msg_label), message);
|
|
|
|
if (default_string && *default_string) {
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry_), default_string);
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_editable_set_position(GTK_EDITABLE(entry_), 0);
|
|
|
|
gtk_editable_select_region(GTK_EDITABLE(entry_), 0, -1);
|
2004-04-26 18:06:48 +02:00
|
|
|
} else
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry_), "");
|
|
|
|
|
|
|
|
gtk_widget_grab_focus(ok_button);
|
|
|
|
gtk_widget_grab_focus(entry_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ok_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
fin = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cancel_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
ack = FALSE;
|
|
|
|
fin = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
|
|
|
{
|
|
|
|
ack = FALSE;
|
|
|
|
fin = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
2004-04-26 18:06:48 +02:00
|
|
|
{
|
2011-10-07 11:17:51 +02:00
|
|
|
if (event && event->keyval == GDK_KEY_Escape) {
|
2004-04-26 18:06:48 +02:00
|
|
|
ack = FALSE;
|
|
|
|
fin = TRUE;
|
2011-10-07 11:17:51 +02:00
|
|
|
} else if (event && event->keyval == GDK_KEY_Return) {
|
2005-06-10 21:23:40 +02:00
|
|
|
ack = TRUE;
|
|
|
|
fin = TRUE;
|
|
|
|
return TRUE; /* do not let Return pass - it
|
|
|
|
* pops up the combo on validating */
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2004-04-26 18:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void entry_activated(GtkEditable *editable)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
fin = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void combo_activated(GtkEditable *editable)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
fin = TRUE;
|
|
|
|
}
|