~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to sources/rb-library-source.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <libgnome/gnome-i18n.h>
26
26
#include <libgnomevfs/gnome-vfs.h>
27
27
#include <glade/glade.h>
28
 
#include <bonobo/bonobo-ui-component.h>
29
 
#include <bonobo/bonobo-window.h>
30
28
#include <string.h>
31
29
 
32
30
#include "rb-source.h"
42
40
#include "rb-util.h"
43
41
#include "rb-file-helpers.h"
44
42
#include "rb-dialog.h"
45
 
#include "rb-volume.h"
46
 
#include "rb-bonobo-helpers.h"
47
43
#include "rb-debug.h"
48
44
#include "eel-gconf-extensions.h"
49
45
#include "rb-song-info.h"
63
59
static void rb_library_source_init (RBLibrarySource *source);
64
60
static GObject *rb_library_source_constructor (GType type, guint n_construct_properties,
65
61
                                               GObjectConstructParam *construct_properties);
 
62
static void rb_library_source_dispose (GObject *object);
66
63
static void rb_library_source_finalize (GObject *object);
67
64
static void rb_library_source_set_property (GObject *object,
68
65
                                          guint prop_id,
72
69
                                          guint prop_id,
73
70
                                          GValue *value,
74
71
                                          GParamSpec *pspec);
75
 
static void rb_library_source_cmd_choose_genre (BonoboUIComponent *component,
76
 
                                                RBShell *shell,
77
 
                                                const char *verbname);
78
 
static void rb_library_source_cmd_choose_artist (BonoboUIComponent *component,
79
 
                                                 RBShell *shell,
80
 
                                                 const char *verbname);
81
 
static void rb_library_source_cmd_choose_album (BonoboUIComponent *component,
82
 
                                                RBShell *shell,
83
 
                                                const char *verbname);
 
72
static void rb_library_source_cmd_choose_genre (GtkAction *action,
 
73
                                                RBShell *shell);
 
74
static void rb_library_source_cmd_choose_artist (GtkAction *action,
 
75
                                                 RBShell *shell);
 
76
static void rb_library_source_cmd_choose_album (GtkAction *action,
 
77
                                                RBShell *shell);
84
78
static void rb_library_source_handle_genre_selection (RBLibrarySource *libsource, GList *genres);
85
79
static void rb_library_source_handle_artist_selection (RBLibrarySource *libsource, GList *artists);
86
80
static void rb_library_source_handle_album_selection (RBLibrarySource *libsource, GList *albums);
115
109
static void rb_library_source_ui_prefs_sync (RBLibrarySource *source);
116
110
static void rb_library_source_preferences_sync (RBLibrarySource *source);
117
111
/* source methods */
118
 
static const char *impl_get_status (RBSource *source);
 
112
static char *impl_get_status (RBSource *source);
119
113
static const char *impl_get_browser_key (RBSource *source);
120
 
static const char *impl_get_search_key (RBSource *source);
121
114
static GdkPixbuf *impl_get_pixbuf (RBSource *source);
122
115
static RBEntryView *impl_get_entry_view (RBSource *source);
123
116
static GList *impl_get_extra_views (RBSource *source);
126
119
static void impl_reset_filters (RBSource *source);
127
120
static GtkWidget *impl_get_config_widget (RBSource *source);
128
121
static void impl_song_properties (RBSource *source);
129
 
static const char * impl_get_artist (RBSource *player);
130
 
static const char * impl_get_album (RBSource *player);
131
122
static gboolean impl_receive_drag (RBSource *source, GtkSelectionData *data);
132
123
static gboolean impl_show_popup (RBSource *source);
 
124
static const char * impl_get_paned_key (RBLibrarySource *source);
133
125
static void rb_library_source_do_query (RBLibrarySource *source, RBLibraryQueryType qtype);
134
126
 
135
127
void rb_library_source_browser_views_activated_cb (GtkWidget *widget,
136
128
                                                 RBLibrarySource *source);
137
129
static GPtrArray * construct_query_from_selection (RBLibrarySource *source);
138
 
 
139
 
 
140
 
#define LIBRARY_SOURCE_SONGS_POPUP_PATH "/popups/LibrarySongsList"
141
 
#define LIBRARY_SOURCE_POPUP_PATH "/popups/LibrarySourceList"
 
130
static void songs_view_drag_data_received_cb (GtkWidget *widget,
 
131
                                              GdkDragContext *dc,
 
132
                                              gint x, gint y,
 
133
                                              GtkSelectionData *data,
 
134
                                              guint info, guint time,
 
135
                                              RBLibrarySource *source);
 
136
 
142
137
 
143
138
#define CONF_UI_LIBRARY_DIR CONF_PREFIX "/ui/library"
144
139
#define CONF_UI_LIBRARY_BROWSER_VIEWS CONF_PREFIX "/ui/library/browser_views"
146
141
#define CONF_STATE_LIBRARY_SORTING CONF_PREFIX "/state/library/sorting"
147
142
#define CONF_STATE_PANED_POSITION CONF_PREFIX "/state/library/paned_position"
148
143
#define CONF_STATE_SHOW_BROWSER   CONF_PREFIX "/state/library/show_browser"
149
 
#define CONF_STATE_SEARCH_TEXT   CONF_PREFIX "/state/library/search_text"
150
144
 
151
145
struct RBLibrarySourcePrivate
152
146
{
 
147
        gboolean disposed;
 
148
        
153
149
        RhythmDB *db;
154
150
        
155
151
        GtkWidget *browser;
166
162
 
167
163
        gboolean lock;
168
164
 
169
 
        char *status;
170
165
        char *artist;
171
166
        char *album;
172
167
 
186
181
        
187
182
        gboolean loading_prefs;
188
183
 
 
184
        GtkActionGroup *action_group;
189
185
        GtkWidget *config_widget;
190
186
        GSList *browser_views_group;
191
 
 
 
187
        
192
188
        RhythmDBEntryType entry_type;
 
189
 
 
190
        char *sorting_key;
 
191
        guint ui_dir_notify_id;
 
192
        guint state_paned_notify_id;
 
193
        guint state_browser_notify_id;
 
194
        guint state_sorting_notify_id;
 
195
        guint browser_view_notify_id;
193
196
};
194
197
 
195
 
static BonoboUIVerb rb_library_source_verbs[] =
 
