mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Move network interface filtering to separate file
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user