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

« back to all changes in this revision

Viewing changes to plugins/daap/rb-dacp-pairing-page.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:
40
40
#include "rhythmdb.h"
41
41
#include "rb-shell.h"
42
42
#include "rb-display-page-group.h"
43
 
#include "eel-gconf-extensions.h"
44
43
#include "rb-stock-icons.h"
45
44
#include "rb-debug.h"
46
45
#include "rb-util.h"
47
46
#include "rb-file-helpers.h"
48
47
#include "rb-builder-helpers.h"
49
48
#include "rb-dialog.h"
50
 
#include "rb-preferences.h"
51
49
#include "rb-playlist-manager.h"
52
50
#include "rb-shell-player.h"
53
51
#include "rb-display-page-model.h"
82
80
static void dacp_remote_removed (DACPShare *share, gchar *service_name, RBDaapPlugin *plugin);
83
81
 
84
82
/* DACPShare signals */
85
 
static gboolean dacp_lookup_guid (DACPShare *share, gchar *guid);
86
 
static void     dacp_add_guid    (DACPShare *share, gchar *guid);
 
83
static gboolean dacp_lookup_guid (DACPShare *share, gchar *guid, GSettings *settings);
 
84
static void     dacp_add_guid    (DACPShare *share, gchar *guid, GSettings *settings);
87
85
 
88
86
static void dacp_player_updated (RBDACPPlayer *player, DACPShare *share);
89
87
 
107
105
        PROP_SERVICE_NAME
108
106
};
109
107
 
110
 
G_DEFINE_TYPE (RBDACPPairingPage, rb_dacp_pairing_page, RB_TYPE_DISPLAY_PAGE)
 
108
G_DEFINE_DYNAMIC_TYPE (RBDACPPairingPage, rb_dacp_pairing_page, RB_TYPE_DISPLAY_PAGE)
111
109
 
112
110
static gboolean
113
111
entry_insert_text_cb (GtkWidget *entry, gchar *text, gint len, gint *position, RBDACPPairingPage *page)
229
227
}
230
228
 
231
229
static void
 
230
rb_dacp_pairing_page_class_finalize (RBDACPPairingPageClass *klass)
 
231
{
 
232
}
 