198
static GtkActionEntry rb_library_source_actions [] =
196
199
{
197
 
        BONOBO_UI_VERB ("SLChooseGenre",(BonoboUIVerbFn) rb_library_source_cmd_choose_genre),
198
 
        BONOBO_UI_VERB ("SLChooseArtist",(BonoboUIVerbFn) rb_library_source_cmd_choose_artist),
199
 
        BONOBO_UI_VERB ("SLChooseAlbum", (BonoboUIVerbFn) rb_library_source_cmd_choose_album),
200
 
        BONOBO_UI_VERB_END
 
200
        { "LibrarySrcChooseGenre", NULL, N_("Browse This _Genre"), NULL,
 
201
          N_("Set the browser to view only this genre"),
 
202
          G_CALLBACK (rb_library_source_cmd_choose_genre) },
 
203
        { "LibrarySrcChooseArtist", NULL , N_("Browse This _Artist"), NULL,
 
204
          N_("Set the browser to view only this artist"),
 
205
          G_CALLBACK (rb_library_source_cmd_choose_artist) },
 
206
        { "LibrarySrcChooseAlbum", NULL, N_("Browse This A_lbum"), NULL,
 
207
          N_("Set the browser to view only this album"),
 
208
          G_CALLBACK (rb_library_source_cmd_choose_album) }
201
209
};
202
210
 
 
211
static const GtkTargetEntry songs_view_drag_types[] = {{  "text/uri-list", 0, 0 }};
 
212
 
203
213
enum
204
214
{
205
215
        PROP_0,
206
 
        PROP_DB,        
207
216
        PROP_ICON,
208
 
        PROP_ENTRY_TYPE
 
217
        PROP_ENTRY_TYPE,
 
218
        PROP_SORTING_KEY
209
219
};
210
220
 
211
221
static GObjectClass *parent_class = NULL;
247
257
 
248
258
        parent_class = g_type_class_peek_parent (klass);
249
259
 
 
260
        object_class->dispose = rb_library_source_dispose;
250
261
        object_class->finalize = rb_library_source_finalize;
251
262
        object_class->constructor = rb_library_source_constructor;
252
263
 
255
266
 
256
267
        source_class->impl_get_status = impl_get_status;
257
268
        source_class->impl_get_browser_key = impl_get_browser_key;
258
 
        source_class->impl_get_search_key = impl_get_search_key;
259
269
        source_class->impl_get_pixbuf  = impl_get_pixbuf;
260
270
        source_class->impl_can_search = (RBSourceFeatureFunc) rb_true_function;
261
271
        source_class->impl_search = impl_search;
269
279
        source_class->impl_can_copy = (RBSourceFeatureFunc) rb_true_function;
270
280
        source_class->impl_can_delete = (RBSourceFeatureFunc) rb_true_function;
271
281
        source_class->impl_delete = impl_delete;
272
 
        source_class->impl_have_artist_album = (RBSourceFeatureFunc) rb_true_function;
273
 
        source_class->impl_get_artist = impl_get_artist;
274
 
        source_class->impl_get_album = impl_get_album;
275
282
        source_class->impl_have_url = (RBSourceFeatureFunc) rb_false_function;
276
283
        source_class->impl_receive_drag = impl_receive_drag;
277
284
        source_class->impl_show_popup = impl_show_popup;
278
285
 
