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

« back to all changes in this revision

Viewing changes to src/ws-queries.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
/* ws-queries.c
 
2
 *
 
3
 * Copyright (C) 2004 - 2007 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 <glib/gi18n-lib.h>
 
22
#include <libgnomedb-extra/libgnomedb-extra.h>
 
23
#include "ws-queries.h"
 
24
#include "workspace-page.h"
 
25
#include <string.h>
 
26
#include <glib-object.h>
 
27
#include <gtk/gtk.h>
 
28
#include "query-druid.h"
 
29
#include "query-editor.h"
 
30
#include "query-params-editor.h"
 
31
 
 
32
/* 
 
33
 * Main static functions 
 
34
 */
 
35
static void ws_queries_class_init (WsQueriesClass * class);
 
36
static void ws_queries_init (WsQueries *ws);
 
37
static void ws_queries_dispose (GObject *object);
 
38
static void ws_queries_finalize (GObject *object);
 
39
 
 
40
/* WorkspacePage interface */
 
41
static void            ws_queries_page_init       (WorkspacePageIface *iface);
 
42
static gchar          *ws_queries_get_name        (WorkspacePage *iface);
 
43
static gchar          *ws_queries_get_description (WorkspacePage *iface);
 
44
static GtkWidget      *ws_queries_get_sel_button  (WorkspacePage *iface);
 
45
static GtkWidget      *ws_queries_get_selector    (WorkspacePage *iface);
 
46
static GtkWidget      *ws_queries_get_work_area   (WorkspacePage *iface);
 
47
static GtkActionGroup *ws_queries_get_actions     (WorkspacePage *iface);
 
48
static const gchar    *ws_queries_get_actions_ui  (WorkspacePage *iface);
 
49
 
 
50
static void            opened_dialog_closed_cb    (GtkWidget *dlg, WsQueries *ws);
 
51
 
 
52
/* get a pointer to the parents to be able to call their destructor */
 
53
static GObjectClass  *parent_class = NULL;
 
54
 
 
55
/* private structure */
 
56
struct _WsQueriesPrivate
 
57
{
 
58
        GdaDict        *dict;
 
59
        GtkWidget      *selector;
 
60
        GtkWidget      *work_area;
 
61
        GtkActionGroup *actions;
 
62
 
 
63
        GtkWidget      *notebook;
 
64
        GtkWidget      *description;
 
65
        GtkWidget      *sql_editor;
 
66
        GtkWidget      *params_editor;
 
67
 
 
68
        GObject        *sel_obj;
 
69
        GSList         *opened_dialogs;
 
70
};
 
71
 
 
72
GType
 
73
ws_queries_get_type (void)
 
74
{
 
75
        static GType type = 0;
 
76
 
 
77
        if (!type) {
 
78
                static const GTypeInfo info = {
 
79
                        sizeof (WsQueriesClass),
 
80
                        (GBaseInitFunc) NULL,
 
81
                        (GBaseFinalizeFunc) NULL,
 
82
                        (GClassInitFunc) ws_queries_class_init,
 
83
                        NULL,
 
84
                        NULL,
 
85
                        sizeof (WsQueries),
 
86
                        0,
 
87
                        (GInstanceInitFunc) ws_queries_init
 
88
                };
 
89
 
 
90
                static const GInterfaceInfo workspace_page_info = {
 
91
                        (GInterfaceInitFunc) ws_queries_page_init,
 
92
                        NULL,
 
93
                        NULL
 
94
                };
 
95
 
 
96
                type = g_type_register_static (G_TYPE_OBJECT, "WsQueries", &info, 0);
 
97
                g_type_add_interface_static (type, WORKSPACE_PAGE_TYPE, &workspace_page_info);
 
98
        }
 
99
        return type;
 
100
}
 
101
 
 
102
static void 
 
103
ws_queries_page_init (WorkspacePageIface *iface)
 
104
{
 
105
        iface->get_name = ws_queries_get_name;
 
106
        iface->get_description = ws_queries_get_description;
 
107
        iface->get_sel_button = ws_queries_get_sel_button;
 
108
        iface->get_selector = ws_queries_get_selector;
 
109
        iface->get_work_area = ws_queries_get_work_area;
 
110
        iface->get_actions = ws_queries_get_actions;
 
111
        iface->get_actions_ui = ws_queries_get_actions_ui;
 
112
}
 
113
 
 
114
static void
 
115
ws_queries_class_init (WsQueriesClass * class)
 
116
{
 
117
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
 
118
 
 
119
        parent_class = g_type_class_peek_parent (class);
 
120
 
 
121
        object_class->dispose = ws_queries_dispose;
 
122
        object_class->finalize = ws_queries_finalize;
 
123
}
 
124
 
 
125
static void
 
126
ws_queries_init (WsQueries *ws)
 
127
{
 
128
        ws->priv = g_new0 (WsQueriesPrivate, 1);
 
129
}
 
130
 
 
131
static void ws_queries_initialize (WsQueries *ws);
 
132
 
 
133
/**
 
134
 * ws_queries_new
 
135
 * @dict: a #GdaDict object
 
136
 *
 
137
 * Creates a new WsQueries object
 
138
 *
 
139
 * Returns: the new object
 
140
 */
 
141
GObject*
 
142
ws_queries_new (GdaDict *dict)
 
143
{
 
144
        GObject  *obj;
 
145
        WsQueries *ws;
 
146
 
 
147
        g_return_val_if_fail (GDA_IS_DICT (dict), NULL);
 
148
 
 
149
        obj = g_object_new (WS_QUERIES_TYPE, NULL);
 
150
        ws = WS_QUERIES (obj);
 
151
        ws->priv->dict = dict;
 
152
        g_object_ref (G_OBJECT (dict));
 
153
 
 
154
        ws_queries_initialize (ws);
 
155
 
 
156
        return obj;
 
157
}
 
158
 
 
159
 
 
160
static void query_updated_cb (GdaDict *dict, GdaQuery *query, WsQueries *ws);
 
161
static void
 
162
ws_queries_dispose (GObject *object)
 
