/* * QMPDClient - An MPD client written in Qt 4. * Copyright (C) 2005-2007 Håvard Tautra Knutsen * * 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; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "iconmanager.h" #include "mpd.h" #include "mpdconnection.h" #include "mpdoutput.h" #include "mpdsong.h" #include "notifications.h" #include "passivepopup.h" #include "preferencesdialog.h" #include "serverinfo.h" #include "servermodel.h" #include "shortcutmodel.h" #include "tagguesser.h" #include #include #include #include #include #include // Work around bug in Qt 4.2.[0-1]. Remove at a later date (E.g. when the next debian lenny is released) class ItemDelegate : public QItemDelegate { bool eventFilter(QObject *object, QEvent *event) { QWidget *editor = qobject_cast(object); if (!editor) return QItemDelegate::eventFilter(object, event); if (event->type() == QEvent::KeyPress) { switch (static_cast(event)->key()) { case Qt::Key_Enter: case Qt::Key_Return: emit commitData(editor); emit closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); return true; } } return QItemDelegate::eventFilter(object, event); } }; bool versionLessThan(int major, int minor, int patch) { QStringList nrs = QString(qVersion()).split('.'); Q_ASSERT(nrs.size() == 3); bool ok = false; int actualMajor = nrs.at(0).toInt(&ok); Q_ASSERT(ok); int actualMinor = nrs.at(1).toInt(&ok); Q_ASSERT(ok); int actualPatch = nrs.at(2).toInt(&ok); Q_ASSERT(ok); if (actualMajor < major) return true; if (actualMinor < minor) return true; return actualPatch < patch; } class PreferencesDialogPrivate { public: PreferencesDialogPrivate() : config(Config::instance()), mpd(MPD::instance()), connection(MPDConnection::instance()), serverItem(0) {} Config *config; MPD *mpd; MPDConnection *connection; ServerModel *serverModel; QItemSelectionModel *serverSel; QButtonGroup *positionGroup; QTreeWidgetItem *connectionItem, *serverItem, *looknfeelItem; QTreeWidgetItem *directoriesItem, *libraryItem, *playlistItem; QTreeWidgetItem *iconsItem, *localeItem, *dynamicPlaylistItem; QTreeWidgetItem *shortcutsItem, *notificationsItem, *tagguesserItem, *trayIconItem; #if (QT_VERSION >= 0x040300) QTreeWidgetItem *stylesItem; #endif }; #define ASSERT \ Q_ASSERT(d); \ Q_ASSERT(d->config); \ Q_ASSERT(d->mpd); \ Q_ASSERT(d->connection); PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent), d(new PreferencesDialogPrivate) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); ASSERT; splitter->setOpaqueResize(d->config->opaqueResize()); splitter->setStretchFactor(0, 1); splitter->setStretchFactor(1, 10); categoryList->header()->hide(); initCategoryList(); initConnectionPage(); initServerPage(); initLookAndFeelPage(); initIconSetPage(); initLibraryPage(); initDirectoriesPage(); initPlaylistPage(); #if (QT_VERSION >= 0x040300) initStylePage(); #endif initDynamicPlaylistPage(); initLanguagePage(); initNotificationsPage(); initShortcutPage(); initTagGuesserPage(); initTrayIconPage(); updateTranslation(); show(); categoryList->setCurrentItem(d->connectionItem); for (int i = 0; i < d->serverModel->columnCount(); i++) serverList->resizeColumnToContents(i); // set alternating QList children = findChildren(QString()); foreach(QObject *child, children) { if (!child->setProperty("alternatingRowColors", d->config->alternatingRowColors())) qWarning("Couldn't set alternatingRowColors for object: %s", qPrintable(child->objectName())); } } void PreferencesDialog::initCategoryList() { ASSERT; d->connectionItem = new QTreeWidgetItem(categoryList); if (d->connection->isConnected()) d->serverItem = new QTreeWidgetItem(d->connectionItem); d->looknfeelItem = new QTreeWidgetItem(categoryList); d->looknfeelItem->setExpanded(true); d->libraryItem = new QTreeWidgetItem(d->looknfeelItem); d->directoriesItem = new QTreeWidgetItem(d->looknfeelItem); d->playlistItem = new QTreeWidgetItem(d->looknfeelItem); d->iconsItem = new QTreeWidgetItem(d->looknfeelItem); #if (QT_VERSION >= 0x040300) d->stylesItem = new QTreeWidgetItem(d->looknfeelItem); #else widgetStack->removeWidget(stylesPage); delete stylesPage; stylesPage = 0; #endif d->dynamicPlaylistItem = new QTreeWidgetItem(categoryList); d->localeItem = new QTreeWidgetItem(categoryList); d->notificationsItem = new QTreeWidgetItem(categoryList); d->shortcutsItem = new QTreeWidgetItem(categoryList); d->tagguesserItem = new QTreeWidgetItem(categoryList); d->trayIconItem = new QTreeWidgetItem(categoryList); d->trayIconItem->setIcon(0, QIcon(":/icons/qmpdclient16.png")); // Make item-index relations for (int i = 0, index = 0; i < categoryList->topLevelItemCount(); i++, index++) { QTreeWidgetItem *item = categoryList->topLevelItem(i); item->setExpanded(true); item->setData(0, Qt::UserRole, index); for (int j = 0; j < item->childCount(); j++) item->child(j)->setData(0, Qt::UserRole, ++index); } } void PreferencesDialog::initConnectionPage() { ASSERT; serverList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); serverList->verticalHeader()->setDefaultSectionSize(fontMetrics().height()); serverList->verticalHeader()->setResizeMode(QHeaderView::Fixed); serverList->verticalHeader()->hide(); serverList->setModel(d->serverModel = new ServerModel(this)); if (versionLessThan(4, 2, 2)) serverList->setItemDelegate(new ItemDelegate); d->serverSel = serverList->selectionModel(); connect(d->serverSel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(serverSelectionChanged())); d->serverModel->setServers(d->config->servers()); deleteButton->setEnabled(false); upButton->setEnabled(false); downButton->setEnabled(false); autoConnectCheck->setChecked(d->config->autoconnect()); timeoutSpin->setValue(d->config->timeoutTime()); reconnectCheck->setChecked(d->config->reconnect()); reconnectSpin->setValue(d->config->reconnectTime()); connect(autoConnectCheck, SIGNAL(toggled(bool)), d->config, SLOT(setAutoconnect(bool))); connect(timeoutSpin, SIGNAL(valueChanged(int)), d->config, SLOT(setTimeoutTime(int))); connect(reconnectCheck, SIGNAL(toggled(bool)), d->config, SLOT(setReconnect(bool))); connect(reconnectSpin, SIGNAL(valueChanged(int)), d->config, SLOT(setReconnectTime(int))); } void PreferencesDialog::initServerPage() { ASSERT; if (!d->connection->isConnected()) { widgetStack->removeWidget(serverPage); return; } Q_ASSERT(d->serverItem); d->serverItem->setText(0, d->connection->server().name()); crossfadeCheck->setChecked(d->mpd->crossfade() > 0); crossfadeSpin->setValue(d->mpd->crossfade()); foreach(MPDOutput o, d->connection->outputs()) { QTreeWidgetItem *i = new QTreeWidgetItem(outputList, o.id()); i->setText(1, o.name()); i->setCheckState(0, o.enabled() ? Qt::Checked : Qt::Unchecked); } connect(crossfadeCheck, SIGNAL(toggled(bool)), this, SLOT(crossfadeChanged())); connect(crossfadeSpin, SIGNAL(valueChanged(int)), this, SLOT(crossfadeChanged())); connect(outputList, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(outputChanged(QTreeWidgetItem *, int))); } void PreferencesDialog::initLookAndFeelPage() { ASSERT; setFontString(font()); if (d->config->enqueue()) enqueueItemRadio->setChecked(true); else playItemRadio->setChecked(true); if (d->config->filterByAlbumOnly()) filterByAlbumRadio->setChecked(true); else filterByBothRadio->setChecked(true); autoResizeCheck->setChecked(d->config->autoResizeColumns()); opaqueCheck->setChecked(d->config->opaqueResize()); alternatingCheck->setChecked(d->config->alternatingRowColors()); connect(enqueueItemRadio, SIGNAL(toggled(bool)), d->config, SLOT(setEnqueue(bool))); connect(filterByAlbumRadio, SIGNAL(toggled(bool)), d->config, SLOT(setFilterByAlbumOnly(bool))); connect(alternatingCheck, SIGNAL(toggled(bool)), d->config, SLOT(setAlternatingRowColors(bool))); connect(autoResizeCheck, SIGNAL(toggled(bool)), d->config, SLOT(setAutoResizeColumns(bool))); connect(opaqueCheck, SIGNAL(toggled(bool)), d->config, SLOT(setOpaqueResize(bool))); } void PreferencesDialog::initIconSetPage() { ASSERT; updateIconSet(); QDir resourceDir(":/icons"); QDir systemDir(d->config->systemPath() + "iconsets"); QDir localDir(d->config->userPath() + "iconsets"); QFileInfoList icons; if (resourceDir.exists()) icons << resourceDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); if (systemDir.exists()) icons << systemDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); if (localDir.exists()) icons << localDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); QString iconSetPath = d->config->iconSetPath(); QListWidgetItem *selected = 0; foreach(QFileInfo fi, icons) { QString confFileName = fi.absoluteFilePath() + "/iconset.conf"; if (!QFile::exists(confFileName)) continue; QSettings conf(confFileName, QSettings::IniFormat); QString title = conf.value("/Iconset/Name").toString(); if (title.isEmpty()) title = fi.baseName(); QListWidgetItem *item = new QListWidgetItem(title, iconList); item->setData(Qt::UserRole, fi.absoluteFilePath()); if (fi.absoluteFilePath() == iconSetPath) selected = item; } if (selected) iconList->setCurrentItem(selected); connect(iconList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(iconsetChanged(QListWidgetItem *))); } void PreferencesDialog::initLibraryPage() { ASSERT; if (d->config->filterByAlbumOnly()) filterByAlbumRadio->setChecked(true); else filterByBothRadio->setChecked(true); showAllCheck->setChecked(d->config->showAll()); connect(filterByAlbumRadio, SIGNAL(toggled(bool)), d->config, SLOT(setFilterByAlbumOnly(bool))); connect(showAllCheck, SIGNAL(toggled(bool)), d->config, SLOT(setShowAll(bool))); } void PreferencesDialog::initDirectoriesPage() { ASSERT; recursiveViewCheck->setChecked(d->config->recurse()); connect(recursiveViewCheck, SIGNAL(toggled(bool)), d->config, SLOT(setRecurse(bool))); } void PreferencesDialog::initPlaylistPage() { ASSERT; titleFormatLine->setText(d->config->playlistPattern()); centerPlayingCheck->setChecked(d->config->scrollToPlaying()); connect(centerPlayingCheck, SIGNAL(toggled(bool)), d->config, SLOT(setScrollToPlaying(bool))); connect(titleFormatLine, SIGNAL(textChanged(const QString &)), d->config, SLOT(setPlaylistPattern(const QString &))); } #if (QT_VERSION >= 0x040300) void PreferencesDialog::initStylePage() { ASSERT; QDir systemDir(d->config->systemPath() + "styles", "*.css"); QDir localDir(d->config->userPath() + "styles", "*.css"); QFileInfoList styles; if (systemDir.exists()) styles << systemDir.entryInfoList(QDir::Files | QDir::Readable); if (localDir.exists()) styles << localDir.entryInfoList(QDir::Files | QDir::Readable); QString styleFile = d->config->styleFile(); QListWidgetItem *selected = 0; QListWidgetItem *defaultStyle = new QListWidgetItem(tr("Default style"), styleList); if (styleFile.isEmpty()) selected = defaultStyle; foreach(QFileInfo fi, styles) { QListWidgetItem *item = new QListWidgetItem(fi.baseName(), styleList); item->setData(Qt::UserRole, fi.absoluteFilePath()); if (fi.absoluteFilePath() == styleFile) selected = item; } if (selected) styleList->setCurrentItem(selected); connect(styleList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(styleChanged(QListWidgetItem *))); } #endif void PreferencesDialog::initLanguagePage() { ASSERT; translationCheck->setChecked(d->config->translate()); QString localeFile = d->config->locale(); QListWidgetItem *selected = 0; QListWidgetItem *systemLocale = new QListWidgetItem(tr("Use system locale"), localeList); if (localeFile.isEmpty()) selected = systemLocale; // Find all translations QFileInfoList translations; QDir localDir(d->config->userPath() + "translations", "??_??.qm"); if (localDir.exists()) translations << localDir.entryInfoList(QDir::Files | QDir::Readable); QDir systemDir(d->config->systemPath() + "translations", "??_??.qm"); if (systemDir.exists()) translations << systemDir.entryInfoList(QDir::Files | QDir::Readable); foreach(QFileInfo fi, translations) { QListWidgetItem *item = new QListWidgetItem(QLocale::languageToString(QLocale(fi.baseName()).language()), localeList); item->setData(Qt::UserRole, fi.absoluteFilePath()); if (fi.absoluteFilePath() == localeFile) selected = item; } if (selected) localeList->setCurrentItem(selected); connect(translationCheck, SIGNAL(toggled(bool)), d->config, SLOT(setTranslate(bool))); connect(localeList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(localeChanged(QListWidgetItem *))); } void PreferencesDialog::initDynamicPlaylistPage() { ASSERT; autoAddCheck->setChecked(d->config->autoAddSongs()); autoAddCountSpin->setValue(d->config->autoAddCount()); autoAddPosSpin->setValue(d->config->autoAddPos()); autoRemoveCheck->setChecked(d->config->autoRemoveSongs()); connect(autoAddCheck, SIGNAL(toggled(bool)), d->config, SLOT(setAutoAddSongs(bool))); connect(autoAddCountSpin, SIGNAL(valueChanged(int)), d->config, SLOT(setAutoAddCount(int))); connect(autoAddPosSpin, SIGNAL(valueChanged(int)), d->config, SLOT(setAutoAddPos(int))); connect(autoRemoveCheck, SIGNAL(toggled(bool)), d->config, SLOT(setAutoRemoveSongs(bool))); } void PreferencesDialog::initNotificationsPage() { ASSERT; PassivePopup::Position pos = static_cast(d->config->notificationsPosition()); d->positionGroup = new QButtonGroup(this); d->positionGroup->addButton(topLeft, PassivePopup::TopLeft); d->positionGroup->addButton(top, PassivePopup::Top); d->positionGroup->addButton(topRight, PassivePopup::TopRight); d->positionGroup->addButton(right, PassivePopup::Right); d->positionGroup->addButton(bottomRight, PassivePopup::BottomRight); d->positionGroup->addButton(bottom, PassivePopup::Bottom); d->positionGroup->addButton(bottomLeft, PassivePopup::BottomLeft); d->positionGroup->addButton(left, PassivePopup::Left); topLeft->setChecked(pos == PassivePopup::TopLeft); top->setChecked(pos == PassivePopup::Top); topRight->setChecked(pos == PassivePopup::TopRight); right->setChecked(pos == PassivePopup::Right); bottom->setChecked(pos == PassivePopup::Bottom); bottomLeft->setChecked(pos == PassivePopup::BottomLeft); left->setChecked(pos == PassivePopup::Left); bottomRight->setChecked(pos == PassivePopup::BottomRight); notificationsTimeoutSpinner->setValue(d->config->notificationsTimeout()); notificationsCheck->setChecked(d->config->notificationsEnabled()); // Needs to be done here, when buttonGroup is ready int i = 0, idx = 0; foreach(Notifications::Type t, Notifications::notifiers()) { notificationCombo->addItem(Notifications::name(t), t); if (d->config->notifier() == t) idx = i; i++; } connect(notificationCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(notifierChanged(int))); notificationCombo->setCurrentIndex(idx); connect(d->positionGroup, SIGNAL(buttonClicked(int)), d->config, SLOT(setNotificationsPosition(int))); connect(notificationsCheck, SIGNAL(toggled(bool)), d->config, SLOT(setNotificationsEnabled(bool))); connect(notificationsTimeoutSpinner, SIGNAL(valueChanged(int)), d->config, SLOT(setNotificationsTimeout(int))); } void PreferencesDialog::initShortcutPage() { ASSERT; shortcutList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); shortcutList->verticalHeader()->setDefaultSectionSize(fontMetrics().height()); shortcutList->verticalHeader()->setResizeMode(QHeaderView::Fixed); shortcutList->verticalHeader()->hide(); ShortcutModel *model = new ShortcutModel(this); shortcutList->setModel(model); if (versionLessThan(4, 2, 2)) shortcutList->setItemDelegate(new ItemDelegate); } void PreferencesDialog::initTagGuesserPage() { ASSERT; tagGuesserCheck->setChecked(d->config->tagGuesserEnabled()); testLine->setText(d->config->testFilename()); patternLine->setText(d->config->guessPattern()); connect(tagGuesserCheck, SIGNAL(toggled(bool)), d->config, SLOT(setTagGuesserEnabled(bool))); } void PreferencesDialog::initTrayIconPage() { ASSERT; trayIconCheck->setChecked(d->config->trayIconEnabled()); startHiddenCheck->setChecked(d->config->startHidden()); minToTrayCheck->setChecked(d->config->minimizeToTray()); connect(trayIconCheck, SIGNAL(toggled(bool)), d->config, SLOT(setTrayIconEnabled(bool))); connect(minToTrayCheck, SIGNAL(toggled(bool)), d->config, SLOT(setMinimizeToTray(bool))); connect(startHiddenCheck, SIGNAL(toggled(bool)), d->config, SLOT(setStartHidden(bool))); } PreferencesDialog::~PreferencesDialog() { delete d; } void PreferencesDialog::crossfadeChanged() { ASSERT; Q_ASSERT(widgetStack->indexOf(serverPage) > -1); if (crossfadeSpin->value() > 0 && crossfadeCheck->isChecked()) d->mpd->setCrossfade(crossfadeSpin->value()); else d->mpd->setCrossfade(0); } void PreferencesDialog::updateTranslation() { ASSERT; // Save previously selected QTreeWidgetItem *selected = categoryList->currentItem(); retranslateUi(this); Q_ASSERT(d->connectionItem); Q_ASSERT(d->looknfeelItem); Q_ASSERT(d->libraryItem); Q_ASSERT(d->directoriesItem); Q_ASSERT(d->playlistItem); Q_ASSERT(d->iconsItem); Q_ASSERT(d->localeItem); Q_ASSERT(d->dynamicPlaylistItem); Q_ASSERT(d->notificationsItem); Q_ASSERT(d->shortcutsItem); Q_ASSERT(d->tagguesserItem); Q_ASSERT(d->trayIconItem); d->connectionItem->setText(0, tr("Connection")); d->looknfeelItem->setText(0, tr("Look and feel")); d->libraryItem->setText(0, tr("Library")); d->directoriesItem->setText(0, tr("Directories")); d->playlistItem->setText(0, tr("Playlist")); d->iconsItem->setText(0, tr("Icons")); d->localeItem->setText(0, tr("Language")); d->dynamicPlaylistItem->setText(0, tr("Dynamic playlist")); d->notificationsItem->setText(0, tr("Notifications")); d->shortcutsItem->setText(0, tr("Shortcuts")); d->tagguesserItem->setText(0, tr("Tag guesser")); d->trayIconItem->setText(0, tr("Tray icon")); categoryList->setCurrentItem(selected); QString help = ""; help += QString("").arg(tr("Title")).arg(tr("Date")); help += QString("").arg(tr("Artist")).arg(tr("Composer")); help += QString("").arg(tr("Album")).arg(tr("Filename")); help += QString("").arg(tr("Track")).arg(tr("URL")); help += QString("").arg(tr("Genre")); help += "
%t: %1%d: %2
%b: %1%c: %2
%a: %1%f: %2
%n: %1%u: %2
%g: %1
"; titleFormatLabel->setText(help); on_testLine_textChanged(testLine->text()); #if (QT_VERSION >= 0x040300) Q_ASSERT(d->stylesItem); d->stylesItem->setText(0, tr("Styles")); Q_ASSERT(styleList->count() > 0); styleList->item(0)->setText(tr("Default style")); #endif Q_ASSERT(localeList->count() > 0); localeList->item(0)->setText(tr("Use system locale")); } void PreferencesDialog::on_closeButton_clicked() { accept(); close(); } void PreferencesDialog::on_fontButton_clicked() { ASSERT; bool ok; QFont newfont = QFontDialog::getFont(&ok, fontButton->font(), this); if (ok) { d->config->setFont(newfont); setFontString(newfont); } } void PreferencesDialog::setFontString(const QFont &newfont) { QString font = newfont.family(); if (newfont.bold()) font += QString(", %1").arg(tr("bold")); if (newfont.italic()) font += QString(", %1").arg(tr("italic")); font += QString(", %1").arg(newfont.pointSize()); fontLine->setText(font); fontLine->setFont(newfont); } void PreferencesDialog::on_testLine_textChanged(const QString &url) { ASSERT; d->config->setTestFilename(url); if (url.isEmpty()) return; // Create song to guess on. MPDSong song = MPDSong::createTest(url); TagGuesser::guessTags(song); bandLabel->setText(QString("%1: %2").arg(tr("Artist")).arg(song.artist())); albumLabel->setText(QString("%1: %2").arg(tr("Album")).arg(song.album())); trackLabel->setText(QString("%1: %2").arg(tr("Track")).arg(song.track())); titleLabel->setText(QString("%1: %2").arg(tr("Title")).arg(song.title())); } void PreferencesDialog::on_patternLine_textChanged(const QString &pattern) { ASSERT; d->config->setGuessPattern(pattern); if (pattern.isEmpty()) return; on_testLine_textChanged(testLine->text()); } void PreferencesDialog::on_categoryList_currentItemChanged(QTreeWidgetItem *c, QTreeWidgetItem *) { if (!c) return; ASSERT; widgetStack->setCurrentIndex(c->data(0, Qt::UserRole).toInt()); currentLabel->setText("

" + c->text(0) + "

"); } void PreferencesDialog::on_addButton_clicked() { ASSERT; Q_ASSERT(d->serverModel); d->serverModel->setServers(d->serverModel->servers() << ServerInfo("New server")); d->config->setServers(d->serverModel->servers()); } void PreferencesDialog::on_deleteButton_clicked() { ASSERT; Q_ASSERT(d->serverModel); Q_ASSERT(d->serverSel); foreach(QModelIndex sel, d->serverSel->selectedIndexes()) { d->serverModel->deleteServer(sel); d->config->setServers(d->serverModel->servers()); break; } deleteButton->setEnabled(d->serverModel->size() > 1 && !d->serverSel->selectedIndexes().isEmpty()); } void PreferencesDialog::serverSelectionChanged() { ASSERT; Q_ASSERT(d->serverModel); Q_ASSERT(d->serverSel); deleteButton->setEnabled(d->serverModel->size() > 1 && !d->serverSel->selectedIndexes().isEmpty()); foreach(QModelIndex sel, d->serverSel->selectedIndexes()) { upButton->setEnabled(sel.row() > 0); downButton->setEnabled(sel.row() < d->serverModel->size() - 1); return; } upButton->setEnabled(false); downButton->setEnabled(false); } void PreferencesDialog::on_downButton_clicked() { ASSERT; Q_ASSERT(d->serverModel); Q_ASSERT(d->serverSel); foreach(QModelIndex sel, d->serverSel->selectedIndexes()) { if (d->serverModel->moveDown(sel)) { d->serverSel->setCurrentIndex(d->serverModel->index(sel.row() + 1, 0), QItemSelectionModel::Clear); d->serverSel->setCurrentIndex(d->serverModel->index(sel.row() + 1, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows); d->config->setServers(d->serverModel->servers()); } return; } } void PreferencesDialog::on_upButton_clicked() { ASSERT; Q_ASSERT(d->serverModel); Q_ASSERT(d->serverSel); foreach(QModelIndex sel, d->serverSel->selectedIndexes()) { if (d->serverModel->moveUp(sel)) { d->serverSel->setCurrentIndex(d->serverModel->index(sel.row() - 1, 0), QItemSelectionModel::Clear); d->serverSel->setCurrentIndex(d->serverModel->index(sel.row() - 1, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows); d->config->setServers(d->serverModel->servers()); } return; } } void PreferencesDialog::updateIconSet() { ASSERT; d->connectionItem->setIcon(0, IconManager::icon("connect")); if (d->serverItem) d->serverItem->setIcon(0, IconManager::icon("server")); d->looknfeelItem->setIcon(0, IconManager::icon("lookandfeel")); d->libraryItem->setIcon(0, IconManager::icon("library")); d->directoriesItem->setIcon(0, IconManager::icon("directories")); d->playlistItem->setIcon(0, IconManager::icon("playlist")); d->iconsItem->setIcon(0, IconManager::icon("icons")); #if (QT_VERSION >= 0x040300) d->stylesItem->setIcon(0, IconManager::icon("styles")); #endif d->localeItem->setIcon(0, IconManager::icon("language")); d->dynamicPlaylistItem->setIcon(0, IconManager::icon("dynamicplaylist")); d->notificationsItem->setIcon(0, IconManager::icon("notifications")); d->shortcutsItem->setIcon(0, IconManager::icon("shortcuts")); d->tagguesserItem->setIcon(0, IconManager::icon("tagguesser")); } void PreferencesDialog::iconsetChanged(QListWidgetItem *i) { ASSERT; if (!i) return; d->config->setIconSet(i->data(Qt::UserRole).toString()); updateIconSet(); iconLabel->setText(IconManager::description()); } void PreferencesDialog::localeChanged(QListWidgetItem *i) { ASSERT; if (i) d->config->setLocale(i->data(Qt::UserRole).toString()); } void PreferencesDialog::notifierChanged(int index) { int type = notificationCombo->itemData(index).toInt(); d->config->setNotifier(type); bool enable = type == Notifications::CUSTOM; desktopLabel->setEnabled(enable); posLabel->setEnabled(enable); foreach(QAbstractButton *b, d->positionGroup->buttons()) { b->setEnabled(enable); } } void PreferencesDialog::outputChanged(QTreeWidgetItem *i, int col) { ASSERT; if (i && col == 0) d->mpd->toggleOutputDevice(i->type(), i->checkState(0) == Qt::Checked); } void PreferencesDialog::styleChanged(QListWidgetItem *i) { ASSERT; if (i) d->config->setStyleFile(i->data(Qt::UserRole).toString()); }