34
34
#include <glib-object.h>
35
35
#include <glib/gi18n-lib.h>
37
36
#include <string.h>
37
#include <libpeas/peas-extension-base.h>
38
#include <libpeas/peas-object-module.h>
39
#include <libpeas/peas-activatable.h>
39
40
#include <unistd.h>
40
41
#include <lirc/lirc_client.h>
42
43
#include "totem-plugin.h"
45
#include "totem-dirs.h"
45
47
#define TOTEM_TYPE_LIRC_PLUGIN (totem_lirc_plugin_get_type ())
46
48
#define TOTEM_LIRC_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_LIRC_PLUGIN, TotemLircPlugin))
49
51
#define TOTEM_IS_LIRC_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_LIRC_PLUGIN))
50
52
#define TOTEM_LIRC_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_LIRC_PLUGIN, TotemLircPluginClass))
56
55
GIOChannel *lirc_channel;
57
56
struct lirc_config *lirc_config;
59
58
TotemObject *totem;
64
TotemPluginClass parent_class;
65
} TotemLircPluginClass;
59
} TotemLircPluginPrivate;
67
61
/* strings that we recognize as commands from lirc */
68
62
#define TOTEM_IR_COMMAND_PLAY "play"
94
88
#define TOTEM_IR_SETTING_TOGGLE_REPEAT "setting_repeat"
95
89
#define TOTEM_IR_SETTING_TOGGLE_SHUFFLE "setting_shuffle"
97
G_MODULE_EXPORT GType register_totem_plugin (GTypeModule *module);
98
GType totem_lirc_plugin_get_type (void) G_GNUC_CONST;
100
static void totem_lirc_plugin_init (TotemLircPlugin *plugin);
101
static void totem_lirc_plugin_finalize (GObject *object);
102
static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error);
103
static void impl_deactivate (TotemPlugin *plugin, TotemObject *totem);
105
TOTEM_PLUGIN_REGISTER(TotemLircPlugin, totem_lirc_plugin)
108
totem_lirc_plugin_class_init (TotemLircPluginClass *klass)
110
GObjectClass *object_class = G_OBJECT_CLASS (klass);
111
TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
113
object_class->finalize = totem_lirc_plugin_finalize;
115
plugin_class->activate = impl_activate;
116
plugin_class->deactivate = impl_deactivate;
120
totem_lirc_plugin_init (TotemLircPlugin *plugin)
125
totem_lirc_plugin_finalize (GObject *object)
127
G_OBJECT_CLASS (totem_lirc_plugin_parent_class)->finalize (object);
91
TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_LIRC_PLUGIN, TotemLircPlugin, totem_lirc_plugin)
131
94
totem_lirc_get_url (const char *str)
245
208
if (g_str_has_prefix (str, TOTEM_IR_SETTING) != FALSE) {
246
TotemRemoteSetting setting;
248
setting = totem_lirc_to_setting (str, &url);
209
gint setting = totem_lirc_to_setting (str, &url);
249
210
if (setting >= 0) {
252
value = totem_action_remote_get_setting (pi->totem, setting);
253
totem_action_remote_set_setting (pi->totem, setting, !value);
213
value = totem_action_remote_get_setting (pi->priv->totem, setting);
214
totem_action_remote_set_setting (pi->priv->totem, setting, !value);
256
217
cmd = totem_lirc_to_command (str, &url);
257
totem_action_remote (pi->totem, cmd, url);
218
totem_action_remote (pi->priv->totem, cmd, url);
268
impl_activate (TotemPlugin *plugin,
229
impl_activate (PeasActivatable *plugin)
272
231
TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin);
276
pi->totem = g_object_ref (totem);
235
pi->priv->totem = g_object_ref (g_object_get_data (G_OBJECT (plugin), "object"));
278
fd = lirc_init ("Totem", 0);
237
fd = lirc_init ((char*) "Totem", 0);
280
241
g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
281
242
_("Couldn't initialize lirc."));
285
247
/* Load the default Totem setup */
286
path = totem_plugin_find_file (plugin, "totem_lirc_default");
287
if (path == NULL || lirc_readconfig (path, &pi->lirc_config, NULL) == -1) {
248
path = totem_plugin_find_file ("lirc", "totem_lirc_default");
249
if (path == NULL || lirc_readconfig (path, &pi->priv->lirc_config, NULL) == -1) {
289
253
g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
290
254
_("Couldn't read lirc configuration."));
296
261
/* Load the user config, doesn't matter if it's not there */
297
lirc_readconfig (NULL, &pi->lirc_config, NULL);
262
lirc_readconfig (NULL, &pi->priv->lirc_config, NULL);
299
pi->lirc_channel = g_io_channel_unix_new (fd);
300
g_io_channel_set_encoding (pi->lirc_channel, NULL, NULL);
301
g_io_channel_set_buffered (pi->lirc_channel, FALSE);
302
g_io_add_watch (pi->lirc_channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
264
pi->priv->lirc_channel = g_io_channel_unix_new (fd);
265
g_io_channel_set_encoding (pi->priv->lirc_channel, NULL, NULL);
266
g_io_channel_set_buffered (pi->priv->lirc_channel, FALSE);
267
g_io_add_watch (pi->priv->lirc_channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
303
268
(GIOFunc) totem_lirc_read_code, pi);
309
impl_deactivate (TotemPlugin *plugin,
272
impl_deactivate (PeasActivatable *plugin)
312
274
TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin);
313
275
GError *error = NULL;
315
if (pi->lirc_channel) {
316
g_io_channel_shutdown (pi->lirc_channel, FALSE, &error);
277
if (pi->priv->lirc_channel) {
278
g_io_channel_shutdown (pi->priv->lirc_channel, FALSE, &error);
317
279
if (error != NULL) {
318
280
g_warning ("Couldn't destroy lirc connection: %s",
320
282
g_error_free (error);
322
pi->lirc_channel = NULL;
284
pi->priv->lirc_channel = NULL;
325
if (pi->lirc_config) {
326
lirc_freeconfig (pi->lirc_config);
327
pi->lirc_config = NULL;
287
if (pi->priv->lirc_config) {
288
lirc_freeconfig (pi->priv->lirc_config);
289
pi->priv->lirc_config = NULL;
333
g_object_unref (pi->totem);
294
if (pi->priv->totem) {
295
g_object_unref (pi->priv->totem);
296
pi->priv->totem = NULL;