163
{
 
164
        WsQueries *ws;
 
165
 
 
166
        g_return_if_fail (object != NULL);
 
167
        g_return_if_fail (IS_WS_QUERIES (object));
 
168
 
 
169
        ws = WS_QUERIES (object);
 
170
        if (ws->priv) {
 
171
                while (ws->priv->opened_dialogs) 
 
172
                        gtk_widget_destroy (GTK_WIDGET (ws->priv->opened_dialogs->data));
 
173
                
 
174
                if (ws->priv->selector) {
 
175
                        gtk_widget_destroy (ws->priv->selector);
 
176
                        ws->priv->selector = NULL;
 
177
                }
 
178
 
 
179
                if (ws->priv->work_area) {
 
180
                        gtk_widget_destroy (ws->priv->work_area);
 
181
                        ws->priv->work_area = NULL;
 
182
                }
 
183
 
 
184
                if (ws->priv->actions) {
 
185
                        g_object_unref (ws->priv->actions);
 
186
                        ws->priv->actions = NULL;
 
187
                }
 
188
 
 
189
                if (ws->priv->dict) {
 
190
                        g_signal_handlers_disconnect_by_func (G_OBJECT (ws->priv->dict),
 
191
                                                              G_CALLBACK (query_updated_cb), ws);
 
192
 
 
193
                        g_object_unref (G_OBJECT (ws->priv->dict));
 
194
                        ws->priv->dict = NULL;
 
195
                }
 
196
        }
 
197
 
 
198
        /* parent class */
 
199
        parent_class->dispose (object);
 
200
}
 
201
 
 
202
static void
 
203
ws_queries_finalize (GObject   * object)
 
204
{
 
205
        WsQueries *ws;
 
206
 
 
207
        g_return_if_fail (object != NULL);
 
208
        g_return_if_fail (IS_WS_QUERIES (object));
 
209
 
 
210
        ws = WS_QUERIES (object);
 
211
        if (ws->priv) {
 
212
                g_free (ws->priv);
 
213
                ws->priv = NULL;
 
214
        }
 
215
 
 
216
        /* parent class */
 
217
        parent_class->finalize (object);
 
218
}
 
219
 
 
220
 
 
221
 
 
222
static void selector_selection_changed_cb (GnomeDbSelector *mgsel, GObject *sel_object, WsQueries *ws);
 
223
static void action_query_add_cb (GtkAction *action, WsQueries *ws);
 
224
static void action_query_edit_cb (GtkAction *action, WsQueries *ws);
 
225
static void action_query_del_cb (GtkAction *action, WsQueries *ws);
 
226
static void action_query_exec_cb (GtkAction *action, WsQueries *ws);
 
227
 
 
228
static GtkActionEntry ui_actions[] = {
 
229
        { "Query", NULL, "_Query", NULL, "Query", NULL },
 
230
        { "QueryAdd", GTK_STOCK_ADD, "_New query", NULL, "Create a new query", 
 
231
          G_CALLBACK (action_query_add_cb)},
 
232
        { "QueryDel", GTK_STOCK_DELETE, "_Delete", NULL, "Delete the selected query", 
 
233
          G_CALLBACK (action_query_del_cb)},
 
234
        { "QueryEdit", GTK_STOCK_EDIT, "_Modify", NULL, "Modify the selected query", 
 
235
          G_CALLBACK (action_query_edit_cb)},
 
236
        { "QueryExec", GTK_STOCK_EXECUTE, "_Execute", NULL, "Execute the selected query", 
 
237
          G_CALLBACK (action_query_exec_cb)},
 
238
};
 
239
 
 
240
static const gchar *ui_actions_info =
 
241
        "<ui>"
 
242
        "  <menubar name='MenuBar'>"
 
243
        "    <placeholder name='PageExtension'>"
 
244
        "      <menu name='Query' action='Query'>"
 
245
        "        <menuitem name='QueryAdd' action= 'QueryAdd'/>"
 
246
        "        <menuitem name='QueryDel' action= 'QueryDel'/>"
 
247
        "        <separator/>"
 
248
        "        <menuitem name='QueryEdit' action= 'QueryEdit'/>"
 
249
        "        <menuitem name='QueryExec' action= 'QueryExec'/>"
 
250
        "      </menu>"
 
251
        "    </placeholder>"
 
252
        "  </menubar>"
 
253
        "  <toolbar  name='ToolBar'>"
 
254
        "    <toolitem action='QueryAdd'/>"
 
255
        "    <toolitem action='QueryDel'/>"
 
256
        "    <separator/>"
 
257
        "    <toolitem action='QueryEdit'/>"
 
258
        "    <toolitem action='QueryExec'/>"
 
259
        "  </toolbar>"
 
260
        "</ui>";
 
261
 
 
262
 
 
263
static void
 
264
ws_queries_initialize (WsQueries *ws)
 
