~ubuntu-branches/ubuntu/wily/xmms2/wily

« back to all changes in this revision

Viewing changes to src/xmms/playlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2008-07-04 16:23:34 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080704162334-b3esbkcapt8wbrk4
Tags: 0.5DrLecter-2ubuntu1
* Merge from debian unstable (LP: #241098), remaining changes:
  + debian/control:
    + Update Maintainer field
    + add lpia to xmms2-plugin-alsa supported architectures
    + Added liba52-0.7.4-dev to build depends
  + debian/rules: Added patch, patch-stamp and unpatch
  + changed 01_gcc4.3.patch:
    + src/include/xmmsclient/xmmsclient++/helpers.h: Added #include <climits>
* New upstream relase fixes LP: #212566, #222341

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  XMMS2 - X Music Multiplexer System
2
 
 *  Copyright (C) 2003-2007 XMMS2 Team
 
2
 *  Copyright (C) 2003-2008 XMMS2 Team
3
3
 *
4
4
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5
5
 *
68
68
static void xmms_playlist_update_queue (xmms_playlist_t *playlist, const gchar *plname, xmmsc_coll_t *coll);
69
69
static void xmms_playlist_update_partyshuffle (xmms_playlist_t *playlist, const gchar *plname, xmmsc_coll_t *coll);
70
70
 
 
71
static void xmms_playlist_current_pos_msg_send (xmms_playlist_t *playlist, GTree *dict);
 
72
static GTree * xmms_playlist_current_pos_msg_new (xmms_playlist_t *playlist, guint32 pos, const gchar *plname);
71
73
 
72
74
XMMS_CMD_DEFINE  (load, xmms_playlist_load, xmms_playlist_t *, NONE, STRING, NONE);
73
75
XMMS_CMD_DEFINE3 (insert_url, xmms_playlist_insert_url, xmms_playlist_t *, NONE, STRING, UINT32, STRING);
78
80
XMMS_CMD_DEFINE3 (move, xmms_playlist_move, xmms_playlist_t *, NONE, STRING, UINT32, UINT32);
79
81
XMMS_CMD_DEFINE  (add_url, xmms_playlist_add_url, xmms_playlist_t *, NONE, STRING, STRING);
80
82
XMMS_CMD_DEFINE  (add_id, xmms_playlist_add_id, xmms_playlist_t *, NONE, STRING, UINT32);
 
83
XMMS_CMD_DEFINE  (add_idlist, xmms_playlist_add_idlist, xmms_playlist_t *, NONE, STRING, COLL);
81
84
XMMS_CMD_DEFINE3 (add_coll, xmms_playlist_add_collection, xmms_playlist_t *, NONE, STRING, COLL, STRINGLIST);
82
85
XMMS_CMD_DEFINE  (clear, xmms_playlist_clear, xmms_playlist_t *, NONE, STRING, NONE);
83
86
XMMS_CMD_DEFINE  (sort, xmms_playlist_sort, xmms_playlist_t *, NONE, STRING, STRINGLIST);
84
87
XMMS_CMD_DEFINE  (list_entries, xmms_playlist_list_entries, xmms_playlist_t *, LIST, STRING, NONE);
85
 
XMMS_CMD_DEFINE  (current_pos, xmms_playlist_current_pos, xmms_playlist_t *, UINT32, STRING, NONE);
 
88
XMMS_CMD_DEFINE  (current_pos, xmms_playlist_current_pos, xmms_playlist_t *, DICT, STRING, NONE);
86
89
XMMS_CMD_DEFINE  (current_active, xmms_playlist_current_active, xmms_playlist_t *, STRING, NONE, NONE);
87
90
XMMS_CMD_DEFINE  (set_pos, xmms_playlist_set_current_position, xmms_playlist_t *, UINT32, UINT32, NONE);
88
91
XMMS_CMD_DEFINE  (set_pos_rel, xmms_playlist_set_current_position_rel, xmms_playlist_t *, UINT32, INT32, NONE);
89
92
XMMS_CMD_DEFINE  (radd, xmms_playlist_radd, xmms_playlist_t *, NONE, STRING, STRING);
90
93
 
91
94
#define XMMS_PLAYLIST_CHANGED_MSG(type, id, name) xmms_playlist_changed_msg_send (playlist, xmms_playlist_changed_msg_new (playlist, type, id, name))
 
95
#define XMMS_PLAYLIST_CURRPOS_MSG(pos, name) xmms_playlist_current_pos_msg_send (playlist, xmms_playlist_current_pos_msg_new (playlist, pos, name))
92
96
 
93
97
 
94
98
/** @defgroup Playlist Playlist
193
197
 
194
198
        XMMS_DBG ("PLAYLIST: updated chg!");
195
199
 
196
 
        pl_cmd_val = g_hash_table_lookup (val->retval->value.dict, "name");
 
200
        pl_cmd_val = g_tree_lookup (val->retval->value.dict, "name");
197
201
        if (pl_cmd_val != NULL) {
198
202
                plname = pl_cmd_val->value.string;
199
203
        } else {
346
350
                             XMMS_CMD_FUNC (add_id));
347
351
 
348
352
        xmms_object_cmd_add (XMMS_OBJECT (ret),
 
353
                             XMMS_IPC_CMD_ADD_IDLIST,
 
354
                             XMMS_CMD_FUNC (add_idlist));
 
355
 
 
356
        xmms_object_cmd_add (XMMS_OBJECT (ret),
349
357
                             XMMS_IPC_CMD_ADD_COLL,
350
358
                             XMMS_CMD_FUNC (add_coll));
351
359
 
409
417
        char *jumplist;
410
418
        xmms_error_t err;
411
419
        xmms_playlist_t *buffer = playlist;
 
420
        guint newpos;
412
421
 
413
422
        g_return_val_if_fail (playlist, FALSE);
414
423
 
434
443
                    xmmsc_coll_attribute_get (plcoll, "jumplist", &jumplist)) {
435
444
 
436
445
                        xmms_collection_set_int_attr (plcoll, "position", 0);
437
 
                        xmms_object_emit_f (XMMS_OBJECT (playlist),
438
 
                                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
439
 
                                            XMMS_OBJECT_CMD_ARG_UINT32,
440
 
                                            0);
 
446
                        XMMS_PLAYLIST_CURRPOS_MSG (0, XMMS_ACTIVE_PLAYLIST);
441
447
 
442
448
                        xmms_playlist_load (buffer, jumplist, &err);
443
449
                        ret = xmms_error_isok (&err);
444
450
                } else {
445
 
                        xmms_collection_set_int_attr (plcoll, "position", currpos%size);
446
 
                        xmms_object_emit_f (XMMS_OBJECT (playlist),
447
 
                                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
448
 
                                            XMMS_OBJECT_CMD_ARG_UINT32,
449
 
                                            currpos%size);
 
451
                        newpos = currpos%size;
 
452
                        xmms_collection_set_int_attr (plcoll, "position", newpos);
 
453
                        XMMS_PLAYLIST_CURRPOS_MSG (newpos, XMMS_ACTIVE_PLAYLIST);
450
454
                        ret = (currpos != size) || playlist->repeat_all;
451
455
                }
452
456
        }
483
487
        if (currpos == -1 && (size > 0)) {
484
488
                currpos = 0;
485
489
                xmms_collection_set_int_attr (plcoll, "position", currpos);
486
 
                xmms_object_emit_f (XMMS_OBJECT (playlist),
487
 
                                    XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
488
 
                                    XMMS_OBJECT_CMD_ARG_UINT32, 0);
 
490
                XMMS_PLAYLIST_CURRPOS_MSG (0, XMMS_ACTIVE_PLAYLIST);
489
491
        }
490
492
 
491
493
        if (currpos < size) {
506
508
 * Retrieve the position of the currently active xmms_medialib_entry_t
507
509
 *
508
510
 */
509
 
guint32
 
511
GTree *
510
512
xmms_playlist_current_pos (xmms_playlist_t *playlist, gchar *plname,
511
513
                           xmms_error_t *err)
512
514
{
513
515
        guint32 pos;
514
516
        xmmsc_coll_t *plcoll;
 
517
        GTree *dict;
515
518
 
516
519
        g_return_val_if_fail (playlist, 0);
517
520
 
531
534
 
532
535
        g_mutex_unlock (playlist->mutex);
533
536
 
534
 
        return pos;
 
537
        dict = xmms_playlist_current_pos_msg_new (playlist, pos, plname);
 
538
 
 
539
        return dict;
535
540
}
536
541
 
537
542
/**
569
574
static void
570
575
xmms_playlist_load (xmms_playlist_t *playlist, gchar *name, xmms_error_t *err)
571
576
{
572
 
        xmmsc_coll_t *plcoll;
 
577
        xmmsc_coll_t *plcoll, *active_coll;
573
578
 
574
579
        if (strcmp (name, XMMS_ACTIVE_PLAYLIST) == 0) {
575
580
                xmms_error_set (err, XMMS_ERROR_INVAL, "invalid playlist to load");
576
581
                return;
577
582
        }
578
583
 
 
584
        active_coll = xmms_playlist_get_coll (playlist, XMMS_ACTIVE_PLAYLIST, err);
 
585
        if (active_coll == NULL) {
 
586
                xmms_error_set (err, XMMS_ERROR_GENERIC, "no active playlist");
 
587
                return;
 
588
        }
 
589
 
579
590
        plcoll = xmms_playlist_get_coll (playlist, name, err);
580
591
        if (plcoll == NULL) {
581
592
                xmms_error_set (err, XMMS_ERROR_NOENT, "no such playlist");
582
593
                return;
583
594
        }
584
595
 
 
596
        if (active_coll == plcoll) {
 
597
                XMMS_DBG ("Not loading %s playlist, already active!", name);
 
598
                return;
 
599
        }
 
600
 
585
601
        XMMS_DBG ("Loading new playlist! %s", name);
586
602
        xmms_collection_update_pointer (playlist->colldag, XMMS_ACTIVE_PLAYLIST,
587
603
                                        XMMS_COLLECTION_NSID_PLAYLISTS, plcoll);
649
665
        }
650
666
 
651
667
        XMMS_PLAYLIST_CHANGED_MSG (XMMS_PLAYLIST_CHANGED_SHUFFLE, 0, plname);
652
 
        xmms_object_emit_f (XMMS_OBJECT (playlist),
653
 
                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
654
 
                            XMMS_OBJECT_CMD_ARG_UINT32,
655
 
                            currpos);
 
668
        XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
656
669
 
657
670
        g_mutex_unlock (playlist->mutex);
658
671
}
661
674
xmms_playlist_remove_unlocked (xmms_playlist_t *playlist, const gchar *plname,
662
675
                               xmmsc_coll_t *plcoll, guint pos, xmms_error_t *err)
663
676
{
664
 
        gint currpos, size;
665
 
        GHashTable *dict;
 
677
        gint currpos;
 
678
        GTree *dict;
666
679
 
667
680
        g_return_val_if_fail (playlist, FALSE);
668
681
 
669
682
        currpos = xmms_playlist_coll_get_currpos (plcoll);
670
 
        size = xmms_playlist_coll_get_size (plcoll);
671
683
 
672
 
        if (pos >= size) {
 
684
        if (!xmmsc_coll_idlist_remove (plcoll, pos)) {
673
685
                if (err) xmms_error_set (err, XMMS_ERROR_NOENT, "Entry was not in list!");
674
686
                return FALSE;
675
687
        }
676
688
 
677
 
        xmmsc_coll_idlist_remove (plcoll, pos);
678
 
        xmms_collection_set_int_attr (plcoll, "size", size - 1);
679
 
 
680
689
        /* decrease currentpos if removed entry was before or if it's
681
690
         * the current entry, but only if currentpos is a valid entry.
682
691
         */
686
695
        }
687
696
 
688
697
        dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_REMOVE, 0, plname);
689
 
        g_hash_table_insert (dict, (gpointer) "position",
690
 
                             xmms_object_cmd_value_int_new (pos));
 
698
        g_tree_insert (dict, (gpointer) "position",
 
699
                       xmms_object_cmd_value_int_new (pos));
691
700
        xmms_playlist_changed_msg_send (playlist, dict);
692
701
 
693
 
        xmms_object_emit_f (XMMS_OBJECT (playlist),
694
 
                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
695
 
                            XMMS_OBJECT_CMD_ARG_UINT32,
696
 
                            currpos);
 
702
        XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
697
703
 
698
704
        return TRUE;
699
705
}
783
789
xmms_playlist_move (xmms_playlist_t *playlist, gchar *plname, guint pos,
784
790
                    guint newpos, xmms_error_t *err)
785
791
{
786
 
        GHashTable *dict;
 
792
        GTree *dict;
787
793
        guint32 id;
788
794
        gint currpos, size;
789
795
        gint64 ipos, inewpos;
833
839
        xmmsc_coll_idlist_get_index (plcoll, newpos, &id);
834
840
 
835
841
        dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_MOVE, id, plname);
836
 
        g_hash_table_insert (dict, (gpointer) "position",
837
 
                             xmms_object_cmd_value_int_new (pos));
