aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-interface.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-01-27 16:42:22 -0600
committerTed Gould <ted@gould.cx>2011-01-27 16:42:22 -0600
commit28f84ee512a35e2b04b211b7c1705a6eef4368ab (patch)
treec4594e72d714db7fd1d688844f3b3f63b3cbc1c7 /src/datetime-interface.c
parent8e1fbde30cfce799b64477113b404d5cda3306aa (diff)
parentaaae5863299681153898d4e701f44aed85c780e9 (diff)
downloadayatana-indicator-datetime-28f84ee512a35e2b04b211b7c1705a6eef4368ab.tar.gz
ayatana-indicator-datetime-28f84ee512a35e2b04b211b7c1705a6eef4368ab.tar.bz2
ayatana-indicator-datetime-28f84ee512a35e2b04b211b7c1705a6eef4368ab.zip
Import upstream version 0.1.91
Diffstat (limited to 'src/datetime-interface.c')
-rw-r--r--src/datetime-interface.c145
1 files changed, 127 insertions, 18 deletions
diff --git a/src/datetime-interface.c b/src/datetime-interface.c
index c58c5af..5939061 100644
--- a/src/datetime-interface.c
+++ b/src/datetime-interface.c
@@ -23,21 +23,37 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#endif
+#include <gio/gio.h>
+
#include "datetime-interface.h"
-#include "datetime-service-server.h"
+#include "gen-datetime-service.xml.h"
#include "dbus-shared.h"
-enum {
- UPDATE_TIME,
- LAST_SIGNAL
+/**
+ DatetimeInterfacePrivate:
+ @dbus_registration: The handle for this object being registered
+ on dbus.
+
+ Structure to define the memory for the private area
+ of the datetime interface instance.
+*/
+struct _DatetimeInterfacePrivate {
+ GDBusConnection * bus;
+ GCancellable * bus_cancel;
+ guint dbus_registration;
};
-static guint signals[LAST_SIGNAL] = { 0 };
+#define DATETIME_INTERFACE_GET_PRIVATE(o) (DATETIME_INTERFACE(o)->priv)
+
+/* GDBus Stuff */
+static GDBusNodeInfo * node_info = NULL;
+static GDBusInterfaceInfo * interface_info = NULL;
static void datetime_interface_class_init (DatetimeInterfaceClass *klass);
static void datetime_interface_init (DatetimeInterface *self);
static void datetime_interface_dispose (GObject *object);
static void datetime_interface_finalize (GObject *object);
+static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
G_DEFINE_TYPE (DatetimeInterface, datetime_interface, G_TYPE_OBJECT);
@@ -46,18 +62,29 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ g_type_class_add_private (klass, sizeof (DatetimeInterfacePrivate));
+
object_class->dispose = datetime_interface_dispose;
object_class->finalize = datetime_interface_finalize;
- signals[UPDATE_TIME] = g_signal_new("update-time",
- G_TYPE_FROM_CLASS(klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (DatetimeInterfaceClass, update_time),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
+ /* Setting up the DBus interfaces */
+ if (node_info == NULL) {
+ GError * error = NULL;
- dbus_g_object_type_install_info(DATETIME_INTERFACE_TYPE, &dbus_glib__datetime_service_server_object_info);
+ node_info = g_dbus_node_info_new_for_xml(_datetime_service, &error);
+ if (error != NULL) {
+ g_error("Unable to parse Datetime Service Interface description: %s", error->message);
+ g_error_free(error);
+ }
+ }
+
+ if (interface_info == NULL) {
+ interface_info = g_dbus_node_info_lookup_interface(node_info, SERVICE_IFACE);
+
+ if (interface_info == NULL) {
+ g_error("Unable to find interface '" SERVICE_IFACE "'");
+ }
+ }
return;
}
@@ -65,17 +92,82 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass)
static void
datetime_interface_init (DatetimeInterface *self)
{
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- dbus_g_connection_register_g_object(connection,
- SERVICE_OBJ,
- G_OBJECT(self));
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, DATETIME_INTERFACE_TYPE, DatetimeInterfacePrivate);
+
+ self->priv->bus = NULL;
+ self->priv->bus_cancel = NULL;
+ self->priv->dbus_registration = 0;
+
+ self->priv->bus_cancel = g_cancellable_new();
+ g_bus_get(G_BUS_TYPE_SESSION,
+ self->priv->bus_cancel,
+ bus_get_cb,
+ self);
return;
}
static void
+bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+ GDBusConnection * connection = g_bus_get_finish(res, &error);
+
+ if (error != NULL) {
+ g_error("OMG! Unable to get a connection to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(user_data);
+
+ g_warn_if_fail(priv->bus == NULL);
+ priv->bus = connection;
+
+ if (priv->bus_cancel != NULL) {
+ g_object_unref(priv->bus_cancel);
+ priv->bus_cancel = NULL;
+ }
+
+ /* Now register our object on our new connection */
+ priv->dbus_registration = g_dbus_connection_register_object(priv->bus,
+ SERVICE_OBJ,
+ interface_info,
+ NULL,
+ user_data,
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ g_error("Unable to register the object to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ return;
+}
+
+static void
datetime_interface_dispose (GObject *object)
{
+ DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(object);
+
+ if (priv->dbus_registration != 0) {
+ g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration);
+ /* Don't care if it fails, there's nothing we can do */
+ priv->dbus_registration = 0;
+ }
+
+ if (priv->bus != NULL) {
+ g_object_unref(priv->bus);
+ priv->bus = NULL;
+ }
+
+ if (priv->bus_cancel != NULL) {
+ g_cancellable_cancel(priv->bus_cancel);
+ g_object_unref(priv->bus_cancel);
+ priv->bus_cancel = NULL;
+ }
G_OBJECT_CLASS (datetime_interface_parent_class)->dispose (object);
return;
@@ -93,6 +185,23 @@ void
datetime_interface_update (DatetimeInterface *self)
{
g_return_if_fail(IS_DATETIME_INTERFACE(self));
- g_signal_emit(G_OBJECT(self), signals[UPDATE_TIME], 0, TRUE);
+
+ DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(self);
+ GError * error = NULL;
+
+ g_dbus_connection_emit_signal (priv->bus,
+ NULL,
+ SERVICE_OBJ,
+ SERVICE_IFACE,
+ "UpdateTime",
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ g_error("Unable to send UpdateTime signal: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
return;
}