2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01: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 "backgroundstreamssettingspage.h"
|
|
|
|
#include "behavioursettingspage.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "config.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "globalshortcutssettingspage.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "iconloader.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "playbacksettingspage.h"
|
|
|
|
#include "networkproxysettingspage.h"
|
|
|
|
#include "notificationssettingspage.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "mainwindow.h"
|
2010-02-03 17:17:04 +01:00
|
|
|
#include "settingsdialog.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "core/backgroundstreams.h"
|
2011-08-14 16:41:47 +02:00
|
|
|
#include "core/logging.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "core/networkproxyfactory.h"
|
2010-04-04 19:50:11 +02:00
|
|
|
#include "engines/enginebase.h"
|
2010-12-26 14:01:35 +01:00
|
|
|
#include "engines/gstengine.h"
|
2011-10-30 19:52:38 +01:00
|
|
|
#include "globalsearch/globalsearchsettingspage.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "internet/digitallyimportedsettingspage.h"
|
2011-09-13 22:32:10 +02:00
|
|
|
#include "internet/groovesharksettingspage.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "internet/magnatunesettingspage.h"
|
|
|
|
#include "library/librarysettingspage.h"
|
2010-08-27 12:36:01 +02:00
|
|
|
#include "playlist/playlistview.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "songinfo/songinfosettingspage.h"
|
|
|
|
#include "transcoder/transcodersettingspage.h"
|
2011-10-30 17:51:43 +01:00
|
|
|
#include "widgets/groupediconview.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "widgets/osdpretty.h"
|
|
|
|
|
2010-12-03 14:53:43 +01:00
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2011-08-14 01:07:10 +02:00
|
|
|
# include "internet/lastfmsettingspage.h"
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-12 22:19:32 +01:00
|
|
|
#ifdef HAVE_WIIMOTEDEV
|
2011-08-14 01:07:10 +02:00
|
|
|
# include "wiimotedev/wiimotesettingspage.h"
|
2010-08-24 21:57:43 +02:00
|
|
|
#endif
|
|
|
|
|
2011-02-17 14:47:54 +01:00
|
|
|
#ifdef HAVE_REMOTE
|
2011-08-14 01:07:10 +02:00
|
|
|
# include "remote/remotesettingspage.h"
|
2011-02-17 14:47:54 +01:00
|
|
|
#endif
|
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
#ifdef HAVE_SPOTIFY
|
2011-08-14 01:07:10 +02:00
|
|
|
# include "internet/spotifysettingspage.h"
|
2011-04-25 21:16:26 +02:00
|
|
|
#endif
|
|
|
|
|
2011-08-14 16:41:47 +02:00
|
|
|
#include <QDesktopWidget>
|
2011-10-30 17:51:43 +01:00
|
|
|
#include <QPainter>
|
2011-08-14 01:07:10 +02:00
|
|
|
#include <QPushButton>
|
2011-08-14 16:41:47 +02:00
|
|
|
#include <QScrollArea>
|
2010-12-03 14:53:43 +01:00
|
|
|
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
SettingsItemDelegate::SettingsItemDelegate(QObject* parent)
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize SettingsItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const {
|
|
|
|
const bool is_separator = index.data(SettingsDialog::Role_IsSeparator).toBool();
|
|
|
|
QSize ret = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
|
|
|
|
if (is_separator) {
|
|
|
|
ret.setHeight(ret.height() * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const {
|
|
|
|
const bool is_separator = index.data(SettingsDialog::Role_IsSeparator).toBool();
|
|
|
|
|
|
|
|
if (is_separator) {
|
|
|
|
GroupedIconView::DrawHeader(painter, option.rect, option.font,
|
|
|
|
option.palette, index.data().toString());
|
|
|
|
} else {
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-03 14:53:43 +01:00
|
|
|
SettingsDialog::SettingsDialog(BackgroundStreams* streams, QWidget* parent)
|
2010-03-25 20:30:10 +01:00
|
|
|
: QDialog(parent),
|
2011-08-14 01:07:10 +02:00
|
|
|
model_(NULL),
|
2010-08-27 15:57:39 +02:00
|
|
|
gst_engine_(NULL),
|
2011-08-14 01:07:10 +02:00
|
|
|
song_info_view_(NULL),
|
|
|
|
streams_(streams),
|
2011-10-30 19:52:38 +01:00
|
|
|
global_search_(NULL),
|
2010-06-09 00:56:31 +02:00
|
|
|
ui_(new Ui_SettingsDialog),
|
2011-08-14 01:07:10 +02:00
|
|
|
loading_settings_(false)
|
2010-02-03 17:17:04 +01:00
|
|
|
{
|
2010-06-09 00:56:31 +02:00
|
|
|
ui_->setupUi(this);
|
2011-10-30 17:51:43 +01:00
|
|
|
ui_->list->setItemDelegate(new SettingsItemDelegate(this));
|
2010-12-18 18:28:02 +01:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
QTreeWidgetItem* general = AddCategory(tr("General"));
|
2010-12-18 18:28:02 +01:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
AddPage(Page_Playback, new PlaybackSettingsPage(this), general);
|
|
|
|
AddPage(Page_Behaviour, new BehaviourSettingsPage(this), general);
|
|
|
|
AddPage(Page_Library, new LibrarySettingsPage(this), general);
|
|
|
|
AddPage(Page_Proxy, new NetworkProxySettingsPage(this), general);
|
|
|
|
AddPage(Page_Transcoding, new TranscoderSettingsPage(this), general);
|
2011-02-17 14:47:54 +01:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
#ifdef HAVE_REMOTE
|
|
|
|
AddPage(Page_Remote, new RemoteSettingsPage(this), general);
|
|
|
|
#endif
|
2011-09-13 22:32:10 +02:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
#ifdef HAVE_WIIMOTEDEV
|
|
|
|
AddPage(Page_Wiimotedev, new WiimoteSettingsPage(this), general);
|
2011-04-25 21:16:26 +02:00
|
|
|
#endif
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
// User interface
|
|
|
|
QTreeWidgetItem* interface = AddCategory(tr("User interface"));
|
|
|
|
AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), interface);
|
2011-10-30 19:52:38 +01:00
|
|
|
AddPage(Page_GlobalSearch, new GlobalSearchSettingsPage(this), interface);
|
2011-10-30 17:51:43 +01:00
|
|
|
AddPage(Page_SongInformation, new SongInfoSettingsPage(this), interface);
|
|
|
|
AddPage(Page_Notifications, new NotificationsSettingsPage(this), interface);
|
2011-02-17 14:47:54 +01:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
// Internet providers
|
|
|
|
QTreeWidgetItem* providers = AddCategory(tr("Internet providers"));
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBLASTFM
|
|
|
|
AddPage(Page_Lastfm, new LastFMSettingsPage(this), providers);
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
AddPage(Page_Grooveshark, new GroovesharkSettingsPage(this), providers);
|
|
|
|
|
|
|
|
#ifdef HAVE_SPOTIFY
|
|
|
|
AddPage(Page_Spotify, new SpotifySettingsPage(this), providers);
|
2010-06-23 18:27:23 +02:00
|
|
|
#endif
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
AddPage(Page_Magnatune, new MagnatuneSettingsPage(this), providers);
|
|
|
|
AddPage(Page_DigitallyImported, new DigitallyImportedSettingsPage(this), providers);
|
|
|
|
AddPage(Page_BackgroundStreams, new BackgroundStreamsSettingsPage(this), providers);
|
|
|
|
|
2010-02-03 18:21:25 +01:00
|
|
|
// List box
|
2011-10-30 17:51:43 +01:00
|
|
|
connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
|
|
|
SLOT(CurrentItemChanged(QTreeWidgetItem*)));
|
|
|
|
ui_->list->setCurrentItem(pages_[Page_Playback].item_);
|
2010-02-03 18:21:25 +01:00
|
|
|
|
2010-05-17 02:47:43 +02:00
|
|
|
// Make sure the list is big enough to show all the items
|
2011-10-30 17:51:43 +01:00
|
|
|
ui_->list->setMinimumWidth(static_cast<QAbstractItemView*>(ui_->list)->sizeHintForColumn(0));
|
2010-06-18 16:21:46 +02:00
|
|
|
|
2010-12-14 18:55:08 +01:00
|
|
|
ui_->buttonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence::Close);
|
2010-03-25 20:30:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog() {
|
2010-06-09 00:56:31 +02:00
|
|
|
delete ui_;
|
2010-02-03 17:17:04 +01:00
|
|
|
}
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
QTreeWidgetItem* SettingsDialog::AddCategory(const QString& name) {
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setData(0, Role_IsSeparator, true);
|
|
|
|
item->setFlags(Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
ui_->list->invisibleRootItem()->addChild(item);
|
|
|
|
item->setExpanded(true);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent) {
|
|
|
|
if (!parent)
|
|
|
|
parent = ui_->list->invisibleRootItem();
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
// Connect page's signals to the settings dialog's signals
|
|
|
|
connect(page, SIGNAL(NotificationPreview(OSD::Behaviour,QString,QString)),
|
|
|
|
SIGNAL(NotificationPreview(OSD::Behaviour,QString,QString)));
|
|
|
|
connect(page, SIGNAL(SetWiimotedevInterfaceActived(bool)),
|
|
|
|
SIGNAL(SetWiimotedevInterfaceActived(bool)));
|
2010-02-03 17:17:04 +01:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
// Create the list item
|
2011-10-30 17:51:43 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
|
|
|
item->setText(0, page->windowTitle());
|
|
|
|
item->setIcon(0, page->windowIcon());
|
|
|
|
item->setData(0, Role_IsSeparator, false);
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
if (!page->IsEnabled()) {
|
|
|
|
item->setFlags(Qt::NoItemFlags);
|
|
|
|
}
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
parent->addChild(item);
|
|
|
|
|
2011-08-14 16:41:47 +02:00
|
|
|
// Create a scroll area containing the page
|
|
|
|
QScrollArea* area = new QScrollArea;
|
|
|
|
area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
area->setWidget(page);
|
|
|
|
area->setWidgetResizable(true);
|
|
|
|
area->setFrameShape(QFrame::NoFrame);
|
2011-08-14 21:19:54 +02:00
|
|
|
area->setMinimumWidth(page->layout()->minimumSize().width());
|
2011-08-14 16:41:47 +02:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
// Add the page to the stack
|
2011-08-14 16:41:47 +02:00
|
|
|
ui_->stacked_widget->addWidget(area);
|
2010-02-03 17:51:56 +01:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
// Remember where the page is
|
|
|
|
PageData data;
|
2011-10-30 17:51:43 +01:00
|
|
|
data.item_ = item;
|
2011-08-14 16:41:47 +02:00
|
|
|
data.scroll_area_ = area;
|
2011-08-14 01:07:10 +02:00
|
|
|
data.page_ = page;
|
|
|
|
pages_[id] = data;
|
2010-06-23 18:27:23 +02:00
|
|
|
}
|
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
void SettingsDialog::accept() {
|
2011-08-14 16:41:47 +02:00
|
|
|
// Save settings
|
2011-08-14 01:07:10 +02:00
|
|
|
foreach (const PageData& data, pages_.values()) {
|
|
|
|
data.page_->Save();
|
|
|
|
}
|
2011-06-27 20:15:55 +02:00
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SettingsDialog::showEvent(QShowEvent* e) {
|
2011-08-14 16:41:47 +02:00
|
|
|
// Load settings
|
2010-03-25 20:30:10 +01:00
|
|
|
loading_settings_ = true;
|
2011-08-14 01:07:10 +02:00
|
|
|
foreach (const PageData& data, pages_.values()) {
|
|
|
|
data.page_->Load();
|
2010-08-27 15:57:39 +02:00
|
|
|
}
|
2010-03-25 20:30:10 +01:00
|
|
|
loading_settings_ = false;
|
|
|
|
|
2011-08-14 16:41:47 +02:00
|
|
|
// Resize the dialog if it's too big
|
|
|
|
const QSize available = QApplication::desktop()->availableGeometry(this).size();
|
|
|
|
if (available.height() < height()) {
|
|
|
|
resize(width(), sizeHint().height());
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
QDialog::showEvent(e);
|
2010-02-03 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void SettingsDialog::OpenAtPage(Page page) {
|
|
|
|
if (!pages_.contains(page)) {
|
2010-03-25 20:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
ui_->list->setCurrentItem(pages_[page].item_);
|
2010-06-09 00:56:31 +02:00
|
|
|
show();
|
2010-04-12 01:03:39 +02:00
|
|
|
}
|
2010-10-10 18:46:35 +02:00
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
void SettingsDialog::CurrentItemChanged(QTreeWidgetItem* item) {
|
|
|
|
if (! (item->flags() & Qt::ItemIsSelectable)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the title
|
|
|
|
ui_->title->setText("<b>" + item->text(0) + "</b>");
|
|
|
|
|
|
|
|
// Display the right page
|
|
|
|
foreach (const PageData& data, pages_.values()) {
|
|
|
|
if (data.item_ == item) {
|
|
|
|
ui_->stacked_widget->setCurrentWidget(data.scroll_area_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-22 23:15:11 +02:00
|
|
|
}
|