2 * mvs-tmdb-movie-service.c
4 * This file is part of maevies
5 * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 #include <dbus/dbus-glib-bindings.h>
21 #include "mvs-tmdb-movie-service.h"
23 #define TMDB_MOVIE_SERVICE_OBJECT_PATH "/TMDBMovie"
24 #define TMDB_MOVIE_SERVICE_NAME "com.simonpena.maevies.tmdbmovie"
26 G_DEFINE_TYPE (MvsTmdbMovieService, mvs_tmdb_movie_service, G_TYPE_OBJECT)
34 #define GET_PRIVATE(o) \
35 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_TMDB_MOVIE_SERVICE, MvsTmdbMovieServicePrivate))
37 struct _MvsTmdbMovieServicePrivate {
39 DBusGConnection *connection;
44 mvs_tmdb_movie_service_get_title (MvsTmdbMovieService *self, gchar **title,
47 *title = g_strdup (mvs_tmdb_movie_get_name (self->priv->movie));
48 return *title != NULL;
52 mvs_tmdb_movie_service_get_popularity (MvsTmdbMovieService *self, gchar **popularity,
55 *popularity = g_strdup (mvs_tmdb_movie_get_popularity (self->priv->movie));
56 return *popularity != NULL;
60 mvs_tmdb_movie_service_get_rating (MvsTmdbMovieService *self, gchar **rating)
62 *rating = g_strdup (mvs_tmdb_movie_get_rating (self->priv->movie));
63 return *rating != NULL;
67 mvs_tmdb_movie_service_get_released (MvsTmdbMovieService *self, gchar **released)
69 *released = g_strdup (mvs_tmdb_movie_get_released (self->priv->movie));
70 return *released != NULL;
74 mvs_tmdb_movie_service_get_overview (MvsTmdbMovieService *self, gchar **overview)
76 *overview = g_strdup (mvs_tmdb_movie_get_overview (self->priv->movie));
77 return *overview != NULL;
80 #include "mvs-tmdb-movie-service-glue.h"
83 setup_dbus (MvsTmdbMovieService *self)
86 guint request_name_result;
88 gchar *object_path = NULL;
90 proxy = dbus_g_proxy_new_for_name (self->priv->connection,
95 if (!org_freedesktop_DBus_request_name (proxy,
96 TMDB_MOVIE_SERVICE_NAME,
97 0, &request_name_result,
99 g_warning ("Unable to register service: %s", error->message);
100 g_error_free (error);
103 object_path = g_strdup_printf (TMDB_MOVIE_SERVICE_OBJECT_PATH "/%s",
106 dbus_g_connection_register_g_object (self->priv->connection,
110 g_free (object_path);
111 g_object_unref (proxy);
115 mvs_tmdb_movie_service_set_property (GObject *object, guint property_id,
116 const GValue *value, GParamSpec *pspec)
118 MvsTmdbMovieService *self = MVS_TMDB_MOVIE_SERVICE (object);
120 switch (property_id) {
122 if (!self->priv->connection) {
123 DBusGConnection *tmp = g_value_get_pointer (value);
125 self->priv->connection =
126 dbus_g_connection_ref (tmp);
130 g_assert (self->priv->connection);
133 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
138 mvs_tmdb_movie_service_finalize (GObject *object)
140 MvsTmdbMovieService *self = MVS_TMDB_MOVIE_SERVICE (object);
142 if (self->priv->connection) {
143 dbus_g_connection_unref (self->priv->connection);
145 g_free (self->priv->suffix);
146 g_object_unref (self->priv->movie);
147 G_OBJECT_CLASS (mvs_tmdb_movie_service_parent_class)->finalize (object);
151 mvs_tmdb_movie_service_class_init (MvsTmdbMovieServiceClass *klass)
153 GObjectClass *object_class = G_OBJECT_CLASS (klass);
155 g_type_class_add_private (klass, sizeof (MvsTmdbMovieServicePrivate));
157 object_class->set_property = mvs_tmdb_movie_service_set_property;
158 object_class->finalize = mvs_tmdb_movie_service_finalize;
160 g_object_class_install_property
161 (object_class, PROP_DBUSGCONN,
162 g_param_spec_pointer ("connection", "DBusGConnection",
166 dbus_g_object_type_install_info (MVS_TYPE_TMDB_MOVIE_SERVICE,
167 &dbus_glib_mvs_tmdb_movie_service_object_info);
171 mvs_tmdb_movie_service_init (MvsTmdbMovieService *self)
173 self->priv = GET_PRIVATE (self);
174 self->priv->movie = NULL;
175 self->priv->connection = NULL;
176 self->priv->suffix = NULL;
180 mvs_tmdb_movie_service_new (DBusGConnection *connection,
181 MvsTmdbMovie *movie, const gchar *suffix)
183 MvsTmdbMovieService *instance = g_object_new (MVS_TYPE_TMDB_MOVIE_SERVICE, NULL);
184 instance->priv->suffix = g_strdup(suffix);
185 g_object_set (instance, "connection", connection, NULL);
186 instance->priv->movie = movie;