~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to plugins/mtpdevice/rb-mtp-plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include <dbus/dbus-glib-lowlevel.h>
49
49
#endif
50
50
 
 
51
#include "rb-plugin-macros.h"
51
52
#include "rb-source.h"
52
53
#include "rb-display-page-group.h"
53
54
#include "rb-display-page-tree.h"
54
55
#include "rb-mtp-source.h"
55
 
#include "rb-plugin.h"
 
56
#include "rb-mtp-thread.h"
56
57
#include "rb-debug.h"
57
58
#include "rb-file-helpers.h"
58
59
#include "rb-util.h"
71
72
 
72
73
typedef struct
73
74
{
74
 
        RBPlugin parent;
 
75
        PeasExtensionBase parent;
75
76
 
76
 
        RBShell *shell;
77
77
        GtkActionGroup *action_group;
78
78
        guint ui_merge_id;
79
79
 
89
89
 
90
90
typedef struct
91
91
{
92
 
        RBPluginClass parent_class;
 
92
        PeasExtensionBaseClass parent_class;
93
93
} RBMtpPluginClass;
94
94
 
95
95
 
96
 
G_MODULE_EXPORT GType register_rb_plugin (GTypeModule *module);
97
 
GType rb_mtp_plugin_get_type (void) G_GNUC_CONST;
 
96
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
98
97
 
99
98
static void rb_mtp_plugin_init (RBMtpPlugin *plugin);
100
 
static void rb_mtp_plugin_finalize (GObject *object);
101
 
static void impl_activate (RBPlugin *plugin, RBShell *shell);
102
 
static void impl_deactivate (RBPlugin *plugin, RBShell *shell);
103
99
 
104
100
#if defined(HAVE_GUDEV)
105
101
static RBSource* create_source_device_cb (RBRemovableMediaManager *rmm, GObject *device, RBMtpPlugin *plugin);
116
112
GType rb_mtp_src_get_type (void);
117
113
GType rb_mtp_sink_get_type (void);
118
114
 
119
 
RB_PLUGIN_REGISTER(RBMtpPlugin, rb_mtp_plugin)
 
115
RB_DEFINE_PLUGIN(RB_TYPE_MTP_PLUGIN, RBMtpPlugin, rb_mtp_plugin,)
120
116
 
121
117
static GtkActionEntry rb_mtp_plugin_actions [] =
122
118
{
129
125
};
130
126
 
131
127
static void
132
 
rb_mtp_plugin_class_init (RBMtpPluginClass *klass)
133
 
{
134
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
135
 
        RBPluginClass *plugin_class = RB_PLUGIN_CLASS (klass);
136
 
 
137
 
        object_class->finalize = rb_mtp_plugin_finalize;
138
 
 
139
 
        plugin_class->activate = impl_activate;
140
 
        plugin_class->deactivate = impl_deactivate;
141
 
 
142
 
        /* register types used by the plugin */
143
 
        RB_PLUGIN_REGISTER_TYPE (rb_mtp_source);
144
 
 
145
 
        /* ensure the gstreamer elements get linked in */
146
 
        rb_mtp_src_get_type ();
147
 
        rb_mtp_sink_get_type ();
148
 
}
149
 
 
150
 
static void
151
128
rb_mtp_plugin_init (RBMtpPlugin *plugin)
152
129
{
153
130
        rb_debug ("RBMtpPlugin initialising");
155
132
}
156
133
 
157
134
static void
158
 
rb_mtp_plugin_finalize (GObject *object)
159
 
{
160
 
        rb_debug ("RBMtpPlugin finalising");
161
 
 
162
 
        G_OBJECT_CLASS (rb_mtp_plugin_parent_class)->finalize (object);
163
 
}
164
 
 
165
 
static void
166
 
impl_activate (RBPlugin *bplugin, RBShell *shell)
 
135
impl_activate (PeasActivatable *bplugin)
167
136
{
168
137
        RBMtpPlugin *plugin = RB_MTP_PLUGIN (bplugin);
169
138
        GtkUIManager *uimanager = NULL;
170
139
        RBRemovableMediaManager *rmm;
171
140
        char *file = NULL;
 
141
        RBShell *shell;
172
142
#if defined(HAVE_GUDEV)
173
143
        gboolean rmm_scanned = FALSE;
174
144
#else
176
146
        LIBMTP_raw_device_t *mtp_devices;
177
147
#endif
178
148
 
179
 
        plugin->shell = shell;
 
149
        g_object_get (plugin, "object", &shell, NULL);
180
150
 
181
151
        g_object_get (shell,
182
152
                     "ui-manager", &uimanager,
189
159
        gtk_action_group_set_translation_domain (plugin->action_group,
190
160
                                                 GETTEXT_PACKAGE);
191
161
        _rb_action_group_add_display_page_actions (plugin->action_group,
192
 
                                                   G_OBJECT (plugin->shell),
 
162
                                                   G_OBJECT (shell),
193
163
                                                   rb_mtp_plugin_actions,
194
164
                                                   G_N_ELEMENTS (rb_mtp_plugin_actions));
195
165
        gtk_ui_manager_insert_action_group (uimanager, plugin->action_group, 0);
196
 
        file = rb_plugin_find_file (bplugin, "mtp-ui.xml");
 
166
        file = rb_find_plugin_data_file (G_OBJECT (bplugin), "mtp-ui.xml");
197
167
        plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager, file, NULL);
198
168
        g_object_unref (uimanager);
 
169
        g_object_unref (shell);
199
170
 
200
171
        /* device detection */
201
172
#if defined(HAVE_GUDEV)
243
214
}
244
215
 
245
216
static void
246
 
impl_deactivate (RBPlugin *bplugin, RBShell *shell)
 
217
impl_deactivate (PeasActivatable *bplugin)
247
218
{
248
219
        RBMtpPlugin *plugin = RB_MTP_PLUGIN (bplugin);
249
220
        GtkUIManager *uimanager = NULL;
250
221
        RBRemovableMediaManager *rmm = NULL;
 
222
        RBShell *shell;
251
223
 
 
224
        g_object_get (plugin, "object", &shell, NULL);
252
225
        g_object_get (shell,
253
226
                      "ui-manager", &uimanager,
254
227
                      "removable-media-manager", &rmm,
283
256
 
284
257
        g_object_unref (uimanager);
285
258
        g_object_unref (rmm);
 
259
        g_object_unref (shell);
286
260
}
287
261
 
288
262
static void
371
345
                    device_list[i].product_id == model) {
372
346
                        LIBMTP_raw_device_t rawdevice;
373
347
                        RBSource *source;
 
348
                        RBShell *shell;
374
349
 
375
350
                        rb_debug ("found libmtp device list entry (model: %s, vendor: %s)",
376
351
                                  device_list[i].vendor, device_list[i].product);
379
354
                        rawdevice.bus_location = busnum;
380
355
                        rawdevice.devnum = devnum;
381
356
 
382
 
                        source = rb_mtp_source_new (plugin->shell, RB_PLUGIN (plugin), device, &rawdevice);
 
357
                        g_object_get (plugin, "object", &shell, NULL);
 
358
                        source = rb_mtp_source_new (shell, G_OBJECT (plugin), device, &rawdevice);
383
359
 
384
360
                        plugin->mtp_sources = g_list_prepend (plugin->mtp_sources, source);
385
361
                        g_signal_connect_object (G_OBJECT (source),
386
362
                                                "deleted", G_CALLBACK (source_deleted_cb),
387
363
                                                plugin, 0);
 
364
                        g_object_unref (shell);
388
365
                        return source;
389
366
                }
390
367
        }
