c2ad30f509c2a428a402566552ec03e9196cecfe
[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 #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                            _("Automatically check for new mail every"));
163
164         spinbtn_autochk_adj = gtk_adjustment_new (5, 1, 100, 1, 10, 10);
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, _("After receiving new mail"));
212
213         PACK_CHECK_BUTTON (vbox2, checkbtn_openinbox, _("Go to Inbox"));
214         PACK_CHECK_BUTTON (vbox2, checkbtn_scan_after_inc,
215                            _("Update all local folders"));
216
217 #ifndef MAEMO 
218         vbox3 = gtkut_get_options_frame(vbox2, &frame, _("Run command"));
219         
220         hbox = gtk_hbox_new (TRUE, 8);
221         gtk_widget_show (hbox);
222         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_auto,
223                            _("after automatic check"));
224         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_manu,
225                            _("after manual check"));
226         gtk_box_pack_start (GTK_BOX(vbox3), hbox, FALSE, FALSE, 0);
227
228         hbox_newmail_notify = gtk_hbox_new (FALSE, 8);
229         gtk_widget_show (hbox_newmail_notify);
230         gtk_box_pack_start (GTK_BOX (vbox3), hbox_newmail_notify, FALSE, 
231                             FALSE, 0);
232
233         label_newmail_notify_cmd = gtk_label_new (_("Command to execute:\n"
234                                                     "(use %d as number of new "
235                                                     "mails)"));
236         gtk_label_set_justify(GTK_LABEL(label_newmail_notify_cmd), 
237                               GTK_JUSTIFY_RIGHT);
238         gtk_widget_show (label_newmail_notify_cmd);
239         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
240                             label_newmail_notify_cmd, FALSE, FALSE, 0);
241
242         entry_newmail_notify_cmd = gtk_entry_new ();
243         gtk_widget_show (entry_newmail_notify_cmd);
244         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
245                             entry_newmail_notify_cmd, TRUE, TRUE, 0);
246
247         gtk_widget_set_sensitive(hbox_newmail_notify, 
248                                  prefs_common.newmail_notify_auto || 
249                                  prefs_common.newmail_notify_manu);
250
251         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_auto),
252                 prefs_common.newmail_notify_auto);
253         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_manu),
254                 prefs_common.newmail_notify_manu);
255         gtk_entry_set_text(GTK_ENTRY(entry_newmail_notify_cmd), 
256                 prefs_common.newmail_notify_cmd);
257 #else
258         PACK_CHECK_BUTTON (vbox2, checkbtn_maemo_show_led, _("Blink LED"));
259         PACK_CHECK_BUTTON (vbox2, checkbtn_maemo_play_sound, _("Play sound"));
260         PACK_CHECK_BUTTON (vbox2, checkbtn_maemo_show_banner,
261                            _("Show info banner"));
262         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_maemo_show_led),
263                 prefs_common.maemo_show_led);
264         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_maemo_play_sound),
265                 prefs_common.maemo_play_sound);
266         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_maemo_show_banner),
267                 prefs_common.maemo_show_banner);
268
269 #endif
270
271         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autochk),
272                 prefs_common.autochk_newmail);
273         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_incext),
274                 prefs_common.use_extinc);
275         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_no_recv_err_panel),
276                 prefs_common.no_recv_err_panel);
277         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_close_recv_dialog),
278                 prefs_common.close_recv_dialog);
279         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_chkonstartup),
280                 prefs_common.chk_on_startup);
281         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_openinbox),
282                 prefs_common.open_inbox_on_inc);
283         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_scan_after_inc),
284                 prefs_common.scan_all_after_inc);
285
286         gtk_entry_set_text(GTK_ENTRY(entry_incext), 
287                 prefs_common.extinc_cmd);
288         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_autochk), 
289                 prefs_common.autochk_itv);
290         combobox_select_by_data(GTK_COMBO_BOX(optmenu_recvdialog),
291                 prefs_common.recv_dialog_mode);
292
293         prefs_receive->window = GTK_WIDGET(window);
294         prefs_receive->checkbtn_incext = checkbtn_incext;
295         prefs_receive->entry_incext = entry_incext;
296         prefs_receive->checkbtn_autochk = checkbtn_autochk;
297         prefs_receive->spinbtn_autochk = spinbtn_autochk;
298         prefs_receive->checkbtn_chkonstartup = checkbtn_chkonstartup;
299         prefs_receive->checkbtn_openinbox = checkbtn_openinbox;
300         prefs_receive->checkbtn_scan_after_inc = checkbtn_scan_after_inc;
301
302 #ifndef MAEMO 
303         prefs_receive->checkbtn_newmail_auto = checkbtn_newmail_auto;
304         prefs_receive->checkbtn_newmail_manu = checkbtn_newmail_manu;
305         prefs_receive->entry_newmail_notify_cmd = entry_newmail_notify_cmd;
306         prefs_receive->hbox_newmail_notify = hbox_newmail_notify;
307 #else
308         prefs_receive->checkbtn_maemo_show_led = checkbtn_maemo_show_led;
309         prefs_receive->checkbtn_maemo_play_sound = checkbtn_maemo_play_sound;
310         prefs_receive->checkbtn_maemo_show_banner = checkbtn_maemo_show_banner;
311 #endif
312
313         prefs_receive->optmenu_recvdialog = optmenu_recvdialog;
314         prefs_receive->checkbtn_no_recv_err_panel = checkbtn_no_recv_err_panel;
315         prefs_receive->checkbtn_close_recv_dialog = checkbtn_close_recv_dialog;
316         prefs_receive->page.widget = vbox1;
317
318 #ifndef MAEMO 
319         g_signal_connect(G_OBJECT(checkbtn_newmail_auto), "toggled",
320                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
321                          NULL);
322         g_signal_connect(G_OBJECT(checkbtn_newmail_manu), "toggled",
323                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
324                          NULL);
325 #endif
326 }
327
328 static void prefs_receive_save(PrefsPage *_page)
329 {
330         ReceivePage *page = (ReceivePage *) _page;
331         gchar *tmp;
332
333         prefs_common.use_extinc = gtk_toggle_button_get_active(
334                 GTK_TOGGLE_BUTTON(page->checkbtn_incext));
335         prefs_common.no_recv_err_panel = gtk_toggle_button_get_active(
336                 GTK_TOGGLE_BUTTON(page->checkbtn_no_recv_err_panel));
337         prefs_common.close_recv_dialog = gtk_toggle_button_get_active(
338                 GTK_TOGGLE_BUTTON(page->checkbtn_close_recv_dialog));
339         prefs_common.chk_on_startup = gtk_toggle_button_get_active(
340                 GTK_TOGGLE_BUTTON(page->checkbtn_chkonstartup));
341         prefs_common.open_inbox_on_inc = gtk_toggle_button_get_active(
342                 GTK_TOGGLE_BUTTON(page->checkbtn_openinbox));
343         prefs_common.scan_all_after_inc = gtk_toggle_button_get_active(
344                 GTK_TOGGLE_BUTTON(page->checkbtn_scan_after_inc));
345
346 #ifndef MAEMO
347         prefs_common.newmail_notify_auto = gtk_toggle_button_get_active(
348                 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_auto));
349         prefs_common.newmail_notify_manu = gtk_toggle_button_get_active(
350                 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_manu));
351 #else
352         prefs_common.maemo_show_led = TRUE;
353         if (!gtk_toggle_button_get_active(
354                 GTK_TOGGLE_BUTTON(page->checkbtn_maemo_show_led))) {
355                 mainwindow_maemo_led_set(FALSE);
356                 prefs_common.maemo_show_led = FALSE;
357         }
358         prefs_common.maemo_play_sound = gtk_toggle_button_get_active(
359                 GTK_TOGGLE_BUTTON(page->checkbtn_maemo_play_sound));
360         prefs_common.maemo_show_banner = gtk_toggle_button_get_active(
361                 GTK_TOGGLE_BUTTON(page->checkbtn_maemo_show_banner));
362 #endif
363         prefs_common.autochk_newmail = gtk_toggle_button_get_active(
364                 GTK_TOGGLE_BUTTON(page->checkbtn_autochk));
365         prefs_common.autochk_itv = gtk_spin_button_get_value_as_int(
366                 GTK_SPIN_BUTTON(page->spinbtn_autochk));
367         
368         tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_incext), 0, -1);
369         g_free(prefs_common.extinc_cmd);
370         prefs_common.extinc_cmd = tmp;
371         
372 #ifndef MAEMO
373         tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_newmail_notify_cmd), 0, -1);
374         g_free(prefs_common.newmail_notify_cmd);
375         prefs_common.newmail_notify_cmd = tmp;
376 #endif
377         
378         prefs_common.recv_dialog_mode =
379                 combobox_get_active_data(GTK_COMBO_BOX(page->optmenu_recvdialog));
380
381         inc_autocheck_timer_remove();
382         inc_autocheck_timer_set();
383
384 }
385
386 static void prefs_receive_destroy_widget(PrefsPage *_page)
387 {
388 }
389
390 void prefs_receive_init(void)
391 {
392         ReceivePage *page;
393         static gchar *path[3];
394
395         path[0] = _("Mail Handling");
396         path[1] = _("Receiving");
397         path[2] = NULL;
398
399         page = g_new0(ReceivePage, 1);
400         page->page.path = path;
401         page->page.create_widget = prefs_receive_create_widget;
402         page->page.destroy_widget = prefs_receive_destroy_widget;
403         page->page.save_page = prefs_receive_save;
404         page->page.weight = 200.0;
405         prefs_gtk_register_page((PrefsPage *) page);
406         prefs_receive = page;
407 }
408
409 void prefs_receive_done(void)
410 {
411         prefs_gtk_unregister_page((PrefsPage *) prefs_receive);
412         g_free(prefs_receive);
413 }