Statistics
| Revision:

root / src / prefs_toolbar.c @ 3039

History | View | Annotate | Download (9.5 kB)

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
37
static 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
         -1, 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
         -1, GTK_STOCK_GO_DOWN, FALSE, FALSE},
77
        {T_PREV,        "prev",                N_("Prev"),
78
         N_("Previous unread message"),
79
         -1, GTK_STOCK_GO_UP, FALSE, FALSE},
80
        {T_SEARCH,        "search",        N_("Search"),
81
         N_("Search messages"),
82
         -1, GTK_STOCK_FIND, FALSE, FALSE},
83
        {T_PRINT,        "print",        N_("Print"),
84
         N_("Print message"),
85
         -1, GTK_STOCK_PRINT, FALSE, FALSE},
86
        {T_STOP,        "stop",                N_("Stop"),
87
         N_("Stop receiving"),
88
         -1, 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
         -1, GTK_STOCK_EXECUTE, FALSE, FALSE},
95
        {T_COMMON_PREFS,        "common-prefs",        N_("Prefs"),
96
         N_("Common preferences"),
97
         -1, GTK_STOCK_PREFERENCES, FALSE, FALSE},
98
        {T_ACCOUNT_PREFS,        "account-prefs", N_("Account"),
99
         N_("Account preferences"),
100
         -1, 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
         -1, 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
#ifdef GTK_STOCK_EDIT
123
         -1, GTK_STOCK_EDIT, FALSE, FALSE},
124
#else
125
         STOCK_PIXMAP_MAIL_COMPOSE, NULL, FALSE, FALSE},
126
#endif
127
        {T_LINEWRAP,        "linewrap",        N_("Linewrap"),
128
         N_("Wrap all long lines"),
129
         STOCK_PIXMAP_LINEWRAP, NULL, FALSE, FALSE},
130
131
        {-1,                NULL,                NULL,                        FALSE, FALSE}
132
};
133
134
static gint main_available_items[] =
135
{
136
        T_SEPARATOR,
137
        T_GET,
138
        T_GET_ALL,
139
        T_REMOTE_MAILBOX,
140
        T_SEND_QUEUE,
141
        T_COMPOSE,
142
        T_REPLY,
143
        T_REPLY_ALL,
144
        T_FORWARD,
145
        T_DELETE,
146
        T_JUNK,
147
        T_NOTJUNK,
148
        T_NEXT,
149
        T_PREV,
150
        T_SEARCH,
151
        T_PRINT,
152
        T_STOP,
153
        T_ADDRESS_BOOK,
154
        T_EXECUTE,
155
        T_COMMON_PREFS,
156
        T_ACCOUNT_PREFS,
157
        -1
158
};
159
160
static gint compose_available_items[] =
161
{
162
        T_SEPARATOR,
163
        T_SEND,
164
        T_SEND_LATER,
165
        T_DRAFT,
166
        T_INSERT_FILE,
167
        T_ATTACH_FILE,
168
        T_SIGNATURE,
169
        T_EDITOR,
170
        T_LINEWRAP,
171
        T_ADDRESS_BOOK,
172
        T_COMMON_PREFS,
173
        T_ACCOUNT_PREFS,
174
        -1
175
};
176
177
static gint default_main_items[] =
178
{
179
        T_GET,
180
        T_GET_ALL,
181
        T_SEPARATOR,
182
        T_SEND_QUEUE,
183
        T_SEPARATOR,
184
        T_COMPOSE,
185
        T_REPLY,
186
        T_REPLY_ALL,
187
        T_FORWARD,
188
        T_SEPARATOR,
189
        T_DELETE,
190
        T_JUNK,
191
        T_SEPARATOR,
192
        T_NEXT,
193
        T_SEPARATOR,
194
        T_SEARCH,
195
        T_PRINT,
196
        T_ADDRESS_BOOK,
197
        -1
198
};
199
200
static gint default_compose_items[] =
201
{
202
        T_SEND,
203
        T_SEND_LATER,
204
        T_DRAFT,
205
        T_SEPARATOR,
206
        T_INSERT_FILE,
207
        T_ATTACH_FILE,
208
        T_SEPARATOR,
209
        T_SIGNATURE,
210
        T_SEPARATOR,
211
        T_EDITOR,
212
        T_LINEWRAP,
213
        T_SEPARATOR,
214
        T_ADDRESS_BOOK,
215
        -1
216
};
217
218
gint prefs_toolbar_open(ToolbarType type, gint *visible_items,
219
                        GList **item_list)
