Commit 647e8ce5 authored by Michael Pyne's avatar Michael Pyne

Cleanup AdvancedSearchPlaylist.

- Port away from K[HV]Box
- Port away from KDialog
- It's been 10 years since you could make a SearchPlaylist from the
track search widget, remove the dead code.

SearchPlaylist still doesn't work but at least there are fewer warnings
and you can at least make it to the AdvancedSearchDialog again.
parent 7fe64d10
/**
* Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org>
* Copyright (C) 2017 Michael Pyne <mpyne@kde.org>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
......@@ -17,17 +18,18 @@
#include "advancedsearchdialog.h"
#include <kcombobox.h>
#include <klineedit.h>
#include <klocale.h>
#include <kvbox.h>
#include <KStandardGuiItem>
#include <QDialogButtonBox>
#include <QRadioButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QLineEdit>
#include "collectionlist.h"
#include "searchwidget.h"
......@@ -38,54 +40,75 @@
AdvancedSearchDialog::AdvancedSearchDialog(const QString &defaultName,
const PlaylistSearch &defaultSearch,
QWidget *parent,
const char *name) :
KDialog(parent)
QWidget *parent) :
QDialog(parent)
{
setCaption( i18n("Create Search Playlist") );
setButtons( Ok|Cancel );
setDefaultButton( Ok );
setObjectName( QLatin1String( name ) );
setModal(true);
setWindowTitle(i18n("Create Search Playlist"));
setObjectName(QStringLiteral("juk_advSrchDlg"));
KVBox *mw = new KVBox(this);
setMainWidget(mw);
auto mw = new QVBoxLayout(this);
setLayout(mw);
KHBox *box = new KHBox(mw);
box->setSpacing(5);
auto box = new QHBoxLayout;
mw->addLayout(box);
new QLabel(i18n("Playlist name:"), box);
m_playlistNameLineEdit = new KLineEdit(defaultName, box);
box->addWidget(new QLabel(i18n("Playlist name:")));
m_playlistNameLineEdit = new QLineEdit(defaultName);
box->addWidget(m_playlistNameLineEdit);
QGroupBox *criteriaGroupBox = new QGroupBox(i18n("Search Criteria"), mw);
mw->setStretchFactor(criteriaGroupBox, 1);
m_criteriaLayout = new QVBoxLayout;
QGroupBox *group = new QGroupBox();
auto criteriaGroupBox = new QGroupBox(i18n("Search Criteria"));
mw->addWidget(criteriaGroupBox, 1);
m_criteriaLayout = new QVBoxLayout(criteriaGroupBox);
auto group = new QGroupBox;
m_matchAnyButton = new QRadioButton(i18n("Match any of the following"));
m_matchAllButton = new QRadioButton(i18n("Match all of the following"));
QHBoxLayout *hgroupbox = new QHBoxLayout;
QHBoxLayout *hgroupbox = new QHBoxLayout(group);
hgroupbox->addWidget(m_matchAnyButton);
hgroupbox->addWidget(m_matchAllButton);
group->setLayout(hgroupbox);
m_criteriaLayout->addWidget(group);
m_criteriaLayout->addStretch(1); // more()/fewer() assume this is here
QWidget *buttons = new QWidget;
mw->addWidget(buttons);
QHBoxLayout *l = new QHBoxLayout(buttons);
l->setSpacing(5);
l->setMargin(0);
const auto &clearGuiItem = KStandardGuiItem::clear();
QPushButton *clearButton = new QPushButton(clearGuiItem.icon(), clearGuiItem.text());
connect(clearButton, &QPushButton::clicked,
this, &AdvancedSearchDialog::clearSearches);
l->addWidget(clearButton);
l->addStretch(1);
m_moreButton = new QPushButton(i18nc("additional search options", "More"));
connect(m_moreButton, &QPushButton::clicked,
this, &AdvancedSearchDialog::more);
l->addWidget(m_moreButton);
m_fewerButton = new QPushButton(i18n("Fewer"));
connect(m_fewerButton, &QPushButton::clicked,
this, &AdvancedSearchDialog::fewer);
l->addWidget(m_fewerButton);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mw->addWidget(buttonBox);
if(defaultSearch.isNull()) {
SearchLine *newSearchLine = new SearchLine(this);
m_searchLines.append(newSearchLine);
m_criteriaLayout->addWidget(newSearchLine);
newSearchLine = new SearchLine(this);
m_searchLines.append(newSearchLine);
m_criteriaLayout->addWidget(newSearchLine);
this->more();
this->more(); // Create first 2 searches
m_matchAnyButton->setChecked(true);
}
else {
PlaylistSearch::ComponentList components = defaultSearch.components();
for(PlaylistSearch::ComponentList::ConstIterator it = components.constBegin();
it != components.constEnd();
++it)
......@@ -93,61 +116,18 @@ AdvancedSearchDialog::AdvancedSearchDialog(const QString &defaultName,
SearchLine *s = new SearchLine(this);
s->setSearchComponent(*it);
m_searchLines.append(s);
m_criteriaLayout->addWidget(s);
m_criteriaLayout->insertWidget(m_criteriaLayout->count() - 1, s);
}
if(defaultSearch.searchMode() == PlaylistSearch::MatchAny)
m_matchAnyButton->setChecked(true);
else
m_matchAllButton->setChecked(true);
}
QWidget *buttons = new QWidget(mw);
QHBoxLayout *l = new QHBoxLayout(buttons);
l->setSpacing(5);
l->setMargin(0);
const auto &clearGuiItem = KStandardGuiItem::clear();
QPushButton *clearButton = new QPushButton(clearGuiItem.icon(), clearGuiItem.text(), buttons);
connect(clearButton, SIGNAL(clicked()), SLOT(clear()));
l->addWidget(clearButton);
l->addStretch(1);
m_moreButton = new QPushButton(i18nc("additional search options", "More"), buttons);
connect(m_moreButton, SIGNAL(clicked()), SLOT(more()));
l->addWidget(m_moreButton);
m_fewerButton = new QPushButton(i18n("Fewer"), buttons);
connect(m_fewerButton, SIGNAL(clicked()), SLOT(fewer()));
l->addWidget(m_fewerButton);
m_criteriaLayout->addStretch(1);
criteriaGroupBox->setLayout(m_criteriaLayout);
m_playlistNameLineEdit->setFocus();
}
AdvancedSearchDialog::~AdvancedSearchDialog()
{
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
//AdvancedSearchDialog::Result AdvancedSearchDialog::exec()
int AdvancedSearchDialog::exec()
{
return 0; // FIXME signal
Result r;
r.result = DialogCode(KDialog::exec());
r.search = m_search;
r.playlistName = m_playlistName;
//return r;
}
////////////////////////////////////////////////////////////////////////////////
// protected slots
////////////////////////////////////////////////////////////////////////////////
......@@ -159,29 +139,28 @@ void AdvancedSearchDialog::accept()
m_search.addPlaylist(CollectionList::instance());
QList<SearchLine *>::const_iterator it = m_searchLines.constBegin();
for(; it != m_searchLines.constEnd(); ++it)
m_search.addComponent((*it)->searchComponent());
for(const auto &searchLine : m_searchLines)
m_search.addComponent(searchLine->searchComponent());
PlaylistSearch::SearchMode m = PlaylistSearch::SearchMode(!m_matchAnyButton->isChecked());
m_search.setSearchMode(m);
m_playlistName = m_playlistNameLineEdit->text();
KDialog::accept();
QDialog::accept();
}
void AdvancedSearchDialog::clear()
void AdvancedSearchDialog::clearSearches()
{
QList<SearchLine *>::const_iterator it = m_searchLines.constBegin();
for(; it != m_searchLines.constEnd(); ++it)
(*it)->clear();
for(auto &searchLine : m_searchLines)
searchLine->clear();
}
void AdvancedSearchDialog::more()
{
SearchLine *searchLine = new SearchLine(this);
m_criteriaLayout->addWidget(searchLine);
// inserting it to keep the trailing stretch item at end
m_criteriaLayout->insertWidget(m_criteriaLayout->count() - 1, searchLine);
m_searchLines.append(searchLine);
searchLine->show();
updateButtons();
......
......@@ -17,46 +17,42 @@
#ifndef ADVANCEDSEARCHDIALOG_H
#define ADVANCEDSEARCHDIALOG_H
#include <kdialog.h>
#include <QDialog>
#include <QList>
#include "playlistsearch.h"
class KLineEdit;
class QLineEdit;
class QPushButton;
class QRadioButton;
class SearchLine;
class QBoxLayout;
class AdvancedSearchDialog : public KDialog
class AdvancedSearchDialog : public QDialog
{
Q_OBJECT
public:
struct Result
{
DialogCode result;
PlaylistSearch search;
QString playlistName;
};
explicit AdvancedSearchDialog(const QString &defaultName,
const PlaylistSearch &defaultSearch = PlaylistSearch(),
QWidget *parent = 0,
const char *name = 0);
AdvancedSearchDialog(
const QString& defaultName,
const PlaylistSearch& defaultSearch = PlaylistSearch(),
QWidget* parent = nullptr);
virtual ~AdvancedSearchDialog();
PlaylistSearch resultSearch() const
{
return m_search;
}
public slots:
// FIXME signal
//Result exec();
int exec();
QString resultPlaylistName() const
{
return m_playlistName;
}
protected slots:
virtual void accept();
virtual void clear();
virtual void more();
virtual void fewer();
void accept() Q_DECL_OVERRIDE;
void clearSearches();
void more();
void fewer();
private:
void updateButtons();
......@@ -65,7 +61,7 @@ private:
PlaylistSearch m_search;
QString m_playlistName;
QList<SearchLine *> m_searchLines;
KLineEdit *m_playlistNameLineEdit;
QLineEdit *m_playlistNameLineEdit;
QRadioButton *m_matchAnyButton;
QRadioButton *m_matchAllButton;
QPushButton *m_moreButton;
......
......@@ -453,18 +453,20 @@ void PlaylistCollection::reload()
void PlaylistCollection::editSearch()
{
SearchPlaylist *p = dynamic_cast<SearchPlaylist *>(visiblePlaylist());
if(!p)
return;
// FIXME signalResult
/*AdvancedSearchDialog::Result r =
AdvancedSearchDialog(p->name(), p->playlistSearch(), JuK::JuKInstance()).exec();
if(r.result == AdvancedSearchDialog::Accepted) {
p->setPlaylistSearch(r.search);
p->setName(r.playlistName);
}*/
auto searchDialog = new AdvancedSearchDialog(
p->name(), p->playlistSearch(), JuK::JuKInstance());
QObject::connect(searchDialog, &QDialog::finished, [searchDialog, p](int result)
{
if (result) {
p->setPlaylistSearch(searchDialog->resultSearch());
p->setName(searchDialog->resultPlaylistName());
}
searchDialog->deleteLater();
});
searchDialog->exec();
}
void PlaylistCollection::removeItems()
......@@ -530,12 +532,19 @@ void PlaylistCollection::createSearchPlaylist()
{
QString name = uniquePlaylistName(i18n("Search Playlist"));
// FIXME signal result
/*AdvancedSearchDialog::Result r =
AdvancedSearchDialog(name, PlaylistSearch(), JuK::JuKInstance()).exec();
if(r.result == AdvancedSearchDialog::Accepted)
raise(new SearchPlaylist(this, r.search, r.playlistName));*/
auto searchDialog = new AdvancedSearchDialog(
name, PlaylistSearch(), JuK::JuKInstance());
QObject::connect(searchDialog, &QDialog::finished, [searchDialog, this](int result)
{
if (result) {
raise(new SearchPlaylist(
this,
searchDialog->resultSearch(),
searchDialog->resultPlaylistName()));
}
searchDialog->deleteLater();
});
searchDialog->exec();
}
void PlaylistCollection::createFolderPlaylist()
......
......@@ -244,8 +244,6 @@ void PlaylistSplitter::setupLayout()
this, SLOT(slotShowSearchResults()));
connect(m_searchWidget, SIGNAL(signalDownPressed()),
this, SLOT(slotFocusCurrentPlaylist()));
connect(m_searchWidget, SIGNAL(signalAdvancedSearchClicked()),
m_playlistBox->object(), SLOT(slotCreateSearchPlaylist()));
connect(m_searchWidget, SIGNAL(signalShown(bool)),
m_playlistBox->object(), SLOT(slotSetSearchEnabled(bool)));
connect(m_searchWidget, SIGNAL(returnPressed()),
......
......@@ -211,14 +211,6 @@ SearchWidget::SearchWidget(QWidget *parent)
connect(&m_searchLine, SIGNAL(signalDownPressed()), this, SIGNAL(signalDownPressed()));
connect(m_searchLine.m_lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
// I've decided that I think this is ugly, for now.
/*
QToolButton *b = new QToolButton(this);
b->setTextLabel(i18n("Advanced Search"), true);
b->setIconSet(SmallIconSet("wizard"));
connect(b, SIGNAL(clicked()), this, SIGNAL(signalAdvancedSearchClicked()));
*/
updateColumns();
}
......
......@@ -89,7 +89,6 @@ public slots:
signals:
void signalQueryChanged();
void signalAdvancedSearchClicked();
void returnPressed();
// This signal is only emitted when the Show/Hide action is triggered.
......
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