[gnome-builder: 105/139] newcomers: port to libide-greeter



commit 691275edf62f3e3358742437307c5d75b6a39465
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:30:40 2019 -0800

    newcomers: port to libide-greeter

 src/plugins/newcomers/gbp-newcomers-project.c  |   3 +-
 src/plugins/newcomers/gbp-newcomers-section.c  | 104 +++++++++++++++++++++----
 src/plugins/newcomers/gbp-newcomers-section.ui |   3 +-
 src/plugins/newcomers/meson.build              |  21 +++--
 src/plugins/newcomers/newcomers-plugin.c       |  10 ++-
 src/plugins/newcomers/newcomers.gresource.xml  |   5 +-
 src/plugins/newcomers/newcomers.plugin         |  11 +--
 7 files changed, 113 insertions(+), 44 deletions(-)
---
diff --git a/src/plugins/newcomers/gbp-newcomers-project.c b/src/plugins/newcomers/gbp-newcomers-project.c
index 07a2fcfb6..4d9f8154c 100644
--- a/src/plugins/newcomers/gbp-newcomers-project.c
+++ b/src/plugins/newcomers/gbp-newcomers-project.c
@@ -174,8 +174,7 @@ gbp_newcomers_project_class_init (GbpNewcomersProjectClass *klass)
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
-  gtk_widget_class_set_template_from_resource (widget_class,
-                                               
"/org/gnome/builder/plugins/newcomers-plugin/gbp-newcomers-project.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/newcomers/gbp-newcomers-project.ui");
   gtk_widget_class_bind_template_child (widget_class, GbpNewcomersProject, label);
   gtk_widget_class_bind_template_child (widget_class, GbpNewcomersProject, icon);
   gtk_widget_class_bind_template_child (widget_class, GbpNewcomersProject, tags_box);
diff --git a/src/plugins/newcomers/gbp-newcomers-section.c b/src/plugins/newcomers/gbp-newcomers-section.c
index 0351ca1c1..3de236be2 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.c
+++ b/src/plugins/newcomers/gbp-newcomers-section.c
@@ -20,7 +20,8 @@
 
 #define G_LOG_DOMAIN "gbp-newcomers-section"
 
-#include <ide.h>
+#include <libide-greeter.h>
+#include <libide-vcs.h>
 
 #include "gbp-newcomers-project.h"
 #include "gbp-newcomers-section.h"
@@ -31,6 +32,13 @@ struct _GbpNewcomersSection
   GtkFlowBox *flowbox;
 };
 