279
 
        g_object_class_install_property (object_class,
280
 
                                         PROP_DB,
281
 
                                         g_param_spec_object ("db",
282
 
                                                              "RhythmDB",
283
 
                                                              "RhythmDB database",
284
 
                                                              RHYTHMDB_TYPE,
285
 
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
286
        klass->impl_get_paned_key = impl_get_paned_key;
 
287
        klass->impl_has_first_added_column = (RBLibrarySourceFeatureFunc) rb_true_function;
 
288
        klass->impl_has_drop_support = (RBLibrarySourceFeatureFunc) rb_true_function;
 
289
 
286
290
        g_object_class_install_property (object_class,
287
291
                                         PROP_ICON,
288
292
                                         g_param_spec_object ("icon",
300
304
                                                            RHYTHMDB_ENTRY_TYPE_SONG,
301
305
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
302
306
 
 
307
        g_object_class_install_property (object_class,
 
308
                                         PROP_SORTING_KEY,
 
309
                                         g_param_spec_string ("sorting-key",
 
310
                                                              "Sorting key",
 
311
                                                              "GConf key for storing sort-order",
 
312
                                                              CONF_STATE_LIBRARY_SORTING,
 
313
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
314
 
303
315
}
304
316
 
305
317
static void
309
321
        GtkWidget *genres = GTK_WIDGET (source->priv->genres);
310
322
        GtkWidget *artists = GTK_WIDGET (source->priv->artists);
311
323
        GtkWidget *albums = GTK_WIDGET (source->priv->albums);
312
 
        BonoboUIComponent *component;
 
324
        GtkAction *action;
313
325
 
314
326
        views = eel_gconf_get_integer (CONF_UI_LIBRARY_BROWSER_VIEWS);
315
327
 
316
 
        g_object_get (G_OBJECT (source), "component", &component, NULL);
 
328
        gtk_widget_show (genres);
 
329
        action = gtk_action_group_get_action (source->priv->action_group,
 
330
                                              "LibrarySrcChooseGenre");
 
331
        if (action) {
 
332
                g_object_set (G_OBJECT (action), "sensitive", TRUE, NULL);
 
333
        }
 
334
 
 
335
 
 
336
        gtk_widget_show (artists);      
 
337
        action = gtk_action_group_get_action (source->priv->action_group,
 
338
                                              "LibrarySrcChooseArtist"); 
 
339
        if (action) {
 
340
                g_object_set (G_OBJECT (action), "sensitive", TRUE, NULL);
 
341
        }
 
342
 
 
343
        gtk_widget_show (albums);
 
344
        action = gtk_action_group_get_action (source->priv->action_group,
 
345
                                              "LibrarySrcChooseAlbum"); 
 
346
        if (action) {
 
347
                g_object_set (G_OBJECT (action), "sensitive", TRUE, NULL);
 
348
        }
317
349
        
318
350
        switch (views)
319
351
        {
320
 
                case 0:
321
 
                        gtk_widget_hide (genres);
322
 
                        rb_library_source_handle_genre_selection (source, NULL);
323
 
                        rb_bonobo_set_sensitive (component,
324
 
                                                 "/commands" "/SLChooseGenre",
325
 
                                                 FALSE);
326
 
                        gtk_widget_show (artists);
327
 
                        rb_bonobo_set_sensitive (component,
328
 
                                                 "/commands" "/SLChooseArtist",
329
 
                                                 TRUE);
330
 
                        gtk_widget_show (albums);
331
 
                        rb_bonobo_set_sensitive (component,
332
 
                                                 "/commands" "/SLChooseAlbum",
333
 
                                                 TRUE);
334
 
                        /* Since this is hidden now, reset the query */
335
 
                break;
336
 
                case 1:
337
 
                        gtk_widget_show (genres);
338
 
                        rb_bonobo_set_sensitive (component,
339
 
                                                 "/commands" "/SLChooseGenre",
340
 
                                                 TRUE);
341
 
                        gtk_widget_show (artists);
342
 
                        rb_bonobo_set_sensitive (component,
343
 
                                                 "/commands" "/SLChooseArtist",
344
 
                                                 TRUE);
345
 
                        gtk_widget_hide (albums);
346
 
                        rb_library_source_handle_artist_selection (source, NULL);
347
 
                        rb_bonobo_set_sensitive (component,
348
 
                                                 "/commands" "/SLChooseAlbum",
349
 
                                                 FALSE);
350
 
                break;
351
 
                case 2:
352
 
                        gtk_widget_show (genres);
353
 
                        rb_bonobo_set_sensitive (component,
354
 
                                                 "/commands" "/SLChooseGenre",
355
 
                                                 TRUE);
356
 
                        gtk_widget_show (artists);
357
 
                        rb_bonobo_set_sensitive (component,
358
 
                                                 "/commands" "/SLChooseArtist",
359
 
                                                 TRUE);
360
 
                        gtk_widget_show (albums);
361
 
                        rb_bonobo_set_sensitive (component,
362
 
                                                 "/commands" "/SLChooseAlbum",
363
 
                                                 TRUE);
 
352
        case 0:
 
353
                action = gtk_action_group_get_action (source->priv->action_group,
 
354
                                                      "LibrarySrcChooseGenre");
 
355
                if (action) {
 
356
                        g_object_set (G_OBJECT (action), 
 
357
                                      "sensitive", FALSE, 
 
358
                                      NULL);
 
359
                }
 
360
                gtk_widget_hide (genres);
 
361
                rb_library_source_handle_genre_selection (source, NULL);
 
362
                /* Since this is hidden now, reset the query */
 
363
                break;
 
364
        case 1:
 
365
                action = gtk_action_group_get_action (source->priv->action_group,
 
366
                                                      "LibrarySrcChooseAlbum");
 
367
                if (action) {
 
368
                        g_object_set (G_OBJECT (action), 
 
369
                                      "sensitive", FALSE, 
 
370
                                      NULL);
 
371
                }
 
372
                gtk_widget_hide (albums);
 
373
                rb_library_source_handle_album_selection (source, NULL);
 
374
                break;
 
375
        case 2:
 
376
                /* All are shown */
 
377
                break;
 
378
        default:
364
379
                break;
365
380
        }
366
381
}
404
419
}
405
420
 
406
421
static void
 
422
rb_library_source_dispose (GObject *object)
 
423
{
 
424
        RBLibrarySource *source;
 
425
        source = RB_LIBRARY_SOURCE (object);
 
426
 
 
427
        if (source->priv->disposed)
 
428
                return;
 
429
        source->priv->disposed = TRUE;
 
430
 
 
431
        g_object_unref (source->priv->db);
 
432
}
 
433
 
 
434
static void
407
435
rb_library_source_finalize (GObject *object)
408
436
{
409
437
        RBLibrarySource *source;
416
444
        g_return_if_fail (source->priv != NULL);
417
445
 
418
446
        rb_debug ("finalizing library source");
 
447
        
 
448
        eel_gconf_notification_remove (source->priv->ui_dir_notify_id);
 
449
        eel_gconf_notification_remove (source->priv->browser_view_notify_id);
 
450
        eel_gconf_notification_remove (source->priv->state_browser_notify_id);
 
451
        eel_gconf_notification_remove (source->priv->state_paned_notify_id);
 
452
        eel_gconf_notification_remove (source->priv->state_sorting_notify_id);
419
453
 
420
 
        g_free (source->priv->status);
 
454
        g_free (source->priv->sorting_key);
421
455
        g_free (source->priv->artist);
422
456
        g_free (source->priv->album);
423
457
 
432
466
 
433
467
static void
434
468
rb_library_source_songs_show_popup_cb (RBEntryView *view,
435
 
                                       RBLibrarySource *library_source)
436
 
{
437
 
        GtkWidget *menu;
438
 
        GtkWidget *window;
439
 
 
440
 
        window = gtk_widget_get_ancestor (GTK_WIDGET (view),
441
 
                                          BONOBO_TYPE_WINDOW);
442
 
 
443
 
        menu = gtk_menu_new ();
444
 
 
445
 
        bonobo_window_add_popup (BONOBO_WINDOW (window), GTK_MENU (menu),
446
 
                                 LIBRARY_SOURCE_SONGS_POPUP_PATH);
447
 
 
448
 
        gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
449
 
                        3, gtk_get_current_event_time ());
450
 
 
451
 
        gtk_object_sink (GTK_OBJECT (menu));
452
 
}
453
 
 
454
 
/* This function may seem a bit weird. Since we have 2 instances of objects 
455
 
 * inheriting from RBLibrarySource, we can't install those ui verbs when
456
 
 * creating a new instance of such an object. Attaching those verbs in the 
457
 
 * shell would also be weird imo since this would add more code 
458
 
 * dependant on the source type to the shell */
459
 
void
460
 
rb_library_source_class_add_verbs (RBShell *shell, 
461
 
                                   BonoboUIComponent *component)
462
 
{
463
 
        bonobo_ui_component_add_verb_list_with_data (component, 
464
 
                                                     rb_library_source_verbs,
465
 
                                                     shell);
466
 
}
467
 
 
 
469
                                       RBLibrarySource *source)
 
470
{
 
471
        _rb_source_show_popup (RB_SOURCE (source), "/LibraryViewPopup");
 
472
}
 
473
 
 
474
static void
 
475
register_action_group (RBLibrarySource *source)
 
476
{
 
477
        GtkUIManager *uimanager;
 
478
        GList *actiongroups;
 
479
        GList *group;
 
480
        RBShell *shell;
 
481
 
 
482
        g_object_get (G_OBJECT (source), "ui-manager", &uimanager, NULL);
 
483
        actiongroups = gtk_ui_manager_get_action_groups (uimanager);
 
484
 
 
485
        /* Don't create the action group if it's already registered */
 
486
        for (group = actiongroups; group != NULL; group = group->next) {
 
487
                const gchar *name;
 
488
 
 
489
                name = gtk_action_group_get_name (GTK_ACTION_GROUP (group->data));
 
490
                if (strcmp (name, "LibraryActions") == 0) {
 
491
                        g_object_unref (G_OBJECT (uimanager));
 
492
                        source->priv->action_group = GTK_ACTION_GROUP (group->data);
 
493
                        return;
 
494
                }
 
495
        }
 
496
 
 
497
        g_object_get (G_OBJECT (source), "shell", &shell, NULL);
 
498
        source->priv->action_group = gtk_action_group_new ("LibraryActions");
 
499
        gtk_action_group_set_translation_domain (source->priv->action_group,
 
500
                                                 GETTEXT_PACKAGE);
 
501
        gtk_action_group_add_actions (source->priv->action_group, 
 
502
                                      rb_library_source_actions,
 
503
                                      G_N_ELEMENTS (rb_library_source_actions),
 
504
                                      shell);
 
505
        gtk_ui_manager_insert_action_group (uimanager, 
 
506
                                            source->priv->action_group, 0);
 
507
        g_object_unref (G_OBJECT (uimanager));
 
508
        g_object_unref (G_OBJECT (shell));
 
509
 
 
510
}
468
511
 
469
512
static GObject *
470
513
rb_library_source_constructor (GType type, guint n_construct_properties,
473
516
        RBLibrarySource *source;
474
517
        RBLibrarySourceClass *klass;
475
518
        GObjectClass *parent_class;  
476
 
        BonoboUIComponent *component;
 
519
        RBShell *shell;
477
520
 
478
521
        klass = RB_LIBRARY_SOURCE_CLASS (g_type_class_peek (RB_TYPE_LIBRARY_SOURCE));
479
 
 
480
522
        parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
 
523
 
481
524
        source = RB_LIBRARY_SOURCE (parent_class->constructor (type, n_construct_properties,
482
525
                                                               construct_properties));
483
526
 
484
 
        g_object_get (G_OBJECT (source), "component", &component, NULL);
 
527
        register_action_group (source);
 
528
 
 
529
        g_object_get (G_OBJECT (source), "shell", &shell, NULL);
 
530
        g_object_get (G_OBJECT (shell), "db", &source->priv->db, NULL);
 
531
        g_object_unref (G_OBJECT (shell));
485
532
 
486
533
        source->priv->paned = gtk_vpaned_new ();
487
534
 
488
535
        source->priv->browser = gtk_hbox_new (TRUE, 5);
489
536
 
490
537
        /* set up songs tree view */
491
 
        source->priv->songs = rb_entry_view_new (source->priv->db, CONF_STATE_LIBRARY_SORTING,
 
538
        source->priv->songs = rb_entry_view_new (source->priv->db, source->priv->sorting_key,
492
539
                                                 TRUE, FALSE);
493
540
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_TRACK_NUMBER);
494
541
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_TITLE);
495
542
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_GENRE);
496
543
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_ARTIST);
497
544
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_ALBUM);
 
