]> saetta.ns0.it Git - zakconfi/gui/commitdiff
Editing config.
authorAndrea Zagli <azagli@libero.it>
Wed, 28 Sep 2016 13:34:26 +0000 (15:34 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 28 Sep 2016 16:38:46 +0000 (18:38 +0200)
src/main.c

index d775f870c35f60ab77516bcebbcaf2be72e9917f..81dbcbe2a09ca29bc354a9b8a5a7a7f2906aa7c2 100644 (file)
@@ -148,7 +148,7 @@ fill_trFolders (const gchar *filter)
 {
        gboolean ret = FALSE;
 
-       GList *lstConfigs = zak_confi_get_configs_list (confi, filter);
+       GList *lstConfigs = zak_confi_get_configs_list (cnc_string, filter);
 
        gtk_tree_store_clear (storeFolders);
 
@@ -551,10 +551,7 @@ on_mnuDbOpen_activate (GtkMenuItem *menuitem,
                                {
                                        filter = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtConfigsFilter));
 
-                                       confi = zak_confi_new (cnc_string);
-
-                                       if (confi != NULL
-                                               && fill_trFolders (filter))
+                                       if (fill_trFolders (filter))
                                                {
                                                        gtk_widget_set_sensitive (mnuDbClose, TRUE);
                                                        gtk_widget_set_sensitive (mnuDbRefresh, TRUE);
@@ -630,7 +627,7 @@ on_mnuConfigsNew_activate (GtkMenuItem *menuitem,
                        gtk_text_buffer_get_bounds (buffer, &iter1, &iter2);
                        description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE);
 
-                       conficonfi = zak_confi_add_config (confi, name, description);
+                       conficonfi = zak_confi_add_config (cnc_string, name, description);
                        if (conficonfi != NULL)
                                {
                                        gtk_tree_store_append (storeFolders, &iter, NULL);
@@ -655,8 +652,6 @@ 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)
                                {
-                                       ZakConfi *confi;
-
                                        GError *error = NULL;
 
                                        gtk_builder_add_objects_from_file (glaMain,
@@ -665,45 +660,40 @@ on_mnuConfigsEdit_activate (GtkMenuItem *menuitem,
                                                                           &error);
 
                                        GtkWidget *diag = GTK_WIDGET (gtk_builder_get_object (glaMain, "wConfiguration"));
-                                       GtkWidget *txtID = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtID"));
                                        GtkWidget *txtName = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtName"));
                                        GtkWidget *txtvDescription = GTK_WIDGET (gtk_builder_get_object (glaMain, "txtvDescription"));
                                        GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription));
 
-                                       gint id;
                                        gchar *name;
                                        gchar *description;
 
                                        gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter,
+                                                                               FOLDERS_COL_KEY, &name,
+                                                                               FOLDERS_COL_DESCRIPTION, &description,
                                                            -1);
 
-                                       g_object_get (G_OBJECT (confi),
-                                                     "id_config", &id,
-                                                     "name", &name,
-                                                     "description", &description,
-                                                     NULL);
-
-                                       gtk_entry_set_text (GTK_ENTRY (txtID), g_strdup_printf ("%d", id));
                                        gtk_entry_set_text (GTK_ENTRY (txtName), name);
-                                       gtk_text_buffer_set_text (buffer, description, strlen (description));
+                                       gtk_text_buffer_set_text (buffer, description, -1);
 
                                        if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK)
                                                {
+                                                       ZakConfi *confi;
                                                        GtkTextIter iter1, iter2;
 
-                                                       name = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtName)));
-                                                       gtk_text_buffer_get_bounds (buffer, &iter1, &iter2);
-                                                       description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE);
+                                                       confi = zak_confi_new (g_strdup_printf ("%s;CONFI_NAME=%s", cnc_string, name));
+                                                       if (confi != NULL)
+                                                               {
+                                                                       name = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtName)));
+                                                                       gtk_text_buffer_get_bounds (buffer, &iter1, &iter2);
+                                                                       description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE);
 
-                                                       g_object_set (G_OBJECT (confi),
-                                                                     "name", name,
-                                                                     "description", description,
-                                                                     NULL);
+                                                                       zak_confi_set_config (confi, name, description);
 
-                                                       gtk_tree_store_set (storeFolders, &iter,
-                                                                           FOLDERS_COL_KEY, name,
-                                                                           FOLDERS_COL_DESCRIPTION, description,
-                                                                           -1);
+                                                                       gtk_tree_store_set (storeFolders, &iter,
+                                                                                                               FOLDERS_COL_KEY, name,
+                                                                                                               FOLDERS_COL_DESCRIPTION, description,
+                                                                                                               -1);
+                                                               }
                                                }
 
                                        gtk_widget_destroy (diag);
@@ -795,7 +785,7 @@ on_mnuConfigsExport_activate (GtkMenuItem *menuitem,
                        else
                                {
                                        /* saving all configurations */
-                                       GList *configs = zak_confi_get_configs_list (confi, filter);
+                                       GList *configs = zak_confi_get_configs_list (cnc_string, filter);
                                        if (configs != NULL)
                                                {
                                                        xmlDocPtr xdoc;
@@ -1168,6 +1158,8 @@ main (int argc, char **argv)
        GOptionContext *context;
        GError *error;
 
+       cnc_string = NULL;
+
        gtk_init (&argc, &argv);
 
 #ifdef G_OS_WIN32