aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-config.c
blob: ee3027e5d374b3ba084bf44ade82f7efc0b4791a (plain) (blame)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * E-table.c: A graphical view of a Table.
 *
 * Author:
 *   Miguel de Icaza (miguel@gnu.org)
 *
 * Copyright 1999, Helix Code, Inc
 */
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include <gnome-xml/xmlmemory.h>
#include "gal/util/e-util.h"
#include "gal/util/e-xml-utils.h"
#include "gal/widgets/e-canvas.h"
#include "e-table.h"
#include "e-table-header-item.h"
#include "e-table-subset.h"
#include "e-table-item.h"
#include "e-table-group.h"
#include "e-table-config.h"

typedef struct {
    GladeXML *gui;
    char     *old_spec;
} ConfigData;

static void
load_data (GladeXML *xml, char *label_widget, const char *content)
{
    GtkLabel *label = GTK_LABEL (glade_xml_get_widget (xml, label_widget));

    gtk_label_set_text (label, content);
}

static char *
get_fields (ETable *etable, xmlNode *xmlRoot)
{
    xmlNode *xmlColumns;
    xmlNode *column;
    GString *res;
    char *s;
    
    res = g_string_new ("");
    xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown");

    for (column = xmlColumns->childs; column; column = column->next){
        ETableCol *ecol;
        char *content;
        int col;

        content = xmlNodeListGetString (column->doc, column->childs, 1);
        col = atoi (content);
        xmlFree (content);

        ecol = e_table_header_get_column (etable->header, col);

        g_string_append (res, ecol->text);
        if (column->next)
            g_string_append (res, ", ");
    }
    s = res->str;
    g_string_free (res, FALSE);

    return s;
}

static char *
get_grouping (ETable *etable, xmlNode *xmlRoot)
{
    xmlNode *xmlGrouping;
    GString *res;
    char *s;
    
    res = g_string_new ("");
    xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping");

    s = res->str;
    g_string_free (res, FALSE);

    return s;
}

static char *
get_sort (ETable *etable)
{
    return g_strdup ("None");
}

static char *
get_filter (ETable *etable)
{
    return g_strdup ("None");
}

/*
 * Loads a user-readable definition of the various e-table parameters
 * into the dialog for configuring it
 */
static void
load_label_data (GladeXML *gui, ETable *etable)
{
    /* FIXME: Set this to the right value. */
    xmlNode *xmlRoot = NULL;
    char *s;
    
/*  xmlRoot = xmlDocGetRootElement (etable->specification); */

    s = get_fields (etable, xmlRoot);
    load_data (gui, "label1", s);
    g_free (s);

    s = get_grouping (etable, xmlRoot);
    load_data (gui, "label2", s);
    g_free (s);

    s = get_sort (etable);
    load_data (gui, "label3", s);
    g_free (s);

    s = get_filter (etable);
    load_data (gui, "label4", s);
    g_free (s);
}

static void
cb_button_fields (GtkWidget *widget, ETable *etable)
{
}

static void
cb_button_grouping (GtkWidget *widget, ETable *etable)
{
}

static void
cb_button_sort (GtkWidget *widget, ETable *etable)
{
}

static void
cb_button_filter (GtkWidget *widget, ETable *etable)
{
}

GnomeDialog *
e_table_gui_config (ETable *etable)
{
    GladeXML *gui;
    GnomeDialog *dialog;
    ConfigData *config_data;

    g_return_val_if_fail(etable != NULL, NULL);
    g_return_val_if_fail(E_IS_TABLE(etable), NULL);

    glade_gnome_init ();
    gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-config.glade", NULL);
    if (!gui)
        return NULL;

    dialog = GNOME_DIALOG (glade_xml_get_widget (gui, "e-table-config"));

    gtk_signal_connect (
        GTK_OBJECT (glade_xml_get_widget (gui, "button-fields")),
        "clicked", GTK_SIGNAL_FUNC (cb_button_fields), etable);
    gtk_signal_connect (
        GTK_OBJECT (glade_xml_get_widget (gui, "button-grouping")),
        "clicked", GTK_SIGNAL_FUNC (cb_button_grouping), etable);
    gtk_signal_connect (
        GTK_OBJECT (glade_xml_get_widget (gui, "button-sort")),
        "clicked", GTK_SIGNAL_FUNC (cb_button_sort), etable);
    gtk_signal_connect (
        GTK_OBJECT (glade_xml_get_widget (gui, "button-filter")),
        "clicked", GTK_SIGNAL_FUNC (cb_button_filter), etable);

    load_label_data (gui, etable);

    config_data = g_new (ConfigData, 1);
    config_data->gui = gui;
    config_data->old_spec = e_table_get_specification (etable);
    
    gtk_object_set_data (
        GTK_OBJECT (dialog), "config-data",
        config_data);
    
    return dialog;
}

static void
e_table_gui_destroy_config_data (GtkWidget *widget)
{
    ConfigData *cd = gtk_object_get_data (GTK_OBJECT (widget), "config-data");

    g_free (cd->old_spec);
    gtk_object_destroy (GTK_OBJECT (cd->gui));
    g_free (cd);
}

void
e_table_gui_config_accept (GtkWidget *widget, ETable *etable)
{
    g_return_if_fail(etable != NULL);
    g_return_if_fail(E_IS_TABLE(etable));
    g_return_if_fail(widget != NULL);
    g_return_if_fail(GTK_IS_WIDGET(widget));

    e_table_gui_destroy_config_data (widget);
}

void
e_table_gui_config_cancel (GtkWidget *widget, ETable *etable)
{
    g_return_if_fail(etable != NULL);
    g_return_if_fail(E_IS_TABLE(etable));
    g_return_if_fail(widget != NULL);
    g_return_if_fail(GTK_IS_WIDGET(widget));

    e_table_gui_destroy_config_data (widget);
}

void
e_table_do_gui_config (GtkWidget *parent, ETable *etable)
{
    GnomeDialog *dialog;
    int r;
    
    g_return_if_fail(etable != NULL);
    g_return_if_fail(E_IS_TABLE(etable));
    g_return_if_fail(parent == NULL || GTK_IS_WINDOW(parent));

    dialog = GNOME_DIALOG (e_table_gui_config (etable));
    if (!dialog)
        return;

    if (parent)
        gnome_dialog_set_parent (dialog, GTK_WINDOW (parent));
    
    r = gnome_dialog_run (GNOME_DIALOG (dialog));

    if (r == -1 || r == 1)
        e_table_gui_config_cancel (GTK_WIDGET (dialog), etable);
    else
        e_table_gui_config_accept (GTK_WIDGET (dialog), etable);

    if (r != -1)
        gtk_object_destroy (GTK_OBJECT (dialog));
}