265
{
 
266
        GtkWidget *label, *vbox, *nb, *vbox2, *wid, *hbox, *vbox3, *vp;
 
267
        GtkWidget *vbox4;
 
268
        gchar *str;
 
269
 
 
270
        /* Selector part */
 
271
        wid = gnome_db_selector_new (ws->priv->dict, NULL,
 
272
                               GNOME_DB_SELECTOR_QUERIES, GNOME_DB_SELECTOR_COLUMN_TYPE);
 
273
        ws->priv->selector = wid;
 
274
        g_signal_connect (G_OBJECT (ws->priv->selector), "selection_changed", 
 
275
                          G_CALLBACK (selector_selection_changed_cb), ws);
 
276
 
 
277
        /* WorkArea part */
 
278
        vbox = gtk_vbox_new (FALSE, 5);
 
279
        ws->priv->work_area = vbox;
 
280
 
 
281
        nb = gtk_notebook_new ();
 
282
        gtk_notebook_set_show_border (GTK_NOTEBOOK (nb), FALSE);
 
283
        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
 
284
        gtk_box_pack_start (GTK_BOX (vbox), nb, TRUE, TRUE, 0);
 
285
        gtk_widget_show (nb);
 
286
        ws->priv->notebook = nb;
 
287
        
 
288
        label = gtk_label_new (_("Please select a query from the list on the left,\n"
 
289
                                 "or create a new one using the 'Add' button below."));
 
290
        gtk_notebook_append_page (GTK_NOTEBOOK (nb), label, NULL);
 
291
        gtk_widget_show (label);
 
292
 
 
293
        vp = gtk_vpaned_new ();
 
294
        gtk_notebook_append_page (GTK_NOTEBOOK (nb), vp, NULL);
 
295
        gtk_widget_show (vp);
 
296
        gtk_paned_set_position (GTK_PANED (vp), 370);
 
297
        
 
298
        vbox2 = gtk_vbox_new (FALSE, 5);
 
299
        gtk_paned_add1 (GTK_PANED (vp), vbox2);
 
300
        gtk_widget_show (vbox2);
 
301
 
 
302
        label = gtk_label_new (NULL);
 
303
        str = g_strdup_printf ("<b>%s:</b>", _("Description"));
 
304
        gtk_label_set_markup (GTK_LABEL (label), str);
 
305
        g_free (str);
 
306
        gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
 
307
        gtk_widget_show (label);
 
308
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
309
 
 
310
        hbox = gtk_hbox_new (FALSE, 0); /* HIG */
 
311
        gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
 
312
        gtk_widget_show (hbox);
 
313
        label = gtk_label_new ("    ");
 
314
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
315
        gtk_widget_show (label);
 
316
 
 
317
        label = gtk_label_new (NULL);
 
318
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
319
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
320
        gtk_widget_show (label);
 
321
        ws->priv->description = label;
 
322
 
 
323
 
 
324
        vbox4 = gtk_vbox_new (FALSE, 0);
 
325
        gtk_box_pack_start (GTK_BOX (vbox2), vbox4, TRUE, TRUE, 0);
 
326
        gtk_widget_show (vbox4);
 
327
 
 
328
        label = gtk_label_new (NULL);
 
329
        str = g_strdup_printf ("<b>%s:</b>", _("SQL statement"));
 
330
        gtk_label_set_markup (GTK_LABEL (label), str);
 
331
        g_free (str);
 
332
        gtk_box_pack_start (GTK_BOX (vbox4), label, FALSE, FALSE, 0);
 
333
        gtk_widget_show (label);
 
334
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
335
 
 
336
        hbox = gtk_hbox_new (FALSE, 0); /* HIG */
 
337
        gtk_box_pack_start (GTK_BOX (vbox4), hbox, TRUE, TRUE, 0);
 
338
        gtk_widget_show (hbox);
 
339
        label = gtk_label_new ("    ");
 
340
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
341
        gtk_widget_show (label);
 
342
 
 
343
        vbox3 = gtk_vbox_new (FALSE, 0);
 
344
        gtk_box_pack_start (GTK_BOX (hbox), vbox3, TRUE, TRUE, 0);
 
345
        gtk_widget_show (vbox3);
 
346
 
 
347
        label = gtk_label_new (NULL);
 
348
        str = g_strdup_printf ("<small>%s</small>", _("For information only, to edit, click on the \"Edit\" button."));
 
349
        gtk_label_set_markup (GTK_LABEL (label), str);
 
350
        g_free (str);
 
351
        gtk_box_pack_start (GTK_BOX (vbox3), label, FALSE, FALSE, 0);
 
352
        gtk_widget_show (label);
 
353
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
354
 
 
355
        wid = gnome_db_editor_new ();
 
356
        gnome_db_editor_set_editable (GNOME_DB_EDITOR (wid), FALSE);
 
357
        gnome_db_editor_set_highlight (GNOME_DB_EDITOR (wid), TRUE);
 
358
        gtk_box_pack_start (GTK_BOX (vbox3), wid, TRUE, TRUE, 0);
 
359
        gtk_widget_show (wid);
 
360
        ws->priv->sql_editor = wid;
 
361
 
 
362
 
 
363
        vbox2 = gtk_vbox_new (FALSE, 5);
 
364
        gtk_paned_add2 (GTK_PANED (vp), vbox2);
 
365
        gtk_widget_show (vbox2);
 
366
        
 
367
        label = gtk_label_new (NULL);
 
368
        str = g_strdup_printf ("<b>%s:</b>", _("Query parameters"));
 
369
        gtk_label_set_markup (GTK_LABEL (label), str);
 
370
        g_free (str);
 
371
        gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
 
372
        gtk_widget_show (label);
 
373
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
374
 
 
375
        hbox = gtk_hbox_new (FALSE, 0); /* HIG */
 
376
        gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0);
 
377
        gtk_widget_show (hbox);
 
378
        label = gtk_label_new ("    ");
 
379
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
380
        gtk_widget_show (label);
 
381
 
 
382
        vbox3 = gtk_vbox_new (FALSE, 0);
 
383
        gtk_box_pack_start (GTK_BOX (hbox), vbox3, TRUE, TRUE, 0);
 
384
        gtk_widget_show (vbox3);
 
385
 
 
386
        label = gtk_label_new (NULL);
 
387
        str = g_strdup_printf ("<small>%s</small>", _("For information only, to edit, click on the \"Edit\" button."));
 
388
        gtk_label_set_markup (GTK_LABEL (label), str);
 
389
        g_free (str);
 
390
        gtk_box_pack_start (GTK_BOX (vbox3), label, FALSE, FALSE, 0);
 
391
        gtk_widget_show (label);
 
392
        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
 
393
 
 
394
        wid = query_params_editor_new (NULL, 0);
 
395
        gtk_box_pack_start (GTK_BOX (vbox3), wid, TRUE, TRUE, 0);
 
396
        gtk_widget_show (wid);
 
397
        ws->priv->params_editor = wid;
 
398
 
 
399
        /* actions part */
 
400
        ws->priv->actions = gtk_action_group_new ("Actions");
 
401
        gtk_action_group_add_actions (ws->priv->actions, ui_actions, G_N_ELEMENTS (ui_actions), ws);
 
402
 
 
403
        if (ws->priv->actions) {
 
404
                GtkAction *action;
 
405
 
 
406
                action = gtk_action_group_get_action (ws->priv->actions, "QueryDel");
 
407
                gtk_action_set_sensitive (action, FALSE);
 
408
                action = gtk_action_group_get_action (ws->priv->actions, "QueryEdit");
 
409
                gtk_action_set_sensitive (action, FALSE);
 
410
                action = gtk_action_group_get_action (ws->priv->actions, "QueryExec");
 
411
                gtk_action_set_sensitive (action, FALSE);
 
412
        }
 