838
 
        g_hash_table_insert (dict, (gpointer) "newposition",
839
 
                             xmms_object_cmd_value_int_new (newpos));
 
842
        g_tree_insert (dict, (gpointer) "position",
 
843
                       xmms_object_cmd_value_int_new (pos));
 
844
        g_tree_insert (dict, (gpointer) "newposition",
 
845
                       xmms_object_cmd_value_int_new (newpos));
840
846
        xmms_playlist_changed_msg_send (playlist, dict);
841
847
 
842
 
        xmms_object_emit_f (XMMS_OBJECT (playlist),
843
 
                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
844
 
                            XMMS_OBJECT_CMD_ARG_UINT32,
845
 
                            currpos);
 
848
        XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
846
849
 
847
850
        g_mutex_unlock (playlist->mutex);
848
851
 
892
895
xmms_playlist_insert_id (xmms_playlist_t *playlist, gchar *plname, guint32 pos,
893
896
                         xmms_medialib_entry_t file, xmms_error_t *err)
894
897
{
895
 
        GHashTable *dict;
 
898
        GTree *dict;
896
899
        gint currpos;
897
900
        gint len;
898
901
        xmmsc_coll_t *plcoll;
920
923
                return FALSE;
921
924
        }
922
925
        xmmsc_coll_idlist_insert (plcoll, pos, file);
