2012-12-31 23:37:39 +01: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 "networkremotesettingspage.h"
|
2018-10-05 17:19:05 +02:00
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
#include <QDesktopServices>
|
2016-02-11 16:11:31 +01:00
|
|
|
#include <QFile>
|
2013-03-03 13:26:11 +01:00
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QNetworkInterface>
|
2016-02-11 16:11:31 +01:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QUrl>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <algorithm>
|
2016-02-11 16:11:31 +01:00
|
|
|
|
2021-04-09 07:58:26 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
|
|
#include <QRandomGenerator>
|
|
|
|
#endif
|
|
|
|
|
2016-02-11 16:11:31 +01:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "networkremote/networkremote.h"
|
|
|
|
#include "networkremote/networkremotehelper.h"
|
|
|
|
#include "transcoder/transcoder.h"
|
|
|
|
#include "transcoder/transcoderoptionsdialog.h"
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
#include "ui/settingsdialog.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "ui_networkremotesettingspage.h"
|
2012-12-31 23:37:39 +01:00
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
const char* NetworkRemoteSettingsPage::kPlayStoreUrl =
|
|
|
|
"https://play.google.com/store/apps/details?id=de.qspool.clementineremote";
|
2020-12-08 19:22:32 +01:00
|
|
|
const char* NetworkRemoteSettingsPage::kPlayStoreUrl2 =
|
|
|
|
"https://play.google.com/store/apps/details?id=fr.mbruel.ClementineRemote";
|
|
|
|
const char* NetworkRemoteSettingsPage::kAppleStoreUrl =
|
|
|
|
"https://apps.apple.com/fr/app/clemremote/id1541922045";
|
|
|
|
const char* NetworkRemoteSettingsPage::kLatestReleasesUrl =
|
|
|
|
"https://github.com/mbruel/ClementineRemote/releases/latest";
|
2013-07-27 07:27:08 +02:00
|
|
|
|
2014-11-13 22:31:49 +01:00
|
|
|
static bool ComparePresetsByName(const TranscoderPreset& left,
|
|
|
|
const TranscoderPreset& right) {
|
|
|
|
return left.name_ < right.name_;
|
|
|
|
}
|
|
|
|
|
2012-12-31 23:37:39 +01:00
|
|
|
NetworkRemoteSettingsPage::NetworkRemoteSettingsPage(SettingsDialog* dialog)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SettingsPage(dialog), ui_(new Ui_NetworkRemoteSettingsPage) {
|
2012-12-31 23:37:39 +01:00
|
|
|
ui_->setupUi(this);
|
2015-10-14 03:01:08 +02:00
|
|
|
setWindowIcon(IconLoader::Load("ipodtouchicon", IconLoader::Base));
|
2013-07-27 07:27:08 +02:00
|
|
|
|
2014-11-13 22:31:49 +01:00
|
|
|
connect(ui_->options, SIGNAL(clicked()), SLOT(Options()));
|
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
ui_->play_store->installEventFilter(this);
|
2020-12-08 19:22:32 +01:00
|
|
|
ui_->play_store_2->installEventFilter(this);
|
|
|
|
ui_->apple_store->installEventFilter(this);
|
|
|
|
ui_->desktop_remote->installEventFilter(this);
|
2014-11-13 22:31:49 +01:00
|
|
|
|
|
|
|
// Get presets
|
|
|
|
QList<TranscoderPreset> presets = Transcoder::GetAllPresets();
|
2018-10-05 17:19:05 +02:00
|
|
|
std::sort(presets.begin(), presets.end(), ComparePresetsByName);
|
2014-11-13 22:31:49 +01:00
|
|
|
for (const TranscoderPreset& preset : presets) {
|
|
|
|
ui_->format->addItem(
|
|
|
|
QString("%1 (.%2)").arg(preset.name_, preset.extension_),
|
|
|
|
QVariant::fromValue(preset));
|
|
|
|
}
|
2012-12-31 23:37:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
NetworkRemoteSettingsPage::~NetworkRemoteSettingsPage() { delete ui_; }
|
2012-12-31 23:37:39 +01:00
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
bool NetworkRemoteSettingsPage::eventFilter(QObject* object, QEvent* event) {
|
2020-12-08 19:22:32 +01:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
QUrl url;
|
|
|
|
if (object == ui_->play_store)
|
|
|
|
url = QUrl(kPlayStoreUrl);
|
|
|
|
else if (object == ui_->play_store_2)
|
|
|
|
url = QUrl(kPlayStoreUrl2);
|
|
|
|
else if (object == ui_->apple_store)
|
|
|
|
url = QUrl(kAppleStoreUrl);
|
|
|
|
else if (object == ui_->desktop_remote)
|
|
|
|
url = QUrl(kLatestReleasesUrl);
|
|
|
|
|
|
|
|
if (!url.isEmpty()) {
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-27 07:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SettingsPage::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
|
2012-12-31 23:37:39 +01:00
|
|
|
void NetworkRemoteSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup(NetworkRemote::kSettingsGroup);
|
|
|
|
|
|
|
|
ui_->use_remote->setChecked(s.value("use_remote").toBool());
|
2013-07-27 07:27:08 +02:00
|
|
|
ui_->remote_port->setValue(
|
|
|
|
s.value("port", NetworkRemote::kDefaultServerPort).toInt());
|
|
|
|
ui_->only_non_public_ip->setChecked(
|
|
|
|
s.value("only_non_public_ip", true).toBool());
|
2012-12-31 23:37:39 +01:00
|
|
|
|
2013-01-23 20:02:12 +01:00
|
|
|
// Auth Code, 5 digits
|
|
|
|
ui_->use_auth_code->setChecked(s.value("use_auth_code", false).toBool());
|
2021-04-09 07:58:26 +02:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
|
2013-01-23 20:02:12 +01:00
|
|
|
ui_->auth_code->setValue(s.value("auth_code", qrand() % 100000).toInt());
|
2021-04-09 07:58:26 +02:00
|
|
|
#else
|
|
|
|
ui_->auth_code->setValue(
|
|
|
|
s.value("auth_code", QRandomGenerator::global()->bounded(100000))
|
|
|
|
.toInt());
|
|
|
|
#endif
|
2013-01-23 20:02:12 +01:00
|
|
|
|
2013-07-12 12:31:27 +02:00
|
|
|
ui_->allow_downloads->setChecked(s.value("allow_downloads", false).toBool());
|
2016-02-11 16:11:31 +01:00
|
|
|
ui_->convert_lossless->setChecked(
|
|
|
|
s.value("convert_lossless", false).toBool());
|
2014-11-13 22:31:49 +01:00
|
|
|
|
|
|
|
// Load settings
|
2016-02-11 16:11:31 +01:00
|
|
|
QString last_output_format =
|
|
|
|
s.value("last_output_format", "audio/x-vorbis").toString();
|
2014-11-13 22:31:49 +01:00
|
|
|
for (int i = 0; i < ui_->format->count(); ++i) {
|
|
|
|
if (last_output_format ==
|
|
|
|
ui_->format->itemData(i).value<TranscoderPreset>().codec_mimetype_) {
|
|
|
|
ui_->format->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 12:31:27 +02:00
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
ui_->files_root_folder->SetPath(s.value("files_root_folder", "").toString());
|
|
|
|
ui_->files_music_extensions->setText(
|
|
|
|
s.value("files_music_extensions",
|
|
|
|
Application::kDefaultMusicExtensionsAllowedRemotely)
|
|
|
|
.toStringList()
|
|
|
|
.join(","));
|
|
|
|
|
2012-12-31 23:37:39 +01:00
|
|
|
s.endGroup();
|
2013-01-22 22:02:16 +01:00
|
|
|
|
2013-03-03 13:26:11 +01:00
|
|
|
// Get local ip addresses
|
|
|
|
QString ip_addresses;
|
|
|
|
QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QHostAddress& address : addresses) {
|
2013-03-03 13:26:11 +01:00
|
|
|
// TODO: Add ipv6 support to tinysvcmdns.
|
|
|
|
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
|
|
|
!address.isInSubnet(QHostAddress::parseSubnet("127.0.0.1/8"))) {
|
|
|
|
if (!ip_addresses.isEmpty()) {
|
2013-07-27 07:27:08 +02:00
|
|
|
ip_addresses.append(", ");
|
2013-03-03 13:26:11 +01:00
|
|
|
}
|
|
|
|
ip_addresses.append(address.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui_->ip_address->setText(ip_addresses);
|
2013-07-27 07:27:08 +02:00
|
|
|
|
|
|
|
// Get the right play store badge for this language.
|
2013-07-27 19:23:55 +02:00
|
|
|
QString language = dialog()->app()->language_without_region();
|
2013-07-27 07:27:08 +02:00
|
|
|
|
|
|
|
QString badge_filename = ":/playstore/" + language + "_generic_rgb_wo_45.png";
|
|
|
|
if (!QFile::exists(badge_filename)) {
|
|
|
|
badge_filename = ":/playstore/en_generic_rgb_wo_45.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_->play_store->setPixmap(QPixmap(badge_filename));
|
2020-12-08 19:22:32 +01:00
|
|
|
ui_->play_store_2->setPixmap(QPixmap(badge_filename));
|
|
|
|
|
|
|
|
ui_->desktop_remote->setText(
|
|
|
|
tr("You can find <a href=\"%1\">here on GitHub</a> the new cross "
|
|
|
|
"platform remote.<br/>It is available on <b>Linux</b>, <b>MacOS</b> "
|
|
|
|
"and <b>Windows</b><br/>")
|
|
|
|
.arg(kLatestReleasesUrl));
|
|
|
|
ui_->desktop_remote->setWordWrap(true);
|
2012-12-31 23:37:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkRemoteSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup(NetworkRemote::kSettingsGroup);
|
|
|
|
s.setValue("port", ui_->remote_port->value());
|
|
|
|
s.setValue("use_remote", ui_->use_remote->isChecked());
|
2013-01-10 21:21:55 +01:00
|
|
|
s.setValue("only_non_public_ip", ui_->only_non_public_ip->isChecked());
|
2013-01-23 20:02:12 +01:00
|
|
|
s.setValue("use_auth_code", ui_->use_auth_code->isChecked());
|
|
|
|
s.setValue("auth_code", ui_->auth_code->value());
|
2013-07-12 12:31:27 +02:00
|
|
|
s.setValue("allow_downloads", ui_->allow_downloads->isChecked());
|
2014-11-13 22:31:49 +01:00
|
|
|
s.setValue("convert_lossless", ui_->convert_lossless->isChecked());
|
|
|
|
|
|
|
|
TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex())
|
|
|
|
.value<TranscoderPreset>();
|
|
|
|
s.setValue("last_output_format", preset.codec_mimetype_);
|
2012-12-31 23:37:39 +01:00
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
s.setValue("files_root_folder", ui_->files_root_folder->Path());
|
|
|
|
|
|
|
|
QStringList files_music_extensions;
|
|
|
|
for (const QString& extension :
|
|
|
|
ui_->files_music_extensions->text().split(",")) {
|
|
|
|
QString ext = extension.trimmed();
|
|
|
|
if (ext.size() > 0 && ext.size() < 8) // no empty string, less than 8 char
|
|
|
|
files_music_extensions << ext;
|
|
|
|
}
|
|
|
|
s.setValue("files_music_extensions", files_music_extensions);
|
|
|
|
|
2012-12-31 23:37:39 +01:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
if (NetworkRemoteHelper::Instance()) {
|
|
|
|
NetworkRemoteHelper::Instance()->ReloadSettings();
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 22:31:49 +01:00
|
|
|
|
|
|
|
void NetworkRemoteSettingsPage::Options() {
|
|
|
|
TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex())
|
|
|
|
.value<TranscoderPreset>();
|
|
|
|
|
2021-01-31 08:34:01 +01:00
|
|
|
TranscoderOptionsDialog dialog(preset, this);
|
2014-11-13 22:31:49 +01:00
|
|
|
dialog.set_settings_postfix(NetworkRemote::kTranscoderSettingPostfix);
|
2021-01-31 09:36:47 +01:00
|
|
|
dialog.exec();
|
2014-11-13 22:31:49 +01:00
|
|
|
}
|