Commit a34953ff authored by Scott Wheeler's avatar Scott Wheeler

Finished the code for saving and restoring search playlists / vfolders.

Wrote streaming operators for the SearchPlaylist, PlaylistSearch and
PlaylistSearch::Component classes and added accessors where appropriate.

svn path=/trunk/kdemultimedia/juk/; revision=243479
parent 60d0fbbb
......@@ -15,11 +15,13 @@
* *
***************************************************************************/
#include <kdatastream.h>
#include <kdebug.h>
#include "playlistsearch.h"
#include "playlist.h"
#include "playlistitem.h"
#include "collectionlist.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -145,7 +147,7 @@ PlaylistSearch::Component::Component(const QRegExp &query, const ColumnList& col
}
bool PlaylistSearch::Component::matches(PlaylistItem *item)
bool PlaylistSearch::Component::matches(PlaylistItem *item) const
{
if((m_re && m_queryRe.isEmpty()) || (!m_re && m_query.isEmpty()))
return false;
......@@ -212,3 +214,68 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item)
}
return false;
}
QDataStream &operator<<(QDataStream &s, const PlaylistSearch &search)
{
s << search.components()
<< Q_INT32(search.searchMode());
return s;
}
QDataStream &operator>>(QDataStream &s, PlaylistSearch &search)
{
search.clearPlaylists();
search.addPlaylist(CollectionList::instance());
search.clearComponents();
PlaylistSearch::ComponentList components;
s >> components;
PlaylistSearch::ComponentList::ConstIterator it = components.begin();
for(; it != components.end(); ++it)
search.addComponent(*it);
Q_INT32 mode;
s >> mode;
search.setSearchMode(PlaylistSearch::SearchMode(mode));
return s;
}
QDataStream &operator<<(QDataStream &s, const PlaylistSearch::Component &c)
{
s << c.isPatternSearch();
if(c.isPatternSearch())
s << c.pattern().pattern();
else
s << c.query();
s << c.isCaseSensitive()
<< c.columns()
<< Q_INT32(c.matchMode());
return s;
}
QDataStream &operator>>(QDataStream &s, PlaylistSearch::Component &c)
{
bool patternSearch;
QString pattern;
bool caseSensitive;
ColumnList columns;
Q_INT32 mode;
s >> patternSearch
>> pattern
>> caseSensitive
>> columns
>> mode;
if(patternSearch)
c = PlaylistSearch::Component(QRegExp(pattern), columns);
else
c = PlaylistSearch::Component(pattern, caseSensitive, columns, PlaylistSearch::Component::MatchMode(mode));
return s;
}
......@@ -58,6 +58,7 @@ public:
ComponentList components() const { return m_components; }
void setSearchMode(SearchMode m) { m_mode = m; }
SearchMode searchMode() const { return m_mode; }
bool isNull() const { return m_components.isEmpty(); }
bool isEmpty() const;
......@@ -105,19 +106,38 @@ public:
QRegExp pattern() const { return m_queryRe; }
ColumnList columns() const { return m_columns; }
bool matches(PlaylistItem *item);
bool matches(PlaylistItem *item) const;
bool isPatternSearch() const { return m_re; }
bool isCaseSensitive() const { return m_caseSensitive; }
MatchMode matchMode() const { return m_mode; }
private:
QString m_query;
QRegExp m_queryRe;
ColumnList m_columns;
mutable ColumnList m_columns;
MatchMode m_mode;
bool m_searchAllVisible;
bool m_caseSensitive;
bool m_re;
};
/**
* Streams \a search to the stream \a s.
* \note This does not save the playlist list, but instead will assume that the
* search is just relevant to the collection list. This is all that is presently
* needed by JuK.
*/
QDataStream &operator<<(QDataStream &s, const PlaylistSearch &search);
/**
* Streams \a search from the stream \a s.
* \note This does not save the playlist list, but instead will assume that the
* search is just relevant to the collection list. This is all that is presently
* needed by JuK.
*/
QDataStream &operator>>(QDataStream &s, PlaylistSearch &search);
QDataStream &operator<<(QDataStream &s, const PlaylistSearch::Component &c);
QDataStream &operator>>(QDataStream &s, PlaylistSearch::Component &c);
#endif
......@@ -710,8 +710,13 @@ void PlaylistSplitter::readPlaylists()
switch(playlistType) {
case Search:
// p = new SearchPlaylist(m_playlistStack);
{
SearchPlaylist *p = new SearchPlaylist(m_playlistStack);
s >> *p;
setupPlaylist(p, false, "find");
break;
}
case History:
{
slotSetHistoryVisible(true);
......@@ -778,15 +783,16 @@ void PlaylistSplitter::savePlaylists()
// These first two aren't implemented yet.
if(*it == m_history) {
s << Q_INT32(History);
s << *m_history;
s << Q_INT32(History)
<< *m_history;
}
else if(dynamic_cast<SearchPlaylist *>(*it)) {
// s << Q_INT32(Search);
s << Q_INT32(Search)
<< *static_cast<SearchPlaylist *>(*it);
}
else {
s << Q_INT32(Normal);
s << *(*it);
s << Q_INT32(Normal)
<< *(*it);
}
}
}
......
......@@ -45,4 +45,31 @@ void SearchPlaylist::updateItems()
createItems(m_search.matchedItems());
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const SearchPlaylist &p)
{
s << p.name()
<< p.playlistSearch();
return s;
}
QDataStream &operator>>(QDataStream &s, SearchPlaylist &p)
{
QString name;
PlaylistSearch search;
s >> name
>> search;
p.setName(name);
p.setPlaylistSearch(search);
return s;
}
#include "searchplaylist.moc"
......@@ -29,6 +29,9 @@ public:
const PlaylistSearch &search = PlaylistSearch(),
const QString &name = QString::null);
PlaylistSearch playlistSearch() const { return m_search; }
void setPlaylistSearch(const PlaylistSearch &s) { m_search = s; }
protected:
/**
* Runs the search to update the current items.
......@@ -38,4 +41,7 @@ protected:
PlaylistSearch m_search;
};
QDataStream &operator<<(QDataStream &s, const SearchPlaylist &p);
QDataStream &operator>>(QDataStream &s, SearchPlaylist &p);
#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