Commit 673e6d3c authored by Scott Wheeler's avatar Scott Wheeler

Make JuK remeber the search for a playlist (during that instance only).

Now when you move to a different playlist the search on the previous one
will be remembered.  Also if you hide the search bar, when you redisplay it
your previous search will still be there.

Doing this also gave me an excuse to clean up the way that the PlaylistSplitter
and SearchWidget interact -- the SearchWidget now returns a real PlaylistSearch
rather than more "raw" information about the search results.

svn path=/trunk/kdemultimedia/juk/; revision=229414
parent 7cb5aaec
......@@ -15,6 +15,8 @@
* *
***************************************************************************/
#include <kdebug.h>
#include "playlistsearch.h"
#include "playlist.h"
#include "playlistitem.h"
......@@ -32,7 +34,10 @@ PlaylistSearch::PlaylistSearch() :
PlaylistSearch::PlaylistSearch(const PlaylistSearch &search) :
m_playlists(search.m_playlists),
m_components(search.m_components),
m_mode(search.m_mode)
m_mode(search.m_mode),
m_items(search.m_items),
m_matchedItems(search.m_matchedItems),
m_unmatchedItems(search.m_unmatchedItems)
{
}
......@@ -47,6 +52,20 @@ 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;
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -51,6 +51,7 @@ public:
ComponentList components() const { return m_components; }
bool isNull() const { return m_components.isEmpty(); }
bool isEmpty() const;
private:
void search();
......
......@@ -23,6 +23,7 @@
#include <qpopupmenu.h>
#include "playlistsplitter.h"
#include "searchwidget.h"
#include "directorylist.h"
#include "playlistsearch.h"
#include "dynamicplaylist.h"
......@@ -349,6 +350,13 @@ void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *lis
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::slotSetSearchVisible(bool visible)
{
m_searchWidget->setShown(visible);
redisplaySearch();
}
void PlaylistSplitter::slotGuessTagInfoFile()
{
visiblePlaylist()->slotGuessTagInfoFile();
......@@ -417,8 +425,7 @@ void PlaylistSplitter::setupLayout()
// Create the search widget -- this must be done after the CollectionList is created.
m_searchWidget = new SearchWidget(editorSplitter, CollectionList::instance(), "searchWidget");
editorSplitter->moveToFirst(m_searchWidget);
connect(m_searchWidget, SIGNAL(signalQueryChanged(const QString &, bool, bool)),
this, SLOT(slotShowSearchResults(const QString &, bool, bool)));
connect(m_searchWidget, SIGNAL(signalQueryChanged()), this, SLOT(slotShowSearchResults()));
connect(CollectionList::instance(), SIGNAL(signalVisibleColumnsChanged()),
this, SLOT(slotVisibleColumnsChanged()));
......@@ -556,8 +563,11 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
if(icon)
m_playlistBox->createItem(p, icon, raise);
if(raise)
m_playlistStack->raiseWidget(p);
if(raise) {
PlaylistList l;
l.append(p);
slotChangePlaylist(l);
}
}
Playlist *PlaylistSplitter::openPlaylist(const QString &file)
......@@ -592,6 +602,16 @@ QString PlaylistSplitter::play(PlaylistItem *item)
return item->absFilePath();
}
void PlaylistSplitter::redisplaySearch()
{
if(!m_searchWidget->isVisible() || visiblePlaylist()->search().isEmpty())
visiblePlaylist()->setItemsVisible(visiblePlaylist()->items(), true);
else {
Playlist::setItemsVisible(visiblePlaylist()->search().matchedItems(), true);
Playlist::setItemsVisible(visiblePlaylist()->search().unmatchedItems(), false);
}
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......@@ -605,14 +625,16 @@ void PlaylistSplitter::slotChangePlaylist(const PlaylistList &l)
Playlist *current = m_dynamicList;
if(m_searchWidget)
m_searchWidget->clear();
m_nextPlaylistItem = 0;
if(l.count() == 1) {
m_playlistStack->raiseWidget(l.first());
m_editor->slotSetItems(playlistSelection());
m_dynamicList = 0;
if(m_searchWidget) {
m_searchWidget->setSearch(l.first()->search());
redisplaySearch();
}
}
else {
m_dynamicList = new DynamicPlaylist(l, m_playlistStack, i18n("Dynamic List"));
......@@ -654,31 +676,15 @@ void PlaylistSplitter::slotCreatePlaylist(const PlaylistItemList &items)
m_playlistBox->initViewMode();
}
void PlaylistSplitter::slotShowSearchResults(const QString &query, bool caseSensitive, bool regExp)
void PlaylistSplitter::slotShowSearchResults()
{
if(query.isEmpty()) {
visiblePlaylist()->setItemsVisible(visiblePlaylist()->items(), true);
return;
}
PlaylistList playlists;
playlists.append(visiblePlaylist());
PlaylistSearch::Component *component;
if(regExp)
component = new PlaylistSearch::Component(QRegExp(query, caseSensitive), m_searchWidget->searchedColumns(0));
else
component = new PlaylistSearch::Component(query, caseSensitive, m_searchWidget->searchedColumns(0));
PlaylistSearch::ComponentList components;
components.append(*component);
PlaylistSearch search(playlists, components);
PlaylistSearch search = m_searchWidget->search(playlists);
Playlist::setItemsVisible(search.matchedItems(), true);
Playlist::setItemsVisible(search.unmatchedItems(), false);
delete component;
visiblePlaylist()->setSearch(search);
redisplaySearch();
}
void PlaylistSplitter::slotVisibleColumnsChanged()
......@@ -686,7 +692,7 @@ void PlaylistSplitter::slotVisibleColumnsChanged()
m_searchWidget->slotUpdateColumns();
m_searchWidget->slotQueryChanged();
if(m_searchWidget->searchedColumns(0).count() > 1)
slotShowSearchResults(m_searchWidget->query(), m_searchWidget->caseSensitive(), m_searchWidget->regExp());
slotShowSearchResults();
}
#include "playlistsplitter.moc"
......
......@@ -28,11 +28,11 @@
#include "collectionlist.h"
#include "stringhash.h"
#include "tageditor.h"
#include "searchwidget.h"
class KActionMenu;
class KDirWatch;
class PlaylistItem;
class SearchWidget;
/**
* This is the main layout class of JuK. It should contain a PlaylistBox and
......@@ -205,7 +205,7 @@ public slots:
*/
void slotSetEditorVisible(bool visible) { m_editor->setShown(visible); }
void slotSetSearchVisible(bool visible) { m_searchWidget->clear(); m_searchWidget->setShown(visible); }
void slotSetSearchVisible(bool visible);
/**
* Add the file to the playlist.
......@@ -268,6 +268,12 @@ private:
*/
QString play(PlaylistItem *item);
/**
* This should be called to update the shown items -- it does not restart the
* search.
*/
void redisplaySearch();
private slots:
void slotChangePlaylist(const PlaylistList &l);
void slotPlaylistCountChanged(Playlist *p);
......@@ -292,7 +298,7 @@ private slots:
void slotSetNextItem(PlaylistItem *item = 0) { m_nextPlaylistItem = item; }
void slotDirChanged(const QString &dir) { slotAddToPlaylist(dir, m_collection); }
void slotCreatePlaylist(const PlaylistItemList &items);
void slotShowSearchResults(const QString &query, bool caseSensitive = false, bool regExp = false);
void slotShowSearchResults();
void slotVisibleColumnsChanged();
private:
......
......@@ -18,6 +18,7 @@
#include <klocale.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <kdebug.h>
#include <qlayout.h>
#include <qlabel.h>
......@@ -26,7 +27,6 @@
#include "searchwidget.h"
#include "playlist.h"
#include "playlistsearch.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -53,12 +53,12 @@ QString SearchWidget::query() const
bool SearchWidget::caseSensitive() const
{
return m_caseSensitive->currentItem() == 1;
return m_caseSensitive->currentItem() == CaseSensitive;
}
bool SearchWidget::regExp() const
{
return m_caseSensitive->currentItem() == 2;
return m_caseSensitive->currentItem() == Pattern;
}
void SearchWidget::setSearch(const PlaylistSearch &search)
......@@ -70,8 +70,10 @@ void SearchWidget::setSearch(const PlaylistSearch &search)
PlaylistSearch::ComponentList::ConstIterator it = components.begin();
if(it == components.end())
if(it == components.end()) {
clear();
return;
}
if(!(*it).isPatternSearch()) {
m_lineEdit->setText((*it).query());
......@@ -83,6 +85,23 @@ void SearchWidget::setSearch(const PlaylistSearch &search)
}
}
PlaylistSearch SearchWidget::search(const PlaylistList &playlists) const
{
PlaylistSearch::ComponentList components;
PlaylistSearch::Component c;
if(m_caseSensitive->currentItem() != Pattern)
c = PlaylistSearch::Component(query(), caseSensitive(), searchedColumns());
else
c = PlaylistSearch::Component(QRegExp(query()), searchedColumns());
components.append(c);
PlaylistSearch s(playlists, components);
return s;
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -107,7 +126,7 @@ void SearchWidget::slotQueryChanged(int)
else
m_searchedColumns[0].append(m_searchFieldsBox->currentItem() - 1);
emit signalQueryChanged(m_lineEdit->text(), caseSensitive(), regExp());
emit signalQueryChanged();
}
void SearchWidget::slotUpdateColumns()
......
......@@ -20,13 +20,14 @@
#include <qwidget.h>
#include "playlistsearch.h"
class QCheckBox;
class KLineEdit;
class KComboBox;
class Playlist;
class PlaylistSearch;
class SearchWidget : public QWidget
{
......@@ -44,11 +45,13 @@ public:
/**
* Returns a list of searched columns for the given search row.
*/
QValueList<int> searchedColumns(int searchLine = 0) { return m_searchedColumns[searchLine]; }
QValueList<int> searchedColumns(int searchLine = 0) const { return m_searchedColumns[searchLine]; }
QString query() const;
bool caseSensitive() const;
bool regExp() const;
PlaylistSearch search(const PlaylistList &playlists) const;
void setSearch(const PlaylistSearch &search);
public slots:
......@@ -57,7 +60,7 @@ public slots:
void slotQueryChanged(int = 0);
signals:
void signalQueryChanged(const QString &query, bool caseSensitive, bool regExp);
void signalQueryChanged();
private:
void setupLayout();
......
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