summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-11-17 01:27:34 +0100
committerraveit65 <[email protected]>2020-11-26 11:50:18 +0100
commitc1dd04d294e329da95c515d7f5a9ac7a00d269cc (patch)
tree2a129f163e6c3302d0fa5dfdf96bdee0de8a2e46
parentb704b0e30d2ad7672c3fa86c02f3f311327fd66a (diff)
downloadmate-notification-daemon-c1dd04d294e329da95c515d7f5a9ac7a00d269cc.tar.bz2
mate-notification-daemon-c1dd04d294e329da95c515d7f5a9ac7a00d269cc.tar.xz
Add Do Not Disturb Applet
-rw-r--r--.build.yml4
-rw-r--r--configure.ac11
-rw-r--r--data/Makefile.am33
-rw-r--r--data/mate-notification-properties.desktop.in (renamed from src/capplet/mate-notification-properties.desktop.in)0
-rw-r--r--data/org.mate.applets.MateNotificationApplet.desktop.in.in16
-rw-r--r--data/org.mate.panel.applet.MateNotificationAppletFactory.service.in3
-rw-r--r--po/POTFILES.in4
-rw-r--r--src/capplet/Makefile.am84
-rw-r--r--src/capplet/mate-notification-applet-menu.xml3
-rw-r--r--src/capplet/mate-notification-applet.c218
-rw-r--r--src/capplet/org.mate.panel.applet.notifications.gresource.xml6
11 files changed, 356 insertions, 26 deletions
diff --git a/.build.yml b/.build.yml
index 2b73ce9..8b470c0 100644
--- a/.build.yml
+++ b/.build.yml
@@ -13,6 +13,7 @@ requires:
- libwnck3
- make
- mate-common
+ - mate-panel
- which
debian:
@@ -36,6 +37,7 @@ requires:
- libglib2.0-dev
- libgtk-3-dev
- libmate-desktop-dev
+ - libmate-panel-applet-dev
- libnotify-dev
- libpango1.0-dev
- libstartup-notification0-dev
@@ -63,6 +65,7 @@ requires:
- make
- mate-common
- mate-desktop-devel
+ - mate-panel-devel
ubuntu:
- autoconf-archive
@@ -81,6 +84,7 @@ requires:
- libglib2.0-dev
- libgtk-3-dev
- libmate-desktop-dev
+ - libmate-panel-applet-dev
- libnotify-dev
- libpango1.0-dev
- libstartup-notification0-dev
diff --git a/configure.ac b/configure.ac
index cf92347..af9be0d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,6 +130,15 @@ pkg_modules="
"
PKG_CHECK_MODULES(NOTIFICATION_DAEMON, $pkg_modules)
+dnl ---------------------------------------------------------------------------
+dnl Requirements for panel applet
+dnl ---------------------------------------------------------------------------
+LIBPANEL4_REQUIRED=1.17.0
+LIBMATE_DESKTOP_REQUIRED=1.17.0
+PKG_CHECK_MODULES(NOTIFICATION_APPLET, mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED libmatepanelapplet-4.0 >= $LIBPANEL4_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $REQ_GLIB_VERSION)
+AC_SUBST(NOTIFICATION_APPLET_CFLAGS)
+AC_SUBST(NOTIFICATION_APPLET_LIBS)
+
dnl Will call AC_SUBSET on NOTIFICATION_DAEMON_* below after appending X11 and Wayland flags
dnl ---------------------------------------------------------------------------
@@ -275,7 +284,9 @@ AC_CONFIG_FILES([
Makefile
data/Makefile
data/org.freedesktop.mate.Notifications.service
+data/org.mate.applets.MateNotificationApplet.desktop.in
data/org.mate.NotificationDaemon.gschema.xml
+data/org.mate.panel.applet.MateNotificationAppletFactory.service
po/Makefile.in
src/Makefile
src/daemon/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 623725d..be9a8b7 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -12,17 +12,31 @@ icon32_DATA = icons/32x32/mate-notification-properties.png
icon48_DATA = icons/48x48/mate-notification-properties.png
iconscalable_DATA = icons/scalable/mate-notification-properties.svg
+servicedir = $(DBUS_SERVICES_DIR)
+service_DATA = org.freedesktop.mate.Notifications.service org.mate.panel.applet.MateNotificationAppletFactory.service
+service_in_files = $(service_DATA:=.in)
-servicedir = $(DBUS_SERVICES_DIR)
-service_DATA = org.freedesktop.mate.Notifications.service
+appletdir = $(datadir)/mate-panel/applets
+applet_DATA = org.mate.applets.MateNotificationApplet.mate-panel-applet
+applet_in_files = $(applet_DATA:.mate-panel-applet=.desktop.in)
-gsettingsschema_in_files = org.mate.NotificationDaemon.gschema.xml.in
-gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml)
+$(applet_DATA): $(applet_in_files)
+ $(AM_V_GEN) $(MSGFMT) --desktop --keyword=Name --keyword=Description --template $< -d $(top_srcdir)/po -o $@
+
+desktopdir = $(datadir)/applications
+desktop_DATA = mate-notification-properties.desktop
+desktop_in_files = $(desktop_DATA:.desktop=.desktop.in)
+
+$(desktop_DATA): $(desktop_in_files)
+ $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@
+
+gsettings_SCHEMAS = org.mate.NotificationDaemon.gschema.xml
+gsettingsschema_in_files = $(gsettings_SCHEMAS:=.in)
@GSETTINGS_RULES@
EXTRA_DIST = \
+ $(desktop_in_files) \
$(gsettingsschema_in_files) \
- $(service_DATA) \
$(icon16_DATA) \
$(icon22_DATA) \
$(icon24_DATA) \
@@ -30,7 +44,14 @@ EXTRA_DIST = \
$(icon48_DATA) \
$(iconscalable_DATA)
-CLEANFILES = $(gsettings_SCHEMAS)
+CLEANFILES = \
+ $(applet_DATA) \
+ $(desktop_DATA) \
+ $(gsettings_SCHEMAS)
+
+DISTCLEANFILES = \
+ $(applet_in_files) \
+ $(service_DATA)
gtk_update_icon_cache = $(UPDATE_ICON_CACHE) -f -t $(datadir)/icons/hicolor
diff --git a/src/capplet/mate-notification-properties.desktop.in b/data/mate-notification-properties.desktop.in
index c96e053..c96e053 100644
--- a/src/capplet/mate-notification-properties.desktop.in
+++ b/data/mate-notification-properties.desktop.in
diff --git a/data/org.mate.applets.MateNotificationApplet.desktop.in.in b/data/org.mate.applets.MateNotificationApplet.desktop.in.in
new file mode 100644
index 0000000..7b3769b
--- /dev/null
+++ b/data/org.mate.applets.MateNotificationApplet.desktop.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=MateNotificationAppletFactory
+Location=@LIBEXECDIR@/mate-notification-applet
+Name=Mate Notification Applet Factory
+Description=Mate Notification Applet Factory
+
+[MateNotificationApplet]
+Name=Do Not Disturb
+Description=Activate the do not disturb mode.
+# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
+Icon=mate-notification-properties
+MateComponentId=OAFIID:MATE_Panel_Notification_Applet
+X-MATE-Bugzilla-Bugzilla=MATE
+X-MATE-Bugzilla-Product=mate-notification-daemon
+X-MATE-Bugzilla-Component=notification applet
+X-MATE-Bugzilla-Version=@VERSION@
diff --git a/data/org.mate.panel.applet.MateNotificationAppletFactory.service.in b/data/org.mate.panel.applet.MateNotificationAppletFactory.service.in
new file mode 100644
index 0000000..e30bf7c
--- /dev/null
+++ b/data/org.mate.panel.applet.MateNotificationAppletFactory.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.mate.panel.applet.MateNotificationAppletFactory
+Exec=@LIBEXECDIR@/mate-notification-applet
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 117a89c..629ff57 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,8 @@
+data/mate-notification-properties.desktop.in
+data/org.mate.applets.MateNotificationApplet.desktop.in.in
data/org.mate.NotificationDaemon.gschema.xml.in
+src/capplet/mate-notification-applet.c
src/capplet/mate-notification-properties.c
-src/capplet/mate-notification-properties.desktop.in
src/capplet/mate-notification-properties.ui
src/daemon/daemon.c
src/daemon/sound.c
diff --git a/src/capplet/Makefile.am b/src/capplet/Makefile.am
index 509133d..2e27e00 100644
--- a/src/capplet/Makefile.am
+++ b/src/capplet/Makefile.am
@@ -1,30 +1,76 @@
+define generate_resources_deps
+ $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/$(1))
+endef
+
bin_PROGRAMS = mate-notification-properties
+libexec_PROGRAMS = mate-notification-applet
-BUILT_SOURCES = mate-notification-properties-resources.h mate-notification-properties-resources.c
+NULL =
-mate_notification_properties_LDADD = $(NOTIFICATION_CAPPLET_LIBS)
-mate_notification_properties_SOURCES = $(BUILT_SOURCES) mate-notification-properties.c
-mate_notification_properties_CFLAGS = $(WARN_CFLAGS)
+mate_notification_properties_CFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src/daemon \
+ $(NOTIFICATION_CAPPLET_CFLAGS) \
+ -DENGINES_DIR=\"$(libdir)/mate-notification-daemon/engines\" \
+ -DNOTIFICATION_LOCALEDIR=\"$(datadir)/locale\" \
+ $(WARN_CFLAGS) \
+ $(NULL)
-mate-notification-properties-resources.h mate-notification-properties-resources.c: org.mate.notifications.properties.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/org.mate.notifications.properties.gresource.xml)
- $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name notification_properties $<
+mate_notification_properties_LDADD = \
+ $(NOTIFICATION_CAPPLET_LIBS) \
+ $(NULL)
-desktopdir = $(datadir)/applications
-desktop_in_files = mate-notification-properties.desktop.in
-desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
-$(desktop_DATA): $(desktop_in_files)
- $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@
+mate_notification_properties_resources_xml = org.mate.notifications.properties.gresource.xml
+mate_notification_properties_resources_deps = $(call generate_resources_deps $(mate_notification_properties_resources_xml))
+mate_notification_properties_resources_files = mate-notification-properties-resources.h mate-notification-properties-resources.c
+$(mate_notification_properties_resources_files): $(mate_notification_properties_resources_xml) Makefile $(mate_notification_properties_resources_deps)
+ $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) $< \
+ --target $@ --sourcedir $(srcdir) --generate --c-name notification_properties
+mate_notification_properties_SOURCES = \
+ $(mate_notification_properties_resources_files) \
+ mate-notification-properties.c \
+ $(NULL)
man_MANS = mate-notification-properties.1
-AM_CPPFLAGS = \
- -I$(top_srcdir) \
- -I$(top_srcdir)/src/daemon \
- $(NOTIFICATION_CAPPLET_CFLAGS) \
- -DENGINES_DIR=\"$(libdir)/mate-notification-daemon/engines\" \
- -DNOTIFICATION_LOCALEDIR=\"$(datadir)/locale\"
+mate_notification_applet_CFLAGS = \
+ $(NOTIFICATION_APPLET_CFLAGS) \
+ -DMATELOCALEDIR=\"$(datadir)/locale\" \
+ -DRESOURCE_PATH=\""/org/mate/panel/applet/notifications/"\" \
+ $(WARN_CFLAGS) \
+ $(NULL)
+
+mate_notification_applet_LDADD = \
+ $(NOTIFICATION_APPLET_LIBS) \
+ $(NULL)
+
+mate_notification_applet_resources_xml = org.mate.panel.applet.notifications.gresource.xml
+mate_notification_applet_resources_deps = $(call generate_resources_deps $(mate_notification_applet_resources_xml))
+mate_notification_applet_resources_files = mate-notification-applet-resources.h mate-notification-applet-resources.c
+$(mate_notification_applet_resources_files): $(mate_notification_applet_resources_xml) Makefile $(mate_notification_applet_resources_deps)
+ $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) $< \
+ --target $@ --sourcedir $(srcdir) --generate --c-name notification_applet
+mate_notification_applet_SOURCES = \
+ $(mate_notification_applet_resources_files) \
+ mate-notification-applet.c \
+ $(NULL)
+
+BUILT_SOURCES = \
+ $(mate_notification_properties_resources_files) \
+ $(mate_notification_applet_resources_files) \
+ $(NULL)
+
+CLEANFILES = \
+ $(BUILT_SOURCES) \
+ $(NULL)
-CLEANFILES = $(desktop_DATA) $(BUILT_SOURCES)
-EXTRA_DIST = mate-notification-properties.ui $(pixmap_DATA) $(desktop_in_files) $(man_MANS) org.mate.notifications.properties.gresource.xml
+EXTRA_DIST = \
+ $(man_MANS) \
+ $(pixmap_DATA) \
+ $(mate_notification_applet_resources_xml) \
+ $(mate_notification_properties_resources_xml) \
+ mate-notification-applet-menu.xml \
+ mate-notification-properties.ui \
+ $(NULL)
-include $(top_srcdir)/git.mk
diff --git a/src/capplet/mate-notification-applet-menu.xml b/src/capplet/mate-notification-applet-menu.xml
new file mode 100644
index 0000000..cab30ac
--- /dev/null
+++ b/src/capplet/mate-notification-applet-menu.xml
@@ -0,0 +1,3 @@
+<menuitem name="DoNotDisturb Item" action="DoNotDisturb" />
+<menuitem name="Preferences Item" action="Preferences" />
+<menuitem name="About Item" action="About" />
diff --git a/src/capplet/mate-notification-applet.c b/src/capplet/mate-notification-applet.c
new file mode 100644
index 0000000..e8ef83f
--- /dev/null
+++ b/src/capplet/mate-notification-applet.c
@@ -0,0 +1,218 @@
+/* mate-notification-applet.c - MATE Notification Applet
+ *
+ * Copyright (c) 2020 Robert Buj <[email protected]>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <mate-panel-applet.h>
+
+#define MATE_DESKTOP_USE_UNSTABLE_API
+#include <libmate-desktop/mate-desktop-utils.h>
+
+#define GSETTINGS_SCHEMA "org.mate.NotificationDaemon"
+#define GSETTINGS_KEY_DO_NOT_DISTURB "do-not-disturb"
+
+typedef struct
+{
+ MatePanelApplet *applet;
+
+ GtkWidget *image_on;
+ GtkWidget *image_off;
+ GtkActionGroup *action_group;
+ GSettings *settings;
+} MateNotificationApplet;
+
+static void
+show_about (GtkAction *action,
+ MateNotificationApplet *applet);
+static void
+call_properties (GtkAction *action,
+ MateNotificationApplet *applet);
+
+static const GtkActionEntry applet_menu_actions [] = {
+ { "Preferences", "document-properties", N_("_Preferences"),
+ NULL, NULL, G_CALLBACK (call_properties) },
+ { "About", "help-about", N_("_About"),
+ NULL, NULL, G_CALLBACK (show_about) }
+};
+
+static const char* notification_properties[] = {
+ "mate-notification-properties",
+};
+
+static void
+applet_destroy (MateNotificationApplet *applet)
+{
+ g_assert (applet);
+
+ g_object_unref (applet->settings);
+ g_object_unref (applet->action_group);
+ g_free (applet);
+}
+
+static void
+call_properties (GtkAction *action,
+ MateNotificationApplet *applet)
+{
+ gsize i;
+ (void) action;
+
+ for (i = 0; i < G_N_ELEMENTS (notification_properties); i++) {
+ char *programpath = g_find_program_in_path (notification_properties[i]);
+
+ if (programpath != NULL) {
+ g_free (programpath);
+ mate_gdk_spawn_command_line_on_screen (gtk_widget_get_screen (GTK_WIDGET (applet->applet)),
+ notification_properties[i],
+ NULL);
+ return;
+ }
+ }
+}
+
+static void
+show_about (GtkAction *action,
+ MateNotificationApplet *applet)
+{
+ static const char *authors[] = {
+ "Robert Buj <[email protected]>",
+ NULL
+ };
+ (void) action;
+ (void) applet;
+
+ gtk_show_about_dialog (NULL,
+ "title", _("About Do Not Disturb"),
+ "version", VERSION,
+ "copyright", _("Copyright \xc2\xa9 2020 MATE developers"),
+ "comments", _("Activate the do not disturb mode quickly."),
+ "authors", authors,
+ "translator-credits", _("translator-credits"),
+ "logo_icon_name", "mate-notification-properties",
+ NULL);
+}
+
+static void
+set_status_image (MateNotificationApplet *applet,
+ gboolean active)
+{
+ gtk_widget_show_all (GTK_WIDGET (applet->applet));
+ if (active)
+ gtk_widget_hide (applet->image_on);
+ else
+ gtk_widget_hide (applet->image_off);
+}
+
+static void
+settings_changed (GSettings *settings,
+ gchar *key,
+ MateNotificationApplet *applet)
+{
+ if (g_strcmp0 (GSETTINGS_KEY_DO_NOT_DISTURB, key) == 0)
+ set_status_image (applet,
+ g_settings_get_boolean (settings, key));
+}
+
+static gboolean
+applet_main (MatePanelApplet *applet_widget)
+{
+ MateNotificationApplet *applet;
+ GtkWidget *box;
+
+ bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ g_set_application_name (_("Do Not Disturb"));
+ gtk_window_set_default_icon_name ("mate-notification-properties");
+
+ applet = g_new (MateNotificationApplet, 1);
+ applet->applet = applet_widget;
+ applet->settings = g_settings_new (GSETTINGS_SCHEMA);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ applet->image_on = gtk_image_new_from_icon_name ("user-available", GTK_ICON_SIZE_BUTTON);
+ applet->image_off = gtk_image_new_from_icon_name ("user-invisible", GTK_ICON_SIZE_BUTTON);
+
+ gtk_widget_set_tooltip_text (applet->image_off, N_("Do Not Disturb"));
+ gtk_widget_set_tooltip_text (applet->image_on, N_("Notifications Enabled"));
+
+ gtk_box_pack_start (GTK_BOX (box), applet->image_on,
+ TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), applet->image_off,
+ TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (applet_widget), box);
+
+ set_status_image (applet,
+ g_settings_get_boolean (applet->settings,
+ GSETTINGS_KEY_DO_NOT_DISTURB));
+
+ /* set up context menu */
+ applet->action_group = gtk_action_group_new ("Do Not Disturb Actions");
+ gtk_action_group_set_translation_domain (applet->action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (applet->action_group, applet_menu_actions,
+ G_N_ELEMENTS (applet_menu_actions), applet);
+
+ GtkToggleAction *do_not_disturb_toggle_action =
+ gtk_toggle_action_new ("DoNotDisturb", N_("_Do not disturb"),
+ N_("Enable/Disable do-not-disturb mode."), NULL);
+
+ gtk_action_group_add_action (applet->action_group,
+ GTK_ACTION (do_not_disturb_toggle_action));
+
+ mate_panel_applet_setup_menu_from_resource (applet->applet,
+ RESOURCE_PATH "menu.xml",
+ applet->action_group);
+
+ g_settings_bind (applet->settings, "do-not-disturb",
+ do_not_disturb_toggle_action, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_signal_connect (G_OBJECT (applet->applet), "destroy",
+ G_CALLBACK (applet_destroy), NULL);
+
+ /* GSettings callback */
+ g_signal_connect (G_OBJECT (applet->settings), "changed::" GSETTINGS_KEY_DO_NOT_DISTURB,
+ G_CALLBACK (settings_changed), applet);
+
+ return TRUE;
+}
+
+static gboolean
+applet_factory (MatePanelApplet *applet,
+ const gchar *iid,
+ gpointer data)
+{
+ gboolean retval = FALSE;
+ (void) data;
+
+ if (!strcmp (iid, "MateNotificationApplet"))
+ retval = applet_main (applet);
+
+ return retval;
+}
+
+MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("MateNotificationAppletFactory",
+ PANEL_TYPE_APPLET,
+ "Do Not Disturb Applet",
+ applet_factory,
+ NULL)
diff --git a/src/capplet/org.mate.panel.applet.notifications.gresource.xml b/src/capplet/org.mate.panel.applet.notifications.gresource.xml
new file mode 100644
index 0000000..43eec64
--- /dev/null
+++ b/src/capplet/org.mate.panel.applet.notifications.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/mate/panel/applet/notifications">
+ <file compressed="true" alias="menu.xml">mate-notification-applet-menu.xml</file>
+ </gresource>
+</gresources>