Statistics
| Revision:

root / src / prefs_toolbar.c @ 1525

History | View | Annotate | Download (9 kB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2007 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/gtkwindow.h>
29
#include <gtk/gtklabel.h>
30
#include <gtk/gtkstock.h>
31
32
#include "prefs_toolbar.h"
33
#include "prefs_display_items.h"
34
35
static PrefsDisplayItem all_items[] =
36
{
37
        {T_SEPARATOR,        "separator",        N_("Separator"),
38
         NULL,        0, NULL, TRUE, FALSE},
39
        {T_GET,                "get",                N_("Get"),
40
         N_("Incorporate new mail"),
41
         STOCK_PIXMAP_MAIL_RECEIVE, NULL, FALSE, FALSE},
42
        {T_GET_ALL,        "get-all",        N_("Get all"),
43
         N_("Incorporate new mail of all accounts"),
44
         STOCK_PIXMAP_MAIL_RECEIVE_ALL,        NULL, FALSE, FALSE},
45
        {T_SEND_QUEUE,        "send-queue",        N_("Send"),
46
         N_("Send queued message(s)"),
47
         STOCK_PIXMAP_MAIL_SEND, NULL, FALSE, FALSE},
48
        {T_COMPOSE,        "compose",        N_("Compose"),
49
         N_("Compose new message"),
50
         STOCK_PIXMAP_MAIL_COMPOSE, NULL, FALSE, FALSE},
51
        {T_REPLY,        "reply",        N_("Reply"),
52
         N_("Reply to the message"),
53
         STOCK_PIXMAP_MAIL_REPLY, NULL, FALSE, FALSE},
54
        {T_REPLY_ALL,        "reply-all",        N_("Reply all"),
55
         N_("Reply to all"),
56
         STOCK_PIXMAP_MAIL_REPLY_TO_ALL, NULL, FALSE, FALSE},
57
        {T_FORWARD,        "forward",        N_("Forward"),
58
         N_("Forward the message"),
59
         STOCK_PIXMAP_MAIL_FORWARD, NULL, FALSE, FALSE},
60
        {T_DELETE,        "delete",        N_("Delete"),
61
         N_("Delete the message"),
62
         STOCK_PIXMAP_DELETE, NULL, FALSE, FALSE},
63
        {T_JUNK,        "junk",                N_("Junk"),
64
         N_("Set as junk mail"),
65
         STOCK_PIXMAP_SPAM, NULL, FALSE, FALSE},
66
        {T_NEXT,        "next",                N_("Next"),
67
         N_("Next unread message"),
68
         -1, GTK_STOCK_GO_DOWN, FALSE, FALSE},
69
        {T_PREV,        "prev",                N_("Prev"),
70
         N_("Previous unread message"),
71
         -1, GTK_STOCK_GO_UP, FALSE, FALSE},
72
        {T_PRINT,        "print",        N_("Print"),
73
         N_("Print message"),
74
         -1, GTK_STOCK_PRINT, FALSE, FALSE},
75
        {T_ADDRESS_BOOK,        "address-book",        N_("Address"),
76
         N_("Address book"),
77
         STOCK_PIXMAP_ADDRESS_BOOK, NULL, FALSE, FALSE},
78
        {T_EXECUTE,        "execute",        N_("Execute"),
79
         N_("Execute marked process"),
80
         -1, GTK_STOCK_EXECUTE, FALSE, FALSE},
81
        {T_COMMON_PREFS,        "common-prefs",        N_("Prefs"),
82
         N_("Common preferences"),
83
         -1, GTK_STOCK_PREFERENCES, FALSE, FALSE},
84
        {T_ACCOUNT_PREFS,        "account-prefs", N_("Account"),
85
         N_("Account preferences"),
86
         -1, GTK_STOCK_PREFERENCES, FALSE, FALSE},
87
88
        {T_SEND,        "send",                N_("Send"),
89
         N_("Send message"),
90
         STOCK_PIXMAP_MAIL_SEND, NULL, FALSE, FALSE},
91
        {T_SEND_LATER,        "send-later",        N_("Send later"),
92
         N_("Put into queue folder and send later"),
93
         STOCK_PIXMAP_MAIL_SEND_QUEUE, NULL, FALSE, FALSE},
94
        {T_DRAFT,        "draft",        N_("Draft"),
95
         N_("Save to draft folder"),
96
         -1, GTK_STOCK_SAVE, FALSE, FALSE},
97
        {T_INSERT_FILE,        "insert-file",        N_("Insert"),
98
         N_("Insert file"),
99
         STOCK_PIXMAP_INSERT_FILE, NULL, FALSE, FALSE},
100
        {T_ATTACH_FILE,        "attach-file",        N_("Attach"),
101
         N_("Attach file"),
102
         STOCK_PIXMAP_MAIL_ATTACH, NULL, FALSE, FALSE},
103
        {T_SIGNATURE,        "signature",        N_("Signature"),
104
         N_("Append signature"),
105
         STOCK_PIXMAP_SIGN, NULL, FALSE, FALSE},
106
        {T_EDITOR,        "editor",        N_("Editor"),
107
         N_("Edit with external editor"),
108
#ifdef GTK_STOCK_EDIT
109
         -1, GTK_STOCK_EDIT, FALSE, FALSE},
110
#else
111
         STOCK_PIXMAP_MAIL_COMPOSE, NULL, FALSE, FALSE},
112
#endif
113
        {T_LINEWRAP,        "linewrap",        N_("Linewrap"),
114
         N_("Wrap all long lines"),
115
         STOCK_PIXMAP_LINEWRAP, NULL, FALSE, FALSE},
116
117
        {-1,                NULL,                NULL,                        FALSE, FALSE}
118
};
119
120
static gint main_available_items[] =
121
{
122
        T_SEPARATOR,
123
        T_GET,
124
        T_GET_ALL,
125
        T_SEND_QUEUE,
126
        T_COMPOSE,
127
        T_REPLY,
128
        T_REPLY_ALL,
129
        T_FORWARD,
130
        T_DELETE,
131
        T_JUNK,
132
        T_NEXT,
133
        T_PREV,
134
        T_PRINT,
135
        T_ADDRESS_BOOK,
136
        T_EXECUTE,
137
        T_COMMON_PREFS,
138
        T_ACCOUNT_PREFS,
139
        -1
140
};
141
142
static gint compose_available_items[] =
143
{
144
        T_SEPARATOR,
145
        T_SEND,
146
        T_SEND_LATER,
147
        T_DRAFT,
148
        T_INSERT_FILE,
149
        T_ATTACH_FILE,
150
        T_SIGNATURE,
151
        T_EDITOR,
152
        T_LINEWRAP,
153
        T_ADDRESS_BOOK,
154
        T_COMMON_PREFS,
155
        T_ACCOUNT_PREFS,
156
        -1
157
};
158
159
static gint default_main_items[] =
160
{
161
        T_GET,
162
        T_GET_ALL,
163
        T_SEPARATOR,
164
        T_SEND_QUEUE,
165
        T_SEPARATOR,
166
        T_COMPOSE,
167
        T_REPLY,
168
        T_REPLY_ALL,
169
        T_FORWARD,
170
        T_SEPARATOR,
171
        T_DELETE,
172
        T_JUNK,
173
        T_SEPARATOR,
174
        T_NEXT,
175
        T_SEPARATOR,
176
        T_PRINT,
177
        T_ADDRESS_BOOK,
178
        -1
179
};
180
181
static gint default_compose_items[] =
182
{
183
        T_SEND,
184
        T_SEND_LATER,
185
        T_DRAFT,
186
        T_SEPARATOR,
187
        T_INSERT_FILE,
188
        T_ATTACH_FILE,
189
        T_SEPARATOR,
190
        T_SIGNATURE,
191
        T_SEPARATOR,
192
        T_EDITOR,
193
        T_LINEWRAP,
194
        T_SEPARATOR,
195
        T_ADDRESS_BOOK,
196
        -1
197
};
198
199
gint prefs_toolbar_open(ToolbarType type, gint *visible_items,
200
                        GList **item_list)
