Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt 6 support #2069

Merged
merged 19 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 33 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tr_auto_option(USE_SYSTEM_MINIUPNPC "Use system miniupnpc library" AUTO)
tr_auto_option(USE_SYSTEM_NATPMP "Use system natpmp library" AUTO)
tr_auto_option(USE_SYSTEM_UTP "Use system utp library" AUTO)
tr_auto_option(USE_SYSTEM_B64 "Use system b64 library" AUTO)
tr_auto_option(USE_QT_VERSION "Use specific Qt version" AUTO 5 6)
tr_list_option(WITH_CRYPTO "Use specified crypto library" AUTO openssl cyassl polarssl ccrypto)
tr_auto_option(WITH_INOTIFY "Enable inotify support (on systems that support it)" AUTO)
tr_auto_option(WITH_KQUEUE "Enable kqueue support (on systems that support it)" AUTO)
Expand Down Expand Up @@ -117,7 +118,7 @@ set(GTK_MINIMUM 3.4.0)
set(GLIB_MINIMUM 2.50.1)
set(GIO_MINIMUM 2.26.0)
set(LIBAPPINDICATOR_MINIMUM 0.4.90)
set(QT5_MINIMUM 5.2)
set(QT_MINIMUM 5.6)
ckerr marked this conversation as resolved.
Show resolved Hide resolved

if(WIN32)
foreach(L C CXX)
Expand Down Expand Up @@ -233,34 +234,44 @@ if(ENABLE_QT)
set(ENABLE_QT_COM_INTEROP OFF)
set(ENABLE_QT_DBUS_INTEROP OFF)

set(QT5_REQUIRED_MODULES Core Gui Widgets Network LinguistTools)
set(QT5_OPTIONAL_MODULES DBus AxContainer AxServer)
set(QT_REQUIRED_MODULES Core Gui Widgets Network LinguistTools)
set(QT_OPTIONAL_MODULES DBus AxContainer AxServer)
set(MISSING_QT_MODULE)

if(WIN32)
list(APPEND QT5_REQUIRED_MODULES WinExtras)
set(Qt_NAMES Qt6 Qt5)
if(NOT USE_QT_VERSION STREQUAL "AUTO")
set(Qt_NAMES Qt${USE_QT_VERSION})
endif()

foreach(M ${QT5_REQUIRED_MODULES})
find_package(Qt5${M} ${QT5_MINIMUM} QUIET)
if(Qt5${M}_FOUND)
if(NOT M STREQUAL "LinguistTools")
list(APPEND QT_TARGETS Qt5::${M})
endif()
else()
set(QT_TARGETS)
break()
find_package(Qt NAMES ${Qt_NAMES} ${QT_MINIMUM} QUIET)
if(Qt_FOUND)
if(WIN32 AND Qt_VERSION_MAJOR EQUAL 5)
list(APPEND QT_REQUIRED_MODULES WinExtras)
endif()
endforeach()

foreach(M ${QT_REQUIRED_MODULES})
find_package(Qt${Qt_VERSION_MAJOR}${M} ${QT_MINIMUM} QUIET)
if(Qt${Qt_VERSION_MAJOR}${M}_FOUND)
if(NOT M STREQUAL "LinguistTools")
list(APPEND QT_TARGETS Qt${Qt_VERSION_MAJOR}::${M})
endif()
else()
set(QT_TARGETS)
set(MISSING_QT_MODULE "${M}")
break()
endif()
endforeach()
endif()

if(QT_TARGETS)
foreach(M ${QT5_OPTIONAL_MODULES})
find_package(Qt5${M} ${QT5_MINIMUM} QUIET)
if(Qt5${M}_FOUND)
list(APPEND QT_TARGETS Qt5::${M})
foreach(M ${QT_OPTIONAL_MODULES})
find_package(Qt${Qt_VERSION_MAJOR}${M} ${QT_MINIMUM} QUIET)
if(Qt${Qt_VERSION_MAJOR}${M}_FOUND)
list(APPEND QT_TARGETS Qt${Qt_VERSION_MAJOR}::${M})
endif()
endforeach()

if(Qt5AxContainer_FOUND AND Qt5AxServer_FOUND)
if(Qt${Qt_VERSION_MAJOR}AxContainer_FOUND AND Qt${Qt_VERSION_MAJOR}AxServer_FOUND)
set(ENABLE_QT_COM_INTEROP ON)