545
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_YEAR);
498
546
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_DURATION);
499
547
/*      rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_QUALITY); */
500
548
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_RATING);
501
549
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_PLAY_COUNT);
502
550
        rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_LAST_PLAYED);
 
551
        if (rb_library_source_has_first_added_column (source))
 
552
                rb_entry_view_append_column (source->priv->songs, RB_ENTRY_VIEW_COL_FIRST_SEEN);
503
553
 
504
554
        g_signal_connect_object (G_OBJECT (source->priv->songs), "show_popup",
505
555
                                 G_CALLBACK (rb_library_source_songs_show_popup_cb), source, 0);
508
558
                                 G_CALLBACK (songs_view_sort_order_changed_cb),
509
559
                                 source, 0);
510
560
 
 
561
        /* set up drag and drop for the song tree view.
 
562
         * we don't use RBEntryView's DnD support because it does too much.
 
563
         * we just want to be able to drop songs in to add them to the 
 
564
         * library.
 
565
         */
 
566
        g_signal_connect_object (G_OBJECT (source->priv->songs), 
 
567
                                 "drag_data_received",
 
568
                                 G_CALLBACK (songs_view_drag_data_received_cb),
 
569
                                 source, 0);
 
570
 
 
571
        /* only add drop support for the Library, subclasses can add it themselves */   
 
572
        if (rb_library_source_has_drop_support (source)) {
 
573
                gtk_drag_dest_set (GTK_WIDGET (source->priv->songs),
 
574
                                   GTK_DEST_DEFAULT_ALL,
 
575
                                   songs_view_drag_types, 1,
 
576
                                   GDK_ACTION_COPY | GDK_ACTION_MOVE);  /* really accept move actions? */
 
577
        }
 
578
 
511
579
        /* set up genres treeview */
512
580
        source->priv->genres = rb_property_view_new (source->priv->db, RHYTHMDB_PROP_GENRE,
513
581
                                                     _("Genre"));
566
634
        rb_library_source_state_prefs_sync (source);
567
635
        rb_library_source_ui_prefs_sync (source);
568
636
        update_browser_views_visibility (source);
569
 
        eel_gconf_notification_add (CONF_STATE_LIBRARY_DIR,
570
 
                                    (GConfClientNotifyFunc) rb_library_source_state_pref_changed,
571
 
                                    source);
