[gnome-builder] template: get author name from IdeVcsConfig



commit 9fa16fc96679c3a6c0bc54ff76a3f18ef6d41c3e
Author: Akshaya Kakkilaya <akshaya kakkilaya gmail com>
Date:   Sat May 28 22:47:33 2016 +0530

    template: get author name from IdeVcsConfig

 libide/template/ide-template-base.c                |    3 --
 .../autotools_templates/__init__.py                |    4 ++
 plugins/create-project/gbp-create-project-widget.c |   38 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/libide/template/ide-template-base.c b/libide/template/ide-template-base.c
index ad0ae15..b101038 100644
--- a/libide/template/ide-template-base.c
+++ b/libide/template/ide-template-base.c
@@ -636,9 +636,6 @@ create_scope (IdeTemplateBase *self,
   filename = g_file_get_basename (destination);
   tmpl_symbol_assign_string (symbol, filename);
 
-  symbol = tmpl_scope_get (scope, "author");
-  tmpl_symbol_assign_string (symbol, g_get_real_name ());
-
   now = g_date_time_new_now_local ();
   year = g_date_time_format (now, "%Y");
   symbol = tmpl_scope_get (scope, "year");
diff --git a/plugins/autotools-templates/autotools_templates/__init__.py 
b/plugins/autotools-templates/autotools_templates/__init__.py
index b832516..3ec1e23 100644
--- a/plugins/autotools-templates/autotools_templates/__init__.py
+++ b/plugins/autotools-templates/autotools_templates/__init__.py
@@ -115,6 +115,8 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
                                          self.language))
             return
 
+        author_name = params['author'].get_string()
+
         directory = Gio.File.new_for_path(dir_path)
 
         scope = Template.Scope.new()
@@ -148,6 +150,8 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
         scope.get('translation_copyright').assign_string('Translation copyright holder')
         scope.get('language').assign_string(self.language)
 
+        scope.get('author').assign_string(author_name)
+
         self.prepare_scope(scope)
 
         expands = {
diff --git a/plugins/create-project/gbp-create-project-widget.c 
b/plugins/create-project/gbp-create-project-widget.c
index 01a5b54..b8611ce 100644
--- a/plugins/create-project/gbp-create-project-widget.c
+++ b/plugins/create-project/gbp-create-project-widget.c
@@ -601,15 +601,21 @@ gbp_create_project_widget_create_async (GbpCreateProjectWidget *self,
   g_autoptr(GTask) task = NULL;
   g_autoptr(GHashTable) params = NULL;
   g_autoptr(IdeProjectTemplate) template = NULL;
+  g_autoptr(IdeVcsConfig) vcs_conf = NULL;
+  GValue str = G_VALUE_INIT;
   g_autofree gchar *name = NULL;
   g_autofree gchar *location = NULL;
   g_autofree gchar *path = NULL;
   g_autofree gchar *language = NULL;
   GtkFlowBoxChild *template_container;
   GbpCreateProjectTemplateIcon *template_icon;
+  PeasEngine *engine;
+  PeasPluginInfo *plugin_info;
   const gchar *text;
   const gchar *child_name;
   const gchar *license_id;
+  const gchar *vcs_id;
+  const gchar *author_name;
   GList *selected_box_child;
 
   g_return_if_fail (GBP_CREATE_PROJECT_WIDGET (self));
@@ -670,6 +676,38 @@ gbp_create_project_widget_create_async (GbpCreateProjectWidget *self,
                            g_variant_ref_sink (g_variant_new_string (license_short_path)));
     }
 
+  vcs_id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (self->versioning_chooser));
+
+  if (vcs_id != NULL)
+    {
+      engine = peas_engine_get_default ();
+      plugin_info = peas_engine_get_plugin_info (engine, vcs_id);
+
+      if (plugin_info != NULL)
+        {
+          vcs_conf = (IdeVcsConfig *)peas_engine_create_extension (engine, plugin_info,
+                                                                   IDE_TYPE_VCS_CONFIG,
+                                                                   NULL);
+
+          if (vcs_conf != NULL)
+            {
+              g_value_init (&str, G_TYPE_STRING);
+              ide_vcs_config_get_config (vcs_conf, IDE_VCS_CONFIG_FULL_NAME, &str);
+            }
+        }
+    }
+
+  if (G_VALUE_HOLDS_STRING (&str) && !ide_str_empty0 (g_value_get_string (&str)))
+    author_name = g_value_get_string (&str);
+  else
+    author_name = g_get_real_name ();
+
+  g_hash_table_insert (params,
+                       g_strdup ("author"),
+                       g_variant_ref_sink (g_variant_new_string (author_name)));
+
+  g_value_unset (&str);
+
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_task_data (task, g_file_new_for_path (path), g_object_unref);
 


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