find_program(MIDL_EXECUTABLE midl)
Expand All @@ -269,15 +280,15 @@ if(ENABLE_QT)
endif()
endif()

if(Qt5DBus_FOUND)
if(Qt${Qt_VERSION_MAJOR}DBus_FOUND)
set(ENABLE_QT_DBUS_INTEROP ON)
endif()
endif()

set(QT_FOUND ON)
if(NOT QT_TARGETS OR NOT (ENABLE_QT_COM_INTEROP OR ENABLE_QT_DBUS_INTEROP))
if(QT_IS_REQUIRED)
message(FATAL_ERROR "Unable to find required Qt libraries.")
message(FATAL_ERROR "Unable to find required Qt libraries (Qt${Qt_VERSION_MAJOR}${MISSING_QT_MODULE})")
endif()
set(QT_FOUND OFF)
endif()
Expand Down
20 changes: 15 additions & 5 deletions cmake/TrMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,27 @@ function(tr_fixup_bundle_item BUNDLE_DIR BUNDLE_ITEMS DEP_DIRS)
endfunction()

macro(tr_qt_wrap_ui)
qt5_wrap_ui(${ARGN})
if(Qt_VERSION_MAJOR EQUAL 6)
qt6_wrap_ui(${ARGN})
else()
qt5_wrap_ui(${ARGN})
endif()
endmacro()

macro(tr_qt_add_resources)
qt5_add_resources(${ARGN})
if(Qt_VERSION_MAJOR EQUAL 6)
qt6_add_resources(${ARGN})
else()
qt5_add_resources(${ARGN})
endif()
endmacro()

macro(tr_qt_add_translation)
if (Qt5LinguistTools_VERSION VERSION_LESS 5.11.0)
qt5_add_translation(${ARGN})
if(Qt_VERSION_MAJOR EQUAL 6)
qt6_add_translation(${ARGN} OPTIONS -silent)
elseif(Qt_VERSION GREATER_EQUAL 5.11)
qt5_add_translation(${ARGN} OPTIONS -silent)
else()
qt5_add_translation(${ARGN} OPTIONS -silent)
qt5_add_translation(${ARGN})
endif()
endmacro()
3 changes: 2 additions & 1 deletion dist/msi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(NOT TR_THIRD_PARTY_DIR)
endif()

if(NOT TR_QT_DIR)
set(TR_QT_DIR "$<TARGET_FILE_DIR:Qt5::Core>/..")
set(TR_QT_DIR "$<TARGET_FILE_DIR:Qt${Qt_VERSION_MAJOR}::Core>/..")
endif()

find_msvc_crt_msm(TR_MSVC_CRT_MSM_FILE)
Expand Down Expand Up @@ -82,6 +82,7 @@ wix_candle(${PROJECT_NAME}_OBJS
"SrcDir=${CMAKE_INSTALL_PREFIX}"
"ThirdPartyDir=${TR_THIRD_PARTY_DIR}"
"QtDir=${TR_QT_DIR}"
"QtMajorVer=${Qt_VERSION_MAJOR}"
"LicenseFile=${CMAKE_CURRENT_SOURCE_DIR}/GPLv2.rtf"
"WebSrcDir=${WEBSRCDIR}"
"TrQmSrcDir=${TRQMSRCDIR}"
Expand Down
80 changes: 57 additions & 23 deletions dist/msi/components/QtClient.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ProgId Id="Transmission.QtClient" Description="Transmission Qt Client Class" />
</ProgId>
</Class>
</AppId>
</AppId>
ckerr marked this conversation as resolved.
Show resolved Hide resolved
</TypeLib>
</File>

Expand Down Expand Up @@ -85,40 +85,64 @@
</DirectoryRef>
<DirectoryRef Id="INSTALLDIR" FileSource="$(var.QtDir)\bin">

<Component Id="dll.qt5.core">
<File DiskId="1" KeyPath="yes" Name="Qt5Core.dll" />
<Component Id="dll.qt.core">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)Core.dll" />
</Component>
<Component Id="dll.qt5.dbus">
<File DiskId="1" KeyPath="yes" Name="Qt5DBus.dll" />
<Component Id="dll.qt.dbus">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)DBus.dll" />
</Component>
<Component Id="dll.qt5.gui">
<File DiskId="1" KeyPath="yes" Name="Qt5Gui.dll" />
<Component Id="dll.qt.gui">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)Gui.dll" />
</Component>
<Component Id="dll.qt5.network">
<File DiskId="1" KeyPath="yes" Name="Qt5Network.dll" />
<Component Id="dll.qt.network">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)Network.dll" />
</Component>
<Component Id="dll.qt5.widgets">
<File DiskId="1" KeyPath="yes" Name="Qt5Widgets.dll" />
<Component Id="dll.qt.widgets">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)Widgets.dll" />
</Component>
<Component Id="dll.qt5.winextras">
<File DiskId="1" KeyPath="yes" Name="Qt5WinExtras.dll" />
<?if $(var.QtMajorVer) = 5 ?>
<Component Id="dll.qt.winextras">
<File DiskId="1" KeyPath="yes" Name="Qt$(var.QtMajorVer)WinExtras.dll" />
</Component>
<?endif ?>

