Commit 782868ba authored by Scott Wheeler's avatar Scott Wheeler

More work on the SearchPlaylist class to get it ready for usage with

"vFolders" / TreeView.  I hope to soon port that code over to using
these classes.

svn path=/trunk/kdemultimedia/juk/; revision=229556
parent 5495508b
......@@ -50,7 +50,7 @@ void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *)
PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *, bool)
{
QString filePath;
......
......@@ -57,7 +57,8 @@ public:
CollectionListItem *lookup(const QString &file) { return m_itemsDict.find(file); }
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
QListViewItem * = 0);
QListViewItem * = 0,
bool = false);
public slots:
virtual void paste() { decode(kapp->clipboard()->data()); }
......
......@@ -615,7 +615,7 @@ void Playlist::showEvent(QShowEvent *e)
KListView::showEvent(e);
}
PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *after)
PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *after, bool emitChanged)
{
QString filePath;
......@@ -647,6 +647,10 @@ PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFile
m_randomList.append(i);
emit signalNumberOfItemsChanged(this);
connect(item, SIGNAL(destroyed()), i, SLOT(deleteLater()));
if(emitChanged)
emit signalNumberOfItemsChanged(this);
return i;
}
else
......@@ -664,6 +668,7 @@ void Playlist::createItems(const PlaylistItemList &siblings)
connect((*it)->collectionItem(), SIGNAL(destroyed()), *it, SLOT(deleteLater()));
}
}
emit signalNumberOfItemsChanged(this);
}
void Playlist::hideColumn(int c)
......@@ -824,6 +829,9 @@ void Playlist::setup()
m_allowDuplicates = false;
connect(header(), SIGNAL(indexChange(int, int, int)), this, SLOT(slotColumnOrderChanged(int, int, int)));
connect(this, SIGNAL(signalDataChanged()), this, SIGNAL(signalChanged()));
connect(this, SIGNAL(signalNumberOfItemsChanged(Playlist *)), this, SIGNAL(signalChanged()));
}
void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
......@@ -849,13 +857,15 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
if(MediaFiles::isMediaFile(item.fileName()) && item.exists() && item.isFile() && item.isReadable()) {
if(after)
after = createItem(item, QString::null, after);
after = createItem(item, QString::null, after, false);
else
after = createItem(item);
after = createItem(item, QString::null, 0, false);
}
}
file.close();
emit signalNumberOfItemsChanged(this);
}
void Playlist::setPlaying(PlaylistItem *item, bool p)
......@@ -1069,9 +1079,11 @@ QDataStream &operator>>(QDataStream &s, Playlist &p)
for(QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
QFileInfo info(*it);
after = p.createItem(info, *it, after);
after = p.createItem(info, *it, after, false);
}
p.emitNumberOfItemsChanged();
return s;
}
......
......@@ -107,7 +107,8 @@ public:
*/
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
QListViewItem *after = 0);
QListViewItem *after = 0,
bool emitChanged = true);
void createItems(const PlaylistItemList &siblings);
......@@ -161,6 +162,8 @@ public:
PlaylistSearch search() const { return m_search; }
void setSearch(const PlaylistSearch &s) { m_search = s; }
void emitNumberOfItemsChanged() { emit signalNumberOfItemsChanged(this); }
public slots:
/**
* Remove the currently selected items from the playlist and disk.
......@@ -231,10 +234,19 @@ signals:
*/
void signalNameChanged(const QString &fileName);
/**
* This signal is emited when items are added to or removed from the list.
*/
void signalNumberOfItemsChanged(Playlist *);
void signalDoubleClicked();
/**
* This is the union of signalDataChanged() and signalNumberOfItemsChanged().
* It is emited with either quantity or value of the PlaylistItems are
* changed.
*/
void signalChanged();
/**
* This signal is emitted just before a playlist item is removed from the
* list.
......
......@@ -44,12 +44,14 @@ PlaylistSearch::PlaylistSearch(const PlaylistSearch &search) :
PlaylistSearch::PlaylistSearch(const PlaylistList &playlists,
const ComponentList &components,
SearchMode mode) :
SearchMode mode,
bool searchNow) :
m_playlists(playlists),
m_components(components),
m_mode(mode)
{
search();
if(searchNow)
search();
}
bool PlaylistSearch::isEmpty() const
......@@ -66,12 +68,11 @@ bool PlaylistSearch::isEmpty() const
return true;
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
void PlaylistSearch::search()
{
m_items.clear();
m_matchedItems.clear();
m_unmatchedItems.clear();
// This really isn't as bad as it looks. Despite the four nexted loops
// most of the time this will be searching one playlist for one search
......
......@@ -39,8 +39,10 @@ public:
PlaylistSearch(const PlaylistSearch &search);
PlaylistSearch(const PlaylistList &playlists,
const ComponentList &components,
SearchMode mode = MatchAny);
SearchMode mode = MatchAny,
bool searchNow = true);
void search();
PlaylistItemList searchedItems() const { return m_items; }
PlaylistItemList matchedItems() const { return m_matchedItems; }
......@@ -54,8 +56,6 @@ public:
bool isEmpty() const;
private:
void search();
PlaylistList m_playlists;
ComponentList m_components;
SearchMode m_mode;
......
......@@ -333,6 +333,7 @@ void PlaylistSplitter::slotAddToPlaylist(const QString &file, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
addImpl(file, list);
list->emitNumberOfItemsChanged();
KApplication::restoreOverrideCursor();
if(m_editor)
......@@ -344,6 +345,7 @@ void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *lis
KApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
addImpl(*it, list);
list->emitNumberOfItemsChanged();
KApplication::restoreOverrideCursor();
if(m_editor)
......@@ -538,7 +540,7 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
}
else {
if(MediaFiles::isMediaFile(file))
list->createItem(fileInfo);
list->createItem(fileInfo, QString::null, 0, false);
else if(MediaFiles::isPlaylistFile(file))
openPlaylist(fileInfo.absFilePath());
}
......
......@@ -23,16 +23,33 @@
SearchPlaylist::SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name) :
DynamicPlaylist(search.playlists(), parent, name),
m_search(search)
m_search(search),
m_dirty(true)
{
PlaylistList::Iterator it = search.playlists().begin();
for(; it != search.playlists().end(); ++it)
connect(*it, SIGNAL(signalChanged()), this, SLOT(slotSetDirty()));
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
void SearchPlaylist::showEvent(QShowEvent *e)
{
if(m_dirty) {
clear();
m_search.search();
createItems(m_search.matchedItems());
m_dirty = false;
}
DynamicPlaylist::showEvent(e);
}
PlaylistItemList SearchPlaylist::items() const
{
return m_search.matchedItems();
}
#include "searchplaylist.moc"
......@@ -23,14 +23,19 @@
class SearchPlaylist : public DynamicPlaylist
{
Q_OBJECT
public:
SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name = QString::null);
protected:
virtual void showEvent(QShowEvent *e);
virtual PlaylistItemList items() const;
private slots:
void slotSetDirty() { m_dirty = true; }
private:
PlaylistSearch m_search;
bool m_dirty;
};
#endif
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