Commit dadb5adc authored by ЀÓù's avatar ЀÓ�ù� Committed by Christian Hergert

notification plugin: notify user that build has finished

https://bugzilla.gnome.org/show_bug.cgi?id=780686
parent 58482b57
......@@ -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}"
......
......@@ -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')
......
......@@ -29,6 +29,7 @@ SUBDIRS = \
meson-templates \
mingw \
mono \
notification \
phpize \
project-tree \
python-gi-imports-completion \
......
......@@ -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')
......
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
# --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])
/* 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;
}
/* 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 */
/* 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);
}
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
[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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment