Skip to content

Commit 6bd652c

Browse files
authored
Merge pull request #967 from deXol/developPortQt6
Fix Qt6 port build issues
2 parents 19225a1 + dbfcb3b commit 6bd652c

7 files changed

Lines changed: 14559 additions & 11 deletions

File tree

daemon.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ HEADERS += \
130130
src/Settings/DeviceSettings.h \
131131
src/Settings/DeviceSettingsMini.h \
132132
src/Settings/DeviceSettingsBLE.h \
133-
src/Mooltipass/MPBLEFreeAddressProvider.h
133+
src/Mooltipass/MPBLEFreeAddressProvider.h \
134+
src/utils/qurltlds_p.h
134135

135136
DISTFILES += \
136137
src/http-parser/CONTRIBUTIONS \

gui.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ HEADERS += src/MainWindow.h \
9292
src/WSClient.h \
9393
src/RotateSpinner.h \
9494
src/utils/GridLayoutUtil.h \
95+
src/utils/qurltlds_p.h \
9596
src/version.h \
9697
src/AppGui.h \
9798
src/DaemonMenuAction.h \

src/ParseDomain.cpp

100644100755
Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "ParseDomain.h"
2-
2+
#if QT_VERSION >= 0x051000
3+
#include "utils/qurltlds_p.h"
4+
#endif
35

46
ParseDomain::ParseDomain(const QString &url) :
57
_url(QUrl::fromUserInput(url))
@@ -60,6 +62,51 @@ ParseDomain::ParseDomain(const QString &url) :
6062
}
6163
}
6264

65+
#if QT_VERSION >= 0x051000
66+
bool ParseDomain::containsTLDEntry(QStringView entry, TLDMatchType match)
67+
{
68+
const QStringView matchSymbols[] = {
69+
u"",
70+
u"*",
71+
u"!",
72+
};
73+
const auto symbol = matchSymbols[match];
74+
int index = qt_hash(entry, qt_hash(symbol)) % tldCount;
75+
// select the right chunk from the big table
76+
short chunk = 0;
77+
uint chunkIndex = tldIndices[index], offset = 0;
78+
while (chunk < tldChunkCount && tldIndices[index] >= tldChunks[chunk]) {
79+
chunkIndex -= tldChunks[chunk];
80+
offset += tldChunks[chunk];
81+
chunk++;
82+
}
83+
// check all the entries from the given index
84+
while (chunkIndex < tldIndices[index+1] - offset) {
85+
const auto utf8 = tldData[chunk] + chunkIndex;
86+
if ((symbol.isEmpty() || QLatin1Char(*utf8) == symbol) && entry == QString::fromUtf8(utf8 + symbol.size()))
87+
return true;
88+
chunkIndex += qstrlen(utf8) + 1; // +1 for the ending \0
89+
}
90+
return false;
91+
}
92+
93+
bool ParseDomain::qIsEffectiveTLD(const QString &domain)
94+
{
95+
// for domain 'foo.bar.com':
96+
// 1. return if TLD table contains 'foo.bar.com'
97+
// 2. else if table contains '*.bar.com',
98+
// 3. test that table does not contain '!foo.bar.com'
99+
if (containsTLDEntry(domain, ExactMatch)) // 1
100+
return true;
101+
const int dot = domain.indexOf(QLatin1Char('.'));
102+
if (dot >= 0) {
103+
if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
104+
return !containsTLDEntry(domain, ExceptionMatch); // 3
105+
}
106+
return false;
107+
}
108+
#endif
109+
63110
QString ParseDomain::getManuallyEnteredDomainName(const QString &service)
64111
{
65112
if (!isWebsite())
@@ -83,11 +130,20 @@ QString ParseDomain::getManuallyEnteredDomainName(const QString &service)
83130
*/
84131
QString ParseDomain::getTopLevel() const
85132
{
86-
QString host = _url.host();
87-
int pos = host.lastIndexOf('.');
88-
if (-1 != pos)
89-
{
90-
return host.right(host.size() - pos);
91-
}
92-
return "";
133+
#if QT_VERSION >= 0x051000
134+
QString domain = _url.host();
135+
const QString domainLower = domain.toLower();
136+
QStringList sections = domainLower.split(QLatin1Char('.'));
137+
if (sections.isEmpty())
138+
return QString();
139+
QString level, tld;
140+
for (int j = sections.count() - 1; j >= 0; --j) {
141+
level.prepend(QLatin1Char('.') + sections.at(j));
142+
if (qIsEffectiveTLD(level.right(level.size() - 1)))
143+
tld = level;
144+
}
145+
return tld;
146+
#else
147+
return _url.topLevelDomain();
148+
#endif
93149
}

src/ParseDomain.h

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ class ParseDomain
6666
private:
6767
ParseDomain();
6868

69+
#if QT_VERSION >= 0x051000
70+
enum TLDMatchType {
71+
ExactMatch,
72+
SuffixMatch,
73+
ExceptionMatch,
74+
};
75+
76+
/**
77+
* Functions from qtldurl.cpp
78+
*/
79+
static bool containsTLDEntry(QStringView entry, TLDMatchType match);
80+
static bool qIsEffectiveTLD(const QString &domain);
81+
#endif
82+
6983
QUrl _url;
7084
bool _isWebsite;
7185
QString _tld;

src/QSimpleUpdater/src/Downloader.cpp

100644100755
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ void Downloader::startDownload (const QUrl& url)
114114
m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown"));
115115

116116
/* Start download */
117+
#if QT_VERSION >= 0x050800
117118
m_startTime = QDateTime::currentDateTime().toSecsSinceEpoch();
119+
#else
120+
m_startTime = QDateTime::currentDateTime().toTime_t();
121+
#endif
118122
m_reply = m_manager->get (QNetworkRequest (url));
119123

120124
/* Ensure that downloads directory exists */
@@ -355,7 +359,11 @@ void Downloader::updateProgress (qint64 received, qint64 total)
355359
*/
356360
void Downloader::calculateTimeRemaining (qint64 received, qint64 total)
357361
{
362+
#if QT_VERSION >= 0x050800
358363
quint64 difference = QDateTime::currentDateTime().toSecsSinceEpoch() - m_startTime;
364+
#else
365+
quint64 difference = QDateTime::currentDateTime().toTime_t() - m_startTime;
366+
#endif
359367

360368
if (difference > 0) {
361369
QString timeString;

0 commit comments

Comments
 (0)