From 0ff3efe2c12e3ebbdd55b6ec5253d386a7663596 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 1 May 2016 15:42:57 +0200 Subject: [PATCH] Changed lib(zak)confi namespace. --- .gitignore | 1 + configure.ac | 27 +++++++++- src/main.c | 150 +++++++++++++++++++++++++-------------------------- 3 files changed, 101 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 29e3115..59a9c5d 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ tests/test *.csv gtk-doc.m4 COPYING +gconfi \ No newline at end of file diff --git a/configure.ac b/configure.ac index 53b43ae..2b382d6 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([gConfi], [0.5.0], [azagli@libero.it]) +AC_INIT([gConfi], [0.10.0], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/main.c]) AM_INIT_AUTOMAKE(-Wall) @@ -16,9 +16,18 @@ AC_CANONICAL_SYSTEM # Checks for programs. AC_PROG_CC +dnl ****************************** +dnl Translations +dnl ****************************** +GETTEXT_PACKAGE=gconfi +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", + [The prefix for our gettext translation domains.]) +AM_GLIB_GNU_GETTEXT + # Checks for libraries. PKG_CHECK_MODULES(GCONFI, [gtk+-3.0 >= 3.0.0 - libconfi >= 0.5.0]) + libzakconfi >= 0.10.0]) AC_SUBST(GCONFI_CFLAGS) AC_SUBST(GCONFI_LIBS) @@ -29,6 +38,20 @@ AC_SUBST(GCONFI_LIBS) # Checks for library functions. +dnl ****************************** +dnl Check for Operating System +dnl ****************************** + +platform_win32=no + +case "$host" in +*-mingw*) + platform_win32=yes + ;; +esac + +AM_CONDITIONAL(PLATFORM_WIN32, [test $platform_win32 = yes]) + AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/main.c b/src/main.c index f418aaf..3d9f630 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2014 Andrea Zagli + * Copyright (C) 2005-2016 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,15 +16,21 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H + #include +#endif + #include +#include + #include #include #include #include #include -#include +#include enum { @@ -111,14 +117,14 @@ static void fill_trFolders_Keys (GNode *node, GtkTreeIter parent) { GtkTreeIter child; - ConfiKey *ck; + ZakConfiKey *ck; if (node == NULL) return; node = node->children; while (node != NULL) { - ck = (ConfiKey *)node->data; + ck = (ZakConfiKey *)node->data; gtk_tree_store_append (storeFolders, &child, &parent); gtk_tree_store_set (storeFolders, &child, @@ -140,24 +146,23 @@ fill_trFolders (const gchar *cnc_string, const gchar *filter) { gboolean ret = FALSE; - GList *lstConfigs = confi_get_configs_list (cnc_string, filter); + GList *lstConfigs = zak_confi_get_configs_list (cnc_string, filter); gtk_tree_store_clear (storeFolders); if (lstConfigs != NULL) { GtkTreeIter iter; - Confi *confi; - GdaDataModel *dmKeys; + ZakConfi *confi; gint id; gchar *name; gchar *description; GNode *tree; lstConfigs = g_list_first (lstConfigs); - while (lstConfigs && IS_CONFI (lstConfigs->data)) + while (lstConfigs && ZAK_IS_CONFI (lstConfigs->data)) { - confi = (Confi *)lstConfigs->data; + confi = (ZakConfi *)lstConfigs->data; g_object_get (G_OBJECT (confi), "id_config", &id, @@ -173,7 +178,7 @@ fill_trFolders (const gchar *cnc_string, const gchar *filter) FOLDERS_COL_OBJPTR, confi, -1); - tree = confi_get_tree (confi); + tree = zak_confi_get_tree (confi); if (tree != NULL) { fill_trFolders_Keys (tree, iter); @@ -223,7 +228,7 @@ view_trFolders_popup_menu (GdkEventButton *event) g_signal_connect (G_OBJECT (mnuitem), "activate", G_CALLBACK (on_mnuKeysEdit_activate), NULL); } - + mnuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), mnuitem); if (gtk_tree_path_get_depth (path) == 1) @@ -237,9 +242,9 @@ view_trFolders_popup_menu (GdkEventButton *event) G_CALLBACK (on_mnuKeysDelete_activate), NULL); } } - + gtk_widget_show_all (menu); - + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, (event != NULL) ? event->button : 0, gdk_event_get_time ((GdkEvent*)event)); @@ -247,17 +252,17 @@ view_trFolders_popup_menu (GdkEventButton *event) } static void -save_key_to_xml (Confi *confi, xmlNodePtr xnodeParent, GNode *node) +save_key_to_xml (ZakConfi *confi, xmlNodePtr xnodeParent, GNode *node) { xmlNodePtr xnodeChild; - ConfiKey *ck; + ZakConfiKey *ck; if (node == NULL) return; node = node->children; while (node != NULL) { - ck = (ConfiKey *)node->data; + ck = (ZakConfiKey *)node->data; xnodeChild = xmlNewNode (NULL, (xmlChar *)"gconfi-key"); xmlAddChild (xnodeParent, xnodeChild); @@ -272,7 +277,7 @@ save_key_to_xml (Confi *confi, xmlNodePtr xnodeParent, GNode *node) } static void -save_configuration_to_xml (Confi *confi, xmlNodePtr xroot) +save_configuration_to_xml (ZakConfi *confi, xmlNodePtr xroot) { xmlNodePtr xnode; gchar *name; @@ -289,7 +294,7 @@ save_configuration_to_xml (Confi *confi, xmlNodePtr xroot) xmlNewTextChild (xnode, NULL, (xmlChar *)"name", (xmlChar *)name); xmlNewTextChild (xnode, NULL, (xmlChar *)"description", (xmlChar *)description); - GNode *tree = confi_get_tree (confi); + GNode *tree = zak_confi_get_tree (confi); if (tree != NULL) { save_key_to_xml (confi, xnode, tree); @@ -297,14 +302,14 @@ save_configuration_to_xml (Confi *confi, xmlNodePtr xroot) } static void -create_key_from_xml (Confi *confi, +create_key_from_xml (ZakConfi *confi, const gchar *pathParent, GtkTreeIter *iterParent, xmlNode *xnode, xmlXPathContextPtr xpcontext) { xmlXPathObjectPtr xpresult; - ConfiKey *ck; + ZakConfiKey *ck; xpcontext->node = xnode; @@ -316,7 +321,7 @@ create_key_from_xml (Confi *confi, { GtkTreeIter iter; - ck = confi_add_key (confi, pathParent, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); + 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)) @@ -326,10 +331,10 @@ create_key_from_xml (Confi *confi, { ck->description = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); - confi_key_set_key (confi, ck); + zak_confi_key_set_key (confi, ck); } } - + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::value", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) { @@ -338,7 +343,7 @@ create_key_from_xml (Confi *confi, { ck->value = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); - confi_key_set_key (confi, ck); + zak_confi_key_set_key (confi, ck); } } @@ -350,7 +355,7 @@ create_key_from_xml (Confi *confi, FOLDERS_COL_DESCRIPTION, ck->description, FOLDERS_COL_OBJPTR, ck, -1); - + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gconfi-key", xpcontext); if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) { @@ -373,7 +378,7 @@ static void create_config_from_xml (xmlNode *xnode, xmlXPathContextPtr xpcontext) { xmlXPathObjectPtr xpresult; - Confi *confi; + ZakConfi *confi; xpcontext->node = xnode; @@ -383,9 +388,8 @@ create_config_from_xml (xmlNode *xnode, xmlXPathContextPtr xpcontext) xmlNodeSetPtr xnodeset = xpresult->nodesetval; if (xnodeset->nodeNr == 1) { - - confi = confi_new (cnc_string, - (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), NULL, TRUE); + + confi = zak_confi_new (cnc_string); if (confi != NULL) { GtkTreeIter iter; @@ -448,14 +452,14 @@ load_xml_configuration_schema (const gchar *filename) g_warning ("Error on xmlXIncludeProcess.\n"); return; } - + xmlXPathContextPtr xpcontext = xmlXPathNewContext (xdoc); if (xpcontext != NULL) { xmlNode *xnode = xmlDocGetRootElement (xdoc); if (xnode != NULL) { - if (strcmp (xnode->name, "gconfi") == 0) + if (g_strcmp0 ((gchar *)xnode->name, "gconfi") == 0) { xnode = xnode->children; while (xnode != NULL) @@ -464,15 +468,15 @@ load_xml_configuration_schema (const gchar *filename) { create_config_from_xml (xnode, xpcontext); } - + xnode = xnode->next; } } - else if (strcmp (xnode->name, "gconfi-configuration") == 0) + else if (g_strcmp0 ((gchar *)xnode->name, "gconfi-configuration") == 0) { create_config_from_xml (xnode, xpcontext); } - else if (strcmp (xnode->name, "gconfi-key") == 0) + else if (g_strcmp0 ((gchar *)xnode->name, "gconfi-key") == 0) { GtkTreeIter iter; @@ -483,8 +487,8 @@ load_xml_configuration_schema (const gchar *filename) { if (gtk_tree_path_get_depth (path) == 1) { - Confi *confi; - + ZakConfi *confi; + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, FOLDERS_COL_OBJPTR, &confi, -1); @@ -498,8 +502,8 @@ load_xml_configuration_schema (const gchar *filename) 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))) { - Confi *confi; - ConfiKey *ck; + ZakConfi *confi; + ZakConfiKey *ck; gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi, FOLDERS_COL_OBJPTR, &confi, @@ -508,8 +512,8 @@ load_xml_configuration_schema (const gchar *filename) gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, FOLDERS_COL_OBJPTR, &ck, -1); - - if (IS_CONFI (confi)) + + if (ZAK_IS_CONFI (confi)) { create_key_from_xml (confi, g_strconcat (ck->path, "/", ck->key, NULL), &iter, xnode, xpcontext); } @@ -569,7 +573,7 @@ on_mnuDbNew_activate (GtkMenuItem *menuitem, if (gdaConn == NULL) { /* TO DO */ - g_fprintf(stderr,"error on first connection\n"); + g_fprintf (stderr,"error on first connection\n"); } else { @@ -638,7 +642,7 @@ on_mnuDbNew_activate (GtkMenuItem *menuitem, " CONSTRAINT values_name_unique UNIQUE (id_configs, id_parent, %ckey%c)" ")", chrquot, chrquot, chrquot, chrquot, chrquot, chrquot); - + if (gdaex_execute (gdao, sql) == -1) { /* TO DO */ @@ -652,7 +656,7 @@ on_mnuDbNew_activate (GtkMenuItem *menuitem, gtk_widget_set_sensitive (mnuDbRefresh, TRUE); gtk_widget_set_sensitive (mnuConfigs, TRUE); gtk_widget_set_sensitive (mnuKeys, TRUE); - + gtk_statusbar_pop (GTK_STATUSBAR (stbar), 0); gtk_statusbar_push (GTK_STATUSBAR (stbar), 0, g_strconcat ("Connection string: ", cnc_string, NULL)); @@ -748,12 +752,11 @@ on_mnuConfigsNew_activate (GtkMenuItem *menuitem, { GtkWidget *txtName; GtkWidget *txtvDescription; - GtkWidget *fcbSchema; GtkTextBuffer *buffer; GtkTextIter iter1, iter2; gchar *name; gchar *description; - Confi *confi; + ZakConfi *confi; txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName")); txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription")); @@ -764,9 +767,7 @@ on_mnuConfigsNew_activate (GtkMenuItem *menuitem, gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); - confi = confi_new (cnc_string, - name, - NULL, TRUE); + confi = zak_confi_new (cnc_string); if (confi != NULL) { GtkTreeIter iter; @@ -824,7 +825,7 @@ on_mnuConfigsEdit_activate (GtkMenuItem *menuitem, GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); if (path != NULL && gtk_tree_path_get_depth (path) == 1) { - Confi *confi; + ZakConfi *confi; GError *error = NULL; gtk_builder_add_objects_from_file (glaMain, @@ -892,12 +893,12 @@ on_mnuConfigsDelete_activate (GtkMenuItem *menuitem, GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); if (path != NULL && gtk_tree_path_get_depth (path) == 1) { - Confi *confi; - + ZakConfi *confi; + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, FOLDERS_COL_OBJPTR, &confi, -1); - if (IS_CONFI (confi)) + if (ZAK_IS_CONFI (confi)) { GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, @@ -906,12 +907,12 @@ on_mnuConfigsDelete_activate (GtkMenuItem *menuitem, "Are you sure you want to delete the selected configuration from database?"); if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_YES) { - if (confi_remove (confi)) + if (zak_confi_remove (confi)) { gtk_tree_store_remove (storeFolders, &iter); } } - + gtk_widget_destroy (diag); } } @@ -931,7 +932,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem, if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_ACCEPT) { - Confi *confi; + ZakConfi *confi; gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (diag)); GtkTreeIter iter; @@ -948,7 +949,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem, gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, FOLDERS_COL_OBJPTR, &confi, -1); - if (IS_CONFI (confi)) + if (ZAK_IS_CONFI (confi)) { xmlDocPtr xdoc; xmlNodePtr xnode; @@ -967,7 +968,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem, else { /* saving all configurations */ - GList *configs = confi_get_configs_list (cnc_string, filter); + GList *configs = zak_confi_get_configs_list (cnc_string, filter); if (configs != NULL) { xmlDocPtr xdoc; @@ -980,7 +981,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem, configs = g_list_first (configs); while (configs != NULL) { - confi = (Confi *)configs->data; + confi = (ZakConfi *)configs->data; save_configuration_to_xml (confi, xnode); @@ -990,7 +991,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem, xmlSaveFile (filename, xdoc); } } - + g_free (filename); } @@ -1008,8 +1009,8 @@ on_mnuKeysNew_activate (GtkMenuItem *menuitem, GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); if (path != NULL) { - Confi *confi; - ConfiKey *ck; + ZakConfi *confi; + ZakConfiKey *ck; GError *error = NULL; gtk_builder_add_objects_from_file (glaMain, @@ -1067,7 +1068,6 @@ on_mnuKeysNew_activate (GtkMenuItem *menuitem, GtkTextIter iter1, iter2; GtkTreeIter parent = iter; - gint id; gchar *name = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtName)); gchar *value = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtValue)); gchar *description; @@ -1076,12 +1076,12 @@ on_mnuKeysNew_activate (GtkMenuItem *menuitem, gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); - ck = confi_add_key (confi, keyPath, name); + ck = zak_confi_add_key (confi, keyPath, name, NULL); if (ck != NULL) { ck->value = value; ck->description = description; - confi_key_set_key (confi, ck); + zak_confi_key_set_key (confi, ck); gtk_tree_store_append (storeFolders, &iter, &parent); gtk_tree_store_set (storeFolders, &iter, @@ -1130,7 +1130,7 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem, GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); if (path != NULL && gtk_tree_path_get_depth (path) > 1) { - Confi *confi; + ZakConfi *confi; GError *error = NULL; gtk_builder_add_objects_from_file (glaMain, @@ -1149,7 +1149,7 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem, GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription")); GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription)); - ConfiKey *ck; + ZakConfiKey *ck; GtkTreeIter iterConfi; GtkTreeIter iterParent; @@ -1166,7 +1166,7 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem, g_object_get (G_OBJECT (confi), "name", &name, NULL); - + gtk_entry_set_text (GTK_ENTRY (txtConfig), name); } @@ -1185,7 +1185,7 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem, if (ck->id_parent > 0 && gtk_tree_model_iter_parent (GTK_TREE_MODEL (storeFolders), &iterParent, &iter)) { - ConfiKey *ckParent; + ZakConfiKey *ckParent; gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterParent, FOLDERS_COL_OBJPTR, &ckParent, @@ -1205,7 +1205,7 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem, gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); ck->description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); - confi_key_set_key (confi, ck); + zak_confi_key_set_key (confi, ck); gtk_tree_store_set (storeFolders, &iter, FOLDERS_COL_NAME, ck->key, @@ -1239,7 +1239,7 @@ on_mnuKeysDelete_activate (GtkMenuItem *menuitem, "Are you sure you want to delete the selected key from database?"); if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_YES) { - Confi *confi; + ZakConfi *confi; GtkTreeIter iterConfig; gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfig, @@ -1249,21 +1249,21 @@ on_mnuKeysDelete_activate (GtkMenuItem *menuitem, FOLDERS_COL_OBJPTR, &confi, -1); - if (IS_CONFI (confi)) + if (ZAK_IS_CONFI (confi)) { - ConfiKey *ck; + ZakConfiKey *ck; gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, FOLDERS_COL_OBJPTR, &ck, -1); - if (confi_remove_path (confi, g_strconcat (ck->path, "/", ck->key, NULL))) + if (zak_confi_remove_path (confi, g_strconcat (ck->path, "/", ck->key, NULL))) { gtk_tree_store_remove (storeFolders, &iter); } } } - + gtk_widget_destroy (diag); } } @@ -1357,7 +1357,7 @@ on_trFolders_row_activated (GtkTreeView *tree_view, int main (int argc, char **argv) { - GOptionEntry entries[] = + GOptionEntry entries[] = { { "cnc_string", 'c', 0, G_OPTION_ARG_STRING, &cnc_string, "Connection string", NULL }, { "filter", 'f', 0, G_OPTION_ARG_STRING, &filter, "Configurations filter", NULL }, -- 2.49.0