]> saetta.ns0.it Git - zakconfi/gui/commitdiff
Adding keys to config.
authorAndrea Zagli <azagli@libero.it>
Wed, 28 Sep 2016 19:23:25 +0000 (21:23 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 28 Sep 2016 19:23:25 +0000 (21:23 +0200)
data/zak-confi-gui/ui/zak-confi-gui.ui
src/main.c

index 2e37ba52b80c19f65ac51a51a30e57a1edbe3e5d..f54f7ff2549f86251958edd433c4c57c2006fd36 100644 (file)
     <property name="title" translatable="yes">Key - ZakConfiGUI</property>
     <property name="modal">True</property>
     <property name="window_position">center-on-parent</property>
+    <property name="default_width">320</property>
+    <property name="default_height">260</property>
     <property name="type_hint">dialog</property>
     <property name="transient_for">wMain</property>
     <property name="attached_to">wMain</property>
index f3411d79aa974f1fc44ae16c6065ebbcb1728690..5cad691d649680688df145e81d09b1b060fbb60c 100644 (file)
@@ -86,6 +86,27 @@ create_trFolders ()
 
        gtk_tree_view_set_model (GTK_TREE_VIEW (trFolders), GTK_TREE_MODEL (storeFolders));
 
+       const gchar *show_all_columns = g_getenv ("SHOW_ALL_COLUMNS");
+
+       if (show_all_columns != NULL)
+               {
+                       renderer = gtk_cell_renderer_text_new ();
+                       column = gtk_tree_view_column_new_with_attributes ("Config",
+                                                                                                                          renderer,
+                                                                                                                          "text", FOLDERS_COL_CONFIG,
+                                                                                                                          NULL);
+                       gtk_tree_view_column_set_resizable (column, TRUE);
+                       gtk_tree_view_append_column (GTK_TREE_VIEW (trFolders), column);
+
+                       renderer = gtk_cell_renderer_text_new ();
+                       column = gtk_tree_view_column_new_with_attributes ("Path",
+                                                                                                                          renderer,
+                                                                                                                          "text", FOLDERS_COL_PATH,
+                                                                                                                          NULL);
+                       gtk_tree_view_column_set_resizable (column, TRUE);
+                       gtk_tree_view_append_column (GTK_TREE_VIEW (trFolders), column);
+               }
+
        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Key",
                                                      renderer,
@@ -143,15 +164,13 @@ fill_trFolders_Keys (GNode *node, GtkTreeIter parent)
                                                                -1);
 
 
-                       if (gtk_tree_path_get_depth (tpath) == 0
-                               || g_strcmp0 (path, "") == 0)
+                       if (gtk_tree_path_get_depth (tpath) == 1)
                                {
-                                       g_free (path);
-                                       path = g_strdup ("/");
+                                       path = g_strdup ("");
                                }
                        else
                                {
-                                       path = g_strdup_printf ("%s%s/", path, parent_name);
+                                       path = g_strdup_printf ("%s/%s", path, parent_name);
                                }
 
                        gtk_tree_store_append (storeFolders, &child, &parent);
@@ -858,62 +877,48 @@ on_mnuKeysNew_activate (GtkMenuItem *menuitem,
                        if (path != NULL)
                                {
                                        ZakConfi *confi;
-                                       ZakConfiKey *ck;
 
                                        GError *error = NULL;
+
                                        gtk_builder_add_objects_from_file (glaMain,
                                                                           uifilename,
                                                                           g_strsplit_set ("wKey", "|", -1),
                                                                           &error);
 
                                        GtkWidget *diag = GTK_WIDGET (gtk_builder_get_object (glaMain, "wKey"));
-                                       GtkWidget *txtIDConfig = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtIDConfig"));
+
                                        GtkWidget *txtConfig = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtConfig"));
-                                       GtkWidget *txtID = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtID"));
-                                       GtkWidget *txtIDParent = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtIDParent"));
                                        GtkWidget *txtParent = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtParent"));
-                                       GtkWidget *txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName"));
-                                       GtkWidget *txtValue = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtValue"));
-                                       GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription"));
-                                       GtkTreeIter iterConfi;
-                                       gint id_config;
-                                       gchar *name;
-                                       gchar *keyPath = "";
 
-                                       if (gtk_tree_path_get_depth (path) == 1)
-                                               {
-                                                       iterConfi = iter;
-                                                       gtk_entry_set_text (GTK_ENTRY (txtIDParent), "0");
-                                               }
-                                       else
-                                               {
-                                                       gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfi,
-                                                                                gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1));
+                                       gchar *config;
+                                       gchar *path;
+                                       gchar *parent_name;
 
-                                                       gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter,
-                                                                           -1);
+                                       gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter,
+                                                                               FOLDERS_COL_CONFIG, &config,
+                                                                               FOLDERS_COL_PATH, &path,
+                                                                               FOLDERS_COL_KEY, &parent_name,
+                                                                               -1);
 
