~woodrow-shen/totem/mybranch

« back to all changes in this revision

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

Tags: 2.24.3-3
* totem-mozilla.docs: ship README.browser-plugin which explains how to 
  disable the plugin for some MIME types.
* rules: remove the hack that only let totem-xine support VCDs and 
  DVDs, now that GStreamer supports them. Closes: #370789.
* 01_fake_keypresses.patch: new patch. Completely disable the broken 
  XTEST code that generates fake keypresses. Closes: #500330.
* 90_autotools.patch: regenerated.
* Build-depend on nautilus 2.22 to be sure to build the extension for 
  the correct version.
* totem-xine depends on libxine1-x.
* Standards version is 3.8.1.
* Upload to unstable.
* 04_tracker_build.patch: new patch, stolen upstream. Fix build with 
  latest tracker version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
18
18
 *
19
19
 * The Totem project hereby grant permission for non-gpl compatible GStreamer
20
20
 * plugins to be used and distributed together with GStreamer and Totem. This
46
46
#include <gmyth/gmyth_file_transfer.h>
47
47
#include <gmyth/gmyth_scheduler.h>
48
48
#include <gmyth/gmyth_util.h>
 
49
#include <gmyth_upnp.h>
 
50
 
49
51
 
50
52
#define TOTEM_TYPE_MYTHTV_PLUGIN                (totem_mythtv_plugin_get_type ())
51
53
#define TOTEM_MYTHTV_PLUGIN(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_MYTHTV_PLUGIN, TotemMythtvPlugin))
74
76
{
75
77
        TotemPlugin parent;
76
78
 
77
 
        GMythBackendInfo *b_info;
 
79
        GList *lst_b_info;
 
80
        GMythUPnP *upnp;
78
81
 
79
82
        TotemObject *totem;
80
83
        GConfClient *client;
103
106
#define THUMB_HEIGHT 32
104
107
 
105
108
static GdkPixbuf *
106
 
get_thumbnail (TotemMythtvPlugin *plugin, char *fname)
 
109
get_thumbnail (TotemMythtvPlugin *plugin, GMythBackendInfo *b_info, char *fname)
107
110
{
108
111
        GMythFileTransfer *transfer;
109
112
        GdkPixbufLoader *loader;
112
115
        guint64 to_read;
113
116
        GByteArray *data;
114
117
 
115
 
        if (gmyth_util_file_exists (plugin->b_info, fname) == FALSE)
 
118
        if (gmyth_util_file_exists (b_info, fname) == FALSE)
116
119
                return NULL;
117
120
 
118
 
        transfer = gmyth_file_transfer_new (plugin->b_info);
 
121
        transfer = gmyth_file_transfer_new (b_info);
119
122
        if (gmyth_file_transfer_open(transfer, fname) == FALSE)
120
123
                return NULL;
121
124
 
204
207
}
205
208
 
206
209
static void
207
 
totem_mythtv_list_recordings (TotemMythtvPlugin *plugin)
 
210
totem_mythtv_list_recordings (TotemMythtvPlugin *plugin,
 
211
                                                          GMythBackendInfo *b_info)
208
212
{
209
213
        GMythScheduler *scheduler;
210
214
        GList *list, *l;
211
215
 
212
 
        if (plugin->b_info == NULL)
 
216
        if (b_info == NULL)
213
217
                return;
214
218
 
215
219
        scheduler = gmyth_scheduler_new();
216
220
        if (gmyth_scheduler_connect_with_timeout(scheduler,
217
 
                                                 plugin->b_info, 5) == FALSE) {
 
221
                                                 b_info, 5) == FALSE) {
218
222
                g_message ("Couldn't connect to scheduler");
219
223
                g_object_unref (scheduler);
220
224
                return;
234
238
                RecordedInfo *recorded_info = (RecordedInfo *) l->data;
235
239
 
236
240
                if (gmyth_util_file_exists
237
 
                    (plugin->b_info, recorded_info->basename->str)) {
 
241
                    (b_info, recorded_info->basename->str)) {
238
242
                        GtkTreeIter iter;
239
243
                        GdkPixbuf *pixbuf;
240
244
                        char *full_name = NULL;
246
250
                                                             recorded_info->subtitle->str);
247
251
                        thumb_fname = g_strdup_printf ("%s.png", recorded_info->basename->str);
248
252
                        uri = g_strdup_printf ("myth://%s:%d/%s",
249
 
                                               plugin->b_info->hostname,
250
 
                                               plugin->b_info->port,
 
253
                                               b_info->hostname,
 
254
                                               b_info->port,
251
255
                                               recorded_info->basename->str);
252
 
                        pixbuf = get_thumbnail (plugin, thumb_fname);
 
256
                        pixbuf = get_thumbnail (plugin, b_info, thumb_fname);
253
257
                        g_free (thumb_fname);
254
258
 
255
259
                        gtk_list_store_insert_with_values (GTK_LIST_STORE (plugin->model), &iter, G_MAXINT32,
281
285
}
282
286
 
283
287
static void
 
288
device_found_cb (GMythUPnP *upnp,
 
289
                                 GMythBackendInfo *b_info,
 
290
                                 TotemMythtvPlugin *plugin)
 
291
{
 
292
        if (!g_list_find (plugin->lst_b_info, b_info)) {
 
293
                plugin->lst_b_info = g_list_append (plugin->lst_b_info,
 
294
                                g_object_ref (b_info));
 
295
                totem_mythtv_list_recordings (plugin, b_info);
 
296
        }
 
297
}
 
298
 
 
299
static void
 
300
device_lost_cb (GMythUPnP *upnp,
 
301
                                 GMythBackendInfo *info,
 
302
                                 TotemMythtvPlugin *plugin)
 
303
{
 
304
        GList *elem;
 
305
        GMythBackendInfo *b_info;
 
306
 
 
307
        elem = g_list_find (plugin->lst_b_info, info);
 
308
        if (elem && elem->data) {
 
309
                b_info = elem->data;
 
310
                plugin->lst_b_info = g_list_remove (plugin->lst_b_info,
 
311
                                b_info);
 
312
                g_object_unref (b_info);
 
313
        }
 
314
 
 
315
}
 
316
 
 
317
static void
284
318
totem_mythtv_update_binfo (TotemMythtvPlugin *plugin)
285
319
{
286
 
        char *address, *user, *password, *database;
287
 
        int port;
288
 
 
289
 
        if (plugin->b_info != NULL) {
290
 
                //FIXME why would this crash?
291
 
                //g_object_unref (plugin->b_info);
292
 
                plugin->b_info = NULL;
293
 
        }
294
 
 
295
 
        if (plugin->client == NULL)
296
 
                plugin->client = gconf_client_get_default ();
297
 
        if (plugin->client == NULL)
298
 
                return;
299
 
 
300
 
        address = gconf_client_get_string (plugin->client, CONF_IP, NULL);
301
 
        /* No address? */
302
 
        if (address == NULL || address[0] == '\0')
303
 
                return;
304
 
 
305
 
        user = gconf_client_get_string (plugin->client, CONF_USER, NULL);
306
 
        if (user == NULL || user[0] == '\0')
307
 
                user = g_strdup ("mythtv");
308
 
        password = gconf_client_get_string (plugin->client, CONF_PASSWORD, NULL);
309
 
        if (password == NULL || password[0] == '\0')
310
 
                password = g_strdup ("mythtv");
311
 
        database = gconf_client_get_string (plugin->client, CONF_DATABASE, NULL);
312
 
        if (database == NULL || database[0] == '\0')
313
 
                database = g_strdup ("mythconverg");
314
 
        port = gconf_client_get_int (plugin->client, CONF_PORT, NULL);
315
 
        if (port == 0)
316
 
                port = 6543;
317
 
 
318
 
        plugin->b_info = gmyth_backend_info_new_full (address,
319
 
                                                      user,
320
 
                                                      password,
321
 
                                                      database,
322
 
                                                      port);
 
320
        GList *lst;
 
321
        GList *w;
 
322
 
 
323
        /* Clear old b_info */
 
324
        if (plugin->lst_b_info != NULL) {
 
325
                g_list_foreach (plugin->lst_b_info, (GFunc) g_object_unref, NULL);
 
326
                g_list_free (plugin->lst_b_info);
 
327
                plugin->lst_b_info = NULL;
 
328
        }
 
329
 
 
330
 
 
331
        /* Using GMythUPnP to search for avaliable servers */
 
332
        if (plugin->upnp == NULL) {
 
333
                plugin->upnp = gmyth_upnp_get_instance ();
 
334
                g_signal_connect (G_OBJECT (plugin->upnp),
 
335
                                                  "device-found",
 
336
                                                  G_CALLBACK (device_found_cb),
 
337
                                                  plugin);
 
338
                plugin->upnp = gmyth_upnp_get_instance ();
 
339
                g_signal_connect (G_OBJECT (plugin->upnp),
 
340
                                                  "device-lost",
 
341
                                                  G_CALLBACK (device_lost_cb),
 
342
                                                  plugin);
 
343
        }
 
344
 
 
345
        /* Load current servers */
 
346
        lst = gmyth_upnp_get_devices (plugin->upnp);
 
347
        for (w = lst; w != NULL; w = w->next) {
 
348
                GMythBackendInfo *b_info;
 
349
 
 
350
                b_info = (GMythBackendInfo *) w->data;
 
351
                plugin->lst_b_info = g_list_append (plugin->lst_b_info,
 
352
                                b_info);
 
353
                totem_mythtv_list_recordings (plugin, b_info);
 
354
        }
 
355
        g_list_free (lst);
 
356
        gmyth_upnp_search (plugin->upnp);
323
357
}
324
358
 
325
359
static void
326
360
refresh_cb (GtkWidget *button, TotemMythtvPlugin *plugin)
327
361
{
328
362
        gtk_widget_set_sensitive (button, FALSE);
329
 
        totem_mythtv_update_binfo (plugin);
330
363
        gtk_list_store_clear (GTK_LIST_STORE (plugin->model));
 
364
        totem_mythtv_update_binfo (plugin);
331
365
        totem_gdk_window_set_waiting_cursor (plugin->sidebar->window);
332
 
        totem_mythtv_list_recordings (plugin);
333
366
        gdk_window_set_cursor (plugin->sidebar->window, NULL);
334
367
        gtk_widget_set_sensitive (button, TRUE);
335
368
}
345
378
{
346
379
        TotemMythtvPlugin *plugin = TOTEM_MYTHTV_PLUGIN(object);
347
380
 
348
 
        if (plugin->b_info != NULL) {
349
 
                g_object_unref (plugin->b_info);
350
 
                plugin->b_info = NULL;
 
381
        if (plugin->lst_b_info != NULL) {
 
382
                g_list_foreach (plugin->lst_b_info, (GFunc ) g_object_unref, NULL);
 
383
                g_list_free (plugin->lst_b_info);
 
384
                plugin->lst_b_info = NULL;
351
385
        }
352
386
        if (plugin->client != NULL) {
353
387
                g_object_unref (plugin->client);
354
388
                plugin->client = NULL;
355
389
        }
 
390
        if (plugin->upnp != NULL) {
 
391
                g_object_unref (plugin->upnp);
 
392
                plugin->upnp = NULL;
 
393
        }
 
394
        if (plugin->sidebar != NULL) {
 
395
                g_object_unref (plugin->sidebar);
 
396
                plugin->sidebar = NULL;
 
397
        }
356
398
 
357
399
        G_OBJECT_CLASS (totem_mythtv_plugin_parent_class)->finalize (object);
358
400
}
405
447
{
406
448
        TotemMythtvPlugin *tm = TOTEM_MYTHTV_PLUGIN(plugin);
407
449
 
408
 
        g_object_unref (tm->sidebar);
409
450
        totem_remove_sidebar_page (totem, "mythtv");
410
451
 
411
 
        if (tm && tm->client != NULL) {
 
452
        if (tm->lst_b_info != NULL) {
 
453
                g_list_foreach (tm->lst_b_info, (GFunc ) g_object_unref, NULL);
 
454
                g_list_free (tm->lst_b_info);
 
455
                tm->lst_b_info = NULL;
 
456
        }
 
457
        if (tm->client != NULL) {
412
458
                g_object_unref (tm->client);
413
459
                tm->client = NULL;
414
460
        }
 
461
        if (tm->upnp != NULL) {
 
462
                g_object_unref (tm->upnp);
 
463
                tm->upnp = NULL;
 
464
        }
 
465
        if (tm->sidebar != NULL) {
 
466
                gtk_widget_destroy (tm->sidebar);
 
467
                tm->sidebar = NULL;
 
468
        }
 
469
 
415
470
        g_object_unref (totem);
416
471
}
417
472