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

« back to all changes in this revision

Viewing changes to plugins/iradio/rb-iradio-source.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:
44
44
#include "rb-util.h"
45
45
#include "rb-file-helpers.h"
46
46
#include "totem-pl-parser.h"
47
 
#include "rb-preferences.h"
48
47
#include "rb-dialog.h"
49
48
#include "rb-station-properties-dialog.h"
50
49
#include "rb-uri-dialog.h"
51
50
#include "rb-debug.h"
52
 
#include "eel-gconf-extensions.h"
53
51
#include "rb-shell-player.h"
54
52
#include "rb-player.h"
55
53
#include "rb-metadata.h"
56
 
#include "rb-plugin.h"
57
54
#include "rb-cut-and-paste-code.h"
58
55
#include "rb-source-search-basic.h"
59
56
 
79
76
static void rb_iradio_source_songs_show_popup_cb (RBEntryView *view,
80
77
                                                  gboolean over_entry,
81
78
                                                  RBIRadioSource *source);
82
 
static void paned_size_allocate_cb (GtkWidget *widget,
83
 
                                    GtkAllocation *allocation,
84
 
                                    RBIRadioSource *source);
85
 
static void rb_iradio_source_state_pref_changed (GConfClient *client,
86
 
                                                 guint cnxn_id,
87
 
                                                 GConfEntry *entry,
88
 
                                                 RBIRadioSource *source);
89
 
static void rb_iradio_source_first_time_changed (GConfClient *client,
90
 
                                                 guint cnxn_id,
91
 
                                                 GConfEntry *entry,
92
 
                                                 RBIRadioSource *source);
93
 
static void rb_iradio_source_show_browser (RBIRadioSource *source,
94
 
                                           gboolean show);
95
 
static void rb_iradio_source_state_prefs_sync (RBIRadioSource *source);
96
79
static void genre_selected_cb (RBPropertyView *propview, const char *name,
97
80
                               RBIRadioSource *iradio_source);
98
81
static void genre_selection_reset_cb (RBPropertyView *propview, RBIRadioSource *iradio_source);
99
 
static void rb_iradio_source_songs_view_sort_order_changed_cb (RBEntryView *view, RBIRadioSource *source);
 
82
static void rb_iradio_source_songs_view_sort_order_changed_cb (GObject *object, GParamSpec *pspec, RBIRadioSource *source);
100
83
static char *guess_uri_scheme (const char *uri);
101
84
 
102
85
/* entry type */
110
93
static void impl_get_status (RBDisplayPage *page, char **text, char **progress_text, float *progress);
111
94
 
112
95
/* source methods */
113
 
static char *impl_get_browser_key (RBSource *source);
114
96
static RBEntryView *impl_get_entry_view (RBSource *source);
115
97
static void impl_search (RBSource *source, RBSourceSearch *search, const char *cur_text, const char *new_text);
116
98
static void impl_delete (RBSource *source);
141
123
                                       RBSource *source,
142
124
                                       RBIRadioSource *iradio_source);
143
125
 
144
 
#define CMD_PATH_SHOW_BROWSER "/commands/ShowBrowser"
145
 
#define CMD_PATH_CURRENT_STATION "/commands/CurrentStation"
146
 
#define CMD_PATH_SONG_INFO    "/commands/SongInfo"
147
 
 
148
 
#define CONF_UI_IRADIO_DIR CONF_PREFIX "/ui/iradio"
149
 
#define CONF_UI_IRADIO_COLUMNS_SETUP CONF_PREFIX "/ui/iradio/columns_setup"
150
 
#define CONF_STATE_IRADIO_DIR CONF_PREFIX "/state/iradio"
151
 
#define CONF_STATE_PANED_POSITION CONF_PREFIX "/state/iradio/paned_position"
152
 
#define CONF_STATE_IRADIO_SORTING CONF_PREFIX "/state/iradio/sorting"
153
 
#define CONF_STATE_SHOW_BROWSER   CONF_PREFIX "/state/iradio/show_browser"
 
