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