-                                                       keyPath = g_strjoin (NULL, ck->path, "/", ck->key, NULL);
-                                                       gtk_entry_set_text (GTK_ENTRY (txtIDParent), ck->path);
-                                                       gtk_entry_set_text (GTK_ENTRY (txtParent), ck->key);
+                                       if (g_strcmp0 (path, "") != 0)
+                                               {
+                                                       path = g_strdup_printf ("%s/%s", path, parent_name);
                                                }
 
-                                       gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi,
-                                                           -1);
-
-                                       g_object_get (G_OBJECT (confi),
-                                                     "id_config", &id_config,
-                                                     "name", &name,
-                                                     NULL);
-
-                                       gtk_entry_set_text (GTK_ENTRY (txtIDConfig), g_strdup_printf ("%d", id_config));
-                                       gtk_entry_set_text (GTK_ENTRY (txtConfig), name);
+                                       gtk_entry_set_text (GTK_ENTRY (txtConfig), config);
+                                       gtk_entry_set_text (GTK_ENTRY (txtParent), path);
 
                                        if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK)
                                                {
+                                                       ZakConfiKey *ck;
+
                                                        GtkTextIter iter1, iter2;
                                                        GtkTreeIter parent = iter;
 
+                                                       GtkWidget *txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName1"));
+                                                       GtkWidget *txtValue = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtValue"));
+                                                       GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription1"));
+
                                                        gchar *name = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtName));
                                                        gchar *value = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtValue));
                                                        gchar *description;
@@ -922,19 +927,28 @@ on_mnuKeysNew_activate (GtkMenuItem *menuitem,
                                                        gtk_text_buffer_get_bounds (buffer, &iter1, &iter2);
                                                        description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE);
 
-                                                       ck = zak_confi_add_key (confi, keyPath, name, NULL);
-                                                       if (ck != NULL)
+                                                       confi = zak_confi_new (g_strdup_printf ("%s;CONFI_NAME=%s", cnc_string, config));
+
+                                                       if (confi != NULL)
                                                                {
-                                                                       ck->value = value;
-                                                                       ck->description = description;
-                                                                       zak_confi_key_set_key (confi, ck);
+                                                                       ck = zak_confi_add_key (confi, path, name, NULL);
+                                                                       if (ck != NULL)
+                                                                               {
+                                                                                       ck->value = g_strdup (value);
+                                                                                       ck->description = g_strdup (description);
+                                                                                       zak_confi_key_set_key (confi, ck);
+
+                                                                                       gtk_tree_store_append (storeFolders, &iter, &parent);
+                                                                                       gtk_tree_store_set (storeFolders, &iter,
+                                                                                                                               FOLDERS_COL_CONFIG, config,
+                                                                                                                               FOLDERS_COL_PATH, path,
+                                                                                                                               FOLDERS_COL_KEY, name,
+                                                                                                                               FOLDERS_COL_VALUE, value,
+                                                                                                                               FOLDERS_COL_DESCRIPTION, description,
+                                                                                                                               -1);
+                                                                               }
 
-                                                                       gtk_tree_store_append (storeFolders, &iter, &parent);
-                                                                       gtk_tree_store_set (storeFolders, &iter,
-                                                                                           FOLDERS_COL_KEY, name,
-                                                                                           FOLDERS_COL_VALUE, value,
-                                                                                           FOLDERS_COL_DESCRIPTION, description,
-                                                                                           -1);
+                                                                       g_object_unref (confi);
                                                                }
                                                }
 
@@ -963,14 +977,11 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem,
                                                                           &error);
 
                                        GtkWidget *diag = GTK_WIDGET (gtk_builder_get_object (glaMain, "wKey"));
-                                       GtkWidget *txtIDConfig = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtIDConfig"));
                                        GtkWidget *txtConfig = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtConfig"));
-                                       GtkWidget *txtID = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtID"));
-                                       GtkWidget *txtIDParent = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtIDParent"));
                                        GtkWidget *txtParent = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtParent"));
-                                       GtkWidget *txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName"));
+                                       GtkWidget *txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName1"));
                                        GtkWidget *txtValue = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtValue"));
-                                       GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription"));
+                                       GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription1"));
                                        GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription));
 
                                        ZakConfiKey *ck;
@@ -998,9 +1009,6 @@ on_mnuKeysEdit_activate (GtkMenuItem *menuitem,
 
                                        if (ck != NULL)
                                                {
-                                                       gtk_entry_set_text (GTK_ENTRY (txtIDConfig), ck->config);
-                                                       gtk_entry_set_text (GTK_ENTRY (txtID), ck->key);
-                                                       gtk_entry_set_text (GTK_ENTRY (txtIDParent), ck->path);
                                                        gtk_entry_set_text (GTK_ENTRY (txtName), ck->key);
                                                        gtk_entry_set_text (GTK_ENTRY (txtValue), ck->value);
                                                        gtk_text_buffer_set_text (buffer, ck->description, strlen (ck->description));