mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 13:33:13 -07:00
Add Manual Hosts
This commit is contained in:
parent
5be510aba2
commit
37921d488c
8 changed files with 280 additions and 4 deletions
|
@ -44,7 +44,9 @@ add_executable(chiaki
|
||||||
include/host.h
|
include/host.h
|
||||||
src/host.cpp
|
src/host.cpp
|
||||||
include/settingsdialog.h
|
include/settingsdialog.h
|
||||||
src/settingsdialog.cpp)
|
src/settingsdialog.cpp
|
||||||
|
include/manualhostdialog.h
|
||||||
|
src/manualhostdialog.cpp)
|
||||||
target_include_directories(chiaki PRIVATE include)
|
target_include_directories(chiaki PRIVATE include)
|
||||||
|
|
||||||
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
||||||
|
|
|
@ -78,7 +78,30 @@ class RegisteredHost
|
||||||
static RegisteredHost LoadFromSettings(QSettings *settings);
|
static RegisteredHost LoadFromSettings(QSettings *settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(RegisteredHost)
|
class ManualHost
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int id;
|
||||||
|
QString host;
|
||||||
|
bool registered;
|
||||||
|
HostMAC registered_mac;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ManualHost();
|
||||||
|
ManualHost(int id, const QString &host, bool registered, const HostMAC ®istered_mac);
|
||||||
|
ManualHost(int id, const ManualHost &o);
|
||||||
|
|
||||||
|
int GetID() const { return id; }
|
||||||
|
QString GetHost() const { return host; }
|
||||||
|
bool GetRegistered() const { return registered; }
|
||||||
|
HostMAC GetMAC() const { return registered_mac; }
|
||||||
|
|
||||||
|
void SaveToSettings(QSettings *settings) const;
|
||||||
|
static ManualHost LoadFromSettings(QSettings *settings);
|
||||||
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(HostMAC)
|
Q_DECLARE_METATYPE(HostMAC)
|
||||||
|
Q_DECLARE_METATYPE(RegisteredHost)
|
||||||
|
Q_DECLARE_METATYPE(ManualHost)
|
||||||
|
|
||||||
#endif //CHIAKI_HOST_H
|
#endif //CHIAKI_HOST_H
|
||||||
|
|
54
gui/include/manualhostdialog.h
Normal file
54
gui/include/manualhostdialog.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki 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.
|
||||||
|
*
|
||||||
|
* Chiaki 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 Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHIAKI_MANUALHOSTDIALOG_H
|
||||||
|
#define CHIAKI_MANUALHOSTDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
class Settings;
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
class QComboBox;
|
||||||
|
class QDialogButtonBox;
|
||||||
|
class QAbstractButton;
|
||||||
|
|
||||||
|
class ManualHostDialog: public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
Settings *settings;
|
||||||
|
int host_id;
|
||||||
|
|
||||||
|
QLineEdit *host_edit;
|
||||||
|
QComboBox *registered_host_combo_box;
|
||||||
|
QDialogButtonBox *button_box;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void ValidateInput();
|
||||||
|
|
||||||
|
void ButtonClicked(QAbstractButton *button);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ManualHostDialog(Settings *settings, int id, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CHIAKI_MANUALHOSTDIALOG_H
|
|
@ -32,10 +32,15 @@ class Settings : public QObject
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
QMap<HostMAC, RegisteredHost> registered_hosts;
|
QMap<HostMAC, RegisteredHost> registered_hosts;
|
||||||
|
QMap<int, ManualHost> manual_hosts;
|
||||||
|
int manual_hosts_id_next;
|
||||||
|
|
||||||
void LoadRegisteredHosts();
|
void LoadRegisteredHosts();
|
||||||
void SaveRegisteredHosts();
|
void SaveRegisteredHosts();
|
||||||
|
|
||||||
|
void LoadManualHosts();
|
||||||
|
void SaveManualHosts();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Settings(QObject *parent = nullptr);
|
explicit Settings(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
@ -58,8 +63,15 @@ class Settings : public QObject
|
||||||
bool GetRegisteredHostRegistered(const HostMAC &mac) const { return registered_hosts.contains(mac); }
|
bool GetRegisteredHostRegistered(const HostMAC &mac) const { return registered_hosts.contains(mac); }
|
||||||
RegisteredHost GetRegisteredHost(const HostMAC &mac) const { return registered_hosts[mac]; }
|
RegisteredHost GetRegisteredHost(const HostMAC &mac) const { return registered_hosts[mac]; }
|
||||||
|
|
||||||
|
QList<ManualHost> GetManualHosts() const { return manual_hosts.values(); }
|
||||||
|
int SetManualHost(const ManualHost &host);
|
||||||
|
void RemoveManualHost(int id);
|
||||||
|
bool GetManualHostExists(int id) { return manual_hosts.contains(id); }
|
||||||
|
ManualHost GetManualHost(int id) const { return manual_hosts[id]; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void RegisteredHostsUpdated();
|
void RegisteredHostsUpdated();
|
||||||
|
void ManualHostsUpdated();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHIAKI_SETTINGS_H
|
#endif // CHIAKI_SETTINGS_H
|
||||||
|
|
|
@ -84,3 +84,45 @@ RegisteredHost RegisteredHost::LoadFromSettings(QSettings *settings)
|
||||||
memcpy(r.rp_key, rp_key.constData(), sizeof(r.rp_key));
|
memcpy(r.rp_key, rp_key.constData(), sizeof(r.rp_key));
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ManualHost::ManualHost()
|
||||||
|
{
|
||||||
|
id = -1;
|
||||||
|
registered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualHost::ManualHost(int id, const QString &host, bool registered, const HostMAC ®istered_mac)
|
||||||
|
: id(id),
|
||||||
|
host(host),
|
||||||
|
registered(registered),
|
||||||
|
registered_mac(registered_mac)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualHost::ManualHost(int id, const ManualHost &o)
|
||||||
|
: id(id),
|
||||||
|
host(o.host),
|
||||||
|
registered(o.registered),
|
||||||
|
registered_mac(o.registered_mac)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualHost::SaveToSettings(QSettings *settings) const
|
||||||
|
{
|
||||||
|
settings->setValue("id", id);
|
||||||
|
settings->setValue("host", host);
|
||||||
|
settings->setValue("registered", registered);
|
||||||
|
settings->setValue("registered_mac", QByteArray((const char *)registered_mac.GetMAC(), 6));
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualHost ManualHost::LoadFromSettings(QSettings *settings)
|
||||||
|
{
|
||||||
|
ManualHost r;
|
||||||
|
r.id = settings->value("id", -1).toInt();
|
||||||
|
r.host = settings->value("host").toString();
|
||||||
|
r.registered = settings->value("registered").toBool();
|
||||||
|
auto registered_mac = settings->value("registered_mac").toByteArray();
|
||||||
|
if(registered_mac.size() == 6)
|
||||||
|
r.registered_mac = HostMAC((const uint8_t *)registered_mac.constData());
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <settingsdialog.h>
|
#include <settingsdialog.h>
|
||||||
#include <streamsession.h>
|
#include <streamsession.h>
|
||||||
#include <streamwindow.h>
|
#include <streamwindow.h>
|
||||||
|
#include <manualhostdialog.h>
|
||||||
|
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -54,10 +55,10 @@ MainWindow::MainWindow(Settings *settings, QWidget *parent)
|
||||||
tool_bar_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
tool_bar_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||||
tool_bar->addWidget(tool_bar_spacer);
|
tool_bar->addWidget(tool_bar_spacer);
|
||||||
|
|
||||||
auto regist_action = new QAction(tr("Register"), this);
|
auto regist_action = new QAction(tr("Add Console manually"), this);
|
||||||
tool_bar->addAction(regist_action);
|
tool_bar->addAction(regist_action);
|
||||||
connect(regist_action, &QAction::triggered, this, [this]() {
|
connect(regist_action, &QAction::triggered, this, [this]() {
|
||||||
RegistDialog dialog(this->settings, QString(), this);
|
ManualHostDialog dialog(this->settings, -1, this);
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
90
gui/src/manualhostdialog.cpp
Normal file
90
gui/src/manualhostdialog.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki 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.
|
||||||
|
*
|
||||||
|
* Chiaki 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 Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <manualhostdialog.h>
|
||||||
|
#include <host.h>
|
||||||
|
#include <settings.h>
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
ManualHostDialog::ManualHostDialog(Settings *settings, int id, QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
{
|
||||||
|
this->settings = settings;
|
||||||
|
host_id = id;
|
||||||
|
|
||||||
|
ManualHost host;
|
||||||
|
if(id >= 0 && settings->GetManualHostExists(id))
|
||||||
|
host = settings->GetManualHost(id);
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
auto form_layout = new QFormLayout();
|
||||||
|
layout->addLayout(form_layout);
|
||||||
|
|
||||||
|
host_edit = new QLineEdit(this);
|
||||||
|
host_edit->setText(host.GetHost());
|
||||||
|
form_layout->addRow(tr("Host:"), host_edit);
|
||||||
|
connect(host_edit, &QLineEdit::textChanged, this, &ManualHostDialog::ValidateInput);
|
||||||
|
|
||||||
|
registered_host_combo_box = new QComboBox(this);
|
||||||
|
registered_host_combo_box->addItem(tr("Register on first Connection"));
|
||||||
|
auto registered_hosts = settings->GetRegisteredHosts();
|
||||||
|
for(const auto ®istered_host : registered_hosts)
|
||||||
|
registered_host_combo_box->addItem(QString("%1 (%2)").arg(registered_host.GetPS4MAC().ToString(), registered_host.GetPS4Nickname()), QVariant::fromValue(registered_host.GetPS4MAC()));
|
||||||
|
form_layout->addRow(tr("Registered Console:"), registered_host_combo_box);
|
||||||
|
|
||||||
|
button_box = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Discard, this);
|
||||||
|
layout->addWidget(button_box);
|
||||||
|
connect(button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
connect(button_box, &QDialogButtonBox::clicked, this, &ManualHostDialog::ButtonClicked);
|
||||||
|
|
||||||
|
ValidateInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualHostDialog::ValidateInput()
|
||||||
|
{
|
||||||
|
button_box->button(QDialogButtonBox::Save)->setEnabled(!host_edit->text().trimmed().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualHostDialog::ButtonClicked(QAbstractButton *button)
|
||||||
|
{
|
||||||
|
if(button_box->buttonRole(button) == QDialogButtonBox::DestructiveRole)
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualHostDialog::accept()
|
||||||
|
{
|
||||||
|
bool registered = false;
|
||||||
|
HostMAC registered_mac;
|
||||||
|
QVariant registered_host_data = registered_host_combo_box->currentData();
|
||||||
|
if(registered_host_data.isValid())
|
||||||
|
{
|
||||||
|
registered = true;
|
||||||
|
registered_mac = registered_host_data.value<HostMAC>();
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualHost host(host_id, host_edit->text().trimmed(), registered, registered_mac);
|
||||||
|
settings->SetManualHost(host);
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
|
@ -21,8 +21,10 @@
|
||||||
|
|
||||||
Settings::Settings(QObject *parent) : QObject(parent)
|
Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
manual_hosts_id_next = 0;
|
||||||
settings.setValue("version", SETTINGS_VERSION);
|
settings.setValue("version", SETTINGS_VERSION);
|
||||||
LoadRegisteredHosts();
|
LoadRegisteredHosts();
|
||||||
|
LoadManualHosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Settings::GetLogLevelMask()
|
uint32_t Settings::GetLogLevelMask()
|
||||||
|
@ -114,3 +116,53 @@ void Settings::RemoveRegisteredHost(const HostMAC &mac)
|
||||||
SaveRegisteredHosts();
|
SaveRegisteredHosts();
|
||||||
emit RegisteredHostsUpdated();
|
emit RegisteredHostsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::LoadManualHosts()
|
||||||
|
{
|
||||||
|
manual_hosts.clear();
|
||||||
|
|
||||||
|
int count = settings.beginReadArray("manual_hosts");
|
||||||
|
for(int i=0; i<count; i++)
|
||||||
|
{
|
||||||
|
settings.setArrayIndex(i);
|
||||||
|
ManualHost host = ManualHost::LoadFromSettings(&settings);
|
||||||
|
if(host.GetID() < 0)
|
||||||
|
continue;
|
||||||
|
if(manual_hosts_id_next <= host.GetID())
|
||||||
|
manual_hosts_id_next = host.GetID();
|
||||||
|
manual_hosts[host.GetID()] = host;
|
||||||
|
}
|
||||||
|
settings.endArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::SaveManualHosts()
|
||||||
|
{
|
||||||
|
settings.beginWriteArray("manual_hosts");
|
||||||
|
int i=0;
|
||||||
|
for(const auto &host : manual_hosts)
|
||||||
|
{
|
||||||
|
settings.setArrayIndex(i);
|
||||||
|
host.SaveToSettings(&settings);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
settings.endArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Settings::SetManualHost(const ManualHost &host)
|
||||||
|
{
|
||||||
|
int id = host.GetID();
|
||||||
|
if(id < 0)
|
||||||
|
id = manual_hosts_id_next++;
|
||||||
|
ManualHost save_host(id, host);
|
||||||
|
manual_hosts[id] = save_host;
|
||||||
|
SaveManualHosts();
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::RemoveManualHost(int id)
|
||||||
|
{
|
||||||
|
manual_hosts.remove(id);
|
||||||
|
SaveManualHosts();
|
||||||
|
emit ManualHostsUpdated();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue