From: Andrea Zagli Date: Sat, 1 Oct 2016 09:27:04 +0000 (+0200) Subject: Removed (for now) xml management. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=c43993d0c18e42fe45c9d94b613c1df4fe9768fa;p=zakconfi%2Fgui Removed (for now) xml management. --- diff --git a/data/zak-confi-gui/ui/zak-confi-gui.ui b/data/zak-confi-gui/ui/zak-confi-gui.ui index f54f7ff..3e4b18e 100644 --- a/data/zak-confi-gui/ui/zak-confi-gui.ui +++ b/data/zak-confi-gui/ui/zak-confi-gui.ui @@ -3,18 +3,6 @@ - - True - False - gtk-save-as - 1 - - - True - False - gtk-save-as - 1 - True False @@ -146,17 +134,6 @@ - - - E_xport - True - False - True - image2 - False - - - @@ -203,17 +180,6 @@ - - - E_xport - True - False - True - image3 - False - - - diff --git a/src/main.c b/src/main.c index a4fba8c..ed2164b 100644 --- a/src/main.c +++ b/src/main.c @@ -25,9 +25,6 @@ #include #include -#include -#include -#include #include @@ -291,291 +288,6 @@ view_trFolders_popup_menu (GdkEventButton *event) } } -static void -save_key_to_xml (ZakConfi *confi, xmlNodePtr xnodeParent, GNode *node) -{ - xmlNodePtr xnodeChild; - ZakConfiKey *ck; - - if (node == NULL) return; - - node = node->children; - while (node != NULL) - { - ck = (ZakConfiKey *)node->data; - - xnodeChild = xmlNewNode (NULL, (xmlChar *)"gconfi-key"); - xmlAddChild (xnodeParent, xnodeChild); - - xmlNewTextChild (xnodeChild, NULL, (xmlChar *)"name", (xmlChar *)ck->key); - xmlNewTextChild (xnodeChild, NULL, (xmlChar *)"description", (xmlChar *)ck->description); - - save_key_to_xml (confi, xnodeChild, node); - - node = node->next; - } -} - -static void -save_configuration_to_xml (ZakConfi *confi, xmlNodePtr xroot) -{ - xmlNodePtr xnode; - gchar *name; - gchar *description; - - g_object_get (G_OBJECT (confi), - "name", &name, - "description", &description, - NULL); - - xnode = xmlNewNode (NULL, (xmlChar *)"gconfi-configuration"); - xmlAddChild (xroot, xnode); - - xmlNewTextChild (xnode, NULL, (xmlChar *)"name", (xmlChar *)name); - xmlNewTextChild (xnode, NULL, (xmlChar *)"description", (xmlChar *)description); - - GNode *tree = zak_confi_get_tree (confi); - if (tree != NULL) - { - save_key_to_xml (confi, xnode, tree); - } -} - -static void -create_key_from_xml (ZakConfi *confi, - const gchar *pathParent, - GtkTreeIter *iterParent, - xmlNode *xnode, - xmlXPathContextPtr xpcontext) -{ - xmlXPathObjectPtr xpresult; - ZakConfiKey *ck; - - xpcontext->node = xnode; - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::name", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xmlNodeSetPtr xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - GtkTreeIter iter; - - ck = zak_confi_add_key (confi, pathParent, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), NULL); - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::description", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - ck->description = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); - - zak_confi_key_set_key (confi, ck); - } - } - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::value", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - ck->value = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); - - zak_confi_key_set_key (confi, ck); - } - } - - gtk_tree_store_append (storeFolders, &iter, iterParent); - gtk_tree_store_set (storeFolders, &iter, - FOLDERS_COL_KEY, ck->key, - FOLDERS_COL_VALUE, ck->value, - FOLDERS_COL_DESCRIPTION, ck->description, - -1); - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gconfi-key", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - gint i; - - xnodeset = xpresult->nodesetval; - for (i = 0; i < xnodeset->nodeNr; i++) - { - create_key_from_xml (confi, - g_strjoin (NULL, ck->path, (strcmp (ck->path, "") == 0 ? "" : "/"), ck->key, NULL), - &iter, - xnodeset->nodeTab[i], xpcontext); - } - } - } - } -} - -static void -create_config_from_xml (xmlNode *xnode, xmlXPathContextPtr xpcontext) -{ - xmlXPathObjectPtr xpresult; - ZakConfi *confi; - - xpcontext->node = xnode; - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::name", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xmlNodeSetPtr xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - - confi = zak_confi_new (cnc_string); - if (confi != NULL) - { - GtkTreeIter iter; - gint id; - gchar *name; - gchar *description; - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::description", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - xnodeset = xpresult->nodesetval; - if (xnodeset->nodeNr == 1) - { - g_object_set (G_OBJECT (confi), - "description", xmlNodeGetContent (xnodeset->nodeTab[0]), - NULL); - } - } - - g_object_get (G_OBJECT (confi), - "id_config", &id, - "name", &name, - "description", &description, - NULL); - - gtk_tree_store_append (storeFolders, &iter, NULL); - gtk_tree_store_set (storeFolders, &iter, - FOLDERS_COL_KEY, name, - FOLDERS_COL_DESCRIPTION, description, - -1); - - xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gconfi-key", xpcontext); - if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) - { - gint i; - - xnodeset = xpresult->nodesetval; - for (i = 0; i < xnodeset->nodeNr; i++) - { - create_key_from_xml (confi, "", &iter, xnodeset->nodeTab[i], xpcontext); - } - } - } - } - } -} - -static void -load_xml_configuration_schema (const gchar *filename) -{ - GNode *tree = NULL; - - xmlDocPtr xdoc = xmlParseFile (filename); - if (xdoc != NULL) - { - if (xmlXIncludeProcess (xdoc) == -1) - { - g_warning ("Error on xmlXIncludeProcess.\n"); - return; - } - - xmlXPathContextPtr xpcontext = xmlXPathNewContext (xdoc); - if (xpcontext != NULL) - { - xmlNode *xnode = xmlDocGetRootElement (xdoc); - if (xnode != NULL) - { - if (g_strcmp0 ((gchar *)xnode->name, "gconfi") == 0) - { - xnode = xnode->children; - while (xnode != NULL) - { - if (strcmp (xnode->name, "gconfi-configuration") == 0) - { - create_config_from_xml (xnode, xpcontext); - } - - xnode = xnode->next; - } - } - else if (g_strcmp0 ((gchar *)xnode->name, "gconfi-configuration") == 0) - { - create_config_from_xml (xnode, xpcontext); - } - else if (g_strcmp0 ((gchar *)xnode->name, "gconfi-key") == 0) - { - GtkTreeIter iter; - - if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) - { - GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); - if (path != NULL) - { - if (gtk_tree_path_get_depth (path) == 1) - { - ZakConfi *confi; - - gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, - -1); - - create_key_from_xml (confi, "", &iter, xnode, xpcontext); - } - else /* if (gtk_tree_path_get_depth (path) > 1 */ - { - GtkTreeIter iterConfi; - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfi, - gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1))) - { - ZakConfi *confi; - ZakConfiKey *ck; - - gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi, - -1); - - gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, - -1); - - if (ZAK_IS_CONFI (confi)) - { - create_key_from_xml (confi, g_strconcat (ck->path, "/", ck->key, NULL), &iter, xnode, xpcontext); - } - } - } - } - } - } - else - { - g_warning ("%s is not a valid gConfi schema for configurations.", filename); - } - } - else - { - g_warning ("%s is not a valid gConfi schema for configurations.", filename); - } - } - else - { - g_warning ("Error on xmlXPathNewContext."); - } - } - else - { - g_warning ("Error on xml parsing file %s.", filename); - } -} - /* CALLBACKS */ G_MODULE_EXPORT void on_mnuDbOpen_activate (GtkMenuItem *menuitem, @@ -787,84 +499,6 @@ on_mnuConfigsDelete_activate (GtkMenuItem *menuitem, } } -G_MODULE_EXPORT void -on_mnuConfigsExport_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ - GtkWidget *diag = gtk_file_chooser_dialog_new ("Export Configurations - gConfi", - GTK_WINDOW (w), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - - if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_ACCEPT) - { - ZakConfi *confi; - gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (diag)); - - GtkTreeIter iter; - if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) - { - /* saving only selected configuration */ - GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); - if (gtk_tree_path_get_depth (path) > 1) - { - path = gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1); - gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iter, path); - } - - gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, - -1); - if (ZAK_IS_CONFI (confi)) - { - xmlDocPtr xdoc; - xmlNodePtr xnode; - - xdoc = xmlNewDoc ((xmlChar *)"1.0"); - xnode = xmlNewNode (NULL, (xmlChar *)"gconfi"); - xmlDocSetRootElement (xdoc, xnode); - - save_configuration_to_xml (confi, xnode); - - xmlSaveFile (filename, xdoc); - } - - gtk_tree_path_free (path); - } - else - { - /* saving all configurations */ - GList *configs = zak_confi_get_configs_list (cnc_string, filter); - if (configs != NULL) - { - xmlDocPtr xdoc; - xmlNodePtr xnode; - - xdoc = xmlNewDoc ((xmlChar *)"1.0"); - xnode = xmlNewNode (NULL, (xmlChar *)"gconfi"); - xmlDocSetRootElement (xdoc, xnode); - - configs = g_list_first (configs); - while (configs != NULL) - { - confi = (ZakConfi *)configs->data; - - save_configuration_to_xml (confi, xnode); - - configs = g_list_next (configs); - } - - xmlSaveFile (filename, xdoc); - } - } - - g_free (filename); - } - - gtk_widget_destroy (diag); -} - G_MODULE_EXPORT void on_mnuKeysNew_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -1079,12 +713,6 @@ on_mnuKeysDelete_activate (GtkMenuItem *menuitem, } } -G_MODULE_EXPORT void -on_mnuKeysExport_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ -} - G_MODULE_EXPORT void on_mnuHelpAbout_activate (GtkMenuItem *menuitem, gpointer user_data)