Commit ba5fa0e0 authored by Scott Wheeler's avatar Scott Wheeler

Making it possible to restrict the search based on a set of columns.

svn path=/trunk/kdemultimedia/juk/; revision=218993
parent 238ef32f
......@@ -608,6 +608,7 @@ void Playlist::hideColumn(int c)
}
m_leftColumn = leftMostVisibleColumn();
}
emit signalVisibleColumnsChanged();
}
void Playlist::showColumn(int c)
......@@ -631,6 +632,7 @@ void Playlist::showColumn(int c)
}
m_leftColumn = leftMostVisibleColumn();
}
emit signalVisibleColumnsChanged();
}
bool Playlist::isColumnVisible(int c) const
......
......@@ -212,6 +212,7 @@ signals:
void signalAboutToRemove(PlaylistItem *item);
void signalFilesDropped(const QStringList &files, Playlist *);
void signalSetNext(PlaylistItem *item);
void signalVisibleColumnsChanged();
private:
void setup();
......
......@@ -17,16 +17,24 @@
#include "playlistsearch.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistSearch::PlaylistSearch(const PlaylistList &playlists,
const ComponentList &components,
SearchMode mode) :
m_playlists(playlists),
m_components(components),
m_components(components),
m_mode(mode)
{
search();
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
void PlaylistSearch::search()
{
......@@ -75,6 +83,10 @@ void PlaylistSearch::search()
}
}
////////////////////////////////////////////////////////////////////////////////
// Component public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistSearch::Component::Component(const QString &query, bool caseSensitive, const ColumnList &columns) :
m_query(query),
m_columns(columns),
......@@ -91,9 +103,9 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item)
if(m_columns.isEmpty()) {
Playlist *p = static_cast<Playlist *>(item->listView());
for(int i = 0; i < PlaylistItem::lastColumn(); i++) {
for(int i = 0; i < p->columns(); i++) {
if(p->isColumnVisible(i))
m_columns.append(PlaylistItem::ColumnType(i));
m_columns.append(i);
}
}
......
......@@ -23,7 +23,7 @@
#include "playlist.h"
#include "playlistitem.h"
typedef QValueList<PlaylistItem::ColumnType> ColumnList;
typedef QValueList<int> ColumnList;
class PlaylistSearch
{
......
......@@ -373,13 +373,9 @@ void PlaylistSplitter::setupLayout()
// Create the playlist and the editor.
m_searchWidget = new SearchWidget(editorSplitter, "searchWidget");
m_playlistStack = new QWidgetStack(editorSplitter, "playlistStack");
m_editor = new TagEditor(editorSplitter, "tagEditor");
connect(m_searchWidget, SIGNAL(signalQueryChanged(const QString &, bool)),
this, SLOT(slotShowSearchResults(const QString &, bool)));
// Make the editor as small as possible (or at least as small as recommended)
editorSplitter->setResizeMode(m_editor, QSplitter::FollowSizeHint);
......@@ -404,6 +400,15 @@ void PlaylistSplitter::setupLayout()
connect(m_collection, SIGNAL(signalRequestPlaylistCreation(const QValueList<QFileInfo> &)),
this, SLOT(slotCreatePlaylist(const QValueList<QFileInfo> &)));
// 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)),
this, SLOT(slotShowSearchResults(const QString &, bool)));
connect(CollectionList::instance(), SIGNAL(signalVisibleColumnsChanged()),
this, SLOT(slotVisibleColumnsChanged()));
// Show the collection on startup.
m_playlistBox->setSelected(0, true);
}
......@@ -628,7 +633,7 @@ void PlaylistSplitter::slotShowSearchResults(const QString &query, bool caseSens
PlaylistList playlists;
playlists.append(visiblePlaylist());
PlaylistSearch::Component component(query, caseSensitive);
PlaylistSearch::Component component(query, caseSensitive, m_searchWidget->searchedColumns(0));
PlaylistSearch::ComponentList components;
components.append(&component);
......@@ -638,6 +643,14 @@ void PlaylistSplitter::slotShowSearchResults(const QString &query, bool caseSens
Playlist::setItemsVisible(search.unmatchedItems(), false);
}
void PlaylistSplitter::slotVisibleColumnsChanged()
{
m_searchWidget->slotUpdateColumns();
m_searchWidget->slotQueryChanged();
if(m_searchWidget->searchedColumns(0).count() > 1)
slotShowSearchResults(m_searchWidget->query(), m_searchWidget->caseSensitive());
}
#include "playlistsplitter.moc"
// vim:ts=8
......@@ -291,6 +291,7 @@ private slots:
void slotDirChanged(const QString &dir) { slotAddToPlaylist(dir, m_collection); }
void slotCreatePlaylist(const QValueList<QFileInfo> &fileInfos);
void slotShowSearchResults(const QString &query, bool caseSensitive = false);
void slotVisibleColumnsChanged();
private:
PlaylistItem *m_playingItem;
......
......@@ -17,6 +17,7 @@
#include <klocale.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <qlayout.h>
#include <qlabel.h>
......@@ -24,33 +25,34 @@
#include <qpushbutton.h>
#include "searchwidget.h"
#include "playlist.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
SearchWidget::SearchWidget(QWidget *parent, const char *name) : QWidget(parent, name)
{
QHBoxLayout *layout = new QHBoxLayout(this, 5);
layout->setAutoAdd(true);
SearchWidget::SearchWidget(QWidget *parent, const Playlist *playlist, const char *name)
: QWidget(parent, name),
m_playlist(playlist)
new QLabel(i18n("Search:"), this);
m_lineEdit = new KLineEdit(this, "searchLineEdit");
m_caseSensitive = new QCheckBox(i18n("Case sensitive"), this);
{
setupLayout();
slotUpdateColumns();
}
QPushButton *button = new QPushButton(i18n("Clear"), this);
SearchWidget::~SearchWidget()
{
connect(button, SIGNAL(clicked()), this, SLOT(clear()));
connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotQueryChanged()));
connect(m_caseSensitive, SIGNAL(toggled(bool)), this, SLOT(slotQueryChanged()));
setFixedHeight(minimumSizeHint().height());
}
SearchWidget::~SearchWidget()
QString SearchWidget::query() const
{
return m_lineEdit->text();
}
bool SearchWidget::caseSensitive() const
{
return m_caseSensitive->isChecked();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -62,13 +64,68 @@ void SearchWidget::clear()
m_lineEdit->clear();
}
void SearchWidget::slotQueryChanged(int)
{
m_searchedColumns[0].clear();
if(m_searchFieldsBox->currentItem() == 0) {
for(int i = 0; i < m_playlist->columns(); i++) {
if(m_playlist->isColumnVisible(i) && !m_playlist->columnText(i).isEmpty())
m_searchedColumns[0].append(i);
}
}
else
m_searchedColumns[0].append(m_searchFieldsBox->currentItem() - 1);
emit signalQueryChanged(m_lineEdit->text(), m_caseSensitive->isChecked());
}
void SearchWidget::slotUpdateColumns()
{
QString currentText = m_searchFieldsBox->currentText();
m_searchFieldsBox->clear();
m_columnHeaders.clear();
m_columnHeaders.append(QString("<%1>").arg(i18n("All Visible")));
int selection = -1;
for(int i = 0; i < m_playlist->columns(); i++) {
if(m_playlist->isColumnVisible(i) && !m_playlist->columnText(i).isEmpty()) {
QString text = m_playlist->columnText(i);
m_columnHeaders.append(text);
if(currentText == text)
selection = i;
}
}
m_searchFieldsBox->insertStringList(m_columnHeaders);
m_searchFieldsBox->setCurrentItem(selection + 1);
}
////////////////////////////////////////////////////////////////////////////////
// private slots
// private methods
////////////////////////////////////////////////////////////////////////////////
void SearchWidget::slotQueryChanged()
void SearchWidget::setupLayout()
{
emit signalQueryChanged(m_lineEdit->text(), m_caseSensitive->isChecked());
QHBoxLayout *layout = new QHBoxLayout(this, 5);
layout->setAutoAdd(true);
new QLabel(i18n("Search:"), this);
m_searchFieldsBox = new KComboBox(this, "searchFields");
connect(m_searchFieldsBox, SIGNAL(activated(int)), this, SLOT(slotQueryChanged()));
m_lineEdit = new KLineEdit(this, "searchLineEdit");
m_caseSensitive = new QCheckBox(i18n("Case sensitive"), this);
QPushButton *button = new QPushButton(i18n("Clear"), this);
connect(button, SIGNAL(clicked()), this, SLOT(clear()));
connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotQueryChanged()));
connect(m_caseSensitive, SIGNAL(toggled(bool)), this, SLOT(slotQueryChanged()));
setFixedHeight(minimumSizeHint().height());
}
#include "searchwidget.moc"
......@@ -20,29 +20,51 @@
#include <qwidget.h>
class KLineEdit;
class QCheckBox;
class KLineEdit;
class KComboBox;
class Playlist;
class SearchWidget : public QWidget
{
Q_OBJECT
public:
SearchWidget(QWidget *parent, const char *name);
/**
* Note that playlist here is just a playlist to get the columns from and
* has nothing to do with the results of a search.
*/
SearchWidget(QWidget *parent, const Playlist *playlist, const char *name);
virtual ~SearchWidget();
/**
* Returns a list of searched columns for the given search row.
*/
QValueList<int> searchedColumns(int searchLine = 0) { return m_searchedColumns[searchLine]; }
QString query() const;
bool caseSensitive() const;
public slots:
void clear();
void slotUpdateColumns();
void slotQueryChanged(int = 0);
signals:
void signalQueryChanged(const QString &query, bool caseSensitive);
private slots:
void slotQueryChanged();
private:
void setupLayout();
private:
const Playlist *m_playlist;
KLineEdit *m_lineEdit;
KComboBox *m_searchFieldsBox;
QCheckBox *m_caseSensitive;
QStringList m_columnHeaders;
QValueList< QValueList<int> > m_searchedColumns;
} ;
#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