572
 
        eel_gconf_notification_add (CONF_UI_LIBRARY_DIR,
 
637
 
 
638
        if (source->priv->sorting_key) {
 
639
                source->priv->state_sorting_notify_id =
 
640
                        eel_gconf_notification_add (source->priv->sorting_key,
 
641
                                            (GConfClientNotifyFunc) rb_library_source_state_pref_changed,
 
642
                                            source);
 
643
        }
 
644
        if (rb_library_source_get_paned_key (source)) {
 
645
                source->priv->state_paned_notify_id =
 
646
                        eel_gconf_notification_add (rb_library_source_get_paned_key (source),
 
647
                                            (GConfClientNotifyFunc) rb_library_source_state_pref_changed,
 
648
                                            source);
 
649
        }
 
650
        if (rb_source_get_browser_key (RB_SOURCE (source))) {
 
651
                source->priv->state_browser_notify_id =
 
652
                        eel_gconf_notification_add (rb_source_get_browser_key (RB_SOURCE (source)),
 
653
                                            (GConfClientNotifyFunc) rb_library_source_state_pref_changed,
 
654
                                            source);
 
655
        }
 
656
 
 
657
        source->priv->ui_dir_notify_id =
 
658
                eel_gconf_notification_add (CONF_UI_LIBRARY_DIR,
573
659
                                    (GConfClientNotifyFunc) rb_library_source_ui_pref_changed, source);
574
 
        eel_gconf_notification_add (CONF_UI_LIBRARY_BROWSER_VIEWS,
 
660
        source->priv->browser_view_notify_id =
 
661
                eel_gconf_notification_add (CONF_UI_LIBRARY_BROWSER_VIEWS,
575
662
                                    (GConfClientNotifyFunc) rb_library_source_browser_views_changed, source);
 
663
 
576
664
        rb_library_source_do_query (source, RB_LIBRARY_QUERY_TYPE_ALL);
577
665
        return G_OBJECT (source);
578
666
}
588
676
 
589
677
        switch (prop_id)
590
678
        {
591
 
        case PROP_DB:
592
 
                source->priv->db = g_value_get_object (value);
593
 
                break;
594
679
        case PROP_ICON:
595
680
                if (source->priv->pixbuf) {
596
681
                        g_object_unref (G_OBJECT (source->priv->pixbuf));
597
682
                }
598
683
                source->priv->pixbuf = g_value_get_object (value);
599
 
                g_object_ref (source->priv->pixbuf);
 
684
 
 
685
                if (source->priv->pixbuf)
 
686
                        g_object_ref (source->priv->pixbuf);
600
687
                break;
601
688
        case PROP_ENTRY_TYPE:
602
689
                source->priv->entry_type = g_value_get_uint (value);
603
690
                break;
 
691
        case PROP_SORTING_KEY:
 
692
                g_free (source->priv->sorting_key);
 
693
                source->priv->sorting_key = g_strdup (g_value_get_string (value));
 
694
                break;
604
695
        default:
605
696
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
606
697
                break;
617
708
 
618
709
        switch (prop_id)
619
710
        {
620
 
        case PROP_DB:
621
 
                g_value_set_object (value, source->priv->db);
622
 
                break;
623
711
        case PROP_ICON:
624
712
                g_value_set_object (value, source->priv->pixbuf);
625
713
                break;
626
714
        case PROP_ENTRY_TYPE:
627
715
                g_value_set_uint (value, source->priv->entry_type);
628
716
                break;
 
717
        case PROP_SORTING_KEY:
 
718
                g_value_set_string (value, source->priv->sorting_key);
 
719
                break;
629
720
        default:
630
721
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
631
722
                break;
633
724
}
634
725
 
635
726
RBSource *
636
 
rb_library_source_new (RBShell *shell, RhythmDB *db, 
637
 
                       BonoboUIComponent *component)
 
727
rb_library_source_new (RBShell *shell)
638
728
{
639
729
        RBSource *source;
640
 
        GtkWidget *dummy = gtk_tree_view_new ();
641
730
        GdkPixbuf *icon;
 
731
        gint size;
642
732
 
643
 
        icon = gtk_widget_render_icon (dummy, RB_STOCK_LIBRARY,
644
 
                                       GTK_ICON_SIZE_LARGE_TOOLBAR,
645
 
                                       NULL);
646
 
        gtk_widget_destroy (dummy);
 
733
        gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
 
734
        icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
 
735
                                         "stock_music-library",
 
736
                                         size,
 
737
                                         0, NULL);
647
738
 
648
739
        source = RB_SOURCE (g_object_new (RB_TYPE_LIBRARY_SOURCE,
649
740
                                          "name", _("Library"),
650
 
                                          "internal-name", "<library>",
651
741
                                          "entry-type", RHYTHMDB_ENTRY_TYPE_SONG,
652
 
                                          "db", db,
653
 
                                          "component", component,
 
742
                                          "shell", shell,
654
743
                                          "icon", icon,
655
744
                                          NULL));
656
745
        rb_shell_register_entry_type_for_source (shell, source, 
658
747
        return source;
659
748
}
660
749
 
661
 
 
662
750
static gboolean
663
751
string_list_equal (GList *a, GList *b)
664
752
{
671
759
                return FALSE;
672
760
 
673
761
        for (sorted_a_keys = NULL; a; a = a->next) {
674
 
                sorted_a_keys = g_list_append (sorted_a_keys,
 
762
                sorted_a_keys = g_list_prepend (sorted_a_keys,
675
763
                                               g_utf8_collate_key (a->data, -1));
676
764
        }
677
765
        for (sorted_b_keys = NULL; b; b = b->next) {
678
 
                sorted_b_keys = g_list_append (sorted_b_keys,
 
766
                sorted_b_keys = g_list_prepend (sorted_b_keys,
679
767
                                               g_utf8_collate_key (b->data, -1));
680
768
        }
681
769
        sorted_a_keys = g_list_sort (sorted_a_keys, (GCompareFunc) strcmp);
704
792
        *data = g_list_prepend (*data, key);
705
793
}
706
794
 
 
795
static void
 
796
rb_library_source_free_list_data (gpointer *data, gpointer unused)
 
797
{
 
798
        g_free (data);
 
799
}
 
800
 
707
801
static GList *
708
802
rb_library_source_gather_properties (RBLibrarySource *source,
709
803
                                     RhythmDBPropType prop)
711
805
        GList *selected, *tem;
712
806
        GHashTable *selected_set;
713
807
 
714
 
        rhythmdb_read_lock (source->priv->db);
715
808
        selected_set = g_hash_table_new (g_str_hash, g_str_equal);
716
809
        selected = rb_entry_view_get_selected_entries (source->priv->songs);
717
810
        for (tem = selected; tem; tem = tem->next) {
718
 
                char *val = g_strdup (rhythmdb_entry_get_string (source->priv->db,
719
 
                                                                 tem->data, prop));
 
811
                RhythmDBEntry *entry = tem->data;
 
812
                char *val = g_strdup (rhythmdb_entry_get_string (entry, prop));
720
813
                g_hash_table_insert (selected_set, val, NULL);
721
814
        }
722
815
 
723
 
        rhythmdb_read_unlock (source->priv->db);
724
816
 
725
817
        g_list_free (selected);
726
818
        
732
824
}
733
825
 
734
826
static void
735
 
rb_library_source_cmd_choose_genre (BonoboUIComponent *component,
736
 
                                    RBShell *shell,
737
 
                                    const char *verbname)
 
827
rb_library_source_cmd_choose_genre (GtkAction *action,
 
828
                                    RBShell *shell)
738
829
{
739
 
        GList *props;   
 
830
        GList *props;
740
831
        RBLibrarySource *source;
741
832
 
742
833
        rb_debug ("choosing genre");
744
835
        g_object_get (G_OBJECT (shell), "selected-source", &source, NULL);
745
836
        props = rb_library_source_gather_properties (source, RHYTHMDB_PROP_GENRE);
746
837
        rb_property_view_set_selection (source->priv->genres, props);
 
838
        g_list_foreach (props, (GFunc) rb_library_source_free_list_data, NULL);
747
839
        g_list_free (props);
 
840
        g_object_unref (source);
748
841
}
749
842
 
750
843
static void
751
 
rb_library_source_cmd_choose_artist (BonoboUIComponent *component,
752
 
                                     RBShell *shell,
753
 
                                     const char *verbname)
 
844
rb_library_source_cmd_choose_artist (GtkAction *action,
 
845
                                     RBShell *shell)
754
846
{
755
847
        GList *props;   
756
848
        RBLibrarySource *source;
760
852
        g_object_get (G_OBJECT (shell), "selected-source", &source, NULL);
761
853
        props = rb_library_source_gather_properties (source, RHYTHMDB_PROP_ARTIST);
762
854
        rb_property_view_set_selection (source->priv->artists, props);
 
855
        g_list_foreach (props, (GFunc) rb_library_source_free_list_data, NULL);
763
856
        g_list_free (props);
 
857
        g_object_unref (source);
764
858
}
765
859
 
766
860
static void
767
 
rb_library_source_cmd_choose_album (BonoboUIComponent *component,
768
 
                                    RBShell *shell,
769
 
                                    const char *verbname)
 
861
rb_library_source_cmd_choose_album (GtkAction *action,
 
862
                                    RBShell *shell)
770
863
{
771
864
        GList *props;   
772
865
        RBLibrarySource *source;
776
869
        g_object_get (G_OBJECT (shell), "selected-source", &source, NULL);
777
870
        props = rb_library_source_gather_properties (source, RHYTHMDB_PROP_ALBUM);
778
871
        rb_property_view_set_selection (source->priv->albums, props);
 
872
        g_list_foreach (props, (GFunc) rb_library_source_free_list_data, NULL);
779
873
        g_list_free (props);
780
 
}
781
 
 
782
 
static void
783
 
rb_library_source_sync_query (RBLibrarySource *source)
784
 
{
785
 
        GPtrArray *query = construct_query_from_selection (source);
786
 
        g_object_set (G_OBJECT (source->priv->model), "query", query, NULL);
787
 
        rhythmdb_query_free (query);
 
874
        g_object_unref (source);
788
875
}
789
876
 
790
877
static void
815
902
        g_list_foreach (libsource->priv->selected_genres, (GFunc) g_free, NULL);
816
903
        g_list_free (libsource->priv->selected_genres);
817
904
        libsource->priv->selected_genres = NULL;
818
 
        rb_library_source_sync_query (libsource);
 
905
        rb_library_source_do_query (libsource, RB_LIBRARY_QUERY_TYPE_GENRE);
819
906
}
820
907
 
821
908
static void
847
934
        g_list_foreach (libsource->priv->selected_artists, (GFunc) g_free, NULL);
848
935
        g_list_free (libsource->priv->selected_artists);
849
936
        libsource->priv->selected_artists = NULL;
850
 
        rb_library_source_sync_query (libsource);
 
937
        rb_library_source_do_query (libsource, RB_LIBRARY_QUERY_TYPE_ALBUM);
851
938
}
852
939
 
853
940
static void
878
965
        g_list_foreach (libsource->priv->selected_albums, (GFunc) g_free, NULL);
879
966
        g_list_free (libsource->priv->selected_albums);
880
967
        libsource->priv->selected_albums = NULL;
881
 
        rb_library_source_sync_query (libsource);
 
968
        rb_library_source_do_query (libsource, RB_LIBRARY_QUERY_TYPE_ALBUM);
882
969
}
883
970
 
