aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2017-02-07 09:37:58 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2017-02-07 09:37:58 +0000
commit75d6a2c0663717aaece28c151349e018516279a5 (patch)
tree538edb288efa0ff9879953b01406f89ee01406f0
parent6cd2c4955d814f96d55cbcd2db9c25b670fd415d (diff)
implemented multiple signatures in one account.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3527 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--libsylph/prefs_account.c21
-rw-r--r--libsylph/prefs_account.h6
-rw-r--r--src/compose.c111
-rw-r--r--src/compose.h4
-rw-r--r--src/prefs_account_dialog.c123
-rw-r--r--src/prefs_ui.c142
-rw-r--r--src/prefs_ui.h6
8 files changed, 346 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index af4ffc0f..e72cabe5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-02-07
+
+ * libsylph/prefs_account.[ch]
+ src/compose.[ch]
+ src/prefs_account_dialog.c
+ src/prefs_ui.[ch]: implemented multiple signatures in one account.
+
2017-02-02
* libsylph/ssl.c: supported the location of SSL certificates on
diff --git a/libsylph/prefs_account.c b/libsylph/prefs_account.c
index eeeef5b9..1aecba9c 100644
--- a/libsylph/prefs_account.c
+++ b/libsylph/prefs_account.c
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -83,7 +83,26 @@ static PrefParam param[] = {
{"signature_type", "2", &tmp_ac_prefs.sig_type, P_ENUM},
{"signature_path", "~" G_DIR_SEPARATOR_S DEFAULT_SIGNATURE,
&tmp_ac_prefs.sig_path, P_STRING},
+ {"signature_name", NULL, &tmp_ac_prefs.sig_names[0], P_STRING},
+ {"signature_name2", NULL, &tmp_ac_prefs.sig_names[1], P_STRING},
+ {"signature_name3", NULL, &tmp_ac_prefs.sig_names[2], P_STRING},
+ {"signature_name4", NULL, &tmp_ac_prefs.sig_names[3], P_STRING},
+ {"signature_name5", NULL, &tmp_ac_prefs.sig_names[4], P_STRING},
+ {"signature_name6", NULL, &tmp_ac_prefs.sig_names[5], P_STRING},
+ {"signature_name7", NULL, &tmp_ac_prefs.sig_names[6], P_STRING},
+ {"signature_name8", NULL, &tmp_ac_prefs.sig_names[7], P_STRING},
+ {"signature_name9", NULL, &tmp_ac_prefs.sig_names[8], P_STRING},
+ {"signature_name10", NULL, &tmp_ac_prefs.sig_names[9], P_STRING},
{"signature_text", NULL, &tmp_ac_prefs.sig_text, P_STRING},
+ {"signature_text2", NULL, &tmp_ac_prefs.sig_texts[1], P_STRING},
+ {"signature_text3", NULL, &tmp_ac_prefs.sig_texts[2], P_STRING},
+ {"signature_text4", NULL, &tmp_ac_prefs.sig_texts[3], P_STRING},
+ {"signature_text5", NULL, &tmp_ac_prefs.sig_texts[4], P_STRING},
+ {"signature_text6", NULL, &tmp_ac_prefs.sig_texts[5], P_STRING},
+ {"signature_text7", NULL, &tmp_ac_prefs.sig_texts[6], P_STRING},
+ {"signature_text8", NULL, &tmp_ac_prefs.sig_texts[7], P_STRING},
+ {"signature_text9", NULL, &tmp_ac_prefs.sig_texts[8], P_STRING},
+ {"signature_text10", NULL, &tmp_ac_prefs.sig_texts[9], P_STRING},
{"signature_before_quote", "FALSE", &tmp_ac_prefs.sig_before_quote,
P_BOOL},
{"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL},
diff --git a/libsylph/prefs_account.h b/libsylph/prefs_account.h
index c8e37803..ad899f87 100644
--- a/libsylph/prefs_account.h
+++ b/libsylph/prefs_account.h
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -183,6 +183,10 @@ struct _PrefsAccount
/* Privacy */
gboolean encrypt_to_self;
+
+ /* Compose */
+ gchar *sig_names[10];
+ gchar *sig_texts[10];
};
PrefsAccount *prefs_account_new (void);
diff --git a/src/compose.c b/src/compose.c
index edbff207..fceb8ddb 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* 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
@@ -198,6 +198,8 @@ static void compose_set_toolbar_button_visibility
static GtkWidget *compose_account_option_menu_create
(Compose *compose,
GtkWidget *hbox);
+static GtkWidget *compose_signature_menu_create(Compose *compose,
+ GtkWidget *hbox);
static void compose_set_out_encoding (Compose *compose);
static void compose_set_template_menu (Compose *compose);
static void compose_template_apply (Compose *compose,
@@ -257,6 +259,7 @@ static void compose_set_title (Compose *compose);
static void compose_select_account (Compose *compose,
PrefsAccount *account,
gboolean init);
+static void compose_update_signature_menu (Compose *compose);
static gboolean compose_check_for_valid_recipient
(Compose *compose);
@@ -376,6 +379,8 @@ static gboolean toolbar_button_pressed (GtkWidget *widget,
static void account_activated (GtkMenuItem *menuitem,
gpointer data);
+static void sig_combo_changed (GtkComboBox *combo,
+ gpointer data);
static void attach_selection_changed (GtkTreeSelection *selection,
gpointer data);
@@ -1998,6 +2003,9 @@ static void compose_insert_sig(Compose *compose, gboolean append,
gchar *sig_str;
gboolean prev_autowrap;
+ debug_print("compose_insert_sig: append:%d replace:%d scroll:%d\n",
+ append, replace, scroll);
+
g_return_if_fail(compose->account != NULL);
prev_autowrap = compose->autowrap;
@@ -2091,13 +2099,20 @@ static gchar *compose_get_signature_str(Compose *compose)
g_return_val_if_fail(compose->account != NULL, NULL);
if (compose->account->sig_type == SIG_DIRECT) {
+ gchar *sig_text;
gchar *p, *sp;
+ gint sig_index;
- if (!compose->account->sig_text)
+ sig_index = gtk_combo_box_get_active(GTK_COMBO_BOX(compose->sig_combo));
+ if (sig_index > 0)
+ sig_text = compose->account->sig_texts[sig_index];
+ else
+ sig_text = compose->account->sig_text;
+ if (!sig_text)
return NULL;
- sp = compose->account->sig_text;
- p = sig_body = g_malloc(strlen(compose->account->sig_text) + 1);
+ sp = sig_text;
+ p = sig_body = g_malloc(strlen(sig_text) + 1);
while (*sp) {
if (*sp == '\\' && *(sp + 1) == 'n') {
*p++ = '\n';
@@ -2946,10 +2961,56 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
}
#endif /* USE_GPGME */
+ compose_update_signature_menu(compose);
+
if (!init && compose->mode != COMPOSE_REDIRECT && prefs_common.auto_sig)
compose_insert_sig(compose, TRUE, TRUE, FALSE);
}
+static void compose_update_signature_menu(Compose *compose)
+{
+ GtkTreeModel *model;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ gboolean valid;
+ gint i;
+ gchar *name;
+
+ if (!compose->account)
+ return;
+
+ model = gtk_combo_box_get_model(GTK_COMBO_BOX(compose->sig_combo));
+ store = GTK_LIST_STORE(model);
+ valid = gtk_tree_model_get_iter_first(model, &iter);
+
+ for (i = 0; valid && i < sizeof(compose->account->sig_names) /
+ sizeof(compose->account->sig_names[0]); i++) {
+ if (compose->account->sig_names[i] &&
+ compose->account->sig_names[i][0] != '\0') {
+ name = g_strdup_printf
+ ("%s", compose->account->sig_names[i]);
+ } else {
+ name = g_strdup_printf(_("Signature %d"), i + 1);
+ }
+ gtk_list_store_set(store, &iter, 0, name, -1);
+ g_free(name);
+ valid = gtk_tree_model_iter_next(model, &iter);
+ }
+
+ g_signal_handlers_block_by_func(G_OBJECT(compose->sig_combo),
+ G_CALLBACK(sig_combo_changed), compose);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(compose->sig_combo), 0);
+ g_signal_handlers_unblock_by_func(G_OBJECT(compose->sig_combo),
+ G_CALLBACK(sig_combo_changed),
+ compose);
+
+ if (compose->account->sig_type != SIG_DIRECT) {
+ gtk_widget_set_sensitive(compose->sig_combo, FALSE);
+ } else {
+ gtk_widget_set_sensitive(compose->sig_combo, TRUE);
+ }
+}
+
static gboolean compose_check_for_valid_recipient(Compose *compose)
{
const gchar *to_raw = "", *cc_raw = "", *bcc_raw = "";
@@ -5193,6 +5254,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *from_optmenu_hbox;
+ GtkWidget *sig_combo;
GtkWidget *to_entry;
GtkWidget *to_hbox;
GtkWidget *newsgroups_entry;
@@ -5320,9 +5382,13 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
from_optmenu_hbox = gtk_hbox_new(FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
1, 2, count, count + 1);
+ //gtk_table_attach(GTK_TABLE(table), from_optmenu_hbox,
+ //1, 2, count, count + 1, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
+ gtk_widget_set_size_request(from_optmenu_hbox, 300, -1);
gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
count++;
compose_account_option_menu_create(compose, from_optmenu_hbox);
+ sig_combo = compose_signature_menu_create(compose, from_optmenu_hbox);
/* header labels and entries */
compose_add_entry_field(table, &to_hbox, &to_entry, &count,
@@ -5621,6 +5687,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
compose->followup_hbox = followup_hbox;
compose->followup_entry = followup_entry;
+ compose->sig_combo = sig_combo;
+
/* compose->attach_toggle = attach_toggle; */
#if USE_GPGME
compose->misc_hbox = misc_hbox;
@@ -6043,6 +6111,33 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose,
return optmenu;
}
+static GtkWidget *compose_signature_menu_create(Compose *compose,
+ GtkWidget *hbox)
+{
+ GtkWidget *label;
+ GtkWidget *combo;
+ gint i;
+
+ label = gtk_label_new(_("Signature:"));
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
+
+ combo = gtk_combo_box_new_text();
+ gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
+
+ for (i = 0; i < 10; i++) {
+ gchar buf[256];
+ g_snprintf(buf, sizeof(buf), _("Signature %d"), i + 1);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo), buf);
+ }
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+ g_signal_connect(GTK_COMBO_BOX(combo), "changed",
+ G_CALLBACK(sig_combo_changed), compose);
+
+ gtk_widget_set_tooltip_text(combo, _("Change signature"));
+
+ return combo;
+}
+
static void compose_set_out_encoding(Compose *compose)
{
GtkItemFactoryEntry *entry;
@@ -7319,6 +7414,14 @@ static void account_activated(GtkMenuItem *menuitem, gpointer data)
compose_select_account(compose, ac, FALSE);
}
+static void sig_combo_changed(GtkComboBox *combo, gpointer data)
+{
+ Compose *compose = (Compose *)data;
+
+ if (compose->mode != COMPOSE_REDIRECT && prefs_common.auto_sig)
+ compose_insert_sig(compose, TRUE, TRUE, FALSE);
+}
+
static void attach_selection_changed(GtkTreeSelection *selection, gpointer data)
{
}
diff --git a/src/compose.h b/src/compose.h
index 7076e460..40282cb4 100644
--- a/src/compose.h
+++ b/src/compose.h
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* 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
@@ -201,6 +201,8 @@ struct _Compose
gboolean block_modified;
GtkTooltips *toolbar_tip;
+
+ GtkWidget *sig_combo;
};
struct _AttachInfo
diff --git a/src/prefs_account_dialog.c b/src/prefs_account_dialog.c
index a9cb5335..89a78439 100644
--- a/src/prefs_account_dialog.c
+++ b/src/prefs_account_dialog.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* 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
@@ -122,6 +122,8 @@ static struct Send {
static struct Compose {
GtkWidget *sig_radiobtn;
+ GtkWidget *sig_combo;
+ GtkWidget *signame_entry;
GtkWidget *sig_text;
GtkTextBuffer *sig_buffer;
GtkWidget *sigpath_entry;
@@ -135,6 +137,9 @@ static struct Compose {
GtkWidget *autoreplyto_entry;
gboolean sig_modified;
+ gchar *sig_names[10];
+ gchar *sig_texts[10];
+ gint sig_selected;
} compose;
#if USE_GPGME
@@ -319,8 +324,6 @@ static PrefsUIData ui_data[] = {
prefs_account_enum_set_radiobtn},
{"signature_path", &compose.sigpath_entry,
prefs_set_data_from_entry, prefs_set_entry},
- {"signature_text", &compose.sig_text,
- prefs_set_data_from_text, prefs_set_text},
{"signature_before_quote", &compose.sig_before_quote_chkbtn,
prefs_set_data_from_toggle, prefs_set_toggle},
{"set_autocc", &compose.autocc_chkbtn,
@@ -463,6 +466,8 @@ static void prefs_account_name_entry_changed_cb (GtkWidget *widget,
gpointer data);
static void prefs_account_sig_changed_cb (GtkWidget *widget,
gpointer data);
+static void prefs_account_sig_combo_changed_cb (GtkWidget *widget,
+ gpointer data);
static gint prefs_account_deleted (GtkWidget *widget,
GdkEventAny *event,
@@ -539,6 +544,9 @@ PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs)
(GTK_OPTION_MENU
(basic.protocol_optmenu))),
TRUE);
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(compose.sig_combo), 0);
+
gtk_window_set_title(GTK_WINDOW(dialog.window),
_("Preferences for new account"));
gtk_widget_hide(dialog.apply_btn);
@@ -547,6 +555,24 @@ PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs)
(G_OBJECT(compose.sig_buffer),
G_CALLBACK(prefs_account_sig_changed_cb), NULL);
} else {
+ gint i;
+
+ for (i = 0; i < 10; i++) {
+ g_free(compose.sig_names[i]);
+ compose.sig_names[i] = g_strdup(ac_prefs->sig_names[i]);
+ }
+ g_free(compose.sig_texts[0]);
+ compose.sig_texts[0] = g_strdup(ac_prefs->sig_text);
+ for (i = 1; i < 10; i++) {
+ g_free(compose.sig_texts[i]);
+ compose.sig_texts[i] = g_strdup(ac_prefs->sig_texts[i]);
+ }
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(compose.sig_combo), 0);
+ gtk_entry_set_text(GTK_ENTRY(compose.signame_entry),
+ compose.sig_names[0] ? compose.sig_names[0] : "");
+ prefs_set_escaped_str_to_text(compose.sig_text, compose.sig_texts[0]);
+
prefs_set_dialog(prefs_account_get_params());
gtk_window_set_title(GTK_WINDOW(dialog.window),
_("Account preferences"));
@@ -1273,9 +1299,13 @@ static void prefs_account_compose_create(void)
GtkWidget *vbox1;
GtkWidget *sig_vbox;
GtkWidget *sig_radiobtn;
+ GtkWidget *sig_hbox;
+ GtkWidget *sig_combo;
+ GtkWidget *signame_label;
+ GtkWidget *signame_entry;
+ GtkWidget *sigtext_label;
GtkWidget *sigtext_scrwin;
GtkWidget *sig_text;
- GtkWidget *sig_hbox;
GtkWidget *sigfile_radiobtn;
GtkWidget *sigcmd_radiobtn;
GtkWidget *sigpath_entry;
@@ -1288,6 +1318,7 @@ static void prefs_account_compose_create(void)
GtkWidget *autobcc_entry;
GtkWidget *autoreplyto_chkbtn;
GtkWidget *autoreplyto_entry;
+ gint i;
vbox1 = gtk_vbox_new (FALSE, VSPACING);
gtk_widget_show (vbox1);
@@ -1308,6 +1339,43 @@ static void prefs_account_compose_create(void)
g_object_set_data (G_OBJECT (sig_radiobtn), MENU_VAL_ID,
GINT_TO_POINTER (SIG_DIRECT));
+ sig_hbox = gtk_hbox_new (FALSE, 8);
+ gtk_widget_show (sig_hbox);
+ gtk_box_pack_start (GTK_BOX (sig_vbox), sig_hbox, FALSE, FALSE, 0);
+
+ sig_combo = gtk_combo_box_new_text();
+ gtk_widget_show (sig_combo);
+ gtk_box_pack_start (GTK_BOX (sig_hbox), sig_combo, FALSE, FALSE, 0);
+
+ for (i = 0; i < 10; i++) {
+ gchar buf[256];
+ g_snprintf(buf, sizeof(buf), _("Signature %d"), i + 1);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(sig_combo), buf);
+ }
+ gtk_combo_box_set_active(GTK_COMBO_BOX(sig_combo), 0);
+ g_signal_connect(GTK_COMBO_BOX(sig_combo), "changed",
+ G_CALLBACK(prefs_account_sig_combo_changed_cb), NULL);
+
+ signame_label = gtk_label_new(_("Name:"));
+ gtk_widget_show (signame_label);
+ gtk_box_pack_start (GTK_BOX (sig_hbox), signame_label, FALSE, FALSE, 0);
+
+ signame_entry = gtk_entry_new ();
+ gtk_widget_show (signame_entry);
+ gtk_box_pack_start (GTK_BOX (sig_hbox), signame_entry, TRUE, TRUE, 0);
+
+ sig_hbox = gtk_hbox_new (FALSE, 8);
+ gtk_widget_show (sig_hbox);
+ gtk_box_pack_start (GTK_BOX (sig_vbox), sig_hbox, FALSE, FALSE, 0);
+
+ sigtext_label = gtk_label_new
+ (_("'Signature 1' will be used by default."));
+ gtk_widget_show (sigtext_label);
+ gtk_box_pack_start (GTK_BOX (sig_hbox), sigtext_label, FALSE, FALSE, 0);
+ gtk_label_set_justify (GTK_LABEL (sigtext_label), GTK_JUSTIFY_LEFT);
+ gtk_label_set_line_wrap (GTK_LABEL (sigtext_label), TRUE);
+ gtkut_widget_set_small_font_size (sigtext_label);
+
sigtext_scrwin = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (sigtext_scrwin);
gtk_box_pack_start (GTK_BOX (sig_vbox), sigtext_scrwin, TRUE, TRUE, 0);
@@ -1409,6 +1477,8 @@ static void prefs_account_compose_create(void)
SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
compose.sig_radiobtn = sig_radiobtn;
+ compose.sig_combo = sig_combo;
+ compose.signame_entry = signame_entry;
compose.sig_text = sig_text;
compose.sigpath_entry = sigpath_entry;
@@ -2101,6 +2171,8 @@ static gint prefs_account_apply(void)
RecvProtocol protocol;
GtkWidget *menu;
GtkWidget *menuitem;
+ PrefsAccount *tmp_ac_prefs;
+ gint i;
menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
menuitem = gtk_menu_get_active(GTK_MENU(menu));
@@ -2147,6 +2219,19 @@ static gint prefs_account_apply(void)
}
prefs_set_data_from_dialog(prefs_account_get_params());
+
+ prefs_account_sig_combo_changed_cb(compose.sig_combo, NULL);
+
+ tmp_ac_prefs = prefs_account_get_tmp_prefs();
+ g_free(tmp_ac_prefs->sig_text);
+ tmp_ac_prefs->sig_text = g_strdup(compose.sig_texts[0]);
+ for (i = 0; i < 10; i++) {
+ g_free(tmp_ac_prefs->sig_names[i]);
+ tmp_ac_prefs->sig_names[i] = g_strdup(compose.sig_names[i]);
+ g_free(tmp_ac_prefs->sig_texts[i]);
+ tmp_ac_prefs->sig_texts[i] = g_strdup(compose.sig_texts[i]);
+ }
+
return 0;
}
@@ -2221,6 +2306,36 @@ static void prefs_account_sig_changed_cb(GtkWidget *widget, gpointer data)
compose.sig_modified = TRUE;
}
+static void prefs_account_sig_combo_changed_cb(GtkWidget *widget, gpointer data)
+{
+ gint cur_page;
+ gint new_page;
+
+ g_print("combo changed\n");
+
+ cur_page = compose.sig_selected;
+ new_page = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+ g_print(" cur page: %d\n", cur_page);
+ g_print(" new page: %d\n", new_page);
+
+ /* Save current one */
+ g_free(compose.sig_names[cur_page]);
+ compose.sig_names[cur_page] =
+ gtk_editable_get_chars(GTK_EDITABLE(compose.signame_entry), 0, -1);
+ g_free(compose.sig_texts[cur_page]);
+ compose.sig_texts[cur_page] =
+ prefs_get_escaped_str_from_text(compose.sig_text);
+
+ /* Restore another one */
+ if (cur_page != new_page) {
+ gtk_entry_set_text(GTK_ENTRY(compose.signame_entry),
+ compose.sig_names[new_page] ? compose.sig_names[new_page] : "");
+ prefs_set_escaped_str_to_text(compose.sig_text,
+ compose.sig_texts[new_page]);
+ compose.sig_selected = new_page;
+ }
+}
+
static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
{
PrefsUIData *ui_data;
diff --git a/src/prefs_ui.c b/src/prefs_ui.c
index 1e718467..a3a8f745 100644
--- a/src/prefs_ui.c
+++ b/src/prefs_ui.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* 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
@@ -297,12 +297,54 @@ void prefs_set_entry(PrefParam *pparam)
}
}
+gchar *prefs_get_escaped_str_from_text(GtkWidget *widget)
+{
+ gchar *text = NULL, *tp = NULL;
+ gchar *str, *p;
+
+ g_return_val_if_fail(widget != NULL, NULL);
+
+ if (GTK_IS_EDITABLE(widget)) {
+ tp = text = gtk_editable_get_chars
+ (GTK_EDITABLE(widget), 0, -1);
+ } else if (GTK_IS_TEXT_VIEW(widget)) {
+ GtkTextView *textview = GTK_TEXT_VIEW(widget);
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+
+ buffer = gtk_text_view_get_buffer(textview);
+ gtk_text_buffer_get_start_iter(buffer, &start);
+ gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
+ tp = text = gtk_text_buffer_get_text
+ (buffer, &start, &end, FALSE);
+ }
+
+ g_return_val_if_fail(tp != NULL && text != NULL, NULL);
+
+ if (text[0] == '\0') {
+ g_free(text);
+ return NULL;
+ }
+
+ p = str = g_malloc(strlen(text) * 2 + 1);
+ while (*tp) {
+ if (*tp == '\n') {
+ *p++ = '\\';
+ *p++ = 'n';
+ tp++;
+ } else
+ *p++ = *tp++;
+ }
+ *p = '\0';
+ g_free(text);
+
+ return str;
+}
+
void prefs_set_data_from_text(PrefParam *pparam)
{
PrefsUIData *ui_data;
gchar **str;
- gchar *text = NULL, *tp = NULL;
- gchar *tmp, *tmpp;
ui_data = (PrefsUIData *)pparam->ui_data;
g_return_if_fail(ui_data != NULL);
@@ -314,41 +356,7 @@ void prefs_set_data_from_text(PrefParam *pparam)
case P_STRING:
str = (gchar **)pparam->data;
g_free(*str);
- if (GTK_IS_EDITABLE(*ui_data->widget)) {
- tp = text = gtk_editable_get_chars
- (GTK_EDITABLE(*ui_data->widget), 0, -1);
- } else if (GTK_IS_TEXT_VIEW(*ui_data->widget)) {
- GtkTextView *textview = GTK_TEXT_VIEW(*ui_data->widget);
- GtkTextBuffer *buffer;
- GtkTextIter start, end;
-
- buffer = gtk_text_view_get_buffer(textview);
- gtk_text_buffer_get_start_iter(buffer, &start);
- gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
- tp = text = gtk_text_buffer_get_text
- (buffer, &start, &end, FALSE);
- }
-
- g_return_if_fail(tp != NULL && text != NULL);
-
- if (text[0] == '\0') {
- *str = NULL;
- g_free(text);
- break;
- }
-
- tmpp = tmp = g_malloc(strlen(text) * 2 + 1);
- while (*tp) {
- if (*tp == '\n') {
- *tmpp++ = '\\';
- *tmpp++ = 'n';
- tp++;
- } else
- *tmpp++ = *tp++;
- }
- *tmpp = '\0';
- *str = tmp;
- g_free(text);
+ *str = prefs_get_escaped_str_from_text(*ui_data->widget);
break;
default:
g_warning("Invalid PrefType for GtkTextView widget: %d\n",
@@ -356,15 +364,44 @@ void prefs_set_data_from_text(PrefParam *pparam)
}
}
-void prefs_set_text(PrefParam *pparam)
+void prefs_set_escaped_str_to_text(GtkWidget *widget, const gchar *str)
{
- PrefsUIData *ui_data;
- gchar *buf, *sp, *bufp;
- gchar **str;
+ gchar *buf, *bufp;
+ const gchar *sp;
GtkTextView *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
+ g_return_if_fail(widget != NULL);
+
+ if (str) {
+ bufp = buf = g_malloc(strlen(str) + 1);
+ sp = str;
+ while (*sp) {
+ if (*sp == '\\' && *(sp + 1) == 'n') {
+ *bufp++ = '\n';
+ sp += 2;
+ } else
+ *bufp++ = *sp++;
+ }
+ *bufp = '\0';
+ } else
+ buf = g_strdup("");
+
+ text = GTK_TEXT_VIEW(widget);
+ buffer = gtk_text_view_get_buffer(text);
+ gtk_text_buffer_set_text(buffer, "", 0);
+ gtk_text_buffer_get_start_iter(buffer, &iter);
+ gtk_text_buffer_insert(buffer, &iter, buf, -1);
+
+ g_free(buf);
+}
+
+void prefs_set_text(PrefParam *pparam)
+{
+ PrefsUIData *ui_data;
+ gchar **str;
+
ui_data = (PrefsUIData *)pparam->ui_data;
g_return_if_fail(ui_data != NULL);
g_return_if_fail(*ui_data->widget != NULL);
@@ -372,26 +409,7 @@ void prefs_set_text(PrefParam *pparam)
switch (pparam->type) {
case P_STRING:
str = (gchar **)pparam->data;
- if (*str) {
- bufp = buf = g_malloc(strlen(*str) + 1);
- sp = *str;
- while (*sp) {
- if (*sp == '\\' && *(sp + 1) == 'n') {
- *bufp++ = '\n';
- sp += 2;
- } else
- *bufp++ = *sp++;
- }
- *bufp = '\0';
- } else
- buf = g_strdup("");
-
- text = GTK_TEXT_VIEW(*ui_data->widget);
- buffer = gtk_text_view_get_buffer(text);
- gtk_text_buffer_set_text(buffer, "", 0);
- gtk_text_buffer_get_start_iter(buffer, &iter);
- gtk_text_buffer_insert(buffer, &iter, buf, -1);
- g_free(buf);
+ prefs_set_escaped_str_to_text(*ui_data->widget, *str);
break;
default:
g_warning("Invalid PrefType for GtkTextView widget: %d\n",
diff --git a/src/prefs_ui.h b/src/prefs_ui.h
index f0eadeb6..cfdf3539 100644
--- a/src/prefs_ui.h
+++ b/src/prefs_ui.h
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2017 Hiroyuki Yamamoto
*
* 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
@@ -176,4 +176,8 @@ void prefs_set_fontbtn (PrefParam *pparam);
void prefs_set_data_from_optmenu(PrefParam *pparam);
void prefs_set_optmenu (PrefParam *pparam);
+gchar *prefs_get_escaped_str_from_text (GtkWidget *widget);
+void prefs_set_escaped_str_to_text (GtkWidget *widget,
+ const gchar *str);
+
#endif /* __PREFS_UI_H__ */