[gnome-builder] notification plugin: notify user that build has finished
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] notification plugin: notify user that build has finished
- Date: Mon, 17 Apr 2017 02:55:43 +0000 (UTC)
commit dadb5adca2c72a65948f877c7196ede2bed247d5
Author: ЀÓù <÷ÖU>
Date: Sat Apr 15 19:57:19 2017 +0200
notification plugin: notify user that build has finished
https://bugzilla.gnome.org/show_bug.cgi?id=780686
configure.ac | 2 +
meson_options.txt | 1 +
plugins/Makefile.am | 1 +
plugins/meson.build | 1 +
plugins/notification/Makefile.am | 20 +++
plugins/notification/configure.ac | 12 ++
plugins/notification/ide-notification-addin.c | 208 ++++++++++++++++++++++++
plugins/notification/ide-notification-addin.h | 32 ++++
plugins/notification/ide-notification-plugin.c | 28 ++++
plugins/notification/meson.build | 19 +++
plugins/notification/notification.plugin | 7 +
11 files changed, 331 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 38debeb..194fd7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -318,6 +318,7 @@ m4_include([plugins/meson/configure.ac])
m4_include([plugins/meson-templates/configure.ac])
m4_include([plugins/mingw/configure.ac])
m4_include([plugins/mono/configure.ac])
+m4_include([plugins/notification/configure.ac])
m4_include([plugins/phpize/configure.ac])
m4_include([plugins/project-tree/configure.ac])
m4_include([plugins/python-gi-imports-completion/configure.ac])
@@ -603,6 +604,7 @@ echo " Make ................................. : ${enable_make_plugin}"
echo " Meson ................................ : ${enable_meson_plugin}"
echo " MinGW ................................ : ${enable_mingw_plugin}"
echo " Mono ................................. : ${enable_mono_plugin}"
+echo " Notification ......................... : ${enable_notification_plugin}"
echo " PHPize ............................... : ${enable_phpize_plugin}"
echo " Project Creation ..................... : ${enable_create_project_plugin}"
echo " Project Tree ......................... : ${enable_project_tree_plugin}"
diff --git a/meson_options.txt b/meson_options.txt
index 459669b..c7067bb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -46,6 +46,7 @@ option('with_meson', type: 'boolean')
option('with_meson_templates', type: 'boolean', value: false)
option('with_mingw', type: 'boolean')
option('with_mono', type: 'boolean')
+option('with_notification', type: 'boolean')
option('with_phpize', type: 'boolean')
option('with_project_tree', type: 'boolean')
option('with_python_gi_imports_completion', type: 'boolean')
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 88326b7..ffe0710 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -29,6 +29,7 @@ SUBDIRS = \
meson-templates \
mingw \
mono \
+ notification \
phpize \
project-tree \
python-gi-imports-completion \
diff --git a/plugins/meson.build b/plugins/meson.build
index 0da6c26..4c9406d 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -40,6 +40,7 @@ subdir('meson')
subdir('meson-templates')
subdir('mingw')
subdir('mono')
+subdir('notification')
subdir('phpize')
subdir('project-tree')
subdir('python-gi-imports-completion')
diff --git a/plugins/notification/Makefile.am b/plugins/notification/Makefile.am
new file mode 100644
index 0000000..876bd3c
--- /dev/null
+++ b/plugins/notification/Makefile.am
@@ -0,0 +1,20 @@
+if ENABLE_NOTIFICATION_PLUGIN
+
+plugindir = $(libdir)/gnome-builder/plugins
+plugin_LTLIBRARIES = libnotification-plugin.la
+dist_plugin_DATA = notification.plugin
+
+libnotification_plugin_la_SOURCES = \
+ ide-notification-plugin.c \
+ ide-notification-addin.c \
+ ide-notification-addin.h \
+ $(NULL)
+
+libnotification_plugin_la_CFLAGS = $(PLUGIN_CFLAGS)
+libnotification_plugin_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/notification/configure.ac b/plugins/notification/configure.ac
new file mode 100644
index 0000000..36586d9
--- /dev/null
+++ b/plugins/notification/configure.ac
@@ -0,0 +1,12 @@
+# --enable-notification-plugin=yes/no
+AC_ARG_ENABLE([notification-plugin],
+ [AS_HELP_STRING([--enable-notification-plugin=@<:@yes/no@:>@],
+ [Build with support for autocompletion in HTML documents.])],
+ [enable_notification_plugin=$enableval],
+ [enable_notification_plugin=yes])
+
+# for if ENABLE_NOTIFICATION_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_NOTIFICATION_PLUGIN, test x$enable_notification_plugin != xno)
+
+# Ensure our makefile is generated by autoconf
+AC_CONFIG_FILES([plugins/notification/Makefile])
diff --git a/plugins/notification/ide-notification-addin.c b/plugins/notification/ide-notification-addin.c
new file mode 100644
index 0000000..d55feaf
--- /dev/null
+++ b/plugins/notification/ide-notification-addin.c
@@ -0,0 +1,208 @@
+/* gbp-notification-addin.c
+ *
+ * Copyright (C) 2017 Lucie Charvat <luci charvat gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "ide-notification-addin.h"
+
+#define NOTIFY_TIMEOUT (10000)
+#define NOTIFY_ID (0)
+
+struct _IdeNotificationAddin
+{
+ IdeObject parent_instance;
+ GDBusProxy* proxy;
+};
+
+static void addin_iface_init (IdeBuildPipelineAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeNotificationAddin,
+ ide_notification_addin,
+ IDE_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_PIPELINE_ADDIN,
+ addin_iface_init))
+
+static void
+ide_notification_addin_notify (IdeNotificationAddin *self,
+ const gchar *msg)
+{
+ GVariant *result;
+ GVariantBuilder actions_builder;
+ GVariantBuilder hints_builder;
+ GtkApplication *app;
+ GtkWindow *window;
+ IdeContext *context;
+ IdeProject *project;
+ const gchar *project_name;
+ gchar *msg_body;
+ gchar *msg_title;
+
+ app = GTK_APPLICATION (g_application_get_default ());
+ window = gtk_application_get_active_window (app);
+ if(gtk_window_has_toplevel_focus (window))
+ return;
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ g_assert (IDE_IS_CONTEXT (context));
+
+ project = ide_context_get_project (context);
+ g_assert (IDE_IS_PROJECT (project));
+
+ project_name = ide_project_get_name (project);
+ if (project_name == NULL)
+ return;
+
+ msg_body = g_strconcat ("Build of project ", project_name, " ", msg, NULL);
+ if (msg_body == NULL)
+ return;
+
+ msg_title = g_strconcat ("Build action ", msg, NULL);
+ if (msg_title == NULL)
+ {
+ g_free(msg_body);
+ return;
+ }
+
+ g_variant_builder_init (&actions_builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
+
+ result = g_dbus_proxy_call_sync (self->proxy,
+ "Notify",
+ g_variant_new ("(susssasa{sv}i)",
+ "org.gnome.Builder", NOTIFY_ID, "",
+ msg_title,
+ msg_body, &actions_builder,
+ &hints_builder, -1),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+ if (result != NULL)
+ g_variant_unref (result);
+
+ g_free(msg_body);
+ g_free(msg_title);
+
+// "/data/icons/hicolor/16x16/apps/org.gnome.Builder.png",
+// GNotification *notification;
+// notification = g_notification_new ("Test");
+// g_notification_set_body (notification, "body");
+// g_application_send_notification (G_APPLICATION (app), "test1", notification);
+// g_object_unref (notification);
+}
+static void
+ide_notification_addin_build_failed (IdeNotificationAddin *self,
+ IdeBuildPipeline *build_pipeline,
+ IdeBuildManager *build_manager)
+{
+ const gchar *msg_body;
+
+ g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
+ g_assert (IDE_IS_BUILD_PIPELINE (build_pipeline));
+ g_assert (IDE_IS_BUILD_MANAGER (build_manager));
+
+ msg_body = "failed";
+
+ ide_notification_addin_notify(self, msg_body);
+
+}
+
+static void
+ide_notification_addin_build_finished (IdeNotificationAddin *self,
+ IdeBuildPipeline *build_pipeline,
+ IdeBuildManager *build_manager)
+{
+ const gchar *msg_body;
+
+ g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
+ g_assert (IDE_IS_BUILD_PIPELINE (build_pipeline));
+ g_assert (IDE_IS_BUILD_MANAGER (build_manager));
+
+ msg_body = "finished";
+
+ ide_notification_addin_notify(self, msg_body);
+
+}
+
+static void
+ide_notification_addin_load (IdeBuildPipelineAddin *addin,
+ IdeBuildPipeline *pipeline)
+{
+ IdeNotificationAddin *self = (IdeNotificationAddin *)addin;
+ IdeContext* context;
+ IdeBuildManager *build_manager;
+
+ g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
+ g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+
+ context = ide_object_get_context (IDE_OBJECT (addin));
+ g_assert (IDE_IS_CONTEXT (context));
+
+ build_manager = ide_context_get_build_manager (context);
+ g_assert (IDE_IS_BUILD_MANAGER (build_manager));
+
+ self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ NULL,
+ NULL);
+ g_assert(G_IS_DBUS_PROXY (self->proxy));
+
+ g_signal_connect_object (build_manager,
+ "build-finished",
+ G_CALLBACK (ide_notification_addin_build_finished),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (build_manager,
+ "build-failed",
+ G_CALLBACK (ide_notification_addin_build_failed),
+ self,
+ G_CONNECT_SWAPPED);
+}
+
+static void
+ide_notification_addin_unload (IdeBuildPipelineAddin *addin,
+ IdeBuildPipeline *pipeline)
+{
+ IdeNotificationAddin *self = (IdeNotificationAddin *)addin;
+
+ g_assert (IDE_IS_NOTIFICATION_ADDIN (self));
+ g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+
+ if (self->proxy)
+ g_object_unref (self->proxy);
+}
+static void
+ide_notification_addin_class_init (IdeNotificationAddinClass *klass)
+{
+}
+
+static void
+ide_notification_addin_init (IdeNotificationAddin *self)
+{
+}
+
+static void
+addin_iface_init (IdeBuildPipelineAddinInterface *iface)
+{
+ iface->load = ide_notification_addin_load;
+ iface->unload = ide_notification_addin_unload;
+}
diff --git a/plugins/notification/ide-notification-addin.h b/plugins/notification/ide-notification-addin.h
new file mode 100644
index 0000000..507766b
--- /dev/null
+++ b/plugins/notification/ide-notification-addin.h
@@ -0,0 +1,32 @@
+/* gbp-notification-addin.h
+ *
+ * Copyright (C) 2017 Lucie Charvat <luci charvat gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GBP_NOTIFICATION_ADDIN_H
+#define GBP_NOTIFICATION_ADDIN_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_NOTIFICATION_ADDIN (ide_notification_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeNotificationAddin, ide_notification_addin, IDE, NOTIFICATION_ADDIN, IdeObject)
+
+G_END_DECLS
+
+#endif /* GBP_NOTIFICATION_ADDIN_H */
diff --git a/plugins/notification/ide-notification-plugin.c b/plugins/notification/ide-notification-plugin.c
new file mode 100644
index 0000000..0a64bff
--- /dev/null
+++ b/plugins/notification/ide-notification-plugin.c
@@ -0,0 +1,28 @@
+/* autotools-plugin.c
+ *
+ * Copyright (C) 2017 Lucie Charvat <luci charvat gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libpeas/peas.h>
+#include <ide.h>
+
+#include "ide-notification-addin.h"
+
+void
+peas_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module, IDE_TYPE_BUILD_PIPELINE_ADDIN,
IDE_TYPE_NOTIFICATION_ADDIN);
+}
diff --git a/plugins/notification/meson.build b/plugins/notification/meson.build
new file mode 100644
index 0000000..93ef102
--- /dev/null
+++ b/plugins/notification/meson.build
@@ -0,0 +1,19 @@
+if get_option('with_notification')
+
+notification_sources = [
+ 'ide-notification-plugin.c',
+ 'ide-notification-addin.c',
+ 'ide-notification-addin.h',
+]
+
+shared_module('notification-plugin', notification_sources,
+ dependencies: notification_deps,
+ link_args: plugin_link_args,
+ link_depends: plugin_link_deps,
+ install: true,
+ install_dir: plugindir,
+)
+
+install_data('notification.plugin', install_dir: plugindir)
+
+endif
diff --git a/plugins/notification/notification.plugin b/plugins/notification/notification.plugin
new file mode 100644
index 0000000..143ad1b
--- /dev/null
+++ b/plugins/notification/notification.plugin
@@ -0,0 +1,7 @@
+[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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]