evolution-3.6.4/modules/prefer-plain/plugin/config-ui.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  */
 16 
 17 #ifdef HAVE_CONFIG_H
 18 #include <config.h>
 19 #endif
 20 
 21 #include <gtk/gtk.h>
 22 #include <glib/gi18n.h>
 23 
 24 #include <mail/em-config.h>
 25 
 26 #include <libedataserverui/libedataserverui.h>
 27 
 28 GtkWidget *prefer_plain_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data);
 29 
 30 enum {
 31 	EPP_NORMAL,
 32 	EPP_PREFER,
 33 	EPP_TEXT
 34 };
 35 
 36 static GSettings *epp_settings = NULL;
 37 static gint epp_mode = -1;
 38 static gboolean epp_show_suppressed = TRUE;
 39 
 40 static struct {
 41 	const gchar *key;
 42 	const gchar *label;
 43 	const gchar *description;
 44 } epp_options[] = {
 45 	{ "normal",
 46 	  N_("Show HTML if present"),
 47 	  N_("Let Evolution choose the best part to show.") },
 48 
 49 	{ "prefer_plain",
 50 	  N_("Show plain text if present"),
 51 	  N_("Show plain text part, if present, otherwise "
 52 	     "let Evolution choose the best part to show.") },
 53 
 54 	{ "only_plain",
 55 	  N_("Only ever show plain text"),
 56 	  N_("Always show plain text part and make attachments "
 57 	     "from other parts, if requested.") },
 58 };
 59 
 60 static void
 61 update_info_label (GtkWidget *info_label,
 62                    guint mode)
 63 {
 64 	gchar *str = g_strconcat ("<i>", _(epp_options[mode > 2 ? 0 : mode].description), "</i>", NULL);
 65 
 66 	gtk_label_set_markup (GTK_LABEL (info_label), str);
 67 
 68 	g_free (str);
 69 }
 70 
 71 static void
 72 epp_mode_changed (GtkComboBox *dropdown,
 73                   GtkWidget *info_label)
 74 {
 75 	epp_mode = gtk_combo_box_get_active (dropdown);
 76 	if (epp_mode > 2)
 77 		epp_mode = 0;
 78 
 79 	g_settings_set_string (epp_settings, "mode", epp_options[epp_mode].key);
 80 	update_info_label (info_label, epp_mode);
 81 }
 82 
 83 static void
 84 epp_show_suppressed_toggled (GtkToggleButton *check,
 85                              gpointer data)
 86 {
 87 	g_return_if_fail (check != NULL);
 88 
 89 	epp_show_suppressed = gtk_toggle_button_get_active (check);
 90 	g_settings_set_boolean (epp_settings, "show-suppressed", epp_show_suppressed);
 91 }
 92 
 93 GtkWidget *
 94 prefer_plain_page_factory (EPlugin *epl,
 95                            struct _EConfigHookItemFactoryData *data)
 96 {
 97 	GtkComboBox *dropdown;
 98 	GtkCellRenderer *cell;
 99 	GtkListStore *store;
100 	GtkWidget *dropdown_label, *info, *check;
101 	guint i;
102 	GtkTreeIter iter;
103 
104 	if (data->old)
105 		return data->old;
106 
107 	check = gtk_check_button_new_with_mnemonic (_("Show s_uppressed HTML parts as attachments"));
108 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), epp_show_suppressed);
109 	gtk_widget_show (check);
110 	g_signal_connect (
111 		check, "toggled",
112 		G_CALLBACK (epp_show_suppressed_toggled), NULL);
113 
114 	dropdown = (GtkComboBox *) gtk_combo_box_new ();
115 	cell = gtk_cell_renderer_text_new ();
116 	store = gtk_list_store_new (1, G_TYPE_STRING);
117 	for (i = 0; i < G_N_ELEMENTS (epp_options); i++) {
118 		gtk_list_store_append (store, &iter);
119 		gtk_list_store_set (store, &iter, 0, _(epp_options[i].label), -1);
120 	}
121 
122 	gtk_cell_layout_pack_start ((GtkCellLayout *) dropdown, cell, TRUE);
123 	gtk_cell_layout_set_attributes ((GtkCellLayout *) dropdown, cell, "text", 0, NULL);
124 	gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store);
125 	/*gtk_combo_box_set_active(dropdown, -1);*/
126 	gtk_combo_box_set_active (dropdown, epp_mode);
127 	gtk_widget_show ((GtkWidget *) dropdown);
128 
129 	dropdown_label = gtk_label_new_with_mnemonic (_("HTML _Mode"));
130 	gtk_widget_show (dropdown_label);
131 	gtk_label_set_mnemonic_widget (GTK_LABEL (dropdown_label), (GtkWidget *) dropdown);
132 
133 	info = gtk_label_new (NULL);
134 	gtk_misc_set_alignment (GTK_MISC (info), 0.0, 0.5);
135 	gtk_label_set_line_wrap (GTK_LABEL (info), TRUE);
136 
137 	gtk_widget_show (info);
138 	update_info_label (info, epp_mode);
139 
140 	g_signal_connect (
141 		dropdown, "changed",
142 		G_CALLBACK (epp_mode_changed), info);
143 
144 	g_object_get (data->parent, "n-rows", &i, NULL);
145 	gtk_table_attach ((GtkTable *) data->parent, check, 0, 2, i, i + 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
146 	gtk_table_attach ((GtkTable *) data->parent, dropdown_label, 0, 1, i + 1, i + 2, 0, 0, 0, 0);
147 	gtk_table_attach ((GtkTable *) data->parent, (GtkWidget *) dropdown, 1, 2, i + 1, i + 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
148 	gtk_table_attach ((GtkTable *) data->parent, info, 1, 2, i + 2, i + 3, GTK_FILL | GTK_EXPAND, 0, 0, 0);
149 
150 	/* since this isnt dynamic, we don't need to track each item */
151 
152 	return (GtkWidget *) dropdown;
153 }
154 
155 gint e_plugin_lib_enable (EPlugin *ep, gint enable);
156 
157 gint
158 e_plugin_lib_enable (EPlugin *ep,
159                      gint enable)
160 {
161 	gchar *key;
162 	gint i;
163 
164 	if (epp_settings || epp_mode != -1)
165 		return 0;
166 
167 	if (enable) {
168 
169 		epp_settings = g_settings_new ("org.gnome.evolution.plugin.prefer-plain");
170 		key = g_settings_get_string (epp_settings, "mode");
171 		if (key) {
172 			for (i = 0; i < G_N_ELEMENTS (epp_options); i++) {
173 				if (!strcmp (epp_options[i].key, key)) {
174 					epp_mode = i;
175 					break;
176 				}
177 			}
178 			g_free (key);
179 		} else {
180 			epp_mode = 0;
181 		}
182 
183 		epp_show_suppressed = g_settings_get_boolean (epp_settings, "show-suppressed");
184 	} else {
185 		if (epp_settings) {
186 			g_object_unref (epp_settings);
187 			epp_settings = NULL;
188 		}
189 	}
190 
191 	return 0;
192 }