aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-interface.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-01-27 16:47:49 -0600
committerTed Gould <ted@gould.cx>2011-01-27 16:47:49 -0600
commitce47d3868094c01e28fb75adecf4cd9de03832b7 (patch)
tree8bbecced83ccd6d259d2190094298bb40a28071c /src/datetime-interface.c
parentb7eb711886ddb2f46b0c685a577a7b0f6c455ba6 (diff)
parent28f84ee512a35e2b04b211b7c1705a6eef4368ab (diff)
downloadayatana-indicator-datetime-ce47d3868094c01e28fb75adecf4cd9de03832b7.tar.gz
ayatana-indicator-datetime-ce47d3868094c01e28fb75adecf4cd9de03832b7.tar.bz2
ayatana-indicator-datetime-ce47d3868094c01e28fb75adecf4cd9de03832b7.zip
* New upstream release.
* Change to canonical.com for naming * Fixing a type callback * Switching to GDbus and dbusmenu-0.4 * Supporting a wider range of custom strings for time and support seconds in the custom time strings. * Fixing to take time settings from LC_TIME
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;
}