2010-10-25 01:46:05 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
Clementine 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 Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
#include "wizard.h"
|
2010-10-25 01:46:05 +02:00
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QVBoxLayout>
|
2010-10-29 20:41:49 +02:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "core/logging.h"
|
|
|
|
#include "querywizardplugin.h"
|
|
|
|
#include "ui_wizardfinishpage.h"
|
|
|
|
#include "wizardplugin.h"
|
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
namespace smart_playlists {
|
2010-10-29 20:41:49 +02:00
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
class Wizard::TypePage : public QWizardPage {
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
|
|
|
TypePage(QWidget* parent) : QWizardPage(parent), next_id_(-1) {}
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
|
|
int nextId() const { return next_id_; }
|
|
|
|
int next_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Wizard::FinishPage : public QWizardPage {
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2010-11-19 00:08:37 +01:00
|
|
|
FinishPage(QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QWizardPage(parent), ui_(new Ui_SmartPlaylistWizardFinishPage) {
|
2010-11-19 00:08:37 +01:00
|
|
|
ui_->setupUi(this);
|
|
|
|
connect(ui_->name, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
~FinishPage() { delete ui_; }
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
|
|
int nextId() const { return -1; }
|
|
|
|
bool isComplete() const { return !ui_->name->text().isEmpty(); }
|
|
|
|
|
|
|
|
Ui_SmartPlaylistWizardFinishPage* ui_;
|
|
|
|
};
|
|
|
|
|
2012-05-30 12:06:25 +02:00
|
|
|
Wizard::Wizard(Application* app, LibraryBackend* library, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QWizard(parent),
|
|
|
|
app_(app),
|
|
|
|
library_(library),
|
|
|
|
type_page_(new TypePage(this)),
|
|
|
|
finish_page_(new FinishPage(this)),
|
2019-11-10 15:07:12 +01:00
|
|
|
type_index_(-1) {
|
2010-11-18 22:13:43 +01:00
|
|
|
setWindowIcon(QIcon(":/icon.png"));
|
|
|
|
setWindowTitle(tr("Smart playlist"));
|
2012-01-15 16:42:12 +01:00
|
|
|
resize(788, 628);
|
2010-11-01 21:24:44 +01:00
|
|
|
|
2012-11-03 23:16:52 +01:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
// MacStyle leaves an ugly empty space on the left side of the dialog.
|
|
|
|
setWizardStyle(QWizard::ClassicStyle);
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // Q_OS_MAC
|
2012-11-03 23:16:52 +01:00
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
// Type page
|
2010-11-18 22:13:43 +01:00
|
|
|
type_page_->setTitle(tr("Playlist type"));
|
2014-02-07 16:34:20 +01:00
|
|
|
type_page_->setSubTitle(
|
|
|
|
tr("A smart playlist is a dynamic list of songs that come from your "
|
|
|
|
"library. There are different types of smart playlist that offer "
|
|
|
|
"different ways of selecting songs."));
|
2010-11-19 00:08:37 +01:00
|
|
|
type_page_->setStyleSheet(
|
2014-02-07 16:34:20 +01:00
|
|
|
"QRadioButton { font-weight: bold; }"
|
|
|
|
"QLabel { margin-bottom: 1em; margin-left: 24px; }");
|
2010-11-18 22:13:43 +01:00
|
|
|
addPage(type_page_);
|
2010-10-29 20:41:49 +02:00
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
// Finish page
|
|
|
|
finish_page_->setTitle(tr("Finish"));
|
|
|
|
finish_page_->setSubTitle(tr("Choose a name for your smart playlist"));
|
|
|
|
finish_id_ = addPage(finish_page_);
|
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
new QVBoxLayout(type_page_);
|
2012-05-30 12:06:25 +02:00
|
|
|
AddPlugin(new QueryWizardPlugin(app_, library_, this));
|
2010-12-04 18:36:10 +01:00
|
|
|
|
|
|
|
// Skip the type page - remove this when we have more than one type
|
|
|
|
setStartId(2);
|
2010-10-29 20:41:49 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
Wizard::~Wizard() { qDeleteAll(plugins_); }
|
2010-11-01 21:24:44 +01:00
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
void Wizard::SetGenerator(GeneratorPtr gen) {
|
|
|
|
// Find the right type and jump to the start page
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < plugins_.count(); ++i) {
|
2010-11-19 00:08:37 +01:00
|
|
|
if (plugins_[i]->type() == gen->type()) {
|
|
|
|
TypeChanged(i);
|
2010-12-04 18:36:10 +01:00
|
|
|
// TODO: Put this back in when the setStartId is removed from the ctor
|
|
|
|
// next();
|
2010-11-19 00:08:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the name
|
|
|
|
finish_page_->ui_->name->setText(gen->name());
|
2010-11-20 19:49:54 +01:00
|
|
|
finish_page_->ui_->dynamic->setChecked(gen->is_dynamic());
|
2020-05-27 21:30:25 +02:00
|
|
|
if (!gen->name().isEmpty()) {
|
|
|
|
setWindowTitle(windowTitle() + " - " + gen->name());
|
|
|
|
}
|
2010-11-19 00:08:37 +01:00
|
|
|
|
2020-01-01 01:21:59 +01:00
|
|
|
if (type_index_ == -1) {
|
|
|
|
qLog(Error) << "Plugin was not found for generator type" << gen->type();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
// Tell the plugin to load
|
|
|
|
plugins_[type_index_]->SetGenerator(gen);
|
|
|
|
}
|
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
void Wizard::AddPlugin(WizardPlugin* plugin) {
|
|
|
|
const int index = plugins_.count();
|
|
|
|
plugins_ << plugin;
|
2010-11-19 00:08:37 +01:00
|
|
|
plugin->Init(this, finish_id_);
|
2010-10-29 20:41:49 +02:00
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
// Create the radio button
|
2010-11-19 00:08:37 +01:00
|
|
|
QRadioButton* radio_button = new QRadioButton(plugin->name(), type_page_);
|
2010-11-18 22:13:43 +01:00
|
|
|
QLabel* description = new QLabel(plugin->description(), type_page_);
|
2010-11-19 00:08:37 +01:00
|
|
|
type_page_->layout()->addWidget(radio_button);
|
2010-11-18 22:13:43 +01:00
|
|
|
type_page_->layout()->addWidget(description);
|
2010-11-03 21:58:33 +01:00
|
|
|
|
2019-11-10 15:16:39 +01:00
|
|
|
connect(radio_button, &QRadioButton::clicked,
|
|
|
|
[this, index]() { TypeChanged(index); });
|
2010-10-29 20:41:49 +02:00
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
if (index == 0) {
|
2010-11-19 00:08:37 +01:00
|
|
|
radio_button->setChecked(true);
|
2010-11-18 22:13:43 +01:00
|
|
|
TypeChanged(0);
|
2010-11-01 21:24:44 +01:00
|
|
|
}
|
2010-10-29 20:41:49 +02:00
|
|
|
}
|
2010-11-03 21:58:33 +01:00
|
|
|
|
2010-11-18 22:13:43 +01:00
|
|
|
void Wizard::TypeChanged(int index) {
|
2010-11-19 00:08:37 +01:00
|
|
|
type_index_ = index;
|
|
|
|
type_page_->next_id_ = plugins_[type_index_]->start_page();
|
|
|
|
}
|
|
|
|
|
|
|
|
GeneratorPtr Wizard::CreateGenerator() const {
|
|
|
|
GeneratorPtr ret;
|
2014-02-07 16:34:20 +01:00
|
|
|
if (type_index_ == -1) return ret;
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
|
|
ret = plugins_[type_index_]->CreateGenerator();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!ret) return ret;
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
|
|
ret->set_name(finish_page_->ui_->name->text());
|
2010-11-20 19:49:54 +01:00
|
|
|
ret->set_dynamic(finish_page_->ui_->dynamic->isChecked());
|
2010-11-19 00:08:37 +01:00
|
|
|
return ret;
|
2010-11-03 21:58:33 +01:00
|
|
|
}
|
2010-11-18 21:19:33 +01:00
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
void Wizard::initializePage(int id) {
|
|
|
|
if (id == finish_id_) {
|
|
|
|
finish_page_->ui_->dynamic_container->setEnabled(
|
2014-02-07 16:34:20 +01:00
|
|
|
plugins_[type_index_]->is_dynamic());
|
2010-11-20 19:49:54 +01:00
|
|
|
}
|
|
|
|
QWizard::initializePage(id);
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
} // namespace smart_playlists
|