Commit 1d3a28fd authored by Scott Wheeler's avatar Scott Wheeler

Added the frontend to the search class that I committed earlier. Wow, that

worked on the first try.  ;-)  Now adding the first version of the dialog.
More features will come shortly, but this version is based on the work of
Richard Laerkaeng, and that's enough for tonight [passes out].

CCMAIL:nouseforaname@home.se

svn path=/trunk/kdemultimedia/juk/; revision=218774
parent 5ce29b54
......@@ -10,7 +10,7 @@ juk_SOURCES = directorylistbase.ui genrelisteditorbase.ui \
genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp \
slideraction.cpp keydialog.cpp juk.cpp main.cpp tagguesser.cpp \
tagguesserconfigdlgwidget.ui tagguesserconfigdlg.cpp jukIface.skel \
playlistsearch.cpp
playlistsearch.cpp searchwidget.cpp
tagguessertest_SOURCES = tagguessertest.cpp tagguesser.cpp
......
......@@ -127,8 +127,12 @@ void JuK::setupActions()
KStdAction::selectAll(this, SLOT(selectAll()), actionCollection());
// view menu
m_showSearchAction = new KToggleAction(i18n("Show &Search Bar"), "filefind", 0, actionCollection(), "showSearch");
connect(m_showSearchAction, SIGNAL(toggled(bool)), m_splitter, SLOT(slotSetSearchVisible(bool)));
m_showEditorAction = new KToggleAction(i18n("Show &Tag Editor"), "edit", 0, actionCollection(), "showEditor");
connect(m_showEditorAction, SIGNAL(toggled(bool)), m_splitter, SLOT(slotSetEditorVisible(bool)));
KStdAction::redisplay(m_splitter, SLOT(slotRefresh()), actionCollection());
actionCollection()->insert(m_splitter->columnVisibleAction());
......@@ -309,6 +313,11 @@ void JuK::readConfig()
}
{ // view settings
KConfigGroupSaver saver(config, "View");
bool showSearch = config->readBoolEntry("ShowSearch", true);
m_showSearchAction->setChecked(showSearch);
m_splitter->slotSetSearchVisible(showSearch);
bool showEditor = config->readBoolEntry("ShowEditor", false);
m_showEditorAction->setChecked(showEditor);
m_splitter->slotSetEditorVisible(showEditor);
......@@ -347,7 +356,9 @@ void JuK::saveConfig()
}
{ // view settings
KConfigGroupSaver saver(config, "View");
config->writeEntry("ShowEditor", m_showEditorAction->isChecked());
config->writeEntry("ShowSearch", m_showSearchAction->isChecked());
}
{ // general settings
KConfigGroupSaver saver(config, "Settings");
......
......@@ -150,6 +150,7 @@ private:
SystemTray *m_systemTray;
// actions
KToggleAction *m_showSearchAction;
KToggleAction *m_showEditorAction;
KToggleAction *m_restoreOnLoadAction;
SliderAction *m_sliderAction;
......
......@@ -25,6 +25,7 @@
<Action name="clear"/>
</Menu>
<Menu name="view" noMerge="1"><text>&amp;View</text>
<Action name="showSearch"/>
<Action name="showEditor"/>
<Action name="showColumns"/>
......@@ -75,6 +76,7 @@
<Separator lineSeparator="true"/>
<Action name="showSearch"/>
<Action name="showEditor"/>
</ToolBar>
......
......@@ -291,7 +291,16 @@ QStringList Playlist::files() const
return list;
}
PlaylistItemList Playlist::items() const
PlaylistItemList Playlist::items()
{
PlaylistItemList list;
for(QListViewItemIterator it(this); it.current(); ++it)
list.append(static_cast<PlaylistItem *>(it.current()));
return list;
}
PlaylistItemList Playlist::visibleItems() const
{
PlaylistItemList list;
for(PlaylistItem *i = static_cast<PlaylistItem *>(firstChild()); i; i = static_cast<PlaylistItem *>(i->itemBelow()))
......@@ -376,6 +385,12 @@ void Playlist::updateLeftColumn()
}
}
void Playlist::setItemsVisible(const PlaylistItemList &items, bool visible)
{
for(PlaylistItemList::ConstIterator it = items.begin(); it != items.end(); ++it)
(*it)->setVisible(visible);
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......
......@@ -71,10 +71,15 @@ public:
*/
QStringList files() const;
/**
* Returns a list of all of the \e visible items in the playlist.
*/
PlaylistItemList items();
/**
* Returns a list of all of the items in the playlist.
*/
PlaylistItemList items() const;
PlaylistItemList visibleItems() const;
/**
* Returns a list of the currently selected items.
......@@ -131,6 +136,8 @@ public:
*/
void updateLeftColumn();
static void setItemsVisible(const PlaylistItemList &items, bool visible = true);
public slots:
/**
* Remove the currently selected items from the playlist and disk.
......
......@@ -67,7 +67,7 @@ public slots:
void clear() {} // override the (destructive) default
signals:
void signalCurrentChanged(const QValueList<Playlist *> &);
void signalCurrentChanged(const PlaylistList &);
void signalDoubleClicked();
private:
......
......@@ -75,7 +75,7 @@ void PlaylistSearch::search()
}
}
PlaylistSearch::Component::Component(const QString &query, const ColumnList &columns, bool caseSensitive) :
PlaylistSearch::Component::Component(const QString &query, bool caseSensitive, const ColumnList &columns) :
m_query(query),
m_columns(columns),
m_searchAllVisible(columns.isEmpty()),
......
/***************************************************************************
playlistsearch.h - description
playlistsearch.h
-------------------
begin : Sun Mar 6 2003
copyright : (C) 2003 by Scott Wheeler
......@@ -65,7 +65,7 @@ public:
/**
* Create a query component. This defaults to searching all visible coulumns.
*/
Component(const QString &query, const ColumnList &columns = ColumnList(), bool caseSensitive = false);
Component(const QString &query, bool caseSensitive = false, const ColumnList &columns = ColumnList());
QString query() const { return m_query; }
ColumnList columns() const { return m_columns; }
......
......@@ -31,6 +31,8 @@
#include "collectionlist.h"
#include "directorylist.h"
#include "playlist.h"
#include "searchwidget.h"
#include "playlistsearch.h"
QStringList *PlaylistSplitter::m_mediaExtensions = 0;
QStringList *PlaylistSplitter::m_listExtensions = 0;
......@@ -216,9 +218,14 @@ void PlaylistSplitter::open(const QString &file)
return;
if(visiblePlaylist() == m_collection ||
KMessageBox::questionYesNo(this, i18n("Do you want to add this item to the current list or to the collection list?"),
QString::null, KGuiItem(i18n("Current")), KGuiItem(i18n("Collection"))) == KMessageBox::No)
KMessageBox::questionYesNo(this,
i18n("Do you want to add this item to the current list or to the collection list?"),
QString::null,
KGuiItem(i18n("Current")),
KGuiItem(i18n("Collection"))) == KMessageBox::No)
{
slotAddToPlaylist(file, m_collection);
}
else
slotAddToPlaylist(file, visiblePlaylist());
}
......@@ -229,9 +236,14 @@ void PlaylistSplitter::open(const QStringList &files)
return;
if(visiblePlaylist() == m_collection ||
KMessageBox::questionYesNo(this, i18n("Do you want to add these items to the current list or to the collection list?"),
QString::null, KGuiItem(i18n("Current")), KGuiItem(i18n("Collection"))) == KMessageBox::No)
KMessageBox::questionYesNo(this,
i18n("Do you want to add these items to the current list or to the collection list?"),
QString::null,
KGuiItem(i18n("Current")),
KGuiItem(i18n("Collection"))) == KMessageBox::No)
{
slotAddToPlaylist(files, m_collection);
}
else
slotAddToPlaylist(files, visiblePlaylist());
}
......@@ -249,8 +261,8 @@ Playlist *PlaylistSplitter::createPlaylist(const QString &name)
void PlaylistSplitter::slotOpen()
{
QStringList files = KFileDialog::getOpenFileNames(QString::null,
extensionsString((*m_mediaExtensions + *m_listExtensions), i18n("Media Files")));
QStringList files = KFileDialog::getOpenFileNames(
QString::null, extensionsString((*m_mediaExtensions + *m_listExtensions), i18n("Media Files")));
open(files);
}
......@@ -261,8 +273,10 @@ void PlaylistSplitter::slotOpenDirectory()
m_directoryQueue.clear();
m_directoryQueueRemove.clear();
connect(l, SIGNAL(signalDirectoryAdded(const QString &)), this, SLOT(slotQueueDirectory(const QString &)));
connect(l, SIGNAL(signalDirectoryRemoved(const QString &)), this, SLOT(slotQueueDirectoryRemove(const QString &)));
connect(l, SIGNAL(signalDirectoryAdded(const QString &)),
this, SLOT(slotQueueDirectory(const QString &)));
connect(l, SIGNAL(signalDirectoryRemoved(const QString &)),
this, SLOT(slotQueueDirectoryRemove(const QString &)));
if(l->exec() == QDialog::Accepted) {
open(m_directoryQueue);
......@@ -270,19 +284,14 @@ void PlaylistSplitter::slotOpenDirectory()
m_dirWatch->addDir(*it, false, true);
m_directoryList += m_directoryQueue;
for(QStringList::Iterator it = m_directoryQueueRemove.begin(); it != m_directoryQueueRemove.end(); it++) {
QStringList::Iterator it = m_directoryQueueRemove.begin();
for(; it != m_directoryQueueRemove.end(); it++) {
m_dirWatch->removeDir(*it);
m_directoryList.remove(*it);
}
}
}
void PlaylistSplitter::slotSetEditorVisible(bool visible)
{
if(visible)
m_editor->show();
else
m_editor->hide();
}
Playlist *PlaylistSplitter::slotCreatePlaylist()
{
......@@ -364,10 +373,14 @@ void PlaylistSplitter::setupLayout()
QSplitter *editorSplitter = new QSplitter(Qt::Vertical, this, "editorSplitter");
// 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);
......@@ -375,8 +388,8 @@ void PlaylistSplitter::setupLayout()
// Make the connection that will update the selected playlist when a
// selection is made in the playlist box.
connect(m_playlistBox, SIGNAL(signalCurrentChanged(const QValueList<Playlist *> &)),
this, SLOT(slotChangePlaylist(const QValueList<Playlist *> &)));
connect(m_playlistBox, SIGNAL(signalCurrentChanged(const PlaylistList &)),
this, SLOT(slotChangePlaylist(const PlaylistList &)));
connect(m_playlistBox, SIGNAL(signalDoubleClicked()), this, SIGNAL(signalListBoxDoubleClicked()));
......@@ -389,7 +402,8 @@ void PlaylistSplitter::setupLayout()
m_collection = CollectionList::instance();
setupPlaylist(m_collection, true, "folder_sound");
connect(m_collection, SIGNAL(signalCollectionChanged()), m_editor, SLOT(slotUpdateCollection()));
connect(m_collection, SIGNAL(signalRequestPlaylistCreation(const QValueList<QFileInfo> &)), this, SLOT(slotCreatePlaylist(const QValueList<QFileInfo> &)));
connect(m_collection, SIGNAL(signalRequestPlaylistCreation(const QValueList<QFileInfo> &)),
this, SLOT(slotCreatePlaylist(const QValueList<QFileInfo> &)));
// Show the collection on startup.
m_playlistBox->setSelected(0, true);
......@@ -433,9 +447,11 @@ void PlaylistSplitter::readConfig()
QTimer::singleShot(0, this, SLOT(slotScanDirectories()));
m_dirWatch = new KDirWatch();
connect(m_dirWatch, SIGNAL(dirty(const QString &)), this, SLOT(slotDirChanged(const QString &)));
connect(m_dirWatch, SIGNAL(dirty(const QString &)),
this, SLOT(slotDirChanged(const QString &)));
for(QStringList::Iterator it = m_directoryList.begin(); it != m_directoryList.end(); ++it)
QStringList::Iterator it = m_directoryList.begin();
for(; it != m_directoryList.end(); ++it)
m_dirWatch->addDir(*it, false, true);
m_dirWatch->startScan();
......@@ -443,9 +459,10 @@ void PlaylistSplitter::readConfig()
// restore the list of hidden and shown columns
if(m_collection)
if(m_collection) {
for(int i = 0; i < m_collection->columns(); i++)
m_columnNames.append(m_collection->columnText(i));
}
}
}
......@@ -507,12 +524,18 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
{
connect(p, SIGNAL(signalSelectionChanged(const PlaylistItemList &)), m_editor, SLOT(slotSetItems(const PlaylistItemList &)));
connect(p, SIGNAL(signalDoubleClicked()), this, SIGNAL(signalDoubleClicked()));
connect(p, SIGNAL(signalNumberOfItemsChanged(Playlist *)), this, SLOT(slotPlaylistCountChanged(Playlist *)));
connect(p, SIGNAL(signalAboutToRemove(PlaylistItem *)), this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *)), this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *)));
connect(p, SIGNAL(signalSetNext(PlaylistItem *)), this, SLOT(slotSetNextItem(PlaylistItem *)));
connect(p, SIGNAL(signalSelectionChanged(const PlaylistItemList &)),
m_editor, SLOT(slotSetItems(const PlaylistItemList &)));
connect(p, SIGNAL(signalDoubleClicked()),
this, SIGNAL(signalDoubleClicked()));
connect(p, SIGNAL(signalNumberOfItemsChanged(Playlist *)),
this, SLOT(slotPlaylistCountChanged(Playlist *)));
connect(p, SIGNAL(signalAboutToRemove(PlaylistItem *)),
this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *)),
this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *)));
connect(p, SIGNAL(signalSetNext(PlaylistItem *)),
this, SLOT(slotSetNextItem(PlaylistItem *)));
m_playlistBox->createItem(p, icon, raise);
......@@ -523,8 +546,13 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
Playlist *PlaylistSplitter::openPlaylist(const QString &file)
{
QFileInfo fileInfo(file);
if(!fileInfo.exists() || !fileInfo.isFile() || !fileInfo.isReadable() || m_playlistFiles.insert(fileInfo.absFilePath()))
if(!fileInfo.exists() ||
!fileInfo.isFile() ||
!fileInfo.isReadable() ||
m_playlistFiles.insert(fileInfo.absFilePath()))
{
return 0;
}
Playlist *p = new Playlist(file, m_playlistStack, fileInfo.baseName(true).latin1());
setupPlaylist(p);
......@@ -551,12 +579,14 @@ QString PlaylistSplitter::play(PlaylistItem *item)
// private slots
////////////////////////////////////////////////////////////////////////////////
void PlaylistSplitter::slotChangePlaylist(const QValueList<Playlist *> &l)
void PlaylistSplitter::slotChangePlaylist(const PlaylistList &l)
{
if(l.isEmpty())
return;
m_nextPlaylistItem = 0;
m_searchWidget->clear();
m_nextPlaylistItem = 0;
m_playlistStack->raiseWidget(l.first());
m_editor->slotSetItems(playlistSelection());
emit signalPlaylistChanged();
......@@ -589,6 +619,26 @@ void PlaylistSplitter::slotCreatePlaylist(const QValueList<QFileInfo> &fileInfos
playlist->createItem(*it);
}
void PlaylistSplitter::slotShowSearchResults(const QString &query, bool caseSensitive)
{
if(query.isEmpty()) {
visiblePlaylist()->setItemsVisible(visiblePlaylist()->items(), true);
return;
}
PlaylistList playlists;
playlists.append(visiblePlaylist());
PlaylistSearch::Component component(query, caseSensitive);
PlaylistSearch::ComponentList components;
components.append(&component);
PlaylistSearch search(playlists, components);
Playlist::setItemsVisible(search.matchedItems(), true);
Playlist::setItemsVisible(search.unmatchedItems(), false);
}
#include "playlistsplitter.moc"
// vim:ts=8
......@@ -28,11 +28,13 @@
#include "collectionlist.h"
#include "stringhash.h"
#include "tageditor.h"
#include "searchwidget.h"
class KActionMenu;
class PlaylistItem;
class KDirWatch;
class PlaylistItem;
/**
* This is the main layout class of JuK. It should contain a PlaylistBox and
* a QWidgetStack of the Playlists.
......@@ -202,7 +204,9 @@ public slots:
/**
* Show or hide the editor.
*/
void slotSetEditorVisible(bool visible);
void slotSetEditorVisible(bool visible) { m_editor->setShown(visible); }
void slotSetSearchVisible(bool visible) { m_searchWidget->clear(); m_searchWidget->setShown(visible); }
/**
* Add the file to the playlist.
......@@ -263,7 +267,7 @@ private:
QString play(PlaylistItem *item);
private slots:
void slotChangePlaylist(const QValueList<Playlist *> &l);
void slotChangePlaylist(const PlaylistList &l);
void slotPlaylistCountChanged(Playlist *p);
/**
* Add a directory to the directory list queue. We need to queue these
......@@ -286,10 +290,12 @@ private slots:
void slotSetNextItem(PlaylistItem *item = 0) { m_nextPlaylistItem = item; }
void slotDirChanged(const QString &dir) { slotAddToPlaylist(dir, m_collection); }
void slotCreatePlaylist(const QValueList<QFileInfo> &fileInfos);
void slotShowSearchResults(const QString &query, bool caseSensitive = false);
private:
PlaylistItem *m_playingItem;
PlaylistBox *m_playlistBox;
SearchWidget *m_searchWidget;
QWidgetStack *m_playlistStack;
TagEditor *m_editor;
......
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