[gnome-panel/wip/status-notifier: 10/13] snh: initial version



commit 28e1068e5d9d66f36415a4d3a56198fe50bfc5c4
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Jun 22 00:16:08 2015 +0300

    snh: initial version

 applets/Makefile.am                                |    1 +
 applets/snh/Makefile.am                            |   57 ++++++++++
 .../org.gnome.panel.SnhApplet.panel-applet.in.in   |   16 +++
 applets/snh/snh-applet.c                           |  117 ++++++++++++++++++++
 applets/snh/snh-applet.h                           |   44 ++++++++
 configure.ac                                       |    6 +
 6 files changed, 241 insertions(+), 0 deletions(-)
---
diff --git a/applets/Makefile.am b/applets/Makefile.am
index e1e952d..021d35e 100644
--- a/applets/Makefile.am
+++ b/applets/Makefile.am
@@ -2,6 +2,7 @@ SUBDIRS =                       \
        clock                   \
        fish                    \
        notification_area       \
+       snh                     \
        wncklet
 
 -include $(top_srcdir)/git.mk
diff --git a/applets/snh/Makefile.am b/applets/snh/Makefile.am
new file mode 100644
index 0000000..c949cc8
--- /dev/null
+++ b/applets/snh/Makefile.am
@@ -0,0 +1,57 @@
+NULL =
+
+AM_CPPFLAGS = \
+       $(LIBPANEL_APPLET_CFLAGS) \
+       $(SNH_CFLAGS) \
+       -I$(srcdir) \
+       -I$(srcdir)/../../libpanel-applet \
+       -I$(top_builddir)/libpanel-applet \
+       -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+       $(NULL)
+
+AM_CFLAGS = \
+       $(WARN_CFLAGS) \
+       $(NULL)
+
+SNH_SOURCES = \
+       snh-applet.c \
+       snh-applet.h \
+       $(NULL)
+
+SNH_LDADD = \
+       ../../libpanel-applet/libpanel-applet.la \
+       $(SNH_LIBS) \
+       $(LIBPANEL_APPLET_LIBS) \
+       $(NULL)
+
+APPLET_LOCATION = $(pkglibdir)/$(LIBPANEL_APPLET_API_VERSION)/libsnh-applet.so
+
+snh_applet_libdir = $(pkglibdir)/$(LIBPANEL_APPLET_API_VERSION)
+snh_applet_lib_LTLIBRARIES = libsnh-applet.la
+libsnh_applet_la_SOURCES = $(SNH_SOURCES)
+libsnh_applet_la_LIBADD = $(SNH_LDADD)
+libsnh_applet_la_LDFLAGS = -module -avoid-version
+libsnh_applet_la_CFLAGS = $(AM_CFLAGS)
+
+appletdir       = $(appletsdir)
+applet_in_files = org.gnome.panel.SnhApplet.panel-applet.in
+applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
+
+$(applet_in_files): $(applet_in_files).in Makefile
+       $(AM_V_GEN)sed \
+               -e "s|\ LOCATION\@|$(APPLET_LOCATION)|" \
+               -e "s|\ VERSION\@|$(PACKAGE_VERSION)|" \
+               $< > $@
+
+ PANEL_INTLTOOL_PANEL_APPLET_RULE@
+
+EXTRA_DIST = \
+       org.gnome.panel.SnhApplet.panel-applet.in.in \
+       $(NULL)
+
+CLEANFILES = \
+       $(applet_DATA) \
+       $(applet_DATA).in \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/applets/snh/org.gnome.panel.SnhApplet.panel-applet.in.in 
b/applets/snh/org.gnome.panel.SnhApplet.panel-applet.in.in
new file mode 100644
index 0000000..031b1f0
--- /dev/null
+++ b/applets/snh/org.gnome.panel.SnhApplet.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=SnhAppletFactory
+InProcess=true
+Location= LOCATION@
+_Name=Status Notifier Host Applet Factory
+_Description=Factory for status notifier host applet
+
+[SnhApplet]
+_Name=Status Notifier Host
+_Description=Display all Status Notifier Items
+Icon=
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-panel
+X-GNOME-Bugzilla-Component=snh-applet
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=snh-applet
diff --git a/applets/snh/snh-applet.c b/applets/snh/snh-applet.c
new file mode 100644
index 0000000..a795fd5
--- /dev/null
+++ b/applets/snh/snh-applet.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2015 Alberts Muktupāvels
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <libstatus-notifier/sn.h>
+
+#include "snh-applet.h"
+
+struct _SnhApplet
+{
+  PanelApplet  parent;
+
+  SnHost      *host;
+
+  GtkWidget   *label;
+};
+
+G_DEFINE_TYPE (SnhApplet, snh_applet, PANEL_TYPE_APPLET)
+
+static void
+items_changed_cb (SnHost   *host,
+                  gpointer  user_data)
+{
+  SnhApplet *applet;
+  GList *list;
+  gchar *text;
+
+  applet = SNH_APPLET (user_data);
+
+  list = sn_host_get_items (host);
+
+  text = g_strdup_printf ("Items: %d", g_list_length (list));
+  g_list_free (list);
+
+  gtk_label_set_text (GTK_LABEL (applet->label), text);
+  g_free (text);
+}
+
+static gboolean
+snh_applet_fill (SnhApplet *applet)
+{
+  applet->label = gtk_label_new ("Items: 0");
+
+  gtk_container_add (GTK_CONTAINER (applet), applet->label);
+  gtk_widget_show (applet->label);
+
+  gtk_widget_show (GTK_WIDGET (applet));
+
+  return TRUE;
+}
+
+static gboolean
+snh_applet_factory (PanelApplet *applet,
+                    const gchar *iid,
+                    gpointer     user_data)
+{
+  if (g_strcmp0 (iid, "SnhApplet") == 0)
+    return snh_applet_fill (SNH_APPLET (applet));
+
+  return FALSE;
+}
+
+static void
+snh_applet_finalize (GObject *object)
+{
+  SnhApplet *applet;
+
+  applet = SNH_APPLET (object);
+
+  g_clear_object (&applet->host);
+
+  G_OBJECT_CLASS (snh_applet_parent_class)->finalize (object);
+}
+
+static void
+snh_applet_class_init (SnhAppletClass *applet_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (applet_class);
+
+  object_class->finalize = snh_applet_finalize;
+}
+
+static void
+snh_applet_init (SnhApplet *applet)
+{
+  PanelApplet *panel_applet;
+
+  panel_applet = PANEL_APPLET (applet);
+
+  applet->host = sn_host_new ();
+
+  g_signal_connect (applet->host, "items-changed",
+                    G_CALLBACK (items_changed_cb), applet);
+
+  panel_applet_set_flags (panel_applet, PANEL_APPLET_HAS_HANDLE |
+                          PANEL_APPLET_EXPAND_MINOR);
+}
+
+PANEL_APPLET_IN_PROCESS_FACTORY ("SnhAppletFactory", SNH_TYPE_APPLET,
+                                 snh_applet_factory, NULL);
diff --git a/applets/snh/snh-applet.h b/applets/snh/snh-applet.h
new file mode 100644
index 0000000..523761e
--- /dev/null
+++ b/applets/snh/snh-applet.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 Alberts Muktupāvels
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SNH_APPLET_H
+#define SNH_APPLET_H
+
+#include <panel-applet.h>
+
+G_BEGIN_DECLS
+
+#define SNH_TYPE_APPLET            (snh_applet_get_type())
+#define SNH_APPLET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SNH_TYPE_APPLET, SnhApplet))
+#define SNH_APPLET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  SNH_TYPE_APPLET, SnhAppletClass))
+#define SNH_IS_APPLET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SNH_TYPE_APPLET))
+#define SNH_IS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  SNH_TYPE_APPLET))
+#define SNH_APPLET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),   SNH_TYPE_APPLET, SnhAppletClass))
+
+typedef struct _SnhApplet      SnhApplet;
+typedef struct _SnhAppletClass SnhAppletClass;
+
+struct _SnhAppletClass
+{
+  PanelAppletClass parent_class;
+};
+
+GType snh_applet_get_type (void);
+
+G_END_DECLS
+
+#endif
diff --git a/configure.ac b/configure.ac
index 3fbcad9..64bc78d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,6 +72,7 @@ GLIB_REQUIRED=2.36.0
 GTK_REQUIRED=3.15.2
 LIBWNCK_REQUIRED=3.4.6
 LIBGNOME_MENU_REQUIRED=3.7.90