923
 
        xmms_collection_set_int_attr (plcoll, "size", len + 1);
924
 
 
 
926
 
 
927
        /** propagate the MID ! */
 
928
        dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_INSERT, file, plname);
 
929
        g_tree_insert (dict, (gpointer) "position",
 
930
                       xmms_object_cmd_value_int_new (pos));
 
931
        xmms_playlist_changed_msg_send (playlist, dict);
 
932
 
 
933
        /** update position once client is familiar with the new item. */
925
934
        currpos = xmms_playlist_coll_get_currpos (plcoll);
926
935
        if (pos <= currpos) {
927
936
                xmms_playlist_set_current_position_do (playlist, currpos + 1, err);
928
937
        }
929
938
 
930
 
        /** propagate the MID ! */
931
 
        dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_INSERT, file, plname);
932
 
        g_hash_table_insert (dict, (gpointer) "position",
933
 
                             xmms_object_cmd_value_int_new (pos));
934
 
        xmms_playlist_changed_msg_send (playlist, dict);
935
 
 
936
939
        g_mutex_unlock (playlist->mutex);
937
940
        return TRUE;
938
941
}
949
952
        while (res) {
950
953
                xmms_object_cmd_value_t *val = (xmms_object_cmd_value_t*)res->data;
951
954
                xmms_playlist_insert_id (playlist, plname, pos, val->value.int32, err);
952
 
                g_free (res->data);
953
 
                res = res->next;
 
955
                xmms_object_cmd_value_unref (val);
 
956
 
 
957
                res = g_list_delete_link (res, res);
954
958
        }
955
959
 
956
 
        g_list_free (res);
957
 
 
958
960
        /* FIXME: detect errors? */
959
961
        return TRUE;
960
962
}
1036
1038
}
1037
1039
 
1038
1040
gboolean
 
1041
xmms_playlist_add_idlist (xmms_playlist_t *playlist, gchar *plname,
 
1042
                          xmmsc_coll_t *coll,
 
1043
                          xmms_error_t *err)
 
1044
{
 
1045
        uint32_t *idlist;
 
1046
 
 
1047
        for (idlist = xmmsc_coll_get_idlist (coll); *idlist; idlist++) {
 
1048
                if (!xmms_medialib_check_id (*idlist)) {
 
1049
                        xmms_error_set (err, XMMS_ERROR_NOENT,
 
1050
                                        "Idlist contains invalid medialib id!");
 
1051
                        return FALSE;
 
1052
                }
 
1053
        }
 
1054
 
 
1055
        for (idlist = xmmsc_coll_get_idlist (coll); *idlist; idlist++) {
 
1056
                xmms_playlist_add_entry (playlist, plname, *idlist, err);
 
1057
        }
 
1058
 
 
1059
        return TRUE;
 
1060
}
 
