[gnome-panel/wip/status-notifier] snh: show item titles
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/status-notifier] snh: show item titles
- Date: Sat, 27 Jun 2015 23:53:59 +0000 (UTC)
commit c616dc8556f78410ed72364b4da0ce5aa72f358d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Jun 28 02:48:44 2015 +0300
snh: show item titles
applets/snh/Makefile.am | 2 +
applets/snh/snh-applet.c | 35 ++++++++-------
applets/snh/snh-item.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++
applets/snh/snh-item.h | 33 ++++++++++++++
4 files changed, 164 insertions(+), 16 deletions(-)
---
diff --git a/applets/snh/Makefile.am b/applets/snh/Makefile.am
index c949cc8..af4e8d9 100644
--- a/applets/snh/Makefile.am
+++ b/applets/snh/Makefile.am
@@ -16,6 +16,8 @@ AM_CFLAGS = \
SNH_SOURCES = \
snh-applet.c \
snh-applet.h \
+ snh-item.c \
+ snh-item.h \
$(NULL)
SNH_LDADD = \
diff --git a/applets/snh/snh-applet.c b/applets/snh/snh-applet.c
index 045b114..b0c8ce1 100644
--- a/applets/snh/snh-applet.c
+++ b/applets/snh/snh-applet.c
@@ -17,9 +17,8 @@
#include "config.h"
-#include <libstatus-notifier/sn.h>
-
#include "snh-applet.h"
+#include "snh-item.h"
struct _SnhApplet
{
@@ -27,49 +26,53 @@ struct _SnhApplet
SnHost *host;
- GtkWidget *label;
+ GtkWidget *menu_bar;
};
G_DEFINE_TYPE (SnhApplet, snh_applet, PANEL_TYPE_APPLET)
static void
+item_remove (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_widget_destroy (widget);
+}
+
+static void
items_changed_cb (SnHost *host,
gpointer user_data)
{
SnhApplet *applet;
GList *list;
GList *l;
- gchar *text;
applet = SNH_APPLET (user_data);
list = sn_host_get_items (host);
+ gtk_container_foreach (GTK_CONTAINER (applet->menu_bar),
+ (GtkCallback) item_remove, NULL);
+
for (l = list; l; l = l->next)
{
- SnItemClient *item;
- SnItemCategory category;
+ GtkWidget *item;
- item = SN_ITEM_CLIENT (l->data);
- category = sn_item_client_get_category (item);
+ item = snh_item_new (SN_ITEM_CLIENT (l->data));
- g_warning ("SnItemCategory: %d", (int) category);
+ gtk_menu_shell_append (GTK_MENU_SHELL (applet->menu_bar), item);
+ gtk_widget_show (item);
}
- 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");
+ applet->menu_bar = gtk_menu_bar_new ();
- gtk_container_add (GTK_CONTAINER (applet), applet->label);
- gtk_widget_show (applet->label);
+ gtk_container_add (GTK_CONTAINER (applet), applet->menu_bar);
+ gtk_widget_show (applet->menu_bar);
gtk_widget_show (GTK_WIDGET (applet));
diff --git a/applets/snh/snh-item.c b/applets/snh/snh-item.c
new file mode 100644
index 0000000..7476900
--- /dev/null
+++ b/applets/snh/snh-item.c
@@ -0,0 +1,110 @@
+/*
+ * 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 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 "config.h"
+
+#include "snh-item.h"
+
+struct _SnhItem
+{
+ GtkMenuItem parent;
+
+ SnItemClient *item;
+};
+
+enum
+{
+ PROP_0,
+
+ PROP_ITEM,
+
+ LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (SnhItem, snh_item, GTK_TYPE_MENU_ITEM)
+
+static void
+snh_item_constructed (GObject *object)
+{
+ SnhItem *item;
+
+ item = SNH_ITEM (object);
+
+ G_OBJECT_CLASS (snh_item_parent_class)->constructed (object);
+
+ const gchar *title = sn_item_client_get_title (item->item);
+ GtkWidget *test = gtk_label_new (title ? title : "Untitled");
+ gtk_container_add (GTK_CONTAINER (item), test);
+ gtk_widget_show (test);
+}
+
+static void
+snh_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ SnhItem *item;
+
+ item = SNH_ITEM (object);
+
+ switch (property_id)
+ {
+ case PROP_ITEM:
+ item->item = g_value_get_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+snh_item_class_init (SnhItemClass *item_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (item_class);
+
+ object_class->constructed = snh_item_constructed;
+ object_class->set_property = snh_item_set_property;
+
+ properties[PROP_ITEM] =
+ g_param_spec_object ("item",
+ "item",
+ "item",
+ SN_TYPE_ITEM_CLIENT,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+}
+
+static void
+snh_item_init (SnhItem *item)
+{
+}
+
+GtkWidget *
+snh_item_new (SnItemClient *item)
+{
+ return g_object_new (SNH_TYPE_ITEM, "item", item, NULL);
+}
diff --git a/applets/snh/snh-item.h b/applets/snh/snh-item.h
new file mode 100644
index 0000000..feb59bc
--- /dev/null
+++ b/applets/snh/snh-item.h
@@ -0,0 +1,33 @@
+/*
+ * 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_ITEM_H
+#define SNH_ITEM_H
+
+#include <gtk/gtk.h>
+#include <libstatus-notifier/sn.h>
+
+G_BEGIN_DECLS
+
+#define SNH_TYPE_ITEM snh_item_get_type ()
+G_DECLARE_FINAL_TYPE (SnhItem, snh_item, SNH, ITEM, GtkMenuItem)
+
+GtkWidget *snh_item_new (SnItemClient *item);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]