Skip to content

Commit

Permalink
Fix to use Ports in the FQDN / IP field (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-w authored Oct 29, 2024
1 parent 039c6f6 commit ea11767
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/virtlyst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,43 @@ void Virtlyst::updateConnections()
server->login = login;
server->password = password;
server->type = type;

QStringList parts = hostname.split(u':');
QString host = parts[0]; // The IP/FQDN part
int port = -1; // Default port value if no port is specified

// Check if a port was provided
if (parts.size() > 1) {
bool ok;
port = parts[1].toInt(&ok);
if (!ok) {
qCWarning(VIRTLYST) << "Invalid port number in hostname:" << parts[1];
port = -1;
}
}

QUrl url;
switch (type) {
case ServerConn::ConnSocket:
url = QStringLiteral("qemu:///system");
break;
case ServerConn::ConnSSH:
url = QStringLiteral("qemu+ssh:///system");
url.setHost(hostname);
url.setHost(host);
url.setPort(port);
url.setUserName(login);
break;
case ServerConn::ConnTCP:
url = QStringLiteral("qemu+tcp:///system");
url.setHost(hostname);
url.setHost(host);
url.setPort(port);
url.setUserName(login);
url.setPassword(password);
break;
case ServerConn::ConnTLS:
url = QStringLiteral("qemu+tls:///system");
url.setHost(hostname);
url.setHost(host);
url.setPort(port);
url.setUserName(login);
url.setPassword(password);
break;
Expand Down

0 comments on commit ea11767

Please sign in to comment.