425
402
                rb_debug ("detected MTP device: device number %d (bus location %u)", raw_devices[i].devnum, raw_devices[i].bus_location);
426
403
                if (raw_devices[i].devnum == device_num) {
427
404
                        RBSource *source;
 
405
                        RBShell *shell;
428
406
 
429
407
                        rb_debug ("device matched, creating a source");
430
 
                        source = RB_SOURCE (rb_mtp_source_new (plugin->shell, RB_PLUGIN (plugin), udi, &raw_devices[i]));
 
408
                        g_object_get (plugin, "object", &shell, NULL);
 
409
                        source = RB_SOURCE (rb_mtp_source_new (shell, G_OBJECT (plugin), udi, &raw_devices[i]));
431
410
 
432
 
                        rb_shell_append_display_page (plugin->shell, RB_DISPLAY_PAGE (source), RB_DISPLAY_PAGE_GROUP_DEVICES);
 
411
                        rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (source), RB_DISPLAY_PAGE_GROUP_DEVICES);
433
412
                        plugin->mtp_sources = g_list_prepend (plugin->mtp_sources, source);
434
413
                        g_signal_connect_object (source,
435
414
                                                "deleted", G_CALLBACK (source_deleted_cb),
436
415
                                                plugin, 0);
 
416
                        g_object_unref (shell);
437
417
                }
438
418
        }
439
419
}
513
493
}
514
494
 
515
495
#endif
 
496
 
 
497
G_MODULE_EXPORT void
 
498
peas_register_types (PeasObjectModule *module)
 
499
{
 
500
        rb_mtp_plugin_register_type (G_TYPE_MODULE (module));
 
501
        _rb_mtp_source_register_type (G_TYPE_MODULE (module));
 
502
        _rb_mtp_thread_register_type (G_TYPE_MODULE (module));
 
503
 
 
504
        /* ensure the gstreamer elements get linked in */
 
505
        rb_mtp_src_get_type ();
 
506
        rb_mtp_sink_get_type ();
 
507
 
 
508
        peas_object_module_register_extension_type (module,
 
509
                                                    PEAS_TYPE_ACTIVATABLE,
 
510
                                                    RB_TYPE_MTP_PLUGIN);
 
511
}