2011-08-14 01:07:10 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "behavioursettingspage.h"
|
|
|
|
#include "mainwindow.h"
|
2015-01-06 05:33:47 +01:00
|
|
|
#include "core/player.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "ui_behavioursettingspage.h"
|
|
|
|
#include "playlist/playlist.h"
|
2013-07-27 19:59:15 +02:00
|
|
|
#include "playlist/playlisttabbar.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
2013-03-18 17:35:54 +01:00
|
|
|
namespace {
|
|
|
|
bool LocaleAwareCompare(const QString& a, const QString& b) {
|
|
|
|
return a.localeAwareCompare(b) < 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog* dialog)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SettingsPage(dialog), ui_(new Ui_BehaviourSettingsPage) {
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_->setupUi(this);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->b_show_tray_icon_, SIGNAL(toggled(bool)),
|
|
|
|
SLOT(ShowTrayIconToggled(bool)));
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
ui_->doubleclick_addmode->setItemData(0, MainWindow::AddBehaviour_Append);
|
|
|
|
ui_->doubleclick_addmode->setItemData(1, MainWindow::AddBehaviour_Load);
|
|
|
|
ui_->doubleclick_addmode->setItemData(2, MainWindow::AddBehaviour_OpenInNew);
|
|
|
|
ui_->doubleclick_addmode->setItemData(3, MainWindow::AddBehaviour_Enqueue);
|
|
|
|
|
|
|
|
ui_->doubleclick_playmode->setItemData(0, MainWindow::PlayBehaviour_Never);
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->doubleclick_playmode->setItemData(1,
|
|
|
|
MainWindow::PlayBehaviour_IfStopped);
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_->doubleclick_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
|
|
|
|
|
|
|
|
ui_->menu_playmode->setItemData(0, MainWindow::PlayBehaviour_Never);
|
|
|
|
ui_->menu_playmode->setItemData(1, MainWindow::PlayBehaviour_IfStopped);
|
|
|
|
ui_->menu_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
|
|
|
|
|
2015-01-06 05:33:47 +01:00
|
|
|
ui_->menu_previousmode->setItemData(0, Player::PreviousBehaviour_DontRestart);
|
|
|
|
ui_->menu_previousmode->setItemData(1, Player::PreviousBehaviour_Restart);
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
// Populate the language combo box. We do this by looking at all the
|
|
|
|
// compiled in translations.
|
|
|
|
QDir dir(":/translations/");
|
|
|
|
QStringList codes(dir.entryList(QStringList() << "*.qm"));
|
|
|
|
QRegExp lang_re("^clementine_(.*).qm$");
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QString& filename : codes) {
|
2011-08-14 01:07:10 +02:00
|
|
|
// The regex captures the "ru" from "clementine_ru.qm"
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!lang_re.exactMatch(filename)) continue;
|
2011-08-14 01:07:10 +02:00
|
|
|
|
2015-01-08 17:22:00 +01:00
|
|
|
QString code = lang_re.cap(1);
|
|
|
|
QString lookup_code = QString(code)
|
|
|
|
.replace("@latin", "_Latn")
|
|
|
|
.replace("_CN", "_Hans_CN")
|
|
|
|
.replace("_TW", "_Hant_TW");
|
|
|
|
QString language_name =
|
|
|
|
QLocale::languageToString(QLocale(lookup_code).language());
|
2013-03-18 17:35:54 +01:00
|
|
|
#if QT_VERSION >= 0x040800
|
2015-01-08 17:22:00 +01:00
|
|
|
QString native_name = QLocale(lookup_code).nativeLanguageName();
|
2013-03-18 17:35:54 +01:00
|
|
|
if (!native_name.isEmpty()) {
|
|
|
|
language_name = native_name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
QString name = QString("%1 (%2)").arg(language_name, code);
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
language_map_[name] = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
language_map_["English (en)"] = "en";
|
|
|
|
|
|
|
|
// Sort the names and show them in the UI
|
|
|
|
QStringList names = language_map_.keys();
|
2013-03-18 17:35:54 +01:00
|
|
|
qStableSort(names.begin(), names.end(), LocaleAwareCompare);
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_->language->addItems(names);
|
|
|
|
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
ui_->b_show_tray_icon_->setEnabled(false);
|
|
|
|
ui_->startup_group_->setEnabled(false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
BehaviourSettingsPage::~BehaviourSettingsPage() { delete ui_; }
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
void BehaviourSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup(MainWindow::kSettingsGroup);
|
|
|
|
ui_->b_show_tray_icon_->setChecked(s.value("showtray", true).toBool());
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->b_keep_running_->setChecked(
|
|
|
|
s.value("keeprunning", ui_->b_show_tray_icon_->isChecked()).toBool());
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_->doubleclick_addmode->setCurrentIndex(ui_->doubleclick_addmode->findData(
|
|
|
|
s.value("doubleclick_addmode", MainWindow::AddBehaviour_Append).toInt()));
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->doubleclick_playmode->setCurrentIndex(
|
|
|
|
ui_->doubleclick_playmode->findData(
|
|
|
|
s.value("doubleclick_playmode", MainWindow::PlayBehaviour_IfStopped)
|
|
|
|
.toInt()));
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_->menu_playmode->setCurrentIndex(ui_->menu_playmode->findData(
|
|
|
|
s.value("menu_playmode", MainWindow::PlayBehaviour_IfStopped).toInt()));
|
|
|
|
|
|
|
|
MainWindow::StartupBehaviour behaviour = MainWindow::StartupBehaviour(
|
|
|
|
s.value("startupbehaviour", MainWindow::Startup_Remember).toInt());
|
|
|
|
switch (behaviour) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case MainWindow::Startup_AlwaysHide:
|
|
|
|
ui_->b_always_hide_->setChecked(true);
|
|
|
|
break;
|
|
|
|
case MainWindow::Startup_AlwaysShow:
|
|
|
|
ui_->b_always_show_->setChecked(true);
|
|
|
|
break;
|
|
|
|
case MainWindow::Startup_Remember:
|
|
|
|
ui_->b_remember_->setChecked(true);
|
|
|
|
break;
|
2011-08-14 01:07:10 +02:00
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->resume_after_start_->setChecked(
|
|
|
|
s.value("resume_playback_after_start", false).toBool());
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("General");
|
|
|
|
QString name = language_map_.key(s.value("language").toString());
|
|
|
|
if (name.isEmpty())
|
|
|
|
ui_->language->setCurrentIndex(0);
|
|
|
|
else
|
|
|
|
ui_->language->setCurrentIndex(ui_->language->findText(name));
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->b_grey_out_deleted_->setChecked(
|
|
|
|
s.value("greyoutdeleted", false).toBool());
|
2014-06-23 07:30:02 +02:00
|
|
|
ui_->b_click_edit_inline_->setChecked(
|
|
|
|
s.value("click_edit_inline", true).toBool());
|
2014-08-13 04:48:18 +02:00
|
|
|
|
2014-08-18 17:56:01 +02:00
|
|
|
Playlist::Path path = Playlist::Path(
|
|
|
|
s.value(Playlist::kPathType, Playlist::Path_Automatic).toInt());
|
|
|
|
switch (path) {
|
2014-08-13 04:48:18 +02:00
|
|
|
case Playlist::Path_Automatic:
|
|
|
|
ui_->b_automatic_path->setChecked(true);
|
|
|
|
break;
|
|
|
|
case Playlist::Path_Absolute:
|
|
|
|
ui_->b_absolute_path->setChecked(true);
|
|
|
|
break;
|
|
|
|
case Playlist::Path_Relative:
|
|
|
|
ui_->b_relative_path->setChecked(true);
|
|
|
|
break;
|
2014-10-07 00:23:28 +02:00
|
|
|
case Playlist::Path_Ask_User:
|
|
|
|
ui_->b_ask_path->setChecked(true);
|
2014-08-13 04:48:18 +02:00
|
|
|
}
|
2014-08-18 17:56:01 +02:00
|
|
|
ui_->b_write_metadata->setChecked(
|
|
|
|
s.value(Playlist::kWriteMetadata, true).toBool());
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
2013-07-27 19:59:15 +02:00
|
|
|
|
|
|
|
s.beginGroup(PlaylistTabBar::kSettingsGroup);
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->b_warn_close_playlist_->setChecked(
|
|
|
|
s.value("warn_close_playlist", true).toBool());
|
2013-07-27 19:59:15 +02:00
|
|
|
s.endGroup();
|
2011-08-14 01:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BehaviourSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
MainWindow::StartupBehaviour behaviour = MainWindow::Startup_Remember;
|
2014-02-07 16:34:20 +01:00
|
|
|
if (ui_->b_always_hide_->isChecked())
|
|
|
|
behaviour = MainWindow::Startup_AlwaysHide;
|
|
|
|
if (ui_->b_always_show_->isChecked())
|
|
|
|
behaviour = MainWindow::Startup_AlwaysShow;
|
|
|
|
if (ui_->b_remember_->isChecked()) behaviour = MainWindow::Startup_Remember;
|
2011-08-14 01:07:10 +02:00
|
|
|
|
|
|
|
MainWindow::AddBehaviour doubleclick_addmode = MainWindow::AddBehaviour(
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->doubleclick_addmode->itemData(
|
|
|
|
ui_->doubleclick_addmode->currentIndex())
|
|
|
|
.toInt());
|
2011-08-14 01:07:10 +02:00
|
|
|
MainWindow::PlayBehaviour doubleclick_playmode = MainWindow::PlayBehaviour(
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->doubleclick_playmode->itemData(
|
|
|
|
ui_->doubleclick_playmode->currentIndex())
|
|
|
|
.toInt());
|
2011-08-14 01:07:10 +02:00
|
|
|
MainWindow::PlayBehaviour menu_playmode = MainWindow::PlayBehaviour(
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->menu_playmode->itemData(ui_->menu_playmode->currentIndex()).toInt());
|
2011-08-14 01:07:10 +02:00
|
|
|
|
2015-01-06 05:33:47 +01:00
|
|
|
Player::PreviousBehaviour menu_previousmode = Player::PreviousBehaviour(
|
|
|
|
ui_->menu_previousmode->itemData(ui_->menu_previousmode->currentIndex())
|
|
|
|
.toInt());
|
|
|
|
|
2014-08-13 04:48:18 +02:00
|
|
|
Playlist::Path path = Playlist::Path_Automatic;
|
2014-08-18 16:08:14 +02:00
|
|
|
if (ui_->b_automatic_path->isChecked()) {
|
2014-08-13 04:48:18 +02:00
|
|
|
path = Playlist::Path_Automatic;
|
2014-08-18 17:56:01 +02:00
|
|
|
} else if (ui_->b_absolute_path->isChecked()) {
|
2014-08-13 04:48:18 +02:00
|
|
|
path = Playlist::Path_Absolute;
|
2014-08-18 17:56:01 +02:00
|
|
|
} else if (ui_->b_relative_path->isChecked()) {
|
2014-08-13 04:48:18 +02:00
|
|
|
path = Playlist::Path_Relative;
|
2014-10-07 00:23:28 +02:00
|
|
|
} else if (ui_->b_ask_path->isChecked()) {
|
|
|
|
path = Playlist::Path_Ask_User;
|
2014-08-18 16:08:14 +02:00
|
|
|
}
|
2014-08-13 04:48:18 +02:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
s.beginGroup(MainWindow::kSettingsGroup);
|
|
|
|
s.setValue("showtray", ui_->b_show_tray_icon_->isChecked());
|
|
|
|
s.setValue("keeprunning", ui_->b_keep_running_->isChecked());
|
|
|
|
s.setValue("startupbehaviour", int(behaviour));
|
|
|
|
s.setValue("doubleclick_addmode", doubleclick_addmode);
|
|
|
|
s.setValue("doubleclick_playmode", doubleclick_playmode);
|
|
|
|
s.setValue("menu_playmode", menu_playmode);
|
2014-02-07 16:34:20 +01:00
|
|
|
s.setValue("resume_playback_after_start",
|
|
|
|
ui_->resume_after_start_->isChecked());
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
2015-01-06 05:33:47 +01:00
|
|
|
s.beginGroup(Player::kSettingsGroup);
|
|
|
|
s.setValue("menu_previousmode", menu_previousmode);
|
|
|
|
s.endGroup();
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
s.beginGroup("General");
|
2014-02-07 16:34:20 +01:00
|
|
|
s.setValue("language", language_map_.contains(ui_->language->currentText())
|
|
|
|
? language_map_[ui_->language->currentText()]
|
|
|
|
: QString());
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
|
|
|
s.setValue("greyoutdeleted", ui_->b_grey_out_deleted_->isChecked());
|
2014-06-23 07:30:02 +02:00
|
|
|
s.setValue("click_edit_inline", ui_->b_click_edit_inline_->isChecked());
|
2014-08-18 16:08:14 +02:00
|
|
|
s.setValue(Playlist::kPathType, static_cast<int>(path));
|
2014-08-16 02:52:01 +02:00
|
|
|
s.setValue(Playlist::kWriteMetadata, ui_->b_write_metadata->isChecked());
|
2011-08-14 01:07:10 +02:00
|
|
|
s.endGroup();
|
2013-07-27 19:59:15 +02:00
|
|
|
|
|
|
|
s.beginGroup(PlaylistTabBar::kSettingsGroup);
|
2013-07-28 15:37:02 +02:00
|
|
|
s.setValue("warn_close_playlist", ui_->b_warn_close_playlist_->isChecked());
|
2013-07-27 19:59:15 +02:00
|
|
|
s.endGroup();
|
2011-08-14 01:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BehaviourSettingsPage::ShowTrayIconToggled(bool on) {
|
|
|
|
ui_->b_always_hide_->setEnabled(on);
|
|
|
|
if (!on && ui_->b_always_hide_->isChecked())
|
|
|
|
ui_->b_remember_->setChecked(true);
|
2012-03-26 19:06:37 +02:00
|
|
|
ui_->b_keep_running_->setEnabled(on);
|
|
|
|
ui_->b_keep_running_->setChecked(on);
|
2011-08-14 01:07:10 +02:00
|
|
|
}
|