3
* Copyright (C) 2004 Vivien Malerba
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program 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 General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
#include "sel-graphs.h"
22
#include <libgnomedb/libgnomedb.h>
23
#include "graph/mg-graph.h"
27
* Module for all graphs managed by MgConf
30
static void module_graphs_fill_model (Module *module);
31
static void module_graphs_free (Module *module);
32
static const gchar *module_graphs_col_name (Module *module, guint colno);
33
static void module_graphs_model_store_data (Module *module, GtkTreeIter *iter);
34
static const gchar *module_graphs_render_graph_type (MgGraph *graph);
37
sel_module_graphs_new (MgSelector *mgsel, gboolean insert_header,
38
GtkTreeIter *iter, gpointer data)
42
module = g_new0 (Module, 1);
43
module->selector = mgsel;
44
module->fill_model = module_graphs_fill_model;
45
module->free = module_graphs_free;
46
module->col_name = module_graphs_col_name;
47
module->obj_manager = NULL;
48
module->model_store_data = module_graphs_model_store_data;
49
module->mod_data = NULL;
51
module->parent_module = NULL;
52
module->sub_modules = NULL;
55
GdkPixbuf *pixbuf = NULL;
56
GtkTreeModel *model = mgsel->priv->model;
58
pixbuf = gnome_db_stock_get_icon_pixbuf (GNOME_DB_STOCK_RELATIONS);
59
module->iter = g_new0 (GtkTreeIter, 1);
60
gtk_tree_store_append (GTK_TREE_STORE (model), module->iter, iter);
61
gtk_tree_store_set (GTK_TREE_STORE (model), module->iter, NAME_COLUMN,
62
_("Graphs"), PIXBUF_COLUMN, pixbuf,
63
CONTENTS_COLUMN, CONTENTS_TOP_CATEGORY,
64
SUB_MODULE_COLUMN, NULL, -1);
68
module->iter = gtk_tree_iter_copy (iter);
75
static GSList *module_graphs_get_objects_list (Module *module);
77
module_graphs_fill_model (Module *module)
80
GdkPixbuf *pixbuf_graph = NULL;
82
pixbuf_graph = gnome_db_stock_get_icon_pixbuf_file ("gnome-db-relations_16x16.png");
84
/* Module's private data */
85
module->mod_data = g_new0 (ModFlatData, 1);
86
FLAT_DATA (module)->manager = NULL;
87
FLAT_DATA (module)->manager_weak_refed = FALSE;
88
FLAT_DATA (module)->fallback_obj_pixbuf = pixbuf_graph;
89
FLAT_DATA (module)->get_objects_list = module_graphs_get_objects_list;
91
/* Initial model filling */
92
model = module->selector->priv->model;
93
flat_init_model_fill (module, model);
95
/* Signals handlers */
96
g_signal_connect (G_OBJECT (module->selector->priv->conf), "graph_added",
97
G_CALLBACK (flat_obj_added_cb), module);
98
g_signal_connect (G_OBJECT (module->selector->priv->conf), "graph_removed",
99
G_CALLBACK (flat_obj_removed_cb), module);
100
g_signal_connect (G_OBJECT (module->selector->priv->conf), "graph_updated",
101
G_CALLBACK (flat_obj_updated_cb), module);
105
module_graphs_get_objects_list (Module *module)
107
return mg_conf_get_graphs (module->selector->priv->conf);
111
module_graphs_free (Module *module)
113
GSList *list = module->sub_modules;
115
/* Free the sub modules */
117
(MODULE (list->data)->free) (MODULE (list->data));
119
list = g_slist_next (list);
121
if (module->sub_modules) {
122
g_slist_free (module->sub_modules);
123
module->sub_modules = NULL;
126
/* free this module */
127
g_signal_handlers_disconnect_by_func (G_OBJECT (module->selector->priv->conf),
128
G_CALLBACK (flat_obj_added_cb), module);
129
g_signal_handlers_disconnect_by_func (G_OBJECT (module->selector->priv->conf),
130
G_CALLBACK (flat_obj_removed_cb), module);
131
g_signal_handlers_disconnect_by_func (G_OBJECT (module->selector->priv->conf),
132
G_CALLBACK (flat_obj_updated_cb), module);
135
gtk_tree_iter_free (module->iter);
137
flat_free_mod_data (module);
138
g_free (module->mod_data);
139
module->mod_data = NULL;
144
module_graphs_col_name (Module *module, guint colno)
160
module_graphs_model_store_data (Module *module, GtkTreeIter *iter)
165
model = module->selector->priv->model;
166
gtk_tree_model_get (model, iter, OBJ_COLUMN, &obj, -1);
168
if (obj && IS_MG_GRAPH (obj)) {
170
gtk_tree_store_set (GTK_TREE_STORE (model), iter,
171
EXTRA1_COLUMN, module_graphs_render_graph_type (MG_GRAPH (obj)),
173
str1 = mg_base_get_name (MG_BASE (obj));
174
if (!str1 || !(*str1)) {
175
gtk_tree_store_set (GTK_TREE_STORE (model), iter,
176
NAME_COLUMN, _("Graph <no name>"),
183
module_graphs_render_graph_type (MgGraph *graph)
185
switch (mg_graph_get_graph_type (graph)) {
186
case MG_GRAPH_DB_RELATIONS:
187
return _("Database relations");
188
case MG_GRAPH_QUERY_JOINS:
189
return _("Query joins");
190
case MG_GRAPH_MODELLING:
193
g_assert_not_reached ();