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