[Xfce4-commits] [apps/xfce4-notifyd] 01/24: Add panel plugin

noreply at xfce.org noreply at xfce.org
Fri Sep 8 23:27:32 CEST 2017


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-notifyd.

commit db09c3a6f81bec0167ecc0a3fb0ad4c9062247de
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Aug 21 00:28:01 2017 +0200

    Add panel plugin
---
 icons/48x48/Makefile.am                     |  10 +
 icons/48x48/xfce4-sample-plugin.png         | Bin 0 -> 2899 bytes
 icons/Makefile.am                           |  20 ++
 icons/scalable/Makefile.am                  |  10 +
 icons/scalable/xfce4-sample-plugin.svg      | 316 ++++++++++++++++++++++
 panel-plugin/Makefile.am                    |  57 ++++
 panel-plugin/notification-plugin-dialogs.c  | 126 +++++++++
 panel-plugin/notification-plugin-dialogs.h  |  34 +++
 panel-plugin/notification-plugin.c          | 391 ++++++++++++++++++++++++++++
 panel-plugin/notification-plugin.desktop.in |  10 +
 panel-plugin/notification-plugin.h          |  53 ++++
 11 files changed, 1027 insertions(+)

diff --git a/icons/48x48/Makefile.am b/icons/48x48/Makefile.am
new file mode 100644
index 0000000..17d0fc3
--- /dev/null
+++ b/icons/48x48/Makefile.am
@@ -0,0 +1,10 @@
+# $Id$
+
+iconsdir = $(datadir)/icons/hicolor/48x48/apps
+icons_DATA =								\
+	xfce4-sample-plugin.png
+
+EXTRA_DIST =								\
+	$(icons_DATA)
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/icons/48x48/xfce4-sample-plugin.png b/icons/48x48/xfce4-sample-plugin.png
new file mode 100644
index 0000000..d1f05ea
Binary files /dev/null and b/icons/48x48/xfce4-sample-plugin.png differ
diff --git a/icons/Makefile.am b/icons/Makefile.am
new file mode 100644
index 0000000..2caedee
--- /dev/null
+++ b/icons/Makefile.am
@@ -0,0 +1,20 @@
+# $Id$
+
+SUBDIRS =								\
+	48x48								\
+	scalable
+
+gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
+
+install-data-hook:
+	@-if test -z "$(DESTDIR)"; then					\
+                echo "Updating Gtk icon cache.";			\
+                $(gtk_update_icon_cache);				\
+        else								\
+                echo "*** Icon cache not updated. Remember to run:";	\
+		echo "***";						\
+                echo "***   $(gtk_update_icon_cache)";			\
+		echo "***";						\
+        fi
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/icons/scalable/Makefile.am b/icons/scalable/Makefile.am
new file mode 100644
index 0000000..7442c40
--- /dev/null
+++ b/icons/scalable/Makefile.am
@@ -0,0 +1,10 @@
+# $Id$
+
+iconsdir = $(datadir)/icons/hicolor/scalable/apps
+icons_DATA =								\
+	xfce4-sample-plugin.svg
+
+EXTRA_DIST =								\
+	$(icons_DATA)
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/icons/scalable/xfce4-sample-plugin.svg b/icons/scalable/xfce4-sample-plugin.svg
new file mode 100644
index 0000000..1331ecb
--- /dev/null
+++ b/icons/scalable/xfce4-sample-plugin.svg
@@ -0,0 +1,316 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://web.resource.org/cc/"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="48.000000px"
+   height="48.000000px"
+   id="svg4376"
+   sodipodi:version="0.32"
+   inkscape:version="0.42+devel"
+   sodipodi:docbase="/home/jimmac/src/cvs/tango-icon-theme/scalable/emotes"
+   sodipodi:docname="face-grin.svg"
+   inkscape:export-filename="/home/tigert/Desktop/face-grin.png"
+   inkscape:export-xdpi="90.000000"
+   inkscape:export-ydpi="90.000000">
+  <defs
+     id="defs3">
+    <linearGradient
+       id="linearGradient2102">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop2104" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0;"
+         offset="1"
+         id="stop2106" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient3290">
+      <stop
+         style="stop-color:#fffcde;stop-opacity:1.0000000;"
+         offset="0.0000000"
+         id="stop3292" />
+      <stop
+         id="stop3294"
+         offset="0.64485979"
+         style="stop-color:#f6e76a;stop-opacity:1.0000000;" />
+      <stop
+         style="stop-color:#ffb738;stop-opacity:1.0000000;"
+         offset="1.0000000"
+         id="stop3296" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient3068">
+      <stop
+         style="stop-color:#cccccc;stop-opacity:1.0000000;"
+         offset="0.0000000"
+         id="stop3070" />
+      <stop
+         id="stop3076"
+         offset="0.34579438"
+         style="stop-color:#ffffff;stop-opacity:1.0000000;" />
+      <stop
+         style="stop-color:#ffffff;stop-opacity:1.0000000;"
+         offset="0.72486681"
+         id="stop3078" />
+      <stop
+         style="stop-color:#cecece;stop-opacity:1.0000000;"
+         offset="1.0000000"
+         id="stop3072" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient4565">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop4567" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0;"
+         offset="1"
+         id="stop4569" />
+    </linearGradient>
+    <radialGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient4565"
+       id="radialGradient1360"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,0.333333,0.000000,25.71429)"
+       cx="24.714285"
+       cy="38.571430"
+       fx="24.714285"
+       fy="38.571430"
+       r="19.714285" />
+    <radialGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3290"
+       id="radialGradient1362"
+       gradientUnits="userSpaceOnUse"
+       cx="29.288071"
+       cy="15.720984"
+       fx="29.158466"
+       fy="15.755712"
+       r="8.9020796" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2102"
+       id="linearGradient2108"
+       x1="14.000000"
+       y1="21.062500"
+       x2="14.000000"
+       y2="32.875000"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,1.033654,1.500000,-0.627404)" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2102"
+       id="linearGradient2112"
+       gradientUnits="userSpaceOnUse"
+       x1="14.000000"
+       y1="21.062500"
+       x2="14"
+       y2="34.305527"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,1.404523,10.50000,-7.966331)" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2102"
+       id="linearGradient2116"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,1.171895,2.500000,-3.141166)"
+       x1="14.000000"
+       y1="21.062500"
+       x2="13.500000"
+       y2="33.426670" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2102"
+       id="linearGradient2120"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,1.159815,18.50000,-2.815047)"
+       x1="14.000000"
+       y1="21.062500"
+       x2="14.500000"
+       y2="33.431156" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient2102"
+       id="linearGradient2124"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.000000,0.000000,0.000000,1.071351,-22.50000,-3.854623)"
+       x1="14.000000"
+       y1="21.062500"
+       x2="14.000000"
+       y2="35.744175" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3068"
+       id="linearGradient2132"
+       x1="9.7892637"
+       y1="29.629091"
+       x2="38.390732"
+       y2="29.629091"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="matrix(1.048897,0.000000,0.000000,1.000000,-1.267931,0.000000)" />
+  </defs>
+  <sodipodi:namedview
+     fill="#a40000"
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="0.19607843"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="1"
+     inkscape:cx="23.514119"
+     inkscape:cy="28.588454"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:grid-bbox="true"
+     inkscape:document-units="px"
+     inkscape:showpageshadow="false"
+     inkscape:window-width="1010"
+     inkscape:window-height="1181"
+     inkscape:window-x="123"
+     inkscape:window-y="34"
+     stroke="#8f5902" />
+  <metadata
+     id="metadata4">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title>Face - Laughing</dc:title>
+        <dc:subject>
+          <rdf:Bag>
+            <rdf:li>emoticon</rdf:li>
+            <rdf:li>emote</rdf:li>
+            <rdf:li>smiley</rdf:li>
+            <rdf:li>laughing</rdf:li>
+            <rdf:li>:-D</rdf:li>
+            <rdf:li>:D</rdf:li>
+          </rdf:Bag>
+        </dc:subject>
+        <cc:license
+           rdf:resource="http://creativecommons.org/licenses/by-sa/2.0/" />
+        <dc:creator>
+          <cc:Agent>
+            <dc:title>Jakub Steiner</dc:title>
+          </cc:Agent>
+        </dc:creator>
+        <dc:source>http://jimmac.musichall.cz</dc:source>
+        <dc:contributor>
+          <cc:Agent>
+            <dc:title>Tuomas Kuosmanen</dc:title>
+          </cc:Agent>
+        </dc:contributor>
+      </cc:Work>
+      <cc:License
+         rdf:about="http://creativecommons.org/licenses/by-sa/2.0/">
+        <cc:permits
+           rdf:resource="http://web.resource.org/cc/Reproduction" />
+        <cc:permits
+           rdf:resource="http://web.resource.org/cc/Distribution" />
+        <cc:requires
+           rdf:resource="http://web.resource.org/cc/Notice" />
+        <cc:requires
+           rdf:resource="http://web.resource.org/cc/Attribution" />
+        <cc:permits
+           rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+        <cc:requires
+           rdf:resource="http://web.resource.org/cc/ShareAlike" />
+      </cc:License>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer">
+    <path
+       sodipodi:type="arc"
+       style="opacity:0.53164560;color:#000000;fill:url(#radialGradient1360);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.40487173;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;visibility:visible;display:inline;overflow:visible"
+       id="path4563"
+       sodipodi:cx="24.714285"
+       sodipodi:cy="38.571430"
+       sodipodi:rx="19.714285"
+       sodipodi:ry="6.5714288"
+       d="M 44.428570 38.571430 A 19.714285 6.5714288 0 1 1  5.0000000,38.571430 A 19.714285 6.5714288 0 1 1  44.428570 38.571430 z" />
+    <path
+       sodipodi:type="arc"
+       style="opacity:1.0000000;color:#000000;fill:url(#radialGradient1362);fill-opacity:1.0000000;fill-rule:evenodd;stroke:#9c8c0a;stroke-width:0.48004404;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;visibility:visible;display:inline;overflow:visible"
+       id="path4320"
+       sodipodi:cx="31.112698"
+       sodipodi:cy="19.008621"
+       sodipodi:rx="8.6620579"
+       sodipodi:ry="8.6620579"
+       d="M 39.774755 19.008621 A 8.6620579 8.6620579 0 1 1  22.450640,19.008621 A 8.6620579 8.6620579 0 1 1  39.774755 19.008621 z"
+       transform="matrix(2.083142,0.000000,0.000000,2.083142,-40.54715,-16.49224)" />
+    <path
+       d="M 39.774755 19.008621 A 8.6620579 8.6620579 0 1 1  22.450640,19.008621 A 8.6620579 8.6620579 0 1 1  39.774755 19.008621 z"
+       sodipodi:ry="8.6620579"
+       sodipodi:rx="8.6620579"
+       sodipodi:cy="19.008621"
+       sodipodi:cx="31.112698"
+       id="path4322"
+       style="opacity:0.67721522;color:#000000;fill:none;fill-opacity:1.0000000;fill-rule:evenodd;stroke:#ffffff;stroke-width:0.50510627;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;visibility:visible;display:inline;overflow:visible"
+       sodipodi:type="arc"
+       transform="matrix(1.979782,0.000000,0.000000,1.979782,-37.33128,-14.52746)" />
+    <path
+       sodipodi:type="arc"
+       style="fill:none;fill-opacity:1.0000000;stroke:#555753;stroke-width:1.0000000;stroke-linecap:butt;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000"
+       id="path1364"
+       sodipodi:cx="-3.8125000"
+       sodipodi:cy="1.8750000"
+       sodipodi:rx="2.9375000"
+       sodipodi:ry="2.8750000"
+       d="M -0.87500000,1.8750000 A 2.9375000,2.8750000 0 0 1 -6.3564497,3.3124999"
+       sodipodi:start="0.0000000"
+       sodipodi:end="2.6179939"
+       sodipodi:open="true"
+       transform="matrix(-0.965926,-0.258819,0.258819,-0.965926,24.53442,17.20131)" />
+    <path
+       transform="matrix(-0.965926,-0.258819,0.258819,-0.965926,15.78442,17.20131)"
+       sodipodi:open="true"
+       sodipodi:end="2.6179939"
+       sodipodi:start="0.0000000"
+       d="M -0.87500000,1.8750000 A 2.9375000,2.8750000 0 0 1 -6.3564497,3.3124999"
+       sodipodi:ry="2.8750000"
+       sodipodi:rx="2.9375000"
+       sodipodi:cy="1.8750000"
+       sodipodi:cx="-3.8125000"
+       id="path2094"
+       style="fill:none;fill-opacity:1.0000000;stroke:#555753;stroke-width:1.0000000;stroke-linecap:butt;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000"
+       sodipodi:type="arc" />
+    <path
+       sodipodi:nodetypes="czcc"
+       id="path2096"
+       d="M 9.1875355,21.044769 C 7.6485541,28.612147 13.879571,38.212295 24.038687,38.212295 C 34.286185,38.212295 40.544215,29.781871 38.758727,21.107269 L 9.1875355,21.044769 z "
+       style="opacity:1.0000000;color:#000000;fill:url(#linearGradient2132);fill-opacity:1.0000000;fill-rule:nonzero;stroke:none;stroke-width:1.0000001;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;visibility:visible;display:inline;overflow:visible" />
+    <path
+       id="path2110"
+       d="M 24.500000,21.528657 L 24.500000,38.382936"
+       style="opacity:0.18181818;fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:url(#linearGradient2112);stroke-width:0.99999988px;stroke-linecap:square;stroke-linejoin:miter;stroke-opacity:1.0000000" />
+    <path
+       style="opacity:0.18181818;fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:url(#linearGradient2116);stroke-width:1.0000002px;stroke-linecap:square;stroke-linejoin:miter;stroke-opacity:1.0000000"
+       d="M 16.500000,21.468635 L 16.500000,35.531381"
+       id="path2114" />
+    <path
+       id="path2118"
+       d="M 32.500000,21.541107 L 32.500000,35.458909"
+       style="opacity:0.18181818;fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:url(#linearGradient2120);stroke-width:1.0000005px;stroke-linecap:square;stroke-linejoin:miter;stroke-opacity:1.0000000" />
+    <path
+       style="opacity:1.0000000;color:#000000;fill:none;fill-opacity:1.0000000;fill-rule:nonzero;stroke:#8f5902;stroke-width:0.99999994;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.0000000;stroke-opacity:1.0000000;visibility:visible;display:inline;overflow:visible"
+       d="M 9.4409398,20.615864 C 7.6602852,29.43779 14.599952,38.703673 24.250001,38.703673 C 34.253546,38.703673 40.902217,29.12529 38.621563,20.553364 L 9.4409398,20.615864 z "
+       id="path2756"
+       sodipodi:nodetypes="czcc" />
+  </g>
+</svg>
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
new file mode 100644
index 0000000..ab43965
--- /dev/null
+++ b/panel-plugin/Makefile.am
@@ -0,0 +1,57 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	-DG_LOG_DOMAIN=\"xfce4-notification-plugin\" \
+	-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+	$(PLATFORM_CPPFLAGS)
+
+#
+# Notification plugin
+#
+plugin_LTLIBRARIES = \
+	libnotification-plugin.la
+
+plugindir = \
+	$(libdir)/xfce4/panel/plugins
+
+libnotification_plugin_la_SOURCES = \
+	notification-plugin.c \
+	notification-plugin.h \
+	notification-plugin-dialogs.c \
+	notification-plugin-dialogs.h
+
+libnotification_plugin_la_CFLAGS = \
+	$(LIBXFCE4UTIL_CFLAGS) \
+	$(LIBXFCE4UI_CFLAGS) \
+	$(LIBXFCE4PANEL_CFLAGS) \
+	$(PLATFORM_CFLAGS)
+
+libnotification_plugin_la_LDFLAGS = \
+       -avoid-version \
+       -module \
+       -no-undefined \
+       -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \
+       $(PLATFORM_LDFLAGS)
+
+libnotification_plugin_la_LIBADD = \
+	$(LIBXFCE4UTIL_LIBS) \
+	$(LIBXFCE4UI_LIBS) \
+	$(LIBXFCE4PANEL_LIBS)
+
+#
+# Desktop file
+#
+desktopdir =								\
+	$(datadir)/xfce4/panel/plugins
+
+desktop_DATA =								\
+	notification-plugin.desktop
+
+ at INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST =								\
+	notification-plugin.desktop.in
+
+CLEANFILES =								\
+	$(desktop_DATA)
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/panel-plugin/notification-plugin-dialogs.c b/panel-plugin/notification-plugin-dialogs.c
new file mode 100644
index 0000000..90767ad
--- /dev/null
+++ b/panel-plugin/notification-plugin-dialogs.c
@@ -0,0 +1,126 @@
+/*  $Id$
+ *
+ *  Copyright (C) 2017 Simon Steinbeiss <simon at xfce.org>
+ *
+ *  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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <gtk/gtk.h>
+
+#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+#include "notification-plugin.h"
+#include "notification-plugin-dialogs.h"
+
+/* the website url */
+#define PLUGIN_WEBSITE "http://goodies.xfce.org/projects/panel-plugins/xfce4-sample-plugin"
+
+
+
+static void
+notification_plugin_configure_response (GtkWidget    *dialog,
+                           gint          response,
+                           NotificationPlugin *notification_plugin)
+{
+  gboolean result;
+
+  if (response == GTK_RESPONSE_HELP)
+    {
+      /* show help */
+      result = g_spawn_command_line_async ("exo-open --launch WebBrowser " PLUGIN_WEBSITE, NULL);
+
+      if (G_UNLIKELY (result == FALSE))
+        g_warning (_("Unable to open the following url: %s"), PLUGIN_WEBSITE);
+    }
+  else
+    {
+      /* remove the dialog data from the plugin */
+      g_object_set_data (G_OBJECT (notification_plugin->plugin), "dialog", NULL);
+
+      /* unlock the panel menu */
+      xfce_panel_plugin_unblock_menu (notification_plugin->plugin);
+
+      /* save the plugin */
+      notification_plugin_save (notification_plugin->plugin, notification_plugin);
+
+      /* destroy the properties dialog */
+      gtk_widget_destroy (dialog);
+    }
+}
+
+
+
+void
+notification_plugin_configure (XfcePanelPlugin *plugin,
+                  NotificationPlugin    *notification_plugin)
+{
+  GtkWidget *dialog;
+
+  /* block the plugin menu */
+  xfce_panel_plugin_block_menu (plugin);
+
+  /* create the dialog */
+  dialog = xfce_titled_dialog_new_with_buttons (_("Notification Plugin"),
+                                                GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+                                                GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                "gtk-help", GTK_RESPONSE_HELP,
+                                                "gtk-close", GTK_RESPONSE_OK,
+                                                NULL);
+
+  /* center dialog on the screen */
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+
+  /* set dialog icon */
+  gtk_window_set_icon_name (GTK_WINDOW (dialog), ICON_NAME);
+
+  /* link the dialog to the plugin, so we can destroy it when the plugin
+   * is closed, but the dialog is still open */
+  g_object_set_data (G_OBJECT (plugin), "dialog", dialog);
+
+  /* connect the reponse signal to the dialog */
+  g_signal_connect (G_OBJECT (dialog), "response",
+                    G_CALLBACK(notification_plugin_configure_response), notification_plugin);
+
+  /* show the entire dialog */
+  gtk_widget_show (dialog);
+}
+
+
+
+void
+notification_plugin_about (XfcePanelPlugin *plugin)
+{
+  const gchar *auth[] =
+    {
+      "Simon Steinbeiss <simon at xfce.org>",
+      NULL
+    };
+  gtk_show_about_dialog (NULL,
+                         "logo-icon-name",         ICON_NAME,
+                         "license",                xfce_get_license_text (XFCE_LICENSE_TEXT_GPL),
+                         "version",                PACKAGE_VERSION,
+                         "program-name",           PACKAGE_NAME,
+                         "comments",               _("This is the notification plugin"),
+                         "website",                PLUGIN_WEBSITE,
+                         "copyright",              _("Copyright \xc2\xa9 2017 Simon Steinbeiss\n"),
+                         "authors",                auth,
+                         NULL);
+}
diff --git a/panel-plugin/notification-plugin-dialogs.h b/panel-plugin/notification-plugin-dialogs.h
new file mode 100644
index 0000000..81ac252
--- /dev/null
+++ b/panel-plugin/notification-plugin-dialogs.h
@@ -0,0 +1,34 @@
+/*  $Id$
+ *
+ *  Copyright (C) 2017 Simon Steinbeiss <simon at xfce.org>
+ *
+ *  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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __NOTIFICATION_PLUGIN_DIALOGS_H__
+#define __NOTIFICATION_PLUGIN_DIALOGS_H__
+
+G_BEGIN_DECLS
+
+void
+notification_plugin_configure    (XfcePanelPlugin *plugin,
+                     NotificationPlugin    *notification_plugin);
+
+void
+notification_plugin_about        (XfcePanelPlugin *plugin);
+
+G_END_DECLS
+
+#endif
diff --git a/panel-plugin/notification-plugin.c b/panel-plugin/notification-plugin.c
new file mode 100644
index 0000000..cce9f16
--- /dev/null
+++ b/panel-plugin/notification-plugin.c
@@ -0,0 +1,391 @@
+/*  $Id$
+ *
+ *  Copyright (C) 2017 Simon Steinbeiss <simon at xfce.org>
+ *
+ *  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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+#include "notification-plugin.h"
+#include "notification-plugin-dialogs.h"
+
+/* default settings */
+#define DEFAULT_SETTING1 NULL
+#define DEFAULT_SETTING2 1
+#define DEFAULT_SETTING3 FALSE
+
+
+
+/* prototypes */
+static void
+notification_plugin_construct (XfcePanelPlugin *panel_plugin);
+
+
+/* register the plugin */
+XFCE_PANEL_PLUGIN_REGISTER (notification_plugin_construct);
+
+
+
+void
+notification_plugin_save (XfcePanelPlugin *plugin,
+                          NotificationPlugin    *notification_plugin)
+{
+  XfceRc *rc;
+  gchar  *file;
+
+  /* get the config file location */
+  file = xfce_panel_plugin_save_location (plugin, TRUE);
+
+  if (G_UNLIKELY (file == NULL))
+    {
+       DBG ("Failed to open config file");
+       return;
+    }
+
+  /* open the config file, read/write */
+  rc = xfce_rc_simple_open (file, FALSE);
+  g_free (file);
+
+  if (G_LIKELY (rc != NULL))
+    {
+      /* save the settings */
+      DBG(".");
+      if (notification_plugin->setting1)
+        xfce_rc_write_entry    (rc, "setting1", notification_plugin->setting1);
+
+      xfce_rc_write_int_entry  (rc, "setting2", notification_plugin->setting2);
+      xfce_rc_write_bool_entry (rc, "setting3", notification_plugin->setting3);
+
+      /* close the rc file */
+      xfce_rc_close (rc);
+    }
+}
+
+
+
+static void
+notification_plugin_read (NotificationPlugin *notification_plugin)
+{
+  XfceRc      *rc;
+  gchar       *file;
+  const gchar *value;
+
+  /* get the plugin config file location */
+  file = xfce_panel_plugin_save_location (notification_plugin->plugin, TRUE);
+
+  if (G_LIKELY (file != NULL))
+    {
+      /* open the config file, readonly */
+      rc = xfce_rc_simple_open (file, TRUE);
+
+      /* cleanup */
+      g_free (file);
+
+      if (G_LIKELY (rc != NULL))
+        {
+          /* read the settings */
+          value = xfce_rc_read_entry (rc, "setting1", DEFAULT_SETTING1);
+          notification_plugin->setting1 = g_strdup (value);
+
+          notification_plugin->setting2 = xfce_rc_read_int_entry (rc, "setting2", DEFAULT_SETTING2);
+          notification_plugin->setting3 = xfce_rc_read_bool_entry (rc, "setting3", DEFAULT_SETTING3);
+
+          /* cleanup */
+          xfce_rc_close (rc);
+
+          /* leave the function, everything went well */
+          return;
+        }
+    }
+
+  /* something went wrong, apply default values */
+  DBG ("Applying default settings");
+
+  notification_plugin->setting1 = g_strdup (DEFAULT_SETTING1);
+  notification_plugin->setting2 = DEFAULT_SETTING2;
+  notification_plugin->setting3 = DEFAULT_SETTING3;
+}
+
+
+
+GtkWidget *
+notification_plugin_menu_new (/* arguments */)
+{
+  GtkWidget *menu;
+  GtkWidget *mi;
+
+  menu = gtk_menu_new ();
+  /* Footer items */
+  mi = gtk_separator_menu_item_new ();
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+  mi = gtk_menu_item_new_with_label ("This is a notification.");
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+  /* Show all the items */
+  gtk_widget_show_all (GTK_WIDGET (menu));
+  return menu;
+}
+
+
+
+void
+notification_plugin_popup_menu (NotificationPlugin *notification_plugin)
+{
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notification_plugin->button), TRUE);
+  gtk_menu_set_screen (GTK_MENU (notification_plugin->menu),
+                       gtk_widget_get_screen (notification_plugin->button));
+  gtk_menu_popup (GTK_MENU (notification_plugin->menu), NULL, NULL,
+                  notification_plugin->menu_position_func, notification_plugin,
+                  0, gtk_get_current_event_time ());
+  xfce_panel_plugin_register_menu (notification_plugin->plugin,
+                                   GTK_MENU (notification_plugin->menu));
+}
+
+
+
+static gboolean
+cb_button_pressed (GtkButton *button,
+                   GdkEventButton *event,
+                   NotificationPlugin *notification_plugin)
+{
+  if (event->button != 1 && !(event->state & GDK_CONTROL_MASK))
+    return FALSE;
+  if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+    notification_plugin_popup_menu (notification_plugin);
+
+  return TRUE;
+}
+
+
+
+static void
+cb_menu_deactivate (GtkMenuShell *menu,
+                    NotificationPlugin *notification_plugin)
+{
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notification_plugin->button), FALSE);
+}
+
+
+
+static void
+my_plugin_position_menu (GtkMenu *menu,
+                         gint *x,
+                         gint *y,
+                         gboolean *push_in,
+                         NotificationPlugin *notification_plugin)
+{
+  gboolean above = TRUE;
+  gint button_width, button_height;
+  GtkRequisition minimum_size;
+  GtkRequisition natural_size;
+  XfceScreenPosition screen_position;
+
+  g_return_if_fail (XFCE_IS_PANEL_PLUGIN (notification_plugin->plugin));
+
+  screen_position = xfce_panel_plugin_get_screen_position (notification_plugin->plugin);
+  gtk_widget_get_size_request (notification_plugin->button, &button_width, &button_height);
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu), &minimum_size, &natural_size);
+  gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (notification_plugin->plugin)), x, y);
+
+  switch (screen_position)
+    {
+      case XFCE_SCREEN_POSITION_NW_H:
+      case XFCE_SCREEN_POSITION_N:
+      case XFCE_SCREEN_POSITION_NE_H:
+        above = FALSE;
+      case XFCE_SCREEN_POSITION_SW_H:
+      case XFCE_SCREEN_POSITION_S:
+      case XFCE_SCREEN_POSITION_SE_H:
+        if (above)
+          /* Show menu above */
+          *y -= minimum_size.height;
+        else
+          /* Show menu below */
+          *y += button_height;
+
+        if (*x + minimum_size.width > gdk_screen_width ())
+          /* Adjust horizontal position */
+          *x = gdk_screen_width () - minimum_size.width;
+
+        break;
+
+      default:
+        if (*x + button_width + minimum_size.width > gdk_screen_width ())
+          /* Show menu on the right */
+          *x -= minimum_size.width;
+        else
+          /* Show menu on the left */
+          *x += button_width;
+
+        if (*y + minimum_size.height > gdk_screen_height ())
+          /* Adjust vertical position */
+          *y = gdk_screen_height () - minimum_size.height;
+
+        break;
+    }
+}
+
+
+
+static NotificationPlugin *
+notification_plugin_new (XfcePanelPlugin *panel_plugin)
+{
+  NotificationPlugin   *notification_plugin;
+  GtkOrientation  orientation;
+  GtkWidget      *label;
+
+  /* allocate memory for the plugin structure */
+  notification_plugin = panel_slice_new0 (NotificationPlugin);
+
+  /* pointer to plugin */
+  notification_plugin->plugin = panel_plugin;
+
+  /* read the user settings */
+  notification_plugin_read (notification_plugin);
+
+  /* get the current orientation */
+  orientation = xfce_panel_plugin_get_orientation (panel_plugin);
+
+  notification_plugin->menu_position_func = (GtkMenuPositionFunc)my_plugin_position_menu;
+
+  /* create some panel widgets */
+  xfce_panel_plugin_set_small (panel_plugin, TRUE);
+  notification_plugin->button = xfce_panel_create_toggle_button ();
+  gtk_widget_set_tooltip_text (GTK_WIDGET (notification_plugin->button), _("Notifications"));
+  notification_plugin->image = gtk_image_new_from_icon_name (ICON_NAME, GTK_ICON_SIZE_MENU);
+  gtk_container_add (GTK_CONTAINER (notification_plugin->button), notification_plugin->image);
+  gtk_container_add (GTK_CONTAINER (panel_plugin), notification_plugin->button);
+  gtk_widget_show_all (GTK_WIDGET (notification_plugin->button));
+  gtk_widget_set_name (GTK_WIDGET (notification_plugin->button), "xfce4-notification-plugin");
+
+  /* create the menu */
+  notification_plugin->menu = notification_plugin_menu_new ();
+
+  g_signal_connect (notification_plugin->button, "button-press-event",
+                    G_CALLBACK (cb_button_pressed), notification_plugin);
+  g_signal_connect (notification_plugin->menu, "deactivate",
+                    G_CALLBACK (cb_menu_deactivate), notification_plugin);
+
+  return notification_plugin;
+}
+
+
+
+static void
+notification_plugin_free (XfcePanelPlugin *plugin,
+             NotificationPlugin    *notification_plugin)
+{
+  GtkWidget *dialog;
+
+  /* check if the dialog is still open. if so, destroy it */
+  dialog = g_object_get_data (G_OBJECT (plugin), "dialog");
+  if (G_UNLIKELY (dialog != NULL))
+    gtk_widget_destroy (dialog);
+
+  /* destroy the panel widgets */
+  gtk_widget_destroy (notification_plugin->button);
+
+  /* cleanup the settings */
+  if (G_LIKELY (notification_plugin->setting1 != NULL))
+    g_free (notification_plugin->setting1);
+
+  /* free the plugin structure */
+  panel_slice_free (NotificationPlugin, notification_plugin);
+}
+
+
+
+static void
+notification_plugin_orientation_changed (XfcePanelPlugin *plugin,
+                            GtkOrientation   orientation,
+                            NotificationPlugin    *notification_plugin)
+{
+  /* change the orienation of the box */
+  gtk_orientable_set_orientation(GTK_ORIENTABLE(notification_plugin->button), orientation);
+}
+
+
+
+static gboolean
+notification_plugin_size_changed (XfcePanelPlugin *plugin,
+                     gint             size,
+                     NotificationPlugin    *notification_plugin)
+{
+  GtkOrientation orientation;
+
+  /* get the orientation of the plugin */
+  orientation = xfce_panel_plugin_get_orientation (plugin);
+
+  /* set the widget size */
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
+  else
+    gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
+
+  /* we handled the orientation */
+  return TRUE;
+}
+
+
+
+static void
+notification_plugin_construct (XfcePanelPlugin *plugin)
+{
+  NotificationPlugin *notification_plugin;
+
+  /* setup transation domain */
+  xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+  /* create the plugin */
+  notification_plugin = notification_plugin_new (plugin);
+
+  /* add the button to the panel */
+  gtk_container_add (GTK_CONTAINER (plugin), notification_plugin->button);
+
+  /* show the panel's right-click menu on this ebox */
+  xfce_panel_plugin_add_action_widget (plugin, notification_plugin->button);
+
+  /* connect plugin signals */
+  g_signal_connect (G_OBJECT (plugin), "free-data",
+                    G_CALLBACK (notification_plugin_free), notification_plugin);
+
+  g_signal_connect (G_OBJECT (plugin), "save",
+                    G_CALLBACK (notification_plugin_save), notification_plugin);
+
+  g_signal_connect (G_OBJECT (plugin), "size-changed",
+                    G_CALLBACK (notification_plugin_size_changed), notification_plugin);
+
+  g_signal_connect (G_OBJECT (plugin), "orientation-changed",
+                    G_CALLBACK (notification_plugin_orientation_changed), notification_plugin);
+
+  /* show the configure menu item and connect signal */
+  xfce_panel_plugin_menu_show_configure (plugin);
+  g_signal_connect (G_OBJECT (plugin), "configure-plugin",
+                    G_CALLBACK (notification_plugin_configure), notification_plugin);
+
+  /* show the about menu item and connect signal */
+  xfce_panel_plugin_menu_show_about (plugin);
+  g_signal_connect (G_OBJECT (plugin), "about",
+                    G_CALLBACK (notification_plugin_about), NULL);
+}
diff --git a/panel-plugin/notification-plugin.desktop.in b/panel-plugin/notification-plugin.desktop.in
new file mode 100644
index 0000000..9f8ca60
--- /dev/null
+++ b/panel-plugin/notification-plugin.desktop.in
@@ -0,0 +1,10 @@
+[Xfce Panel]
+Type=X-XFCE-PanelPlugin
+Encoding=UTF-8
+_Name=Notification Plugin
+_Comment=Notification plugin for the Xfce panel
+Icon=preferences-system-notifications
+X-XFCE-Module=notification-plugin
+X-XFCE-Internal=false
+X-XFCE-Unique=false
+X-XFCE-API=2.0
diff --git a/panel-plugin/notification-plugin.h b/panel-plugin/notification-plugin.h
new file mode 100644
index 0000000..2692a0e
--- /dev/null
+++ b/panel-plugin/notification-plugin.h
@@ -0,0 +1,53 @@
+/*  $Id$
+ *
+ *  Copyright (C) 2017 Simon Steinbeiss <simon at xfce.org>
+ *
+ *  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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __NOTIFICATION_PLUGIN_H__
+#define __NOTIFICATION_PLUGIN_H__
+
+G_BEGIN_DECLS
+
+#define ICON_NAME "preferences-system-notifications"
+
+/* plugin structure */
+typedef struct
+{
+    XfcePanelPlugin *plugin;
+
+    /* panel widgets */
+    GtkWidget       *button;
+    GtkWidget       *image;
+    GtkWidget       *menu;
+    GtkMenuPositionFunc   menu_position_func;
+
+    /* sample settings */
+    gchar           *setting1;
+    gint             setting2;
+    gboolean         setting3;
+}
+NotificationPlugin;
+
+
+
+void
+notification_plugin_save (XfcePanelPlugin *plugin,
+                          NotificationPlugin    *notification_plugin);
+
+G_END_DECLS
+
+#endif /* !__NOTIFICATION_PLUGIN_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list