</DirectoryRef>
<DirectoryRef Id="INSTALLDIR" FileSource="$(var.QtDir)\plugins">

<?if $(var.QtMajorVer) = 6 ?>
<Directory Id="QTIMAGEFORMATSDIR" Name="imageformats">
<Component Id="dll.qt.plugins.imageformats.gif">
<File DiskId="1" KeyPath="yes" Name="qgif.dll" />
</Component>
<Component Id="dll.qt.plugins.imageformats.ico">
<File DiskId="1" KeyPath="yes" Name="qico.dll" />
</Component>
<Component Id="dll.qt.plugins.imageformats.jpeg">
<File DiskId="1" KeyPath="yes" Name="qjpeg.dll" />
</Component>
</Directory>
<?endif ?>
ckerr marked this conversation as resolved.
Show resolved Hide resolved

<Directory Id="QTPLATFORMDIR" Name="platforms">
<Component Id="dll.qt5.plugins.platforms.windows">
<Component Id="dll.qt.plugins.platforms.windows">
<File DiskId="1" KeyPath="yes" Name="qwindows.dll" />
</Component>
</Directory>

<Directory Id="QTSTYLESDIR" Name="styles">
<Component Id="dll.qt5.plugins.styles.windowsvista">
<Component Id="dll.qt.plugins.styles.windowsvista">
<File DiskId="1" KeyPath="yes" Name="qwindowsvistastyle.dll" />
</Component>
</Directory>

<?if $(var.QtMajorVer) = 6 ?>
<Directory Id="QTTLSDIR" Name="tls">
<Component Id="dll.qt.plugins.tls.openssl">
<File DiskId="1" KeyPath="yes" Name="qopensslbackend.dll" />
</Component>
</Directory>
<?endif ?>

</DirectoryRef>
<DirectoryRef Id="INSTALLDIR" FileSource="$(var.ThirdPartyDir)\bin">

