1 /*
2  * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  * Copyright (C) 2010 Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301, USA.
19  */
20 
21 #ifndef __GDA_TREE_MANAGER_H__
22 #define __GDA_TREE_MANAGER_H__
23 
24 #include <glib-object.h>
25 #include "gda-decl.h"
26 
27 G_BEGIN_DECLS
28 
29 #define GDA_TYPE_TREE_MANAGER            (gda_tree_manager_get_type())
30 #define GDA_TREE_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_TREE_MANAGER, GdaTreeManager))
31 #define GDA_TREE_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_TREE_MANAGER, GdaTreeManagerClass))
32 #define GDA_IS_TREE_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_TREE_MANAGER))
33 #define GDA_IS_TREE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_TREE_MANAGER))
34 #define GDA_TREE_MANAGER_GET_CLASS(o)	 (G_TYPE_INSTANCE_GET_CLASS ((o), GDA_TYPE_TREE_MANAGER, GdaTreeManagerClass))
35 
36 typedef GSList *(*GdaTreeManagerNodesFunc) (GdaTreeManager *manager, GdaTreeNode *node,
37 					    const GSList *children_nodes,
38 					    gboolean *out_error, GError **error);
39 typedef GdaTreeNode *(*GdaTreeManagerNodeFunc) (GdaTreeManager *manager, GdaTreeNode *parent, const gchar *name);
40 
41 /* error reporting */
42 extern GQuark gda_tree_manager_error_quark (void);
43 #define GDA_TREE_MANAGER_ERROR gda_tree_manager_error_quark ()
44 
45 typedef enum {
46 	GDA_TREE_MANAGER_UNKNOWN_ERROR
47 } GdaTreeManagerError;
48 
49 struct _GdaTreeManager {
50 	GObject            object;
51 	GdaTreeManagerPrivate *priv;
52 };
53 
54 struct _GdaTreeManagerClass {
55 	GObjectClass       object_class;
56 
57 	/* virtual methods */
58 	/**
59 	 * update_children:
60 	 *
61 	 * Returns: NULL if an error occurred, and @out_error is set to TRUE
62 	 */
63 	GSList *(*update_children) (GdaTreeManager *manager, GdaTreeNode *node,
64 				    const GSList *children_nodes,
65 				    gboolean *out_error, GError **error);
66 
67 	/*< private >*/
68 	/* Padding for future expansion */
69 	void (*_gda_reserved1) (void);
70 	void (*_gda_reserved2) (void);
71 	void (*_gda_reserved3) (void);
72 	void (*_gda_reserved4) (void);
73 };
74 
75 /**
76  * SECTION:gda-tree-manager
77  * @short_description: Base class for all the tree managers
78  * @title: GdaTreeManager
79  * @stability: Stable
80  * @see_also:
81  *
82  * A #GdaTreeManager object is responsible for creating nodes in the tree(s) for which it
83  * operates.
84  *
85  * When creating nodes, a #GdaTreeManager object can (depending on its implementation), get some
86  * named attributes from the node below which it has to create nodes, using the gda_tree_node_fetch_attribute()
87  * or gda_tree_node_get_node_attribute(). For example the #GdaTreeMgrColumns manager (which creates a node for each column
88  * of a table) needs the table name and the schema in which the table is; both can be specified using an
89  * object's property, or, if not specified that way, are fetched as attributes.
90  *
91  * The #GdaTreeManager itself is an abstract type (which can't be instantiated). Use an existing sub class or subclass
92  * it yourself.
93  */
94 
95 GType                  gda_tree_manager_get_type                 (void) G_GNUC_CONST;
96 
97 GdaTreeManager        *gda_tree_manager_new_with_func            (GdaTreeManagerNodesFunc update_func);
98 void                   gda_tree_manager_add_manager              (GdaTreeManager *manager, GdaTreeManager *sub);
99 const GSList          *gda_tree_manager_get_managers             (GdaTreeManager *manager);
100 
101 void                   gda_tree_manager_set_node_create_func     (GdaTreeManager *manager, GdaTreeManagerNodeFunc func);
102 GdaTreeManagerNodeFunc gda_tree_manager_get_node_create_func     (GdaTreeManager *manager);
103 
104 void                   gda_tree_manager_add_new_node_attribute   (GdaTreeManager *manager, const gchar *attribute, const GValue *value);
105 GdaTreeNode           *gda_tree_manager_create_node              (GdaTreeManager *manager, GdaTreeNode *parent, const gchar *name);
106 
107 /* private */
108 void                   _gda_tree_manager_update_children         (GdaTreeManager *manager, GdaTreeNode *node,
109 								  const GSList *children_nodes,
110 								  gboolean *out_error, GError **error);
111 
112 
113 G_END_DECLS
114 
115 #endif
116