201
{
202
        PrefsDisplayItemsDialog *dialog;
203
        GList *list;
204
        gint ret = 0;
205
206
        dialog = prefs_display_items_dialog_create();
207
        gtk_window_set_title(GTK_WINDOW(dialog->window),
208
                             _("Customize toolbar"));
209
        gtk_label_set_text(GTK_LABEL(dialog->label),
210
                           _("Select items to be displayed on the toolbar. You can modify\n"
211
                             "the order by using the Up / Down button, or dragging the items."));
212
213
        switch (type) {
214
        case TOOLBAR_MAIN:
215
                prefs_display_items_dialog_set_available
216
                        (dialog, all_items, main_available_items);
217
                prefs_display_items_dialog_set_default_visible
218
                        (dialog, default_main_items);
219
                break;
220
        case TOOLBAR_COMPOSE:
221
        default:
222
                prefs_display_items_dialog_set_available
223
                        (dialog, all_items, compose_available_items);
224
                prefs_display_items_dialog_set_default_visible
225
                        (dialog, default_compose_items);
226
                break;
227
        }
228
229
        prefs_display_items_dialog_set_visible(dialog, visible_items);
230
231
        gtk_widget_show(dialog->window);
232
233
        while (dialog->finished == FALSE)
234
                gtk_main_iteration();
235
236
        if (dialog->cancelled) {
237
                ret = -1;
238
                *item_list = NULL;
239
        } else {
240
                list = dialog->visible_items;
241
                dialog->visible_items = NULL;
242
                *item_list = list;
243
        }
244
245
        prefs_display_items_dialog_destroy(dialog);
246
247
        return ret;
248
}
249
250
const PrefsDisplayItem *prefs_toolbar_get_item_from_name(const gchar *name)
251
{
252
        gint i;
253
254
        for (i = 0; all_items[i].id != -1; i++) {
255
                if (!strcmp(name, all_items[i].name))
256
                        return &all_items[i];
257
        }
258
259
        return NULL;
260
}
261
262
const PrefsDisplayItem *prefs_toolbar_get_item_from_id(gint id)
263
{
264
        gint i;
265
266
        for (i = 0; all_items[i].id != -1; i++) {
267
                if (id == all_items[i].id)
268
                        return &all_items[i];
269
        }
270
271
        return NULL;
272
}
273
274
GList *prefs_toolbar_get_item_list_from_name_list(const gchar *name_list)
275
{
276
        gint i;
277
        gchar **array;
278
        GList *list = NULL;
279
280
        array = g_strsplit(name_list, ",", 0);
281
282
        for (i = 0; array[i] != NULL; i++) {
283
                gchar *name = array[i];
284
                const PrefsDisplayItem *item;
285
286
                g_strstrip(name);
287
                item = prefs_toolbar_get_item_from_name(name);
288
                if (item)
289
                        list = g_list_append(list, (gpointer)item);
290
        }
291
292
        g_strfreev(array);
293
294
        return list;
295
}
296
297
gint *prefs_toolbar_get_id_list_from_name_list(const gchar *name_list)
298
{
299
        gint i;
300
        gchar **array;
301
        GArray *iarray;
302
303
        iarray = g_array_new(FALSE, FALSE, sizeof(gint));
304
        array = g_strsplit(name_list, ",", 0);
305
306
        for (i = 0; array[i] != NULL; i++) {
307
                gchar *name = array[i];
308
                const PrefsDisplayItem *item;
309
310
                g_strstrip(name);
311
                item = prefs_toolbar_get_item_from_name(name);
312
                if (item)
313
                        g_array_append_val(iarray, item->id);
314
        }
315
316
        i = -1;
317
        g_array_append_val(iarray, i);
318
319
        g_strfreev(array);
320
321
        return (gint *)g_array_free(iarray, FALSE);
322
}
323
324
gchar *prefs_toolbar_get_name_list_from_item_list(GList *item_list)
325
{
326
        GString *str;
327
        GList *cur;
328
329
        str = g_string_new(NULL);
330
331
        for (cur = item_list; cur != NULL; cur = cur->next) {
332
                const PrefsDisplayItem *item = cur->data;
333
334
                g_string_append(str, item->name);
335
                if (cur->next)
336
                        g_string_append_c(str, ',');
337
        }
338
339
        return g_string_free(str, FALSE);
340
}
341
342
const gchar *prefs_toolbar_get_default_main_setting_name_list(void)
343
{
344
        GString *str;
345
        gint i;
346
        static gchar *default_name_list = NULL;
347
348
        if (default_name_list)
349
                return default_name_list;
350
351
        str = g_string_new(NULL);
352
353
        for (i = 0; default_main_items[i] != -1; i++) {
354
                const PrefsDisplayItem *item;
355
356
                item = prefs_toolbar_get_item_from_id(default_main_items[i]);
357
                if (item) {
358
                        g_string_append(str, item->name);
359
                        if (default_main_items[i + 1] != -1)
360
                                g_string_append_c(str, ',');
361
                }
362
        }
363
364
        default_name_list = g_string_free(str, FALSE);
365
366
        return default_name_list;
367
}
368
369
const gchar *prefs_toolbar_get_default_compose_setting_name_list(void)
370
{
371
        GString *str;
372
        gint i;
373
        static gchar *default_name_list = NULL;
374
375
        if (default_name_list)
376
                return default_name_list;
377
378
        str = g_string_new(NULL);
379
380
        for (i = 0; default_compose_items[i] != -1; i++) {
381
                const PrefsDisplayItem *item;
382
383
                item = prefs_toolbar_get_item_from_id(default_compose_items[i]);
384
                if (item) {
385
                        g_string_append(str, item->name);
386
                        if (default_compose_items[i + 1] != -1)
387
                                g_string_append_c(str, ',');
388
                }
389
        }
390
391
        default_name_list = g_string_free(str, FALSE);
392
393
        return default_name_list;
394
}