Expand All @@ -133,14 +157,24 @@
<ComponentGroup Id="QtClientComponents">
<ComponentRef Id="exe.transmission.qt" />
<ComponentRef Id="conf.qt" />
<ComponentRef Id="dll.qt5.core" />
<ComponentRef Id="dll.qt5.dbus" />
<ComponentRef Id="dll.qt5.gui" />
<ComponentRef Id="dll.qt5.network" />
<ComponentRef Id="dll.qt5.widgets" />
<ComponentRef Id="dll.qt5.winextras" />
<ComponentRef Id="dll.qt5.plugins.platforms.windows" />
<ComponentRef Id="dll.qt5.plugins.styles.windowsvista" />
<ComponentRef Id="dll.qt.core" />
<ComponentRef Id="dll.qt.dbus" />
<ComponentRef Id="dll.qt.gui" />
<ComponentRef Id="dll.qt.network" />
<ComponentRef Id="dll.qt.widgets" />
<?if $(var.QtMajorVer) = 5 ?>
<ComponentRef Id="dll.qt.winextras" />
<?endif ?>
<?if $(var.QtMajorVer) = 6 ?>
<ComponentRef Id="dll.qt.plugins.imageformats.gif" />
<ComponentRef Id="dll.qt.plugins.imageformats.ico" />
<ComponentRef Id="dll.qt.plugins.imageformats.jpeg" />
<?endif ?>
<ComponentRef Id="dll.qt.plugins.platforms.windows" />
<ComponentRef Id="dll.qt.plugins.styles.windowsvista" />
<?if $(var.QtMajorVer) = 6 ?>
<ComponentRef Id="dll.qt.plugins.tls.openssl" />
<?endif ?>
<ComponentRef Id="dll.dbus" />
<ComponentGroupRef Id="QtClientTranslationsComponents" />
<ComponentGroupRef Id="QtTranslationsComponents" />
Expand Down
3 changes: 0 additions & 3 deletions qt/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,7 @@ int tr_main(int argc, char** argv)
{
InteropHelper::initialize();

#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
Application::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

Application::setAttribute(Qt::AA_UseHighDpiPixmaps);

Application app(argc, argv);
Expand Down
4 changes: 2 additions & 2 deletions qt/DetailsDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QMap>
#include <QMessageBox>
#include <QResizeEvent>
#include <QRegExp>
#include <QRegularExpression>
#include <QStringList>
#include <QStyle>
#include <QTreeWidgetItem>
Expand Down Expand Up @@ -1294,7 +1294,7 @@ void DetailsDialog::onAddTrackerClicked()
QSet<QString> urls;
torrent_ids_t ids;

for (auto const& line : text.split(QRegExp(QStringLiteral("[\r\n]+"))))
for (auto const& line : text.split(QRegularExpression(QStringLiteral("[\r\n]+"))))
{
QString const url = line.trimmed();
if (!line.isEmpty() && QUrl(url).isValid())
Expand Down
39 changes: 38 additions & 1 deletion qt/FaviconCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@
****
***/

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Q_NETWORK_EXPORT bool qIsEffectiveTLD(QStringView domain);
#endif

namespace
{

QString getTopLevelDomain(QUrl const& url)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)

auto const host = url.host();
auto const dot = QChar(QLatin1Char('.'));

for (auto dot_pos = host.indexOf(dot); dot_pos != -1; dot_pos = host.indexOf(dot, dot_pos + 1))
{
if (qIsEffectiveTLD(QStringView(&host.data()[dot_pos + 1], host.size() - dot_pos - 1)))
ckerr marked this conversation as resolved.
Show resolved Hide resolved
{
return host.mid(dot_pos);
}
}

return {};

#else

return url.topLevelDomain();

#endif
}

} // namespace

/***
****
***/

FaviconCache::FaviconCache()
: nam_(new QNetworkAccessManager(this))
{
Expand Down Expand Up @@ -119,7 +156,7 @@ FaviconCache::Key FaviconCache::getKey(QUrl const& url)
auto host = url.host();

// remove tld
auto const suffix = url.topLevelDomain();
auto const suffix = getTopLevelDomain(url);
host.truncate(host.size() - suffix.size());

// remove subdomain
Expand Down
2 changes: 1 addition & 1 deletion qt/FileTreeDelegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void FileTreeDelegate::paint(QPainter* painter, QStyleOptionViewItem const& opti
if (column == FileTreeModel::COL_PROGRESS)
{
QStyleOptionProgressBar p;
p.state = option.state | QStyle::State_Small;
p.state = option.state | QStyle::State_Horizontal | QStyle::State_Small;
p.direction = QApplication::layoutDirection();
p.rect = option.rect;
p.rect.setSize(QSize(option.rect.width() - 4, option.rect.height() - 8));
Expand Down
2 changes: 1 addition & 1 deletion qt/FileTreeItem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ QVariant FileTreeItem::data(int column, int role) const
case Qt::TextAlignmentRole:
if (column == FileTreeModel::COL_SIZE)
{
value = Qt::AlignRight + Qt::AlignVCenter;
value = static_cast<int>(Qt::AlignRight | Qt::AlignVCenter);
}

break;
Expand Down
6 changes: 3 additions & 3 deletions qt/FileTreeModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ForwardPathIterator : public PathIteratorBase
{
int new_slash_index = path_.lastIndexOf(SlashChar, slash_index_);
token_.truncate(0);
token_ += path_.midRef(new_slash_index + 1, slash_index_ - new_slash_index);
token_.append(&path_.data()[new_slash_index + 1], slash_index_ - new_slash_index);
slash_index_ = new_slash_index - 1;
return token_;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ class BackwardPathIterator : public PathIteratorBase
}

token_.truncate(0);
token_ += path_.midRef(slash_index_, new_slash_index - slash_index_);
token_.append(&path_.data()[slash_index_], new_slash_index - slash_index_);
slash_index_ = new_slash_index + 1;
return token_;
}
Expand Down Expand Up @@ -171,7 +171,7 @@ Qt::ItemFlags FileTreeModel::flags(QModelIndex const& index) const

if (index.column() == COL_WANTED)
{
i |= Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
i |= Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
}

return Qt::ItemFlags(i);
Expand Down