Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Expose network proxy settings
Browse files Browse the repository at this point in the history
See #170
  • Loading branch information
ColinDuquesnoy committed Dec 25, 2017
1 parent ca4be93 commit 2973b62
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/MellowPlayer/Domain/Properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

#define CONSTANT_OBJECT_PROPERTY(type, name) \
protected: \
Q_PROPERTY (type name READ name CONSTANT) \
Q_PROPERTY (type* name READ name CONSTANT) \
std::shared_ptr<type> name##_; \
public: \
virtual type* name() const { \
Expand Down
57 changes: 57 additions & 0 deletions lib/MellowPlayer/Infrastructure/Network/NetworkProxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "NetworkProxy.h"

using namespace MellowPlayer::Infrastructure;

NetworkProxy::NetworkProxy(const QVariantMap& rawData): rawData_(rawData)
{
}

bool NetworkProxy::isEnabled() const {
return rawData_["enabled"].toBool();
}

void NetworkProxy::setEnabled(bool value) {
if (isEnabled() != value) {
rawData_["enabled"] = value;
emit enabledChanged();
emit changed();
}
}

QString NetworkProxy::hostName() const
{
return rawData_["hostName"].toString();
}

void NetworkProxy::setHostName(const QString& value)
{
if(hostName() != value){
rawData_["hostName"] = value;
emit hostNameChanged();
emit changed();
}
}

int NetworkProxy::port() const
{
return rawData_["port"].toInt();
}

void NetworkProxy::setPort(int value)
{
if (port() != value) {
rawData_["port"] = value;
emit portChanged();
emit changed();
}
}

QVariantMap NetworkProxy::rawData() const
{
return rawData_;
}

QNetworkProxy NetworkProxy::create() const {
return QNetworkProxy(isEnabled() ? QNetworkProxy::HttpProxy : QNetworkProxy::DefaultProxy,
hostName(), static_cast<quint16 >(port()));
}
42 changes: 42 additions & 0 deletions lib/MellowPlayer/Infrastructure/Network/NetworkProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <MellowPlayer/Domain/Properties.hpp>
#include <QVariantMap>
#include <QtNetwork/QNetworkProxy>

namespace MellowPlayer::Infrastructure
{
class NetworkProxy: public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(QString hostName READ hostName WRITE setHostName NOTIFY hostNameChanged)
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)

public:
NetworkProxy() = default;
NetworkProxy(const QVariantMap& rawData);

bool isEnabled() const;
void setEnabled(bool value);

QString hostName() const;
void setHostName(const QString& hostName);

int port() const;
void setPort(int port);

QNetworkProxy create() const;

QVariantMap rawData() const;

signals:
void changed();
void enabledChanged();
void hostNameChanged();
void portChanged();

private:
QVariantMap rawData_;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
#include <MellowPlayer/Domain/Settings/ISettingsStore.hpp>
#include <MellowPlayer/Domain/StreamingServices/StreamingService.hpp>
#include <MellowPlayer/Domain/Settings/SettingKey.hpp>
#include <MellowPlayer/Infrastructure/Network/NetworkProxy.h>
#include <qfile.h>

using namespace std;
using namespace MellowPlayer::Domain;
using namespace MellowPlayer::Domain;
using namespace MellowPlayer::Infrastructure;
using namespace MellowPlayer::Presentation;

#define DEFAULT_ZOOM_FACTOR 7
Expand All @@ -17,14 +20,19 @@ StreamingServiceViewModel::StreamingServiceViewModel(StreamingService& streaming
IUserScriptFactory& factory,
Players& players,
QObject* parent) :
QObject(parent),
QObject(parent),
networkProxy_(nullptr),
streamingService_(streamingService),
settingsStore_(settingsStore),
player_(players.get(streamingService.name())),
userScriptsViewModel_(streamingService.name(), factory, settingsStore, this),
zoomFactor_(settingsStore_.value(zoomFactorSettingsKey(), 7).toInt())
{

networkProxy_ = make_shared<NetworkProxy>(settingsStore_.value(networkProxySettingsKey()).toMap());
connect(networkProxy_.get(), &NetworkProxy::changed, [&]()
{
settingsStore.setValue(networkProxySettingsKey(), networkProxy()->rawData());
});
}

QString StreamingServiceViewModel::logo() const
Expand Down Expand Up @@ -176,3 +184,7 @@ QString StreamingServiceViewModel::notificationsEnabledSettingsKey() const
{
return streamingService_.name() + "/notificationsEnabled";
}

QString StreamingServiceViewModel::networkProxySettingsKey() const {
return streamingService_.name() + "/networkProxy";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QtCore/QObject>
#include <memory>
#include <MellowPlayer/Domain/Properties.hpp>
#include <MellowPlayer/Presentation/ViewModels/UserScripts/UserScriptsViewModel.hpp>


Expand All @@ -14,6 +15,11 @@ namespace MellowPlayer::Domain
class Players;
}

namespace MellowPlayer::Infrastructure
{
class NetworkProxy;
}

namespace MellowPlayer::Presentation
{
class StreamingServiceViewModel : public QObject
Expand All @@ -32,6 +38,8 @@ namespace MellowPlayer::Presentation
Q_PROPERTY(QObject* userScripts READ userScripts CONSTANT)
Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
CONSTANT_OBJECT_PROPERTY(Infrastructure::NetworkProxy, networkProxy);

public:
StreamingServiceViewModel(Domain::StreamingService& streamingService,
Domain::ISettingsStore& settingsStore,
Expand Down Expand Up @@ -66,6 +74,8 @@ namespace MellowPlayer::Presentation
bool notificationsEnabled() const;
void setNotificationsEnabled(bool value);



public slots:
void setUrl(const QString& newUrl);

Expand All @@ -83,6 +93,7 @@ namespace MellowPlayer::Presentation
QString isEnabledSettingsKey() const;
QString zoomFactorSettingsKey() const;
QString notificationsEnabledSettingsKey() const;
QString networkProxySettingsKey() const;

Domain::StreamingService& streamingService_;
Domain::ISettingsStore& settingsStore_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include <MellowPlayer/Domain/StreamingServices/StreamingService.hpp>
#include <MellowPlayer/Domain/StreamingServices/StreamingServicesController.hpp>
#include <MellowPlayer/Infrastructure/PlatformFilters/TokenizedFilters.hpp>
#include <MellowPlayer/Infrastructure/Network/NetworkProxy.h>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtWebEngine/QtWebEngine>

using namespace MellowPlayer;
using namespace MellowPlayer::Domain;
using namespace MellowPlayer::Domain;
using namespace MellowPlayer::Presentation;
Expand Down Expand Up @@ -229,3 +231,8 @@ StreamingServiceProxyListModel* StreamingServicesViewModel::enabledServices()
{
return &enabledServices_;
}

void StreamingServicesViewModel::initialize(IQmlApplicationEngine &qmlApplicationEngine) {
qRegisterMetaType<Infrastructure::NetworkProxy*>("Infrastructure::NetworkProxy*");
ContextProperty::initialize(qmlApplicationEngine);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace MellowPlayer::Presentation
const QString& authorWebsite, bool allPlatforms, bool linuxPlatform, bool appImagePlatform,
bool osxPlatform, bool windowsPlatform);

void initialize(IQmlApplicationEngine &qmlApplicationEngine) override;

public slots:
void setCurrentService(QObject* value);
void setCurrentIndex(int value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3

Rectangle {
color: _theme.isDark(_theme.background) ? Qt.lighter(_theme.background) : Qt.darker(_theme.background, 1.1)
height: 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2

ItemDelegate {
id: root

property string label: ""
property int value: 0
property int from: 0
property int to: 65535

hoverEnabled: true

RowLayout {
anchors.fill: parent
anchors.leftMargin: 16
anchors.rightMargin: 16
spacing: 12

Label {
text: root.label
enabled: root.enabled
}

Item {
Layout.fillWidth: true
}

SpinBox {
enabled: root.enabled
editable: true
value: root.value
from: root.from
to: root.to

onValueChanged: root.value = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2

ItemDelegate {
id: root

property string label: ""
property string value: ""
property int textFieldPreferredWidth: 320

hoverEnabled: true

RowLayout {
anchors.fill: parent
anchors.leftMargin: 16
anchors.rightMargin: 16
spacing: 12

Label {
text: root.label
enabled: root.enabled
}

Item {
Layout.fillWidth: true
}

TextField {
enabled: root.enabled
selectByMouse: true
text: root.value

onTextChanged: root.value = text;

Layout.preferredWidth: root.textFieldPreferredWidth
}
}
}
Loading

0 comments on commit 2973b62

Please sign in to comment.