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