b3a27426b7d29658dd6ac97540dece1df09767f7
[claws.git] / src / prefs_receive.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2007 Colin Leroy <colin@colino.net> & The Claws Mail Team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36 #include "inc.h"
37
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
40 #include "gtk/menu.h"
41
42 #include "manage_window.h"
43
44 typedef struct _ReceivePage
45 {
46         PrefsPage page;
47
48         GtkWidget *window;
49
50         GtkWidget *checkbtn_incext;
51         GtkWidget *entry_incext;
52         GtkWidget *checkbtn_autochk;
53         GtkWidget *spinbtn_autochk;
54         GtkWidget *checkbtn_chkonstartup;
55         GtkWidget *checkbtn_openinbox;
56         GtkWidget *checkbtn_scan_after_inc;
57 #ifndef MAEMO
58         GtkWidget *checkbtn_newmail_auto;
59         GtkWidget *checkbtn_newmail_manu;
60         GtkWidget *entry_newmail_notify_cmd;
61         GtkWidget *hbox_newmail_notify;
62 #else
63         GtkWidget *checkbtn_maemo_play_sound;
64         GtkWidget *checkbtn_maemo_show_banner;
65 #endif
66         GtkWidget *optmenu_recvdialog;
67         GtkWidget *checkbtn_no_recv_err_panel;
68         GtkWidget *checkbtn_close_recv_dialog;
69 } ReceivePage;
70
71 ReceivePage *prefs_receive;
72
73 #ifndef MAEMO
74 static void prefs_common_recv_dialog_newmail_notify_toggle_cb(GtkWidget *w, gpointer data)
75 {
76         gboolean toggled;
77
78         toggled = gtk_toggle_button_get_active
79                         (GTK_TOGGLE_BUTTON(prefs_receive->checkbtn_newmail_manu)) ||
80                   gtk_toggle_button_get_active
81                         (GTK_TOGGLE_BUTTON(prefs_receive->checkbtn_newmail_auto));
82         gtk_widget_set_sensitive(prefs_receive->hbox_newmail_notify, toggled);
83 }
84 #endif
85
86
87 static void prefs_receive_create_widget(PrefsPage *_page, GtkWindow *window, 
88                                   gpointer data)
89 {
90         ReceivePage *prefs_receive = (ReceivePage *) _page;
91         
92         GtkWidget *vbox1;
93         GtkWidget *vbox2;
94         GtkWidget *checkbtn_incext;
95         GtkWidget *hbox;
96         GtkWidget *label_incext;
97         GtkWidget *entry_incext;
98
99         GtkWidget *hbox_autochk;
100         GtkWidget *checkbtn_autochk;
101         GtkObject *spinbtn_autochk_adj;
102         GtkWidget *spinbtn_autochk;
103         GtkWidget *label_autochk2;
104         GtkWidget *checkbtn_chkonstartup;
105         GtkWidget *checkbtn_openinbox;
106         GtkWidget *checkbtn_scan_after_inc;
107
108         GtkWidget *frame;
109 #ifndef MAEMO
110         GtkWidget *vbox3;
111         GtkWidget *hbox_newmail_notify;
112         GtkWidget *checkbtn_newmail_auto;
113         GtkWidget *checkbtn_newmail_manu;
114         GtkWidget *entry_newmail_notify_cmd;
115         GtkWidget *label_newmail_notify_cmd;
116 #else
117         GtkWidget *checkbtn_maemo_play_sound;
118         GtkWidget *checkbtn_maemo_show_banner;
119 #endif
120         
121         GtkWidget *label_recvdialog;
122         GtkWidget *menu;
123         GtkWidget *menuitem;
124         GtkWidget *optmenu_recvdialog;
125         GtkWidget *checkbtn_no_recv_err_panel;
126         GtkWidget *checkbtn_close_recv_dialog;
127
128         vbox1 = gtk_vbox_new (FALSE, VSPACING);
129         gtk_widget_show (vbox1);
130         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
131
132         /* Use of external incorporation program */
133         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("External incorporation program"));
134
135         PACK_CHECK_BUTTON (vbox2, checkbtn_incext,
136                            _("Use external program for receiving mail"));
137
138         hbox = gtk_hbox_new (FALSE, 8);
139         gtk_widget_show (hbox);
140         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
141         SET_TOGGLE_SENSITIVITY (checkbtn_incext, hbox);
142
143         label_incext = gtk_label_new (_("Command"));
144         gtk_widget_show (label_incext);
145         gtk_box_pack_start (GTK_BOX (hbox), label_incext, FALSE, FALSE, 0);
146
147         entry_incext = gtk_entry_new ();
148         gtk_widget_show (entry_incext);
149         gtk_box_pack_start (GTK_BOX (hbox), entry_incext, TRUE, TRUE, 0);
150
151         /* Auto-checking */
152         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Automatic checking"));        
153         
154         hbox_autochk = gtk_hbox_new (FALSE, 8);
155         gtk_widget_show (hbox_autochk);
156         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autochk, FALSE, FALSE, 0);
157
158         PACK_CHECK_BUTTON (hbox_autochk, checkbtn_autochk,
159                            _("Automatically check for new mail every"));
160
161         spinbtn_autochk_adj = gtk_adjustment_new (5, 1, 100, 1, 10, 10);
162         spinbtn_autochk = gtk_spin_button_new
163                 (GTK_ADJUSTMENT (spinbtn_autochk_adj), 1, 0);
164         gtk_widget_show (spinbtn_autochk);
165         gtk_box_pack_start (GTK_BOX (hbox_autochk), spinbtn_autochk, FALSE, FALSE, 0);
166         gtk_widget_set_size_request (spinbtn_autochk, 64, -1);
167         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autochk), TRUE);
168
169         label_autochk2 = gtk_label_new (_("minute(s)"));
170         gtk_widget_show (label_autochk2);
171         gtk_box_pack_start (GTK_BOX (hbox_autochk), label_autochk2, FALSE, FALSE, 0);
172
173         SET_TOGGLE_SENSITIVITY(checkbtn_autochk, spinbtn_autochk);
174         SET_TOGGLE_SENSITIVITY(checkbtn_autochk, label_autochk2);
175
176         PACK_CHECK_BUTTON (vbox2, checkbtn_chkonstartup,
177                            _("Check for new mail on start-up"));
178
179         /* receive dialog */
180         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Dialogs"));
181         
182         label_recvdialog = gtk_label_new (_("Show receive dialog"));
183         gtk_misc_set_alignment(GTK_MISC(label_recvdialog), 0, 0.5);
184         gtk_widget_show (label_recvdialog);
185
186         optmenu_recvdialog = gtk_option_menu_new ();
187         gtk_widget_show (optmenu_recvdialog);
188
189         menu = gtk_menu_new ();
190         MENUITEM_ADD (menu, menuitem, _("Always"), RECV_DIALOG_ALWAYS);
191         MENUITEM_ADD (menu, menuitem, _("Only on manual receiving"),
192                       RECV_DIALOG_MANUAL);
193         MENUITEM_ADD (menu, menuitem, _("Never"), RECV_DIALOG_NEVER);
194
195         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_recvdialog), menu);
196
197         hbox = gtk_hbox_new(FALSE, 20);
198         gtk_widget_show(hbox);
199         gtk_box_pack_start(GTK_BOX(hbox), label_recvdialog, FALSE, FALSE, 0);
200         gtk_box_pack_start(GTK_BOX(hbox), optmenu_recvdialog, FALSE, FALSE, 0);
201         
202         gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
203         
204         PACK_CHECK_BUTTON (vbox2, checkbtn_close_recv_dialog,
205                            _("Close receive dialog when finished"));
206
207         PACK_CHECK_BUTTON (vbox2, checkbtn_no_recv_err_panel,
208                            _("Don't popup error dialog on receive error"));
209
210         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("After receiving new mail"));
211
212         PACK_CHECK_BUTTON (vbox2, checkbtn_openinbox, _("Go to inbox"));
213         PACK_CHECK_BUTTON (vbox2, checkbtn_scan_after_inc,
214                            _("Update all local folders"));
215
216 #ifndef MAEMO 
217         vbox3 = gtkut_get_options_frame(vbox2, &frame, _("Run command"));
218         
219         hbox = gtk_hbox_new (TRUE, 8);
220         gtk_widget_show (hbox);
221         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_auto,
222                            _("after automatic check"));
223         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_manu,
224                            _("after manual check"));
225         gtk_box_pack_start (GTK_BOX(vbox3), hbox, FALSE, FALSE, 0);
226
227         hbox_newmail_notify = gtk_hbox_new (FALSE, 8);
228         gtk_widget_show (hbox_newmail_notify);
229         gtk_box_pack_start (GTK_BOX (vbox3), hbox_newmail_notify, FALSE, 
230                             FALSE, 0);
231
232         label_newmail_notify_cmd = gtk_label_new (_("Command to execute:\n"
233                                                     "(use %d as number of new "
234                                                     "mails)"));
235         gtk_label_set_justify(GTK_LABEL(label_newmail_notify_cmd), 
236                               GTK_JUSTIFY_RIGHT);
237         gtk_widget_show (label_newmail_notify_cmd);
238         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
239                             label_newmail_notify_cmd, FALSE, FALSE, 0);
240
241         entry_newmail_notify_cmd = gtk_entry_new ();
242         gtk_widget_show (entry_newmail_notify_cmd);
243         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
244                             entry_newmail_notify_cmd, TRUE, TRUE, 0);
245
246         gtk_widget_set_sensitive(hbox_newmail_notify, 
247                                  prefs_common.newmail_notify_auto || 
248                                  prefs_common.newmail_notify_manu);
249
250         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_auto),
251                 prefs_common.newmail_notify_auto);
252         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_manu),
253                 prefs_common.newmail_notify_manu);
254         gtk_entry_set_text(GTK_ENTRY(entry_newmail_notify_cmd), 
255                 prefs_common.newmail_notify_cmd);
256 #else
257         PACK_CHECK_BUTTON (vbox2, checkbtn_maemo_play_sound, _("Play sound"));
258         PACK_CHECK_BUTTON (vbox2, checkbtn_maemo_show_banner,
259                            _("Show info banner"));
260         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_maemo_play_sound),
261                 prefs_common.maemo_play_sound);
262         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_maemo_show_banner),
263                 prefs_common.maemo_show_banner);
264
265 #endif
266
267         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autochk),
268                 prefs_common.autochk_newmail);
269         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_incext),
270                 prefs_common.use_extinc);
271         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_no_recv_err_panel),
272                 prefs_common.no_recv_err_panel);
273         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_close_recv_dialog),
274                 prefs_common.close_recv_dialog);
275         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_chkonstartup),
276                 prefs_common.chk_on_startup);
277         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_openinbox),
278                 prefs_common.open_inbox_on_inc);
279         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_scan_after_inc),
280                 prefs_common.scan_all_after_inc);
281
282         gtk_entry_set_text(GTK_ENTRY(entry_incext), 
283                 prefs_common.extinc_cmd);
284         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_autochk), 
285                 prefs_common.autochk_itv);
286         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_recvdialog),
287                 prefs_common.recv_dialog_mode);
288
289         prefs_receive->window = GTK_WIDGET(window);
290         prefs_receive->checkbtn_incext = checkbtn_incext;
291         prefs_receive->entry_incext = entry_incext;
292         prefs_receive->checkbtn_autochk = checkbtn_autochk;
293         prefs_receive->spinbtn_autochk = spinbtn_autochk;
294         prefs_receive->checkbtn_chkonstartup = checkbtn_chkonstartup;
295         prefs_receive->checkbtn_openinbox = checkbtn_openinbox;
296         prefs_receive->checkbtn_scan_after_inc = checkbtn_scan_after_inc;
297
298 #ifndef MAEMO 
299         prefs_receive->checkbtn_newmail_auto = checkbtn_newmail_auto;
300         prefs_receive->checkbtn_newmail_manu = checkbtn_newmail_manu;
301         prefs_receive->entry_newmail_notify_cmd = entry_newmail_notify_cmd;
302         prefs_receive->hbox_newmail_notify = hbox_newmail_notify;
303 #else
304         prefs_receive->checkbtn_maemo_play_sound = checkbtn_maemo_play_sound;
305         prefs_receive->checkbtn_maemo_show_banner = checkbtn_maemo_show_banner;
306 #endif
307
308         prefs_receive->optmenu_recvdialog = optmenu_recvdialog;
309         prefs_receive->checkbtn_no_recv_err_panel = checkbtn_no_recv_err_panel;
310         prefs_receive->checkbtn_close_recv_dialog = checkbtn_close_recv_dialog;
311         prefs_receive->page.widget = vbox1;
312
313 #ifndef MAEMO 
314         g_signal_connect(G_OBJECT(checkbtn_newmail_auto), "toggled",
315                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
316                          NULL);
317         g_signal_connect(G_OBJECT(checkbtn_newmail_manu), "toggled",
318                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
319                          NULL);
320 #endif
321 }
322
323 static void prefs_receive_save(PrefsPage *_page)
324 {
325         ReceivePage *page = (ReceivePage *) _page;
326         gchar *tmp;
327         GtkWidget *menu;
328         GtkWidget *menuitem;
329
330         prefs_common.use_extinc = gtk_toggle_button_get_active(
331                 GTK_TOGGLE_BUTTON(page->checkbtn_incext));
332         prefs_common.no_recv_err_panel = gtk_toggle_button_get_active(
333                 GTK_TOGGLE_BUTTON(page->checkbtn_no_recv_err_panel));
334         prefs_common.close_recv_dialog = gtk_toggle_button_get_active(
335                 GTK_TOGGLE_BUTTON(page->checkbtn_close_recv_dialog));
336         prefs_common.chk_on_startup = gtk_toggle_button_get_active(
337                 GTK_TOGGLE_BUTTON(page->checkbtn_chkonstartup));
338         prefs_common.open_inbox_on_inc = gtk_toggle_button_get_active(
339                 GTK_TOGGLE_BUTTON(page->checkbtn_openinbox));
340         prefs_common.scan_all_after_inc = gtk_toggle_button_get_active(
341                 GTK_TOGGLE_BUTTON(page->checkbtn_scan_after_inc));
342
343 #ifndef MAEMO
344         prefs_common.newmail_notify_auto = gtk_toggle_button_get_active(
345                 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_auto));
346         prefs_common.newmail_notify_manu = gtk_toggle_button_get_active(
347                 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_manu));
348 #else
349         prefs_common.maemo_play_sound = gtk_toggle_button_get_active(
350                 GTK_TOGGLE_BUTTON(page->checkbtn_maemo_play_sound));
351         prefs_common.maemo_show_banner = gtk_toggle_button_get_active(
352                 GTK_TOGGLE_BUTTON(page->checkbtn_maemo_show_banner));
353 #endif
354         prefs_common.autochk_newmail = gtk_toggle_button_get_active(
355                 GTK_TOGGLE_BUTTON(page->checkbtn_autochk));
356         prefs_common.autochk_itv = gtk_spin_button_get_value_as_int(
357                 GTK_SPIN_BUTTON(page->spinbtn_autochk));
358         
359         tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_incext), 0, -1);
360         g_free(prefs_common.extinc_cmd);
361         prefs_common.extinc_cmd = tmp;
362         
363 #ifndef MAEMO
364         tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_newmail_notify_cmd), 0, -1);
365         g_free(prefs_common.newmail_notify_cmd);
366         prefs_common.newmail_notify_cmd = tmp;
367 #endif
368         
369         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_recvdialog));
370         menuitem = gtk_menu_get_active(GTK_MENU(menu));
371         prefs_common.recv_dialog_mode = GPOINTER_TO_INT
372                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
373         inc_autocheck_timer_remove();
374         inc_autocheck_timer_set();
375
376 }
377
378 static void prefs_receive_destroy_widget(PrefsPage *_page)
379 {
380 }
381
382 void prefs_receive_init(void)
383 {
384         ReceivePage *page;
385         static gchar *path[3];
386
387         path[0] = _("Mail Handling");
388         path[1] = _("Receiving");
389         path[2] = NULL;
390
391         page = g_new0(ReceivePage, 1);
392         page->page.path = path;
393         page->page.create_widget = prefs_receive_create_widget;
394         page->page.destroy_widget = prefs_receive_destroy_widget;
395         page->page.save_page = prefs_receive_save;
396         page->page.weight = 200.0;
397         prefs_gtk_register_page((PrefsPage *) page);
398         prefs_receive = page;
399 }
400
401 void prefs_receive_done(void)
402 {
403         prefs_gtk_unregister_page((PrefsPage *) prefs_receive);
404         g_free(prefs_receive);
405 }