--- /dev/null
+/*
+ * mvs-watc-movie-service.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
+ *
+ * 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.
+ *
+ */
+
+#include <dbus/dbus-glib-bindings.h>
+
+#include "mvs-watc-movie-service.h"
+
+#define WATC_MOVIE_SERVICE_OBJECT_PATH "/WATCMovie"
+#define WATC_MOVIE_SERVICE_NAME "com.simonpena.maevies.watcmovie"
+
+G_DEFINE_TYPE (MvsWatcMovieService, mvs_watc_movie_service, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_DBUSGCONN,
+};
+
+#define GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_WATC_MOVIE_SERVICE, MvsWatcMovieServicePrivate))
+
+struct _MvsWatcMovieServicePrivate {
+ MvsWatcMovie *movie;
+ DBusGConnection *connection;
+ gchar *suffix;
+};
+
+gboolean
+mvs_watc_movie_service_get_name (MvsWatcMovieService *self, gchar **title,
+ GError **error)
+{
+ *title = g_strdup (mvs_watc_movie_get_name (self->priv->movie));
+ return *title != NULL;
+}
+
+gboolean
+mvs_watc_movie_service_get_year (MvsWatcMovieService *self, gchar **year,
+ GError **error)
+{
+ *year = g_strdup (mvs_watc_movie_get_year(self->priv->movie));
+ return *year != NULL;
+}
+
+gboolean
+mvs_watc_movie_service_get_stingers (MvsWatcMovieService *self, int *stingers,
+ GError **error)
+{
+ *stingers = mvs_watc_movie_get_stingers (self->priv->movie);
+ return TRUE;
+}
+
+#include "mvs-watc-movie-service-glue.h"
+
+static void
+setup_dbus (MvsWatcMovieService *self)
+{
+ DBusGProxy *proxy;
+ guint request_name_result;
+ GError *error = NULL;
+ gchar *object_path = NULL;
+
+ proxy = dbus_g_proxy_new_for_name (self->priv->connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ if (!org_freedesktop_DBus_request_name (proxy,
+ WATC_MOVIE_SERVICE_NAME,
+ 0, &request_name_result,
+ &error)) {
+ g_warning ("Unable to register service: %s", error->message);
+ g_error_free (error);
+ }
+
+ object_path = g_strdup_printf (WATC_MOVIE_SERVICE_OBJECT_PATH "/%s",
+ self->priv->suffix);
+
+ dbus_g_connection_register_g_object (self->priv->connection,
+ object_path,
+ G_OBJECT (self));
+
+ g_free (object_path);
+ g_object_unref (proxy);
+}
+
+static void
+mvs_watc_movie_service_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ MvsWatcMovieService *self = MVS_WATC_MOVIE_SERVICE (object);
+
+ switch (property_id) {
+ case PROP_DBUSGCONN:
+ if (!self->priv->connection) {
+ DBusGConnection *tmp = g_value_get_pointer (value);
+ if (tmp) {
+ self->priv->connection =
+ dbus_g_connection_ref (tmp);
+ setup_dbus (self);
+ }
+ }
+ g_assert (self->priv->connection);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+mvs_watc_movie_service_finalize (GObject *object)
+{
+ MvsWatcMovieService *self = MVS_WATC_MOVIE_SERVICE (object);
+
+ if (self->priv->connection) {
+ dbus_g_connection_unref (self->priv->connection);
+ }
+ g_free (self->priv->suffix);
+ g_object_unref (self->priv->movie);
+ G_OBJECT_CLASS (mvs_watc_movie_service_parent_class)->finalize (object);
+}
+
+static void
+mvs_watc_movie_service_class_init (MvsWatcMovieServiceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (MvsWatcMovieServicePrivate));
+
+ object_class->set_property = mvs_watc_movie_service_set_property;
+ object_class->finalize = mvs_watc_movie_service_finalize;
+
+ g_object_class_install_property
+ (object_class, PROP_DBUSGCONN,
+ g_param_spec_pointer ("connection", "DBusGConnection",
+ "DBus GConnection",
+ G_PARAM_WRITABLE));
+
+ dbus_g_object_type_install_info (MVS_TYPE_WATC_MOVIE_SERVICE,
+ &dbus_glib_mvs_watc_movie_service_object_info);
+}
+
+static void
+mvs_watc_movie_service_init (MvsWatcMovieService *self)
+{
+ self->priv = GET_PRIVATE (self);
+ self->priv->movie = NULL;
+ self->priv->connection = NULL;
+ self->priv->suffix = NULL;
+}
+
+MvsWatcMovieService*
+mvs_watc_movie_service_new (DBusGConnection *connection,
+ MvsWatcMovie *movie, const gchar *suffix)
+{
+ MvsWatcMovieService *instance = g_object_new (MVS_TYPE_WATC_MOVIE_SERVICE, NULL);
+ instance->priv->suffix = g_strdup(suffix);
+ g_object_set (instance, "connection", connection, NULL);
+ instance->priv->movie = movie;
+ return instance;
+}
--- /dev/null
+/*
+ * mvs-watc-movie-service.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef _MVS_WATC_MOVIE_SERVICE
+#define _MVS_WATC_MOVIE_SERVICE
+
+#include <glib-object.h>
+#include "mvs-watc-movie.h"
+
+G_BEGIN_DECLS
+
+#define MVS_TYPE_WATC_MOVIE_SERVICE mvs_watc_movie_service_get_type()
+#define MVS_WATC_MOVIE_SERVICE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), MVS_TYPE_WATC_MOVIE_SERVICE, MvsWatcMovieService))
+#define MVS_WATC_MOVIE_SERVICE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), MVS_TYPE_WATC_MOVIE_SERVICE, MvsWatcMovieServiceClass))
+#define MVS_IS_WATC_MOVIE_SERVICE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MVS_TYPE_WATC_MOVIE_SERVICE))
+#define MVS_IS_WATC_MOVIE_SERVICE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), MVS_TYPE_WATC_MOVIE_SERVICE))
+#define MVS_WATC_MOVIE_SERVICE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), MVS_TYPE_WATC_MOVIE_SERVICE, MvsWatcMovieServiceClass))
+
+typedef struct _MvsWatcMovieServicePrivate MvsWatcMovieServicePrivate;
+
+typedef struct {
+ GObject parent;
+
+ /* <private> */
+ MvsWatcMovieServicePrivate *priv;
+} MvsWatcMovieService;
+
+typedef struct {
+ GObjectClass parent_class;
+} MvsWatcMovieServiceClass;
+
+GType mvs_watc_movie_service_get_type (void);
+MvsWatcMovieService* mvs_watc_movie_service_new (DBusGConnection *connection,
+ MvsWatcMovie *movie, const gchar *suffix);
+
+G_END_DECLS
+
+#endif /* _MVS_WATC_MOVIE_SERVICE */