File: kz-profile.h

package info (click to toggle)
kazehakase 0.5.8-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 8,184 kB
  • ctags: 7,837
  • sloc: ansic: 64,119; sh: 19,622; cpp: 12,601; ruby: 1,590; makefile: 1,437; xml: 464
file content (245 lines) | stat: -rw-r--r-- 6,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 * Profile
 * copyright (c) 2002-2003 Kazuki IWAMOTO http://www.maid.org/ iwm@maid.org
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 *  2003-09-03 Takuro Ashie <ashie@homa.ne.jp>
 *      Added Kz and kz_ prefix.
 *      GObjectize.
 *      Added const keyword for value field of KzPrrofileList.
 *
 *  2003-08-28 Takuro Ashie <ashie@homa.ne.jp>
 *      Translated comments into English.
 *
 *  2003-08-27 Takuro Ashie <ashie@homa.ne.jp>
 *      Modified coding style.
 *      Changed interface of profile_open().
 */

#ifndef __KZ_PROFILE_H__
#define __KZ_PROFILE_H__

/* #include "common.h" */
#include <glib.h>
#include <glib-object.h>

G_BEGIN_DECLS

#define KZ_TYPE_PROFILE			(kz_profile_get_type ())
#define KZ_PROFILE(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_PROFILE, KzProfile))
#define KZ_PROFILE_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_PROFILE, KzProfileClass))
#define KZ_IS_PROFILE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_PROFILE))
#define KZ_IS_PROFILE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_PROFILE))
#define KZ_PROFILE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_PROFILE, KzProfileClass))


typedef struct KzProfile_Tag      KzProfile;
typedef struct KzProfileClass_Tag KzProfileClass;
typedef struct KzProfileList_Tag  KzProfileList;


#define KZ_PROFILE_DATA_TYPE_UNKNOW  0
#define KZ_PROFILE_DATA_TYPE_SPACE   1
#define KZ_PROFILE_DATA_TYPE_COMMENT 2
#define KZ_PROFILE_DATA_TYPE_SECTION 3
#define KZ_PROFILE_DATA_TYPE_KEY     4

#define KZ_PROFILE_VALUE_TYPE_BOOL   0
#define KZ_PROFILE_VALUE_TYPE_INT    1
#define KZ_PROFILE_VALUE_TYPE_STRING 2
#define KZ_PROFILE_VALUE_TYPE_ARRAY  3


struct KzProfile_Tag
{
	GObject parent;

	gboolean auto_save;
	gboolean edit;
	gchar *file, *subfile;
	KzProfileList *list, *sublist;
};


struct KzProfileList_Tag
{
	gchar *data, *section, *key;
	const gchar *value;
	guint type;
	struct KzProfileList_Tag *prev, *next;
};


struct KzProfileClass_Tag
{
	GObjectClass parent_class;

	/* -- signals -- */
	void (*section_added)   (KzProfile *profile,
				 const gchar *section);
	void (*section_deleted) (KzProfile *profile,
				 const gchar *section);
	void (*key_added)       (KzProfile *profile,
				 const gchar *section,
				 const gchar *key);
	void (*key_deleted)     (KzProfile *profile,
				 const gchar *section,
				 const gchar *key);
	void (*changed)         (KzProfile *profile,
				 const gchar *section,
				 const gchar *key,
				 const gchar *old_value);
};


GType      kz_profile_get_type (void) G_GNUC_CONST;
KzProfile *kz_profile_new      (void);


/*
 * Open the initialize file.
 * @file,file name
 * @RET,the KzProfile struct
 */
KzProfile *kz_profile_open (const gchar *file,
			    const gchar *subfile);

/*
 * Close the initialize file.
 * @profile,the KzProfile struct
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_close (KzProfile *profile);


/*
 * Save the initialize file.
 * @profile,the KzProfile struct
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_save (KzProfile *profile);


/*
 * Get a string from the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @key,name of the key
 * @RET,string,NULL:error
 */
gchar *kz_profile_get_string (KzProfile *profile,
			      const gchar *section,
			      const gchar *key);


/*
 * Get size of a value.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @key,name of the key
 * @type,value type
 * @RET,bytes,0:error
 */
gint kz_profile_get_size (KzProfile *profile,
			  const gchar *section,
			  const gchar *key,
			  const guint type);


/*
 * Get a value from the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @key,name of the key
 * @value,buffer to store value.
 * @size,size of buffer to store value.
 * @type,value type
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_get_value (KzProfile *profile,
			       const gchar *section,
			       const gchar *key,
			       gpointer value,
			       const gint size,
			       const guint type);


/*
 * Set a value into the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @key,name of the key
 * @value,buffer which store the value.
 * @size,size of buffer which store the value.
 * @type,value type
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_set_value (KzProfile *profile,
			       const gchar *section,
			       const gchar *key,
			       gconstpointer value,
			       const size_t size,
			       const guint type);


/*
 * Delete a section from the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_delete_section (KzProfile *profile,
				    const gchar *section);


/*
 * Delete a key from the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @key,key
 * @RET,TRUE:normal exit,FALSE:error
 */
gboolean kz_profile_delete_key (KzProfile *profile,
				const gchar *section,
				const gchar *key);


/*
 * Enumerate sections in the initialize file.
 * @profile,the KzProfile struct
 * @RET,list of sections,NULL:error
 */
GList *kz_profile_enum_section (KzProfile *profile);


/*
 * Enumelate keys in the initialize file.
 * @profile,the KzProfile struct
 * @section,name of the section
 * @RET,list of keys,NULL:error
*/
GList *kz_profile_enum_key (KzProfile *profile,
			    const gchar *section,
			    gboolean users_only);

void   kz_profile_set_auto_save (KzProfile *profile,
    				 gboolean auto_save);

G_END_DECLS

#endif /* __KZ_PROFILE_H__ */