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 "iconloader.h"
|
|
|
|
#include "networkremotesettingspage.h"
|
|
|
|
#include "ui_networkremotesettingspage.h"
|
|
|
|
#include "networkremote/networkremote.h"
|
|
|
|
#include "networkremote/networkremotehelper.h"
|
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
#include <QDesktopServices>
|
2012-12-31 23:37:39 +01:00
|
|
|
#include <QSettings>
|
2013-03-03 13:26:11 +01:00
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QNetworkInterface>
|
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";
|
|
|
|
|
2012-12-31 23:37:39 +01:00
|
|
|
NetworkRemoteSettingsPage::NetworkRemoteSettingsPage(SettingsDialog* dialog)
|
|
|
|
: SettingsPage(dialog),
|
|
|
|
ui_(new Ui_NetworkRemoteSettingsPage)
|
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
setWindowIcon(IconLoader::Load("ipodtouchicon"));
|
2013-07-27 07:27:08 +02:00
|
|
|
|
|
|
|
ui_->play_store->installEventFilter(this);
|
2012-12-31 23:37:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NetworkRemoteSettingsPage::~NetworkRemoteSettingsPage() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2013-07-27 07:27:08 +02:00
|
|
|
bool NetworkRemoteSettingsPage::eventFilter(QObject* object, QEvent* event) {
|
|
|
|
if (object == ui_->play_store &&
|
|
|
|
event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
QDesktopServices::openUrl(QUrl(kPlayStoreUrl));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
ui_->auth_code->setValue(s.value("auth_code", qrand() % 100000).toInt());
|
|
|
|
|
2013-07-12 12:31:27 +02:00
|
|
|
ui_->allow_downloads->setChecked(s.value("allow_downloads", false).toBool());
|
|
|
|
|
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();
|
|
|
|
foreach (const QHostAddress& address, addresses) {
|
|
|
|
// TODO: Add ipv6 support to tinysvcmdns.
|
|
|
|
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
|
|
|
!address.isInSubnet(QHostAddress::parseSubnet("127.0.0.1/8"))) {
|
|
|
|
qLog(Debug) << "IP:" << address.toString();
|
|
|
|
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));
|
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());
|
2012-12-31 23:37:39 +01:00
|
|
|
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
if (NetworkRemoteHelper::Instance()) {
|
|
|
|
NetworkRemoteHelper::Instance()->ReloadSettings();
|
|
|
|
}
|
|
|
|
}
|