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-GdaDataModel.html
27  * outPack = gda
28  * outFile = DataModel
29  * strct   = GdaDataModel
30  * realStrct=
31  * ctorStrct=
32  * clss    = DataModel
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = GObject
38  * implements:
39  * prefixes:
40  * 	- gda_data_model_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ListG
48  * 	- gda.FieldAttributes
49  * 	- gda.Row
50  * 	- gda.Value
51  * structWrap:
52  * 	- GList* -> ListG
53  * 	- GdaFieldAttributes* -> FieldAttributes
54  * 	- GdaRow* -> Row
55  * 	- GdaValue* -> Value
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gda.DataModel;
62 
63 public  import gdac.gdatypes;
64 
65 private import gdac.gda;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 
70 private import glib.Str;
71 private import glib.ListG;
72 private import gda.FieldAttributes;
73 private import gda.Row;
74 private import gda.Value;
75 
76 
77 
78 private import gobject.ObjectG;
79 
80 /**
81  * Description
82  */
83 public class DataModel : ObjectG
84 {
85 	
86 	/** the main Gtk struct */
87 	protected GdaDataModel* gdaDataModel;
88 	
89 	
90 	public GdaDataModel* getDataModelStruct()
91 	{
92 		return gdaDataModel;
93 	}
94 	
95 	
96 	/** the main Gtk struct as a void* */
97 	protected override void* getStruct()
98 	{
99 		return cast(void*)gdaDataModel;
100 	}
101 	
102 	/**
103 	 * Sets our main struct and passes it to the parent class
104 	 */
105 	public this (GdaDataModel* gdaDataModel)
106 	{
107 		super(cast(GObject*)gdaDataModel);
108 		this.gdaDataModel = gdaDataModel;
109 	}
110 	
111 	protected override void setStruct(GObject* obj)
112 	{
113 		super.setStruct(obj);
114 		gdaDataModel = cast(GdaDataModel*)obj;
115 	}
116 	
117 	/** */
118 	this (ListG glist) {
119 		this( cast(GdaDataModel*)glist.data );
120 	}
121 	
122 	/**
123 	 */
124 	
125 	/**
126 	 * Notifies listeners of the given data model object of changes
127 	 * in the underlying data. Listeners usually will connect
128 	 * themselves to the "changed" signal in the GdaDataModel
129 	 * class, thus being notified of any new data being appended
130 	 * or removed from the data model.
131 	 */
132 	public void changed()
133 	{
134 		// void gda_data_model_changed (GdaDataModel *model);
135 		gda_data_model_changed(gdaDataModel);
136 	}
137 	
138 	/**
139 	 * Emits the 'row_inserted' and 'changed' signals on model.
140 	 * Params:
141 	 * row = row number.
142 	 */
143 	public void rowInserted(int row)
144 	{
145 		// void gda_data_model_row_inserted (GdaDataModel *model,  gint row);
146 		gda_data_model_row_inserted(gdaDataModel, row);
147 	}
148 	
149 	/**
150 	 * Emits the 'row_updated' and 'changed' signals on model.
151 	 * Params:
152 	 * row = row number.
153 	 */
154 	public void rowUpdated(int row)
155 	{
156 		// void gda_data_model_row_updated (GdaDataModel *model,  gint row);
157 		gda_data_model_row_updated(gdaDataModel, row);
158 	}
159 	
160 	/**
161 	 * Emits the 'row_removed' and 'changed' signal on model.
162 	 * Params:
163 	 * row = row number.
164 	 */
165 	public void rowRemoved(int row)
166 	{
167 		// void gda_data_model_row_removed (GdaDataModel *model,  gint row);
168 		gda_data_model_row_removed(gdaDataModel, row);
169 	}
170 	
171 	/**
172 	 * Emits the 'column_inserted' and 'changed' signals on model.
173 	 * Params:
174 	 * col = column number.
175 	 */
176 	public void columnInserted(int col)
177 	{
178 		// void gda_data_model_column_inserted (GdaDataModel *model,  gint col);
179 		gda_data_model_column_inserted(gdaDataModel, col);
180 	}
181 	
182 	/**
183 	 * Emits the 'column_updated' and 'changed' signals on model.
184 	 * Params:
185 	 * col = column number.
186 	 */
187 	public void columnUpdated(int col)
188 	{
189 		// void gda_data_model_column_updated (GdaDataModel *model,  gint col);
190 		gda_data_model_column_updated(gdaDataModel, col);
191 	}
192 	
193 	/**
194 	 * Emits the 'column_removed' and 'changed' signal on model.
195 	 * Params:
196 	 * col = column number.
197 	 */
198 	public void columnRemoved(int col)
199 	{
200 		// void gda_data_model_column_removed (GdaDataModel *model,  gint col);
201 		gda_data_model_column_removed(gdaDataModel, col);
202 	}
203 	
204 	/**
205 	 * Disables notifications of changes on the given data model. To
206 	 * re-enable notifications again, you should call the
207 	 * gda_data_model_thaw function.
208 	 */
209 	public void freeze()
210 	{
211 		// void gda_data_model_freeze (GdaDataModel *model);
212 		gda_data_model_freeze(gdaDataModel);
213 	}
214 	
215 	/**
216 	 * Re-enables notifications of changes on the given data model.
217 	 */
218 	public void thaw()
219 	{
220 		// void gda_data_model_thaw (GdaDataModel *model);
221 		gda_data_model_thaw(gdaDataModel);
222 	}
223 	
224 	/**
225 	 * Returns: the number of rows in the given data model.
226 	 */
227 	public int getNRows()
228 	{
229 		// gint gda_data_model_get_n_rows (GdaDataModel *model);
230 		return gda_data_model_get_n_rows(gdaDataModel);
231 	}
232 	
233 	/**
234 	 * Returns: the number of columns in the given data model.
235 	 */
236 	public int getNColumns()
237 	{
238 		// gint gda_data_model_get_n_columns (GdaDataModel *model);
239 		return gda_data_model_get_n_columns(gdaDataModel);
240 	}
241 	
242 	/**
243 	 * Queries the underlying data model implementation for a description
244 	 * of a given column. That description is returned in the form of
245 	 * a GdaFieldAttributes structure, which contains all the information
246 	 * about the given column in the data model.
247 	 * Params:
248 	 * col = column number.
249 	 * Returns: the description of the column.
250 	 */
251 	public FieldAttributes describeColumn(int col)
252 	{
253 		// GdaFieldAttributes* gda_data_model_describe_column (GdaDataModel *model,  gint col);
254 		auto p = gda_data_model_describe_column(gdaDataModel, col);
255 		
256 		if(p is null)
257 		{
258 			return null;
259 		}
260 		
261 		return ObjectG.getDObject!(FieldAttributes)(cast(GdaFieldAttributes*) p);
262 	}
263 	
264 	/**
265 	 * Params:
266 	 * col = column number.
267 	 * Returns: the title for the given column in a data model object.
268 	 */
269 	public string getColumnTitle(int col)
270 	{
271 		// const gchar* gda_data_model_get_column_title (GdaDataModel *model,  gint col);
272 		return Str.toString(gda_data_model_get_column_title(gdaDataModel, col));
273 	}
274 	
275 	/**
276 	 * Sets the title of the given col in model.
277 	 * Params:
278 	 * col = column number
279 	 * title = title for the given column.
280 	 */
281 	public void setColumnTitle(int col, string title)
282 	{
283 		// void gda_data_model_set_column_title (GdaDataModel *model,  gint col,  const gchar *title);
284 		gda_data_model_set_column_title(gdaDataModel, col, Str.toStringz(title));
285 	}
286 	
287 	/**
288 	 * Gets the position of a column on the data model, based on
289 	 * the column's title.
290 	 * Params:
291 	 * title = column title.
292 	 * Returns: the position of the column in the data model, or -1 if the column could not be found.
293 	 */
294 	public int getColumnPosition(string title)
295 	{
296 		// gint gda_data_model_get_column_position (GdaDataModel *model,  const gchar *title);
297 		return gda_data_model_get_column_position(gdaDataModel, Str.toStringz(title));
298 	}
299 	
300 	/**
301 	 * Retrieves a given row from a data model.
302 	 * Params:
303 	 * row = row number.
304 	 * Returns: a GdaRow object.
305 	 */
306 	public Row getRow(int row)
307 	{
308 		// const GdaRow* gda_data_model_get_row (GdaDataModel *model,  gint row);
309 		auto p = gda_data_model_get_row(gdaDataModel, row);
310 		
311 		if(p is null)
312 		{
313 			return null;
314 		}
315 		
316 		return ObjectG.getDObject!(Row)(cast(GdaRow*) p);
317 	}
318 	
319 	/**
320 	 * Retrieves the data stored in the given position (identified by
321 	 * the col and row parameters) on a data model.
322 	 * This is the main function for accessing data in a model.
323 	 * Params:
324 	 * col = column number.
325 	 * row = row number.
326 	 * Returns: a GdaValue containing the value stored in the given position, or NULL on error (out-of-bound position, etc).
327 	 */
328 	public Value getValueAt(int col, int row)
329 	{
330 		// const GdaValue* gda_data_model_get_value_at (GdaDataModel *model,  gint col,  gint row);
331 		auto p = gda_data_model_get_value_at(gdaDataModel, col, row);
332 		
333 		if(p is null)
334 		{
335 			return null;
336 		}
337 		
338 		return ObjectG.getDObject!(Value)(cast(GdaValue*) p);
339 	}
340 	
341 	/**
342 	 * Checks whether the given data model can be updated or not.
343 	 * Returns: TRUE if it can be updated, FALSE if not.
344 	 */
345 	public int isUpdatable()
346 	{
347 		// gboolean gda_data_model_is_updatable (GdaDataModel *model);
348 		return gda_data_model_is_updatable(gdaDataModel);
349 	}
350 	
351 	/**
352 	 * Appends a row to the given data model.
353 	 * Params:
354 	 * values = GList of GdaValue* representing the row to add. The
355 	 *  length must match model's column count. These GdaValue
356 	 *  are value-copied. The user is still responsible for freeing them.
357 	 * Returns: the added row.
358 	 */
359 	public Row appendRow(ListG values)
360 	{
361 		// const GdaRow* gda_data_model_append_row (GdaDataModel *model,  const GList *values);
362 		auto p = gda_data_model_append_row(gdaDataModel, (values is null) ? null : values.getListGStruct());
363 		
364 		if(p is null)
365 		{
366 			return null;
367 		}
368 		
369 		return ObjectG.getDObject!(Row)(cast(GdaRow*) p);
370 	}
371 	
372 	/**
373 	 * Removes a row from the data model. This results in the underlying
374 	 * database row being removed in the database.
375 	 * Params:
376 	 * row = the GdaRow to be removed.
377 	 * Returns: TRUE if successful, FALSE otherwise.
378 	 */
379 	public int removeRow(Row row)
380 	{
381 		// gboolean gda_data_model_remove_row (GdaDataModel *model,  const GdaRow *row);
382 		return gda_data_model_remove_row(gdaDataModel, (row is null) ? null : row.getRowStruct());
383 	}
384 	
385 	/**
386 	 * Updates a row data model. This results in the underlying
387 	 * database row's values being changed.
388 	 * Params:
389 	 * row = the GdaRow to be updated.
390 	 * Returns: TRUE if successful, FALSE otherwise.
391 	 */
392 	public int updateRow(Row row)
393 	{
394 		// gboolean gda_data_model_update_row (GdaDataModel *model,  const GdaRow *row);
395 		return gda_data_model_update_row(gdaDataModel, (row is null) ? null : row.getRowStruct());
396 	}
397 	
398 	/**
399 	 * Appends a column to the given data model. If successful, the position of
400 	 * the new column in the data model is set on col, and you can grab it using
401 	 * gda_field_attributes_get_position.
402 	 * Params:
403 	 * attrs = a GdaFieldAttributes describing the column to add.
404 	 * Returns: TRUE if successful, FALSE otherwise.
405 	 */
406 	public int appendColumn(FieldAttributes attrs)
407 	{
408 		// gboolean gda_data_model_append_column (GdaDataModel *model,  const GdaFieldAttributes *attrs);
409 		return gda_data_model_append_column(gdaDataModel, (attrs is null) ? null : attrs.getFieldAttributesStruct());
410 	}
411 	
412 	/**
413 	 * Updates a column in the given data model. This results in the underlying
414 	 * database row's values being changed.
415 	 * Params:
416 	 * col = the column to be updated.
417 	 * attrs = attributes for the column.
418 	 * Returns: TRUE if successful, FALSE otherwise.
419 	 */
420 	public int updateColumn(int col, FieldAttributes attrs)
421 	{
422 		// gboolean gda_data_model_update_column (GdaDataModel *model,  gint col,  const GdaFieldAttributes *attrs);
423 		return gda_data_model_update_column(gdaDataModel, col, (attrs is null) ? null : attrs.getFieldAttributesStruct());
424 	}
425 	
426 	/**
427 	 * Removes a column from the data model. This means that all values attached to this
428 	 * column in the data model will be destroyed in the underlying database.
429 	 * Params:
430 	 * col = the column to be removed.
431 	 * Returns: TRUE if successful, FALSE otherwise.
432 	 */
433 	public int removeColumn(int col)
434 	{
435 		// gboolean gda_data_model_remove_column (GdaDataModel *model,  gint col);
436 		return gda_data_model_remove_column(gdaDataModel, col);
437 	}
438 	
439 	/**
440 	 * Calls the specified callback function for each row in the data model.
441 	 * This will just traverse all rows, and call the given callback
442 	 * function for each of them.
443 	 * Params:
444 	 * func = callback function.
445 	 * userData = context data for the callback function.
446 	 */
447 	public void foreac(GdaDataModelForeachFunc func, void* userData)
448 	{
449 		// void gda_data_model_foreach (GdaDataModel *model,  GdaDataModelForeachFunc func,  gpointer user_data);
450 		gda_data_model_foreach(gdaDataModel, func, userData);
451 	}
452 	
453 	/**
454 	 * Checks whether this data model is in updating mode or not. Updating
455 	 * mode is set to TRUE when gda_data_model_begin_update has been
456 	 * called successfully, and is not set back to FALSE until either
457 	 * gda_data_model_cancel_update or gda_data_model_end_update have
458 	 * been called.
459 	 * Returns: TRUE if updating mode, FALSE otherwise.
460 	 */
461 	public int hasChanged()
462 	{
463 		// gboolean gda_data_model_has_changed (GdaDataModel *model);
464 		return gda_data_model_has_changed(gdaDataModel);
465 	}
466 	
467 	/**
468 	 * Starts update of this data model. This function should be the
469 	 * first called when modifying the data model.
470 	 * Returns: TRUE on success, FALSE if there was an error.
471 	 */
472 	public int beginUpdate()
473 	{
474 		// gboolean gda_data_model_begin_update (GdaDataModel *model);
475 		return gda_data_model_begin_update(gdaDataModel);
476 	}
477 	
478 	/**
479 	 * Cancels update of this data model. This means that all changes
480 	 * will be discarded, and the old data put back in the model.
481 	 * Returns: TRUE on success, FALSE if there was an error.
482 	 */
483 	public int cancelUpdate()
484 	{
485 		// gboolean gda_data_model_cancel_update (GdaDataModel *model);
486 		return gda_data_model_cancel_update(gdaDataModel);
487 	}
488 	
489 	/**
490 	 * Approves all modifications and send them to the underlying
491 	 * data source/store.
492 	 * Returns: TRUE on success, FALSE if there was an error.
493 	 */
494 	public int endUpdate()
495 	{
496 		// gboolean gda_data_model_end_update (GdaDataModel *model);
497 		return gda_data_model_end_update(gdaDataModel);
498 	}
499 	
500 	/**
501 	 * Converts the given model into a comma-separated series of rows.
502 	 * Returns: the representation of the model. You should free this string when you no longer need it.
503 	 */
504 	public string toCommaSeparated()
505 	{
506 		// gchar* gda_data_model_to_comma_separated (GdaDataModel *model);
507 		return Str.toString(gda_data_model_to_comma_separated(gdaDataModel));
508 	}
509 	
510 	/**
511 	 * Converts the given model into a tab-separated series of rows.
512 	 * Returns: the representation of the model. You should free this string when you no longer need it.
513 	 */
514 	public string toTabSeparated()
515 	{
516 		// gchar* gda_data_model_to_tab_separated (GdaDataModel *model);
517 		return Str.toString(gda_data_model_to_tab_separated(gdaDataModel));
518 	}
519 	
520 	/**
521 	 * Converts the given model into a XML representation.
522 	 * Params:
523 	 * standalone = whether ...
524 	 * Returns: the representation of the model. You should free this string when you no longer need it.
525 	 */
526 	public string toXml(int standalone)
527 	{
528 		// gchar* gda_data_model_to_xml (GdaDataModel *model,  gboolean standalone);
529 		return Str.toString(gda_data_model_to_xml(gdaDataModel, standalone));
530 	}
531 	
532 	/**
533 	 * Converts a GdaDataModel into a xmlNodePtr (as used in libxml).
534 	 * Params:
535 	 * name = name to use for the XML resulting table.
536 	 * Returns: a xmlNodePtr representing the whole data model.
537 	 */
538 	public xmlNodePtr toXmlNode(string name)
539 	{
540 		// xmlNodePtr gda_data_model_to_xml_node (GdaDataModel *model,  const gchar *name);
541 		return gda_data_model_to_xml_node(gdaDataModel, Str.toStringz(name));
542 	}
543 	
544 	/**
545 	 * Adds the data from a XML node to the given data model.
546 	 * Params:
547 	 * node = a XML node representing a lt;datagt; XML node.
548 	 * Returns: TRUE if successful, FALSE otherwise.
549 	 */
550 	public int addDataFromXmlNode(xmlNodePtr node)
551 	{
552 		// gboolean gda_data_model_add_data_from_xml_node  (GdaDataModel *model,  xmlNodePtr node);
553 		return gda_data_model_add_data_from_xml_node(gdaDataModel, node);
554 	}
555 	
556 	/**
557 	 * Gets the text of command that generated this data model.
558 	 * Returns: a string with the command issued.
559 	 */
560 	public string getCommandText()
561 	{
562 		// const gchar* gda_data_model_get_command_text (GdaDataModel *model);
563 		return Str.toString(gda_data_model_get_command_text(gdaDataModel));
564 	}
565 	
566 	/**
567 	 * Sets the command text of the given model.
568 	 * Params:
569 	 * txt = the command text.
570 	 */
571 	public void setCommandText(string txt)
572 	{
573 		// void gda_data_model_set_command_text (GdaDataModel *model,  const gchar *txt);
574 		gda_data_model_set_command_text(gdaDataModel, Str.toStringz(txt));
575 	}
576 	
577 	/**
578 	 * Gets the type of command that generated this data model.
579 	 * Returns: a GdaCommandType.
580 	 */
581 	public GdaCommandType getCommandType()
582 	{
583 		// GdaCommandType gda_data_model_get_command_type (GdaDataModel *model);
584 		return gda_data_model_get_command_type(gdaDataModel);
585 	}
586 	
587 	/**
588 	 * Sets the type of command that generated this data model.
589 	 * Params:
590 	 * type = the type of the command (one of GdaCommandType)
591 	 */
592 	public void setCommandType(GdaCommandType type)
593 	{
594 		// void gda_data_model_set_command_type (GdaDataModel *model,  GdaCommandType type);
595 		gda_data_model_set_command_type(gdaDataModel, type);
596 	}
597 }