Statistics
| Revision:

root / src / prefs_toolbar.c @ 2277

History | View | Annotate | Download (9.5 kB)

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