2 * mvs-watc-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-watc-movie-service.h"
23 #define WATC_MOVIE_SERVICE_OBJECT_PATH "/WATCMovie"
24 #define WATC_MOVIE_SERVICE_NAME "com.simonpena.maevies.watcmovie"
26 G_DEFINE_TYPE (MvsWatcMovieService, mvs_watc_movie_service, G_TYPE_OBJECT)
34 #define GET_PRIVATE(o) \
35 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_WATC_MOVIE_SERVICE, MvsWatcMovieServicePrivate))
37 struct _MvsWatcMovieServicePrivate {
39 DBusGConnection *connection;
44 mvs_watc_movie_service_get_name (MvsWatcMovieService *self, gchar **title,
47 *title = g_strdup (mvs_watc_movie_get_name (self->priv->movie));
48 return *title != NULL;
52 mvs_watc_movie_service_get_year (MvsWatcMovieService *self, gchar **year,
55 *year = g_strdup (mvs_watc_movie_get_year(self->priv->movie));
60 mvs_watc_movie_service_get_stingers (MvsWatcMovieService *self, int *stingers,
63 *stingers = mvs_watc_movie_get_stingers (self->priv->movie);
67 #include "mvs-watc-movie-service-glue.h"
70 setup_dbus (MvsWatcMovieService *self)
73 guint request_name_result;
75 gchar *object_path = NULL;
77 proxy = dbus_g_proxy_new_for_name (self->priv->connection,
82 if (!org_freedesktop_DBus_request_name (proxy,
83 WATC_MOVIE_SERVICE_NAME,
84 0, &request_name_result,
86 g_warning ("Unable to register service: %s", error->message);
90 object_path = g_strdup_printf (WATC_MOVIE_SERVICE_OBJECT_PATH "/%s",
93 dbus_g_connection_register_g_object (self->priv->connection,
98 g_object_unref (proxy);
102 mvs_watc_movie_service_set_property (GObject *object, guint property_id,
103 const GValue *value, GParamSpec *pspec)
105 MvsWatcMovieService *self = MVS_WATC_MOVIE_SERVICE (object);
107 switch (property_id) {
109 if (!self->priv->connection) {
110 DBusGConnection *tmp = g_value_get_pointer (value);
112 self->priv->connection =
113 dbus_g_connection_ref (tmp);
117 g_assert (self->priv->connection);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
125 mvs_watc_movie_service_finalize (GObject *object)
127 MvsWatcMovieService *self = MVS_WATC_MOVIE_SERVICE (object);
129 if (self->priv->connection) {
130 dbus_g_connection_unref (self->priv->connection);
132 g_free (self->priv->suffix);
133 g_object_unref (self->priv->movie);
134 G_OBJECT_CLASS (mvs_watc_movie_service_parent_class)->finalize (object);
138 mvs_watc_movie_service_class_init (MvsWatcMovieServiceClass *klass)
140 GObjectClass *object_class = G_OBJECT_CLASS (klass);
142 g_type_class_add_private (klass, sizeof (MvsWatcMovieServicePrivate));
144 object_class->set_property = mvs_watc_movie_service_set_property;
145 object_class->finalize = mvs_watc_movie_service_finalize;
147 g_object_class_install_property
148 (object_class, PROP_DBUSGCONN,
149 g_param_spec_pointer ("connection", "DBusGConnection",
153 dbus_g_object_type_install_info (MVS_TYPE_WATC_MOVIE_SERVICE,
154 &dbus_glib_mvs_watc_movie_service_object_info);
158 mvs_watc_movie_service_init (MvsWatcMovieService *self)
160 self->priv = GET_PRIVATE (self);
161 self->priv->movie = NULL;
162 self->priv->connection = NULL;
163 self->priv->suffix = NULL;
167 mvs_watc_movie_service_new (DBusGConnection *connection,
168 MvsWatcMovie *movie, const gchar *suffix)
170 MvsWatcMovieService *instance = g_object_new (MVS_TYPE_WATC_MOVIE_SERVICE, NULL);
171 instance->priv->suffix = g_strdup(suffix);
172 g_object_set (instance, "connection", connection, NULL);
173 instance->priv->movie = movie;