mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 05:53:12 -07:00
Display Registered Hosts in SettingsDialog
This commit is contained in:
parent
d435a9d368
commit
c993ca611e
12 changed files with 192 additions and 16 deletions
|
@ -32,12 +32,23 @@ class HostMAC
|
|||
|
||||
public:
|
||||
HostMAC() { memset(mac, 0, sizeof(mac)); }
|
||||
HostMAC(const HostMAC &o) { memcpy(mac, o.GetMAC(), sizeof(mac)); }
|
||||
explicit HostMAC(const uint8_t mac[6]) { memcpy(this->mac, mac, sizeof(this->mac)); }
|
||||
const uint8_t *GetMAC() const { return mac; }
|
||||
QString ToString() const { return QByteArray((const char *)mac, sizeof(mac)).toHex(); }
|
||||
uint64_t GetValue() const
|
||||
{
|
||||
return ((uint64_t)mac[0] << 0x28)
|
||||
| ((uint64_t)mac[1] << 0x20)
|
||||
| ((uint64_t)mac[2] << 0x18)
|
||||
| ((uint64_t)mac[3] << 0x10)
|
||||
| ((uint64_t)mac[4] << 0x8)
|
||||
| mac[5];
|
||||
}
|
||||
};
|
||||
|
||||
static bool operator==(const HostMAC &a, const HostMAC &b) { return memcmp(a.GetMAC(), b.GetMAC(), 6) == 0; }
|
||||
static bool operator==(const HostMAC &a, const HostMAC &b) { return memcmp(a.GetMAC(), b.GetMAC(), 6) == 0; }
|
||||
static bool operator<(const HostMAC &a, const HostMAC &b) { return a.GetValue() < b.GetValue(); }
|
||||
|
||||
class RegisteredHost
|
||||
{
|
||||
|
@ -54,14 +65,18 @@ class RegisteredHost
|
|||
|
||||
public:
|
||||
RegisteredHost();
|
||||
RegisteredHost(const RegisteredHost &o);
|
||||
|
||||
RegisteredHost(const ChiakiRegisteredHost &chiaki_host);
|
||||
|
||||
const HostMAC &GetPS4MAC() const { return ps4_mac; }
|
||||
const QString &GetPS4Nickname() const { return ps4_nickname; }
|
||||
|
||||
void SaveToSettings(QSettings *settings);
|
||||
void SaveToSettings(QSettings *settings) const;
|
||||
static RegisteredHost LoadFromSettings(QSettings *settings);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(RegisteredHost)
|
||||
Q_DECLARE_METATYPE(HostMAC)
|
||||
|
||||
#endif //CHIAKI_HOST_H
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QMainWindow>
|
||||
|
||||
#include "discoverymanager.h"
|
||||
#include "host.h"
|
||||
|
||||
class DynamicGridWidget;
|
||||
class ServerItemWidget;
|
||||
|
@ -31,6 +32,9 @@ struct DisplayServer
|
|||
DiscoveryHost discovery_host;
|
||||
bool discovered;
|
||||
|
||||
RegisteredHost registered_host;
|
||||
bool registered;
|
||||
|
||||
QString GetHostAddr() const { return discovered ? discovery_host.host_addr : QString(); }
|
||||
};
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ class RegistExecuteDialog: public QDialog
|
|||
friend class RegistExecuteDialogPrivate;
|
||||
|
||||
private:
|
||||
Settings *settings;
|
||||
|
||||
ChiakiLog log;
|
||||
ChiakiRegist regist;
|
||||
|
||||
|
@ -75,7 +77,7 @@ class RegistExecuteDialog: public QDialog
|
|||
void Failed();
|
||||
|
||||
public:
|
||||
explicit RegistExecuteDialog(const ChiakiRegistInfo ®ist_info, QWidget *parent = nullptr);
|
||||
explicit RegistExecuteDialog(Settings *settings, const ChiakiRegistInfo ®ist_info, QWidget *parent = nullptr);
|
||||
~RegistExecuteDialog();
|
||||
};
|
||||
|
||||
|
|
|
@ -18,18 +18,36 @@
|
|||
#ifndef CHIAKI_SETTINGS_H
|
||||
#define CHIAKI_SETTINGS_H
|
||||
|
||||
#include "host.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
class Settings
|
||||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QSettings settings;
|
||||
|
||||
QMap<HostMAC, RegisteredHost> registered_hosts;
|
||||
|
||||
void LoadRegisteredHosts();
|
||||
void SaveRegisteredHosts();
|
||||
|
||||
public:
|
||||
Settings();
|
||||
explicit Settings(QObject *parent = nullptr);
|
||||
|
||||
bool GetDiscoveryEnabled() { return settings.value("settings/auto_discovery", true).toBool(); }
|
||||
void SetDiscoveryEnabled(bool enabled) { settings.setValue("settings/auto_discovery", enabled); }
|
||||
|
||||
QList<RegisteredHost> GetRegisteredHosts() const { return registered_hosts.values(); }
|
||||
void AddRegisteredHost(const RegisteredHost &host);
|
||||
void RemoveRegisteredHost(const HostMAC &mac);
|
||||
bool GetRegisteredHostRegistered(const HostMAC &mac) const { return registered_hosts.contains(mac); }
|
||||
RegisteredHost GetRegisteredHost(const HostMAC &mac) const { return registered_hosts[mac]; }
|
||||
|
||||
signals:
|
||||
void RegisteredHostsUpdated();
|
||||
};
|
||||
|
||||
#endif // CHIAKI_SETTINGS_H
|
||||
|
|
|
@ -31,6 +31,12 @@ class SettingsDialog : public QDialog
|
|||
Settings *settings;
|
||||
|
||||
QListWidget *registered_hosts_list_widget;
|
||||
QPushButton *delete_registered_host_button;
|
||||
|
||||
private slots:
|
||||
void UpdateRegisteredHosts();
|
||||
void UpdateRegisteredHostsButtons();
|
||||
void DeleteRegisteredHost();
|
||||
|
||||
public:
|
||||
SettingsDialog(Settings *settings, QWidget *parent = nullptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue