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