Unify appearance of lyrics and wikipedia settings.

This commit is contained in:
craig.p.drummond
2013-05-25 12:24:41 +00:00
committed by craig.p.drummond
parent 99e53efd5e
commit ce7df2f020
9 changed files with 228 additions and 282 deletions

View File

@@ -104,7 +104,7 @@ SET( CANTATA_SRCS gui/application.cpp gui/main.cpp gui/initialsettingswizard.cpp
devices/deviceoptions.cpp
context/lyricsettings.cpp context/ultimatelyricsprovider.cpp context/ultimatelyrics.cpp context/lyricsdialog.cpp
context/contextpage.cpp context/view.cpp context/artistview.cpp context/albumview.cpp context/songview.cpp context/contextengine.cpp
context/wikipediaengine.cpp context/wikipediasettings.cpp context/othersettings.cpp context/contextsettings.cpp)
context/wikipediaengine.cpp context/wikipediasettings.cpp context/othersettings.cpp context/contextsettings.cpp context/togglelist.cpp)
SET( CANTATA_MOC_HDRS
gui/initialsettingswizard.h gui/mainwindow.h gui/settings.h gui/covers.h gui/folderpage.h gui/librarypage.h gui/albumspage.h
gui/playlistspage.h gui/serverplaybacksettings.h gui/serversettings.h gui/preferencesdialog.h gui/filesettings.h
@@ -119,7 +119,7 @@ SET( CANTATA_MOC_HDRS
widgets/playqueueview.h widgets/groupedview.h widgets/actionitemdelegate.h widgets/coverwidget.h widgets/volumecontrol.h
widgets/genrecombo.h widgets/toolbar.h
network/networkaccessmanager.h
context/lyricsettings.h context/ultimatelyrics.h context/ultimatelyricsprovider.h context/lyricsdialog.h
context/togglelist.h context/ultimatelyrics.h context/ultimatelyricsprovider.h context/lyricsdialog.h
context/contextpage.h context/artistview.h context/albumview.h context/songview.h context/view.h context/contextengine.h
context/wikipediaengine.h context/wikipediasettings.h context/othersettings.h)
SET( CANTATA_UIS
@@ -128,7 +128,7 @@ SET( CANTATA_UIS
gui/coverdialog.ui
streams/streamspage.ui
dynamic/dynamicpage.ui dynamic/dynamicrule.ui dynamic/dynamicrules.ui
context/lyricsettings.ui context/wikipediasettings.ui context/othersettings.ui
context/togglelist.ui context/othersettings.ui
widgets/itemview.ui)
if (ENABLE_ONLINE_SERVICES)

View File

@@ -26,76 +26,37 @@
#include "ultimatelyrics.h"
#include "ui_lyricsettings.h"
#include "localize.h"
#include "icon.h"
#include "config.h"
#include "settings.h"
LyricSettings::LyricSettings(QWidget *p)
: QWidget(p)
: ToggleList(p)
{
setupUi(this);
connect(up, SIGNAL(clicked()), SLOT(moveUp()));
connect(down, SIGNAL(clicked()), SLOT(moveDown()));
connect(providers, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
SLOT(currentItemChanged(QListWidgetItem*)));
up->setIcon(Icon("arrow-up"));
down->setIcon(Icon("arrow-down"));
label->setText(i18n("Choose the websites you want to use when searching for lyrics."));
}
void LyricSettings::load()
{
const QList<UltimateLyricsProvider *> &lprov=UltimateLyrics::self()->getProviders();
providers->clear();
available->clear();
selected->clear();
foreach (const UltimateLyricsProvider *provider, lprov) {
QListWidgetItem *item = new QListWidgetItem(providers);
QListWidgetItem *item = new QListWidgetItem(provider->isEnabled() ? selected : available);
QString name(provider->getName());
name.replace("(POLISH)", i18n("(Polish Translations)"));
name.replace("(PORTUGUESE)", i18n("(Portuguese Translations)"));
item->setText(name);
item->setData(Qt::UserRole, provider->getName());
item->setCheckState(provider->isEnabled() ? Qt::Checked : Qt::Unchecked);
}
}
void LyricSettings::save()
{
QStringList enabled;
for (int i=0 ; i<providers->count() ; ++i) {
const QListWidgetItem* item = providers->item(i);
if (Qt::Checked==item->checkState()) {
enabled << item->data(Qt::UserRole).toString();
}
for (int i=0; i<selected->count(); ++i) {
enabled.append(selected->item(i)->data(Qt::UserRole).toString());
}
UltimateLyrics::self()->setEnabled(enabled);
}
void LyricSettings::currentItemChanged(QListWidgetItem *item)
{
if (!item) {
up->setEnabled(false);
down->setEnabled(false);
} else {
const int row = providers->row(item);
up->setEnabled(row != 0);
down->setEnabled(row != providers->count() - 1);
}
}
void LyricSettings::moveUp()
{
move(-1);
}
void LyricSettings::moveDown()
{
move(+1);
}
void LyricSettings::move(int d)
{
const int row = providers->currentRow();
QListWidgetItem* item = providers->takeItem(row);
providers->insertItem(row + d, item);
providers->setCurrentRow(row + d);
}

View File

@@ -27,27 +27,19 @@
#include <QWidget>
#include <QStringList>
#include <QList>
#include "ui_lyricsettings.h"
#include "togglelist.h"
class QListWidgetItem;
class UltimateLyricsProvider;
class LyricSettings : public QWidget, private Ui::LyricSettings
class LyricSettings : public ToggleList
{
Q_OBJECT
public:
LyricSettings(QWidget *p);
virtual ~LyricSettings() { }
void load();
void save();
private Q_SLOTS:
void moveUp();
void moveDown();
void move(int d);
void currentItemChanged(QListWidgetItem *item);
};
#endif // LYRICSETTINGS_H

View File

@@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LyricSettings</class>
<widget class="QWidget" name="LyricSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>414</width>
<height>255</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Choose the websites you want to use when searching for lyrics.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="providers">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="up">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="down">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Move Down</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

112
context/togglelist.cpp Normal file
View File

@@ -0,0 +1,112 @@
/*
* Cantata
*
* Copyright (c) 2011-2013 Craig Drummond <craig.p.drummond@gmail.com>
*
* ----
*
* 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 Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "togglelist.h"
#include "localize.h"
#include "icon.h"
#include "settings.h"
ToggleList::ToggleList(QWidget *p)
: QWidget(p)
{
setupUi(this);
connect(upButton, SIGNAL(clicked()), SLOT(moveUp()));
connect(downButton, SIGNAL(clicked()), SLOT(moveDown()));
connect(addButton, SIGNAL(clicked()), SLOT(add()));
connect(removeButton, SIGNAL(clicked()), SLOT(remove()));
connect(available, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(availableChanged(QListWidgetItem*)));
connect(selected, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(selectedChanged(QListWidgetItem*)));
upButton->setIcon(Icon("go-up"));
downButton->setIcon(Icon("go-down"));
addButton->setIcon(Icon("list-add"));
removeButton->setIcon(Icon("list-remove"));
upButton->setEnabled(false);
downButton->setEnabled(false);
addButton->setEnabled(false);
removeButton->setEnabled(false);
}
void ToggleList::moveUp()
{
move(-1);
}
void ToggleList::moveDown()
{
move(+1);
}
void ToggleList::add()
{
int index=available->currentRow();
if (index<0 || index>available->count()) {
return;
}
QListWidgetItem *item = available->takeItem(index);
QListWidgetItem *newItem=new QListWidgetItem(selected);
newItem->setText(item->text());
newItem->setData(Qt::UserRole, item->data(Qt::UserRole));
delete item;
}
void ToggleList::remove()
{
int index=selected->currentRow();
if (index<0 || index>selected->count()) {
return;
}
QListWidgetItem *item = selected->takeItem(index);
QListWidgetItem *newItem=new QListWidgetItem(available);
newItem->setText(item->text());
newItem->setData(Qt::UserRole, item->data(Qt::UserRole));
delete item;
}
void ToggleList::move(int d)
{
const int row = selected->currentRow();
QListWidgetItem *item = selected->takeItem(row);
selected->insertItem(row + d, item);
selected->setCurrentRow(row + d);
}
void ToggleList::availableChanged(QListWidgetItem *item)
{
addButton->setEnabled(item);
}
void ToggleList::selectedChanged(QListWidgetItem *item)
{
if (!item) {
upButton->setEnabled(false);
downButton->setEnabled(false);
removeButton->setEnabled(false);
} else {
const int row = available->row(item);
upButton->setEnabled(row != 0);
downButton->setEnabled(row != available->count() - 1);
}
removeButton->setEnabled(item);
}

48
context/togglelist.h Normal file
View File

@@ -0,0 +1,48 @@
/*
* Cantata
*
* Copyright (c) 2011-2013 Craig Drummond <craig.p.drummond@gmail.com>
*
* ----
*
* 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 Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef TOGGLELIST_H
#define TOGGLELIST_H
#include "ui_togglelist.h"
class Spinner;
class ToggleList : public QWidget, protected Ui::ToggleList
{
Q_OBJECT
public:
ToggleList(QWidget *p);
protected Q_SLOTS:
void moveUp();
void moveDown();
void move(int d);
void add();
void remove();
void availableChanged(QListWidgetItem *item);
void selectedChanged(QListWidgetItem *item);
};
#endif

View File

@@ -1,26 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WikipediaSettings</class>
<widget class="QWidget" name="WikipediaSettings">
<class>ToggleList</class>
<widget class="QWidget" name="ToggleList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>362</height>
<width>391</width>
<height>296</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Choose the wikipedia languages you want to use when searching for artist and album information.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@@ -35,8 +25,8 @@
</property>
</widget>
</item>
<item row="2" column="0" rowspan="6">
<widget class="QListWidget" name="langs">
<item row="2" column="0" rowspan="4">
<widget class="QListWidget" name="available">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@@ -58,8 +48,8 @@
</property>
</spacer>
</item>
<item row="2" column="2" rowspan="6">
<widget class="QListWidget" name="preferredLangs">
<item row="2" column="2" rowspan="4">
<widget class="QListWidget" name="selected">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@@ -68,7 +58,7 @@
</property>
</widget>
</item>
<item row="2" column="3" rowspan="2">
<item row="2" column="3">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -81,48 +71,35 @@
</property>
</spacer>
</item>
<item row="3" column="1" rowspan="2">
<item row="3" column="1">
<widget class="QToolButton" name="addButton">
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="3" rowspan="2">
<item row="3" column="3">
<widget class="QToolButton" name="upButton">
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1" rowspan="2">
<item row="4" column="1">
<widget class="QToolButton" name="removeButton">
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="3">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>73</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="3">
<item row="4" column="3">
<widget class="QToolButton" name="downButton">
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="5" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -135,26 +112,38 @@
</property>
</spacer>
</item>
<item row="8" column="0">
<widget class="QPushButton" name="reload">
<property name="enabled">
<bool>true</bool>
<item row="5" column="3">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>73</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Reload</string>
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>langs</tabstop>
<tabstop>available</tabstop>
<tabstop>addButton</tabstop>
<tabstop>removeButton</tabstop>
<tabstop>preferredLangs</tabstop>
<tabstop>selected</tabstop>
<tabstop>upButton</tabstop>
<tabstop>downButton</tabstop>
<tabstop>reload</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@@ -30,6 +30,7 @@
#include "settings.h"
#include "qtiocompressor/qtiocompressor.h"
#include "utils.h"
#include "action.h"
#include <QNetworkReply>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
@@ -38,32 +39,20 @@
#include <QFile>
static QString localeFile() {
return Utils::configDir(QString(), true)+"wikipedia-langs.xml.gz";
return Utils::configDir(QString(), true)+"wikipedia-available.xml.gz";
}
WikipediaSettings::WikipediaSettings(QWidget *p)
: QWidget(p)
: ToggleList(p)
, loaded(false)
, job(0)
, spinner(0)
{
setupUi(this);
connect(upButton, SIGNAL(clicked()), SLOT(moveUp()));
connect(downButton, SIGNAL(clicked()), SLOT(moveDown()));
connect(reload, SIGNAL(clicked()), SLOT(getLangs()));
connect(addButton, SIGNAL(clicked()), SLOT(add()));
connect(removeButton, SIGNAL(clicked()), SLOT(remove()));
connect(langs, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(currentLangChanged(QListWidgetItem*)));
connect(preferredLangs, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(currentPreferredLangChanged(QListWidgetItem*)));
upButton->setIcon(Icon("go-up"));
downButton->setIcon(Icon("go-down"));
addButton->setIcon(Icon("list-add"));
removeButton->setIcon(Icon("list-remove"));
upButton->setEnabled(false);
downButton->setEnabled(false);
addButton->setEnabled(false);
removeButton->setEnabled(false);
label->setText(i18n("Choose the wikipedia languages you want to use when searching for artist and album information."));
reload=new Action(i18n("Reload"), this);
connect(reload, SIGNAL(triggered(bool)), this, SLOT(getLangs()));
available->addAction(reload);
available->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void WikipediaSettings::showEvent(QShowEvent *e)
@@ -100,8 +89,8 @@ void WikipediaSettings::save()
return;
}
QStringList pref;
for (int i=0; i<preferredLangs->count(); ++i) {
pref.append(preferredLangs->item(i)->data(Qt::UserRole).toString());
for (int i=0; i<selected->count(); ++i) {
pref.append(selected->item(i)->data(Qt::UserRole).toString());
}
if (pref.isEmpty()) {
pref.append("en:en");
@@ -122,12 +111,12 @@ void WikipediaSettings::cancel()
void WikipediaSettings::getLangs()
{
if (!spinner) {
spinner=new Spinner(langs);
spinner->setWidget(langs);
spinner=new Spinner(available);
spinner->setWidget(available);
}
spinner->start();
langs->clear();
preferredLangs->clear();
available->clear();
selected->clear();
reload->setEnabled(false);
cancel();
QUrl url("https://en.wikipedia.org/w/api.php");
@@ -191,7 +180,7 @@ void WikipediaSettings::parseLangs(const QByteArray &data)
QString prefix=a.value(QLatin1String("prefix")).toString();
QString entry=prefix+":"+urlPrefix;
int index=preferred.indexOf(entry);
QListWidgetItem *item = new QListWidgetItem(-1==index ? langs : preferredLangs);
QListWidgetItem *item = new QListWidgetItem(-1==index ? available : selected);
item->setText(QString("[%1] %2").arg(prefix).arg(a.value(QLatin1String("language")).toString()));
item->setData(Qt::UserRole, entry);
if (-1!=index) {
@@ -204,9 +193,9 @@ void WikipediaSettings::parseLangs(const QByteArray &data)
QMap<int, QListWidgetItem *>::ConstIterator it(prefMap.constBegin());
QMap<int, QListWidgetItem *>::ConstIterator end(prefMap.constEnd());
for (; it!=end; ++it) {
int row=preferredLangs->row(it.value());
int row=selected->row(it.value());
if (row!=it.key()) {
preferredLangs->insertItem(it.key(), preferredLangs->takeItem(row));
selected->insertItem(it.key(), selected->takeItem(row));
}
}
@@ -214,66 +203,3 @@ void WikipediaSettings::parseLangs(const QByteArray &data)
spinner->stop();
}
}
void WikipediaSettings::currentLangChanged(QListWidgetItem *item)
{
addButton->setEnabled(item);
}
void WikipediaSettings::currentPreferredLangChanged(QListWidgetItem *item)
{
if (!item) {
upButton->setEnabled(false);
downButton->setEnabled(false);
removeButton->setEnabled(false);
} else {
const int row = langs->row(item);
upButton->setEnabled(row != 0);
downButton->setEnabled(row != langs->count() - 1);
}
removeButton->setEnabled(item);
}
void WikipediaSettings::moveUp()
{
move(-1);
}
void WikipediaSettings::moveDown()
{
move(+1);
}
void WikipediaSettings::add()
{
int index=langs->currentRow();
if (index<0 || index>langs->count()) {
return;
}
QListWidgetItem *item = langs->takeItem(index);
QListWidgetItem *newItem=new QListWidgetItem(preferredLangs);
newItem->setText(item->text());
newItem->setData(Qt::UserRole, item->data(Qt::UserRole));
delete item;
}
void WikipediaSettings::remove()
{
int index=preferredLangs->currentRow();
if (index<0 || index>preferredLangs->count()) {
return;
}
QListWidgetItem *item = preferredLangs->takeItem(index);
QListWidgetItem *newItem=new QListWidgetItem(langs);
newItem->setText(item->text());
newItem->setData(Qt::UserRole, item->data(Qt::UserRole));
delete item;
}
void WikipediaSettings::move(int d)
{
const int row = preferredLangs->currentRow();
QListWidgetItem *item = preferredLangs->takeItem(row);
preferredLangs->insertItem(row + d, item);
preferredLangs->setCurrentRow(row + d);
}

View File

@@ -24,14 +24,14 @@
#ifndef WIKIPEDIA_SETTINGS_H
#define WIKIPEDIA_SETTINGS_H
#include "contextengine.h"
#include "ui_wikipediasettings.h"
#include "togglelist.h"
class QNetworkReply;
class QShowEvent;
class Spinner;
class Action;
class WikipediaSettings : public QWidget, private Ui::WikipediaSettings
class WikipediaSettings : public ToggleList
{
Q_OBJECT
@@ -46,13 +46,6 @@ public:
private Q_SLOTS:
void getLangs();
void parseLangs();
void moveUp();
void moveDown();
void move(int d);
void add();
void remove();
void currentLangChanged(QListWidgetItem *item);
void currentPreferredLangChanged(QListWidgetItem *item);
private:
void parseLangs(const QByteArray &data);
@@ -61,6 +54,7 @@ private:
bool loaded;
QNetworkReply *job;
Spinner *spinner;
Action *reload;
};
#endif