summaryrefslogtreecommitdiff
path: root/src/prefs_toolbar.c
diff options
context:
space:
mode:
authorSimeon Simeonov2018-02-26 11:23:00 +0100
committerSimeon Simeonov2018-02-26 11:23:00 +0100
commit0b3cbf57875fd692e4ba0b336fefa4bee1ed00dc (patch)
treeaf916a30553c78ce9d4f2d8658656a175c5b6921 /src/prefs_toolbar.c
Initial commit for sylpheed 3.7.0
Diffstat (limited to 'src/prefs_toolbar.c')
-rw-r--r--src/prefs_toolbar.c409
1 files changed, 409 insertions, 0 deletions
diff --git a/src/prefs_toolbar.c b/src/prefs_toolbar.c
new file mode 100644
index 0000000..1aad751
--- /dev/null
+++ b/src/prefs_toolbar.c
@@ -0,0 +1,409 @@
1/*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2008 Hiroyuki Yamamoto
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21# include "config.h"
22#endif
23
24#include "defs.h"
25
26#include <glib.h>
27#include <glib/gi18n.h>
28#include <gtk/gtkmain.h>
29#include <gtk/gtklabel.h>
30#include <gtk/gtkstock.h>
31
32#include <string.h>
33
34#include "prefs_toolbar.h"
35#include "prefs_display_items.h"
36
37static PrefsDisplayItem all_items[] =
38{
39 {T_SEPARATOR, "separator", N_("---- Separator ----"),
40 NULL, 0, NULL, TRUE, FALSE},
41 {T_GET, "get", N_("Get"),
42 N_("Incorporate new mail"),
43 STOCK_PIXMAP_MAIL_RECEIVE, NULL, FALSE, FALSE},
44 {T_GET_ALL, "get-all", N_("Get all"),
45 N_("Incorporate new mail of all accounts"),
46 STOCK_PIXMAP_MAIL_RECEIVE_ALL, NULL, FALSE, FALSE},
47 {T_REMOTE_MAILBOX, "remote-mailbox", N_("Remote mailbox"),
48 N_("POP3 Remote mailbox"),
49 STOCK_PIXMAP_REMOTE_MAILBOX, GTK_STOCK_NETWORK, FALSE, FALSE},
50 {T_SEND_QUEUE, "send-queue", N_("Send"),
51 N_("Send queued message(s)"),
52 STOCK_PIXMAP_MAIL_SEND, NULL, FALSE, FALSE},
53 {T_COMPOSE, "compose", N_("Compose"),
54 N_("Compose new message"),
55 STOCK_PIXMAP_MAIL_COMPOSE, NULL, FALSE, FALSE},
56 {T_REPLY, "reply", N_("Reply"),
57 N_("Reply to the message"),
58 STOCK_PIXMAP_MAIL_REPLY, NULL, FALSE, FALSE},
59 {T_REPLY_ALL, "reply-all", N_("Reply all"),
60 N_("Reply to all"),
61 STOCK_PIXMAP_MAIL_REPLY_TO_ALL, NULL, FALSE, FALSE},
62 {T_FORWARD, "forward", N_("Forward"),
63 N_("Forward the message"),
64 STOCK_PIXMAP_MAIL_FORWARD, NULL, FALSE, FALSE},
65 {T_DELETE, "delete", N_("Delete"),
66 N_("Delete the message"),
67 STOCK_PIXMAP_DELETE, NULL, FALSE, FALSE},
68 {T_JUNK, "junk", N_("Junk"),
69 N_("Set as junk mail"),
70 STOCK_PIXMAP_SPAM, NULL, FALSE, FALSE},
71 {T_NOTJUNK, "not-junk", N_("Not junk"),
72 N_("Set as not junk mail"),
73 STOCK_PIXMAP_NOTSPAM, NULL, FALSE, FALSE},
74 {T_NEXT, "next", N_("Next"),
75 N_("Next unread message"),
76 STOCK_PIXMAP_NEXT, GTK_STOCK_GO_DOWN, FALSE, FALSE},
77 {T_PREV, "prev", N_("Prev"),
78 N_("Previous unread message"),
79 STOCK_PIXMAP_PREV, GTK_STOCK_GO_UP, FALSE, FALSE},
80 {T_SEARCH, "search", N_("Search"),
81 N_("Search messages"),
82 STOCK_PIXMAP_SEARCH, GTK_STOCK_FIND, FALSE, FALSE},
83 {T_PRINT, "print", N_("Print"),
84 N_("Print message"),
85 STOCK_PIXMAP_PRINT, GTK_STOCK_PRINT, FALSE, FALSE},
86 {T_STOP, "stop", N_("Stop"),
87 N_("Stop receiving"),
88 STOCK_PIXMAP_STOP, GTK_STOCK_STOP, FALSE, FALSE},
89 {T_ADDRESS_BOOK, "address-book", N_("Address"),
90 N_("Address book"),
91 STOCK_PIXMAP_ADDRESS_BOOK, NULL, FALSE, FALSE},
92 {T_EXECUTE, "execute", N_("Execute"),
93 N_("Execute marked process"),
94 STOCK_PIXMAP_EXECUTE, GTK_STOCK_EXECUTE, FALSE, FALSE},
95 {T_COMMON_PREFS, "common-prefs", N_("Prefs"),
96 N_("Common preferences"),
97 STOCK_PIXMAP_COMMON_PREFS, GTK_STOCK_PREFERENCES, FALSE, FALSE},
98 {T_ACCOUNT_PREFS, "account-prefs", N_("Account"),
99 N_("Account preferences"),
100 STOCK_PIXMAP_ACCOUNT_PREFS, GTK_STOCK_PREFERENCES, FALSE, FALSE},
101
102 {T_SEND, "send", N_("Send"),
103 N_("Send message"),
104 STOCK_PIXMAP_MAIL_SEND, NULL, FALSE, FALSE},
105 {T_SEND_LATER, "send-later", N_("Send later"),
106 N_("Put into queue folder and send later"),
107 STOCK_PIXMAP_MAIL_SEND_QUEUE, NULL, FALSE, FALSE},
108 {T_DRAFT, "draft", N_("Draft"),
109 N_("Save to draft folder"),
110 STOCK_PIXMAP_SAVE, GTK_STOCK_SAVE, FALSE, FALSE},
111 {T_INSERT_FILE, "insert-file", N_("Insert"),
112 N_("Insert file"),
113 STOCK_PIXMAP_INSERT_FILE, NULL, FALSE, FALSE},
114 {T_ATTACH_FILE, "attach-file", N_("Attach"),
115 N_("Attach file"),
116 STOCK_PIXMAP_MAIL_ATTACH, NULL, FALSE, FALSE},
117 {T_SIGNATURE, "signature", N_("Signature"),
118 N_("Append signature"),
119 STOCK_PIXMAP_SIGN, NULL, FALSE, FALSE},
120 {T_EDITOR, "editor", N_("Editor"),
121 N_("Edit with external editor"),
122 STOCK_PIXMAP_EDIT, GTK_STOCK_EDIT, FALSE, FALSE},
123 {T_LINEWRAP, "linewrap", N_("Linewrap"),
124 N_("Wrap all long lines"),
125 STOCK_PIXMAP_LINEWRAP, NULL, FALSE, FALSE},
126
127 {-1, NULL, NULL, FALSE, FALSE}
128};
129
130static gint main_available_items[] =
131{
132 T_SEPARATOR,
133 T_GET,
134 T_GET_ALL,
135 T_REMOTE_MAILBOX,
136 T_SEND_QUEUE,
137 T_COMPOSE,
138 T_REPLY,
139 T_REPLY_ALL,
140 T_FORWARD,
141 T_DELETE,
142 T_JUNK,
143 T_NOTJUNK,
144 T_NEXT,
145 T_PREV,
146 T_SEARCH,
147 T_PRINT,
148 T_STOP,
149 T_ADDRESS_BOOK,
150 T_EXECUTE,
151 T_COMMON_PREFS,
152 T_ACCOUNT_PREFS,
153 -1
154};
155
156static gint compose_available_items[] =
157{
158 T_SEPARATOR,
159 T_SEND,
160 T_SEND_LATER,
161 T_DRAFT,
162 T_INSERT_FILE,
163 T_ATTACH_FILE,
164 T_SIGNATURE,
165 T_EDITOR,
166 T_LINEWRAP,
167 T_ADDRESS_BOOK,
168 T_COMMON_PREFS,
169 T_ACCOUNT_PREFS,
170 -1
171};
172
173static gint default_main_items[] =
174{
175 T_GET,
176 T_GET_ALL,
177 T_SEPARATOR,
178 T_SEND_QUEUE,
179 T_SEPARATOR,
180 T_COMPOSE,
181 T_REPLY,
182 T_REPLY_ALL,
183 T_FORWARD,
184 T_SEPARATOR,
185 T_DELETE,
186 T_JUNK,
187 T_SEPARATOR,
188 T_NEXT,
189 T_SEPARATOR,
190 T_SEARCH,
191 T_PRINT,
192 T_ADDRESS_BOOK,
193 -1
194};
195
196static gint default_compose_items[] =
197{
198 T_SEND,
199 T_SEND_LATER,
200 T_DRAFT,
201 T_SEPARATOR,
202 T_INSERT_FILE,
203 T_ATTACH_FILE,
204 T_SEPARATOR,
205 T_SIGNATURE,
206 T_SEPARATOR,
207 T_EDITOR,
208 T_LINEWRAP,
209 T_SEPARATOR,
210 T_ADDRESS_BOOK,
211 -1
212};
213
214gint prefs_toolbar_open(ToolbarType type, gint *visible_items,
215 GList **item_list)
216{
217 PrefsDisplayItemsDialog *dialog;
218 GList *list;
219 gint ret = 0;
220
221 dialog = prefs_display_items_dialog_create();
222 gtk_window_set_title(GTK_WINDOW(dialog->window),
223 _("Customize toolbar"));
224 gtk_label_set_text(GTK_LABEL(dialog->label),
225 _("Select items to be displayed on the toolbar. You can modify\n"
226 "the order by using the Up / Down button."));
227
228 switch (type) {
229 case TOOLBAR_MAIN:
230 prefs_display_items_dialog_set_available
231 (dialog, all_items, main_available_items);
232 prefs_display_items_dialog_set_default_visible
233 (dialog, default_main_items);
234 break;
235 case TOOLBAR_COMPOSE:
236 default:
237 prefs_display_items_dialog_set_available
238 (dialog, all_items, compose_available_items);
239 prefs_display_items_dialog_set_default_visible
240 (dialog, default_compose_items);
241 break;
242 }
243
244 prefs_display_items_dialog_set_visible(dialog, visible_items);
245
246 gtk_widget_show(dialog->window);
247
248 while (dialog->finished == FALSE)
249 gtk_main_iteration();
250
251 if (dialog->cancelled) {
252 ret = -1;
253 *item_list = NULL;
254 } else {
255 list = dialog->visible_items;
256 dialog->visible_items = NULL;
257 *item_list = list;
258 }
259
260 prefs_display_items_dialog_destroy(dialog);
261
262 return ret;
263}
264
265const PrefsDisplayItem *prefs_toolbar_get_item_from_name(const gchar *name)
266{
267 gint i;
268
269 for (i = 0; all_items[i].id != -1; i++) {
270 if (!strcmp(name, all_items[i].name))
271 return &all_items[i];
272 }
273
274 return NULL;
275}
276
277const PrefsDisplayItem *prefs_toolbar_get_item_from_id(gint id)
278{
279 gint i;
280
281 for (i = 0; all_items[i].id != -1; i++) {
282 if (id == all_items[i].id)
283 return &all_items[i];
284 }
285
286 return NULL;
287}
288
289GList *prefs_toolbar_get_item_list_from_name_list(const gchar *name_list)
290{
291 gint i;
292 gchar **array;
293 GList *list = NULL;
294
295 array = g_strsplit(name_list, ",", 0);
296
297 for (i = 0; array[i] != NULL; i++) {
298 gchar *name = array[i];
299 const PrefsDisplayItem *item;
300
301 g_strstrip(name);
302 item = prefs_toolbar_get_item_from_name(name);
303 if (item)
304 list = g_list_append(list, (gpointer)item);
305 }
306
307 g_strfreev(array);
308
309 return list;
310}
311
312gint *prefs_toolbar_get_id_list_from_name_list(const gchar *name_list)
313{
314 gint i;
315 gchar **array;
316 GArray *iarray;
317
318 iarray = g_array_new(FALSE, FALSE, sizeof(gint));
319 array = g_strsplit(name_list, ",", 0);
320
321 for (i = 0; array[i] != NULL; i++) {
322 gchar *name = array[i];
323 const PrefsDisplayItem *item;
324
325 g_strstrip(name);
326 item = prefs_toolbar_get_item_from_name(name);
327 if (item)
328 g_array_append_val(iarray, item->id);
329 }
330
331 i = -1;
332 g_array_append_val(iarray, i);
333
334 g_strfreev(array);
335
336 return (gint *)g_array_free(iarray, FALSE);
337}
338
339gchar *prefs_toolbar_get_name_list_from_item_list(GList *item_list)
340{
341 GString *str;
342 GList *cur;
343
344 str = g_string_new(NULL);
345
346 for (cur = item_list; cur != NULL; cur = cur->next) {
347 const PrefsDisplayItem *item = cur->data;
348
349 g_string_append(str, item->name);
350 if (cur->next)
351 g_string_append_c(str, ',');
352 }
353
354 return g_string_free(str, FALSE);
355}
356
357const gchar *prefs_toolbar_get_default_main_setting_name_list(void)
358{
359 GString *str;
360 gint i;
361 static gchar *default_name_list = NULL;
362
363 if (default_name_list)
364 return default_name_list;
365
366 str = g_string_new(NULL);
367
368 for (i = 0; default_main_items[i] != -1; i++) {
369 const PrefsDisplayItem *item;
370
371 item = prefs_toolbar_get_item_from_id(default_main_items[i]);
372 if (item) {
373 g_string_append(str, item->name);
374 if (default_main_items[i + 1] != -1)
375 g_string_append_c(str, ',');
376 }
377 }
378
379 default_name_list = g_string_free(str, FALSE);
380
381 return default_name_list;
382}
383
384const gchar *prefs_toolbar_get_default_compose_setting_name_list(void)
385{
386 GString *str;
387 gint i;
388 static gchar *default_name_list = NULL;
389
390 if (default_name_list)
391 return default_name_list;
392
393 str = g_string_new(NULL);
394
395 for (i = 0; default_compose_items[i] != -1; i++) {
396 const PrefsDisplayItem *item;
397
398 item = prefs_toolbar_get_item_from_id(default_compose_items[i]);
399 if (item) {
400 g_string_append(str, item->name);
401 if (default_compose_items[i + 1] != -1)
402 g_string_append_c(str, ',');
403 }
404 }
405
406 default_name_list = g_string_free(str, FALSE);
407
408 return default_name_list;
409}