[gnome-builder: 106/139] notification: port to IdeNotification



commit a1de0d10b1ad017add128ceef7e96d6bbff784ee
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:31:12 2019 -0800

    notification: port to IdeNotification
    
    This ports the notifications plugin to use libide-core and libide-foundry
    to track build status and provide notifications to the user.

 src/plugins/notification/ide-notification-addin.c  | 68 +++++++++++++++++-----
 src/plugins/notification/ide-notification-addin.h  |  2 +-
 src/plugins/notification/meson.build               | 20 +++----
 ...notification-plugin.c => notification-plugin.c} | 12 ++--
 .../notification/notification.gresource.xml        |  2 +-
 src/plugins/notification/notification.plugin       | 11 ++--
 6 files changed, 78 insertions(+), 37 deletions(-)
---
diff --git a/src/plugins/notification/ide-notification-addin.c 
b/src/plugins/notification/ide-notification-addin.c
index a4aa2d137..0d0718607 100644
--- a/src/plugins/notification/ide-notification-addin.c
+++ b/src/plugins/notification/ide-notification-addin.c
@@ -22,6 +22,7 @@
 
 #include <glib/gi18n.h>
 #include <gio/gio.h>
+#include <libide-foundry.h>
 
 #include "ide-notification-addin.h"
 
@@ -29,10 +30,12 @@
 
 struct _IdeNotificationAddin
 {
-  IdeObject  parent_instance;
-  gchar     *last_msg_body;
-  gint64     last_time;
-  guint      supress : 1;
+  IdeObject        parent_instance;
+  IdeNotification *notif;
+  gchar           *last_msg_body;
+  IdeBuildPhase    requested_phase;
+  gint64           last_time;
+  guint            supress : 1;
 };
 
 static void addin_iface_init (IdeBuildPipelineAddinInterface *iface);