126
enum
 
127
{
 
128
        PROP_0,
 
129
        PROP_SHOW_BROWSER
 
130
};
154
131
 
155
132
struct RBIRadioSourcePrivate
156
133
{
168
145
        RhythmDBQuery *search_query;
169
146
        RBSourceSearch *default_search;
170
147
 
171
 
        guint prefs_notify_id;
172
 
        guint first_time_notify_id;
173
 
        gboolean firstrun_done;
174
 
 
175
148
        RBShellPlayer *player;
176
149
 
177
150
        gint info_available_id;
193
166
        {  "_NETSCAPE_URL", 0, 1 },
194
167
};
195
168
 
196
 
G_DEFINE_TYPE (RBIRadioSource, rb_iradio_source, RB_TYPE_STREAMING_SOURCE);
 
169
G_DEFINE_DYNAMIC_TYPE (RBIRadioSource, rb_iradio_source, RB_TYPE_STREAMING_SOURCE);
197
170
 
198
 
G_DEFINE_TYPE (RBIRadioEntryType, rb_iradio_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 
171
G_DEFINE_DYNAMIC_TYPE (RBIRadioEntryType, rb_iradio_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
199
172
 
200
173
static void
201
174
rb_iradio_entry_type_class_init (RBIRadioEntryTypeClass *klass)
206
179
}
207
180
 
208
181
static void
 
182
rb_iradio_entry_type_class_finalize (RBIRadioEntryTypeClass *klass)
 
183
{
 
184
}
 
185
 
 
186
static void
209
187
rb_iradio_entry_type_init (RBIRadioEntryType *etype)
210
188
{
211
189
}
232
210
        source_class->impl_can_delete = (RBSourceFeatureFunc) rb_true_function;
233
211
        source_class->impl_can_pause = (RBSourceFeatureFunc) rb_false_function;
234
212
        source_class->impl_delete = impl_delete;
235
 
        source_class->impl_get_browser_key  = impl_get_browser_key;
236
213
        source_class->impl_get_entry_view = impl_get_entry_view;
237
214
        source_class->impl_search = impl_search;
238
215
        source_class->impl_song_properties = impl_song_properties;
239
216
        source_class->impl_want_uri = impl_want_uri;
240
217
        source_class->impl_add_uri = impl_add_uri;
241
218
 
 
219
        g_object_class_override_property (object_class,
 
220
                                          PROP_SHOW_BROWSER,
 
221
                                          "show-browser");
 
222
 
242
223
        g_type_class_add_private (klass, sizeof (RBIRadioSourcePrivate));
243
224
}
244
225
 
245
226
static void
 
227
rb_iradio_source_class_finalize (RBIRadioSourceClass *klass)
 
228
{
 
229
}
 
230
 
 
231
static void
246
232
rb_iradio_source_init (RBIRadioSource *source)
247
233
{
248
234
        gint size;
304
290
                source->priv->search_query = NULL;
305
291
        }
306
292
 
307
 
        eel_gconf_notification_remove (source->priv->prefs_notify_id);
308
 
        eel_gconf_notification_remove (source->priv->first_time_notify_id);
309
 
 
310
293
        G_OBJECT_CLASS (rb_iradio_source_parent_class)->dispose (object);
311
294
}
312
295
 
316
299
        RBIRadioSource *source;
317
300
        RBShell *shell;
318
301
        GtkAction *action;
 
302
        GSettings *settings;
319
303
 
320
304
        RB_CHAIN_GOBJECT_METHOD (rb_iradio_source_parent_class, constructed, object);
321
305
        source = RB_IRADIO_SOURCE (object);
329
313
                      NULL);
330
314
        g_object_unref (shell);
331
315
 
 
316
        settings = g_settings_new ("org.gnome.rhythmbox.plugins.iradio");
 