884
971
static void
889
976
        rb_library_source_do_query (source, RB_LIBRARY_QUERY_TYPE_SEARCH);
890
977
}
891
978
 
892
 
static const char *
 
979
static char *
893
980
impl_get_status (RBSource *asource)
894
981
{
895
982
        RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
896
 
        g_free (source->priv->status);
897
 
        source->priv->status = rhythmdb_compute_status_normal (rb_entry_view_get_num_entries (source->priv->songs),
898
 
                                                               rb_entry_view_get_duration (source->priv->songs),
899
 
                                                               rb_entry_view_get_total_size (source->priv->songs));
900
 
        return source->priv->status;
 
983
        gchar *status;
 
984
 
 
985
        status = rhythmdb_compute_status_normal (rb_entry_view_get_num_entries (source->priv->songs),
 
986
                                                 rb_entry_view_get_duration (source->priv->songs),
 
987
                                                 rb_entry_view_get_total_size (source->priv->songs));
 
988
        return status;
901
989
}
902
990
 
903
991
static const char *
907
995
}
908
996
 
909
997
static const char *
910
 
impl_get_search_key (RBSource *source)
 
998
impl_get_paned_key (RBLibrarySource *status)
911
999
{
912
 
        return CONF_STATE_SEARCH_TEXT;
 
1000
        return CONF_STATE_PANED_POSITION;
913
1001
}
914
1002
 
915
1003
static GdkPixbuf *
938
1026
        rb_debug ("doing search for \"%s\"", search_text ? search_text : "(NULL)");
939
1027
 
940
1028
        g_free (source->priv->search_text);
941
 
        source->priv->search_text = search_text != NULL ? g_utf8_casefold (search_text, -1) : NULL;
 
1029
        source->priv->search_text = g_strdup (search_text);
942
1030
        rb_library_source_do_query (source, RB_LIBRARY_QUERY_TYPE_SEARCH);
943
1031
 
944
1032
        rb_source_notify_filter_changed (RB_SOURCE (source));
959
1047
        GList *ret;
960
1048
        RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
961
1049
 
962
 
        ret = g_list_append (NULL, source->priv->genres);
963
 
        ret = g_list_append (ret, source->priv->artists);
964
 
        ret = g_list_append (ret, source->priv->albums);
 
1050
        ret = g_list_prepend (NULL, source->priv->albums);
 
1051
        ret = g_list_prepend (ret, source->priv->artists);
 
1052
        ret = g_list_prepend (ret, source->priv->genres);
965
1053
        return ret;
966
1054
}
967
1055
 
1036
1124
        return source->priv->config_widget;
1037
1125
}
1038
1126
 
1039
 
static const char *
1040
 
impl_get_artist (RBSource *asource)
1041
 
{
1042
 
        RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
1043
 
        RhythmDBEntry *entry;
1044
 
 
1045
 
        g_free (source->priv->artist);
1046
 
 
1047
 
        entry = rb_entry_view_get_playing_entry (source->priv->songs);
1048
 
 
1049
 
        if (entry != NULL) {
1050
 
                rhythmdb_read_lock (source->priv->db);
1051
 
                
1052
 
                source->priv->artist =
1053
 
                        g_strdup (rhythmdb_entry_get_string (source->priv->db, entry, RHYTHMDB_PROP_ARTIST));
1054
 
 
1055
 
                rhythmdb_read_unlock (source->priv->db);
1056
 
        } else {
1057
 
                source->priv->artist = NULL;
1058
 
        }
1059
 
 
1060
 
        return source->priv->artist;
1061
 
}
1062
 
 
1063
 
