~ubuntu-branches/ubuntu/karmic/mergeant/karmic

« back to all changes in this revision

Viewing changes to libmergeant/sel-graphs.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo R. Montesino
  • Date: 2007-11-29 08:44:48 UTC
  • mfrom: (2.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20071129084448-6aon73d22bv6hzfw
Tags: 0.67-3
* Re-enable installation of the mime files in mergeant.install
* mergeant.dirs: create usr/share/mime/packages to make dh_installmime add
  the update-mime-database code snippets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* sel-graphs.c
2
 
 *
3
 
 * Copyright (C) 2004 Vivien Malerba
4
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 * USA
19
 
 */
20
 
 
21
 
#include "sel-graphs.h"
22
 
#include <libgnomedb/libgnomedb.h>
23
 
#include "graph/mg-graph.h"
24
 
 
25
 
/*
26
 
 *
27
 
 * Module for all graphs managed by MgConf
28
 
 *
29
 
 */
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);
35
 
 
36
 
Module *
37
 
sel_module_graphs_new (MgSelector *mgsel, gboolean insert_header, 
38
 
                       GtkTreeIter *iter, gpointer data)
39
 
{
40
 
        Module *module;
41
 
 
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;
50
 
        module->iter = NULL;
51
 
        module->parent_module = NULL;
52
 
        module->sub_modules = NULL;
53
 
 
54
 
        if (insert_header) {
55
 
                GdkPixbuf *pixbuf = NULL;
56
 
                GtkTreeModel *model = mgsel->priv->model;
57
 
 
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);               
65
 
        }
66
 
        else {
67
 
                if (iter)
68
 
                        module->iter = gtk_tree_iter_copy (iter);
69
 
        }
70
 
 
71
 
        return module;
72
 
}
73
 
 
74
 
 
75
 
static GSList *module_graphs_get_objects_list (Module *module);
76
 
static void
77
 
module_graphs_fill_model (Module *module)
78
 
{
79
 
        GtkTreeModel *model;
80
 
        GdkPixbuf *pixbuf_graph = NULL;
81
 
 
82
 
        pixbuf_graph = gnome_db_stock_get_icon_pixbuf_file ("gnome-db-relations_16x16.png");
83
 
 
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;
90
 
 
91
 
        /* Initial model filling */
92
 
        model = module->selector->priv->model;
93
 
        flat_init_model_fill (module, model);
94
 
 
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);
102
 
}
103
 
 
104
 
static GSList *
105
 
module_graphs_get_objects_list (Module *module)
106
 
{
107
 
        return mg_conf_get_graphs (module->selector->priv->conf);
108
 
}
109
 
 
110
 
static void
111
 
module_graphs_free (Module *module)
112
 
{
113
 
        GSList *list = module->sub_modules;
114
 
 
115
 
        /* Free the sub modules */
116
 
        while (list) {
117
 
                (MODULE (list->data)->free) (MODULE (list->data));
118
 
                g_free (list->data);
119
 
                list = g_slist_next (list);
120
 
        }
121
 
        if (module->sub_modules) {
122
 
                g_slist_free (module->sub_modules);
123
 
                module->sub_modules = NULL;
124
 
        }
125
 
 
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);
133
 
 
134
 
        if (module->iter)
135
 
                gtk_tree_iter_free (module->iter);
136
 
 
137
 
        flat_free_mod_data (module);
138
 
        g_free (module->mod_data);
139
 
        module->mod_data = NULL;
140
 
}
141
 
 
142
 
 
143
 
static const gchar *
144
 
module_graphs_col_name (Module *module, guint colno)
145
 
{
146
 
        switch (colno) {
147
 
        case 0:
148
 
                return _("Graph");
149
 
                break;
150
 
        case EXTRA1_COLUMN:
151
 
                return _("Type");
152
 
                break;
153
 
        default:
154
 
                return NULL;
155
 
                break;
156
 
        }
157
 
}
158
 
 
159
 
static void
160
 
module_graphs_model_store_data (Module *module, GtkTreeIter *iter)
161
 
{
162
 
        GObject *obj;
163
 
        GtkTreeModel *model;
164
 
 
165
 
        model = module->selector->priv->model;
166
 
        gtk_tree_model_get (model, iter, OBJ_COLUMN, &obj, -1);
167
 
 
168
 
        if (obj && IS_MG_GRAPH (obj)) {
169
 
                const gchar *str1;
170
 
                gtk_tree_store_set (GTK_TREE_STORE (model), iter, 
171
 
                                    EXTRA1_COLUMN, module_graphs_render_graph_type (MG_GRAPH (obj)),
172
 
                                    -1);
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>"),
177
 
                                    -1);
178
 
                }
179
 
        }
180
 
}
181
 
 
182
 
static const gchar *
183
 
module_graphs_render_graph_type (MgGraph *graph)
184
 
{
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:
191
 
                return _("Model");
192
 
        default:
193
 
                g_assert_not_reached ();
194
 
        }
195
 
 
196
 
        return NULL;
197
 
}
198