317
        if (g_settings_get_boolean (settings, "initial-stations-loaded") == FALSE) {
 
318
                GObject *plugin;
 
319
                char *file;
 
320
 
 
321
                g_object_get (source, "plugin", &plugin, NULL);
 
322
                file = rb_find_plugin_data_file (plugin, "iradio-initial.xspf");
 
323
                if (file != NULL) {
 
324
                        char *uri = g_filename_to_uri (file, NULL, NULL);
 
325
                        if (uri != NULL) {
 
326
                                rb_iradio_source_add_from_playlist (source, uri);
 
327
                                g_free (uri);
 
328
 
 
329
                                g_settings_set_boolean (settings, "initial-stations-loaded", TRUE);
 
330
                        }
 
331
                }
 
332
                g_free (file);
 
333
                g_object_unref (plugin);
 
334
        }
 
335
 
332
336
        source->priv->action_group = _rb_display_page_register_action_group (RB_DISPLAY_PAGE (source),
333
337
                                                                             "IRadioActions",
334
338
                                                                             rb_iradio_source_actions,
344
348
 
345
349
        /* set up stations view */
346
350
        source->priv->stations = rb_entry_view_new (source->priv->db, G_OBJECT (source->priv->player),
347
 
                                                    CONF_STATE_IRADIO_SORTING,
348
351
                                                    FALSE, FALSE);
349
352
 
350
353
        rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_TITLE, TRUE);
354
357
/*      rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_PLAY_COUNT, FALSE);*/
355
358
        rb_entry_view_append_column (source->priv->stations, RB_ENTRY_VIEW_COL_LAST_PLAYED, FALSE);
356
359
        g_signal_connect_object (source->priv->stations,
357
 
                                 "sort-order-changed",
 
360
                                 "notify::sort-order",
358
361
                                 G_CALLBACK (rb_iradio_source_songs_view_sort_order_changed_cb),
359
362
                                 source, 0);
360
363
 
371
374
                           stations_view_drag_types, 2,
372
375
                           GDK_ACTION_COPY | GDK_ACTION_MOVE);
373
376
 
374
 
        g_signal_connect_object (source->priv->stations,
375
 
                                 "size_allocate",
376
 
                                 G_CALLBACK (paned_size_allocate_cb),
377
 
                                 source, 0);
378
377
        g_signal_connect_object (source->priv->stations, "show_popup",
379
378
                                 G_CALLBACK (rb_iradio_source_songs_show_popup_cb), source, 0);
380
379
 
382
381
        source->priv->genres = rb_property_view_new (source->priv->db,
383
382
                                                     RHYTHMDB_PROP_GENRE,
384
383
                                                     _("Genre"));
 
384
        gtk_widget_show_all (GTK_WIDGET (source->priv->genres));
 
385
        gtk_widget_set_no_show_all (GTK_WIDGET (source->priv->genres), TRUE);
385
386
        g_signal_connect_object (source->priv->genres,
386
387
                                 "property-selected",
387
388
                                 G_CALLBACK (genre_selected_cb),
401
402
 
402
403
        gtk_box_pack_start (GTK_BOX (source->priv->vbox), source->priv->paned, TRUE, TRUE, 0);
403
404
 
404
 
        source->priv->prefs_notify_id =
405
 
                eel_gconf_notification_add (CONF_STATE_IRADIO_DIR,
406
 
                                            (GConfClientNotifyFunc) rb_iradio_source_state_pref_changed,
407
 
                                            source);
408
 
        source->priv->firstrun_done = eel_gconf_get_boolean (CONF_FIRST_TIME);
409
 
 
410
 
        source->priv->first_time_notify_id =
411
 
                eel_gconf_notification_add (CONF_FIRST_TIME,
412
 
                                            (GConfClientNotifyFunc) rb_iradio_source_first_time_changed,
413
 
                                            source);
 
405
        rb_source_bind_settings (RB_SOURCE (source),
 
406
                                 GTK_WIDGET (source->priv->stations),
 
407
                                 source->priv->paned,
 
408
                                 GTK_WIDGET (source->priv->genres));
414
409
 
415
410
        gtk_widget_show_all (GTK_WIDGET (source));
416
411
 
417
 
        rb_iradio_source_state_prefs_sync (source);
418
 
 
419
412
        g_signal_connect_object (source->priv->player, "playing-source-changed",
420
413
                                 G_CALLBACK (playing_source_changed_cb),
421
414
                                 source, 0);
431
424
                               const GValue *value,
432
425
                               GParamSpec *pspec)
