2011-10-20 [paul] 3.7.10cvs39
[claws.git] / src / prefs_gtk.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 Hiroyuki Yamamoto and 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 #ifndef __PREFS_GTK_H__
21 #define __PREFS_GTK_H__
22
23 #include <glib.h>
24 #include <gtk/gtk.h>
25 #include <stdio.h>
26
27 typedef struct _PrefParam       PrefParam;
28 typedef struct _PrefsDialog     PrefsDialog;
29
30 #include "prefs.h"
31 #include "account.h"
32 #include "gtk/prefswindow.h"
33
34 #define HSPACING_NARROW         4
35 #define VSPACING                10
36 #define VSPACING_NARROW         4
37 #define VSPACING_NARROW_2       2
38 #define VBOX_BORDER             8
39 #define DEFAULT_ENTRY_WIDTH     80
40 #define PREFSBUFSIZE            32768
41
42 typedef enum
43 {
44         P_STRING,
45         P_INT,
46         P_BOOL,
47         P_ENUM,
48         P_USHORT,
49         P_COLOR,
50         P_PASSWORD,
51         P_OTHER
52 } PrefType;
53
54 typedef void (*DataSetFunc)   (PrefParam *pparam);
55 typedef void (*WidgetSetFunc) (PrefParam *pparam);
56
57 struct _PrefParam {
58         gchar         *name;
59         gchar         *defval;
60         gpointer       data;
61         PrefType       type;
62         GtkWidget    **widget;
63         DataSetFunc    data_set_func;
64         WidgetSetFunc  widget_set_func;
65 };
66
67 struct _PrefsDialog 
68 {
69         GtkWidget *window;
70         GtkWidget *notebook;
71
72         GtkWidget *ok_btn;
73         GtkWidget *cancel_btn;
74         GtkWidget *apply_btn;
75 };
76
77 #define SET_NOTEBOOK_LABEL(notebook, str, page_num) \
78 { \
79         GtkWidget *label; \
80         gint i = page_num;      \
81   \
82         label = gtk_label_new_with_mnemonic (str); \
83         gtk_widget_show (label); \
84         gtk_notebook_set_tab_label \
85                 (GTK_NOTEBOOK (notebook), \
86                  gtk_notebook_get_nth_page \
87                         (GTK_NOTEBOOK (notebook), i), \
88                  label); \
89         gtk_notebook_set_menu_label_text \
90                 (GTK_NOTEBOOK (notebook), \
91                  gtk_notebook_get_nth_page \
92                         (GTK_NOTEBOOK (notebook), i), \
93                  str);\
94 }
95
96 #define PACK_CHECK_BUTTON(box, checkbtn, label) \
97 { \
98         checkbtn = gtk_check_button_new_with_label(label); \
99         gtk_widget_show(checkbtn); \
100         gtk_box_pack_start(GTK_BOX(box), checkbtn, FALSE, TRUE, 0); \
101 }
102
103 #define PACK_END_CHECK_BUTTON(box, checkbtn, label) \
104 { \
105         checkbtn = gtk_check_button_new_with_label(label); \
106         gtk_widget_show(checkbtn); \
107         gtk_box_pack_end(GTK_BOX(box), checkbtn, FALSE, TRUE, 0); \
108 }
109
110 #define PACK_FRAME(box, frame, label) \
111 { \
112         frame = gtk_frame_new(label); \
113         gtk_widget_show(frame); \
114         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \
115         gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \
116 }
117
118 #define PACK_VSPACER(box, vbox, spacing) \
119 { \
120         vbox = gtk_vbox_new(FALSE, 0); \
121         gtk_widget_show(vbox); \
122         gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \
123 }
124
125 #define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \
126 { \
127         gtk_widget_set_sensitive(targetwid, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
128         g_signal_connect(G_OBJECT(togglewid), "toggled", \
129                          G_CALLBACK(prefs_button_toggled), targetwid); \
130 }
131
132 #define SET_TOGGLE_SENSITIVITY_REVERSE(togglewid, targetwid) \
133 { \
134         gtk_widget_set_sensitive(targetwid, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
135         g_signal_connect(G_OBJECT(togglewid), "toggled", \
136                          G_CALLBACK(prefs_button_toggled_reverse), targetwid); \
137 }
138
139 void prefs_read_config          (PrefParam      *param,
140                                  const gchar    *label,
141                                  const gchar    *rcfile,
142                                  const gchar    *encoding);
143 void prefs_write_config         (PrefParam      *param,
144                                  const gchar    *label,
145                                  const gchar    *rcfile);
146 gint prefs_write_param          (PrefParam      *param,
147                                  FILE           *fp);
148
149 PrefFile *prefs_write_open      (const gchar    *path);
150 gint prefs_write_close          (PrefFile       *pfile);
151 gint prefs_write_close_revert   (PrefFile       *pfile);
152
153 void prefs_set_default          (PrefParam      *param);
154 void prefs_free                 (PrefParam      *param);
155
156 void prefs_button_toggled       (GtkToggleButton        *toggle_btn,
157                                  GtkWidget              *widget);
158 void prefs_button_toggled_reverse       (GtkToggleButton        *toggle_btn,
159                                  GtkWidget              *widget);
160
161 void prefs_set_dialog           (PrefParam      *param);
162 void prefs_set_data_from_dialog (PrefParam      *param);
163 void prefs_set_dialog_to_default(PrefParam      *param);
164
165 void prefs_set_data_from_entry  (PrefParam      *pparam);
166 void prefs_set_escaped_data_from_entry  (PrefParam      *pparam);
167 void prefs_set_entry            (PrefParam      *pparam);
168 void prefs_set_entry_from_escaped       (PrefParam      *pparam);
169 void prefs_set_data_from_text   (PrefParam      *pparam);
170 void prefs_set_escaped_data_from_text   (PrefParam      *pparam);
171 void prefs_set_text             (PrefParam      *pparam);
172 void prefs_set_text_from_escaped(PrefParam *pparam);
173 void prefs_set_data_from_toggle (PrefParam      *pparam);
174 void prefs_set_toggle           (PrefParam      *pparam);
175 void prefs_set_data_from_spinbtn(PrefParam      *pparam);
176 void prefs_set_spinbtn          (PrefParam      *pparam);
177
178 void prefs_gtk_open             (void);
179 void prefs_gtk_register_page    (PrefsPage      *page);
180 void prefs_gtk_unregister_page  (PrefsPage      *page);
181
182 void prefs_prepare_cache(void);
183 void prefs_destroy_cache(void);
184
185 #endif /* __PREFS_H__ */