Skip to content

Commit

Permalink
Merge PR mumble-voip#6596: REFAC: Qt cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl authored Oct 3, 2024
2 parents 590c34c + ab7285f commit 4148f9b
Show file tree
Hide file tree
Showing 50 changed files with 44 additions and 576 deletions.
10 changes: 5 additions & 5 deletions cmake/pkg-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endfunction()
# It also handles multiple package names and searches them with pkg-config if they are not found.
macro(find_pkg ARG_ALIASES)
# We specify "CONFIG", "MODULE" and "NO_MODULE" so that they are not considered unparsed arguments (passed to find_package()).
cmake_parse_arguments(FIND_PACKAGE "ARG_ALIASES;CONFIG;MODULE;NO_DEFAULT_PATH;NO_MODULE;REQUIRED;QUIET" "" "COMPONENTS;OPTIONAL_COMPONENTS;PATHS" ${ARGN})
cmake_parse_arguments(FIND_PACKAGE "ARG_ALIASES;CONFIG;MODULE;NO_DEFAULT_PATH;NO_MODULE;REQUIRED;QUIET" "VERSION" "COMPONENTS;OPTIONAL_COMPONENTS;PATHS" ${ARGN})

if(FIND_PACKAGE_PATHS)
list(APPEND FIND_PACKAGE_ARGUMENTS "PATHS" ${FIND_PACKAGE_PATHS})
Expand All @@ -74,21 +74,21 @@ macro(find_pkg ARG_ALIASES)

if(FIND_PACKAGE_COMPONENTS)
foreach(COMPONENT ${FIND_PACKAGE_COMPONENTS})
find_package(${NAME} COMPONENTS ${COMPONENT} ${FIND_PACKAGE_ARGUMENTS} ${QUIET_STR} CONFIG ${FIND_PACKAGE_UNPARSED_ARGUMENTS})
find_package(${NAME} ${FIND_PACKAGE_VERSION} COMPONENTS ${COMPONENT} ${FIND_PACKAGE_ARGUMENTS} ${QUIET_STR} CONFIG ${FIND_PACKAGE_UNPARSED_ARGUMENTS})
if(NOT ${NAME}_FOUND)
find_package(${NAME} COMPONENTS ${COMPONENT} ${FIND_PACKAGE_ARGUMENTS} ${QUIET_STR} MODULE ${FIND_PACKAGE_UNPARSED_ARGUMENTS})
find_package(${NAME} ${FIND_PACKAGE_VERSION} COMPONENTS ${COMPONENT} ${FIND_PACKAGE_ARGUMENTS} ${QUIET_STR} MODULE ${FIND_PACKAGE_UNPARSED_ARGUMENTS})
endif()

if(NOT ${NAME}_FOUND)
if(NOT ${NAME} STREQUAL ${LAST_ALIAS})
break()
else()
if(FIND_PACKAGE_REQUIRED)
message(FATAL_ERROR "${NAME} component not found: ${COMPONENT}")
message(FATAL_ERROR "${NAME} component not found: ${COMPONENT} ${FIND_PACKAGE_VERSION}")
endif()

if(NOT FIND_PACKAGE_QUIET)
message(STATUS "${NAME} component not found: ${COMPONENT}")
message(STATUS "${NAME} component not found: ${COMPONENT} ${FIND_PACKAGE_VERSION}")
endif()

break()
Expand Down
6 changes: 0 additions & 6 deletions src/ACL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ QFlags< ChanACL::Perm > ChanACL::effectivePermissions(ServerUser *p, Channel *ch
return static_cast< Permissions >(All & ~(Speak | Whisper));
}

# if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
// Qt 5.15 introduced a default constructor that initializes the flags to be set to no flags
Permissions granted;
# else
// Before Qt 5.15 we have emulate the default constructor by assigning a literal zero
Permissions granted = 0;
# endif