@@ -67,14 +70,13 @@ ide_notification_addin_notify (IdeNotificationAddin *self,
                                gboolean              success)
 {
   g_autofree gchar *msg_body = NULL;
+  g_autofree gchar *project_name = NULL;
   g_autoptr(GNotification) notification = NULL;
   g_autoptr(GIcon) icon = NULL;
   GtkApplication *app;
-  const gchar *project_name;
   const gchar *msg_title;
   const gchar *id;
   IdeContext *context;
-  IdeProject *project;
   GtkWindow *window;
 
   g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
@@ -91,9 +93,8 @@ ide_notification_addin_notify (IdeNotificationAddin *self,
     return;
 
   context = ide_object_get_context (IDE_OBJECT (self));
-  project = ide_context_get_project (context);
-  project_name = ide_project_get_name (project);
-  id = ide_project_get_id (project);
+  project_name = ide_context_dup_title (context);
+  id = ide_context_dup_project_id (context);
 
   if (success)
     {
@@ -119,24 +120,38 @@ ide_notification_addin_notify (IdeNotificationAddin *self,
 
 static void
 ide_notification_addin_build_started (IdeNotificationAddin *self,
-                                      IdeBuildPipeline     *build_pipeline,
+                                      IdeBuildPipeline     *pipeline,
                                       IdeBuildManager      *build_manager)
 {
   IdeBuildPhase phase;
 
   g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
-  g_assert (IDE_IS_BUILD_PIPELINE (build_pipeline));
+  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
   g_assert (IDE_IS_BUILD_MANAGER (build_manager));
 
+  if (self->notif != NULL)
+    {
+      ide_notification_withdraw (self->notif);
+      g_clear_object (&self->notif);
+    }
+
   /* We don't care about any build that is advancing to a phase
    * before the BUILD phase. We advanced to CONFIGURE a lot when
    * extracting build flags.
    */
 
-  phase = ide_build_pipeline_get_requested_phase (build_pipeline);
+  phase = ide_build_pipeline_get_requested_phase (pipeline);
   g_assert ((phase & IDE_BUILD_PHASE_MASK) == phase);
 
+  self->requested_phase = phase;
   self->supress = phase < IDE_BUILD_PHASE_BUILD;
+
+  if (self->requested_phase)
+    {
+      self->notif = ide_notification_new ();
+      g_object_bind_property (pipeline, "message", self->notif, "title", G_BINDING_SYNC_CREATE);
+      ide_notification_attach (self->notif, IDE_OBJECT (self));
+    }
 }
 
 static void
@@ -148,18 +163,35 @@ ide_notification_addin_build_failed (IdeNotificationAddin *self,
   g_assert (IDE_IS_BUILD_PIPELINE (build_pipeline));
   g_assert (IDE_IS_BUILD_MANAGER (build_manager));
 
+  if (self->notif)
+    ide_notification_set_title (self->notif, _("Build failed"));
+
   ide_notification_addin_notify (self, FALSE);
 }
 
 static void
 ide_notification_addin_build_finished (IdeNotificationAddin *self,
-                                       IdeBuildPipeline     *build_pipeline,
+                                       IdeBuildPipeline     *pipeline,
                                        IdeBuildManager      *build_manager)
 {
   g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
-  g_assert (IDE_IS_BUILD_PIPELINE (build_pipeline));
+  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
   g_assert (IDE_IS_BUILD_MANAGER (build_manager));
 
+  if (self->notif)
+    {
+      g_autoptr(GIcon) icon = g_themed_icon_new ("emblem-ok-symbolic");
+
+      if (self->requested_phase & IDE_BUILD_PHASE_BUILD)
+        ide_notification_set_title (self->notif, _("Build succeeded"));
+      else if (self->requested_phase & IDE_BUILD_PHASE_CONFIGURE)
+        ide_notification_set_title (self->notif, _("Build configured"));
+      else if (self->requested_phase & IDE_BUILD_PHASE_AUTOGEN)
+        ide_notification_set_title (self->notif, _("Build bootstrapped"));
+
+      ide_notification_set_icon (self->notif, icon);
+    }
+
   ide_notification_addin_notify (self, TRUE);
 }
 
@@ -177,7 +209,7 @@ ide_notification_addin_load (IdeBuildPipelineAddin *addin,
   context = ide_object_get_context (IDE_OBJECT (addin));
   g_assert (IDE_IS_CONTEXT (context));
 
-  build_manager = ide_context_get_build_manager (context);
+  build_manager = ide_build_manager_from_context (context);
   g_assert (IDE_IS_BUILD_MANAGER (build_manager));
 
   g_signal_connect_object (build_manager,
@@ -208,6 +240,12 @@ ide_notification_addin_unload (IdeBuildPipelineAddin *addin,
   g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
   g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
 
+  if (self->notif != NULL)
+    {
+      ide_notification_withdraw (self->notif);
+      g_clear_object (&self->notif);
+    }
+
   g_clear_pointer (&self->last_msg_body, g_free);
 }
 
diff --git a/src/plugins/notification/ide-notification-addin.h 
b/src/plugins/notification/ide-notification-addin.h
index 7e971b9a7..18832a59c 100644
--- a/src/plugins/notification/ide-notification-addin.h
+++ b/src/plugins/notification/ide-notification-addin.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-core.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/plugins/notification/meson.build b/src/plugins/notification/meson.build
index a30684721..e7d23dcd1 100644
--- a/src/plugins/notification/meson.build
+++ b/src/plugins/notification/meson.build
@@ -1,18 +1,16 @@
-if get_option('with_notification')
+if get_option('plugin_notification')
 
-notification_resources = gnome.compile_resources(
+plugins_sources += files([
+  'notification-plugin.c',
+  'ide-notification-addin.c',
+])
+
+plugin_notification_resources = gnome.compile_resources(
   'notification-resources',
   'notification.gresource.xml',
-  c_name: 'ide_notification',
+  c_name: 'gbp_notification',
 )
 
-notification_sources = [
-  'ide-notification-plugin.c',
-  'ide-notification-addin.c',
-  'ide-notification-addin.h',
-]
-
-gnome_builder_plugins_sources += files(notification_sources)
-gnome_builder_plugins_sources += notification_resources[0]
+plugins_sources += plugin_notification_resources[0]
 
 endif
diff --git a/src/plugins/notification/ide-notification-plugin.c 
b/src/plugins/notification/notification-plugin.c
similarity index 71%
rename from src/plugins/notification/ide-notification-plugin.c
rename to src/plugins/notification/notification-plugin.c
index 43232e1dd..4a53c0afa 100644
--- a/src/plugins/notification/ide-notification-plugin.c
+++ b/src/plugins/notification/notification-plugin.c
@@ -18,13 +18,17 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#include "config.h"
+
 #include <libpeas/peas.h>
-#include <ide.h>
+#include <libide-foundry.h>
 
 #include "ide-notification-addin.h"
 
-void
-ide_notification_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_ide_notification_register_types (PeasObjectModule *module)
 {
-  peas_object_module_register_extension_type (module, IDE_TYPE_BUILD_PIPELINE_ADDIN, 
IDE_TYPE_NOTIFICATION_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_PIPELINE_ADDIN,
+                                              IDE_TYPE_NOTIFICATION_ADDIN);
 }
diff --git a/src/plugins/notification/notification.gresource.xml 
b/src/plugins/notification/notification.gresource.xml
index a4906c684..2ffb079f9 100644
--- a/src/plugins/notification/notification.gresource.xml
+++ b/src/plugins/notification/notification.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/notification">
     <file>notification.plugin</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/notification/notification.plugin b/src/plugins/notification/notification.plugin
index 3f1f0c789..079e89883 100644
--- a/src/plugins/notification/notification.plugin
+++ b/src/plugins/notification/notification.plugin
@@ -1,8 +1,9 @@
 [Plugin]
-Module=notification-plugin
-Name=Notification of progress
-Description=Notification of progress when Builder application is not on foreground
 Authors=Lucie Charvat <luci charvat gmail com>
-Copyright=Copyright © 2017 Lucie Charvat
 Builtin=true
-Embedded=ide_notification_register_types
+Copyright=Copyright © 2017 Lucie Charvat
+Description=Notification of progress when Builder application is not on foreground
+Embedded=_ide_notification_register_types
+Hidden=true
+Module=notification
+Name=Notification of progress


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