413
        
 
414
        g_signal_connect (G_OBJECT (ws->priv->dict), "object_updated",
 
415
                          G_CALLBACK (query_updated_cb), ws);
 
416
}
 
417
 
 
418
static void query_info_display_update (GdaQuery *query, WsQueries *ws);
 
419
static void
 
420
selector_selection_changed_cb (GnomeDbSelector *mgsel, GObject *sel_object, WsQueries *ws)
 
421
{
 
422
        GtkAction *action;
 
423
 
 
424
        if (sel_object && !GDA_IS_QUERY (sel_object))
 
425
                return;
 
426
        
 
427
        ws->priv->sel_obj = sel_object;
 
428
        gtk_notebook_set_current_page (GTK_NOTEBOOK (ws->priv->notebook), sel_object ? 1 : 0);
 
429
 
 
430
        action = gtk_action_group_get_action (ws->priv->actions, "QueryDel");
 
431
        gtk_action_set_sensitive (action, sel_object ? TRUE : FALSE);
 
432
        action = gtk_action_group_get_action (ws->priv->actions, "QueryEdit");
 
433
        gtk_action_set_sensitive (action, sel_object ? TRUE : FALSE);
 
434
        action = gtk_action_group_get_action (ws->priv->actions, "QueryExec");
 
435
        gtk_action_set_sensitive (action, sel_object ? TRUE : FALSE);
 
436
 
 
437
        query_info_display_update ((GdaQuery*) sel_object, ws);
 
438
}
 
439
 
 
440
static void
 
441
query_updated_cb (GdaDict *dict, GdaQuery *query, WsQueries *ws)
 
442
{
 
443
        if (GDA_IS_QUERY (query) && ((GObject *)query == ws->priv->sel_obj))
 
444
                query_info_display_update (query, ws);
 
445
}
 
446
 
 
447
static void
 
448
dialog_exec_response_cb (GtkDialog *dlg, gint response, GObject *obj)
 
449
{
 
450
        gtk_widget_destroy (GTK_WIDGET (dlg));
 
451
}
 
452
 
 
453
static void
 
454
action_query_add_cb (GtkAction *action, WsQueries *ws)
 
455
{
 
456
        GtkWidget *druid;
 
457
 
 
458
        druid = query_druid_new (ws->priv->dict);
 
459
        gtk_widget_show (druid);
 
460
 
 
461
        ws->priv->opened_dialogs = g_slist_append (ws->priv->opened_dialogs, druid);
 
462
        g_signal_connect (G_OBJECT (druid), "destroy",
 
463
                          G_CALLBACK (opened_dialog_closed_cb), ws);
 
464
}
 
465
 
 
466
static void
 
467
action_query_edit_cb (GtkAction *action, WsQueries *ws)
 
468
{
 
469
        GtkWidget *dlg, *editor;
 
470
        GObject *sel_query = ws->priv->sel_obj;
 
471
        gchar *title;
 
472
 
 
473
        if (!sel_query)
 
474
                return;
 
475
 
 
476
        editor = query_editor_new (GDA_QUERY (sel_query));
 
477
        gtk_widget_show (editor);
 
478
        title = g_strdup_printf (_("Edition of query '%s'"), gda_object_get_name (GDA_OBJECT (sel_query)));
 
479
        dlg = gtk_dialog_new_with_buttons (title, NULL, 0, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
 
480
        g_free (title);
 
481
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), editor, TRUE, TRUE, 6);
 
482
        gtk_widget_set_size_request (dlg, 770, 570);
 
483
        gtk_widget_show (dlg);
 
484
        g_signal_connect (G_OBJECT (dlg), "response",
 
485
                          G_CALLBACK (dialog_exec_response_cb), NULL);
 
486
 
 
487
        ws->priv->opened_dialogs = g_slist_append (ws->priv->opened_dialogs, dlg);
 
488
        g_signal_connect (G_OBJECT (dlg), "destroy",
 
489
                          G_CALLBACK (opened_dialog_closed_cb), ws);
 
490
}
 
491
 
 
492
static void
 
493
action_query_del_cb (GtkAction *action, WsQueries *ws)
 
494
{
 
495
        GObject *sel_query = ws->priv->sel_obj;
 
496
        GtkWidget *dlg;
 
497
 
 
498
        if (!sel_query)
 
499
                return;
 
500
 
 
501
        dlg = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
 
502
                                      _("Do you want to delete the '%s' query?"), 
 
503
                                      gda_object_get_name (GDA_OBJECT (sel_query)));
 
504
        if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_YES) 
 
505
                gda_object_destroy (GDA_OBJECT (sel_query));
 
506
 
 
507
        gtk_widget_destroy (dlg);
 
508
}
 
509
 
 
510
/* extra action for the grid widgets */
 
511
static void extra_action_close_cb (GtkAction *action, GtkWidget *window);
 
512
static GtkActionEntry extra_actions[] = {
 
513
        { "Close", GTK_STOCK_CLOSE, "_Close", NULL, "Close this window", G_CALLBACK (extra_action_close_cb)}
 
514
};
 
515
static const gchar *grid_actions =
 
516
        "<ui>"
 
517
        "  <toolbar  name='ToolBar'>"
 
518
        "    <toolitem action='Close'/>"
 
519
        "  </toolbar>"
 
520
        "</ui>";
 
521
 
 
522
 
 
523
static gint
 
524
fill_context_in_dialog (WsQueries *ws, GdaParameterList *context)
 
525
{
 
526
        GtkWidget *dlg;
 
527
        GnomeDbBasicForm *sform;
 
528
        GtkWidget *parent_window;
 
529
        gint result;
 
530
 
 
531
        if (!context || gda_parameter_list_is_valid (context))
 
532
                return GTK_RESPONSE_ACCEPT;
 
533
        
 
534
        parent_window = gtk_widget_get_toplevel (ws->priv->work_area);
 
535
        if (! GTK_WIDGET_TOPLEVEL (parent_window))
 
536
                parent_window = NULL;
 
537
 
 
538
        dlg = gnome_db_basic_form_new_in_dialog (context, GTK_WINDOW (parent_window),
 
539
                                                 _("Values to be filled"), 
 
540
                                                 _("<big><b>Required values:</b></big>\n"
 
541
                                                   "<small>The following values are required to "
 
542
                                                   "execute the query.</small>"));
 
543
        sform = g_object_get_data (G_OBJECT (dlg), "form");
 
544
        gnome_db_basic_form_set_entries_auto_default (sform, TRUE);
 
545
        
 
546
        gtk_widget_show (dlg);
 
547
        result = gtk_dialog_run (GTK_DIALOG (dlg));
 
548
        gtk_widget_destroy (dlg);
 
549
 
 
550
        return result;
 
551
}
 