static const char *
1064
 
impl_get_album (RBSource *asource)
1065
 
{
1066
 
        RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
1067
 
        RhythmDBEntry *entry;
1068
 
 
1069
 
        g_free (source->priv->artist);
1070
 
 
1071
 
        entry = rb_entry_view_get_playing_entry (source->priv->songs);
1072
 
 
1073
 
        if (entry != NULL) {
1074
 
                rhythmdb_read_lock (source->priv->db);
1075
 
 
1076
 
                source->priv->album =
1077
 
                        g_strdup (rhythmdb_entry_get_string (source->priv->db, entry, RHYTHMDB_PROP_ALBUM));
1078
 
                
1079
 
                rhythmdb_read_unlock (source->priv->db);
1080
 
        } else {
1081
 
                source->priv->album = NULL;
1082
 
        }
1083
 
        return source->priv->album;
1084
 
}
1085
 
 
1086
 
 
1087
1127
static void
1088
1128
rb_library_source_preferences_sync (RBLibrarySource *source)
1089
1129
{
1117
1157
        GList *l;
1118
1158
 
1119
1159
        for (l = rb_entry_view_get_selected_entries (source->priv->songs); l != NULL; l = g_list_next (l)) {
1120
 
                rhythmdb_write_lock (source->priv->db);
1121
1160
                rhythmdb_entry_delete (source->priv->db, l->data);
1122
 
                rhythmdb_write_unlock (source->priv->db);
 
1161
                rhythmdb_commit (source->priv->db);
1123
1162
        }
1124
1163
}
1125
1164
 
1146
1185
                        GtkAllocation *allocation,
1147
1186
                        RBLibrarySource *source)
1148
1187
{
 
1188
        const char *key = rb_library_source_get_paned_key (source);;
 
1189
 
1149
1190
        /* save state */
1150
1191
        rb_debug ("paned size allocate");
1151
 
        eel_gconf_set_integer (CONF_STATE_PANED_POSITION,
1152
 
                               gtk_paned_get_position (GTK_PANED (source->priv->paned)));
 
1192
        if (key)
 
1193
                eel_gconf_set_integer (key, gtk_paned_get_position (GTK_PANED (source->priv->paned)));
1153
1194
}
1154
1195
 
1155
1196
static void
1156
1197
rb_library_source_state_prefs_sync (RBLibrarySource *source)
1157
1198
{
 
1199
        const char *key;
 
1200
 
1158
1201
        rb_debug ("syncing state");
1159
 
        gtk_paned_set_position (GTK_PANED (source->priv->paned),
1160
 
                                eel_gconf_get_integer (CONF_STATE_PANED_POSITION));
1161
 
        
1162
 
        if (eel_gconf_get_boolean (CONF_STATE_SHOW_BROWSER))
1163
 
                gtk_widget_show (source->priv->browser);
1164
 
        else
1165
 
                gtk_widget_hide (source->priv->browser);
 
1202
        key = rb_library_source_get_paned_key (source);
 
1203
        if (key)
 
1204
                gtk_paned_set_position (GTK_PANED (source->priv->paned),
 
1205
                                        eel_gconf_get_integer (key));
 
1206
 
 
1207
        key = rb_source_get_browser_key (RB_SOURCE (source));
 
1208
        if (key && eel_gconf_get_boolean (key))
 
1209
                        gtk_widget_show (source->priv->browser);
 
1210
                else
 
1211
                        gtk_widget_hide (source->priv->browser);
1166
1212
}
1167
1213
 
1168
1214
static void
1234
1280
                if (uri != NULL) {
1235
1281
                        GnomeVFSURI *vfsuri = gnome_vfs_uri_new (uri);
1236
1282
                        if (vfsuri != NULL) {
1237
 
                                rhythmdb_add_uri_async (source->priv->db, uri);
 
1283
                                rhythmdb_add_uri (source->priv->db, uri);
1238
1284
                                gnome_vfs_uri_unref (vfsuri);
1239
1285
                        } else
1240
1286
                                rb_debug ("invalid uri: \"%s\"", uri);
1256
1302
        GList *list, *uri_list, *i;
1257
1303
 
1258
1304
        rb_debug ("parsing uri list");
1259
 
        list = gnome_vfs_uri_list_parse (data->data);
 
1305
        list = gnome_vfs_uri_list_parse ((char *) data->data);
1260
1306
 
1261
1307
        if (list == NULL)
1262
1308
                return FALSE;
1264
1310
        uri_list = NULL;
1265
1311
 
1266
1312
        for (i = list; i != NULL; i = g_list_next (i))
1267
 
                uri_list = g_list_append (uri_list, gnome_vfs_uri_to_string ((const GnomeVFSURI *) i->data, 0));
 
1313
                uri_list = g_list_prepend (uri_list, gnome_vfs_uri_to_string ((const GnomeVFSURI *) i->data, 0));
1268
1314
 
1269
1315
        gnome_vfs_uri_list_free (list);
1270
1316
 
1277
1323
                char *uri = i->data;
1278
1324
 
1279
1325
                if (uri != NULL)
1280
 
                        rhythmdb_add_uri_async (source->priv->db, uri);
 
1326
                        rhythmdb_add_uri (source->priv->db, uri);
1281
1327
 
1282
1328
                g_free (uri);
1283
1329
        }
1289
1335
static gboolean
1290
1336
impl_show_popup (RBSource *source)
1291
1337
{
1292
 
        rb_bonobo_show_popup (GTK_WIDGET (source), LIBRARY_SOURCE_POPUP_PATH);
 
1338
        _rb_source_show_popup (RB_SOURCE (source), "/LibrarySourcePopup");
1293
1339
        return TRUE;
1294
1340
}
1295
1341
 
 
1342
const char *
 
1343
rb_library_source_get_paned_key (RBLibrarySource *source)
 
1344
{
 
1345
        RBLibrarySourceClass *klass = RB_LIBRARY_SOURCE_GET_CLASS (source);
 
1346
 
 
1347
        if (klass->impl_get_paned_key)
 
1348
                return klass->impl_get_paned_key (source);
 
1349
        else
 
1350
                return NULL;
 
1351
}
 
1352
 
 
1353
gboolean
 
1354
rb_library_source_has_first_added_column (RBLibrarySource *source)
 
1355
{
 
1356
        RBLibrarySourceClass *klass = RB_LIBRARY_SOURCE_GET_CLASS (source);
 
1357
 
 
1358
        return klass->impl_has_first_added_column (source);
 
1359
}
 