433
426
{
434
 
        /*RBIRadioSource *source = RB_IRADIO_SOURCE (object);*/
 
427
        RBIRadioSource *source = RB_IRADIO_SOURCE (object);
435
428
 
436
429
        switch (prop_id) {
 
430
        case PROP_SHOW_BROWSER:
 
431
                gtk_widget_set_visible (GTK_WIDGET (source->priv->genres), g_value_get_boolean (value));
 
432
                break;
437
433
        default:
438
434
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
439
435
                break;
446
442
                               GValue *value,
447
443
                               GParamSpec *pspec)
448
444
{
449
 
        /*RBIRadioSource *source = RB_IRADIO_SOURCE (object);*/
 
445
        RBIRadioSource *source = RB_IRADIO_SOURCE (object);
450
446
 
451
447
        switch (prop_id) {
 
448
        case PROP_SHOW_BROWSER:
 
449
                g_value_set_boolean (value, gtk_widget_get_visible (GTK_WIDGET (source->priv->genres)));
 
450
                break;
452
451
        default:
453
452
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
454
453
                break;
456
455
}
457
456
 
458
457
RBSource *
459
 
rb_iradio_source_new (RBShell *shell, RBPlugin *plugin)
 
458
rb_iradio_source_new (RBShell *shell, GObject *plugin)
460
459
{
461
460
        RBSource *source;
462
461
        RhythmDBEntryType *entry_type;
463
462
        RhythmDB *db;
 
463
        GSettings *settings;
464
464
 
465
465
        g_object_get (shell, "db", &db, NULL);
466
466
 
476
476
        }
477
477
        g_object_unref (db);
478
478
 
 
479
        settings = g_settings_new ("org.gnome.rhythmbox.plugins.iradio");
479
480
        source = RB_SOURCE (g_object_new (RB_TYPE_IRADIO_SOURCE,
480
481
                                          "name", _("Radio"),
481
482
                                          "shell", shell,
482
483
                                          "entry-type", entry_type,
483
484
                                          "plugin", plugin,
484
485
                                          "search-type", RB_SOURCE_SEARCH_INCREMENTAL,
 
486
                                          "settings", g_settings_get_child (settings, "source"),
485
487
                                          NULL));
 
488
        g_object_unref (settings);
486
489
        rb_shell_register_entry_type_for_source (shell, source, entry_type);
487
490
        return source;
488
491
}
621
624
        rb_streaming_source_get_progress (RB_STREAMING_SOURCE (source), progress_text, progress);
622
625
}
623
626
 
624
 
static char *
625
 
impl_get_browser_key (RBSource *asource)
626
 