552
 
 
553
typedef struct {
 
554
        GdaQuery       *query; /* copied, to free */
 
555
        GtkWidget      *grid_box;
 
556
        GtkWidget      *grid;
 
557
        GtkWidget      *combo; /* to free to unref the GdaQueryTarget objects referenced in the GdaDataModel */
 
558
        GdaQueryTarget *modif_target;
 
559
} QueryExecInstance;
 
560
 
 
561
static void
 
562
query_exec_instance_free (QueryExecInstance *qei)
 
563
{
 
564
        /* REM: we need to destroy qei->combo first because it uses a GdaDataModel which
 
565
         * has GValue of type G_TYPE_OBJECT which increment the refence count of
 
566
         * the GdaQueryTarget it references, and which will be actually destroyed by the 
 
567
         * destruction of the query */
 
568
        if (qei->combo) 
 
569
                gtk_widget_destroy (qei->combo);
 
570
        if (qei->query)
 
571
                g_object_unref (G_OBJECT (qei->query));
 
572
 
 
573
        g_free (qei);
 
574
}
 
575
 
 
576
/**
 
577
 * utility_query_execute_modif
 
578
 * @query: the #GdaQuery to be executed
 
579
 * @context: a #GdaParameterList object
 
580
 * @ask_confirm_insert:
 
581
 * @ask_confirm_update:
 
582
 * @ask_confirm_delete:
 
583
 * @parent_window: a #GtkWindow object, or a #GtkWidget and the parent window will be found automatically
 
584
 * @user_cancelled: a place to store if the user cancelled the query if the choice was given, or %NULL
 
585
 * @query_error: a place to store if there was an error, or %NULL
 
586
 *
 
587
 * Executes @query and displays question and information dialogs if necessary.
 
588
 * If a user confirmation was required and the user cancelled the execution, then 
 
589
 * the returned value is FALSE.
 
590
 *
 
591
 * Returns: TRUE if the query was executed.
 
592
 */
 
593
static gboolean
 
594
utility_query_execute_modif (GdaQuery *query, GdaParameterList *context,
 
595
                             gboolean ask_confirm_insert,
 
596
                             gboolean ask_confirm_update,
 
597
                             gboolean ask_confirm_delete,
 
598
                             GtkWidget *parent_window,
 
599
                             gboolean *user_cancelled,
 
600
                             gboolean *query_error)
 
601
{
 
602
        gchar *sql = NULL;
 
603
        GdaQueryType qtype;
 
604
        gchar *confirm = NULL;
 
605
        gboolean do_execute = TRUE;
 
606
        gboolean allok = TRUE;
 
607
        GError *error = NULL;
 
608
 
 
609
        g_return_val_if_fail (query && GDA_IS_QUERY (query), FALSE);
 
610
        
 
611
        /* find the GtkWindow object for @parent_window */
 
612
        while (parent_window && !GTK_IS_WINDOW (parent_window)) 
 
613
                parent_window = gtk_widget_get_parent (parent_window);
 
614
 
 
615
        sql = gda_renderer_render_as_sql (GDA_RENDERER (query), context, NULL, 0, &error);
 
616
        qtype = gda_query_get_query_type (query);
 
617
 
 
618
        switch (qtype) {
 
619
        case GDA_QUERY_TYPE_INSERT:
 
620
                if (ask_confirm_insert)
 
621
                        confirm = _("Execute the following insertion query?");
 
622
                break;
 
623
        case GDA_QUERY_TYPE_UPDATE:
 
624
                if (ask_confirm_update)
 
625
                        confirm = _("Execute the following update query?");
 
626
                break;
 
627
        case GDA_QUERY_TYPE_DELETE:
 
628
                if (ask_confirm_delete)
 
629
                        confirm = _("Execute the following deletion query?");
 
630
                break;
 
631
        default:
 
632
                g_assert_not_reached ();
 
633
        }
 
634
 
 
635
        if (user_cancelled)
 
636
                *user_cancelled = FALSE;
 
637
        if (query_error)
 
638
                *query_error = FALSE;
 
639
 
 
640
        if (sql) {
 
641
                if (confirm) {
 
642
                        GtkWidget *dlg;
 
643
                        gint result;
 
644
                        gchar *msg;
 
645
                        
 
646
                        msg = g_strdup_printf (_("<b><big>%s</big></b>\n"
 
647
                                                 "<small>The preferences require a confirmation for the "
 
648
                                                 "following query</small>\n\n%s"), confirm, sql);
 
649
                        dlg = gtk_message_dialog_new (GTK_WINDOW (parent_window), 0,
 
650
                                                      GTK_MESSAGE_QUESTION,
 
651
                                                      GTK_BUTTONS_YES_NO, msg);
 
652
                        g_free (msg);
 
653
                        gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (dlg)->label), TRUE);
 
654
                        result = gtk_dialog_run (GTK_DIALOG (dlg));
 
655
                        gtk_widget_destroy (dlg);
 
656
                        do_execute = (result == GTK_RESPONSE_YES);
 
657
                        if (user_cancelled)
 
658
                                *user_cancelled = !do_execute;
 
659
                }
 
660
                        
 
661
                if (do_execute) {
 
662
                        GdaDict *dict = gda_object_get_dict (GDA_OBJECT (query));
 
663
                        GdaCommand *cmd;
 
664
                        gint res;
 
665
#ifdef debug
 
666
                        g_print ("MODIF SQL: %s\n", sql);
 
667
#endif
 
668
                        cmd = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, 0);
 
669
                        res = gda_connection_execute_non_select_command (gda_dict_get_connection (dict), cmd, 
 
670
                                                                         NULL, &error);
 
671
                        gda_command_free (cmd);
 
