Commit 37036f47 authored by Paolo Borelli's avatar Paolo Borelli

Clean up some of the Query logic, QueryResult is now hashtable of GValues

instead of ints, bringing us a little nearer to support other kind of queries.
Remove the query->window_title field since it doesn't make sense: e.g a query
dialog can contain differnt queries.
parent f575368b
2003-10-20 Paolo Borelli <pborelli@katamail.com>
* src/glade-project-window.[ch]: move GladeProjectQuery here and
remove the window_title field since it doesn't make sense, e.g. you
can query for different properties in the same dialog.
* src/glade-widget.c: move QueryResult struct here and cleanup the
query logic a little.
* src/glade-property.[ch]: delete stuff moved elsewhere.
* src/glade.h: remove the WindowTitle tag.
* widgets/gtkbox.xml: remove WindowTitle.
* widgets/gtktable.xml: ditto.
* widgets/gtknotebook.xml: ditto.
2003-10-20 Paolo Borelli <pborelli@katamail.com>
* src/glade-widget.c (glade_widget_query_properties): set the query
......
......@@ -208,7 +208,6 @@ glade_property_query_new (void)
GladePropertyQuery *query;
query = g_new0 (GladePropertyQuery, 1);
query->window_title = NULL;
query->question = NULL;
return query;
......@@ -224,11 +223,9 @@ glade_query_new_from_node (GladeXmlNode *node)
query = glade_property_query_new ();
query->window_title = glade_xml_get_value_string_required (node, GLADE_TAG_WINDOW_TITLE, NULL);
query->question = glade_xml_get_value_string_required (node, GLADE_TAG_QUESTION, NULL);
if ((query->window_title == NULL) ||
(query->question == NULL))
if (!query->question)
return NULL;
return query;
......@@ -242,7 +239,6 @@ glade_property_query_clone (GladePropertyQuery *query)
g_return_val_if_fail (query != NULL, NULL);
clon = glade_property_query_new ();
clon->window_title = g_strdup (query->window_title);
clon->question = g_strdup (clon->question);
return clon;
......@@ -254,7 +250,6 @@ glade_property_query_free (GladePropertyQuery *query)
if (query == NULL)
return;
g_free (query->window_title);
g_free (query->question);
g_free (query);
}
......
......@@ -192,6 +192,18 @@ struct _GladePropertyClass
*/
};
/**
* For now it only contains a string with the question for the query,
* since we only support numerical queries... when we add support for
* others queries it should contain something more complicated, maybe
* a whole GtkWidget (look at the query you get when creating a GtkDialog
* in glade-2
*/
struct _GladePropertyQuery
{
gchar *question;
};
GladePropertyClass * glade_property_class_new (void);
GladePropertyClass * glade_property_class_new_from_spec (GParamSpec *spec);
GladePropertyClass *glade_property_class_clone (GladePropertyClass *property_class);
......
......@@ -325,51 +325,6 @@ glade_property_get_enum (GladeProperty *property)
return choice;
}
void
glade_property_query_result_set_int (GladePropertyQueryResult *result,
const gchar *key,
gint value)
{
g_return_if_fail (result != NULL);
g_return_if_fail (key != NULL);
g_hash_table_insert (result->hash, (gchar *)key,
GINT_TO_POINTER (value));
}
void
glade_property_query_result_get_int (GladePropertyQueryResult *result,
const gchar *key,
gint *return_value)
{
g_return_if_fail (result != NULL);
g_return_if_fail (key != NULL);
*return_value = GPOINTER_TO_INT (g_hash_table_lookup (result->hash, key));
}
GladePropertyQueryResult *
glade_property_query_result_new (void)
{
GladePropertyQueryResult *result;
result = g_new0 (GladePropertyQueryResult, 1);
result->hash = g_hash_table_new (g_str_hash, g_str_equal);
return result;
}
void
glade_property_query_result_destroy (GladePropertyQueryResult *result)
{
g_return_if_fail (result != NULL);
g_hash_table_destroy (result->hash);
result->hash = NULL;
g_free (result);
}
GladeXmlNode *
glade_property_write (GladeXmlContext *context, GladeProperty *property)
{
......
......@@ -51,18 +51,6 @@ struct _GladePropertyObjectClass
void (*changed) (GladeProperty *property, const gchar *value);
};
struct _GladePropertyQuery
{
gchar *window_title;
gchar *question;
};
struct _GladePropertyQueryResult
{
GHashTable *hash;
};
GType glade_property_get_type (void);
GList *glade_property_list_new_from_widget_class (GladeWidgetClass *class,
......@@ -88,17 +76,6 @@ void glade_property_get_from_widget (GladeProperty *property);
GladeProperty *glade_property_get_from_id (GList *settings_list,
const gchar *id);
/* Property Queries */
GladePropertyQueryResult *glade_property_query_result_new (void);
void glade_property_query_result_destroy (GladePropertyQueryResult *result);
void glade_property_query_result_get_int (GladePropertyQueryResult *result,
const gchar *name,
gint *return_value);
void glade_property_query_result_set_int (GladePropertyQueryResult *result,
const gchar *key,
gint value);
/* XML i/o */
GladeXmlNode *glade_property_write (GladeXmlContext *context, GladeProperty *property);
......
......@@ -17,7 +17,6 @@ typedef struct _GladeWidgetClassSignal GladeWidgetClassSignal;
typedef struct _GladeProperty GladeProperty;
typedef struct _GladePropertyClass GladePropertyClass;
typedef struct _GladePropertyQuery GladePropertyQuery;
typedef struct _GladePropertyQueryResult GladePropertyQueryResult;
typedef struct _GladeParameter GladeParameter;
typedef struct _GladeChoice GladeChoice;
......
......@@ -679,6 +679,61 @@ glade_widget_new_full (GladeWidgetClass *class,
return widget;
}
/**
* Temp struct to hold the results of a query.
* The keys of the hashtable are the GladePropertyClass->id , while the
* values are the GValues the user sets for the property.
*/
typedef struct {
GHashTable *hash;
} GladePropertyQueryResult;
static GladePropertyQueryResult *
glade_property_query_result_new (void)
{
GladePropertyQueryResult *result;
result = g_new0 (GladePropertyQueryResult, 1);
result->hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
return result;
}
static void
glade_property_query_result_destroy (GladePropertyQueryResult *result)
{
g_return_if_fail (result != NULL);
g_hash_table_destroy (result->hash);
result->hash = NULL;
g_free (result);
}
static void
glade_widget_query_set_result (gpointer _key,
gpointer _value,
gpointer _data)
{
gchar *property_id = _key;
GtkWidget *widget = _value;
GladePropertyQueryResult *result = _data;
gint num;
GValue *value = g_new0 (GValue, 1);
g_value_init (value, G_TYPE_INT);
/* TODO: for now we only support quering int properties through a
* spinbutton. In the future we should have a different function for
* each GladePropertyClass which requires it.
*/
num = (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
g_value_set_int (value, num);
g_hash_table_insert (result->hash, property_id, value);
}
static GtkWidget *
glade_widget_append_query (GtkWidget *table,
GladePropertyClass *property_class,
......@@ -715,20 +770,6 @@ glade_widget_append_query (GtkWidget *table,
return spin;
}
void
glade_widget_query_properties_set (gpointer key_,
gpointer value_,
gpointer user_data)
{
GladePropertyQueryResult *result = user_data;
GtkWidget *spin = value_;
const gchar *key = key_;
gint num;
num = (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin));
glade_property_query_result_set_int (result, key, num);
}
/**
* glade_widget_query_properties:
* @class:
......@@ -774,7 +815,7 @@ glade_widget_query_properties (GladeWidgetClass *class,
table = gtk_table_new (0, 0, FALSE);
gtk_widget_show (table);
gtk_box_pack_start_defaults (GTK_BOX (vbox), table);
hash = g_hash_table_new (g_str_hash, g_str_equal);
for (list = class->properties; list; list = list->next) {
......@@ -794,7 +835,7 @@ glade_widget_query_properties (GladeWidgetClass *class,
switch (response) {
case GTK_RESPONSE_ACCEPT:
g_hash_table_foreach (hash,
glade_widget_query_properties_set,
glade_widget_query_set_result,
result);
break;
case GTK_RESPONSE_REJECT:
......@@ -822,20 +863,20 @@ glade_widget_apply_queried_properties (GladeWidget *widget,
GladePropertyQueryResult *result)
{
GList *list;
GValue *value = g_new0 (GValue, 1);
g_value_init (value, G_TYPE_INT);
for (list = widget->properties; list; list = list->next) {
GladeProperty *property;
GladePropertyClass *pclass;
GValue *value;
list = widget->class->properties;
for (; list; list = list->next) {
GladePropertyClass *pclass = list->data;
property = GLADE_PROPERTY (list->data);
pclass = property->class;
if (pclass->query) {
GladeProperty *property;
gint temp;
glade_property_query_result_get_int (result, pclass->id, &temp);
property = glade_property_get_from_id (widget->properties, pclass->id);
g_value_set_int (value, temp);
value = g_hash_table_lookup (result->hash, pclass->id);
if (!value) {
g_warning ("Property value not found in query result");
continue;
}
glade_property_set (property, value);
}
}
......@@ -876,12 +917,13 @@ glade_widget_new_from_class (GladeWidgetClass *class,
if (widget->class->fill_empty)
widget->class->fill_empty (widget->widget);
glade_widget_apply_queried_properties (widget, result);
if (result)
glade_property_query_result_destroy (result);
glade_widget_set_default_options (widget);
if (result) {
glade_widget_apply_queried_properties (widget, result);
glade_property_query_result_destroy (result);
}
return widget;
}
......
......@@ -82,7 +82,6 @@
#define GLADE_TAG_SET_FUNCTION "SetFunction"
#define GLADE_TAG_GET_FUNCTION "GetFunction"
#define GLADE_TAG_QUERY "Query"
#define GLADE_TAG_WINDOW_TITLE "WindowTitle"
#define GLADE_TAG_QUESTION "Question"
#define GLADE_TAG_VISIBLE_LINES "VisibleLines"
#define GLADE_ENUM_DATA_TAG "GladeEnumDataTag"
......
......@@ -13,7 +13,6 @@
<Parameter Key="ClimbRate" Value="1"/>
</Parameters>
<Query>
<WindowTitle>New box</WindowTitle>
<Question>Number of items on the box</Question>
</Query>
<SetFunction>glade_gtk_box_set_size</SetFunction>
......
......@@ -15,7 +15,6 @@
<Parameter Key="ClibmRate" Value="1"/>
</Parameters>
<Query>
<WindowTitle>New Notebook</WindowTitle>
<Question>Number of pages</Question>
</Query>
<SetFunction>glade_gtk_notebook_set_n_pages</SetFunction>
......
......@@ -12,7 +12,6 @@
<Parameter Key="ClimbRate" Value="1"/>
</Parameters>
<Query>
<WindowTitle>New table</WindowTitle>
<Question>Number of rows</Question>
</Query>
<SetFunction>glade_gtk_table_set_n_rows</SetFunction>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment