Skip to content

Commit dff0186

Browse files
committed
Use new settings in remote factory
1 parent 326a093 commit dff0186

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

devices/remoteusb2sneswfactory.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ Q_LOGGING_CATEGORY(log_remoteusb2snes, "Remote factory")
66

77
#include "remoteusb2sneswfactory.h"
88
#include "remoteusb2sneswdevice.h"
9+
#include "settings.hpp"
10+
11+
extern Settings* mySettings;
912

1013

1114
RemoteUsb2SnesWFactory::RemoteUsb2SnesWFactory(QObject *parent)
1215
: DeviceFactory{parent}
1316
{
1417
devFacStatus.name = name();
15-
remoteUrl = "ws://192.168.0.37:" + QString::number(USB2SnesWS::defaultPort);
1618
}
1719

1820
QStringList RemoteUsb2SnesWFactory::listDevices()
1921
{
2022
return QStringList();
2123
}
2224

25+
QUrl RemoteUsb2SnesWFactory::remoteUrl()
26+
{
27+
return QUrl("ws://" + mySettings->value<Settings::RemoteHost>() + ":" + QString::number(USB2SnesWS::defaultPort));
28+
}
29+
2330
ADevice* RemoteUsb2SnesWFactory::attach(QString deviceName)
2431
{
2532
if (remote == nullptr)
@@ -44,7 +51,7 @@ ADevice* RemoteUsb2SnesWFactory::attach(QString deviceName)
4451
if (mapLocalNamesToRemoteNames.key(dev) == deviceName)
4552
{
4653
RemoteUsb2snesWDevice* newDev = new RemoteUsb2snesWDevice(mapLocalNamesToRemoteNames[deviceName]);
47-
newDev->createWebsocket(remoteUrl);
54+
newDev->createWebsocket(remoteUrl());
4855
return newDev;
4956
}
5057
}
@@ -168,7 +175,7 @@ void RemoteUsb2SnesWFactory::checkStatus()
168175
remote->deviceList();
169176
} else {
170177
sDebug() << "Attempt to connect to remote";
171-
remote->connectToHost("192.168.0.37", USB2SnesWS::defaultPort);
178+
remote->connectToHost(mySettings->value<Settings::RemoteHost>(), USB2SnesWS::defaultPort);
172179
QTimer::singleShot(100, this, [=] {
173180
if (remote->state() == Usb2Snes::None)
174181
{

devices/remoteusb2sneswfactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class RemoteUsb2SnesWFactory : public DeviceFactory
2929
DeviceFactoryStatus devFacStatus;
3030
void checkFailed(Error::DeviceFactoryError err);
3131
void checkStatus();
32-
QUrl remoteUrl;
3332
void createRemote();
3433
QStringList deviceList;
34+
QUrl remoteUrl();
3535

3636
};
3737

main.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ std::ostream* stdLogStream = nullptr;
6161
WSServer wsServer;
6262
QSettings* globalSettings;
6363

64-
Settings testSettings;
64+
Settings* mySettings;
6565

6666
/*
6767
#include "backward.hpp"
@@ -227,6 +227,8 @@ int main(int ac, char *ag[])
227227
if (!QFile::exists(SQPath::logDirectoryPath()))
228228
QDir().mkdir(SQPath::logDirectoryPath());
229229
//std::filebuf crashFile;
230+
mySettings = new Settings();
231+
mySettings->setValue<Settings::RemoteHost>("192.168.0.27");
230232
#ifndef Q_OS_WIN
231233
globalSettings = new QSettings("nyo.fr", "QUsb2Snes");
232234
#else
@@ -318,10 +320,5 @@ int main(int ac, char *ag[])
318320
});
319321
QTimer::singleShot(100, &startServer);
320322
#endif
321-
qDebug() << std::is_convertible<const char*, std::string>::value;
322-
qDebug() << std::is_convertible<const char*, QString>::value;
323-
testSettings.setValue<Settings::RemoteHost>("PcxikoNyo");
324-
qDebug() << "Settings" << testSettings.value<Settings::RemoteHost>();
325-
//return 1;
326323
return app.exec();
327324
}

settings.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ class Settings : private QSettings
2424
};
2525

2626
public:
27-
explicit Settings(QObject *parent = nullptr) : QSettings("Test.ini", QSettings::IniFormat) {};
27+
#ifndef Q_OS_WIN
28+
explicit Settings(QObject *parent = nullptr) : QSettings("nyo.fr", "QUsb2Snes") {};
29+
#else
30+
explicit Settings(QObject *parent = nullptr) : QSettings("config.ini", QSettings::IniFormat) {};
31+
#endif
2832
~Settings() {};
2933
template<SettingsV key> auto value()
3034
{

ui/appui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void AppUi::init()
154154
wsServer.addTrusted(ori);
155155
}
156156
}
157-
//addRemoteFactory();
157+
addRemoteFactory();
158158
checkForApplications();
159159
connect(qApp, &QCoreApplication::aboutToQuit, this, [=]() {
160160
sysTray->hide();

0 commit comments

Comments
 (0)