1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2007 Bastien Nocera <hadess@hadess.net>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* The Totem project hereby grant permission for non-gpl compatible GStreamer
20
* plugins to be used and distributed together with GStreamer and Totem. This
21
* permission are above and beyond the permissions granted by the GPL license
22
* Totem is covered by.
24
* See license_change file for details.
31
#include <glib-object.h>
32
#include <glib/gi18n-lib.h>
35
#include <libgalago/galago.h>
37
#include "totem-plugin.h"
40
#define TOTEM_TYPE_GALAGO_PLUGIN (totem_galago_plugin_get_type ())
41
#define TOTEM_GALAGO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_GALAGO_PLUGIN, TotemGalagoPlugin))
42
#define TOTEM_GALAGO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_GALAGO_PLUGIN, TotemGalagoPluginClass))
43
#define TOTEM_IS_GALAGO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_GALAGO_PLUGIN))
44
#define TOTEM_IS_GALAGO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_GALAGO_PLUGIN))
45
#define TOTEM_GALAGO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_GALAGO_PLUGIN, TotemGalagoPluginClass))
51
guint handler_id_fullscreen;
52
guint handler_id_playing;
53
gboolean idle; /* Whether we're idle */
54
GalagoPerson *me; /* Me! */
59
TotemPluginClass parent_class;
60
} TotemGalagoPluginClass;
63
G_MODULE_EXPORT GType register_totem_plugin (GTypeModule *module);
64
GType totem_galago_plugin_get_type (void) G_GNUC_CONST;
66
static void totem_galago_plugin_init (TotemGalagoPlugin *plugin);
67
static void totem_galago_plugin_dispose (GObject *object);
68
static void totem_galago_plugin_finalize (GObject *object);
69
static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error);
70
static void impl_deactivate (TotemPlugin *plugin, TotemObject *totem);
72
TOTEM_PLUGIN_REGISTER(TotemGalagoPlugin, totem_galago_plugin)
75
totem_galago_plugin_class_init (TotemGalagoPluginClass *klass)
77
GObjectClass *object_class = G_OBJECT_CLASS (klass);
78
TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
80
object_class->dispose = totem_galago_plugin_dispose;
81
object_class->finalize = totem_galago_plugin_finalize;
83
plugin_class->activate = impl_activate;
84
plugin_class->deactivate = impl_deactivate;
88
totem_galago_plugin_init (TotemGalagoPlugin *plugin)
90
if (galago_init (PACKAGE_NAME, GALAGO_INIT_FEED) == FALSE
91
|| galago_is_connected () == FALSE) {
92
g_warning ("Failed to initialise libgalago.");
96
/* Get "me" and list accounts */
97
plugin->me = galago_get_me (GALAGO_REMOTE, TRUE);
101
totem_galago_plugin_dispose (GObject *object)
103
TotemGalagoPlugin *plugin = TOTEM_GALAGO_PLUGIN (object);
105
if (plugin->me != NULL) {
106
g_object_unref (plugin->me);
110
G_OBJECT_CLASS (totem_galago_plugin_parent_class)->dispose (object);
114
totem_galago_plugin_finalize (GObject *object)
116
if (galago_is_connected ())
119
G_OBJECT_CLASS (totem_galago_plugin_parent_class)->finalize (object);
123
totem_galago_set_idleness (TotemGalagoPlugin *plugin, gboolean idle)
126
GalagoPresence *presence;
128
if (galago_is_connected () == FALSE)
131
if (plugin->idle == idle)
135
for (account = galago_person_get_accounts (plugin->me, TRUE); account != NULL; account = g_list_next (account)) {
136
presence = galago_account_get_presence ((GalagoAccount *)account->data, TRUE);
137
if (presence != NULL)
138
galago_presence_set_idle (presence, idle, time (NULL));
143
totem_galago_update_from_state (TotemObject *totem,
144
TotemGalagoPlugin *plugin)
146
if (totem_is_playing (totem) != FALSE
147
&& totem_is_fullscreen (totem) != FALSE) {
148
totem_galago_set_idleness (plugin, TRUE);
150
totem_galago_set_idleness (plugin, FALSE);
155
property_notify_cb (TotemObject *totem,
157
TotemGalagoPlugin *plugin)
159
totem_galago_update_from_state (totem, plugin);
163
impl_activate (TotemPlugin *plugin,
167
TotemGalagoPlugin *pi = TOTEM_GALAGO_PLUGIN (plugin);
169
if (!galago_is_connected ()) {
170
g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
171
_("Could not connect to the Galago daemon."));
175
pi->handler_id_fullscreen = g_signal_connect (G_OBJECT (totem),
176
"notify::fullscreen",
177
G_CALLBACK (property_notify_cb),
179
pi->handler_id_playing = g_signal_connect (G_OBJECT (totem),
181
G_CALLBACK (property_notify_cb),
184
/* Force setting the current status */
185
totem_galago_update_from_state (totem, pi);
191
impl_deactivate (TotemPlugin *plugin,
194
TotemGalagoPlugin *pi = TOTEM_GALAGO_PLUGIN (plugin);
196
g_signal_handler_disconnect (G_OBJECT (totem), pi->handler_id_fullscreen);
197
g_signal_handler_disconnect (G_OBJECT (totem), pi->handler_id_playing);
199
totem_galago_set_idleness (pi, FALSE);