+LIBSTATUS_NOTIFIER_REQUIRED=3.17.0
 TELEPATHY_GLIB_REQUIRED=0.14.0
 LIBECAL_REQUIRED=3.5.3
 LIBEDATASERVER_REQUIRED=3.5.3
@@ -118,6 +119,10 @@ PKG_CHECK_MODULES(NOTIFICATION_AREA, gtk+-3.0 >= $GTK_REQUIRED)
 AC_SUBST(NOTIFICATION_AREA_CFLAGS)
 AC_SUBST(NOTIFICATION_AREA_LIBS)
 
+PKG_CHECK_MODULES(SNH, gtk+-3.0 >= $GTK_REQUIRED libstatus-notifier-3.0 >= $LIBSTATUS_NOTIFIER_REQUIRED)
+AC_SUBST(SNH_CFLAGS)
+AC_SUBST(SNH_LIBS)
+
 PKG_CHECK_MODULES(WNCKLET, gtk+-3.0 >= $GTK_REQUIRED libwnck-3.0 >= $LIBWNCK_REQUIRED)
 AC_SUBST(WNCKLET_CFLAGS)
 AC_SUBST(WNCKLET_LIBS)
@@ -248,6 +253,7 @@ applets/clock/Makefile
 applets/clock/pixmaps/Makefile
 applets/fish/Makefile
 applets/notification_area/Makefile
+applets/snh/Makefile
 applets/wncklet/Makefile
 doc/Makefile
 doc/reference/Makefile


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