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