672
                        if (res == -1) {
 
673
                                GtkWidget *dlg;
 
674
                                
 
675
                                dlg = gtk_message_dialog_new (GTK_WINDOW (parent_window), 0,
 
676
                                                              GTK_MESSAGE_ERROR,
 
677
                                                              GTK_BUTTONS_CLOSE,
 
678
                                                              error->message);
 
679
                                gtk_dialog_run (GTK_DIALOG (dlg));
 
680
                                gtk_widget_destroy (dlg);
 
681
                                allok = FALSE;
 
682
 
 
683
                                if (query_error)
 
684
                                        *query_error = TRUE;
 
685
                        }
 
686
                        if (error)
 
687
                                g_error_free (error);
 
688
                }
 
689
                else
 
690
                        allok = FALSE;
 
691
                
 
692
                g_free (sql);
 
693
        }
 
694
        else {
 
695
                GtkWidget *dlg;
 
696
                gchar *message;
 
697
                
 
698
                if (error) {
 
699
                        message = g_strdup_printf (_("The following error occurred while preparing the query:\n%s"),
 
700
                                                   error->message);
 
701
                        g_error_free (error);
 
702
                }
 
703
                else
 
704
                        message = g_strdup_printf (_("An unknown error occurred while preparing the query."));
 
705
                
 
706
                dlg = gtk_message_dialog_new (GTK_WINDOW (parent_window), 0,
 
707
                                              GTK_MESSAGE_ERROR,
 
708
                                              GTK_BUTTONS_CLOSE,
 
709
                                              message);
 
710
                g_free (message);
 
711
                gtk_dialog_run (GTK_DIALOG (dlg));
 
712
                gtk_widget_destroy (dlg);
 
713
                allok = FALSE;
 
714
 
 
715
                if (query_error)
 
716
                        *query_error = TRUE;
 
717
        }
 
718
 
 
719
        return allok;
 
720
}
 
721
 
 
722
static void query_exec_window_destroy_cb (GtkWindow *window, QueryExecInstance *qei);
 
723
static void
 
724
action_query_exec_cb (GtkAction *action, WsQueries *ws)
 
725
{
 
726
        GdaQuery *query;
 
727
        GdaParameterList *context;
 
728
        GtkWidget *parent_window;
 
729
        QueryExecInstance *qei;
 
730
        
 
731
        parent_window = gtk_widget_get_toplevel (ws->priv->work_area);
 
732
        if (! GTK_WIDGET_TOPLEVEL (parent_window))
 
733
                parent_window = NULL;
 
734
                
 
735
        query = (GdaQuery *) ws->priv->sel_obj;
 
736
 
 
737
        /* make a copy of @query so we are not impacted by any future modification of @query */
 
738
        qei = g_new0 (QueryExecInstance, 1);
 
739
        qei->query = gda_query_new_copy (query, NULL);
 
740
        query = qei->query;
 
741
 
 
742
        if (gda_query_is_modify_query (query)) {
 
743
                /* modification query */
 
744
                context = gda_query_get_parameter_list (query);
 
745
                if (fill_context_in_dialog (ws, context) == GTK_RESPONSE_ACCEPT) 
 
746
                        utility_query_execute_modif (query, context, TRUE, TRUE, TRUE, parent_window, NULL, NULL);
 
747
                g_object_unref (G_OBJECT (context));
 
748
                query_exec_instance_free (qei);
 
749
        }
 
750
        else {
 
751
                /* SELECT query */
 
752
                if (gda_query_is_select_query (query)) {
 
753
                        /* parsed SELECT query */
 
754
                        GtkWidget *grid;
 
755
                        GdaDataModel *model;
 
756
                        GError *error = NULL;
 
757
 
 
758
                        model = gda_data_model_query_new (query);
 
759
                        if (!gda_data_model_query_refresh (GDA_DATA_MODEL_QUERY (model), &error)) {
 
760
                                GtkWidget *dlg;
 
761
                                gchar *msg, *errmsg;
 
762
 
 
763
                                if (error && error->message)
 
764
                                        errmsg = g_markup_escape_text (error->message, -1);
 
765
                                else
 
766
                                        errmsg = _("No detail");
 
767
                                msg = g_strdup_printf ("<b>%s</b>\n%s", 
 
768
                                                       _("Can't execute query:"), errmsg);
 
769
                                if (error && error->message)
 
770
                                        g_free (errmsg);
 
771
                                
 
772
                                dlg = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent_window), 0,
 
773
                                                                          GTK_MESSAGE_ERROR,
 
774
                                                                          GTK_BUTTONS_CLOSE,
 
775
                                                                          msg);
 
776
                                g_free (msg);
 
777
                                if (error)
 
778
                                        g_error_free (error);
 
779
                                gtk_dialog_run (GTK_DIALOG (dlg));
 
780
                                gtk_widget_destroy (dlg);
 
781
                                return;
 
782
                        }
 
783
                        
 
784
                        grid = gnome_db_grid_new (model);
 
785
 
 
786
                        qei->grid = grid;
 
787
                        
 
788
                        context = gda_data_model_query_get_parameter_list (GDA_DATA_MODEL_QUERY (model));
 
789
                        g_object_unref (model);
 
790
 
 
791
                        if (fill_context_in_dialog (ws, context) == GTK_RESPONSE_ACCEPT) {
 
792
                                GtkWidget *window, *vbox, *toolbar;
 
793
                                gchar *str;
 
794
                                GtkActionGroup *extra_group;
 
795
                                GtkUIManager *ui;
 
796
 
 
797
                                str = g_strdup_printf (_("Execution of query '%s'"), 
 
798
                                                       gda_object_get_name (GDA_OBJECT (query)));
 
799
                                window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
800
                                g_signal_connect (G_OBJECT (window), "destroy",
 
801
                                                  G_CALLBACK (query_exec_window_destroy_cb), qei);
 
802
                                gtk_window_set_title (GTK_WINDOW (window), str);
 
803
                                g_free (str);                           
 
804
 
 
805
                                vbox = gtk_vbox_new (FALSE, 0);
 
806
                                gtk_container_add (GTK_CONTAINER (window), vbox);
 
807
                                gtk_widget_show (vbox);
 
808
                                qei->grid_box = vbox;
 
809
                                                                
 
810
                                ui = gtk_ui_manager_new ();
 
811
                                extra_group = gtk_action_group_new ("ExtraActions");
 
812
                                gtk_action_group_add_actions (extra_group, extra_actions, 
 
813
                                                              G_N_ELEMENTS (extra_actions),
 
814
                                                              window);
 
815
                                gtk_ui_manager_insert_action_group (ui, extra_group, 0);
 
816
                                gtk_ui_manager_add_ui_from_string (ui, grid_actions, -1, NULL);
 
817
                                toolbar = gtk_ui_manager_get_widget (ui, "/ToolBar");
 
818
                                gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
 
819
                                gtk_widget_show (toolbar);
 
820
                                
 
821
                                gtk_box_pack_start (GTK_BOX (vbox), grid, TRUE, TRUE, 0);
 
822
                                gtk_widget_show (grid);
 
823
                                gtk_widget_set_size_request (grid, 800, 300);
 
824
                                
 
825
                                gtk_widget_show (window);
 
826
 
 
827
                                ws->priv->opened_dialogs = g_slist_append (ws->priv->opened_dialogs, window);
 
828
                                g_signal_connect (G_OBJECT (window), "destroy",
 
829
                                                  G_CALLBACK (opened_dialog_closed_cb), ws);
 
830
                        }
 
831
                        else {
 
832
                                gtk_widget_destroy (grid);
 
833
                                query_exec_instance_free (qei);
 
834
                        }
 
835
                }
 
