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