~wongchiachen/ubuntu/precise/totem/hey_about_dialog

« back to all changes in this revision

Viewing changes to src/plugins/lirc/totem-lirc.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-20 16:38:02 UTC
  • mfrom: (1.11.13 upstream) (2.1.17 experimental)
  • Revision ID: james.westby@ubuntu.com-20110520163802-p3lohdmfvws2jqeo
Tags: 3.0.1-0ubuntu1
* Resynchronize on Debian, remaining diffs:
* debian/control.in:
  - use suggests rather than recommends for universe gstreamer components
  - add totem-plugins-extra for the components which have depends in universe
  - add build-depends on gnome-common, dh-autoreconf, 
    liblaunchpad-intrgration-3.0-dev, hardening-wrapper
  - drop build-depends on libepc-ui-dev, python-feedparser, xulrunner-dev,
    libtracker-sparql-0.10-dev
  - add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - change refences from Iceweasel to Firefox
  - recommends gnome-icon-theme-symbolic rather than depending on it
  - list firefox as a totem-mozilla recommends before epiphany-browser
  - libtotem replaces totem (<< 3.0.1-1) for ppa upgrades
* debian/totem-common.install:
  - Install apport hook
* debian/totem-plugins-extra.install:
  - Plugins split out ouf totem-plugins
* debian/totem-plugins.install:    
  - Move some plugins to totem-plugins-extra
* debian/totem.preinst:
  - No longer required as Lucid has been released
* debian/patches/01_fake_keypresses.patch:
  - dropped it's an old workaround and should not be required
* debian/patches/02_lpi.patch:
  - Launchpad integration
* debian/patches/03_default_options.patch: 
  - enable the youtube option by default
* debian/patches/70_bbc_plugin.patch:
  - bbc content viewer, needs to be fixed for the new version
* debian/source_totem.py:
  - ubuntu apport debugging
* debian/rules:
  - run autoreconf on build
* debian/watch:
  - Watch for unstable versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <glib.h>
34
34
#include <glib-object.h>
35
35
#include <glib/gi18n-lib.h>
36
 
#include <gmodule.h>
37
36
#include <string.h>
38
 
 
 
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>
41
42
 
42
43
#include "totem-plugin.h"
43
44
#include "totem.h"
 
45
#include "totem-dirs.h"
44
46
 
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))
51
53
 
52
 
typedef struct
53
 
{
54
 
        TotemPlugin   parent;
55
 
 
 
54
typedef struct {
56
55
        GIOChannel *lirc_channel;
57
56
        struct lirc_config *lirc_config;
58
57
 
59
58
        TotemObject *totem;
60
 
} TotemLircPlugin;
61
 
 
62
 
typedef struct
63
 
{
64
 
        TotemPluginClass parent_class;
65
 
} TotemLircPluginClass;
 
59
} TotemLircPluginPrivate;
66
60
 
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"
96
90
 
97
 
G_MODULE_EXPORT GType register_totem_plugin     (GTypeModule *module);
98
 
GType   totem_lirc_plugin_get_type              (void) G_GNUC_CONST;
99
 
 
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);
104
 
 
105
 
TOTEM_PLUGIN_REGISTER(TotemLircPlugin, totem_lirc_plugin)
106
 
 
107
 
static void
108
 
totem_lirc_plugin_class_init (TotemLircPluginClass *klass)
109
 
{
110
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
111
 
        TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
112
 
 
113
 
        object_class->finalize = totem_lirc_plugin_finalize;
114
 
 
115
 
        plugin_class->activate = impl_activate;
116
 
        plugin_class->deactivate = impl_deactivate;
117
 
}
118
 
 
119
 
static void
120
 
totem_lirc_plugin_init (TotemLircPlugin *plugin)
121
 
{
122
 
}
123
 
 
124
 
static void
125
 
totem_lirc_plugin_finalize (GObject *object)
126
 
