Commit b4f8ac04 authored by Scott Wheeler's avatar Scott Wheeler

Make it so that items that are added are checked against the current search

before being displayed.

CCMAIL:63551-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=265969
parent 92f394e5
......@@ -69,7 +69,9 @@ PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &a
delete item;
return 0;
}
setupItem(item);
return item;
}
......
......@@ -926,6 +926,12 @@ void Playlist::polish()
m_disableColumnWidthUpdates = false;
}
void Playlist::setupItem(PlaylistItem *item)
{
if(!m_search.isEmpty())
item->setVisible(m_search.checkItem(item));
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......
......@@ -387,6 +387,14 @@ protected:
*/
virtual void polish();
/**
* Do some finial initialization of created items. Notably ensure that they
* are shown or hidden based on the contents of the current PlaylistSearch.
*
* This is called by the PlaylistItem constructor.
*/
void setupItem(PlaylistItem *item);
/**
* As a template this allows us to use the same code to initialize the items
* in subclasses. CollectionItemType should always be CollectionListItem and
......@@ -646,6 +654,7 @@ ItemType *Playlist::createItem(const QFileInfo &file, const QString &absFilePath
if(!item) {
item = new CollectionItemType(file, filePath);
setupItem(item);
// If a valid tag was not created, destroy the CollectionListItem.
if(!item->isValid()) {
......@@ -662,8 +671,12 @@ ItemType *Playlist::createItem(const QFileInfo &file, const QString &absFilePath
i = new ItemType(item, this, after);
else
i = new ItemType(item, this);
setupItem(i);
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.append(i);
emit signalCountChanged(this);
connect(item, SIGNAL(destroyed()), i, SLOT(deleteLater()));
......
......@@ -45,20 +45,6 @@ PlaylistSearch::PlaylistSearch(const PlaylistList &playlists,
search();
}
bool PlaylistSearch::isEmpty() const
{
if(isNull())
return true;
ComponentList::ConstIterator it = m_components.begin();
for(; it != m_components.end(); ++it) {
if(!(*it).query().isEmpty() || !(*it).pattern().isEmpty())
return false;
}
return true;
}
void PlaylistSearch::search()
{
m_items.clear();
......@@ -76,38 +62,54 @@ void PlaylistSearch::search()
PlaylistList::Iterator playlistIt = m_playlists.begin();
for(; playlistIt != m_playlists.end(); ++playlistIt) {
for(QListViewItemIterator it(*playlistIt); it.current(); ++it)
checkItem(static_cast<PlaylistItem *>(*it));
}
}
for(QListViewItemIterator it(*playlistIt); it.current(); ++it) {
bool PlaylistSearch::checkItem(PlaylistItem *item)
{
m_items.append(item);
PlaylistItem *item = static_cast<PlaylistItem *>(*it);
// set our default
bool match = bool(m_mode);
m_items.append(item);
ComponentList::Iterator componentIt = m_components.begin();
for(; componentIt != m_components.end(); ++componentIt) {
// set our default
bool match = bool(m_mode);
bool componentMatches = (*componentIt).matches(item);
ComponentList::Iterator componentIt = m_components.begin();
for(; componentIt != m_components.end(); ++componentIt) {
if(componentMatches && m_mode == MatchAny) {
match = true;
break;
}
bool componentMatches = (*componentIt).matches(item);
if(!componentMatches && m_mode == MatchAll) {
match = false;
break;
}
}
if(componentMatches && m_mode == MatchAny) {
match = true;
break;
}
if(match)
m_matchedItems.append(item);
else
m_unmatchedItems.append(item);
if(!componentMatches && m_mode == MatchAll) {
match = false;
break;
}
}
return match;
}
if(match)
m_matchedItems.append(item);
else
m_unmatchedItems.append(item);
}
bool PlaylistSearch::isEmpty() const
{
if(isNull())
return true;
ComponentList::ConstIterator it = m_components.begin();
for(; it != m_components.end(); ++it) {
if(!(*it).query().isEmpty() || !(*it).pattern().isEmpty())
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -44,6 +44,7 @@ public:
bool searchNow = true);
void search();
bool checkItem(PlaylistItem *item);
PlaylistItemList searchedItems() const { return m_items; }
PlaylistItemList matchedItems() const { return m_matchedItems; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment