2005-09-08 [colin] 1.9.14cvs9
[claws.git] / src / prefs_gtk.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 VSPACING                10
40 #define VSPACING_NARROW         4
41 #define VSPACING_NARROW_2       2
42 #define VBOX_BORDER             16
43 #define DEFAULT_ENTRY_WIDTH     80
44 #define PREFSBUFSIZE            1024
45
46 typedef enum
47 {
48         P_STRING,
49         P_INT,
50         P_BOOL,
51         P_ENUM,
52         P_USHORT,
53         P_COLOR,
54         P_PASSWORD,
55         P_OTHER
56 } PrefType;
57
58 typedef void (*DataSetFunc)   (PrefParam *pparam);
59 typedef void (*WidgetSetFunc) (PrefParam *pparam);
60
61 struct _PrefParam {
62         gchar         *name;
63         gchar         *defval;
64         gpointer       data;
65         PrefType       type;
66         GtkWidget    **widget;
67         DataSetFunc    data_set_func;
68         WidgetSetFunc  widget_set_func;
69 };
70
71 struct _PrefsDialog 
72 {
73         GtkWidget *window;
74         GtkWidget *notebook;
75
76         GtkWidget *ok_btn;
77         GtkWidget *cancel_btn;
78         GtkWidget *apply_btn;
79 };
80
81 #define SET_NOTEBOOK_LABEL(notebook, str, page_num) \
82 { \
83         GtkWidget *label; \
84         gint i = page_num;      \
85   \
86         label = gtk_label_new (str); \
87         gtk_widget_show (label); \
88         gtk_notebook_set_tab_label \
89                 (GTK_NOTEBOOK (notebook), \
90                  gtk_notebook_get_nth_page \
91                         (GTK_NOTEBOOK (notebook), i), \
92                  label); \
93         gtk_notebook_set_menu_label_text \
94                 (GTK_NOTEBOOK (notebook), \
95                  gtk_notebook_get_nth_page \
96                         (GTK_NOTEBOOK (notebook), i), \
97                  str);\
98 }
99
100 #define PACK_CHECK_BUTTON(box, chkbtn, label) \
101 { \
102         chkbtn = gtk_check_button_new_with_label(label); \
103         gtk_widget_show(chkbtn); \
104         gtk_box_pack_start(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
105 }
106
107 #define PACK_END_CHECK_BUTTON(box, chkbtn, label) \
108 { \
109         chkbtn = gtk_check_button_new_with_label(label); \
110         gtk_widget_show(chkbtn); \
111         gtk_box_pack_end(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
112 }
113
114 #define PACK_FRAME(box, frame, label) \
115 { \
116         frame = gtk_frame_new(label); \
117         gtk_widget_show(frame); \
118         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \
119         gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \
120 }
121
122 #define PACK_VSPACER(box, vbox, spacing) \
123 { \
124         vbox = gtk_vbox_new(FALSE, 0); \
125         gtk_widget_show(vbox); \
126         gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \
127 }
128
129 #define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \
130 { \
131         gtk_widget_set_sensitive(targetwid, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
132         g_signal_connect(G_OBJECT(togglewid), "toggled", \
133                          G_CALLBACK(prefs_button_toggled), targetwid); \
134 }
135
136 void prefs_read_config          (PrefParam      *param,
137                                  const gchar    *label,
138                                  const gchar    *rcfile,
139                                  const gchar    *encoding);
140 void prefs_config_parse_one_line(PrefParam      *param,
141                                  const gchar    *buf);
142 void prefs_write_config         (PrefParam      *param,
143                                  const gchar    *label,
144                                  const gchar    *rcfile);
145 gint prefs_write_param          (PrefParam      *param,
146                                  FILE           *fp);
147
148 PrefFile *prefs_write_open      (const gchar    *path);
149 gint prefs_write_close          (PrefFile       *pfile);
150 gint prefs_write_close_revert   (PrefFile       *pfile);
151
152 void prefs_set_default          (PrefParam      *param);
153 void prefs_free                 (PrefParam      *param);
154
155 void prefs_dialog_create        (PrefsDialog    *dialog);
156 void prefs_dialog_destroy       (PrefsDialog    *dialog);
157
158 void prefs_button_toggled       (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_entry            (PrefParam      *pparam);
167 void prefs_set_data_from_text   (PrefParam      *pparam);
168 void prefs_set_text             (PrefParam      *pparam);
169 void prefs_set_data_from_toggle (PrefParam      *pparam);
170 void prefs_set_toggle           (PrefParam      *pparam);
171 void prefs_set_data_from_spinbtn(PrefParam      *pparam);
172 void prefs_set_spinbtn          (PrefParam      *pparam);
173
174 void prefs_gtk_open             (void);
175 void prefs_gtk_register_page    (PrefsPage      *page);
176 void prefs_gtk_unregister_page  (PrefsPage      *page);
177
178 #endif /* __PREFS_H__ */