{
127
 
        G_OBJECT_CLASS (totem_lirc_plugin_parent_class)->finalize (object);
128
 
}
 
91
TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_LIRC_PLUGIN, TotemLircPlugin, totem_lirc_plugin)
129
92
 
130
93
static char *
131
94
totem_lirc_get_url (const char *str)
140
103
        return g_strdup (s + 1);
141
104
}
142
105
 
143
 
static TotemRemoteSetting
 
106
static gint
144
107
totem_lirc_to_setting (const gchar *str, char **url)
145
108
{
146
109
        if (strcmp (str, TOTEM_IR_SETTING_TOGGLE_REPEAT) == 0)
230
193
        }
231
194
 
232
195
        do {
233
 
                ok = lirc_code2char (pi->lirc_config, code, &str);
 
196
                ok = lirc_code2char (pi->priv->lirc_config, code, &str);
234
197
 
235
198
                if (ok != 0) {
236
199
                        /* Couldn't convert lirc code to string. */
243
206
                }
244
207
 
245
208
                if (g_str_has_prefix (str, TOTEM_IR_SETTING) != FALSE) {
246
 
                        TotemRemoteSetting setting;
247
 
 
248
 
                        setting = totem_lirc_to_setting (str, &url);
 
209
                        gint setting = totem_lirc_to_setting (str, &url);
249
210
                        if (setting >= 0) {
250
211
                                gboolean value;
251
212
 
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);
254
215
                        }
255
216
                } else {
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);
258
219
                }
259
220
                g_free (url);
260
221
        } while (TRUE);
264
225
        return TRUE;
265
226
}
266
227
 
267
 
static gboolean
268
 
impl_activate (TotemPlugin *plugin,
269
 
               TotemObject *totem,
270
 
               GError **error)
 
228
static void
 
229
impl_activate (PeasActivatable *plugin)
271
230
{
272
231
        TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin);
273
232
        char *path;
274
233
        int fd;
275
234
 
276
 
        pi->totem = g_object_ref (totem);
 
235
        pi->priv->totem = g_object_ref (g_object_get_data (G_OBJECT (plugin), "object"));
277
236
 
278
 
        fd = lirc_init ("Totem", 0);
 
237
        fd = lirc_init ((char*) "Totem", 0);
279
238
        if (fd < 0) {
 
239
                //FIXME
 
240
#if 0
280
241
                g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
281
242
                                     _("Couldn't initialize lirc."));
282
243
                return FALSE;
 
244
#endif
283
245
        }
284
246
 
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) {
288
250
                g_free (path);
 
251
                //FIXME
 
252
#if 0
289
253
                g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
290
254
                                     _("Couldn't read lirc configuration."));
 
255
#endif
291
256
                close (fd);
292
 
                return FALSE;
 
257
                return;
293
258
        }
294
259
        g_free (path);
295
260
 
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);
298
263
 
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);
304
 
 
305
 
        return TRUE;
306
269
}
307
270
 
308
271
static void
309
 
impl_deactivate (TotemPlugin *plugin,
310
 
                 TotemObject *totem)
 
272
impl_deactivate (PeasActivatable *plugin)
311
273
{
312
274
        TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin);
313
275
        GError *error = NULL;
314
276
 
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",
319
281
                                   error->message);
320
282
                        g_error_free (error);
321
283
                }
322
 
                pi->lirc_channel = NULL;
 
284
                pi->priv->lirc_channel = NULL;
323
285
        }
324
286
 
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;
328
290
 
329
291
                lirc_deinit ();
330
292
        }
331
293
 
332
 
        if (pi->totem) {
333
 
                g_object_unref (pi->totem);
334
 
                pi->totem = NULL;
 
294
        if (pi->priv->totem) {
 
295
                g_object_unref (pi->priv->totem);
 
296
                pi->priv->totem = NULL;
335
297
        }
336
298
}
 
299