From c094ea641e3dece80a803799f63e16d0987cc31f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sim=C3=B3n=20Pena?= Date: Sun, 20 Jun 2010 20:20:49 +0200 Subject: [PATCH] watc-movie-service: Added WATC movie service --- src/Makefile.am | 7 ++ src/mvs-watc-movie-service.c | 175 ++++++++++++++++++++++++++++++++++++++++++ src/mvs-watc-movie-service.h | 58 ++++++++++++++ src/mvs-watc-movie.xml | 17 ++++ 4 files changed, 257 insertions(+) create mode 100644 src/mvs-watc-movie-service.c create mode 100644 src/mvs-watc-movie-service.h create mode 100644 src/mvs-watc-movie.xml diff --git a/src/Makefile.am b/src/Makefile.am index b568481..044d2cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,9 @@ maevies_service_SOURCES = \ mvs-tmdb-movie-service.c \ mvs-tmdb-movie-service.h \ mvs-tmdb-movie-service-glue.h \ + mvs-watc-movie-service.c \ + mvs-watc-movie-service.h \ + mvs-watc-movie-service-glue.h \ mvs-marshal.c \ mvs-marshal.h @@ -45,6 +48,9 @@ mvs-minfo-provider-service-glue.h: mvs-minfo-provider.xml mvs-tmdb-movie-service-glue.h: mvs-tmdb-movie.xml dbus-binding-tool --mode=glib-server --prefix=mvs_tmdb_movie_service $< > $@ +mvs-watc-movie-service-glue.h: mvs-watc-movie.xml + dbus-binding-tool --mode=glib-server --prefix=mvs_watc_movie_service $< > $@ + mvs-marshal.h: marshal.list glib-genmarshal --header --prefix=mvs_marshal $< > $@ @@ -56,5 +62,6 @@ DISTCLEANFILES = $(MAINTAINERCLEANFILES) BUILT_SOURCES = \ mvs-minfo-provider-service-glue.h \ mvs-tmdb-movie-service-glue.h \ + mvs-watc-movie-service-glue.h \ mvs-marshal.h \ mvs-marshal.c \ No newline at end of file diff --git a/src/mvs-watc-movie-service.c b/src/mvs-watc-movie-service.c new file mode 100644 index 0000000..610a6ea --- /dev/null +++ b/src/mvs-watc-movie-service.c @@ -0,0 +1,175 @@ +/* + * mvs-watc-movie-service.c + * + * This file is part of maevies + * Copyright (C) 2010 Simón Pena + * + * 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 + +#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; +} diff --git a/src/mvs-watc-movie-service.h b/src/mvs-watc-movie-service.h new file mode 100644 index 0000000..bbd3a61 --- /dev/null +++ b/src/mvs-watc-movie-service.h @@ -0,0 +1,58 @@ +/* + * mvs-watc-movie-service.h + * + * This file is part of maevies + * Copyright (C) 2010 Simón Pena + * + * 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 +#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; + + /* */ + 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 */ diff --git a/src/mvs-watc-movie.xml b/src/mvs-watc-movie.xml new file mode 100644 index 0000000..c984500 --- /dev/null +++ b/src/mvs-watc-movie.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file -- 1.7.9.5