836
                else {
 
837
                        /* unparsed query */
 
838
                        context = gda_query_get_parameter_list (query);
 
839
                        if (fill_context_in_dialog (ws, context) == GTK_RESPONSE_ACCEPT) {
 
840
                                GtkWidget *dlg;
 
841
                                gint result;
 
842
                                gchar *msg;
 
843
                                const gchar *sql;
 
844
                                
 
845
                                sql = gda_renderer_render_as_sql (GDA_RENDERER (query), context, NULL,
 
846
                                                                  GDA_RENDERER_EXTRA_PRETTY_SQL, NULL);
 
847
                                query_exec_instance_free (qei);
 
848
                                msg = g_strdup_printf (_("<b><big>Execute the following query ?</big></b>\n"
 
849
                                                         "<small>This query can't be parsed: it may contain some "
 
850
                                                         "syntax or grammar which is dependant on the type of database "
 
851
                                                         "used, or may contain some error.</small>\n\n%s"), sql);
 
852
                                dlg = gtk_message_dialog_new (GTK_WINDOW (parent_window), 0,
 
853
                                                              GTK_MESSAGE_QUESTION,
 
854
                                                              GTK_BUTTONS_YES_NO, msg);
 
855
                                g_free (msg);
 
856
                                gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (dlg)->label), TRUE);
 
857
                                result = gtk_dialog_run (GTK_DIALOG (dlg));
 
858
                                gtk_widget_destroy (dlg);
 
859
                                if (result == GTK_RESPONSE_YES) {
 
860
                                        GError *error = NULL;
 
861
                                        GdaDataModel *data;
 
862
                                        GdaCommand *cmd;
 
863
                                        
 
864
                                        cmd = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, 0);
 
865
                                        data = gda_connection_execute_select_command (gda_dict_get_connection (ws->priv->dict),
 
866
                                                                                      cmd, NULL, &error);
 
867
                                        
 
868
                                        if (error) {
 
869
                                                GtkWidget *dlg;
 
870
                                                gchar *message;
 
871
                                                
 
872
                                                message = g_strdup (error->message);
 
873
                                                g_error_free (error);
 
874
                                                dlg = gtk_message_dialog_new (GTK_WINDOW (parent_window), 0,
 
875
                                                                              GTK_MESSAGE_ERROR,
 
876
                                                                              GTK_BUTTONS_CLOSE,
 
877
                                                                              message);
 
878
                                                g_free (message);
 
879
                                                gtk_dialog_run (GTK_DIALOG (dlg));
 
880
                                                gtk_widget_destroy (dlg);
 
881
                                        }
 
882
                                        else {
 
883
                                                if (data) {
 
884
                                                        GtkWidget *grid, *window, *vbox, *toolbar;
 
885
                                                        GtkActionGroup *extra_group;
 
886
                                                        GtkUIManager *ui;
 
887
 
 
888
                                                        grid = gnome_db_grid_new (data);
 
889
                                                        gtk_widget_set_size_request (grid, 800, 300);
 
890
                                                        g_object_unref (G_OBJECT (data));
 
891
                                                        
 
892
                                                        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
893
                                                        gtk_window_set_title (GTK_WINDOW (window), _("Execution results"));
 
894
                                                        
 
895
                                                        vbox = gtk_vbox_new (FALSE, 0);
 
896
                                                        gtk_container_add (GTK_CONTAINER (window), vbox);
 
897
                                                        gtk_widget_show (vbox);
 
898
                                                        
 
899
                                                        ui = gtk_ui_manager_new ();
 
900
                                                        extra_group = gtk_action_group_new ("ExtraActions");
 
901
                                                        gtk_action_group_add_actions (extra_group, extra_actions, 
 
902
                                                                                      G_N_ELEMENTS (extra_actions),
 
903
                                                                                      window);
 
904
                                                        gtk_ui_manager_insert_action_group (ui, extra_group, 0);
 
905
                                                        gtk_ui_manager_add_ui_from_string (ui, grid_actions, -1, NULL);
 
906
                                                        toolbar = gtk_ui_manager_get_widget (ui, "/ToolBar");
 
907
                                                        gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
 
908
                                                        gtk_widget_show (toolbar);
 
909
                                                        
 
910
                                                        gtk_box_pack_start (GTK_BOX (vbox), grid, TRUE, TRUE, 0);
 
911
                                                        gtk_widget_show (grid);
 
912
                                                        gtk_widget_show (window);
 
913
 
 
914
                                                        ws->priv->opened_dialogs = g_slist_append (ws->priv->opened_dialogs, window);
 
915
                                                        g_signal_connect (G_OBJECT (window), "destroy",
 
916
                                                                          G_CALLBACK (opened_dialog_closed_cb), ws);
 
917
                                                }
 
918
                                        }
 
919
                                }
 
920
                        }
 
921
                }
 
922
        }
 
923
}
 
924
 
 
925
static void
 
926
extra_action_close_cb (GtkAction *action, GtkWidget *window)
 
