~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/songinfo/lyricsettings.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
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.
8
 
 
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.
13
 
 
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/>.
16
 
*/
17
 
 
18
 
#include "lyricsettings.h"
19
 
#include "songinfoview.h"
20
 
#include "ultimatelyricsprovider.h"
21
 
#include "ui_lyricsettings.h"
22
 
 
23
 
#include <QSettings>
24
 
 
25
 
LyricSettings::LyricSettings(QWidget *parent)
26
 
  : QWidget(parent),
27
 
    ui_(new Ui_LyricSettings),
28
 
    view_(NULL)
29
 
{
30
 
  ui_->setupUi(this);
31
 
 
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*)));
38
 
}
39
 
 
40
 
LyricSettings::~LyricSettings() {
41
 
  delete ui_;
42
 
}
43
 
 
44
 
void LyricSettings::Load() {
45
 
  QList<const UltimateLyricsProvider*> providers = view_->lyric_providers();
46
 
 
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));
54
 
  }
55
 
}
56
 
 
57
 
void LyricSettings::Save() {
58
 
  QSettings s;
59
 
  s.beginGroup(SongInfoView::kSettingsGroup);
60
 
 
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();
66
 
  }
67
 
  s.setValue("search_order", search_order);
68
 
}
69
 
 
70
 
void LyricSettings::CurrentItemChanged(QListWidgetItem* item) {
71
 
  if (!item) {
72
 
    ui_->up->setEnabled(false);
73
 
    ui_->down->setEnabled(false);
74
 
  } else {
75
 
    const int row = ui_->providers->row(item);
76
 
    ui_->up->setEnabled(row != 0);
77
 
    ui_->down->setEnabled(row != ui_->providers->count() - 1);
78
 
  }
79
 
}
80
 
 
81
 
void LyricSettings::MoveUp() {
82
 
  Move(-1);
83
 
}
84
 
 
85
 
void LyricSettings::MoveDown() {
86
 
  Move(+1);
87
 
}
88
 
 
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);
94
 
}
95
 
 
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));
100
 
}