4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "e-tree-model.h"
31 static guint signals
[LAST_SIGNAL
];
33 G_DEFINE_INTERFACE (ETreeModel
, e_tree_model
, G_TYPE_OBJECT
)
36 e_tree_model_default_init (ETreeModelInterface
*iface
)
38 signals
[PRE_CHANGE
] = g_signal_new (
40 G_TYPE_FROM_INTERFACE (iface
),
42 G_STRUCT_OFFSET (ETreeModelInterface
, pre_change
),
46 signals
[REBUILT
] = g_signal_new (
48 G_TYPE_FROM_INTERFACE (iface
),
50 G_STRUCT_OFFSET (ETreeModelInterface
, rebuilt
),
54 signals
[NODE_CHANGED
] = g_signal_new (
56 G_TYPE_FROM_INTERFACE (iface
),
58 G_STRUCT_OFFSET (ETreeModelInterface
, node_changed
),
63 signals
[NODE_DATA_CHANGED
] = g_signal_new (
65 G_TYPE_FROM_INTERFACE (iface
),
67 G_STRUCT_OFFSET (ETreeModelInterface
, node_data_changed
),
72 signals
[NODE_INSERTED
] = g_signal_new (
74 G_TYPE_FROM_INTERFACE (iface
),
76 G_STRUCT_OFFSET (ETreeModelInterface
, node_inserted
),
82 signals
[NODE_REMOVED
] = g_signal_new (
84 G_TYPE_FROM_INTERFACE (iface
),
86 G_STRUCT_OFFSET (ETreeModelInterface
, node_removed
),
93 signals
[NODE_DELETED
] = g_signal_new (
95 G_TYPE_FROM_INTERFACE (iface
),
97 G_STRUCT_OFFSET (ETreeModelInterface
, node_deleted
),
104 * e_tree_model_pre_change:
110 e_tree_model_pre_change (ETreeModel
*tree_model
)
112 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
114 g_signal_emit (tree_model
, signals
[PRE_CHANGE
], 0);
118 * e_tree_model_rebuilt:
124 e_tree_model_rebuilt (ETreeModel
*tree_model
)
126 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
128 g_signal_emit (tree_model
, signals
[REBUILT
], 0);
131 * e_tree_model_node_changed:
140 e_tree_model_node_changed (ETreeModel
*tree_model
,
143 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
145 g_signal_emit (tree_model
, signals
[NODE_CHANGED
], 0, path
);
149 * e_tree_model_node_data_changed:
158 e_tree_model_node_data_changed (ETreeModel
*tree_model
,
161 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
163 g_signal_emit (tree_model
, signals
[NODE_DATA_CHANGED
], 0, path
);
167 * e_tree_model_node_inserted:
175 e_tree_model_node_inserted (ETreeModel
*tree_model
,
176 ETreePath parent_path
,
177 ETreePath inserted_path
)
179 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
182 tree_model
, signals
[NODE_INSERTED
], 0,
183 parent_path
, inserted_path
);
187 * e_tree_model_node_removed:
195 e_tree_model_node_removed (ETreeModel
*tree_model
,
196 ETreePath parent_path
,
197 ETreePath removed_path
,
200 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
203 tree_model
, signals
[NODE_REMOVED
], 0,
204 parent_path
, removed_path
, old_position
);
208 * e_tree_model_node_deleted:
215 e_tree_model_node_deleted (ETreeModel
*tree_model
,
216 ETreePath deleted_path
)
218 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
220 g_signal_emit (tree_model
, signals
[NODE_DELETED
], 0, deleted_path
);
224 * e_tree_model_get_root
225 * @tree_model: the ETreeModel of which we want the root node.
227 * Accessor for the root node of @tree_model.
229 * return values: the ETreePath corresponding to the root node.
232 e_tree_model_get_root (ETreeModel
*tree_model
)
234 ETreeModelInterface
*iface
;
236 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
238 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
239 g_return_val_if_fail (iface
->get_root
!= NULL
, NULL
);
241 return iface
->get_root (tree_model
);
245 * e_tree_model_node_get_parent:
254 e_tree_model_node_get_parent (ETreeModel
*tree_model
,
257 ETreeModelInterface
*iface
;
259 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
261 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
262 g_return_val_if_fail (iface
->get_parent
!= NULL
, NULL
);
264 return iface
->get_parent (tree_model
, path
);
268 * e_tree_model_node_get_first_child:
277 e_tree_model_node_get_first_child (ETreeModel
*tree_model
,
280 ETreeModelInterface
*iface
;
282 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
284 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
285 g_return_val_if_fail (iface
->get_first_child
!= NULL
, NULL
);
287 return iface
->get_first_child (tree_model
, path
);
291 * e_tree_model_node_get_next:
300 e_tree_model_node_get_next (ETreeModel
*tree_model
,
303 ETreeModelInterface
*iface
;
305 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
307 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
308 g_return_val_if_fail (iface
->get_next
!= NULL
, NULL
);
310 return iface
->get_next (tree_model
, path
);
314 * e_tree_model_node_is_root:
323 e_tree_model_node_is_root (ETreeModel
*tree_model
,
326 ETreeModelInterface
*iface
;
328 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), FALSE
);
330 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
331 g_return_val_if_fail (iface
->is_root
!= NULL
, FALSE
);
333 return iface
->is_root (tree_model
, path
);
337 * e_tree_model_node_is_expandable:
346 e_tree_model_node_is_expandable (ETreeModel
*tree_model
,
349 ETreeModelInterface
*iface
;
351 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), FALSE
);
352 g_return_val_if_fail (path
!= NULL
, FALSE
);
354 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
355 g_return_val_if_fail (iface
->is_expandable
!= NULL
, FALSE
);
357 return iface
->is_expandable (tree_model
, path
);
361 e_tree_model_node_get_n_nodes (ETreeModel
*tree_model
)
363 ETreeModelInterface
*iface
;
365 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), 0);
367 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
368 g_return_val_if_fail (iface
->get_n_nodes
!= NULL
, 0);
370 return iface
->get_n_nodes (tree_model
);
374 e_tree_model_node_get_n_children (ETreeModel
*tree_model
,
377 ETreeModelInterface
*iface
;
379 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), 0);
381 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
382 g_return_val_if_fail (iface
->get_n_children
!= NULL
, 0);
384 return iface
->get_n_children (tree_model
, path
);
388 * e_tree_model_node_depth:
397 e_tree_model_node_depth (ETreeModel
*tree_model
,
400 ETreeModelInterface
*iface
;
402 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), 0);
404 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
405 g_return_val_if_fail (iface
->depth
!= NULL
, 0);
407 return iface
->depth (tree_model
, path
);
411 * e_tree_model_get_expanded_default
412 * @tree_model: The ETreeModel.
416 * return values: Whether nodes should be expanded by default.
419 e_tree_model_get_expanded_default (ETreeModel
*tree_model
)
421 ETreeModelInterface
*iface
;
423 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), FALSE
);
425 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
426 g_return_val_if_fail (iface
->get_expanded_default
!= NULL
, FALSE
);
428 return iface
->get_expanded_default (tree_model
);
432 * e_tree_model_column_count
433 * @tree_model: The ETreeModel.
437 * return values: The number of columns
440 e_tree_model_column_count (ETreeModel
*tree_model
)
442 ETreeModelInterface
*iface
;
444 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), 0);
446 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
447 g_return_val_if_fail (iface
->column_count
!= NULL
, 0);
449 return iface
->column_count (tree_model
);
453 * e_tree_model_get_save_id
454 * @tree_model: The ETreeModel.
455 * @path: The ETreePath.
459 * return values: The save id for this path.
462 e_tree_model_get_save_id (ETreeModel
*tree_model
,
465 ETreeModelInterface
*iface
;
467 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
469 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
470 g_return_val_if_fail (iface
->get_save_id
!= NULL
, NULL
);
472 return iface
->get_save_id (tree_model
, path
);
476 * e_tree_model_get_node_by_id
477 * @tree_model: The ETreeModel.
480 * get_node_by_id(get_save_id(node)) should be the original node.
481 * Likewise if get_node_by_id is not NULL, then
482 * get_save_id(get_node_by_id(string)) should be a copy of the
485 * return values: The path for this save id.
488 e_tree_model_get_node_by_id (ETreeModel
*tree_model
,
489 const gchar
*save_id
)
491 ETreeModelInterface
*iface
;
493 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
495 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
496 g_return_val_if_fail (iface
->get_node_by_id
!= NULL
, NULL
);
498 return iface
->get_node_by_id (tree_model
, save_id
);
502 * e_tree_model_sort_value_at:
503 * @tree_model: The ETreeModel.
504 * @path: The ETreePath to the node we're getting the data from.
505 * @col: the column to retrieve data from
507 * Return value: This function returns the value that is stored by the
508 * @tree_model in column @col and node @path. The data returned can be a
509 * pointer or any data value that can be stored inside a pointer.
511 * The data returned is typically used by an sort renderer if it wants
512 * to proxy the data of cell value_at at a better sorting order.
514 * The data returned must be valid until the model sends a signal that
515 * affect that piece of data. node_changed and node_deleted affect
516 * all data in tha t node and all nodes under that node.
517 * node_data_changed affects the data in that node. node_col_changed
518 * affects the data in that node for that column. node_inserted,
519 * node_removed, and no_change don't affect any data in this way.
522 e_tree_model_sort_value_at (ETreeModel
*tree_model
,
526 ETreeModelInterface
*iface
;
528 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
530 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
531 g_return_val_if_fail (iface
->sort_value_at
!= NULL
, NULL
);
533 return iface
->sort_value_at (tree_model
, path
, col
);
537 * e_tree_model_value_at:
538 * @tree_model: The ETreeModel.
539 * @path: The ETreePath to the node we're getting the data from.
540 * @col: the column to retrieve data from
542 * Return value: This function returns the value that is stored by the
543 * @tree_model in column @col and node @path. The data returned can be a
544 * pointer or any data value that can be stored inside a pointer.
546 * The data returned is typically used by an ECell renderer.
548 * The data returned must be valid until the model sends a signal that
549 * affect that piece of data. node_changed and node_deleted affect
550 * all data in tha t node and all nodes under that node.
551 * node_data_changed affects the data in that node. node_col_changed
552 * affects the data in that node for that column. node_inserted,
553 * node_removed, and no_change don't affect any data in this way.
556 e_tree_model_value_at (ETreeModel
*tree_model
,
560 ETreeModelInterface
*iface
;
562 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
564 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
565 g_return_val_if_fail (iface
->value_at
!= NULL
, NULL
);
567 return iface
->value_at (tree_model
, path
, col
);
571 * e_tree_model_duplicate_value:
580 e_tree_model_duplicate_value (ETreeModel
*tree_model
,
584 ETreeModelInterface
*iface
;
586 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
588 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
589 g_return_val_if_fail (iface
->duplicate_value
!= NULL
, NULL
);
591 return iface
->duplicate_value (tree_model
, col
, value
);
595 * e_tree_model_free_value:
604 e_tree_model_free_value (ETreeModel
*tree_model
,
608 ETreeModelInterface
*iface
;
610 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
612 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
613 g_return_if_fail (iface
->free_value
!= NULL
);
615 iface
->free_value (tree_model
, col
, value
);
619 * e_tree_model_initialize_value:
628 e_tree_model_initialize_value (ETreeModel
*tree_model
,
631 ETreeModelInterface
*iface
;
633 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
635 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
636 g_return_val_if_fail (iface
->initialize_value
!= NULL
, NULL
);
638 return iface
->initialize_value (tree_model
, col
);
642 * e_tree_model_value_is_empty:
651 e_tree_model_value_is_empty (ETreeModel
*tree_model
,
655 ETreeModelInterface
*iface
;
657 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), TRUE
);
659 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
660 g_return_val_if_fail (iface
->value_is_empty
!= NULL
, TRUE
);
662 return iface
->value_is_empty (tree_model
, col
, value
);
666 * e_tree_model_value_to_string:
675 e_tree_model_value_to_string (ETreeModel
*tree_model
,
679 ETreeModelInterface
*iface
;
681 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
683 iface
= E_TREE_MODEL_GET_INTERFACE (tree_model
);
684 g_return_val_if_fail (iface
->value_to_string
!= NULL
, NULL
);
686 return iface
->value_to_string (tree_model
, col
, value
);
690 * e_tree_model_node_traverse:
699 e_tree_model_node_traverse (ETreeModel
*tree_model
,
706 g_return_if_fail (E_IS_TREE_MODEL (tree_model
));
707 g_return_if_fail (path
!= NULL
);
709 child
= e_tree_model_node_get_first_child (tree_model
, path
);
712 ETreePath next_child
;
714 next_child
= e_tree_model_node_get_next (tree_model
, child
);
715 e_tree_model_node_traverse (tree_model
, child
, func
, data
);
716 if (func (tree_model
, child
, data
))
724 e_tree_model_node_real_traverse (ETreeModel
*model
,
732 g_return_val_if_fail (E_IS_TREE_MODEL (model
), NULL
);
733 g_return_val_if_fail (path
!= NULL
, NULL
);
735 child
= e_tree_model_node_get_first_child (model
, path
);
740 if (child
== end_path
|| func (model
, child
, data
))
743 if ((result
= e_tree_model_node_real_traverse (
744 model
, child
, end_path
, func
, data
)))
747 child
= e_tree_model_node_get_next (model
, child
);
754 * e_tree_model_node_find:
764 e_tree_model_node_find (ETreeModel
*tree_model
,
773 g_return_val_if_fail (E_IS_TREE_MODEL (tree_model
), NULL
);
775 /* Just search the whole tree in this case. */
778 root
= e_tree_model_get_root (tree_model
);
780 if (end_path
== root
|| func (tree_model
, root
, data
))
783 result
= e_tree_model_node_real_traverse (
784 tree_model
, root
, end_path
, func
, data
);
793 if ((result
= e_tree_model_node_real_traverse (
794 tree_model
, path
, end_path
, func
, data
)))
796 next
= e_tree_model_node_get_next (tree_model
, path
);
798 while (next
== NULL
) {
799 path
= e_tree_model_node_get_parent (tree_model
, path
);
804 next
= e_tree_model_node_get_next (tree_model
, path
);
807 if (end_path
== next
|| func (tree_model
, next
, data
))