File: sel-data-types.c

package info (click to toggle)
mergeant 0.52-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 12,872 kB
  • ctags: 6,584
  • sloc: ansic: 63,372; xml: 23,218; sh: 10,895; makefile: 612; sql: 237
file content (171 lines) | stat: -rw-r--r-- 5,322 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* sel-data-types.c
 *
 * Copyright (C) 2004 Vivien Malerba
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include "sel-data-types.h"
#include <libgnomedb/libgnomedb.h>
#include "mg-server.h"
#include "mg-server-data-type.h"

/*
 *
 * Module for data types
 *
 */


static void         module_data_types_fill_model (Module *module);
static void         module_data_types_free (Module *module);
static const gchar *module_data_types_col_name (Module *module, guint colno);
Module *
sel_module_data_types_new (MgSelector *mgsel, gboolean insert_header, GtkTreeIter *iter, gpointer data)
{
	Module *module;

	module = g_new0 (Module, 1);
	module->selector = mgsel;
	module->fill_model = module_data_types_fill_model;
	module->free = module_data_types_free;
	module->col_name = module_data_types_col_name;
	module->obj_manager = NULL;
	module->model_store_data = NULL;
	module->mod_data = NULL;
	module->iter = NULL;
	module->parent_module = NULL;
	module->sub_modules = NULL;

	if (insert_header) {
		GdkPixbuf *pixbuf = NULL;
		GtkTreeModel *model = mgsel->priv->model;

		pixbuf = gnome_db_stock_get_icon_pixbuf (GNOME_DB_STOCK_TYPES);

		module->iter = g_new0 (GtkTreeIter, 1);
		gtk_tree_store_append (GTK_TREE_STORE (model), module->iter, iter);
		gtk_tree_store_set (GTK_TREE_STORE (model), module->iter, NAME_COLUMN, 
				    _("Data Types"), PIXBUF_COLUMN, pixbuf, 
				    CONTENTS_COLUMN, CONTENTS_TOP_CATEGORY, 
				    SUB_MODULE_COLUMN, NULL, -1);		
	}
	else {
		if (iter)
			module->iter = gtk_tree_iter_copy (iter);
	}

	return module;
}

static GSList *module_data_types_get_objects_list (Module *module);
static gchar  *module_data_types_get_extended_name (GObject *obj);
static void
module_data_types_fill_model (Module *module)
{
	MgServer *srv;
	GtkTreeModel *model;
	GdkPixbuf *pixbuf_func = NULL;

	srv = mg_conf_get_server (module->selector->priv->conf);
	pixbuf_func = gnome_db_stock_get_icon_pixbuf_file ("gnome-db-types_16x16.png");

	/* Module's private data */
	module->mod_data = g_new0 (ModNameGroupData, 1);
	GROUP_DATA (module)->manager = G_OBJECT (srv);
	GROUP_DATA (module)->manager_weak_refed = FALSE;
	GROUP_DATA (module)->obj_pixbuf = pixbuf_func;
	GROUP_DATA (module)->get_objects_list = module_data_types_get_objects_list;
	GROUP_DATA (module)->get_extended_name = module_data_types_get_extended_name;
	
	/* Initial model filling */
	model = module->selector->priv->model;
	name_group_init_model_fill (module, model);

	/* Signals handlers */
	g_signal_connect (G_OBJECT (srv), "data_type_added",
			  G_CALLBACK (name_group_obj_added_cb), module);
	g_signal_connect (G_OBJECT (srv), "data_type_removed",
			  G_CALLBACK (name_group_obj_removed_cb), module);
	g_signal_connect (G_OBJECT (srv), "data_type_updated",
			  G_CALLBACK (name_group_obj_updated_cb), module);
	g_signal_connect (G_OBJECT (srv), "data_update_started",
			  G_CALLBACK (name_group_update_started_cb), module);
	g_signal_connect (G_OBJECT (srv), "data_update_finished",
			  G_CALLBACK (name_group_update_finished_cb), module);
}

static GSList *
module_data_types_get_objects_list (Module *module)
{
	g_return_val_if_fail (GROUP_DATA (module)->manager, NULL);
	g_return_val_if_fail (IS_MG_SERVER (GROUP_DATA (module)->manager), NULL);

	return mg_server_get_data_types (MG_SERVER (GROUP_DATA (module)->manager));
}

static gchar *
module_data_types_get_extended_name (GObject *obj)
{
	MgServerDataType *dt;

	g_return_val_if_fail (obj && IS_MG_SERVER_DATA_TYPE (obj), NULL);

	dt = MG_SERVER_DATA_TYPE (obj);

	return g_strdup (mg_server_data_type_get_sqlname (dt));
}

static void
module_data_types_free (Module *module)
{
	MgServer *srv;
	srv = mg_conf_get_server (module->selector->priv->conf);

	if (srv) {
		g_signal_handlers_disconnect_by_func (G_OBJECT (srv),
						      G_CALLBACK (name_group_obj_added_cb), module);
		g_signal_handlers_disconnect_by_func (G_OBJECT (srv),
						      G_CALLBACK (name_group_obj_removed_cb), module);
		g_signal_handlers_disconnect_by_func (G_OBJECT (srv),
						      G_CALLBACK (name_group_obj_updated_cb), module);
		g_signal_handlers_disconnect_by_func (G_OBJECT (srv),
						      G_CALLBACK (name_group_update_started_cb), module);
		g_signal_handlers_disconnect_by_func (G_OBJECT (srv),
						      G_CALLBACK (name_group_update_finished_cb), module);
	}
	if (module->iter)
		gtk_tree_iter_free (module->iter);
	name_group_free_mod_data (module);
	g_free (module->mod_data);
	module->mod_data = NULL;
}


static const gchar *
module_data_types_col_name (Module *module, guint colno)
{
	switch (colno) {
	case 0:
		return _("Data Type");
		break;
	default:
		return NULL;
		break;
	}
}