{
627
 
        return g_strdup (CONF_STATE_SHOW_BROWSER);
628
 
}
629
 
 
630
627
static void
631
628
impl_delete (RBSource *asource)
632
629
{
648
645
impl_song_properties (RBSource *asource)
649
646
{
650
647
        RBIRadioSource *source = RB_IRADIO_SOURCE (asource);
651
 
        RBPlugin *plugin;
 
648
        GObject *plugin;
652
649
        GtkWidget *dialog;
653
650
 
654
651
        g_object_get (source, "plugin", &plugin, NULL);
704
701
}
705
702
 
706
703
static void
707
 
paned_size_allocate_cb (GtkWidget *widget,
708
 
                        GtkAllocation *allocation,
709
 
                        RBIRadioSource *source)
710
 
{
711
 
        /* save state */
712
 
        rb_debug ("paned size allocate");
713
 
        eel_gconf_set_integer (CONF_STATE_PANED_POSITION,
714
 
                               gtk_paned_get_position (GTK_PANED (source->priv->paned)));
715
 
}
716
 
 
717
 
static void
718
 
rb_iradio_source_state_prefs_sync (RBIRadioSource *source)
719
 
{
720
 
        rb_debug ("syncing state");
721
 
        gtk_paned_set_position (GTK_PANED (source->priv->paned),
722
 
                                eel_gconf_get_integer (CONF_STATE_PANED_POSITION));
723
 
        rb_iradio_source_show_browser (source,
724
 
                                       eel_gconf_get_boolean (CONF_STATE_SHOW_BROWSER));
725
 
}
726
 
 
727
 
static void
728
 
rb_iradio_source_state_pref_changed (GConfClient *client,
729
 
                                     guint cnxn_id,
730
 
                                     GConfEntry *entry,
731
 
                                     RBIRadioSource *source)
732
 
{
733
 
        rb_debug ("state prefs changed");
734
 
        rb_iradio_source_state_prefs_sync (source);
735
 
}
736
 
 
737
 
static void
738
 
rb_iradio_source_songs_view_sort_order_changed_cb (RBEntryView *view,
 
704
rb_iradio_source_songs_view_sort_order_changed_cb (GObject *object,
 
705
                                                   GParamSpec *pspec,
739
706
                                                   RBIRadioSource *source)
740
707
{
741
708
        rb_debug ("sort order changed");
742
 
 
743
 
        rb_entry_view_resort_model (view);
 
709
        rb_entry_view_resort_model (RB_ENTRY_VIEW (object));
744
710
}
745
711
 
746
712
static void
788
754
}
789
755
 
790
756
static void
791
 
rb_iradio_source_show_browser (RBIRadioSource *source,
792
 
                               gboolean show)
793
 
{
794
 
        GtkWidget *genreswidget = GTK_WIDGET (source->priv->genres);
795
 
 
796
 
        if (show == TRUE) {
797
 
                gtk_widget_show (genreswidget);
798
 
        } else {
799
 
                gtk_widget_hide (genreswidget);
800
 
        }
801
 
}
802
 
 
803
 
static void
804
757
rb_iradio_source_do_query (RBIRadioSource *source)
805
758
{
806
759
        RhythmDBQueryModel *genre_query_model = NULL;
941
894
}
942
895
 
943
896
static void
944
 
rb_iradio_source_first_time_changed (GConfClient *client,
945
 
                                     guint cnxn_id,
946
 
                                     GConfEntry *entry,
947
 
                                     RBIRadioSource *source)
948
 
{
949
 
        char *uri;
950
 
        char *file;
951
 
        RBPlugin *plugin;
952
 
 
953
 
        if (source->priv->firstrun_done || !gconf_value_get_bool (entry->value))
954
 
                return;
955
 
 
956
 
        g_object_get (source, "plugin", &plugin, NULL);
957
 
        file = rb_plugin_find_file (plugin, "iradio-initial.xspf");
958
 
        if (file != NULL) {
959
 
                GFile *f;
960
 
 
961
 
                f = g_file_new_for_path (file);
962
 
                uri = g_file_get_uri (f);
963
 
 
964
 
                rb_iradio_source_add_from_playlist (source, uri);
965
 
 
966
 
                g_object_unref (f);
967
 
                g_free (uri);
968
 
        }
969
 
        g_free (file);
970
 
 
971
 
        source->priv->firstrun_done = TRUE;
972
 
}
973
 
 
974
 
static void
975
897
stations_view_drag_data_received_cb (GtkWidget *widget,
976
898
                                     GdkDragContext *dc,
977
899
                                     gint x,
1213
1135
        g_object_unref (backend);
1214
1136
}
1215
1137
 
 
1138
void
 
1139
_rb_iradio_source_register_type (GTypeModule *module)
 
1140
{
 
1141
        rb_iradio_entry_type_register_type (module);
 
1142
        rb_iradio_source_register_type (module);
 
1143
}