+typedef struct
+{
+  GbpNewcomersSection *self;
+  GbpNewcomersProject *project;
+  guint                mode;
+} DelayedActivate;
+
 enum {
   PROP_0,
   PROP_HAS_SELECTION,
@@ -40,6 +48,17 @@ enum {
 static void gbp_newcomers_section_child_activated (GbpNewcomersSection *self,
                                                    GbpNewcomersProject *project,
                                                    GtkFlowBox          *flowbox);
+
+static void
+delayed_activate_free (gpointer data)
+{
+  DelayedActivate *state = data;
+
+  g_clear_object (&state->self);
+  g_clear_object (&state->project);
+  g_slice_free (DelayedActivate, state);
+}
+
 static gint
 gbp_newcomers_section_get_priority (IdeGreeterSection *section)
 {
@@ -156,30 +175,77 @@ G_DEFINE_TYPE_WITH_CODE (GbpNewcomersSection, gbp_newcomers_section, GTK_TYPE_BI
                          G_IMPLEMENT_INTERFACE (IDE_TYPE_GREETER_SECTION,
                                                 greeter_section_iface_init))
 
-static void
-gbp_newcomers_section_child_activated (GbpNewcomersSection *self,
-                                       GbpNewcomersProject *project,
-                                       GtkFlowBox          *flowbox)
+static gboolean
+clear_selection_from_timeout (gpointer data)
+{
+  GbpNewcomersSection *self = data;
+
+  g_assert (GBP_IS_NEWCOMERS_SECTION (self));
+
+  if (self->flowbox != NULL)
+    gtk_flow_box_selected_foreach (self->flowbox,
+                                   (GtkFlowBoxForeachFunc)gtk_flow_box_unselect_child,
+                                   NULL);
+
+  return G_SOURCE_REMOVE;
+}
+
+static gboolean
+do_selection_from_timeout (gpointer data)
 {
+  DelayedActivate *state = data;
   g_autoptr(IdeProjectInfo) project_info = NULL;
-  g_autoptr(IdeVcsUri) vcs_uri = NULL;
   const gchar *name;
   const gchar *uri;
 
-  g_assert (GBP_IS_NEWCOMERS_SECTION (self));
-  g_assert (GBP_IS_NEWCOMERS_PROJECT (project));
-  g_assert (GTK_IS_FLOW_BOX (flowbox));
+  g_assert (state != NULL);
+  g_assert (GBP_IS_NEWCOMERS_SECTION (state->self));
+  g_assert (GBP_IS_NEWCOMERS_PROJECT (state->project));
 
-  name = gbp_newcomers_project_get_name (project);
-  uri = gbp_newcomers_project_get_uri (project);
-  vcs_uri = ide_vcs_uri_new (uri);
+  name = gbp_newcomers_project_get_name (state->project);
+  uri = gbp_newcomers_project_get_uri (state->project);
 
   project_info = g_object_new (IDE_TYPE_PROJECT_INFO,
-                               "vcs-uri", vcs_uri,
+                               "vcs-uri", uri,
                                "name", name,
                                NULL);
 
-  ide_greeter_section_emit_project_activated (IDE_GREETER_SECTION (self), project_info);
+  ide_greeter_section_emit_project_activated (IDE_GREETER_SECTION (state->self),
+                                              project_info);
+
+  g_timeout_add_full (G_PRIORITY_HIGH,
+                      300,
+                      clear_selection_from_timeout,
+                      g_object_ref (state->self),
+                      g_object_unref);
+
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+gbp_newcomers_section_child_activated (GbpNewcomersSection *self,
+                                       GbpNewcomersProject *project,
+                                       GtkFlowBox          *flowbox)
+{
+  DelayedActivate *state;
+
+  g_assert (GBP_IS_NEWCOMERS_SECTION (self));
+  g_assert (GBP_IS_NEWCOMERS_PROJECT (project));
+  g_assert (GTK_IS_FLOW_BOX (flowbox));
+
+  state = g_slice_new0 (DelayedActivate);
+  state->self = g_object_ref (self);
+  state->project = g_object_ref (project);
+
+  /* Delay the selection for just a moment so the user can actually
+   * see what selection they made.
+   */
+  g_timeout_add_full (G_PRIORITY_HIGH,
+                      150,
+                      do_selection_from_timeout,
+                      g_steal_pointer (&state),
+                      delayed_activate_free);
 }
 
 static void
@@ -214,10 +280,8 @@ gbp_newcomers_section_class_init (GbpNewcomersSectionClass *klass)
                                                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
   gtk_widget_class_set_css_name (widget_class, "newcomers");
-  gtk_widget_class_set_template_from_resource (widget_class,
-                                               
"/org/gnome/builder/plugins/newcomers-plugin/gbp-newcomers-section.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/newcomers/gbp-newcomers-section.ui");
   gtk_widget_class_bind_template_child (widget_class, GbpNewcomersSection, flowbox);
-  gtk_widget_class_bind_template_callback (widget_class, gbp_newcomers_section_child_activated);
 
   g_type_ensure (GBP_TYPE_NEWCOMERS_PROJECT);
 }
@@ -226,4 +290,10 @@ static void
 gbp_newcomers_section_init (GbpNewcomersSection *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  g_signal_connect_object (self->flowbox,
+                           "child-activated",
+                           G_CALLBACK (gbp_newcomers_section_child_activated),
+                           self,
+                           G_CONNECT_SWAPPED | G_CONNECT_AFTER);
 }
diff --git a/src/plugins/newcomers/gbp-newcomers-section.ui b/src/plugins/newcomers/gbp-newcomers-section.ui
index d18c510cf..6947026ee 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.ui
+++ b/src/plugins/newcomers/gbp-newcomers-section.ui
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="GbpNewcomersSection" parent="GtkBin">
+    <property name="halign">center</property>
+    <property name="hexpand">true</property>
     <child>
       <object class="GtkBox">
         <property name="orientation">vertical</property>
@@ -26,7 +28,6 @@
             <property name="selection-mode">browse</property>
             <property name="min-children-per-line">3</property>
             <property name="max-children-per-line">5</property>
-            <signal name="child-activated" handler="gbp_newcomers_section_child_activated" swapped="true" 
object="GbpNewcomersSection"/>
             <child>
               <object class="GbpNewcomersProject">
                 <property name="name" translatable="yes">Polari</property>
diff --git a/src/plugins/newcomers/meson.build b/src/plugins/newcomers/meson.build
index f461394ee..be45e6b45 100644
--- a/src/plugins/newcomers/meson.build
+++ b/src/plugins/newcomers/meson.build
@@ -1,20 +1,17 @@
-if get_option('with_newcomers')
+if get_option('plugin_newcomers')
 
-newcomers_resources = gnome.compile_resources(
+plugins_sources += files([
+  'newcomers-plugin.c',
+  'gbp-newcomers-project.c',
+  'gbp-newcomers-section.c',
+])
+
+plugin_newcomers_resources = gnome.compile_resources(
   'newcomers-resources',
   'newcomers.gresource.xml',
   c_name: 'gbp_newcomers',
 )
 
-newcomers_sources = [
-  'newcomers-plugin.c',
-  'gbp-newcomers-project.c',
-  'gbp-newcomers-project.h',
-  'gbp-newcomers-section.c',
-  'gbp-newcomers-section.h',
-]
-
-gnome_builder_plugins_sources += files(newcomers_sources)
-gnome_builder_plugins_sources += newcomers_resources[0]
+plugins_sources += plugin_newcomers_resources[0]
 
 endif
diff --git a/src/plugins/newcomers/newcomers-plugin.c b/src/plugins/newcomers/newcomers-plugin.c
index bc5b71e6b..6ec9547c8 100644
--- a/src/plugins/newcomers/newcomers-plugin.c
+++ b/src/plugins/newcomers/newcomers-plugin.c
@@ -18,13 +18,17 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#define G_LOG_DOMAIN "newcomers-plugin"
+
+#include "config.h"
+
 #include <libpeas/peas.h>
-#include <ide.h>
+#include <libide-greeter.h>
 
 #include "gbp-newcomers-section.h"
 
-void
-gbp_newcomers_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_gbp_newcomers_register_types (PeasObjectModule *module)
 {
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_GREETER_SECTION,
diff --git a/src/plugins/newcomers/newcomers.gresource.xml b/src/plugins/newcomers/newcomers.gresource.xml
index c0e8b3a45..2ca18ba34 100644
--- a/src/plugins/newcomers/newcomers.gresource.xml
+++ b/src/plugins/newcomers/newcomers.gresource.xml
@@ -1,11 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
 
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/newcomers">
     <file>newcomers.plugin</file>
-  </gresource>
-
-  <gresource prefix="/org/gnome/builder/plugins/newcomers-plugin">
     <file>gbp-newcomers-project.ui</file>
     <file>gbp-newcomers-section.ui</file>
   </gresource>
diff --git a/src/plugins/newcomers/newcomers.plugin b/src/plugins/newcomers/newcomers.plugin
index fe9f44e41..01c297dff 100644
--- a/src/plugins/newcomers/newcomers.plugin
+++ b/src/plugins/newcomers/newcomers.plugin
@@ -1,8 +1,9 @@
 [Plugin]
-Module=newcomers-plugin
-Name=GNOME Newcomers
-Description=Integration with GNOME newcomers initiative
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2017 Christian Hergert
 Builtin=true
-Embedded=gbp_newcomers_register_types
+Copyright=Copyright © 2017-2018 Christian Hergert
+Description=Integration with GNOME newcomers initiative
+Embedded=_gbp_newcomers_register_types
+Module=newcomers
+Depends=greeter;
+Name=GNOME Newcomers


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