Skip to content

Commit

Permalink
Combine manual + discovered hosts that share the same mac + ip
Browse files Browse the repository at this point in the history
  • Loading branch information
streetpea committed Sep 7, 2024
1 parent c30f19c commit 4967466
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gui/include/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ManualHost
void SaveToSettings(QSettings *settings) const;
static ManualHost LoadFromSettings(QSettings *settings);
};

static bool operator==(const ManualHost &a, const ManualHost &b) { return (a.GetID() == b.GetID() && a.GetHost() == b.GetHost() && a.GetRegistered() == b.GetRegistered() && a.GetMAC() == b.GetMAC()); }
class PsnHost
{
private:
Expand Down
16 changes: 13 additions & 3 deletions gui/src/qml/MainView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Pane {
}

function deleteHost() {
if (!modelData.discovered && !modelData.duid)
if (modelData.manual)
root.showConfirmDialog(qsTr("Delete Console"), qsTr("Are you sure you want to delete this console?"), () => Chiaki.deleteHost(index));
}

Expand All @@ -146,6 +146,7 @@ Pane {
}

RowLayout {
visible: modelData.display
anchors {
fill: parent
leftMargin: 30
Expand Down Expand Up @@ -178,7 +179,16 @@ Pane {
t += "\n" + qsTr("Remote Connection via PSN");
}
else
t += "\n" + (modelData.discovered ? qsTr("discovered") : qsTr("manual"));
t += "\n";
if(modelData.discovered)
{
if(modelData.manual)
t += qsTr("discovered + manual")
else
t += qsTr("discovered");
}
else
t += qsTr("manual");
return t;
}
}
Expand Down Expand Up @@ -211,7 +221,7 @@ Pane {
padding: 20
leftPadding: delegate.highlighted ? 50 : undefined
focusPolicy: Qt.NoFocus
visible: !modelData.discovered && !modelData.duid
visible: modelData.manual
onClicked: delegate.deleteHost()
Material.roundedScale: Material.SmallScale

Expand Down
38 changes: 32 additions & 6 deletions gui/src/qmlbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,24 @@ QVariantList QmlBackend::hosts() const
{
QVariantList out;
QList<QString> discovered_nicknames;
QList<ManualHost> discovered_manual_hosts;
size_t registered_discovered_ps4s = 0;
auto manual_hosts = settings->GetManualHosts();
for (const auto &host : discovery_manager.GetHosts()) {
QVariantMap m;
bool registered = settings->GetRegisteredHostRegistered(host.GetHostMAC());
m["discovered"] = true;
m["manual"] = false;
bool manual = false;
for(int i = 0; i < manual_hosts.length(); i++)
{
auto manual_host = manual_hosts.at(i);
if(manual_host.GetRegistered() && manual_host.GetMAC() == host.GetHostMAC() && manual_host.GetHost() == host.host_addr)
{
manual = true;
discovered_manual_hosts.append(manual_host);
}
}
m["manual"] = manual;
m["name"] = host.host_name;
m["duid"] = "";
m["address"] = host.host_addr;
Expand All @@ -437,6 +449,7 @@ QVariantList QmlBackend::hosts() const
m["app"] = host.running_app_name;
m["titleId"] = host.running_app_titleid;
m["registered"] = registered;
m["display"] = true;
discovered_nicknames.append(host.host_name);
out.append(m);
if(!host.ps5 && registered)
Expand All @@ -450,6 +463,7 @@ QVariantList QmlBackend::hosts() const
m["duid"] = "";
m["address"] = host.GetHost();
m["registered"] = false;
m["display"] = discovered_manual_hosts.contains(host) ? false : true;
if (host.GetRegistered() && settings->GetRegisteredHostRegistered(host.GetMAC())) {
auto registered = settings->GetRegisteredHost(host.GetMAC());
m["registered"] = true;
Expand All @@ -474,6 +488,7 @@ QVariantList QmlBackend::hosts() const
continue;
m["discovered"] = false;
m["manual"] = false;
m["display"] = true;
m["name"] = host.GetName();
m["duid"] = host.GetDuid();
m["address"] = "";
Expand Down Expand Up @@ -742,9 +757,10 @@ bool QmlBackend::closeRequested()
void QmlBackend::deleteHost(int index)
{
auto server = displayServerAt(index);
if (!server.valid || server.discovered)
auto id = server.manual_host.GetID();
if (!server.valid || (id < 0))
return;
settings->RemoveManualHost(server.manual_host.GetID());
settings->RemoveManualHost(id);
}

void QmlBackend::wakeUpHost(int index)
Expand Down Expand Up @@ -992,19 +1008,29 @@ QmlBackend::DisplayServer QmlBackend::displayServerAt(int index) const
if (index < 0)
return {};
auto discovered = discovery_manager.GetHosts();
auto manual = settings->GetManualHosts();
if (index < discovered.size()) {
DisplayServer server;
server.valid = true;
server.discovered = true;
server.discovery_host = discovered.at(index);
server.registered = settings->GetRegisteredHostRegistered(server.discovery_host.GetHostMAC());
auto host_mac = server.discovery_host.GetHostMAC();
server.registered = settings->GetRegisteredHostRegistered(host_mac);
server.duid = QString();
if (server.registered)
server.registered_host = settings->GetRegisteredHost(server.discovery_host.GetHostMAC());
server.registered_host = settings->GetRegisteredHost(host_mac);
for (int i = 0; i < manual.size(); i++)
{
auto manual_host = manual.at(i);
if(manual_host.GetRegistered() && manual_host.GetMAC() == host_mac && manual_host.GetHost() == server.discovery_host.host_addr)
{
server.manual_host = manual_host;
break;
}
}
return server;
}
index -= discovered.size();
auto manual = settings->GetManualHosts();
if (index < manual.size()) {
DisplayServer server;
server.valid = true;
Expand Down

0 comments on commit 4967466

Please sign in to comment.