[gnome-builder/wip/chergert/perspective] prefs: merge version control values to git



commit 20826fda0279416d2d75e9e4fd0723d9926e7594
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 8 01:35:46 2015 -0800

    prefs: merge version control values to git
    
    We want this abstracted long term, but that can wait until VCS is
    abstracted better.

 libide/preferences/ide-preferences-builtin.c |   80 ++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/libide/preferences/ide-preferences-builtin.c b/libide/preferences/ide-preferences-builtin.c
index 898867e..cea01d2 100644
--- a/libide/preferences/ide-preferences-builtin.c
+++ b/libide/preferences/ide-preferences-builtin.c
@@ -18,6 +18,7 @@
 
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
+#include <libgit2-glib/ggit.h>
 #include <libpeas/peas.h>
 
 #include "ide-preferences-builtin.h"
@@ -164,22 +165,101 @@ ide_preferences_builtin_register_snippets (IdePreferences *preferences)
   ide_preferences_add_switch (preferences, "snippets", "completion", "org.gnome.builder.code-insight", 
"snippet-completion", NULL, NULL, _("Code snippets"), _("Use code fragments to increase typing efficiency"), 
NULL, 0);
 }
 
+static gchar *
+read_config_string (GgitConfig   *orig_config,
+                    const gchar  *key,
+                    GError      **error)
+{
+  GgitConfig *config;
+  const gchar *value;
+  gchar *ret;
+
+  g_assert (GGIT_IS_CONFIG (orig_config));
+  g_assert (key != NULL);
+
+  config = ggit_config_snapshot (orig_config, error);
+  if (config == NULL)
+    return NULL;
+
+  value = ggit_config_get_string (config, key, error);
+
+  ret = value ? g_strdup (value) : NULL;
+
+  g_clear_object (&config);
+
+  return ret;
+}
+
+static void
+author_changed_cb (IdePreferencesEntry *entry,
+                   const gchar         *text,
+                   GgitConfig          *config)
+{
+  g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
+  g_assert (text != NULL);
+  g_assert (GGIT_IS_CONFIG (config));
+
+  ggit_config_set_string (config, "user.name", text, NULL);
+}
+
+static void
+email_changed_cb (IdePreferencesEntry *entry,
+                  const gchar         *text,
+                  GgitConfig          *config)
+{
+  g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
+  g_assert (text != NULL);
+  g_assert (GGIT_IS_CONFIG (config));
+
+  ggit_config_set_string (config, "user.email", text, NULL);
+}
+
 static void
 ide_preferences_builtin_register_vcs (IdePreferences *preferences)
 {
+  g_autofree gchar *author_text = NULL;
+  g_autofree gchar *email_text = NULL;
+  g_autoptr(GFile) global_file = NULL;
+  GgitConfig *config;
   GtkWidget *author;
   GtkWidget *email;
 
   ide_preferences_add_page (preferences, "vcs", _("Version Control"), 600);
 
+  if (!(global_file = ggit_config_find_global ()))
+    {
+      g_autofree gchar *path = NULL;
+
+      path = g_build_filename (g_get_home_dir (), ".gitconfig", NULL);
+      global_file = g_file_new_for_path (path);
+    }
+
+  config = ggit_config_new_from_file (global_file, NULL);
+  g_object_set_data_full (G_OBJECT (preferences), "GGIT_CONFIG", config, g_object_unref);
+
+  author_text = read_config_string (config, "user.name", NULL);
   author = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
+                         "text", author_text,
                          "title", "Author",
                          "visible", TRUE,
                          NULL);
+  g_signal_connect_object (author,
+                           "changed",
+                           G_CALLBACK (author_changed_cb),
+                           config,
+                           0);
+
+  email_text = read_config_string (config, "user.email", NULL);
   email = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
+                         "text", email_text,
                         "title", "Email",
                         "visible", TRUE,
                         NULL);
+  g_signal_connect_object (email,
+                           "changed",
+                           G_CALLBACK (email_changed_cb),
+                           config,
+                           0);
 
   ide_preferences_add_list_group (preferences, "vcs", "attribution", _("Attribution"), 0);
   ide_preferences_add_custom (preferences, "vcs", "attribution", author, NULL, 0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]