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