1360
 
 
1361
gboolean
 
1362
rb_library_source_has_drop_support (RBLibrarySource *source)
 
1363
{
 
1364
        RBLibrarySourceClass *klass = RB_LIBRARY_SOURCE_GET_CLASS (source);
 
1365
 
 
1366
        return klass->impl_has_drop_support (source);
 
1367
}
 
1368
 
 
1369
 
1296
1370
static void
1297
1371
push_multi_equals_query (RhythmDB *db, GPtrArray *query, guint propid, GList *items)
1298
1372
{
1343
1417
        if (source->priv->search_text) {
1344
1418
                GPtrArray *subquery = rhythmdb_query_parse (source->priv->db,
1345
1419
                                                            RHYTHMDB_QUERY_PROP_LIKE,
1346
 
                                                            RHYTHMDB_PROP_GENRE_FOLDED,
1347
 
                                                            source->priv->search_text,
1348
 
                                                            RHYTHMDB_QUERY_DISJUNCTION,
1349
 
                                                            RHYTHMDB_QUERY_PROP_LIKE,
1350
 
                                                            RHYTHMDB_PROP_ARTIST_FOLDED,
1351
 
                                                            source->priv->search_text,
1352
 
                                                            RHYTHMDB_QUERY_DISJUNCTION,
1353
 
                                                            RHYTHMDB_QUERY_PROP_LIKE,
1354
 
                                                            RHYTHMDB_PROP_ALBUM_FOLDED,
1355
 
                                                            source->priv->search_text,
1356
 
                                                            RHYTHMDB_QUERY_DISJUNCTION,
1357
 
                                                            RHYTHMDB_QUERY_PROP_LIKE,
1358
 
                                                            RHYTHMDB_PROP_TITLE_FOLDED,
 
1420
                                                            RHYTHMDB_PROP_SEARCH_MATCH,
1359
1421
                                                            source->priv->search_text,
1360
1422
                                                            RHYTHMDB_QUERY_END);
1361
1423
                rhythmdb_query_append (source->priv->db,
1429
1491
 
1430
1492
        /* Unlocked */
1431
1493
        rb_debug ("preparing to read lock for query");
1432
 
        rhythmdb_read_lock (source->priv->db);
1433
 
 
1434
 
        if (source->priv->active_query) {
1435
 
                rb_debug ("killing active query");
1436
 
                rhythmdb_query_model_cancel (RHYTHMDB_QUERY_MODEL (source->priv->active_query));
1437
 
        }
1438
1494
 
1439
1495
        is_all_query = (source->priv->selected_genres == NULL &&
1440
1496
                        source->priv->selected_artists == NULL &&           
1464
1520
                                                    source->priv->cached_artists_model);
1465
1521
                        rb_property_view_set_model (source->priv->albums,
1466
1522
                                                    source->priv->cached_albums_model);
1467
 
                        rb_entry_view_poll_model (source->priv->songs);
1468
 
                        rhythmdb_read_unlock (source->priv->db);
1469
1523
                        return;
1470
1524
                } else if (source->priv->cached_all_query) {
1471
1525
                        rb_debug ("sorting mismatch, freeing cached query");
1501
1555
                                            source->priv->cached_artists_model);
1502
1556
                rb_property_view_set_model (source->priv->albums,
1503
1557
                                            source->priv->cached_albums_model);
1504
 
                g_object_ref (G_OBJECT (source->priv->cached_all_query));
1505
 
                g_object_ref (G_OBJECT (source->priv->cached_genres_model));
1506
 
                g_object_ref (G_OBJECT (source->priv->cached_artists_model));
1507
 
                g_object_ref (G_OBJECT (source->priv->cached_albums_model));
1508
1558
        } else {
1509
1559
                rb_debug ("query is not special");
1510
1560
                source->priv->active_query = source->priv->model = 
1533
1583
                        genre_model = rb_property_view_get_model (source->priv->genres);
1534
1584
                        g_object_set (G_OBJECT (genre_model), "query-model",
1535
1585
                                      query_model, NULL);
 
1586
                        g_object_unref (G_OBJECT (genre_model));
1536
1587
                case RB_LIBRARY_QUERY_TYPE_GENRE:
1537
1588
                        rb_debug ("resetting artist view");
1538
1589
                        g_list_foreach (source->priv->selected_artists,
1544
1595
                        artist_model = rb_property_view_get_model (source->priv->artists);
1545
1596
                        g_object_set (G_OBJECT (artist_model), "query-model",
1546
1597
                                      query_model, NULL);
 
1598
                        g_object_unref (G_OBJECT (artist_model));
1547
1599
                case RB_LIBRARY_QUERY_TYPE_ARTIST:
1548
1600
                        rb_debug ("resetting album view");
1549
1601
                        g_list_foreach (source->priv->selected_albums,
1555
1607
                        album_model = rb_property_view_get_model (source->priv->albums);
1556
1608
                        g_object_set (G_OBJECT (album_model), "query-model",
1557
1609
                                      query_model, NULL);
 
1610
                        g_object_unref (G_OBJECT (album_model));
1558
1611
                case RB_LIBRARY_QUERY_TYPE_ALBUM:
1559
1612
                case RB_LIBRARY_QUERY_TYPE_SEARCH:
1560
1613
                        break;
1564
1617
        model = GTK_TREE_MODEL (query_model);
1565
1618
 
1566
1619
        rb_debug ("setting empty model");
1567
 
        rb_entry_view_set_model (source->priv->songs, RHYTHMDB_QUERY_MODEL (query_model));
 
1620
        rb_entry_view_set_model (source->priv->songs, query_model);
1568
1621
 
1569
1622
        query = construct_query_from_selection (source);
1570
1623
        
1572
1625
        rhythmdb_do_full_query_async_parsed (source->priv->db, model, query);
1573
1626
                
1574
1627
        rhythmdb_query_free (query);
1575
 
        g_object_unref (G_OBJECT (query_model));
1576
 
}
 
1628
        
 
1629
        if (!is_all_query)
 
1630
                g_object_unref (G_OBJECT (query_model));
 
1631
}
 
1632
 
 
1633
static void
 
1634
songs_view_drag_data_received_cb (GtkWidget *widget,
 
1635
                                  GdkDragContext *dc,
 
1636
                                  gint x, gint y,
 
1637
                                  GtkSelectionData *selection_data,
 
1638
                                  guint info, guint time,
 
1639
                                  RBLibrarySource *source)
 
1640
{
 
1641
        rb_debug ("data dropped on the library source song view");
 
1642
        rb_source_receive_drag (RB_SOURCE (source), selection_data);
 
1643
}
 
1644