2010-09-26 19:04:57 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-09-26 19:04:57 +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/>.
|
|
|
|
*/
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "songinfofetcher.h"
|
|
|
|
#include "songinfosettingspage.h"
|
|
|
|
#include "songinfotextview.h"
|
2010-10-10 18:46:35 +02:00
|
|
|
#include "songinfoview.h"
|
|
|
|
#include "ultimatelyricsprovider.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "ui_songinfosettingspage.h"
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
#include "ui/settingsdialog.h"
|
2010-09-26 19:04:57 +02:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
#include <QFile>
|
2010-09-26 19:04:57 +02:00
|
|
|
#include <QSettings>
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
SongInfoSettingsPage::SongInfoSettingsPage(SettingsDialog* dialog)
|
|
|
|
: SettingsPage(dialog),
|
|
|
|
ui_(new Ui_SongInfoSettingsPage)
|
2010-09-26 19:04:57 +02:00
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
2011-08-14 01:07:10 +02:00
|
|
|
setWindowIcon(IconLoader::Load("view-media-lyrics"));
|
2010-09-26 19:04:57 +02:00
|
|
|
|
|
|
|
connect(ui_->up, SIGNAL(clicked()), SLOT(MoveUp()));
|
|
|
|
connect(ui_->down, SIGNAL(clicked()), SLOT(MoveDown()));
|
|
|
|
connect(ui_->providers, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
|
|
|
|
SLOT(CurrentItemChanged(QListWidgetItem*)));
|
|
|
|
connect(ui_->providers, SIGNAL(itemChanged(QListWidgetItem*)),
|
|
|
|
SLOT(ItemChanged(QListWidgetItem*)));
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
QFile song_info_preview(":/lumberjacksong.txt");
|
|
|
|
song_info_preview.open(QIODevice::ReadOnly);
|
|
|
|
ui_->song_info_font_preview->setText(QString::fromUtf8(song_info_preview.readAll()));
|
|
|
|
|
|
|
|
connect(ui_->song_info_font_size, SIGNAL(valueChanged(double)), SLOT(FontSizeChanged(double)));
|
2010-09-26 19:04:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
SongInfoSettingsPage::~SongInfoSettingsPage() {
|
2010-09-26 19:04:57 +02:00
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup(SongInfoTextView::kSettingsGroup);
|
|
|
|
ui_->song_info_font_size->setValue(
|
|
|
|
s.value("font_size", SongInfoTextView::kDefaultFontSize).toReal());
|
|
|
|
ui_->song_info_timeout->setValue(
|
|
|
|
s.value("timeout", SongInfoFetcher::kDefaultTimeoutDuration).toInt());
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
QList<const UltimateLyricsProvider*> providers = dialog()->song_info_view()->lyric_providers();
|
2010-09-26 19:04:57 +02:00
|
|
|
|
|
|
|
ui_->providers->clear();
|
2010-10-10 18:46:35 +02:00
|
|
|
foreach (const UltimateLyricsProvider* provider, providers) {
|
2010-09-26 19:04:57 +02:00
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui_->providers);
|
|
|
|
item->setText(provider->name());
|
|
|
|
item->setCheckState(provider->is_enabled() ? Qt::Checked : Qt::Unchecked);
|
|
|
|
item->setForeground(provider->is_enabled() ? palette().color(QPalette::Active, QPalette::Text)
|
|
|
|
: palette().color(QPalette::Disabled, QPalette::Text));
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
2010-09-26 19:04:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::Save() {
|
2010-10-10 18:46:35 +02:00
|
|
|
QSettings s;
|
2010-09-26 19:04:57 +02:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
s.beginGroup(SongInfoTextView::kSettingsGroup);
|
|
|
|
s.setValue("font_size", ui_->song_info_font_preview->font().pointSizeF());
|
|
|
|
s.setValue("timeout", ui_->song_info_timeout->value());
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup(SongInfoView::kSettingsGroup);
|
2010-09-26 19:04:57 +02:00
|
|
|
QVariantList search_order;
|
|
|
|
for (int i=0 ; i<ui_->providers->count() ; ++i) {
|
|
|
|
const QListWidgetItem* item = ui_->providers->item(i);
|
|
|
|
if (item->checkState() == Qt::Checked)
|
|
|
|
search_order << item->text();
|
|
|
|
}
|
2010-10-10 18:46:35 +02:00
|
|
|
s.setValue("search_order", search_order);
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
2010-09-26 19:04:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::CurrentItemChanged(QListWidgetItem* item) {
|
2010-09-26 19:04:57 +02:00
|
|
|
if (!item) {
|
|
|
|
ui_->up->setEnabled(false);
|
|
|
|
ui_->down->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
const int row = ui_->providers->row(item);
|
|
|
|
ui_->up->setEnabled(row != 0);
|
|
|
|
ui_->down->setEnabled(row != ui_->providers->count() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::MoveUp() {
|
2010-09-26 19:04:57 +02:00
|
|
|
Move(-1);
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::MoveDown() {
|
2010-09-26 19:04:57 +02:00
|
|
|
Move(+1);
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::Move(int d) {
|
2010-09-26 19:04:57 +02:00
|
|
|
const int row = ui_->providers->currentRow();
|
|
|
|
QListWidgetItem* item = ui_->providers->takeItem(row);
|
|
|
|
ui_->providers->insertItem(row + d, item);
|
|
|
|
ui_->providers->setCurrentRow(row + d);
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SongInfoSettingsPage::ItemChanged(QListWidgetItem* item) {
|
2010-09-26 19:04:57 +02:00
|
|
|
const bool checked = item->checkState() == Qt::Checked;
|
|
|
|
item->setForeground(checked ? palette().color(QPalette::Active, QPalette::Text)
|
|
|
|
: palette().color(QPalette::Disabled, QPalette::Text));
|
|
|
|
}
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
void SongInfoSettingsPage::FontSizeChanged(double value) {
|
|
|
|
QFont font;
|
|
|
|
font.setPointSizeF(value);
|
|
|
|
|
|
|
|
ui_->song_info_font_preview->setFont(font);
|
|
|
|
}
|