if (cache) {
QHash< Channel *, Permissions > *h = cache->value(p);
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ option(bundled-gsl "Use the bundled GSL version instead of looking for one on th


find_pkg(Qt6
VERSION 6.2
COMPONENTS
Core
Network
Expand Down
8 changes: 0 additions & 8 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,11 @@ QSslCipher Connection::sessionCipher() const {
}

QSsl::SslProtocol Connection::sessionProtocol() const {
#if QT_VERSION >= 0x050400
return qtsSocket->sessionProtocol();
#else
return QSsl::UnknownProtocol; // Cannot determine session cipher. We only know it's some TLS variant
#endif
}

QString Connection::sessionProtocolString() const {
#if QT_VERSION >= 0x050400
return MumbleSSL::protocolToString(sessionProtocol());
#else
return QLatin1String("TLS"); // Cannot determine session cipher. We only know it's some TLS variant
#endif
}

#ifdef Q_OS_WIN
Expand Down
17 changes: 1 addition & 16 deletions src/SSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,10 @@ QList< QSslCipher > MumbleSSL::ciphersFromOpenSSLCipherString(QString cipherStri
if (!name) {
break;
}
#if QT_VERSION >= 0x050300
QSslCipher c = QSslCipher(QString::fromLatin1(name));
if (!c.isNull()) {
chosenCiphers << c;
}
#else
foreach (const QSslCipher &c, QSslSocket::supportedCiphers()) {
if (c.name() == QString::fromLatin1(name)) {
chosenCiphers << c;
}
}
#endif
++i;
}

Expand All @@ -97,16 +89,11 @@ QList< QSslCipher > MumbleSSL::ciphersFromOpenSSLCipherString(QString cipherStri
}

void MumbleSSL::addSystemCA() {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
// Qt 5.15 introduced adding certificates to the QSslConfiguration and deprecated doing so on QSslSocket
auto config = QSslConfiguration::defaultConfiguration();

config.addCaCertificates(QSslConfiguration::systemCaCertificates());

QSslConfiguration::setDefaultConfiguration(config);
#else
QSslSocket::addDefaultCaCertificates(QSslConfiguration::systemCaCertificates());
#endif

#ifdef Q_OS_WIN
// Work around issue #1271.
Expand Down Expand Up @@ -144,18 +131,16 @@ void MumbleSSL::addSystemCA() {

QString MumbleSSL::protocolToString(QSsl::SslProtocol protocol) {
switch (protocol) {
#if QT_VERSION < 0x060300
#if QT_VERSION < QT_VERSION_CHECK(6, 3, 0)
case QSsl::TlsV1_0:
return QLatin1String("TLS 1.0");
case QSsl::TlsV1_1:
return QLatin1String("TLS 1.1");
#endif
case QSsl::TlsV1_2:
return QLatin1String("TLS 1.2");
#if QT_VERSION >= 0x050C00
case QSsl::TlsV1_3:
return QLatin1String("TLS 1.3");
#endif
case QSsl::AnyProtocol:
return QLatin1String("AnyProtocol");
case QSsl::SecureProtocols:
Expand Down
8 changes: 2 additions & 6 deletions src/ServerResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ void ServerResolverPrivate::srvResolved() {
}

void ServerResolverPrivate::hostResolved(QHostInfo hostInfo) {
const int lookupId = hostInfo.lookupId();
const qsizetype idx = m_hostInfoIdToIndexMap[lookupId];
#if QT_VERSION >= 0x060000
const int lookupId = hostInfo.lookupId();
const qsizetype idx = m_hostInfoIdToIndexMap[lookupId];
QDnsServiceRecord record = m_srvQueue.at(idx);
#else
QDnsServiceRecord record = m_srvQueue.at(static_cast< int >(idx));
#endif

if (hostInfo.error() == QHostInfo::NoError) {
QList< QHostAddress > resolvedAddresses = hostInfo.addresses();
Expand Down
14 changes: 1 addition & 13 deletions src/mumble/ACLEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "User.h"
#include "widgets/EventFilters.h"

#if QT_VERSION >= 0x050000
# include <QtWidgets/QMessageBox>
#else
# include <QtGui/QMessageBox>
#endif
#include <QtWidgets/QMessageBox>

#include "Global.h"

Expand Down Expand Up @@ -794,11 +790,7 @@ void ACLEditor::on_qpbACLUp_clicked() {
if (idx <= numInheritACL + 1)
return;

#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
qlACLs.swapItemsAt(idx - 1, idx);
#else
qlACLs.swap(idx - 1, idx);
#endif
qlwACLs->setCurrentRow(qlwACLs->currentRow() - 1);
refillACL();
}
Expand All @@ -812,11 +804,7 @@ void ACLEditor::on_qpbACLDown_clicked() {
if (idx >= qlACLs.count())
return;

#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
qlACLs.swapItemsAt(idx - 1, idx);
#else
qlACLs.swap(idx - 1, idx);
#endif
qlwACLs->setCurrentRow(qlwACLs->currentRow() + 1);
refillACL();
}
Expand Down
9 changes: 2 additions & 7 deletions src/mumble/API_v_1_x_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,8 @@ QVariant getMumbleSettingHelper(mumble_settings_key_t key) {

// IS_TYPE actually only checks if the QVariant can be converted to the needed type since that's all that we really care
// about at the end of the day.
#if QT_VERSION >= 0x060000
# define IS_TYPE(var, varType) static_cast< QMetaType::Type >(var.typeId()) == varType
# define IS_NOT_TYPE(var, varType) static_cast< QMetaType::Type >(var.typeId()) != varType
#else
# define IS_TYPE(var, varType) static_cast< QMetaType::Type >(var.type()) == varType
# define IS_NOT_TYPE(var, varType) static_cast< QMetaType::Type >(var.type()) != varType
#endif
#define IS_TYPE(var, varType) static_cast< QMetaType::Type >(var.typeId()) == varType
#define IS_NOT_TYPE(var, varType) static_cast< QMetaType::Type >(var.typeId()) != varType

void MumbleAPI::getMumbleSetting_bool_v_1_0_x(mumble_plugin_id_t callerID, mumble_settings_key_t key, bool *outValue,
std::shared_ptr< api_promise_t > promise) {
Expand Down
18 changes: 0 additions & 18 deletions src/mumble/ASIOInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ void ASIOInit::initialize() {
DWORD keynamelen = 255;
WCHAR keyname[255];
while (RegEnumKeyEx(hkDevs, idx++, keyname, &keynamelen, nullptr, nullptr, nullptr, &ft) == ERROR_SUCCESS) {
#if QT_VERSION >= 0x060000
QString name = QString::fromUtf16(reinterpret_cast< char16_t * >(keyname), keynamelen);
#else
QString name = QString::fromUtf16(reinterpret_cast< ushort * >(keyname), keynamelen);
#endif
if (RegOpenKeyEx(hkDevs, keyname, 0, KEY_READ, &hk) == ERROR_SUCCESS) {
DWORD dtype = REG_SZ;
WCHAR wclsid[255];
Expand All @@ -109,13 +105,8 @@ void ASIOInit::initialize() {
== ERROR_SUCCESS) {
if (datasize > 76)
datasize = 76;
#if QT_VERSION >= 0x060000
QString qsCls =
QString::fromUtf16(reinterpret_cast< char16_t * >(wclsid), datasize / 2).toLower().trimmed();
#else
QString qsCls =
QString::fromUtf16(reinterpret_cast< ushort * >(wclsid), datasize / 2).toLower().trimmed();
#endif
if (!blacklist.contains(qsCls.toLower()) && !FAILED(CLSIDFromString(wclsid, &clsid))) {
bFound = true;
}
Expand Down Expand Up @@ -163,11 +154,7 @@ ASIOConfig::ASIOConfig(Settings &st) : ConfigWidget(st) {
DWORD idx = 0;
DWORD keynamelen = keynamebufsize;
while (RegEnumKeyEx(hkDevs, idx++, keyname, &keynamelen, nullptr, nullptr, nullptr, &ft) == ERROR_SUCCESS) {
#if QT_VERSION >= 0x060000
QString deviceName = QString::fromUtf16(reinterpret_cast< char16_t * >(keyname), keynamelen);
#else
QString deviceName = QString::fromUtf16(reinterpret_cast< ushort * >(keyname), keynamelen);
#endif
HKEY hk;
if (RegOpenKeyEx(hkDevs, keyname, 0, KEY_READ, &hk) == ERROR_SUCCESS) {
DWORD dtype = REG_SZ;
Expand All @@ -177,13 +164,8 @@ ASIOConfig::ASIOConfig(Settings &st) : ConfigWidget(st) {
== ERROR_SUCCESS) {
if (datasize > 76)
datasize = 76;
#if QT_VERSION >= 0x060000
QString qsCls =
QString::fromUtf16(reinterpret_cast< char16_t * >(wclsid), datasize / 2).toLower().trimmed();
#else
QString qsCls =
QString::fromUtf16(reinterpret_cast< ushort * >(wclsid), datasize / 2).toLower().trimmed();
#endif
CLSID clsid;
if (!blacklist.contains(qsCls) && !FAILED(CLSIDFromString(wclsid, &clsid))) {
ASIODev ad(std::move(deviceName), qsCls);
Expand Down
7 changes: 1 addition & 6 deletions src/mumble/AudioStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,7 @@ AudioStats::AudioStats(QWidget *p) : QDialog(p) {
AudioStats::~AudioStats() {
}

#if QT_VERSION >= 0x050500
# define FORMAT_TO_TXT(format, arg) txt = QString::asprintf(format, arg)
#else
// sprintf() has been deprecated in Qt 5.5 in favor for the static QString::asprintf()
# define FORMAT_TO_TXT(format, arg) txt.sprintf(format, arg)
#endif
#define FORMAT_TO_TXT(format, arg) txt = QString::asprintf(format, arg)
void AudioStats::on_Tick_timeout() {
AudioInputPtr ai = Global::get().ai;

Expand Down
4 changes: 0 additions & 4 deletions src/mumble/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@ void ConfigDialog::updateListView() {
int configNavbarWidth = 0;

foreach (ConfigWidget *cw, qmWidgets) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
configNavbarWidth = qMax(configNavbarWidth, qfm.horizontalAdvance(cw->title()));
#else
configNavbarWidth = qMax(configNavbarWidth, qfm.width(cw->title()));
#endif

QListWidgetItem *i = new QListWidgetItem(qlwIcons);
i->setIcon(cw->icon());
Expand Down
24 changes: 5 additions & 19 deletions src/mumble/ConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ServerView::ServerView(QWidget *p) : QTreeWidget(p) {
siLAN->setExpanded(true);
siLAN->setHidden(true);
#else
siLAN = nullptr;
siLAN = nullptr;
#endif

if (!Global::get().s.bDisablePublicList) {
Expand All @@ -130,11 +130,7 @@ ServerView::~ServerView() {
delete siPublic;
}

#if QT_VERSION >= 0x060000
QMimeData *ServerView::mimeData(const QList< QTreeWidgetItem * > &mimeitems) const {
#else
QMimeData *ServerView::mimeData(const QList< QTreeWidgetItem * > mimeitems) const {
#endif
if (mimeitems.isEmpty())
return nullptr;

Expand Down Expand Up @@ -233,7 +229,7 @@ ServerItem::ServerItem(const FavoriteServer &fs) : QTreeWidgetItem(QTreeWidgetIt
qsHostname = fs.qsHostname;
}
#else
qsHostname = fs.qsHostname;
qsHostname = fs.qsHostname;
#endif
init();
}
Expand Down Expand Up @@ -274,7 +270,7 @@ ServerItem::ServerItem(const QString &name, const QString &host, unsigned short
qsHostname = host;
}
#else
qsHostname = host;
qsHostname = host;
#endif
init();
}
Expand Down Expand Up @@ -1216,7 +1212,7 @@ void ConnectDialog::on_qaFavoriteEdit_triggered() {
else
host = si->qsHostname;
#else
host = si->qsHostname;
host = si->qsHostname;
#endif
ConnectDialogEdit *cde = new ConnectDialogEdit(this, si->qsName, host, si->qsUsername, si->usPort, si->qsPassword);

Expand All @@ -1243,7 +1239,7 @@ void ConnectDialog::on_qaFavoriteEdit_triggered() {
si->zeroconfRecord = BonjourRecord();
}
#else
si->qsHostname = cde->qsHostname;
si->qsHostname = cde->qsHostname;
#endif
startDns(si);
}
Expand Down Expand Up @@ -1422,13 +1418,8 @@ void ConnectDialog::onResolved(const BonjourRecord record, const QString host, c

void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
QSet< ServerItem * > items;
# if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QSet< ServerItem * > old =
QSet< ServerItem * >(qtwServers->siLAN->qlChildren.begin(), qtwServers->siLAN->qlChildren.end());
# else
// In Qt 5.14 QList::toSet() has been deprecated as there exists a dedicated constructor of QSet for this now
QSet< ServerItem * > old = qtwServers->siLAN->qlChildren.toSet();
# endif

foreach (const BonjourRecord &record, list) {
bool found = false;
Expand Down Expand Up @@ -1767,12 +1758,7 @@ void ConnectDialog::sendPing(const QHostAddress &host, unsigned short port, Vers
if (qhPingRand.contains(addr)) {
uiRand = qhPingRand.value(addr);
} else {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
uiRand = QRandomGenerator::global()->generate64() << 32;
#else
// Qt 5.10 introduces the QRandomGenerator class and in Qt 5.15 qrand got deprecated in its favor
uiRand = (static_cast< quint64 >(qrand()) << 32) | static_cast< quint64 >(qrand());
#endif
qhPingRand.insert(addr, uiRand);
}

Expand Down
4 changes: 0 additions & 4 deletions src/mumble/ConnectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ class ServerView : public QTreeWidget {
void fixupName(ServerItem *si);

protected:
#if QT_VERSION >= 0x060000
QMimeData *mimeData(const QList< QTreeWidgetItem * > &) const Q_DECL_OVERRIDE;
#else
QMimeData *mimeData(const QList< QTreeWidgetItem * >) const Q_DECL_OVERRIDE;
#endif
QStringList mimeTypes() const Q_DECL_OVERRIDE;
Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
bool dropMimeData(QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction) Q_DECL_OVERRIDE;
Expand Down
4 changes: 0 additions & 4 deletions src/mumble/GKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ GKeyLibrary::GKeyLibrary() {
if (RegOpenKeyEx(GKEY_LOGITECH_DLL_REG_HKEY, GKEY_LOGITECH_DLL_REG_PATH, 0, KEY_READ, &key) == ERROR_SUCCESS) {
LONG err = RegQueryValueEx(key, L"", nullptr, &type, reinterpret_cast< LPBYTE >(wcLocation), &len);
if (err == ERROR_SUCCESS && type == REG_SZ) {
#if QT_VERSION >= 0x060000
const auto qsLocation = QString::fromUtf16(reinterpret_cast< char16_t * >(wcLocation), len / 2);
#else
const auto qsLocation = QString::fromUtf16(reinterpret_cast< ushort * >(wcLocation), len / 2);
#endif
qWarning("GKeyLibrary: Found ServerBinary with libLocation = \"%s\", len = %lu", qPrintable(qsLocation),
static_cast< unsigned long >(len));
alternatives << qsLocation;
Expand Down
Loading

0 comments on commit 4148f9b

Please sign in to comment.