1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "lyricsettings.h"
19
#include "songinfoview.h"
20
#include "ultimatelyricsprovider.h"
21
#include "ui_lyricsettings.h"
25
LyricSettings::LyricSettings(QWidget *parent)
27
ui_(new Ui_LyricSettings),
32
connect(ui_->up, SIGNAL(clicked()), SLOT(MoveUp()));
33
connect(ui_->down, SIGNAL(clicked()), SLOT(MoveDown()));
34
connect(ui_->providers, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
35
SLOT(CurrentItemChanged(QListWidgetItem*)));
36
connect(ui_->providers, SIGNAL(itemChanged(QListWidgetItem*)),
37
SLOT(ItemChanged(QListWidgetItem*)));
40
LyricSettings::~LyricSettings() {
44
void LyricSettings::Load() {
45
QList<const UltimateLyricsProvider*> providers = view_->lyric_providers();
47
ui_->providers->clear();
48
foreach (const UltimateLyricsProvider* provider, providers) {
49
QListWidgetItem* item = new QListWidgetItem(ui_->providers);
50
item->setText(provider->name());
51
item->setCheckState(provider->is_enabled() ? Qt::Checked : Qt::Unchecked);
52
item->setForeground(provider->is_enabled() ? palette().color(QPalette::Active, QPalette::Text)
53
: palette().color(QPalette::Disabled, QPalette::Text));
57
void LyricSettings::Save() {
59
s.beginGroup(SongInfoView::kSettingsGroup);
61
QVariantList search_order;
62
for (int i=0 ; i<ui_->providers->count() ; ++i) {
63
const QListWidgetItem* item = ui_->providers->item(i);
64
if (item->checkState() == Qt::Checked)
65
search_order << item->text();
67
s.setValue("search_order", search_order);
70
void LyricSettings::CurrentItemChanged(QListWidgetItem* item) {
72
ui_->up->setEnabled(false);
73
ui_->down->setEnabled(false);
75
const int row = ui_->providers->row(item);
76
ui_->up->setEnabled(row != 0);
77
ui_->down->setEnabled(row != ui_->providers->count() - 1);
81
void LyricSettings::MoveUp() {
85
void LyricSettings::MoveDown() {
89
void LyricSettings::Move(int d) {
90
const int row = ui_->providers->currentRow();
91
QListWidgetItem* item = ui_->providers->takeItem(row);
92
ui_->providers->insertItem(row + d, item);
93
ui_->providers->setCurrentRow(row + d);
96
void LyricSettings::ItemChanged(QListWidgetItem* item) {
97
const bool checked = item->checkState() == Qt::Checked;
98
item->setForeground(checked ? palette().color(QPalette::Active, QPalette::Text)
99
: palette().color(QPalette::Disabled, QPalette::Text));