[gnome-builder/wip/vim] prefs: load some git config info just for fun



commit e5ca43d8d49eb335f0805743c246867337308c8f
Author: Christian Hergert <christian hergert me>
Date:   Fri Oct 3 03:34:35 2014 -0700

    prefs: load some git config info just for fun

 src/preferences/gb-preferences-window.c |   41 +++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/src/preferences/gb-preferences-window.c b/src/preferences/gb-preferences-window.c
index 64c5e8c..a33fd43 100644
--- a/src/preferences/gb-preferences-window.c
+++ b/src/preferences/gb-preferences-window.c
@@ -16,7 +16,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/*
+ * TODO: We will probably have to split all the preferences stuff out into
+ *       child widgets just to keep things under control.
+ *       Feel free to do that if you beat me to it.
+ */
+
 #include <glib/gi18n.h>
+#include <libgit2-glib/ggit.h>
 
 #include "gb-preferences-window.h"
 #include "gb-sidebar.h"
@@ -27,6 +34,9 @@ struct _GbPreferencesWindowPrivate
   GtkSearchEntry  *search_entry;
   GtkSearchBar    *search_bar;
   GtkStack        *stack;
+
+  GtkEntry        *git_author_name_entry;
+  GtkEntry        *git_author_email_entry;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GbPreferencesWindow, gb_preferences_window,
@@ -68,6 +78,29 @@ gb_preferences_window_section_changed (GtkStack            *stack,
 }
 
 static void
+load_git (GbPreferencesWindow *window)
+{
+  GgitConfig *config;
+  const gchar *value;
+  
+  g_return_if_fail (GB_IS_PREFERENCES_WINDOW (window));
+
+  config = ggit_config_new_default (NULL);
+  if (!config)
+    return;
+
+  value = ggit_config_get_string (config, "user.name", NULL);
+  if (value)
+    gtk_entry_set_text (window->priv->git_author_name_entry, value);
+
+  value = ggit_config_get_string (config, "user.email", NULL);
+  if (value)
+    gtk_entry_set_text (window->priv->git_author_email_entry, value);
+
+  g_object_unref (config);
+}
+
+static void
 gb_preferences_window_constructed (GObject *object)
 {
   GbPreferencesWindow *window = (GbPreferencesWindow *)object;
@@ -82,6 +115,8 @@ gb_preferences_window_constructed (GObject *object)
                     G_CALLBACK (gb_preferences_window_section_changed),
                     window);
   gb_preferences_window_section_changed (window->priv->stack, NULL, window);
+  
+  load_git (window);
 }
 
 static void
@@ -147,6 +182,12 @@ gb_preferences_window_class_init (GbPreferencesWindowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class,
                                                 GbPreferencesWindow,
                                                 stack);
+  gtk_widget_class_bind_template_child_private (widget_class,
+                                                GbPreferencesWindow,
+                                                git_author_name_entry);
+  gtk_widget_class_bind_template_child_private (widget_class,
+                                                GbPreferencesWindow,
+                                                git_author_email_entry);
 
   g_type_ensure (GB_TYPE_SIDEBAR);
 }


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