[gnome-panel] status-notifier: pass SnApplet object to SnHostV0



commit 2dbdbc9fb8b28c9fb4bc97ccb01e2c25e14498b5
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jan 30 22:21:24 2018 +0200

    status-notifier: pass SnApplet object to SnHostV0

 modules/status-notifier/sn-applet.c  |    2 +-
 modules/status-notifier/sn-host-v0.c |   66 +++++++++++++++++++++++++++++----
 modules/status-notifier/sn-host-v0.h |    3 +-
 modules/status-notifier/sn-host.c    |   10 +++++
 4 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/modules/status-notifier/sn-applet.c b/modules/status-notifier/sn-applet.c
index d5bf10b..2cf7222 100644
--- a/modules/status-notifier/sn-applet.c
+++ b/modules/status-notifier/sn-applet.c
@@ -272,7 +272,7 @@ sn_applet_constructed (GObject *object)
   G_OBJECT_CLASS (sn_applet_parent_class)->constructed (object);
   sn = SN_APPLET (object);
 
-  host = sn_host_v0_new ();
+  host = sn_host_v0_new (sn);
   sn->hosts = g_slist_prepend (sn->hosts, host);
 
   g_signal_connect (host, "item-added", G_CALLBACK (item_added_cb), sn);
diff --git a/modules/status-notifier/sn-host-v0.c b/modules/status-notifier/sn-host-v0.c
index 6c2d2fa..ef84417 100644
--- a/modules/status-notifier/sn-host-v0.c
+++ b/modules/status-notifier/sn-host-v0.c
@@ -31,6 +31,8 @@ struct _SnHostV0
 {
   SnHostV0GenSkeleton  parent;
 
+  SnApplet            *applet;
+
   gchar               *bus_name;
   gchar               *object_path;
   guint                bus_name_id;
@@ -43,6 +45,15 @@ struct _SnHostV0
   GSList              *items;
 };
 
+enum
+{
+  PROP_0,
+
+  PROP_APPLET,
+
+  LAST_PROP
+};
+
 static void sn_host_v0_gen_init (SnHostV0GenIface *iface);
 static void sn_host_init        (SnHostInterface  *iface);
 
@@ -324,12 +335,29 @@ bus_acquired_cb (GDBusConnection *connection,
 }
 
 static void
+sn_host_v0_constructed (GObject *object)
+{
+  SnHostV0 *v0;
+  GBusNameOwnerFlags flags;
+
+  G_OBJECT_CLASS (sn_host_v0_parent_class)->constructed (object);
+
+  v0 = SN_HOST_V0 (object);
+  flags = G_BUS_NAME_OWNER_FLAGS_NONE;
+
+  v0->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, v0->bus_name, flags,
+                                    bus_acquired_cb, NULL, NULL, v0, NULL);
+}
+
+static void
 sn_host_v0_dispose (GObject *object)
 {
   SnHostV0 *v0;
 
   v0 = SN_HOST_V0 (object);
 
+  v0->applet = NULL;
+
   if (v0->bus_name_id > 0)
     {
       g_bus_unown_name (v0->bus_name_id);
@@ -371,34 +399,56 @@ sn_host_v0_finalize (GObject *object)
 }
 
 static void
+sn_host_v0_set_property (GObject      *object,
+                         guint         property_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  SnHostV0 *v0;
+
+  v0 = SN_HOST_V0 (object);
+
+  switch (property_id)
+    {
+      case PROP_APPLET:
+        g_assert (v0->applet == NULL);
+        v0->applet = g_value_get_object (value);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
 sn_host_v0_class_init (SnHostV0Class *v0_class)
 {
   GObjectClass *object_class;
 
   object_class = G_OBJECT_CLASS (v0_class);
 
+  object_class->constructed = sn_host_v0_constructed;
   object_class->dispose = sn_host_v0_dispose;
   object_class->finalize = sn_host_v0_finalize;
+  object_class->set_property = sn_host_v0_set_property;
+
+  g_object_class_override_property (object_class, PROP_APPLET, "applet");
 }
 
 static void
 sn_host_v0_init (SnHostV0 *v0)
 {
-  GBusNameOwnerFlags flags;
   static guint id;
 
-  flags = G_BUS_NAME_OWNER_FLAGS_NONE;
   id++;
 
   v0->bus_name = g_strdup_printf ("%s-%d-%d", SN_HOST_BUS_NAME, getpid (), id);
-  v0->object_path = g_strdup_printf ("%s/%d", SN_HOST_OBJECT_PATH,id);
-
-  v0->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, v0->bus_name, flags,
-                                    bus_acquired_cb, NULL, NULL, v0, NULL);
+  v0->object_path = g_strdup_printf ("%s/%d", SN_HOST_OBJECT_PATH, id);
 }
 
 SnHost *
-sn_host_v0_new (void)
+sn_host_v0_new (SnApplet *applet)
 {
-  return g_object_new (SN_TYPE_HOST_V0, NULL);
+  return g_object_new (SN_TYPE_HOST_V0, "applet", applet, NULL);
 }
diff --git a/modules/status-notifier/sn-host-v0.h b/modules/status-notifier/sn-host-v0.h
index 792c160..8616cdc 100644
--- a/modules/status-notifier/sn-host-v0.h
+++ b/modules/status-notifier/sn-host-v0.h
@@ -18,6 +18,7 @@
 #ifndef SN_HOST_V0_H
 #define SN_HOST_V0_H
 
+#include "sn-applet.h"
 #include "sn-host.h"
 #include "sn-host-v0-gen.h"
 
@@ -26,7 +27,7 @@ G_BEGIN_DECLS
 #define SN_TYPE_HOST_V0 sn_host_v0_get_type ()
 G_DECLARE_FINAL_TYPE (SnHostV0, sn_host_v0, SN, HOST_V0, SnHostV0GenSkeleton)
 
-SnHost *sn_host_v0_new (void);
+SnHost *sn_host_v0_new (SnApplet *applet);
 
 G_END_DECLS
 
diff --git a/modules/status-notifier/sn-host.c b/modules/status-notifier/sn-host.c
index c8fe48c..65b3599 100644
--- a/modules/status-notifier/sn-host.c
+++ b/modules/status-notifier/sn-host.c
@@ -17,6 +17,7 @@
 
 #include "config.h"
 
+#include "sn-applet.h"
 #include "sn-host.h"
 #include "sn-item.h"
 
@@ -35,6 +36,15 @@ G_DEFINE_INTERFACE (SnHost, sn_host, G_TYPE_OBJECT)
 static void
 sn_host_default_init (SnHostInterface *iface)
 {
+  GParamSpec *spec;
+
+  spec = g_param_spec_object ("applet", "Applet", "Applet",
+                              SN_TYPE_APPLET,
+                              G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                              G_PARAM_STATIC_STRINGS);
+
+  g_object_interface_install_property (iface, spec);
+
   signals[SIGNAL_ITEM_ADDED] =
     g_signal_new ("item-added", G_TYPE_FROM_INTERFACE (iface),
                   G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,


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