233
 
 
234
static void
232
235
rb_dacp_pairing_page_init (RBDACPPairingPage *page)
233
236
{
234
237
        page->priv = G_TYPE_INSTANCE_GET_PRIVATE (page,
244
247
        GtkWidget *passcode_widget;
245
248
        GtkWidget *close_pairing_button;
246
249
        PangoFontDescription *font;
247
 
        RBPlugin *plugin;
 
250
        GObject *plugin;
248
251
        int i;
249
252
 
250
253
        g_object_get (page, "plugin", &plugin, NULL);
251
254
 
252
 
        builder_filename = rb_plugin_find_file (RB_PLUGIN (plugin), "daap-prefs.ui");
 
255
        builder_filename = rb_find_plugin_data_file (G_OBJECT (plugin), "daap-prefs.ui");
253
256
        g_assert (builder_filename != NULL);
254
257
 
255
258
        page->priv->builder = rb_builder_load (builder_filename, NULL);
330
333
}
331
334
 
332
335
RBDACPPairingPage *
333
 
rb_dacp_pairing_page_new (RBPlugin *plugin,
 
336
rb_dacp_pairing_page_new (GObject *plugin,
334
337
                          RBShell *shell,
335
338
                          DACPShare *dacp_share,
336
339
                          const char *display_name,
341
344
        int icon_size;
342
345
        GdkPixbuf *icon_pixbuf;
343
346
 
344
 
        icon_filename = rb_plugin_find_file (plugin, "remote-icon.png");
 
347
        icon_filename = rb_find_plugin_data_file (plugin, "remote-icon.png");
345
348
        gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_size, NULL);
346
349
        icon_pixbuf = gdk_pixbuf_new_from_file_at_size (icon_filename, icon_size, icon_size, NULL);
347
350
 
431
434
}
432
435
 
433
436
DACPShare *
434
 
rb_daap_create_dacp_share (RBPlugin *plugin)
 
437
rb_daap_create_dacp_share (GObject *plugin)
435
438
{
436
439
        DACPShare *share;
437
440
        DACPPlayer *player;
440
443
        DMAPContainerDb *container_db;
441
444
        RBPlaylistManager *playlist_manager;
442
445
        RBShell *shell;
 
446
        GSettings *share_settings;
 
447
        GSettings *daap_settings;
 
448
        GSettings *settings;
443
449
        gchar *name;
444
450
 
445
 
        g_object_get (plugin, "shell", &shell, NULL);
 
451
        g_object_get (plugin, "object", &shell, NULL);
446
452
 
447
453
        g_object_get (shell,
448
454
                      "db", &rdb,
453
459
 
454
460
        player = DACP_PLAYER (rb_dacp_player_new (shell));
455
461
 
456
 
        name = eel_gconf_get_string (CONF_DAAP_SHARE_NAME);
 
462
        share_settings = g_settings_new ("org.gnome.rhythmbox.sharing");
 
463
        name = g_settings_get_string (share_settings, "share-name");
457
464
        if (name == NULL || *name == '\0') {
458
465
                g_free (name);
459
466
                name = rb_daap_sharing_default_share_name ();
460
467
        }
 
468
        g_object_unref (share_settings);
461
469
 
462
470
        share = dacp_share_new (name, player, db, container_db);
463
471
 
 
472
        daap_settings = g_settings_new ("org.gnome.rhythmbox.plugins.daap");
 
473
        settings = g_settings_get_child (daap_settings, "dacp");
 
474
        g_object_unref (daap_settings);
 
475
 
464
476
        g_signal_connect_object (share,
465
477
                                 "add-guid",
466
478
                                 G_CALLBACK (dacp_add_guid),
467
 
                                 RB_DAAP_PLUGIN (plugin),
 
479
                                 settings,
468
480
                                 0);
469
481
        g_signal_connect_object (share,
470
482
                                 "lookup-guid",
471
483
                                 G_CALLBACK (dacp_lookup_guid),
472
 
                                 RB_DAAP_PLUGIN (plugin),
 
484
                                 settings,
473
485
                                 0);
474
486
 
475
487
        g_signal_connect_object (share,
494
506
        g_object_unref (rdb);
495
507
        g_object_unref (playlist_manager);
496
508
        g_object_unref (player);
 
509
        g_object_unref (shell);
497
510
 
498
511
        return share;
499
512
}
507
520
 
508
521
static void
509
522
dacp_add_guid (DACPShare *share,
510
 
               gchar *guid)
 
523
               gchar *guid,
 
524
               GSettings *settings)
511
525
{
512
 
        GSList *known_guids;
513
 
 
514
 
        known_guids = eel_gconf_get_string_list (CONF_KNOWN_REMOTES);
515
 
        if (g_slist_find_custom (known_guids, guid, (GCompareFunc) g_strcmp0)) {
516
 
                g_slist_free (known_guids);
517
 
                return;
 
526
        GVariantBuilder *vb;
 
527
        GVariantIter iter;
 
528
        GVariant *v;
 
529
        const char *g;
 
530
 
 
531
        v = g_settings_get_value (settings, "known-remotes");
 
532
 
 
533
        vb = g_variant_builder_new (G_VARIANT_TYPE ("as"));
 
534
        g_variant_iter_init (&iter, v);
 
535
        while (g_variant_iter_loop (&iter, "s", &g)) {
 
536
                g_variant_builder_add (vb, "s", g);
518
537
        }
519
 
        known_guids = g_slist_insert_sorted (known_guids, guid, (GCompareFunc) g_strcmp0);
520
 
        eel_gconf_set_string_list (CONF_KNOWN_REMOTES, known_guids);
521
 
 
522
 
        g_slist_free (known_guids);
 
538
 
 
539
        g_variant_builder_add (vb, "s", guid);
 
540
        g_variant_unref (v);
 
541
 
 
542
        g_settings_set_value (settings, "known-remotes", g_variant_builder_end (vb));
 
543
        g_variant_builder_unref (vb);
523
544
}
524
545
 
525
546
static gboolean
526
547
dacp_lookup_guid (DACPShare *share,
527
 
                  gchar *guid)
 
548
                  gchar *guid,
 
549
                  GSettings *settings)
528
550
{
529
 
        GSList *known_guids;
530
 
        int found;
531
 
 
532
 
        known_guids = eel_gconf_get_string_list (CONF_KNOWN_REMOTES);
533
 
        found = g_slist_find_custom (known_guids, guid, (GCompareFunc) g_strcmp0) != NULL;
534
 
 
535
 
        g_slist_free (known_guids);
 
551
        char **guids;
 
552
        gboolean found;
 
553
 
 
554
        guids = g_settings_get_strv (settings, "known-remotes");
 
555
        found = rb_str_in_strv (guid, (const char **)guids);
 
556
        g_strfreev (guids);
536
557
 
537
558
        return found;
538
559
}
594
615
 
595
616
        rb_debug ("Remote %s (%s) found", service_name, display_name);
596
617
 
597
 
        g_object_get (plugin, "shell", &shell, NULL);
 
618
        g_object_get (plugin, "object", &shell, NULL);
598
619
 
599
620
        GDK_THREADS_ENTER ();
600
621
 
611
632
                        rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (page_group), NULL);
612
633
                }
613
634
 
614
 
                page = rb_dacp_pairing_page_new (RB_PLUGIN (plugin), shell, share, display_name, service_name);
 
635
                page = rb_dacp_pairing_page_new (G_OBJECT (plugin), shell, share, display_name, service_name);
615
636
 
616
637
                rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (page), RB_DISPLAY_PAGE (page_group));
617
638
        } else {
619
640
        }
620
641
 
621
642
        GDK_THREADS_LEAVE ();
 
643
 
 
644
        g_object_unref (shell);
622
645
}
623
646
 
624
647
static void
631
654
 
632
655
        rb_debug ("Remote '%s' went away", service_name);
633
656
 
634
 
        g_object_get (plugin, "shell", &shell, NULL);
 
657
        g_object_get (plugin, "object", &shell, NULL);
635
658
 
636
659
        GDK_THREADS_ENTER ();
637
660
 
641
664
        }
642
665
 
643
666
        GDK_THREADS_LEAVE ();
 
667
 
 
668
        g_object_unref (shell);
 
669
}
 
670
 
 
671
void
 
672
_rb_dacp_pairing_page_register_type (GTypeModule *module)
 
673
{
 
674
        rb_dacp_pairing_page_register_type (module);
644
675
}