2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2016 Colin Leroy and The Claws Mail Team
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.
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.
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/>.
21 #include "claws-features.h"
30 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "prefs_common.h"
35 #include "prefs_receive.h"
36 #include "prefs_gtk.h"
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
43 #include "manage_window.h"
46 typedef struct _ReceivePage
52 GtkWidget
*checkbtn_incext
;
53 GtkWidget
*entry_incext
;
54 GtkWidget
*checkbtn_autochk
;
55 GtkWidget
*spinbtn_autochk_sec
;
56 GtkWidget
*spinbtn_autochk_min
;
57 GtkWidget
*spinbtn_autochk_hour
;
58 GtkWidget
*checkbtn_chkonstartup
;
59 GtkWidget
*checkbtn_openinbox
;
60 GtkWidget
*checkbtn_scan_after_inc
;
61 GtkWidget
*checkbtn_newmail_auto
;
62 GtkWidget
*checkbtn_newmail_manu
;
63 GtkWidget
*entry_newmail_notify_cmd
;
64 GtkWidget
*hbox_newmail_notify
;
65 GtkWidget
*optmenu_recvdialog
;
66 GtkWidget
*checkbtn_no_recv_err_panel
;
67 GtkWidget
*checkbtn_close_recv_dialog
;
70 ReceivePage
*prefs_receive
;
72 static void prefs_common_recv_dialog_newmail_notify_toggle_cb(GtkWidget
*w
, gpointer data
)
76 toggled
= gtk_toggle_button_get_active
77 (GTK_TOGGLE_BUTTON(prefs_receive
->checkbtn_newmail_manu
)) ||
78 gtk_toggle_button_get_active
79 (GTK_TOGGLE_BUTTON(prefs_receive
->checkbtn_newmail_auto
));
80 gtk_widget_set_sensitive(prefs_receive
->hbox_newmail_notify
, toggled
);
83 static void prefs_receive_itv_spinbutton_value_changed_cb(GtkWidget
*w
, gpointer data
)
85 ReceivePage
*page
= (ReceivePage
*)data
;
86 gint seconds
= gtk_spin_button_get_value_as_int (
87 GTK_SPIN_BUTTON (page
->spinbtn_autochk_sec
));
88 gint minutes
= gtk_spin_button_get_value_as_int (
89 GTK_SPIN_BUTTON (page
->spinbtn_autochk_min
));
90 gint hours
= gtk_spin_button_get_value_as_int (
91 GTK_SPIN_BUTTON(page
->spinbtn_autochk_hour
));
92 if (seconds
< PREFS_RECV_AUTOCHECK_MIN_INTERVAL
&& minutes
== 0 && hours
== 0) {
93 gtk_spin_button_set_value (
94 GTK_SPIN_BUTTON (page
->spinbtn_autochk_sec
),
95 PREFS_RECV_AUTOCHECK_MIN_INTERVAL
);
99 static void prefs_receive_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
102 ReceivePage
*prefs_receive
= (ReceivePage
*) _page
;
106 GtkWidget
*checkbtn_incext
;
108 GtkWidget
*label_incext
;
109 GtkWidget
*entry_incext
;
111 GtkWidget
*hbox_autochk
;
112 GtkWidget
*checkbtn_autochk
;
113 GtkAdjustment
*spinbtn_autochk_adj
;
114 GtkWidget
*spinbtn_autochk_sec
;
115 GtkWidget
*spinbtn_autochk_min
;
116 GtkWidget
*spinbtn_autochk_hour
;
117 GtkWidget
*label_autochk2
;
118 GtkWidget
*label_autochk1
;
119 GtkWidget
*label_autochk0
;
120 GtkWidget
*checkbtn_chkonstartup
;
121 GtkWidget
*checkbtn_openinbox
;
122 GtkWidget
*checkbtn_scan_after_inc
;
126 GtkWidget
*hbox_newmail_notify
;
127 GtkWidget
*checkbtn_newmail_auto
;
128 GtkWidget
*checkbtn_newmail_manu
;
129 GtkWidget
*entry_newmail_notify_cmd
;
130 GtkWidget
*label_newmail_notify_cmd
;
131 GtkWidget
*label_newmail_notify_cmd_syntax
;
133 GtkWidget
*label_recvdialog
;
136 GtkWidget
*optmenu_recvdialog
;
137 GtkWidget
*checkbtn_no_recv_err_panel
;
138 GtkWidget
*checkbtn_close_recv_dialog
;
140 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING
);
141 gtk_widget_show (vbox1
);
142 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), VBOX_BORDER
);
144 /* Use of external incorporation program */
145 vbox2
= gtkut_get_options_frame(vbox1
, &frame
, _("External incorporation program"));
147 PACK_CHECK_BUTTON (vbox2
, checkbtn_incext
,
148 _("Use external program for receiving mail"));
150 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
151 gtk_widget_show (hbox
);
152 gtk_box_pack_start (GTK_BOX (vbox2
), hbox
, FALSE
, FALSE
, 0);
153 SET_TOGGLE_SENSITIVITY (checkbtn_incext
, hbox
);
155 label_incext
= gtk_label_new (_("Command"));
156 gtk_widget_show (label_incext
);
157 gtk_box_pack_start (GTK_BOX (hbox
), label_incext
, FALSE
, FALSE
, 0);
159 entry_incext
= gtk_entry_new ();
160 gtk_widget_show (entry_incext
);
161 gtk_box_pack_start (GTK_BOX (hbox
), entry_incext
, TRUE
, TRUE
, 0);
164 vbox2
= gtkut_get_options_frame(vbox1
, &frame
, _("Automatic checking"));
166 hbox_autochk
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
167 gtk_widget_show (hbox_autochk
);
168 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_autochk
, FALSE
, FALSE
, 0);
170 PACK_CHECK_BUTTON (hbox_autochk
, checkbtn_autochk
,
171 _("Check for new mail every"));
173 spinbtn_autochk_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (5, 0, 99, 1, 10, 0));
174 spinbtn_autochk_hour
= gtk_spin_button_new
175 (GTK_ADJUSTMENT (spinbtn_autochk_adj
), 1, 0);
177 gtk_widget_show (spinbtn_autochk_hour
);
178 gtk_box_pack_start (GTK_BOX (hbox_autochk
), spinbtn_autochk_hour
, FALSE
, FALSE
, 0);
180 label_autochk0
= gtk_label_new (_("hours"));
181 gtk_widget_show (label_autochk0
);
182 gtk_box_pack_start (GTK_BOX (hbox_autochk
), label_autochk0
, FALSE
, FALSE
, 0);
184 spinbtn_autochk_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (5, 0, 59, 1, 10, 0));
185 spinbtn_autochk_min
= gtk_spin_button_new
186 (GTK_ADJUSTMENT (spinbtn_autochk_adj
), 1, 0);
187 gtk_widget_show (spinbtn_autochk_min
);
188 gtk_box_pack_start (GTK_BOX (hbox_autochk
), spinbtn_autochk_min
, FALSE
, FALSE
, 0);
190 label_autochk1
= gtk_label_new (_("minutes"));
191 gtk_widget_show (label_autochk1
);
192 gtk_box_pack_start (GTK_BOX (hbox_autochk
), label_autochk1
, FALSE
, FALSE
, 0);
194 spinbtn_autochk_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (5, 0, 59, 1, 10, 0));
195 spinbtn_autochk_sec
= gtk_spin_button_new
196 (GTK_ADJUSTMENT (spinbtn_autochk_adj
), 1, 0);
197 gtk_widget_show (spinbtn_autochk_sec
);
198 gtk_box_pack_start (GTK_BOX (hbox_autochk
), spinbtn_autochk_sec
, FALSE
, FALSE
, 0);
199 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autochk_sec
), TRUE
);
200 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autochk_min
), TRUE
);
201 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autochk_hour
), TRUE
);
203 label_autochk2
= gtk_label_new (_("seconds"));
204 gtk_widget_show (label_autochk2
);
205 gtk_box_pack_start (GTK_BOX (hbox_autochk
), label_autochk2
, FALSE
, FALSE
, 0);
207 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, spinbtn_autochk_sec
);
208 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, spinbtn_autochk_min
);
209 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, spinbtn_autochk_hour
);
210 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, label_autochk0
);
211 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, label_autochk1
);
212 SET_TOGGLE_SENSITIVITY(checkbtn_autochk
, label_autochk2
);
214 PACK_CHECK_BUTTON (vbox2
, checkbtn_chkonstartup
,
215 _("Check for new mail on start-up"));
218 vbox2
= gtkut_get_options_frame(vbox1
, &frame
, _("Dialogs"));
220 label_recvdialog
= gtk_label_new (_("Show receive dialog"));
221 gtk_label_set_xalign(GTK_LABEL(label_recvdialog
), 0.0);
222 gtk_widget_show (label_recvdialog
);
224 optmenu_recvdialog
= gtkut_sc_combobox_create(NULL
, FALSE
);
225 gtk_widget_show (optmenu_recvdialog
);
227 menu
= GTK_LIST_STORE(gtk_combo_box_get_model(
228 GTK_COMBO_BOX(optmenu_recvdialog
)));
229 COMBOBOX_ADD (menu
, _("Always"), RECV_DIALOG_ALWAYS
);
230 COMBOBOX_ADD (menu
, _("Only on manual receiving"), RECV_DIALOG_MANUAL
);
231 COMBOBOX_ADD (menu
, _("Never"), RECV_DIALOG_NEVER
);
233 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 20);
234 gtk_widget_show(hbox
);
235 gtk_box_pack_start(GTK_BOX(hbox
), label_recvdialog
, FALSE
, FALSE
, 0);
236 gtk_box_pack_start(GTK_BOX(hbox
), optmenu_recvdialog
, FALSE
, FALSE
, 0);
238 gtk_box_pack_start(GTK_BOX(vbox2
), hbox
, FALSE
, FALSE
, 0);
240 PACK_CHECK_BUTTON (vbox2
, checkbtn_close_recv_dialog
,
241 _("Close receive dialog when finished"));
243 PACK_CHECK_BUTTON (vbox2
, checkbtn_no_recv_err_panel
,
244 _("Don't popup error dialog on receive error"));
246 vbox2
= gtkut_get_options_frame(vbox1
, &frame
,
247 _("After receiving new mail"));
249 PACK_CHECK_BUTTON (vbox2
, checkbtn_openinbox
, _("Go to Inbox"));
250 PACK_CHECK_BUTTON (vbox2
, checkbtn_scan_after_inc
,
251 _("Update all local folders"));
253 vbox3
= gtkut_get_options_frame(vbox2
, &frame
, _("Run command"));
255 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
256 gtk_widget_show (hbox
);
257 PACK_CHECK_BUTTON (hbox
, checkbtn_newmail_auto
,
258 _("after automatic check"));
259 PACK_CHECK_BUTTON (hbox
, checkbtn_newmail_manu
,
260 _("after manual check"));
261 gtk_box_pack_start (GTK_BOX(vbox3
), hbox
, FALSE
, FALSE
, 0);
263 hbox_newmail_notify
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
264 gtk_widget_show (hbox_newmail_notify
);
265 gtk_box_pack_start (GTK_BOX (vbox3
), hbox_newmail_notify
, FALSE
,
268 label_newmail_notify_cmd
= gtk_label_new (_("Command to execute"));
269 gtk_label_set_justify(GTK_LABEL(label_newmail_notify_cmd
),
271 gtk_widget_show (label_newmail_notify_cmd
);
272 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify
),
273 label_newmail_notify_cmd
, FALSE
, FALSE
, 0);
275 entry_newmail_notify_cmd
= gtk_entry_new ();
276 gtk_widget_show (entry_newmail_notify_cmd
);
277 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify
),
278 entry_newmail_notify_cmd
, TRUE
, TRUE
, 0);
280 label_newmail_notify_cmd_syntax
= gtk_label_new (_("Use %d as number of new mails"));
281 gtk_widget_show (label_newmail_notify_cmd_syntax
);
282 gtkut_widget_set_small_font_size (label_newmail_notify_cmd_syntax
);
283 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify
),
284 label_newmail_notify_cmd_syntax
, FALSE
, FALSE
, 0);
286 gtk_widget_set_sensitive(hbox_newmail_notify
,
287 prefs_common
.newmail_notify_auto
||
288 prefs_common
.newmail_notify_manu
);
290 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_auto
),
291 prefs_common
.newmail_notify_auto
);
292 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_manu
),
293 prefs_common
.newmail_notify_manu
);
294 gtk_entry_set_text(GTK_ENTRY(entry_newmail_notify_cmd
),
295 prefs_common
.newmail_notify_cmd
);
296 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_autochk
),
297 prefs_common
.autochk_newmail
);
298 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_incext
),
299 prefs_common
.use_extinc
);
300 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_no_recv_err_panel
),
301 prefs_common
.no_recv_err_panel
);
302 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_close_recv_dialog
),
303 prefs_common
.close_recv_dialog
);
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_chkonstartup
),
305 prefs_common
.chk_on_startup
);
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_openinbox
),
307 prefs_common
.open_inbox_on_inc
);
308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_scan_after_inc
),
309 prefs_common
.scan_all_after_inc
);
311 gtk_entry_set_text(GTK_ENTRY(entry_incext
),
312 prefs_common
.extinc_cmd
);
313 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_autochk_hour
),
314 prefs_common
.autochk_itv
/ 3600);
315 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_autochk_min
),
316 (prefs_common
.autochk_itv
% 3600) / 60);
317 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_autochk_sec
),
318 (prefs_common
.autochk_itv
% 3600) % 60);
319 combobox_select_by_data(GTK_COMBO_BOX(optmenu_recvdialog
),
320 prefs_common
.recv_dialog_mode
);
322 prefs_receive
->window
= GTK_WIDGET(window
);
323 prefs_receive
->checkbtn_incext
= checkbtn_incext
;
324 prefs_receive
->entry_incext
= entry_incext
;
325 prefs_receive
->checkbtn_autochk
= checkbtn_autochk
;
326 prefs_receive
->spinbtn_autochk_sec
= spinbtn_autochk_sec
;
327 prefs_receive
->spinbtn_autochk_min
= spinbtn_autochk_min
;
328 prefs_receive
->spinbtn_autochk_hour
= spinbtn_autochk_hour
;
329 prefs_receive
->checkbtn_chkonstartup
= checkbtn_chkonstartup
;
330 prefs_receive
->checkbtn_openinbox
= checkbtn_openinbox
;
331 prefs_receive
->checkbtn_scan_after_inc
= checkbtn_scan_after_inc
;
332 prefs_receive
->checkbtn_newmail_auto
= checkbtn_newmail_auto
;
333 prefs_receive
->checkbtn_newmail_manu
= checkbtn_newmail_manu
;
334 prefs_receive
->entry_newmail_notify_cmd
= entry_newmail_notify_cmd
;
335 prefs_receive
->hbox_newmail_notify
= hbox_newmail_notify
;
337 prefs_receive
->optmenu_recvdialog
= optmenu_recvdialog
;
338 prefs_receive
->checkbtn_no_recv_err_panel
= checkbtn_no_recv_err_panel
;
339 prefs_receive
->checkbtn_close_recv_dialog
= checkbtn_close_recv_dialog
;
340 prefs_receive
->page
.widget
= vbox1
;
342 g_signal_connect(G_OBJECT(checkbtn_newmail_auto
), "toggled",
343 G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb
),
345 g_signal_connect(G_OBJECT(checkbtn_newmail_manu
), "toggled",
346 G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb
),
348 g_signal_connect(G_OBJECT(spinbtn_autochk_hour
), "value-changed",
349 G_CALLBACK(prefs_receive_itv_spinbutton_value_changed_cb
),
350 (gpointer
) prefs_receive
);
351 g_signal_connect(G_OBJECT(spinbtn_autochk_min
), "value-changed",
352 G_CALLBACK(prefs_receive_itv_spinbutton_value_changed_cb
),
353 (gpointer
) prefs_receive
);
354 g_signal_connect(G_OBJECT(spinbtn_autochk_sec
), "value-changed",
355 G_CALLBACK(prefs_receive_itv_spinbutton_value_changed_cb
),
356 (gpointer
) prefs_receive
);
359 static void prefs_receive_save(PrefsPage
*_page
)
361 ReceivePage
*page
= (ReceivePage
*) _page
;
364 prefs_common
.use_extinc
= gtk_toggle_button_get_active(
365 GTK_TOGGLE_BUTTON(page
->checkbtn_incext
));
366 prefs_common
.no_recv_err_panel
= gtk_toggle_button_get_active(
367 GTK_TOGGLE_BUTTON(page
->checkbtn_no_recv_err_panel
));
368 prefs_common
.close_recv_dialog
= gtk_toggle_button_get_active(
369 GTK_TOGGLE_BUTTON(page
->checkbtn_close_recv_dialog
));
370 prefs_common
.chk_on_startup
= gtk_toggle_button_get_active(
371 GTK_TOGGLE_BUTTON(page
->checkbtn_chkonstartup
));
372 prefs_common
.open_inbox_on_inc
= gtk_toggle_button_get_active(
373 GTK_TOGGLE_BUTTON(page
->checkbtn_openinbox
));
374 prefs_common
.scan_all_after_inc
= gtk_toggle_button_get_active(
375 GTK_TOGGLE_BUTTON(page
->checkbtn_scan_after_inc
));
377 prefs_common
.newmail_notify_auto
= gtk_toggle_button_get_active(
378 GTK_TOGGLE_BUTTON(page
->checkbtn_newmail_auto
));
379 prefs_common
.newmail_notify_manu
= gtk_toggle_button_get_active(
380 GTK_TOGGLE_BUTTON(page
->checkbtn_newmail_manu
));
381 prefs_common
.autochk_newmail
= gtk_toggle_button_get_active(
382 GTK_TOGGLE_BUTTON(page
->checkbtn_autochk
));
383 prefs_common
.autochk_itv
=
384 (3600 * gtk_spin_button_get_value_as_int(
385 GTK_SPIN_BUTTON(page
->spinbtn_autochk_hour
)))
386 + (60 * gtk_spin_button_get_value_as_int(
387 GTK_SPIN_BUTTON(page
->spinbtn_autochk_min
)))
388 + gtk_spin_button_get_value_as_int(
389 GTK_SPIN_BUTTON(page
->spinbtn_autochk_sec
));
391 tmp
= gtk_editable_get_chars(GTK_EDITABLE(page
->entry_incext
), 0, -1);
392 g_free(prefs_common
.extinc_cmd
);
393 prefs_common
.extinc_cmd
= tmp
;
395 tmp
= gtk_editable_get_chars(GTK_EDITABLE(page
->entry_newmail_notify_cmd
), 0, -1);
396 g_free(prefs_common
.newmail_notify_cmd
);
397 prefs_common
.newmail_notify_cmd
= tmp
;
398 prefs_common
.recv_dialog_mode
=
399 combobox_get_active_data(GTK_COMBO_BOX(page
->optmenu_recvdialog
));
401 inc_autocheck_timer_remove();
402 inc_autocheck_timer_set();
406 static void prefs_receive_destroy_widget(PrefsPage
*_page
)
410 void prefs_receive_init(void)
413 static gchar
*path
[3];
415 path
[0] = _("Mail Handling");
416 path
[1] = _("Receiving");
419 page
= g_new0(ReceivePage
, 1);
420 page
->page
.path
= path
;
421 page
->page
.create_widget
= prefs_receive_create_widget
;
422 page
->page
.destroy_widget
= prefs_receive_destroy_widget
;
423 page
->page
.save_page
= prefs_receive_save
;
424 page
->page
.weight
= 200.0;
425 prefs_gtk_register_page((PrefsPage
*) page
);
426 prefs_receive
= page
;
429 void prefs_receive_done(void)
431 prefs_gtk_unregister_page((PrefsPage
*) prefs_receive
);
432 g_free(prefs_receive
);