mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Move network interface filtering to separate file
This commit is contained in:
parent
9f67bb5e53
commit
c100edfcd0
@ -150,7 +150,8 @@ HEADERS += comic_flow.h \
|
|||||||
yacreader_comic_info_helper.h \
|
yacreader_comic_info_helper.h \
|
||||||
db/reading_list.h \
|
db/reading_list.h \
|
||||||
db/query_parser.h \
|
db/query_parser.h \
|
||||||
current_comic_view_helper.h
|
current_comic_view_helper.h \
|
||||||
|
ip_config_helper.h
|
||||||
|
|
||||||
!CONFIG(no_opengl) {
|
!CONFIG(no_opengl) {
|
||||||
HEADERS += ../common/gl/yacreader_flow_gl.h
|
HEADERS += ../common/gl/yacreader_flow_gl.h
|
||||||
@ -232,7 +233,8 @@ SOURCES += comic_flow.cpp \
|
|||||||
yacreader_comic_info_helper.cpp\
|
yacreader_comic_info_helper.cpp\
|
||||||
db/reading_list.cpp \
|
db/reading_list.cpp \
|
||||||
current_comic_view_helper.cpp \
|
current_comic_view_helper.cpp \
|
||||||
db/query_parser.cpp
|
db/query_parser.cpp \
|
||||||
|
ip_config_helper.cpp
|
||||||
|
|
||||||
!CONFIG(no_opengl) {
|
!CONFIG(no_opengl) {
|
||||||
SOURCES += ../common/gl/yacreader_flow_gl.cpp
|
SOURCES += ../common/gl/yacreader_flow_gl.cpp
|
||||||
|
33
YACReaderLibrary/ip_config_helper.cpp
Normal file
33
YACReaderLibrary/ip_config_helper.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <QNetworkInterface>
|
||||||
|
#include "ip_config_helper.h"
|
||||||
|
#include "qnaturalsorting.h"
|
||||||
|
|
||||||
|
// 192.168 (most comon local subnet for ips are always put first)
|
||||||
|
// IPs are sorted using natoral sorting
|
||||||
|
|
||||||
|
QList<QString> getIpAddresses()
|
||||||
|
{
|
||||||
|
auto 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);
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
return addresses;
|
||||||
|
}
|
4
YACReaderLibrary/ip_config_helper.h
Normal file
4
YACReaderLibrary/ip_config_helper.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef YR_IP_CONFIG_HELPER
|
||||||
|
#define YR_IP_CONFIG_HELPER
|
||||||
|
QList<QString> getIpAddresses();
|
||||||
|
#endif
|
@ -1,5 +1,4 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QNetworkInterface>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
@ -10,25 +9,9 @@
|
|||||||
#include "yacreader_http_server.h"
|
#include "yacreader_http_server.h"
|
||||||
#include "yacreader_global_gui.h"
|
#include "yacreader_global_gui.h"
|
||||||
|
|
||||||
#include "qnaturalsorting.h"
|
#include "ip_config_helper.h"
|
||||||
#include "qrcodegen.hpp"
|
#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;
|
extern YACReaderHttpServer *httpServer;
|
||||||
|
|
||||||
ServerConfigDialog::ServerConfigDialog(QWidget *parent)
|
ServerConfigDialog::ServerConfigDialog(QWidget *parent)
|
||||||
@ -174,16 +157,7 @@ void ServerConfigDialog::generateQR()
|
|||||||
{
|
{
|
||||||
ip->clear();
|
ip->clear();
|
||||||
|
|
||||||
QList<QString> addresses;
|
auto addresses = getIpAddresses();
|
||||||
for (auto add : QNetworkInterface::allAddresses()) {
|
|
||||||
// Exclude loopback, local, multicast
|
|
||||||
if (add.isGlobal()) {
|
|
||||||
addresses.push_back(add.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(addresses.begin(), addresses.end(), ipComparator);
|
|
||||||
|
|
||||||
if (addresses.length() > 0) {
|
if (addresses.length() > 0) {
|
||||||
generateQR(addresses.first() + ":" + httpServer->getPort());
|
generateQR(addresses.first() + ":" + httpServer->getPort());
|
||||||
ip->addItems(addresses);
|
ip->addItems(addresses);
|
||||||
|
Loading…
Reference in New Issue
Block a user