2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2002-01-16 12:48:36 +01:00
|
|
|
* Copyright (C) 1999-2002 Hiroyuki Yamamoto
|
2001-04-19 14:21:46 +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
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtkmain.h>
|
|
|
|
#include <gtk/gtkwidget.h>
|
|
|
|
#include <gtk/gtkdialog.h>
|
|
|
|
#include <gtk/gtkwindow.h>
|
|
|
|
#include <gtk/gtksignal.h>
|
|
|
|
#include <gtk/gtkvbox.h>
|
|
|
|
#include <gtk/gtkhbox.h>
|
|
|
|
#include <gtk/gtklabel.h>
|
|
|
|
#include <gtk/gtkentry.h>
|
2001-11-07 11:29:45 +01:00
|
|
|
#include <gtk/gtkcombo.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <gtk/gtkbutton.h>
|
|
|
|
#include <gtk/gtkhbbox.h>
|
|
|
|
|
|
|
|
#include "intl.h"
|
|
|
|
#include "inputdialog.h"
|
|
|
|
#include "manage_window.h"
|
|
|
|
#include "gtkutils.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#define INPUT_DIALOG_WIDTH 420
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
INPUT_DIALOG_NORMAL,
|
|
|
|
INPUT_DIALOG_INVISIBLE,
|
|
|
|
INPUT_DIALOG_COMBO
|
|
|
|
} InputDialogType;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static gboolean ack;
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
static InputDialogType type;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GtkWidget *dialog;
|
|
|
|
static GtkWidget *msg_label;
|
|
|
|
static GtkWidget *entry;
|
2001-11-07 11:29:45 +01:00
|
|
|
static GtkWidget *combo;
|
2001-04-19 14:21:46 +02:00
|
|
|
static GtkWidget *ok_button;
|
|
|
|
|
|
|
|
static void input_dialog_create (void);
|
2001-11-07 11:29:45 +01:00
|
|
|
static gchar *input_dialog_open (const gchar *title,
|
|
|
|
const gchar *message,
|
|
|
|
const gchar *default_string);
|
2001-04-19 14:21:46 +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);
|
2001-05-08 00:13:03 +02:00
|
|
|
static gint delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event,
|
|
|
|
gpointer data);
|
2001-04-19 14:21:46 +02:00
|
|
|
static void key_pressed (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
|
|
|
static void entry_activated (GtkEditable *editable);
|
2001-11-07 11:29:45 +01:00
|
|
|
static void combo_activated (GtkEditable *editable);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gchar *input_dialog(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
|
|
|
if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
|
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create();
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
type = INPUT_DIALOG_NORMAL;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
return input_dialog_open(title, message, default_string);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
|
|
|
if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
|
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create();
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
type = INPUT_DIALOG_INVISIBLE;
|
|
|
|
gtk_widget_hide(combo);
|
|
|
|
gtk_widget_show(entry);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
return input_dialog_open(title, message, default_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *input_dialog_combo(const gchar *title, const gchar *message,
|
2002-04-21 11:24:27 +02:00
|
|
|
const gchar *default_string, GList *list,
|
|
|
|
gboolean case_sensitive)
|
2001-11-07 11:29:45 +01:00
|
|
|
{
|
|
|
|
if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
|
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create();
|
|
|
|
|
|
|
|
type = INPUT_DIALOG_COMBO;
|
|
|
|
gtk_widget_hide(entry);
|
|
|
|
gtk_widget_show(combo);
|
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
GList empty_list;
|
|
|
|
|
|
|
|
empty_list.data = (gpointer)"";
|
|
|
|
empty_list.next = NULL;
|
|
|
|
empty_list.prev = NULL;
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), &empty_list);
|
|
|
|
} else
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);
|
|
|
|
|
2002-04-21 11:24:27 +02:00
|
|
|
gtk_combo_set_case_sensitive(GTK_COMBO(combo), case_sensitive);
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
return input_dialog_open(title, message, default_string);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
gchar *input_dialog_query_password(const gchar *server, const gchar *user)
|
|
|
|
{
|
|
|
|
gchar *message;
|
|
|
|
gchar *pass;
|
|
|
|
|
|
|
|
message = g_strdup_printf(_("Input password for %s on %s:"),
|
|
|
|
user, server);
|
|
|
|
pass = input_dialog_with_invisible(_("Input password"), message, NULL);
|
|
|
|
g_free(message);
|
|
|
|
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void input_dialog_create(void)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *confirm_area;
|
|
|
|
GtkWidget *cancel_button;
|
|
|
|
|
|
|
|
dialog = gtk_dialog_new();
|
|
|
|
gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
|
|
|
|
gtk_widget_set_usize(dialog, INPUT_DIALOG_WIDTH, -1);
|
|
|
|
gtk_container_set_border_width
|
|
|
|
(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
|
|
|
|
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
|
2001-05-08 00:13:03 +02:00
|
|
|
GTK_SIGNAL_FUNC(delete_event), NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
|
|
|
|
GTK_SIGNAL_FUNC(key_pressed), NULL);
|
2002-02-23 11:52:54 +01:00
|
|
|
MANAGE_WINDOW_SIGNALS_CONNECT(dialog);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gtk_widget_realize(dialog);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 8);
|
|
|
|
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
msg_label = gtk_label_new("");
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), msg_label, FALSE, FALSE, 0);
|
|
|
|
gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_LEFT);
|
|
|
|
|
|
|
|
entry = gtk_entry_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(entry), "activate",
|
|
|
|
GTK_SIGNAL_FUNC(entry_activated), NULL);
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
combo = gtk_combo_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "activate",
|
|
|
|
GTK_SIGNAL_FUNC(combo_activated), NULL);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gtkut_button_set_create(&confirm_area,
|
|
|
|
&ok_button, _("OK"),
|
|
|
|
&cancel_button, _("Cancel"),
|
|
|
|
NULL, NULL);
|
|
|
|
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
|
|
|
|
confirm_area);
|
|
|
|
gtk_widget_grab_default(ok_button);
|
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(ok_clicked), NULL);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(cancel_clicked), NULL);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
|
|
|
|
}
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
static gchar *input_dialog_open(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
|
|
|
|
|
|
|
|
if (!dialog)
|
|
|
|
input_dialog_create();
|
|
|
|
|
|
|
|
input_dialog_set(title, message, default_string);
|
|
|
|
gtk_widget_show(dialog);
|
|
|
|
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
|
|
|
|
manage_window_set_transient(GTK_WINDOW(dialog));
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
manage_window_focus_out(dialog, NULL, NULL);
|
|
|
|
gtk_widget_hide(dialog);
|
|
|
|
|
|
|
|
if (ack) {
|
|
|
|
GtkEditable *editable;
|
|
|
|
|
|
|
|
if (type == INPUT_DIALOG_COMBO)
|
|
|
|
editable = GTK_EDITABLE(GTK_COMBO(combo)->entry);
|
|
|
|
else
|
|
|
|
editable = GTK_EDITABLE(entry);
|
|
|
|
|
|
|
|
str = gtk_editable_get_chars(editable, 0, -1);
|
|
|
|
if (str && *str == '\0') {
|
|
|
|
g_free(str);
|
|
|
|
str = NULL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
|
|
|
|
debug_print("return string = %s\n", str ? str : "(none)");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void input_dialog_set(const gchar *title, const gchar *message,
|
|
|
|
const gchar *default_string)
|
|
|
|
{
|
2001-11-07 11:29:45 +01:00
|
|
|
GtkWidget *entry_;
|
|
|
|
|
|
|
|
if (type == INPUT_DIALOG_COMBO)
|
|
|
|
entry_ = GTK_COMBO(combo)->entry;
|
|
|
|
else
|
|
|
|
entry_ = entry;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(dialog), title);
|
|
|
|
gtk_label_set_text(GTK_LABEL(msg_label), message);
|
|
|
|
if (default_string && *default_string)
|
2001-11-07 11:29:45 +01:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry_), default_string);
|
2001-04-19 14:21:46 +02:00
|
|
|
else
|
2001-11-07 11:29:45 +01:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry_), "");
|
|
|
|
gtk_entry_set_position(GTK_ENTRY(entry_), 0);
|
|
|
|
gtk_entry_select_region(GTK_ENTRY(entry_), 0, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gtk_widget_grab_focus(ok_button);
|
2001-11-07 11:29:45 +01:00
|
|
|
gtk_widget_grab_focus(entry_);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ok_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cancel_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
ack = FALSE;
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
2001-05-08 00:13:03 +02:00
|
|
|
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
|
|
|
{
|
|
|
|
ack = FALSE;
|
|
|
|
gtk_main_quit();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|
|
|
{
|
|
|
|
if (event && event->keyval == GDK_Escape) {
|
|
|
|
ack = FALSE;
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void entry_activated(GtkEditable *editable)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
2001-11-07 11:29:45 +01:00
|
|
|
|
|
|
|
static void combo_activated(GtkEditable *editable)
|
|
|
|
{
|
|
|
|
ack = TRUE;
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|