2006-09-03 [paul] 2.4.0cvs136
[claws.git] / src / prefs_other.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2005-2006 Colin Leroy <colin@colino.net> & The Sylpheed-Claws 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         PACK_FRAME (vbox1, frame_addr, _("Address book"));
102
103         vbox_addr = gtk_vbox_new (FALSE, 0);
104         gtk_widget_show (vbox_addr);
105         gtk_container_add (GTK_CONTAINER (frame_addr), vbox_addr);
106         gtk_container_set_border_width (GTK_CONTAINER (vbox_addr), 8);
107
108         PACK_CHECK_BUTTON
109                 (vbox_addr, checkbtn_addaddrbyclick,
110                  _("Add address to destination when double-clicked"));
111
112         /* Clip Log */
113         PACK_FRAME (vbox1, frame_cliplog, _("Log Size"));
114
115         vbox_cliplog = gtk_vbox_new (FALSE, 0);
116         gtk_widget_show (vbox_cliplog);
117         gtk_container_add (GTK_CONTAINER (frame_cliplog), vbox_cliplog);
118         gtk_container_set_border_width (GTK_CONTAINER (vbox_cliplog), 8);
119         PACK_CHECK_BUTTON (vbox_cliplog, checkbtn_cliplog,
120                            _("Clip the log size"));
121         hbox_cliplog = gtk_hbox_new (FALSE, 8);
122         gtk_container_add (GTK_CONTAINER (vbox_cliplog), hbox_cliplog);
123         gtk_widget_show (hbox_cliplog);
124         
125         loglength_label = gtk_label_new (_("Log window length"));
126         gtk_box_pack_start (GTK_BOX (hbox_cliplog), loglength_label,
127                             FALSE, TRUE, 0);
128         gtk_widget_show (GTK_WIDGET (loglength_label));
129         
130         loglength_tooltip = gtk_tooltips_new();
131
132         spinbtn_loglength_adj = gtk_adjustment_new (500, 0, G_MAXINT, 1, 10, 10);
133         spinbtn_loglength = gtk_spin_button_new
134                 (GTK_ADJUSTMENT (spinbtn_loglength_adj), 1, 0);
135         gtk_widget_show (spinbtn_loglength);
136         gtk_box_pack_start (GTK_BOX (hbox_cliplog), spinbtn_loglength,
137                             FALSE, FALSE, 0);
138         gtk_widget_set_size_request (GTK_WIDGET (spinbtn_loglength), 64, -1);
139         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_loglength), TRUE);
140
141         gtk_tooltips_set_tip(GTK_TOOLTIPS(loglength_tooltip), spinbtn_loglength,
142                              _("0 to stop logging in the log window"),
143                              NULL);
144
145         label = gtk_label_new(_("lines"));
146         gtk_widget_show (label);
147         gtk_box_pack_start(GTK_BOX(hbox_cliplog), label, FALSE, FALSE, 0);
148
149         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, loglength_label);
150         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, spinbtn_loglength);
151         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, label);
152
153         /* On Exit */
154         PACK_FRAME (vbox1, frame_exit, _("On exit"));
155
156         vbox_exit = gtk_vbox_new (FALSE, 0);
157         gtk_widget_show (vbox_exit);
158         gtk_container_add (GTK_CONTAINER (frame_exit), vbox_exit);
159         gtk_container_set_border_width (GTK_CONTAINER (vbox_exit), 8);
160
161         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
162                            _("Confirm on exit"));
163
164         hbox1 = gtk_hbox_new (FALSE, 32);
165         gtk_widget_show (hbox1);
166         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
167
168         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
169                            _("Empty trash on exit"));
170         PACK_CHECK_BUTTON (hbox1, checkbtn_askonclean,
171                            _("Ask before emptying"));
172         SET_TOGGLE_SENSITIVITY (checkbtn_cleanonexit, checkbtn_askonclean);
173
174         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
175                            _("Warn if there are queued messages"));
176
177         hbox1 = gtk_hbox_new (FALSE, 8);
178         gtk_widget_show (hbox1);
179         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
180
181         label_iotimeout = gtk_label_new (_("Socket I/O timeout"));
182         gtk_widget_show (label_iotimeout);
183         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
184
185         spinbtn_iotimeout_adj = gtk_adjustment_new (60, 0, 1000, 1, 10, 10);
186         spinbtn_iotimeout = gtk_spin_button_new
187                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
188         gtk_widget_show (spinbtn_iotimeout);
189         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
190                             FALSE, FALSE, 0);
191         gtk_widget_set_size_request (spinbtn_iotimeout, 64, -1);
192         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
193
194         label_iotimeout = gtk_label_new (_("seconds"));
195         gtk_widget_show (label_iotimeout);
196         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
197
198         PACK_CHECK_BUTTON(vbox1, chkbtn_never_send_retrcpt,
199                           _("Never send Return Receipts"));
200
201         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_addaddrbyclick), 
202                 prefs_common.add_address_by_click);
203         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_confonexit), 
204                 prefs_common.confirm_on_exit);
205         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cleanonexit), 
206                 prefs_common.clean_on_exit);
207         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_askonclean), 
208                 prefs_common.ask_on_clean);
209         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_warnqueued), 
210                 prefs_common.warn_queued_on_exit);
211         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cliplog), 
212                 prefs_common.cliplog);
213         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_never_send_retrcpt),
214                 prefs_common.never_send_retrcpt);
215         
216         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_loglength),
217                 prefs_common.loglength);
218         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_iotimeout),
219                 prefs_common.io_timeout_secs);
220
221         prefs_other->checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
222         prefs_other->checkbtn_confonexit = checkbtn_confonexit;
223         prefs_other->checkbtn_cleanonexit = checkbtn_cleanonexit;
224         prefs_other->checkbtn_askonclean = checkbtn_askonclean;
225         prefs_other->checkbtn_warnqueued = checkbtn_warnqueued;
226         prefs_other->checkbtn_cliplog = checkbtn_cliplog;
227         prefs_other->spinbtn_loglength = spinbtn_loglength;
228         prefs_other->spinbtn_iotimeout = spinbtn_iotimeout;
229         prefs_other->chkbtn_never_send_retrcpt = chkbtn_never_send_retrcpt;
230
231         prefs_other->page.widget = vbox1;
232 }
233
234 void prefs_other_save(PrefsPage *_page)
235 {
236         OtherPage *page = (OtherPage *) _page;
237         MainWindow *mainwindow;
238
239         prefs_common.add_address_by_click = gtk_toggle_button_get_active(
240                 GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick));
241         prefs_common.confirm_on_exit = gtk_toggle_button_get_active(
242                 GTK_TOGGLE_BUTTON(page->checkbtn_confonexit));
243         prefs_common.clean_on_exit = gtk_toggle_button_get_active(
244                 GTK_TOGGLE_BUTTON(page->checkbtn_cleanonexit)); 
245         prefs_common.ask_on_clean = gtk_toggle_button_get_active(
246                 GTK_TOGGLE_BUTTON(page->checkbtn_askonclean));
247         prefs_common.warn_queued_on_exit = gtk_toggle_button_get_active(
248                 GTK_TOGGLE_BUTTON(page->checkbtn_warnqueued)); 
249         prefs_common.cliplog = gtk_toggle_button_get_active(
250                 GTK_TOGGLE_BUTTON(page->checkbtn_cliplog));
251         prefs_common.loglength = gtk_spin_button_get_value_as_int(
252                 GTK_SPIN_BUTTON(page->spinbtn_loglength));
253         prefs_common.io_timeout_secs = gtk_spin_button_get_value_as_int(
254                 GTK_SPIN_BUTTON(page->spinbtn_iotimeout));
255         sock_set_io_timeout(prefs_common.io_timeout_secs);
256 #ifdef HAVE_LIBETPAN
257         imap_main_set_timeout(prefs_common.io_timeout_secs);
258 #endif
259         prefs_common.never_send_retrcpt = gtk_toggle_button_get_active(
260                 GTK_TOGGLE_BUTTON(page->chkbtn_never_send_retrcpt));
261         mainwindow = mainwindow_get_mainwindow();
262         log_window_set_clipping(mainwindow->logwin, prefs_common.cliplog,
263                                 prefs_common.loglength);
264
265 }
266
267 static void prefs_other_destroy_widget(PrefsPage *_page)
268 {
269 }
270
271 OtherPage *prefs_other;
272
273 void prefs_other_init(void)
274 {
275         OtherPage *page;
276         static gchar *path[2];
277
278         path[0] = _("Other");
279         path[1] = NULL;
280
281         page = g_new0(OtherPage, 1);
282         page->page.path = path;
283         page->page.create_widget = prefs_other_create_widget;
284         page->page.destroy_widget = prefs_other_destroy_widget;
285         page->page.save_page = prefs_other_save;
286         page->page.weight = 5.0;
287         prefs_gtk_register_page((PrefsPage *) page);
288         prefs_other = page;
289 }
290
291 void prefs_other_done(void)
292 {
293         prefs_gtk_unregister_page((PrefsPage *) prefs_other);
294         g_free(prefs_other);
295 }