enable NNTP over SSL
[claws.git] / src / prefs.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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_H__
21 #define __PREFS_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 _PrefFile        PrefFile;
34 typedef struct _PrefsDialog     PrefsDialog;
35
36 #include "account.h"
37
38 #define VSPACING                10
39 #define VSPACING_NARROW         4
40 #define VSPACING_NARROW_2       2
41 #define VBOX_BORDER             16
42 #define DEFAULT_ENTRY_WIDTH     80
43 #define PREFSBUFSIZE            1024
44
45 typedef enum
46 {
47         P_STRING,
48         P_INT,
49         P_BOOL,
50         P_ENUM,
51         P_USHORT,
52         P_OTHER
53 } PrefType;
54
55 typedef void (*DataSetFunc)   (PrefParam *pparam);
56 typedef void (*WidgetSetFunc) (PrefParam *pparam);
57
58 struct _PrefParam {
59         gchar         *name;
60         gchar         *defval;
61         gpointer       data;
62         PrefType       type;
63         GtkWidget    **widget;
64         DataSetFunc    data_set_func;
65         WidgetSetFunc  widget_set_func;
66 };
67
68 struct _PrefFile {
69         FILE *fp;
70         gchar *path;
71 };
72
73 struct _PrefsDialog 
74 {
75         GtkWidget *window;
76         GtkWidget *notebook;
77
78         GtkWidget *ok_btn;
79         GtkWidget *cancel_btn;
80         GtkWidget *apply_btn;
81 };
82
83 #define SET_NOTEBOOK_LABEL(notebook, str, page_num) \
84 { \
85         GtkWidget *label; \
86         gint i = page_num;      \
87   \
88         label = gtk_label_new (str); \
89         gtk_widget_show (label); \
90         gtk_notebook_set_tab_label \
91                 (GTK_NOTEBOOK (notebook), \
92                  gtk_notebook_get_nth_page \
93                         (GTK_NOTEBOOK (notebook), i), \
94                  label); \
95         gtk_notebook_set_menu_label_text \
96                 (GTK_NOTEBOOK (notebook), \
97                  gtk_notebook_get_nth_page \
98                         (GTK_NOTEBOOK (notebook), i), \
99                  str);\
100 }
101
102 #define PACK_CHECK_BUTTON(box, chkbtn, label) \
103 { \
104         chkbtn = gtk_check_button_new_with_label(label); \
105         gtk_widget_show(chkbtn); \
106         gtk_box_pack_start(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
107 }
108
109 #define PACK_END_CHECK_BUTTON(box, chkbtn, label) \
110 { \
111         chkbtn = gtk_check_button_new_with_label(label); \
112         gtk_widget_show(chkbtn); \
113         gtk_box_pack_end(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
114 }
115
116 #define PACK_FRAME(box, frame, label) \
117 { \
118         frame = gtk_frame_new(label); \
119         gtk_widget_show(frame); \
120         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \
121         gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \
122 }
123
124 #define PACK_VSPACER(box, vbox, spacing) \
125 { \
126         vbox = gtk_vbox_new(FALSE, 0); \
127         gtk_widget_show(vbox); \
128         gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \
129 }
130
131 #define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \
132 { \
133         gtk_widget_set_sensitive(targetwid, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
134         gtk_signal_connect(GTK_OBJECT(togglewid), "toggled", \
135                            GTK_SIGNAL_FUNC(prefs_button_toggled), targetwid); \
136 }
137
138 void prefs_read_config          (PrefParam      *param,
139                                  const gchar    *label,
140                                  const gchar    *rcfile);
141 void prefs_config_parse_one_line(PrefParam      *param,
142                                  const gchar    *buf);
143 void prefs_save_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_dialog_create        (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 gboolean prefs_is_readonly(const gchar * path);
174 gboolean prefs_rc_is_readonly(const gchar * rcfile);
175
176 #endif /* __PREFS_H__ */