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;
51 #include "mvs-tmdb-movie-service-glue.h"
54 setup_dbus (MvsTMDBMovieService *self)
57 guint request_name_result;
59 gchar *object_path = NULL;
61 proxy = dbus_g_proxy_new_for_name (self->priv->connection,
66 if (!org_freedesktop_DBus_request_name (proxy,
67 TMDB_MOVIE_SERVICE_NAME,
68 0, &request_name_result,
70 g_warning ("Unable to register service: %s", error->message);
74 object_path = g_strdup_printf (TMDB_MOVIE_SERVICE_OBJECT_PATH "/%s",
77 dbus_g_connection_register_g_object (self->priv->connection,
82 g_object_unref (proxy);
86 mvs_tmdb_movie_service_set_property (GObject *object, guint property_id,
87 const GValue *value, GParamSpec *pspec)
89 MvsTMDBMovieService *self = MVS_TMDB_MOVIE_SERVICE (object);
91 switch (property_id) {
93 if (!self->priv->connection) {
94 DBusGConnection *tmp = g_value_get_pointer (value);
96 self->priv->connection =
97 dbus_g_connection_ref (tmp);
101 g_assert (self->priv->connection);
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 mvs_tmdb_movie_service_finalize (GObject *object)
111 MvsTMDBMovieService *self = MVS_TMDB_MOVIE_SERVICE (object);
113 if (self->priv->connection) {
114 dbus_g_connection_unref (self->priv->connection);
116 g_free (self->priv->suffix);
117 g_object_unref (self->priv->movie);
118 G_OBJECT_CLASS (mvs_tmdb_movie_service_parent_class)->finalize (object);
122 mvs_tmdb_movie_service_class_init (MvsTMDBMovieServiceClass *klass)
124 GObjectClass *object_class = G_OBJECT_CLASS (klass);
126 g_type_class_add_private (klass, sizeof (MvsTMDBMovieServicePrivate));
128 object_class->set_property = mvs_tmdb_movie_service_set_property;
129 object_class->finalize = mvs_tmdb_movie_service_finalize;
131 g_object_class_install_property
132 (object_class, PROP_DBUSGCONN,
133 g_param_spec_pointer ("connection", "DBusGConnection",
137 dbus_g_object_type_install_info (MVS_TYPE_TMDB_MOVIE_SERVICE,
138 &dbus_glib_mvs_tmdb_movie_service_object_info);
142 mvs_tmdb_movie_service_init (MvsTMDBMovieService *self)
144 self->priv = GET_PRIVATE (self);
145 self->priv->movie = NULL;
146 self->priv->connection = NULL;
147 self->priv->suffix = NULL;
151 mvs_tmdb_movie_service_new (DBusGConnection *connection,
152 MvsTmdbMovie *movie, const gchar *suffix)
154 MvsTMDBMovieService *instance = g_object_new (MVS_TYPE_TMDB_MOVIE_SERVICE, NULL);
155 instance->priv->suffix = g_strdup(suffix);
156 g_object_set (instance, "connection", connection, NULL);
157 instance->priv->movie = movie;