#ifdef HAVE_CONFIG_H #include "config.h" #endif #include "client.h" #include "dbusmenu-client.h" /* Properties */ enum { PROP_0, PROP_DBUSOBJECT, PROP_DBUSNAME }; typedef struct _DbusmenuClientPrivate DbusmenuClientPrivate; struct _DbusmenuClientPrivate { DbusmenuMenuitem * root; gchar * dbus_object; gchar * dbus_name; DBusGProxy * menuproxy; DBusGProxy * propproxy; DBusGProxyCall * layoutcall; }; #define DBUSMENU_CLIENT_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_CLIENT, DbusmenuClientPrivate)) /* GObject Stuff */ static void dbusmenu_client_class_init (DbusmenuClientClass *klass); static void dbusmenu_client_init (DbusmenuClient *self); static void dbusmenu_client_dispose (GObject *object); static void dbusmenu_client_finalize (GObject *object); static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); /* Private Funcs */ static void build_proxies (DbusmenuClient * client); /* Build a type */ G_DEFINE_TYPE (DbusmenuClient, dbusmenu_client, G_TYPE_OBJECT); static void dbusmenu_client_class_init (DbusmenuClientClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (DbusmenuClientPrivate)); object_class->dispose = dbusmenu_client_dispose; object_class->finalize = dbusmenu_client_finalize; object_class->set_property = set_property; object_class->get_property = get_property; g_object_class_install_property (object_class, PROP_DBUSOBJECT, g_param_spec_string("dbus-object", "DBus Object we represent", "The Object on the client that we're getting our data from.", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DBUSNAME, g_param_spec_string("dbus-name", "DBus Client we connect to", "Name of the DBus client we're connecting to.", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); return; } static void dbusmenu_client_init (DbusmenuClient *self) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(self); priv->root = NULL; priv->dbus_object = NULL; priv->dbus_name = NULL; priv->menuproxy = NULL; priv->propproxy = NULL; priv->layoutcall = NULL; return; } static void dbusmenu_client_dispose (GObject *object) { G_OBJECT_CLASS (dbusmenu_client_parent_class)->dispose (object); return; } static void dbusmenu_client_finalize (GObject *object) { G_OBJECT_CLASS (dbusmenu_client_parent_class)->finalize (object); return; } static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(obj); switch (id) { case PROP_DBUSNAME: priv->dbus_name = g_value_dup_string(value); if (priv->dbus_name != NULL && priv->dbus_object != NULL) { build_proxies(DBUSMENU_CLIENT(obj)); } break; case PROP_DBUSOBJECT: priv->dbus_object = g_value_dup_string(value); if (priv->dbus_name != NULL && priv->dbus_object != NULL) { build_proxies(DBUSMENU_CLIENT(obj)); } break; default: g_warning("Unknown property %d.", id); return; } return; } static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(obj); switch (id) { case PROP_DBUSNAME: g_value_set_string(value, priv->dbus_name); break; case PROP_DBUSOBJECT: g_value_set_string(value, priv->dbus_object); break; default: g_warning("Unknown property %d.", id); return; } return; } /* Internal funcs */ /* When we have a name and an object, build the two proxies and get the first version of the layout */ static void build_proxies (DbusmenuClient * client) { } /* When the layout property returns, here's where we take care of that. */ static void update_layout_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) { } /* Call the property on the server we're connected to and set it up to be async back to _update_layout_cb */ static void update_layout (DbusmenuClient * client) { update_layout_cb(NULL, NULL, NULL); } /* Public API */ DbusmenuClient * dbusmenu_client_new (const gchar * name, const gchar * object) { DbusmenuClient * self = g_object_new(DBUSMENU_TYPE_CLIENT, "name", name, "object", object, NULL); update_layout(self); return self; } DbusmenuMenuitem * dbusmenu_client_get_root (DbusmenuClient * client) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); if (priv->layoutcall != NULL) { /* Oh, we're in the middle of getting it */ /* TODO: Wait here */ } return priv->root; }