r6834 - dumbhippo/trunk/client/common/ddm
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6834 - dumbhippo/trunk/client/common/ddm
- Date: Fri, 26 Oct 2007 09:53:45 -0500 (CDT)
Author: otaylor
Date: 2007-10-26 09:53:44 -0500 (Fri, 26 Oct 2007)
New Revision: 6834
Modified:
dumbhippo/trunk/client/common/ddm/static-file-backend.h
dumbhippo/trunk/client/common/ddm/static-file-parser.c
Log:
Add ddm_static_load_local_string(), so that we can conveniently feed
local resources into the model when testing rule-based properties.
Modified: dumbhippo/trunk/client/common/ddm/static-file-backend.h
===================================================================
--- dumbhippo/trunk/client/common/ddm/static-file-backend.h 2007-10-25 23:28:22 UTC (rev 6833)
+++ dumbhippo/trunk/client/common/ddm/static-file-backend.h 2007-10-26 14:53:44 UTC (rev 6834)
@@ -5,15 +5,27 @@
G_BEGIN_DECLS
-DDMDataModel *ddm_static_file_model_new (const char *filename,
- GError **error);
+DDMDataModel *ddm_static_file_model_new (const char *filename,
+ GError **error);
+/* Processes all pending requests, avoids having to run the main loop
+ */
void ddm_static_file_model_flush (DDMDataModel *model);
+/* Used internally to ddm_static_file_model_new
+ */
gboolean ddm_static_file_parse (const char *filename,
DDMDataModel *model,
GError **error);
+/* This one one uses the same XML parsing mechanism that is used to
+ * load the backend model to fill in local resources in the frontend
+ * model (or any other model.)
+ */
+gboolean ddm_static_load_local_string(const char *str,
+ DDMDataModel *mode,
+ GError **error);
+
G_END_DECLS
#endif /* __STATIC_FILE_BACKEND_H__ */
Modified: dumbhippo/trunk/client/common/ddm/static-file-parser.c
===================================================================
--- dumbhippo/trunk/client/common/ddm/static-file-parser.c 2007-10-25 23:28:22 UTC (rev 6833)
+++ dumbhippo/trunk/client/common/ddm/static-file-parser.c 2007-10-26 14:53:44 UTC (rev 6834)
@@ -61,7 +61,9 @@
} SFElement;
typedef struct {
+ GMarkupParseContext *context;
DDMDataModel *model;
+ gboolean local;
SFParseState state;
GSList *elements;
@@ -85,16 +87,48 @@
const char *uri;
} SFNamespace;
+static void static_file_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error);
+static void static_file_end_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error);
+static void static_file_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error);
+static void static_file_passthrough (GMarkupParseContext *context,
+ const gchar *passthrough_text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error);
+static void static_file_error (GMarkupParseContext *context,
+ GError *error,
+ gpointer user_data);
+
+static const GMarkupParser static_file_parser = {
+ static_file_start_element,
+ static_file_end_element,
+ static_file_text,
+ static_file_passthrough,
+ static_file_error
+};
+
static void
-sf_parse_info_init(SFParseInfo *info,
- DDMDataModel *model)
+sf_parse_info_init(SFParseInfo *info,
+ DDMDataModel *model,
+ gboolean local)
{
+ memset(info, 0, sizeof(*info));
+
info->model = model;
info->state = STATE_OUTSIDE;
- info->elements = NULL;
- info->element = NULL;
-
info->names[NAME_INVALID] = NULL;
info->names[NAME_DEFAULT_CHILDREN] = ddm_qname_get(SYSTEM_NAMESPACE, "defaultChildren");
info->names[NAME_MODEL] = ddm_qname_get(SYSTEM_NAMESPACE, "model");
@@ -103,11 +137,10 @@
info->names[NAME_TYPE] = ddm_qname_get(SYSTEM_NAMESPACE, "type");
info->names[NAME_UPDATE] = ddm_qname_get(SYSTEM_NAMESPACE, "update");
- info->current_resource = NULL;
- info->current_property_id = NULL;
- info->current_default_children = NULL;
-
- info->value = NULL;
+ info->context = g_markup_parse_context_new(&static_file_parser,
+ G_MARKUP_TREAT_CDATA_AS_TEXT,
+ info,
+ NULL);
}
static gboolean
@@ -349,6 +382,8 @@
static void
sf_parse_info_finish(SFParseInfo *info)
{
+ g_markup_parse_context_free(info->context);
+
while (info->elements)
sf_parse_info_pop_element(info);
@@ -453,10 +488,14 @@
absolute_resource_id = get_absolute_resource_id(info, resource_id, error);
if (!absolute_resource_id)
return;
-
- info->current_resource = ddm_data_model_ensure_resource(info->model, absolute_resource_id,
- element->name->uri);
+ if (info->local)
+ info->current_resource = ddm_data_model_ensure_local_resource(info->model, absolute_resource_id,
+ element->name->uri);
+ else
+ info->current_resource = ddm_data_model_ensure_resource(info->model, absolute_resource_id,
+ element->name->uri);
+
g_free(absolute_resource_id);
info->state = STATE_RESOURCE;
@@ -696,21 +735,12 @@
{
}
-static const GMarkupParser static_file_parser = {
- static_file_start_element,
- static_file_end_element,
- static_file_text,
- static_file_passthrough,
- static_file_error
-};
-
gboolean
ddm_static_file_parse(const char *filename,
DDMDataModel *model,
GError **error)
{
SFParseInfo info;
- GMarkupParseContext *context;
gboolean result;
char *text;
gsize len;
@@ -722,19 +752,30 @@
if (!g_file_get_contents(filename, &text, &len, error))
return FALSE;
- sf_parse_info_init(&info, model);
+ sf_parse_info_init(&info, model, FALSE);
- info.model = model;
- info.state = STATE_OUTSIDE;
+ result = g_markup_parse_context_parse(info.context, text, len, error);
- context = g_markup_parse_context_new(&static_file_parser,
- G_MARKUP_TREAT_CDATA_AS_TEXT,
- &info,
- NULL);
+ sf_parse_info_finish(&info);
+
+ return result;
+}
+
+gboolean
+ddm_static_load_local_string(const char *str,
+ DDMDataModel *model,
+ GError **error)
+{
+ SFParseInfo info;
+ gboolean result;
- result = g_markup_parse_context_parse(context, text, len, error);
+ g_return_val_if_fail(str != NULL, FALSE);
+ g_return_val_if_fail(DDM_IS_DATA_MODEL(model), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
- g_markup_parse_context_free(context);
+ sf_parse_info_init(&info, model, TRUE);
+
+ result = g_markup_parse_context_parse(info.context, str, strlen(str), error);
sf_parse_info_finish(&info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]