Commit 78506604 authored by winckel's avatar winckel

Moved xmlCleanupParser into main function, it is not safe to call it in threads.

Added messages for XML filters parsing when no definitions are found in the file.
Saved file names when opening or saving files.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4336 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 7f70223d
......@@ -82,7 +82,8 @@ int main(int argc, char *argv[])
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
LIBXML_TEST_VERSION;
xmlInitParser();
/* Initialize the widget set */
gtk_init(&argc, &argv);
......@@ -94,5 +95,10 @@ int main(int argc, char *argv[])
/* Enter the main event loop, and wait for user interaction */
gtk_main ();
/* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser ();
return ret;
}
......@@ -752,11 +752,6 @@ static int xml_parse_doc(xmlDocPtr doc) {
/* Free the document */
xmlFreeDoc(doc);
/* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser();
if (ret == RC_OK) {
resolve_typedefs (&head);
resolve_pointer_type (&head);
......
......@@ -214,7 +214,7 @@ static int xml_parse_filters(xmlDocPtr doc)
xmlNode *filter_node = NULL;
xmlNode *cur_node = NULL;
ui_filter_e filter;
int ret = RC_OK;
int ret = RC_FAIL;
/* Get the root element node */
root_element = xmlDocGetRootElement (doc);
......@@ -222,7 +222,7 @@ static int xml_parse_filters(xmlDocPtr doc)
if (root_element != NULL)
{
/* Search for the start of filters definition */
for (cur_node = root_element; (strcmp ((char *) cur_node->name, "filters") != 0) && (cur_node != NULL);
for (cur_node = root_element; (cur_node != NULL) && (strcmp ((char *) cur_node->name, "filters") != 0);
cur_node = cur_node->next)
;
......@@ -265,6 +265,7 @@ static int xml_parse_filters(xmlDocPtr doc)
cur_node->properties->children->content[0] == '0' ?
ENTRY_ENABLED_FALSE : ENTRY_ENABLED_TRUE);
ret = RC_OK;
cur_node = cur_node->next;
}
}
......@@ -281,12 +282,7 @@ static int xml_parse_filters(xmlDocPtr doc)
/* Free the document */
xmlFreeDoc (doc);
/* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser ();
g_message("Parsed filters definition");
g_message("Parsed XML filters definition");
return ret;
}
......@@ -294,6 +290,7 @@ static int xml_parse_filters(xmlDocPtr doc)
int ui_filters_read(const char *file_name)
{
xmlDocPtr doc; /* the resulting document tree */
int ret;
if (file_name == NULL)
{
......@@ -310,7 +307,16 @@ int ui_filters_read(const char *file_name)
return RC_FAIL;
}
return xml_parse_filters (doc);
ret = xml_parse_filters (doc);
if (ret != RC_OK)
{
g_warning("Found no filter definition in \"%s\"", file_name);
ui_notification_dialog (DIALOG_WARNING, "Found no filter definition in \"%s\"", file_name);
return RC_FAIL;
}
return ret;
}
static void write_filter(FILE *filter_file, ui_filter_t *filter)
......@@ -343,7 +349,8 @@ int ui_filters_file_write(const char *file_name)
return RC_FAIL;
}
fprintf (filter_file, "<filters>\n");
fprintf (filter_file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<filters>\n");
write_filter (filter_file, &ui_filters.messages);
write_filter (filter_file, &ui_filters.origin_tasks);
......
......@@ -42,7 +42,11 @@ static void ui_gtk_parse_arg(int argc, char *argv[])
switch (c)
{
case 'f':
ui_main_data.filters_file_name = optarg;
ui_main_data.filters_file_name = malloc (strlen (optarg) + 1);
if (ui_main_data.filters_file_name != NULL)
{
strcpy (ui_main_data.filters_file_name, optarg);
}
break;
case 'h':
......@@ -55,7 +59,11 @@ static void ui_gtk_parse_arg(int argc, char *argv[])
break;
case 'm':
ui_main_data.messages_file_name = optarg;
ui_main_data.messages_file_name = malloc (strlen (optarg) + 1);
if (ui_main_data.messages_file_name != NULL)
{
strcpy (ui_main_data.messages_file_name, optarg);
}
break;
case 'p':
......
......@@ -191,8 +191,20 @@ int ui_messages_open_file_chooser(void)
if (accept)
{
result = ui_messages_read (filename);
if (result == RC_OK)
{
/* Update messages file name for future use */
if (ui_main_data.messages_file_name != NULL)
{
g_free (ui_main_data.messages_file_name);
}
ui_main_data.messages_file_name = filename;
}
else
{
g_free (filename);
}
}
return result;
}
......@@ -219,8 +231,20 @@ int ui_filters_open_file_chooser(void)
if (accept)
{
result = ui_filters_read(filename);
if (result == RC_OK)
{
/* Update filters file name for future use */
if (ui_main_data.filters_file_name != NULL)
{
g_free (ui_main_data.filters_file_name);
}
ui_main_data.filters_file_name = filename;
}
else
{
g_free (filename);
}
}
return result;
}
......@@ -231,15 +255,19 @@ int ui_filters_save_file_chooser(void)
int result = RC_OK;
filechooser = gtk_file_chooser_dialog_new ("Save file", GTK_WINDOW (ui_main_data.window),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (filechooser), TRUE);
//gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filechooser), "filters.xml");
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), "./filters.xml");
if (ui_main_data.filters_file_name != NULL)
{
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), ui_main_data.filters_file_name);
}
else
{
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filechooser), "filters.xml");
}
/* Process the response */
if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
......@@ -247,9 +275,21 @@ int ui_filters_save_file_chooser(void)
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
result = ui_filters_file_write(filename);
result = ui_filters_file_write (filename);
if (result == RC_OK)
{
/* Update filters file name for future use */
if (ui_main_data.filters_file_name != NULL)
{
g_free (ui_main_data.filters_file_name);
}
ui_main_data.filters_file_name = filename;
}
else
{
g_free (filename);
}
}
gtk_widget_destroy (filechooser);
return result;
......
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