1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/***************************************************************************
begin : Mon May 5 2003
copyright : (C) 2003 - 2004 by Scott Wheeler
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kdebug.h>
#include <tqptrdict.h>
#include "searchplaylist.h"
#include "playlistitem.h"
#include "collectionlist.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
SearchPlaylist::SearchPlaylist(PlaylistCollection *collection,
const PlaylistSearch &search,
const TQString &name,
bool setupPlaylist,
bool synchronizePlaying) :
DynamicPlaylist(search.playlists(), collection, name, "edit-find",
setupPlaylist, synchronizePlaying),
m_search(search)
{
}
void SearchPlaylist::setPlaylistSearch(const PlaylistSearch &s, bool update)
{
m_search = s;
if(update)
setPlaylists(s.playlists());
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
void SearchPlaylist::updateItems()
{
// Here we don't simply use "clear" since that would involve a call to
// items() which would in turn call this method...
PlaylistItemList l = Playlist::items();
TQPtrDict<PlaylistItem> oldItems(503);
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it)
oldItems.insert((*it)->collectionItem(), *it);
m_search.search();
PlaylistItemList matched = m_search.matchedItems();
PlaylistItemList newItems;
for(PlaylistItemList::ConstIterator it = matched.begin(); it != matched.end(); ++it) {
if(!oldItems.remove((*it)->collectionItem()))
newItems.append((*it)->collectionItem());
}
// kdDebug(65432) << k_funcinfo << "newItems.size() == " << newItems.size() << endl;
for(TQPtrDictIterator<PlaylistItem> it(oldItems); it.current(); ++it)
clearItem(it.current(), false);
if(!oldItems.isEmpty() && newItems.isEmpty())
dataChanged();
createItems(newItems);
if(synchronizePlaying()) {
kdDebug(65432) << k_funcinfo << "synchronizing playing" << endl;
synchronizePlayingItems(m_search.playlists(), true);
}
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
TQDataStream &operator<<(TQDataStream &s, const SearchPlaylist &p)
{
s << p.name()
<< p.playlistSearch();
return s;
}
TQDataStream &operator>>(TQDataStream &s, SearchPlaylist &p)
{
TQString name;
PlaylistSearch search;
s >> name
>> search;
p.setName(name);
p.setPlaylistSearch(search, false);
return s;
}
#include "searchplaylist.moc"
|