1061
 
 
1062
gboolean
1039
1063
xmms_playlist_add_collection (xmms_playlist_t *playlist, gchar *plname,
1040
1064
                              xmmsc_coll_t *coll, GList *order,
1041
1065
                              xmms_error_t *err)
1047
1071
        while (res) {
1048
1072
                xmms_object_cmd_value_t *val = (xmms_object_cmd_value_t*)res->data;
1049
1073
                xmms_playlist_add_entry (playlist, plname, val->value.int32, err);
1050
 
                g_free (res->data);
1051
 
                res = res->next;
 
1074
                xmms_object_cmd_value_unref (val);
 
1075
 
 
1076
                res = g_list_delete_link (res, res);
1052
1077
        }
1053
1078
 
1054
 
        g_list_free (res);
1055
 
 
1056
1079
        /* FIXME: detect errors? */
1057
1080
        return TRUE;
1058
1081
}
1090
1113
                                  xmms_error_t *err)
1091
1114
{
1092
1115
        gint prev_size;
1093
 
        GHashTable *dict;
 
1116
        GTree *dict;
1094
1117
 
1095
1118
        prev_size = xmms_playlist_coll_get_size (plcoll);
1096
1119
        xmmsc_coll_idlist_append (plcoll, file);
1097
 
        xmms_collection_set_int_attr (plcoll, "size", prev_size + 1);
1098
1120
 
1099
1121
        /** propagate the MID ! */
1100
1122
        dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_ADD, file, plname);
1101
 
        g_hash_table_insert (dict, (gpointer) "position",
1102
 
                             xmms_object_cmd_value_int_new (prev_size));
 
1123
        g_tree_insert (dict, (gpointer) "position",
 
1124
                       xmms_object_cmd_value_int_new (prev_size));
1103
1125
        xmms_playlist_changed_msg_send (playlist, dict);
1104
1126
}
1105
1127
 
1115
1137
 
1116
1138
        plcoll = xmms_playlist_get_coll (playlist, plname, err);
1117
1139
        if (plcoll == NULL) {
 
1140
                g_mutex_unlock (playlist->mutex);
1118
1141
                return;
1119
1142
        }
1120
1143
 
1121
1144
        xmmsc_coll_idlist_clear (plcoll);
1122
1145
        xmms_collection_set_int_attr (plcoll, "position", -1);
1123
 
        xmms_collection_set_int_attr (plcoll, "size", 0);
1124
1146
 
1125
1147
        XMMS_PLAYLIST_CHANGED_MSG (XMMS_PLAYLIST_CHANGED_CLEAR, 0, plname);
1126
1148
        g_mutex_unlock (playlist->mutex);