927
{
 
928
        gtk_widget_destroy (window);
 
929
}
 
930
 
 
931
static void
 
932
query_exec_window_destroy_cb (GtkWindow *window, QueryExecInstance *qei)
 
933
{
 
934
        query_exec_instance_free (qei);
 
935
}
 
936
 
 
937
static void
 
938
query_info_display_update (GdaQuery *query, WsQueries *ws)
 
939
{
 
940
        const gchar *str = NULL;
 
941
        gchar *title = NULL;
 
942
        
 
943
        if (query)
 
944
                str = gda_object_get_description (GDA_OBJECT (query));
 
945
        if (str && *str) 
 
946
                gtk_label_set_text (GTK_LABEL (ws->priv->description), str);
 
947
        else
 
948
                gtk_label_set_text (GTK_LABEL (ws->priv->description), "---");
 
949
 
 
950
        /* global title update */
 
951
        title = ws_queries_get_description (WORKSPACE_PAGE (ws));
 
952
        g_signal_emit_by_name (G_OBJECT (ws), "description_changed", title);
 
953
        g_free (title);
 
954
 
 
955
        /* SQL version of the query */
 
956
        if (query) {
 
957
                gchar *sql;
 
958
                GError *error = NULL;
 
959
                sql = gda_renderer_render_as_sql (GDA_RENDERER (query), NULL, NULL,
 
960
                                                  GDA_RENDERER_EXTRA_PRETTY_SQL, &error);
 
961
                if (sql) {
 
962
                        gnome_db_editor_set_text (GNOME_DB_EDITOR (ws->priv->sql_editor), sql, -1);
 
963
                        g_free (sql);
 
964
                }
 
965
                else {
 
966
                        if (error) {
 
967
                                str = error->message;
 
968
                                gnome_db_editor_set_text (GNOME_DB_EDITOR (ws->priv->sql_editor), str, -1);
 
969
                                g_error_free (error);
 
970
                        }
 
971
                        else
 
972
                                gnome_db_editor_set_text (GNOME_DB_EDITOR (ws->priv->sql_editor),
 
973
                                                          _("Non reported error"), -1);
 
974
                }
 
975
        }
 
976
        else
 
977
                gnome_db_editor_set_text (GNOME_DB_EDITOR (ws->priv->sql_editor), "", -1);
 
978
 
 
979
        /* query parameters */
 
980
        query_params_editor_set_query (QUERY_PARAMS_EDITOR (ws->priv->params_editor), query);
 
981
}
 
982
 
 
983
 
 
984
 
 
985
/* 
 
986
 * WorkspacePage interface implementation
 
987
 */
 
988
static gchar *
 
989
ws_queries_get_name (WorkspacePage *iface)
 
990
{
 
991
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
992
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
993
 
 
994
        return g_strdup_printf (_("Queries"));
 
995
}
 
996
 
 
997
static gchar *
 
998
ws_queries_get_description (WorkspacePage *iface)
 
999
{
 
1000
        gchar *str = NULL;
 
1001
        WsQueries *ws;
 
1002
 
 
1003
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1004
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1005
 
 
1006
        ws = WS_QUERIES (iface);
 
1007
        if (ws->priv->sel_obj) {
 
1008
                const gchar *cstr;
 
1009
                 cstr =  gda_object_get_name (GDA_OBJECT (ws->priv->sel_obj));
 
1010
                 str = g_strdup_printf ("Query: <b>%s</b>", (cstr && *cstr) ? cstr : "---");
 
1011
        }
 
1012
        else
 
1013
                str = g_strdup_printf ("<b>%s</b>", _("No query selected"));
 
1014
 
 
1015
        return str;
 
1016
}
 
1017
 
 
1018
static GtkWidget *
 
1019
ws_queries_get_sel_button (WorkspacePage *iface)
 
1020
{
 
1021
        GdkPixbuf *pixbuf;
 
1022
        GtkWidget *button, *wid, *hbox;
 
1023
 
 
1024
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1025
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1026
 
 
1027
        hbox = gtk_hbox_new (FALSE, 0);
 
1028
 
 
1029
        pixbuf = gnome_db_stock_get_icon_pixbuf (GNOME_DB_STOCK_QUERY);
 
1030
        wid = gtk_image_new_from_pixbuf (pixbuf);
 
1031
        g_object_unref (pixbuf);
 
1032
        gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
 
1033
        gtk_widget_show (wid);
 
1034
 
 
1035
        wid = gtk_label_new (_("Queries"));
 
1036
        gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 5);
 
1037
        gtk_widget_show (wid);
 
1038
 
 
1039
        button = gtk_toggle_button_new ();
 
1040
        gtk_container_add (GTK_CONTAINER (button), hbox);
 
1041
        gtk_widget_show (hbox);
 
1042
 
 
1043
        return button;
 
1044
}
 
1045
 
 
1046
static GtkWidget *
 
1047
ws_queries_get_selector (WorkspacePage *iface)
 
1048
{
 
1049
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1050
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1051
 
 
1052
        return WS_QUERIES (iface)->priv->selector;
 
1053
}
 
1054
 
 
1055
static GtkWidget *
 
1056
ws_queries_get_work_area (WorkspacePage *iface)
 
1057
{
 
1058
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1059
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1060
 
 
1061
        return WS_QUERIES (iface)->priv->work_area;
 
1062
}
 
1063
 
 
1064
static GtkActionGroup *
 
1065
ws_queries_get_actions (WorkspacePage *iface)
 
1066
{
 
1067
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1068
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1069
 
 
1070
        return WS_QUERIES (iface)->priv->actions;
 
1071
}
 
1072
 
 
1073
static const gchar *
 
1074
ws_queries_get_actions_ui (WorkspacePage *iface)
 
1075
{
 
1076
        g_return_val_if_fail (IS_WS_QUERIES (iface), NULL);
 
1077
        g_return_val_if_fail (WS_QUERIES (iface)->priv, NULL);
 
1078
 
 
1079
        return ui_actions_info;
 
1080
}
 
1081
 
 
1082
static void
 
1083
opened_dialog_closed_cb (GtkWidget *dlg, WsQueries *ws)
 
1084
{
 
1085
        ws->priv->opened_dialogs = g_slist_remove (ws->priv->opened_dialogs, dlg);
 
1086
}