Files
evolution/widgets/table/e-table-config.c
Christopher James Lahey e16e25daa7 Changed these to match the new ETable system.
2000-10-11  Christopher James Lahey  <clahey@helixcode.com>

	* tests/test-tree-1.c, tests/test-tree-2.c, tests/test-tree-3.c:
	Changed these to match the new ETable system.

	* gal/Makefile.am: Added e-table-column-specification.lo,
	e-table-extras.lo, e-table-specification.lo, and e-table-state.lo.

From gal/e-table/ChangeLog:

2000-10-11  Christopher James Lahey  <clahey@helixcode.com>

	* Makefile.am: Added e-table-column-specification.c,
	e-table-column-specification.h, e-table-extras.c,
	e-table-extras.h, e-table-specification.c,
	e-table-specification.h, e-table-state.c, and e-table-state.h.
	Removed some duplicated .h files.

	* e-cell-tree.c: Ref, sink, and unref the subcell instead of destroying
	it when done.

	* e-table-column-specification.c, e-table-column-specification.h:
	New class which describes a column without having a table get
	instantiated.

	* e-table-config.c: Changed get_specification to get_state to get
	this to compile.

	* e-table-defines.h, e-table-item.h: Moved the definition of
	ETableCursorMode from e-table-item.h to e-table-defines.h.

	* e-table-extras.c, e-table-extras.h: New class which acts as a
	set of 3 hash tables.  All from char * and to alternately, ECells,
	GCompareFuncs, and GdkPxibufs.

	* e-table-scrolled.c, e-table-scrolled.h: Changed this to match
	the new ETable function declarations.

	* e-table-sort-info.c, e-table-sort-info.h: Added functions for
	saving to and loading from xml.

	* e-table-specification.c, e-table-specification.h: New class
	which describes a table without having to instantiate it.

	* e-table-state.c, e-table-state.h: New class which describes the
	state of a table without having to instantiate the table.

	* e-table.c, e-table.h: Changed this to accept both a state and a
	specification instead of just a specification.  You then save only
	the state.  The specification stays exactly the same.  Also, you
	no longer need to pass in an ETableHeader.  Most of the
	information contained in the ETableHeader are in the
	specification.  However you may need to translate some of the
	strings in the specification to objects.  If you need anything
	other than the builtin choices, you need to create an ETableExtras
	and pass it in.

	* e-tree-model.c: Removed an unused variable.

svn path=/trunk/; revision=5837
2000-10-11 08:16:37 +00:00

251 lines
5.3 KiB
C

/* -*- 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_state (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));
}