1158
1180
            xmmsc_coll_attribute_get (plcoll, "jumplist", &jumplist)) {
1159
1181
 
1160
1182
                xmms_collection_set_int_attr (plcoll, "position", 0);
1161
 
                xmms_object_emit_f (XMMS_OBJECT (playlist),
1162
 
                                    XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
1163
 
                                    XMMS_OBJECT_CMD_ARG_UINT32,
1164
 
                                    0);
 
1183
                XMMS_PLAYLIST_CURRPOS_MSG (0, XMMS_ACTIVE_PLAYLIST);
1165
1184
 
1166
1185
                xmms_playlist_load (playlist, jumplist, err);
1167
1186
                if (xmms_error_iserror (err)) {
1175
1194
        } else if (pos < size) {
1176
1195
                XMMS_DBG ("newpos! %d", pos);
1177
1196
                xmms_collection_set_int_attr (plcoll, "position", pos);
1178
 
 
1179
 
                xmms_object_emit_f (XMMS_OBJECT (playlist),
1180
 
                                    XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
1181
 
                                    XMMS_OBJECT_CMD_ARG_UINT32,
1182
 
                                    pos);
 
1197
                XMMS_PLAYLIST_CURRPOS_MSG (pos, XMMS_ACTIVE_PLAYLIST);
1183
1198
        } else {
1184
1199
                xmms_error_set (err, XMMS_ERROR_INVAL,
1185
1200
                                "Can't set pos outside the current playlist!");
1210
1225
xmms_playlist_set_current_position_rel (xmms_playlist_t *playlist, gint32 pos,
1211
1226
                                        xmms_error_t *err)
1212
1227
{
1213
 
        gint currpos;
 
1228
        gint currpos, newpos;
1214
1229
        guint mid = 0;
1215
1230
        xmmsc_coll_t *plcoll;
1216
1231
 
1222
1237
        if (plcoll != NULL) {
1223
1238
                currpos = xmms_playlist_coll_get_currpos (plcoll);
1224
1239
 
1225
 
                if (currpos + pos >= 0)
1226
 
                        mid = xmms_playlist_set_current_position_do (playlist, currpos + pos, err);
 
1240
                if (playlist->repeat_all) {
 
1241
                        newpos = (pos+currpos) % (gint)xmmsc_coll_idlist_get_size (plcoll);
 
1242
 
 
1243
                        if (newpos < 0) {
 
1244
                                newpos += xmmsc_coll_idlist_get_size (plcoll);
 
1245
                        }
 
1246
 
 
1247
                        mid = xmms_playlist_set_current_position_do (playlist, newpos, err);
 
1248
                } else {
 
1249
                        if (currpos + pos >= 0) {
 
1250
                                mid = xmms_playlist_set_current_position_do (playlist,
 
1251
                                                                             currpos + pos,
 
1252
                                                                             err);
 
1253
                        } else {
 
1254
                                xmms_error_set (err, XMMS_ERROR_INVAL,
 
1255
                                                "Can't set pos outside the current playlist!");
 
1256
                        }
 
1257
                }
1227
1258
        }
1228
1259
 
1229
1260
        g_mutex_unlock (playlist->mutex);
1328
1359
 
1329
1360
        for (n = sorted->val; n; n = n->next) {
1330
1361
                if (n->data) {
1331
 
                        xmms_object_cmd_value_free (n->data);
 
1362
                        xmms_object_cmd_value_unref (n->data);
1332
1363
                }
1333
1364
        }
1334
1365
        g_list_free (sorted->val);
1462
1493
        g_list_free (tmp);
1463
1494
 
1464
1495
        XMMS_PLAYLIST_CHANGED_MSG (XMMS_PLAYLIST_CHANGED_SORT, 0, plname);
1465
 
 
1466
 
        xmms_object_emit_f (XMMS_OBJECT (playlist),
1467
 
                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
1468
 
                            XMMS_OBJECT_CMD_ARG_UINT32,
1469
 
                            currpos);
 
1496
        XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
1470
1497
 
1471
1498
        g_mutex_unlock (playlist->mutex);
1472
1499
}
1601
1628
static gint
1602
1629
xmms_playlist_coll_get_size (xmmsc_coll_t *plcoll)
1603
1630
{
1604
 
        gint size;
1605
 
 
1606
 
        /* If absent, compute the size and save it */
1607
 
        if (!xmms_collection_get_int_attr (plcoll, "size", &size)) {
1608
 
                gint i;
1609
 
                guint *idlist;
1610
 
 
1611
 
                size = 0;
1612
 
                idlist = xmmsc_coll_get_idlist (plcoll);
1613
 
                for (i = 0; idlist[i] != 0; i++) {
1614
 
                        size++;
1615
 
                }
1616
 
 
1617
 
                xmms_collection_set_int_attr (plcoll, "size", size);
1618
 
        }
1619
 
 
1620
 
        return size;
 
1631
        return xmmsc_coll_idlist_get_size (plcoll);
1621
1632
}
1622
1633
 
1623
1634
 
1624
 
GHashTable *
 
1635
GTree *
1625
1636
xmms_playlist_changed_msg_new (xmms_playlist_t *playlist,
1626
1637
                               xmms_playlist_changed_actions_t type,
1627
1638
                               guint32 id, const gchar *plname)
1628
1639
{
1629
 
        GHashTable *dict;
 
1640
        GTree *dict;
1630
1641
        xmms_object_cmd_value_t *val;
1631
1642
        const gchar *tmp;
1632
1643
 
1633
 
        dict = g_hash_table_new_full (g_str_hash,
1634
 
                                      g_str_equal,
1635
 
                                      NULL,
1636
 
                                      xmms_object_cmd_value_free);
 
1644
        dict = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
 
1645
                                NULL, (GDestroyNotify)xmms_object_cmd_value_unref);
 
1646
 
1637
1647
        val = xmms_object_cmd_value_int_new (type);
1638
 
        g_hash_table_insert (dict, (gpointer) "type", val);
 
1648
        g_tree_insert (dict, (gpointer) "type", val);
 
1649
 
1639
1650
        if (id) {
1640
1651
                val = xmms_object_cmd_value_uint_new (id);
1641
 
                g_hash_table_insert (dict, (gpointer) "id", val);
 
1652
                g_tree_insert (dict, (gpointer) "id", val);
1642
1653
        }
1643
1654
 
1644
1655
        tmp = xmms_playlist_canonical_name (playlist, plname);
1645
1656
        val = xmms_object_cmd_value_str_new (tmp);
1646
 
        g_hash_table_insert (dict, (gpointer) "name", val);
 
1657
        g_tree_insert (dict, (gpointer) "name", val);
 
1658
 
 
1659
        return dict;
 
1660
}
 
1661
 
 
1662
GTree *
 
1663
xmms_playlist_current_pos_msg_new (xmms_playlist_t *playlist,
 
1664
                                   guint32 pos, const gchar *plname)
 
1665
{
 
1666
        GTree *dict;
 
1667
        xmms_object_cmd_value_t *val;
 
1668
        const gchar *tmp;
 
1669
 
 
1670
        dict = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
 
1671
                                NULL, (GDestroyNotify)xmms_object_cmd_value_unref);
 
1672
 
 
1673
        val = xmms_object_cmd_value_uint_new (pos);
 
1674
        g_tree_insert (dict, (gpointer) "position", val);
 
1675
 
 
1676
        tmp = xmms_playlist_canonical_name (playlist, plname);
 
1677
        val = xmms_object_cmd_value_str_new (tmp);
 
1678
        g_tree_insert (dict, (gpointer) "name", val);
1647
1679
 
1648
1680
        return dict;
1649
1681
}
1650
1682
 
