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