diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index b496b89e..d454d218 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -150,7 +150,8 @@ HEADERS += comic_flow.h \ yacreader_comic_info_helper.h \ db/reading_list.h \ db/query_parser.h \ - current_comic_view_helper.h + current_comic_view_helper.h \ + ip_config_helper.h !CONFIG(no_opengl) { HEADERS += ../common/gl/yacreader_flow_gl.h @@ -232,7 +233,8 @@ SOURCES += comic_flow.cpp \ yacreader_comic_info_helper.cpp\ db/reading_list.cpp \ current_comic_view_helper.cpp \ - db/query_parser.cpp + db/query_parser.cpp \ + ip_config_helper.cpp !CONFIG(no_opengl) { SOURCES += ../common/gl/yacreader_flow_gl.cpp diff --git a/YACReaderLibrary/ip_config_helper.cpp b/YACReaderLibrary/ip_config_helper.cpp new file mode 100644 index 00000000..38c58188 --- /dev/null +++ b/YACReaderLibrary/ip_config_helper.cpp @@ -0,0 +1,33 @@ +#include +#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 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 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; +} diff --git a/YACReaderLibrary/ip_config_helper.h b/YACReaderLibrary/ip_config_helper.h new file mode 100644 index 00000000..8cabe1d3 --- /dev/null +++ b/YACReaderLibrary/ip_config_helper.h @@ -0,0 +1,4 @@ +#ifndef YR_IP_CONFIG_HELPER +#define YR_IP_CONFIG_HELPER +QList getIpAddresses(); +#endif diff --git a/YACReaderLibrary/server_config_dialog.cpp b/YACReaderLibrary/server_config_dialog.cpp index e80c4510..c15902bc 100644 --- a/YACReaderLibrary/server_config_dialog.cpp +++ b/YACReaderLibrary/server_config_dialog.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -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 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);