1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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 Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = libgda-gda-config.html
27  * outPack = gda
28  * outFile = Config
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Config
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gda_config_
41  * omit structs:
42  * omit prefixes:
43  * 	- gda_data_source_
44  * 	- gda_provider_
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- glib.ListG
50  * 	- gda.DataModel
51  * 	- gda.DataSourceInfo
52  * 	- gda.ProviderInfo
53  * structWrap:
54  * 	- GList* -> ListG
55  * 	- GdaDataModel* -> DataModel
56  * 	- GdaDataSourceInfo* -> DataSourceInfo
57  * 	- GdaProviderInfo* -> ProviderInfo
58  * module aliases:
59  * local aliases:
60  * overrides:
61  */
62 
63 module gda.Config;
64 
65 public  import gdac.gdatypes;
66 
67 private import gdac.gda;
68 private import glib.ConstructionException;
69 private import gobject.ObjectG;
70 
71 
72 private import glib.Str;
73 private import glib.ListG;
74 private import gda.DataModel;
75 private import gda.DataSourceInfo;
76 private import gda.ProviderInfo;
77 
78 
79 
80 
81 /**
82  *  The functions in this section allow applications an easy access to the libgda
83  *  configuration, thus making them able to access the list of data sources
84  *  configured in the system, for instance.
85  */
86 public class Config
87 {
88 	
89 	/**
90 	 */
91 	
92 	/**
93 	 * Gets the value of the specified configuration entry as a string. You
94 	 * are then responsible to free the returned string.
95 	 * Params:
96 	 * path = path to the configuration entry.
97 	 * Returns: the value stored at the given entry.
98 	 */
99 	public static string getString(string path)
100 	{
101 		// gchar* gda_config_get_string (const gchar *path);
102 		return Str.toString(gda_config_get_string(Str.toStringz(path)));
103 	}
104 	
105 	/**
106 	 * Gets the value of the specified configuration entry as an integer.
107 	 * Params:
108 	 * path = path to the configuration entry.
109 	 * Returns: the value stored at the given entry.
110 	 */
111 	public static int getInt(string path)
112 	{
113 		// gint gda_config_get_int (const gchar *path);
114 		return gda_config_get_int(Str.toStringz(path));
115 	}
116 	
117 	/**
118 	 * Gets the value of the specified configuration entry as a float.
119 	 * Params:
120 	 * path = path to the configuration entry.
121 	 * Returns: the value stored at the given entry.
122 	 */
123 	public static double getFloat(string path)
124 	{
125 		// gdouble gda_config_get_float (const gchar *path);
126 		return gda_config_get_float(Str.toStringz(path));
127 	}
128 	
129 	/**
130 	 * Gets the value of the specified configuration entry as a boolean.
131 	 * Params:
132 	 * path = path to the configuration entry.
133 	 * Returns: the value stored at the given entry.
134 	 */
135 	public static int getBoolean(string path)
136 	{
137 		// gboolean gda_config_get_boolean (const gchar *path);
138 		return gda_config_get_boolean(Str.toStringz(path));
139 	}
140 	
141 	/**
142 	 * Sets the given configuration entry to contain a string.
143 	 * Params:
144 	 * path = path to the configuration entry.
145 	 * newValue = new value.
146 	 */
147 	public static void setString(string path, string newValue)
148 	{
149 		// void gda_config_set_string (const gchar *path,  const gchar *new_value);
150 		gda_config_set_string(Str.toStringz(path), Str.toStringz(newValue));
151 	}
152 	
153 	/**
154 	 * Sets the given configuration entry to contain an integer.
155 	 * Params:
156 	 * path = path to the configuration entry.
157 	 * newValue = new value.
158 	 */
159 	public static void setInt(string path, int newValue)
160 	{
161 		// void gda_config_set_int (const gchar *path,  gint new_value);
162 		gda_config_set_int(Str.toStringz(path), newValue);
163 	}
164 	
165 	/**
166 	 * Sets the given configuration entry to contain a float.
167 	 * Params:
168 	 * path = path to the configuration entry.
169 	 * newValue = new value.
170 	 */
171 	public static void setFloat(string path, double newValue)
172 	{
173 		// void gda_config_set_float (const gchar *path,  gdouble new_value);
174 		gda_config_set_float(Str.toStringz(path), newValue);
175 	}
176 	
177 	/**
178 	 * Sets the given configuration entry to contain a boolean.
179 	 * Params:
180 	 * path = path to the configuration entry.
181 	 * newValue = new value.
182 	 */
183 	public static void setBoolean(string path, int newValue)
184 	{
185 		// void gda_config_set_boolean (const gchar *path,  gboolean new_value);
186 		gda_config_set_boolean(Str.toStringz(path), newValue);
187 	}
188 	
189 	/**
190 	 * Removes the given section from the configuration database.
191 	 * Params:
192 	 * path = path to the configuration section.
193 	 */
194 	public static void removeSection(string path)
195 	{
196 		// void gda_config_remove_section (const gchar *path);
197 		gda_config_remove_section(Str.toStringz(path));
198 	}
199 	
200 	/**
201 	 * Removes the given entry from the configuration database.
202 	 * If the section is empty, also remove the section.
203 	 * Params:
204 	 * path = path to the configuration entry.
205 	 */
206 	public static void removeKey(string path)
207 	{
208 		// void gda_config_remove_key (const gchar *path);
209 		gda_config_remove_key(Str.toStringz(path));
210 	}
211 	
212 	/**
213 	 * Checks whether the given section exists in the configuration
214 	 * system.
215 	 * Params:
216 	 * path = path to the configuration section.
217 	 * Returns: TRUE if the section exists, FALSE otherwise.
218 	 */
219 	public static int hasSection(string path)
220 	{
221 		// gboolean gda_config_has_section (const gchar *path);
222 		return gda_config_has_section(Str.toStringz(path));
223 	}
224 	
225 	/**
226 	 * Checks whether the given key exists in the configuration system.
227 	 * Params:
228 	 * path = path to the configuration key.
229 	 * Returns: TRUE if the entry exists, FALSE otherwise.
230 	 */
231 	public static int hasKey(string path)
232 	{
233 		// gboolean gda_config_has_key (const gchar *path);
234 		return gda_config_has_key(Str.toStringz(path));
235 	}
236 	
237 	/**
238 	 * Returns a GList containing the names of all the sections available
239 	 * under the given root directory.
240 	 * To free the returned value, you can use gda_config_free_list.
241 	 * Params:
242 	 * path = path for root dir.
243 	 * Returns: a list containing all the section names.
244 	 */
245 	public static ListG listSections(string path)
246 	{
247 		// GList* gda_config_list_sections (const gchar *path);
248 		auto p = gda_config_list_sections(Str.toStringz(path));
249 		
250 		if(p is null)
251 		{
252 			return null;
253 		}
254 		
255 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
256 	}
257 	
258 	/**
259 	 * Returns a list of all keys that exist under the given path.
260 	 * To free the returned value, you can use gda_config_free_list.
261 	 * Params:
262 	 * path = path for root dir.
263 	 * Returns: a list containing all the key names.
264 	 */
265 	public static ListG listKeys(string path)
266 	{
267 		// GList* gda_config_list_keys (const gchar *path);
268 		auto p = gda_config_list_keys(Str.toStringz(path));
269 		
270 		if(p is null)
271 		{
272 			return null;
273 		}
274 		
275 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
276 	}
277 	
278 	/**
279 	 * Gets a string representing the type of the value of the given key.
280 	 * The caller is responsible of freeing the returned value.
281 	 * Params:
282 	 * path = path to the configuration key.
283 	 * Returns: NULL if not found. Otherwise: "string", "float", "long", "bool".
284 	 */
285 	public static string getType(string path)
286 	{
287 		// gchar* gda_config_get_type (const gchar *path);
288 		return Str.toString(gda_config_get_type(Str.toStringz(path)));
289 	}
290 	
291 	/**
292 	 * Frees all memory used by the given GList, which must be the return value
293 	 * from either gda_config_list_sections and gda_config_list_keys.
294 	 * Params:
295 	 * list = list to be freed.
296 	 */
297 	public static void freeList(ListG list)
298 	{
299 		// void gda_config_free_list (GList *list);
300 		gda_config_free_list((list is null) ? null : list.getListGStruct());
301 	}
302 	
303 	/**
304 	 * Installs a configuration listener, which is a callback function
305 	 * which will be called every time a change occurs on a given
306 	 * configuration entry.
307 	 * Params:
308 	 * path = configuration path to listen to.
309 	 * func = callback function.
310 	 * userData = data to be passed to the callback function.
311 	 * Returns: the ID of the listener, which you will need for calling gda_config_remove_listener. If an error occurs, 0 is returned.
312 	 */
313 	public static uint addListener(string path, GdaConfigListenerFunc func, void* userData)
314 	{
315 		// guint gda_config_add_listener (const gchar *path,  GdaConfigListenerFunc func,  gpointer user_data);
316 		return gda_config_add_listener(Str.toStringz(path), func, userData);
317 	}
318 	
319 	/**
320 	 * Removes a configuration listener previously installed with
321 	 * gda_config_add_listener, given its ID.
322 	 * Params:
323 	 * id = the ID of the listener to remove.
324 	 */
325 	public static void removeListener(uint id)
326 	{
327 		// void gda_config_remove_listener (guint id);
328 		gda_config_remove_listener(id);
329 	}
330 	
331 	/**
332 	 * Returns a list of all providers currently installed in
333 	 * the system. Each of the nodes in the returned GList
334 	 * is a GdaProviderInfo. To free the returned list,
335 	 * call the gda_config_free_provider_list function.
336 	 * Returns: a GList of GdaProviderInfo structures.
337 	 */
338 	public static ListG getProviderList()
339 	{
340 		// GList* gda_config_get_provider_list (void);
341 		auto p = gda_config_get_provider_list();
342 		
343 		if(p is null)
344 		{
345 			return null;
346 		}
347 		
348 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
349 	}
350 	
351 	/**
352 	 * Frees a list of GdaProviderInfo structures.
353 	 * Params:
354 	 * list = the list to be freed.
355 	 */
356 	public static void freeProviderList(ListG list)
357 	{
358 		// void gda_config_free_provider_list (GList *list);
359 		gda_config_free_provider_list((list is null) ? null : list.getListGStruct());
360 	}
361 	
362 	/**
363 	 * Gets a GdaProviderInfo structure from the provider list given its name.
364 	 * Params:
365 	 * name = name of the provider to search for.
366 	 * Returns: a GdaProviderInfo structure, if found, or NULL if not found.
367 	 */
368 	public static ProviderInfo getProviderByName(string name)
369 	{
370 		// GdaProviderInfo* gda_config_get_provider_by_name (const gchar *name);
371 		auto p = gda_config_get_provider_by_name(Str.toStringz(name));
372 		
373 		if(p is null)
374 		{
375 			return null;
376 		}
377 		
378 		return ObjectG.getDObject!(ProviderInfo)(cast(GdaProviderInfo*) p);
379 	}
380 	
381 	/**
382 	 * Fills and returns a new GdaDataModel object using information from all
383 	 * providers which are currently installed in the system.
384 	 * Rows are separated in 3 columns:
385 	 * 'Id', 'Location' and 'Description'.
386 	 * Returns: a new GdaDataModel object.
387 	 */
388 	public static DataModel getProviderModel()
389 	{
390 		// GdaDataModel* gda_config_get_provider_model (void);
391 		auto p = gda_config_get_provider_model();
392 		
393 		if(p is null)
394 		{
395 			return null;
396 		}
397 		
398 		return ObjectG.getDObject!(DataModel)(cast(GdaDataModel*) p);
399 	}
400 	
401 	/**
402 	 * Creates a new GdaDataSourceInfo structure from an existing one.
403 	 * Params:
404 	 * src = data source information to get a copy from.
405 	 * Returns: a newly allocated GdaDataSourceInfo with contains a copy of information in src.
406 	 */
407 	public static DataSourceInfo copyDataSourceInfo(DataSourceInfo src)
408 	{
409 		// GdaDataSourceInfo* gda_config_copy_data_source_info (GdaDataSourceInfo *src);
410 		auto p = gda_config_copy_data_source_info((src is null) ? null : src.getDataSourceInfoStruct());
411 		
412 		if(p is null)
413 		{
414 			return null;
415 		}
416 		
417 		return ObjectG.getDObject!(DataSourceInfo)(cast(GdaDataSourceInfo*) p);
418 	}
419 	
420 	/**
421 	 * Deallocates all memory associated to the given GdaDataSourceInfo.
422 	 * Params:
423 	 * info = data source information to free.
424 	 */
425 	public static void freeDataSourceInfo(DataSourceInfo info)
426 	{
427 		// void gda_config_free_data_source_info (GdaDataSourceInfo *info);
428 		gda_config_free_data_source_info((info is null) ? null : info.getDataSourceInfoStruct());
429 	}
430 	
431 	/**
432 	 * Returns a list of all data sources currently configured in the system.
433 	 * Each of the nodes in the returned GList is a GdaDataSourceInfo.
434 	 * To free the returned list, call the gda_config_free_data_source_list
435 	 * function.
436 	 * Returns: a GList of GdaDataSourceInfo structures.
437 	 */
438 	public static ListG getDataSourceList()
439 	{
440 		// GList* gda_config_get_data_source_list (void);
441 		auto p = gda_config_get_data_source_list();
442 		
443 		if(p is null)
444 		{
445 			return null;
446 		}
447 		
448 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
449 	}
450 	
451 	/**
452 	 * Gets a GdaDataSourceInfo structure from the data source list given its
453 	 * name.
454 	 * Params:
455 	 * name = name of the data source to search for.
456 	 * Returns: a GdaDataSourceInfo structure, if found, or NULL if not found.
457 	 */
458 	public static DataSourceInfo findDataSource(string name)
459 	{
460 		// GdaDataSourceInfo* gda_config_find_data_source (const gchar *name);
461 		auto p = gda_config_find_data_source(Str.toStringz(name));
462 		
463 		if(p is null)
464 		{
465 			return null;
466 		}
467 		
468 		return ObjectG.getDObject!(DataSourceInfo)(cast(GdaDataSourceInfo*) p);
469 	}
470 	
471 	/**
472 	 * Frees a list of GdaDataSourceInfo structures.
473 	 * Params:
474 	 * list = the list to be freed.
475 	 */
476 	public static void freeDataSourceList(ListG list)
477 	{
478 		// void gda_config_free_data_source_list (GList *list);
479 		gda_config_free_data_source_list((list is null) ? null : list.getListGStruct());
480 	}
481 	
482 	/**
483 	 * Fills and returns a new GdaDataModel object using information from all
484 	 * data sources which are currently configured in the system.
485 	 * Rows are separated in 6 columns:
486 	 * 'Name', 'Provider', 'Connection string', 'Description', 'Username' and
487 	 * 'Password'.
488 	 * Returns: a new GdaDataModel object.
489 	 */
490 	public static DataModel getDataSourceModel()
491 	{
492 		// GdaDataModel* gda_config_get_data_source_model (void);
493 		auto p = gda_config_get_data_source_model();
494 		
495 		if(p is null)
496 		{
497 			return null;
498 		}
499 		
500 		return ObjectG.getDObject!(DataModel)(cast(GdaDataModel*) p);
501 	}
502 	
503 	/**
504 	 * Adds a new data source (or update an existing one) to the GDA
505 	 * configuration, based on the parameters given.
506 	 * Params:
507 	 * name = name for the data source to be saved.
508 	 * provider = provider ID for the new data source.
509 	 * cncString = connection string for the new data source.
510 	 * description = description for the new data source.
511 	 * username = user name for the new data source.
512 	 * password = password to use when authenticating username.
513 	 */
514 	public static void saveDataSource(string name, string provider, string cncString, string description, string username, string password)
515 	{
516 		// void gda_config_save_data_source (const gchar *name,  const gchar *provider,  const gchar *cnc_string,  const gchar *description,  const gchar *username,  const gchar *password);
517 		gda_config_save_data_source(Str.toStringz(name), Str.toStringz(provider), Str.toStringz(cncString), Str.toStringz(description), Str.toStringz(username), Str.toStringz(password));
518 	}
519 	
520 	/**
521 	 * Saves a data source in the libgda configuration given a
522 	 * GdaDataSourceInfo structure containing all the information
523 	 * about the data source.
524 	 * Params:
525 	 * dsnInfo = a GdaDataSourceInfo structure.
526 	 */
527 	public static void saveDataSourceInfo(DataSourceInfo dsnInfo)
528 	{
529 		// void gda_config_save_data_source_info (GdaDataSourceInfo *dsn_info);
530 		gda_config_save_data_source_info((dsnInfo is null) ? null : dsnInfo.getDataSourceInfoStruct());
531 	}
532 	
533 	/**
534 	 * Removes the given data source from the GDA configuration.
535 	 * Params:
536 	 * name = name for the data source to be removed.
537 	 */
538 	public static void removeDataSource(string name)
539 	{
540 		// void gda_config_remove_data_source (const gchar *name);
541 		gda_config_remove_data_source(Str.toStringz(name));
542 	}
543 }