267
269
iface->drag_data_get = rhythmdb_property_model_drag_data_get;
273
_remove_entry_cb (RhythmDBEntry *entry,
275
RhythmDBPropertyModel *model)
277
rhythmdb_property_model_delete (model, entry);
282
_add_entry_cb (GtkTreeModel *model,
285
RhythmDBPropertyModel *propmodel)
287
rhythmdb_property_model_row_inserted_cb (model, path, iter, propmodel);
271
292
rhythmdb_property_model_set_property (GObject *object,
276
297
RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (object);
322
338
g_signal_handlers_disconnect_by_func (G_OBJECT (model->priv->query_model),
323
339
G_CALLBACK (rhythmdb_property_model_prop_changed_cb),
341
g_hash_table_foreach_remove (model->priv->entries, (GHRFunc)_remove_entry_cb, model);
325
342
g_object_unref (G_OBJECT (model->priv->query_model));
328
345
model->priv->query_model = g_value_get_object (value);
346
g_assert (rhythmdb_property_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 1);
330
348
if (model->priv->query_model) {
349
g_object_ref (G_OBJECT (model->priv->query_model));
331
350
g_signal_connect_object (G_OBJECT (model->priv->query_model),
333
352
G_CALLBACK (rhythmdb_property_model_row_inserted_cb),
436
456
return g_object_new (RHYTHMDB_TYPE_PROPERTY_MODEL, "db", db, "prop", propid, NULL);
439
static inline RhythmDBEntry *
440
entry_from_tree_iter (GtkTreeModel *model, GtkTreeIter *iter)
442
RhythmDBEntry *entry;
443
gtk_tree_model_get (model, iter, 0, &entry, -1);
448
460
rhythmdb_property_model_row_inserted_cb (GtkTreeModel *model,
449
461
GtkTreePath *path,
450
462
GtkTreeIter *iter,
451
463
RhythmDBPropertyModel *propmodel)
453
RhythmDBEntry *entry = entry_from_tree_iter (model, iter);
455
if (rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN) == FALSE) {
456
rhythmdb_property_model_insert (propmodel, entry);
457
rhythmdb_property_model_sync (propmodel);
465
RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter);
466
RhythmDBPropertyModelEntry *prop;
468
if (g_hash_table_lookup (propmodel->priv->entries, entry))
472
prop = rhythmdb_property_model_insert (propmodel, entry);
473
g_hash_table_insert (propmodel->priv->entries, entry, prop);
475
rhythmdb_property_model_sync (propmodel);
462
479
rhythmdb_property_model_prop_changed_cb (RhythmDB *db, RhythmDBEntry *entry,
463
RhythmDBPropType prop, const GValue *old,
480
RhythmDBPropType propid, const GValue *old,
464
481
const GValue *new,
465
482
RhythmDBPropertyModel *propmodel)
467
if (prop == RHYTHMDB_PROP_HIDDEN) {
468
gboolean old_hidden = g_value_get_boolean (old);
469
gboolean new_hidden = g_value_get_boolean (new);
471
if (new_hidden == old_hidden)
474
rb_debug ("recieving hidden-change notification for %s", entry->location);
477
rhythmdb_property_model_delete (propmodel, entry);
479
rhythmdb_property_model_insert (propmodel, entry);
481
rhythmdb_property_model_sync (propmodel);
483
if (prop != propmodel->priv->propid)
485
if (rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN))
488
rhythmdb_property_model_delete_prop (propmodel, g_value_get_string (old));
489
rhythmdb_property_model_insert (propmodel, entry);
490
rhythmdb_property_model_sync (propmodel);
484
if (propid == RHYTHMDB_PROP_HIDDEN) {
485
gboolean old_val = g_value_get_boolean (old);
486
gboolean new_val = g_value_get_boolean (new);
488
if (old_val != new_val) {
489
if (new_val == FALSE) {
490
RhythmDBPropertyModelEntry *prop;
492
if (g_hash_table_lookup (propmodel->priv->entries, entry) != NULL)
495
prop = rhythmdb_property_model_insert (propmodel, entry);
496
g_hash_table_insert (propmodel->priv->entries, entry, prop);
498
if (g_hash_table_lookup (propmodel->priv->entries, entry) == NULL)
501
rhythmdb_property_model_delete (propmodel, entry);
502
g_hash_table_remove (propmodel->priv->entries, entry);
506
RhythmDBPropertyModelEntry *prop;
508
if (propid != propmodel->priv->propid)
511
if (g_hash_table_lookup (propmodel->priv->entries, entry) == NULL)
514
rhythmdb_property_model_delete (propmodel, entry);
515
prop = rhythmdb_property_model_insert (propmodel, entry);
516
g_hash_table_insert (propmodel->priv->entries, entry, prop);
519
rhythmdb_property_model_sync (propmodel);
550
581
path = rhythmdb_property_model_get_path (GTK_TREE_MODEL (model), &iter);
551
582
gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
552
583
gtk_tree_path_free (path);
556
589
rhythmdb_property_model_delete (RhythmDBPropertyModel *model,
557
590
RhythmDBEntry *entry)
592
RhythmDBPropertyModelEntry *prop;
559
593
const char *propstr;
561
propstr = rhythmdb_entry_get_string (entry, model->priv->propid);
595
prop = g_hash_table_lookup (model->priv->entries, entry);
596
propstr = rb_refstring_get (prop->string);
562
597
rhythmdb_property_model_delete_prop (model, propstr);
871
915
RhythmDBPropertyModel *model = RHYTHMDB_PROPERTY_MODEL (dragsource);
873
917
GtkTargetList *drag_target_list;
874
GCompareDataFunc sort_func = NULL;
876
919
switch (model->priv->propid) {
877
920
case RHYTHMDB_PROP_GENRE:
878
921
drag_target_list = rhythmdb_property_model_genre_drag_target_list;
879
sort_func = (GCompareDataFunc) rhythmdb_query_model_genre_sort_func;
881
923
case RHYTHMDB_PROP_ALBUM:
882
924
drag_target_list = rhythmdb_property_model_album_drag_target_list;
883
sort_func = (GCompareDataFunc) rhythmdb_query_model_album_sort_func;
885
926
case RHYTHMDB_PROP_ARTIST:
886
927
drag_target_list = rhythmdb_property_model_artist_drag_target_list;
887
sort_func = (GCompareDataFunc) rhythmdb_query_model_artist_sort_func;
929
case RHYTHMDB_PROP_LOCATION:
930
drag_target_list = rhythmdb_property_model_location_drag_target_list;
890
933
g_assert_not_reached ();
899
942
if (target == TARGET_URIS) {
900
943
RhythmDB *db = model->priv->db;
901
GtkTreeModel* query_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db));
944
RhythmDBQueryModel *query_model;
902
945
GString* reply = g_string_new ("");
903
946
GtkTreeIter iter;
905
948
struct QueryModelCbStruct tmp;
906
949
GtkTreePath *path;
950
GCompareDataFunc sort_func = NULL;
952
gboolean sort_reverse;
954
query_model = rhythmdb_query_model_new_empty (db);
955
/* FIXME the sort order on the query model at this point is usually
956
* not the user's selected sort order.
958
g_object_get (G_OBJECT (model->priv->query_model),
959
"sort-func", &sort_func,
960
"sort-data", &sort_data,
961
"sort-reverse", &sort_reverse,
908
963
rhythmdb_query_model_set_sort_order (RHYTHMDB_QUERY_MODEL (query_model),
909
sort_func, 0, FALSE);
964
sort_func, GUINT_TO_POINTER (sort_data), NULL, sort_reverse);
911
966
rb_debug ("getting drag data as uri list");
912
967
/* check if first selected row is 'All' */
918
973
gtk_tree_path_free (path);
920
/*filter out radios*/
921
rhythmdb_do_full_query (db, query_model,
922
RHYTHMDB_QUERY_PROP_EQUALS,
924
RHYTHMDB_ENTRY_TYPE_SONG,
975
g_object_set (G_OBJECT (query_model),
976
"base-model", model->priv->query_model,
928
GPtrArray* subquery = g_ptr_array_new();
981
GPtrArray *subquery = g_ptr_array_new ();
930
983
for (row = paths; row; row = row->next) {
934
987
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
935
988
RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE,
938
991
rhythmdb_query_append (db, subquery,
939
992
RHYTHMDB_QUERY_PROP_EQUALS,
940
993
model->priv->propid, name,
996
rhythmdb_query_append (db, subquery,
941
997
RHYTHMDB_QUERY_DISJUNCTION,
998
RHYTHMDB_QUERY_PROP_EQUALS,
999
model->priv->propid, name,
942
1000
RHYTHMDB_QUERY_END);
944
rhythmdb_query_append (db, subquery,
945
RHYTHMDB_QUERY_PROP_EQUALS,
946
model->priv->propid, name,
950
1003
gtk_tree_path_free (path);
953
/*filter out radios*/
954
rhythmdb_do_full_query (db, query_model,
955
RHYTHMDB_QUERY_PROP_EQUALS,
957
RHYTHMDB_ENTRY_TYPE_SONG,
958
RHYTHMDB_QUERY_SUBQUERY,
1006
query = rhythmdb_query_parse (db,
1007
RHYTHMDB_QUERY_SUBQUERY, subquery,
1008
RHYTHMDB_QUERY_END);
1010
g_object_set (G_OBJECT (query_model),
1012
"base-model", model->priv->query_model,
1014
rhythmdb_query_free (query);
968
1022
* and prepare the query using do_full_query_async. The query would be
969
1023
* hooked to the drag context.
971
gtk_tree_model_foreach (query_model,
972
(GtkTreeModelForeachFunc)query_model_cb,
1025
gtk_tree_model_foreach (GTK_TREE_MODEL (query_model),
1026
(GtkTreeModelForeachFunc) query_model_cb,
975
g_object_unref (query_model);
1029
g_object_unref (query_model);
977
1031
gtk_selection_data_set (selection_data,
978
1032
selection_data->target,
1069
1123
model->priv->syncing_id = g_idle_add ((GSourceFunc)rhythmdb_property_model_perform_sync, model);
1126
/* This should really be standard. */
1127
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
1130
rhythmdb_property_model_column_get_type (void)
1132
static GType etype = 0;
1135
static const GEnumValue values[] = {
1136
ENUM_ENTRY (RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, "Property title"),
1137
ENUM_ENTRY (RHYTHMDB_PROPERTY_MODEL_COLUMN_PRIORITY, "Value priority"),
1138
ENUM_ENTRY (RHYTHMDB_PROPERTY_MODEL_COLUMN_NUMBER, "Track count"),
1142
etype = g_enum_register_static ("RhythmDBPropertyModelColumn", values);