2007-01-13 [colin] 2.7.0cvs21
[claws.git] / src / prefs_other.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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
37 #include "gtk/gtkutils.h"
38 #include "gtk/prefswindow.h"
39
40 #include "manage_window.h"
41 #ifdef HAVE_LIBETPAN
42 #include "imap-thread.h"
43 #endif
44
45 typedef struct _OtherPage
46 {
47         PrefsPage page;
48
49         GtkWidget *window;
50
51         GtkWidget *checkbtn_addaddrbyclick;
52         GtkWidget *checkbtn_confonexit;
53         GtkWidget *checkbtn_cleanonexit;
54         GtkWidget *checkbtn_askonclean;
55         GtkWidget *checkbtn_warnqueued;
56         GtkWidget *checkbtn_cliplog;
57         GtkWidget *spinbtn_loglength;
58         GtkWidget *spinbtn_iotimeout;
59         GtkWidget *chkbtn_never_send_retrcpt;
60 } OtherPage;
61
62 void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, 
63                                   gpointer data)
64 {
65         OtherPage *prefs_other = (OtherPage *) _page;
66         
67         GtkWidget *vbox1;
68         GtkWidget *hbox1;
69
70         GtkWidget *frame_addr;
71         GtkWidget *vbox_addr;
72         GtkWidget *checkbtn_addaddrbyclick;
73         
74         GtkWidget *frame_cliplog;
75         GtkWidget *vbox_cliplog;
76         GtkWidget *hbox_cliplog;
77         GtkWidget *checkbtn_cliplog;
78         GtkWidget *loglength_label;
79         GtkWidget *spinbtn_loglength;
80         GtkObject *spinbtn_loglength_adj;
81         GtkTooltips *loglength_tooltip;
82         GtkWidget *label;
83
84         GtkWidget *frame_exit;
85         GtkWidget *vbox_exit;
86         GtkWidget *checkbtn_confonexit;
87         GtkWidget *checkbtn_cleanonexit;
88         GtkWidget *checkbtn_askonclean;
89         GtkWidget *checkbtn_warnqueued;
90
91         GtkWidget *label_iotimeout;
92         GtkWidget *spinbtn_iotimeout;
93         GtkObject *spinbtn_iotimeout_adj;
94
95         GtkWidget *chkbtn_never_send_retrcpt;
96
97         vbox1 = gtk_vbox_new (FALSE, VSPACING);
98         gtk_widget_show (vbox1);
99         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
100
101         vbox_addr = gtkut_get_options_frame(vbox1, &frame_addr, _("Address book"));
102
103         PACK_CHECK_BUTTON
104                 (vbox_addr, checkbtn_addaddrbyclick,
105                  _("Add address to destination when double-clicked"));
106
107         /* Clip Log */
108         vbox_cliplog = gtkut_get_options_frame(vbox1, &frame_cliplog, _("Log Size"));
109
110         PACK_CHECK_BUTTON (vbox_cliplog, checkbtn_cliplog,
111                            _("Clip the log size"));
112         hbox_cliplog = gtk_hbox_new (FALSE, 8);
113         gtk_container_add (GTK_CONTAINER (vbox_cliplog), hbox_cliplog);
114         gtk_widget_show (hbox_cliplog);
115         
116         loglength_label = gtk_label_new (_("Log window length"));
117         gtk_box_pack_start (GTK_BOX (hbox_cliplog), loglength_label,
118                             FALSE, TRUE, 0);
119         gtk_widget_show (GTK_WIDGET (loglength_label));
120         
121         loglength_tooltip = gtk_tooltips_new();
122
123         spinbtn_loglength_adj = gtk_adjustment_new (500, 0, G_MAXINT, 1, 10, 10);
124         spinbtn_loglength = gtk_spin_button_new
125                 (GTK_ADJUSTMENT (spinbtn_loglength_adj), 1, 0);
126         gtk_widget_show (spinbtn_loglength);
127         gtk_box_pack_start (GTK_BOX (hbox_cliplog), spinbtn_loglength,
128                             FALSE, FALSE, 0);
129         gtk_widget_set_size_request (GTK_WIDGET (spinbtn_loglength), 64, -1);
130         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_loglength), TRUE);
131
132         gtk_tooltips_set_tip(GTK_TOOLTIPS(loglength_tooltip), spinbtn_loglength,
133                              _("0 to stop logging in the log window"),
134                              NULL);
135
136         label = gtk_label_new(_("lines"));
137         gtk_widget_show (label);
138         gtk_box_pack_start(GTK_BOX(hbox_cliplog), label, FALSE, FALSE, 0);
139
140         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, loglength_label);
141         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, spinbtn_loglength);
142         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, label);
143
144         /* On Exit */
145         vbox_exit = gtkut_get_options_frame(vbox1, &frame_exit, _("On exit"));
146
147         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
148                            _("Confirm on exit"));
149
150         hbox1 = gtk_hbox_new (FALSE, 32);
151         gtk_widget_show (hbox1);
152         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
153
154         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
155                            _("Empty trash on exit"));
156         PACK_CHECK_BUTTON (hbox1, checkbtn_askonclean,
157                            _("Ask before emptying"));
158         SET_TOGGLE_SENSITIVITY (checkbtn_cleanonexit, checkbtn_askonclean);
159
160         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
161                            _("Warn if there are queued messages"));
162
163         hbox1 = gtk_hbox_new (FALSE, 8);
164         gtk_widget_show (hbox1);
165         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
166
167         label_iotimeout = gtk_label_new (_("Socket I/O timeout"));
168         gtk_widget_show (label_iotimeout);
169         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
170
171         spinbtn_iotimeout_adj = gtk_adjustment_new (60, 0, 1000, 1, 10, 10);
172         spinbtn_iotimeout = gtk_spin_button_new
173                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
174         gtk_widget_show (spinbtn_iotimeout);
175         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
176                             FALSE, FALSE, 0);
177         gtk_widget_set_size_request (spinbtn_iotimeout, 64, -1);
178         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
179
180         label_iotimeout = gtk_label_new (_("seconds"));
181         gtk_widget_show (label_iotimeout);
182         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
183
184         PACK_CHECK_BUTTON(vbox1, chkbtn_never_send_retrcpt,
185                           _("Never send Return Receipts"));
186
187         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
188                 prefs_common.add_address_by_click);
189         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
190                 prefs_common.confirm_on_exit);
191         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
192                 prefs_common.clean_on_exit);
193         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
194                 prefs_common.ask_on_clean);
195         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
196                 prefs_common.warn_queued_on_exit);
197         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cliplog), 
198                 prefs_common.cliplog);
199         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_never_send_retrcpt),
200                 prefs_common.never_send_retrcpt);
201         
202         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_loglength),
203                 prefs_common.loglength);
204         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
205                 prefs_common.io_timeout_secs);
206
207         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
208         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
209         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
210         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
211         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
212         prefs_other->checkbtn_cliplog = checkbtn_cliplog;
213         prefs_other->spinbtn_loglength = spinbtn_loglength;
214         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
215         prefs_other->chkbtn_never_send_retrcpt = chkbtn_never_send_retrcpt;
216
217         prefs_other->page.widget = vbox1;
218 }
219
220 void prefs_other_save(PrefsPage *_page)
221 {
222         OtherPage *page = (OtherPage *) _page;
223         MainWindow *mainwindow;
224
225         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
226                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
227         prefs_common.confirm_on_exit = gtk_toggle_button_get_active(
228                 GTK_TOGGLE_BUTTON(page->checkbtn_confonexit));
229         prefs_common.clean_on_exit = gtk_toggle_button_get_active(
230                 GTK_TOGGLE_BUTTON(page->checkbtn_cleanonexit)); 
231         prefs_common.ask_on_clean = gtk_toggle_button_get_active(
232                 GTK_TOGGLE_BUTTON(page->checkbtn_askonclean));
233         prefs_common.warn_queued_on_exit = gtk_toggle_button_get_active(
234                 GTK_TOGGLE_BUTTON(page->checkbtn_warnqueued)); 
235         prefs_common.cliplog = gtk_toggle_button_get_active(
236                 GTK_TOGGLE_BUTTON(page->checkbtn_cliplog));
237         prefs_common.loglength = gtk_spin_button_get_value_as_int(
238                 GTK_SPIN_BUTTON(page->spinbtn_loglength));
239         prefs_common.io_timeout_secs = gtk_spin_button_get_value_as_int(
240                 GTK_SPIN_BUTTON(page->spinbtn_iotimeout));
241         sock_set_io_timeout(prefs_common.io_timeout_secs);
242 #ifdef HAVE_LIBETPAN
243         imap_main_set_timeout(prefs_common.io_timeout_secs);
244 #endif
245         prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
246                 GTK_TOGGLE_BUTTON(page->chkbtn_never_send_retrcpt));
247         mainwindow = mainwindow_get_mainwindow();
248         log_window_set_clipping(mainwindow->logwin, prefs_common.cliplog,
249                                 prefs_common.loglength);
250
251 }
252
253 static void prefs_other_destroy_widget(PrefsPage *_page)
254 {
255 }
256
257 OtherPage *prefs_other;
258
259 void prefs_other_init(void)
260 {
261         OtherPage *page;
262         static gchar *path[2];
263
264         path[0] = _("Other");
265         path[1] = NULL;
266
267         page = g_new0(OtherPage, 1);
268         page->page.path = path;
269         page->page.create_widget = prefs_other_create_widget;
270         page->page.destroy_widget = prefs_other_destroy_widget;
271         page->page.save_page = prefs_other_save;
272         page->page.weight = 5.0;
273         prefs_gtk_register_page((PrefsPage *) page);
274         prefs_other = page;
275 }
276
277 void prefs_other_done(void)
278 {
279         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
280         g_free(prefs_other);
281 }