220
{
221
        PrefsDisplayItemsDialog *dialog;
222
        GList *list;
223
        gint ret = 0;
224
225
        dialog = prefs_display_items_dialog_create();
226
        gtk_window_set_title(GTK_WINDOW(dialog->window),
227
                             _("Customize toolbar"));
228
        gtk_label_set_text(GTK_LABEL(dialog->label),
229
                           _("Select items to be displayed on the toolbar. You can modify\n"
230
                             "the order by using the Up / Down button."));
231
232
        switch (type) {
233
        case TOOLBAR_MAIN:
234
                prefs_display_items_dialog_set_available
235
                        (dialog, all_items, main_available_items);
236
                prefs_display_items_dialog_set_default_visible
237
                        (dialog, default_main_items);
238
                break;
239
        case TOOLBAR_COMPOSE:
240
        default:
241
                prefs_display_items_dialog_set_available
242
                        (dialog, all_items, compose_available_items);
243
                prefs_display_items_dialog_set_default_visible
244
                        (dialog, default_compose_items);
245
                break;
246
        }
247
248
        prefs_display_items_dialog_set_visible(dialog, visible_items);
249
250
        gtk_widget_show(dialog->window);
251
252
        while (dialog->finished == FALSE)
253
                gtk_main_iteration();
254
255
        if (dialog->cancelled) {
256
                ret = -1;
257
                *item_list = NULL;
258
        } else {
259
                list = dialog->visible_items;
260
                dialog->visible_items = NULL;
261
                *item_list = list;
262
        }
263
264
        prefs_display_items_dialog_destroy(dialog);
265
266
        return ret;
267
}
268
269
const PrefsDisplayItem *prefs_toolbar_get_item_from_name(const gchar *name)
270
{
271
        gint i;
272
273
        for (i = 0; all_items[i].id != -1; i++) {
274
                if (!strcmp(name, all_items[i].name))
275
                        return &all_items[i];
276
        }
277
278
        return NULL;
279
}
280
281
const PrefsDisplayItem *prefs_toolbar_get_item_from_id(gint id)
282
{
283
        gint i;
284
285
        for (i = 0; all_items[i].id != -1; i++) {
286
                if (id == all_items[i].id)
287
                        return &all_items[i];
288
        }
289
290
        return NULL;
291
}
292
293
GList *prefs_toolbar_get_item_list_from_name_list(const gchar *name_list)
294
{
295
        gint i;
296
        gchar **array;
297
        GList *list = NULL;
298
299
        array = g_strsplit(name_list, ",", 0);
300
301
        for (i = 0; array[i] != NULL; i++) {
302
                gchar *name = array[i];
303
                const PrefsDisplayItem *item;
304
305
                g_strstrip(name);
306
                item = prefs_toolbar_get_item_from_name(name);
307
                if (item)
308
                        list = g_list_append(list, (gpointer)item);
309
        }
310
311
        g_strfreev(array);
312
313
        return list;
314
}
315
316
gint *prefs_toolbar_get_id_list_from_name_list(const gchar *name_list)
317
{
318
        gint i;
319
        gchar **array;
320
        GArray *iarray;
321
322
        iarray = g_array_new(FALSE, FALSE, sizeof(gint));
323
        array = g_strsplit(name_list, ",", 0);
324
325
        for (i = 0; array[i] != NULL; i++) {
326
                gchar *name = array[i];
327
                const PrefsDisplayItem *item;
328
329
                g_strstrip(name);
330
                item = prefs_toolbar_get_item_from_name(name);
331
                if (item)
332
                        g_array_append_val(iarray, item->id);
333
        }
334
335
        i = -1;
336
        g_array_append_val(iarray, i);
337
338
        g_strfreev(array);
339
340
        return (gint *)g_array_free(iarray, FALSE);
341
}
342
343
gchar *prefs_toolbar_get_name_list_from_item_list(GList *item_list)
344
{
345
        GString *str;
346
        GList *cur;
347
348
        str = g_string_new(NULL);
349
350
        for (cur = item_list; cur != NULL; cur = cur->next) {
351
                const PrefsDisplayItem *item = cur->data;
352
353
                g_string_append(str, item->name);
354
                if (cur->next)
355
                        g_string_append_c(str, ',');
356
        }
357
358
        return g_string_free(str, FALSE);
359
}
360
361
const gchar *prefs_toolbar_get_default_main_setting_name_list(void)
362
{
363
        GString *str;
364
        gint i;
365
        static gchar *default_name_list = NULL;
366
367
        if (default_name_list)
368
                return default_name_list;
369
370
        str = g_string_new(NULL);
371
372
        for (i = 0; default_main_items[i] != -1; i++) {
373
                const PrefsDisplayItem *item;
374
375
                item = prefs_toolbar_get_item_from_id(default_main_items[i]);
376
                if (item) {
377
                        g_string_append(str, item->name);
378
                        if (default_main_items[i + 1] != -1)
379
                                g_string_append_c(str, ',');
380
                }
381
        }
382
383
        default_name_list = g_string_free(str, FALSE);
384
385
        return default_name_list;
386
}
387
388
const gchar *prefs_toolbar_get_default_compose_setting_name_list(void)
389
{
390
        GString *str;
391
        gint i;
392
        static gchar *default_name_list = NULL;
393
394
        if (default_name_list)
395
                return default_name_list;
396
397
        str = g_string_new(NULL);
398
399
        for (i = 0; default_compose_items[i] != -1; i++) {
400
                const PrefsDisplayItem *item;
401
402
                item = prefs_toolbar_get_item_from_id(default_compose_items[i]);
403
                if (item) {
404
                        g_string_append(str, item->name);
405
                        if (default_compose_items[i + 1] != -1)
406
                                g_string_append_c(str, ',');
407
                }
408
        }
409
410
        default_name_list = g_string_free(str, FALSE);
411
412
        return default_name_list;
413
}