Move network interface filtering to separate file

This commit is contained in:
Felix Kauselmann
2023-04-07 20:19:11 +02:00
parent 9f67bb5e53
commit c100edfcd0
4 changed files with 43 additions and 30 deletions

View File

@ -1,5 +1,4 @@
#include <QGridLayout>
#include <QNetworkInterface>
#include <QSettings>
#include <QPalette>
#include <QBitmap>
@ -10,25 +9,9 @@
#include "yacreader_http_server.h"
#include "yacreader_global_gui.h"
#include "qnaturalsorting.h"
#include "ip_config_helper.h"
#include "qrcodegen.hpp"
// 192.168 (most comon local subnet for ips are always put first)
// IPs are sorted using natoral sorting
bool ipComparator(const QString &ip1, const QString &ip2)
{
if (ip1.startsWith("192.168") && ip2.startsWith("192.168"))
return naturalSortLessThanCI(ip1, ip2);
if (ip1.startsWith("192.168"))
return true;
if (ip2.startsWith("192.168"))
return false;
return naturalSortLessThanCI(ip1, ip2);
}
extern YACReaderHttpServer *httpServer;
ServerConfigDialog::ServerConfigDialog(QWidget *parent)
@ -174,16 +157,7 @@ void ServerConfigDialog::generateQR()
{
ip->clear();
QList<QString> addresses;
for (auto add : QNetworkInterface::allAddresses()) {
// Exclude loopback, local, multicast
if (add.isGlobal()) {
addresses.push_back(add.toString());
}
}
std::sort(addresses.begin(), addresses.end(), ipComparator);
auto addresses = getIpAddresses();
if (addresses.length() > 0) {
generateQR(addresses.first() + ":" + httpServer->getPort());
ip->addItems(addresses);