1651
1683
void
1652
 
xmms_playlist_changed_msg_send (xmms_playlist_t *playlist, GHashTable *dict)
 
1684
xmms_playlist_changed_msg_send (xmms_playlist_t *playlist, GTree *dict)
1653
1685
{
1654
1686
        xmms_object_cmd_value_t *type_cmd_val;
1655
1687
        xmms_object_cmd_value_t *pl_cmd_val;
1658
1690
        g_return_if_fail (dict);
1659
1691
 
1660
1692
        /* If local playlist change, trigger a COLL_CHANGED signal */
1661
 
        type_cmd_val = g_hash_table_lookup (dict, "type");
1662
 
        pl_cmd_val = g_hash_table_lookup (dict, "name");
 
1693
        type_cmd_val = g_tree_lookup (dict, "type");
 
1694
        pl_cmd_val = g_tree_lookup (dict, "name");
1663
1695
        if (type_cmd_val != NULL &&
1664
1696
            type_cmd_val->value.int32 != XMMS_PLAYLIST_CHANGED_UPDATE &&
1665
1697
            pl_cmd_val != NULL) {
1672
1704
                            XMMS_OBJECT_CMD_ARG_DICT,
1673
1705
                            dict);
1674
1706
 
1675
 
        g_hash_table_destroy (dict);
 
1707
        g_tree_destroy (dict);
 
1708
}
 
1709
 
 
1710
static void
 
1711
xmms_playlist_current_pos_msg_send (xmms_playlist_t *playlist,
 
1712
                                   GTree *dict)
 
1713
{
 
1714
        g_return_if_fail (playlist);
 
1715
 
 
1716
        g_return_if_fail (dict);
 
1717
 
 
1718
        xmms_object_emit_f (XMMS_OBJECT (playlist),
 
1719
                            XMMS_IPC_SIGNAL_PLAYLIST_CURRENT_POS,
 
1720
                            XMMS_OBJECT_CMD_ARG_DICT,
 
1721
                            dict);
 
1722
 
 
1723
        g_tree_destroy (dict);
1676
1724
}