Skip to content

Commit

Permalink
Port to Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
xiota committed Nov 20, 2023
1 parent 978757d commit bd1e6d4
Show file tree
Hide file tree
Showing 57 changed files with 278 additions and 222 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
86 changes: 46 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(fatrat)

cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00)

INCLUDE(CheckFunctionExists)
INCLUDE(CheckIncludeFiles)
Expand All @@ -13,17 +15,18 @@ INCLUDE(FindBoost)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5LinguistTools REQUIRED)

message(STATUS "XML: ${Qt5Xml_INCLUDE_DIRS}")
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS} ${Qt5Svg_INCLUDE_DIRS})
find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
find_package(Qt6 REQUIRED COMPONENTS DBus)
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
find_package(Qt6 REQUIRED COMPONENTS Network)
find_package(Qt6 REQUIRED COMPONENTS Svg)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(Qt6 REQUIRED COMPONENTS Xml)

message(STATUS "XML: ${Qt6Xml_INCLUDE_DIRS}")
include_directories(${Qt6Widgets_INCLUDE_DIRS} ${Qt6Xml_INCLUDE_DIRS}
${Qt6Network_INCLUDE_DIRS} ${Qt6Svg_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

ADD_DEFINITIONS(-DBOOST_FILESYSTEM_NARROW_ONLY)
Expand All @@ -46,8 +49,6 @@ if(WITH_EVERYTHING)
set(WITH_JPLUGINS ON)
endif(WITH_EVERYTHING)

ADD_DEFINITIONS(-std=c++14)

if(WITH_JPLUGINS)
set(WITH_CURL ON)

Expand Down Expand Up @@ -86,18 +87,18 @@ if(WITH_BITTORRENT)
#else(ASIO_FOUND)
# message(FATAL_ERROR "No Boost asio")
#endif(ASIO_FOUND)

find_package(Qt5WebEngine)
find_package(Qt5WebEngineWidgets)

if (Qt5WebEngine_FOUND)
find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
find_package(Qt6 REQUIRED COMPONENTS WebEngineWidgets)

if (Qt6WebEngineCore_FOUND)
set(HAVE_WEBENGINE TRUE)
set(QT_LIBRARIES ${QT_LIBRAIRES} Qt5::WebEngine Qt5::WebEngineWidgets)
else(Qt5WebEngine_FOUND)
message(WARNING "Qt WebEngine not found, BitTorrent search not available")
endif (Qt5WebEngine_FOUND)
set(QT_LIBRARIES ${QT_LIBRAIRES} Qt6::WebEngineCore Qt6::WebEngineWidgets)
else(Qt6WebEngineCore_FOUND)
message(WARNING "Qt WebEngineCore not found, BitTorrent search not available")
endif (Qt6WebEngineCore_FOUND)

include_directories(${Qt5WebEngine_INCLUDE_DIRS})
include_directories(${Qt6WebEngineCore_INCLUDE_DIRS})
ADD_DEFINITIONS(-DTORRENT_USE_OPENSSL)
endif(WITH_BITTORRENT)

Expand Down Expand Up @@ -127,8 +128,8 @@ CHECK_FUNCTION_EXISTS(kqueue HAVE_KQUEUE)
CONFIGURE_FILE(config.h.in config.h)

if(WITH_DOCUMENTATION)
find_package(Qt5Help REQUIRED)
set(QT_LIBRARIES ${QT_LIBRARIES} Qt5::Help)
find_package(Qt6Help REQUIRED)
set(QT_LIBRARIES ${QT_LIBRARIES} Qt6::Help)
endif(WITH_DOCUMENTATION)
if(WITH_WEBINTERFACE)
find_path(POCO_INCLUDE Poco/Net/HTTPServer.h DOC "Poco header location")
Expand Down Expand Up @@ -541,15 +542,15 @@ if(WITH_DOCUMENTATION)
)
endif(WITH_DOCUMENTATION)

qt5_wrap_cpp(fatrat_MOC_SRCS ${fatrat_MOC_HDRS})
qt6_wrap_cpp(fatrat_MOC_SRCS ${fatrat_MOC_HDRS})

set(fatrat_RCS
gfx/resources.qrc
)

qt5_wrap_ui(fatrat_UIS_H ${fatrat_UIS})
qt5_add_resources(fatrat_QRC_H gfx/resources.qrc)
qt5_add_translation(lrelease_outputs locale/fatrat_cs_CZ.ts
qt6_wrap_ui(fatrat_UIS_H ${fatrat_UIS})
qt6_add_resources(fatrat_QRC_H gfx/resources.qrc)
qt6_add_translation(lrelease_outputs locale/fatrat_cs_CZ.ts
locale/fatrat_pl_PL.ts locale/fatrat_tr_TR.ts locale/fatrat_sk_SK.ts locale/fatrat_ru_RU.ts locale/fatrat_fr_FR.ts
locale/fatrat_uk_UA.ts locale/fatrat_es_AR.ts locale/fatrat_es_ES.ts locale/fatrat_ca_ES.ts locale/fatrat_zh_CN.ts
locale/fatrat_zh_TW.ts locale/fatrat_sr_RS.ts locale/fatrat_sr_BA.ts locale/fatrat_de_DE.ts)
Expand All @@ -563,10 +564,10 @@ if (POSIX_LINUX)
endif (POSIX_LINUX)

target_link_libraries(fatrat ${DL_LDFLAGS} -lpthread ${QT_LIBRARIES}
Qt5::Widgets Qt5::Svg Qt5::Network Qt5::DBus Qt5::Xml
Qt6::Core5Compat Qt6::Widgets Qt6::Svg Qt6::Network Qt6::DBus Qt6::Xml
LibtorrentRasterbar::torrent-rasterbar ${gloox_LDFLAGS} ${curl_LDFLAGS} ${Boost_LIBRARIES}
${Poco_LIBRARIES} ${XATTR_LIBRARIES} crypto -export-dynamic)
target_link_libraries(fatrat-conf Qt5::Core)
${Poco_LIBRARIES} ${XATTR_LIBRARIES} crypto)
target_link_libraries(fatrat-conf Qt6::Core Qt6::Core5Compat)

set(fatrat_DEV_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/fatrat.h
Expand Down Expand Up @@ -646,11 +647,16 @@ if(WITH_JPLUGINS)
endif(WITH_JPLUGINS)

if(WITH_DOCUMENTATION)
execute_process(COMMAND qcollectiongenerator
${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhcp -o
${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhc)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhc DESTINATION share/fatrat/doc)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qch DESTINATION share/fatrat/doc)
find_program(QHELPGENERATOR_EXECUTABLE NAMES qhelpgenerator)
if(QHELPGENERATOR_EXECUTABLE)
execute_process(COMMAND ${QHELPGENERATOR_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhcp" -o
"${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhc")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qch DESTINATION share/fatrat/doc)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/fatrat.qhc DESTINATION share/fatrat/doc)
else()
message(WARNING "qhelpgenerator not found. Documentation not generated.")
endif()
endif(WITH_DOCUMENTATION)

install(FILES doc/fatrat.1 DESTINATION share/man/man1)
Expand Down
2 changes: 1 addition & 1 deletion doc/generate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
echo -- Compiling documentation
cd doc
exec qcollectiongenerator fatrat.qhcp -o fatrat.qhc
exec qhelpgenerator fatrat.qhcp -o fatrat.qhc
1 change: 1 addition & 0 deletions src/AutoActionForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ respects for all of the code used other than "OpenSSL".
#ifndef AUTOACTIONFORM_H
#define AUTOACTIONFORM_H

#include "WidgetHostChild.h"
#include "ui_AutoActionForm.h"

class AutoActionForm : public WidgetHostChild, Ui_AutoActionForm {
Expand Down
15 changes: 9 additions & 6 deletions src/ClipboardMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ void ClipboardMonitor::reloadSettings() {
m_bEnabledGlobal = getSettingsValue("clipboard/monitorglobal").toBool();
m_bEnabledSelection = getSettingsValue("clipboard/monitorselection").toBool();
QStringList r = getSettingsValue("clipboard/regexps").toStringList();
QList<QRegExp> nr;
QList<QRegularExpression> nr;

foreach (const QString& s, r) {
nr << QRegExp(s);
nr << QRegularExpression(s);
}
m_regexps = nr;
}
Expand All @@ -66,12 +66,15 @@ void ClipboardMonitor::dataChanged(QClipboard::Mode mode) {

QStringList links;

foreach (const QRegExp& re, m_regexps) {
foreach (const QRegularExpression& re, m_regexps) {
int pos = 0, start = links.size();

while ((pos = re.indexIn(text, pos)) != -1) {
links << re.cap(0);
pos += re.cap(0).length();
QRegularExpressionMatch match = re.match(text, pos);

while (match.hasMatch()) {
links << match.captured(0);
pos = match.capturedEnd(0);
match = re.match(text, pos);
}

for (int i = start; i < links.size(); i++) text.remove(links[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/ClipboardMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ respects for all of the code used other than "OpenSSL".
#define CLIPBOARDMONITOR_H
#include <QClipboard>
#include <QList>
#include <QRegExp>
#include <QRegularExpression>

class ClipboardMonitor : public QObject {
Q_OBJECT
Expand All @@ -44,7 +44,7 @@ class ClipboardMonitor : public QObject {
private:
QClipboard* m_clipboard;
bool m_bEnabledGlobal, m_bEnabledSelection;
QList<QRegExp> m_regexps;
QList<QRegularExpression> m_regexps;
static ClipboardMonitor* m_instance;
};

Expand Down
2 changes: 1 addition & 1 deletion src/DropBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void DropBox::mousePressEvent(QMouseEvent* event) {
if (event->buttons() == Qt::LeftButton) {
m_mx = event->globalX();
m_my = event->globalY();
} else if (event->buttons() == Qt::MidButton)
} else if (event->buttons() == Qt::MiddleButton)
g_wndMain->trayIconActivated(QSystemTrayIcon::MiddleClick);
}

Expand Down
2 changes: 1 addition & 1 deletion src/InfoBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void InfoBar::mousePressEvent(QMouseEvent* event) {
if (event->buttons() == Qt::LeftButton) {
m_mx = event->globalX();
m_my = event->globalY();
} else if (event->buttons() == Qt::MidButton)
} else if (event->buttons() == Qt::MiddleButton)
delete this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MainTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void MainTab::contextMenuEvent(QContextMenuEvent* event) {
}

void MainTab::mousePressEvent(QMouseEvent* event) {
if (event->buttons() == Qt::MidButton) {
if (event->buttons() == Qt::MiddleButton) {
QTabBar* bar = tabBar();
m_index = bar->tabAt(bar->mapFrom(this, event->pos()));
closeTab();
Expand Down
4 changes: 2 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ respects for all of the code used other than "OpenSSL".
#include "util/BalloonTip.h"

#ifdef WITH_JPLUGINS
#include "ExtensionMgr.h"
#include "engines/JavaAccountStatusWidget.h"
#include "engines/SettingsJavaPluginForm.h"
#include "java/JVM.h"
#include "ExtensionMgr.h"
#endif

#ifdef WITH_DOCUMENTATION
Expand Down Expand Up @@ -957,7 +957,7 @@ void MainWindow::addTransfer(QString uri, Transfer::Mode mode,
if (!sep)
uris = m_dlgNewTransfer->m_strURIs.split('\n', Qt::SkipEmptyParts);
else
uris = m_dlgNewTransfer->m_strURIs.split(QRegExp("\\s+"),
uris = m_dlgNewTransfer->m_strURIs.split(QRegularExpression("\\s+"),
Qt::SkipEmptyParts);

if (uris.isEmpty()) throw RuntimeException();
Expand Down
2 changes: 1 addition & 1 deletion src/MyFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ QString MyFileDialog::getExistingDirectory(QWidget* parent, QString caption,
QString dir) {
QFileDialog dlg(parent, caption, dir);

dlg.setFileMode(QFileDialog::DirectoryOnly);
dlg.setFileMode(QFileDialog::Directory);
if (dlg.exec() == QDialog::Accepted)
return dlg.directory().absolutePath();
else
Expand Down
1 change: 1 addition & 0 deletions src/MyTrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ respects for all of the code used other than "OpenSSL".

#ifndef MYTRAYICON_H
#define MYTRAYICON_H
#include <QEvent>
#include <QtDebug>
#include <cstdlib>

Expand Down
7 changes: 5 additions & 2 deletions src/NetIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ respects for all of the code used other than "OpenSSL".
#include "NetIface.h"

#include <QFile>
#include <QRegularExpression>
#include <QStringList>
#include <QtDebug>

Expand All @@ -39,7 +40,8 @@ QString getRoutingInterface4() {

while (1) {
QString line = route.readLine();
QStringList parts = line.split(QRegExp("\\W+"), QString::SkipEmptyParts);
QStringList parts =
line.split(QRegularExpression("\\W+"), Qt::SkipEmptyParts);

if (line.isEmpty()) break;

Expand All @@ -57,7 +59,8 @@ QPair<qint64, qint64> getInterfaceStats(QString iface) {

while (1) {
QString line = dev.readLine().replace(':', ' ');
QStringList parts = line.split(QRegExp("\\W+"), QString::SkipEmptyParts);
QStringList parts =
line.split(QRegularExpression("\\W+"), Qt::SkipEmptyParts);

if (line.isEmpty()) break;
if (parts[0] == iface) {
Expand Down
6 changes: 3 additions & 3 deletions src/NewTransferDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ void NewTransferDlg::textChanged()
QStringList list;
if(radioDownload->isChecked())
list = textURIs->toPlainText().split(QRegExp('\n'),
QString::SkipEmptyParts); else list =
textFiles->toPlainText().split(QRegExp('\n'), QString::SkipEmptyParts);
list = textURIs->toPlainText().split(QRegularExpression('\n'),
Qt::SkipEmptyParts); else list =
textFiles->toPlainText().split(QRegularExpression('\n'), Qt::SkipEmptyParts);
checkDetails->setEnabled(list.size() <= 1);
}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ QList<Proxy> Proxy::loadProxys() {
p.strUser = g_settings->value("user").toString();
p.strPassword = g_settings->value("password").toString();
p.nType = (Proxy::ProxyType)g_settings->value("type", 0).toInt();
p.uuid = g_settings->value("uuid").toString();
p.uuid = QUuid::fromString(g_settings->value("uuid").toString());

r << p;
}
Expand All @@ -61,7 +61,7 @@ Proxy Proxy::getProxy(QUuid uuid) {
Proxy p;
g_settings->setArrayIndex(i);

p.uuid = g_settings->value("uuid").toString();
p.uuid = QUuid::fromString(g_settings->value("uuid").toString());
if (p.uuid != uuid) continue;

p.strName = g_settings->value("name").toString();
Expand Down
5 changes: 3 additions & 2 deletions src/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ respects for all of the code used other than "OpenSSL".
#include <QList>
#include <QReadWriteLock>
#include <QtDebug>
#include <algorithm>

#include "QueueMgr.h"
#include "Settings.h"
Expand Down Expand Up @@ -285,7 +286,7 @@ void Queue::add(QList<Transfer*> d) {
int Queue::moveDown(int n, bool nolock) {
if (m_transfers.size() > n + 1) {
if (!nolock) m_lock.lockForWrite();
m_transfers.swap(n, n + 1);
std::swap(m_transfers[n], m_transfers[n + 1]);
if (!nolock) m_lock.unlock();

return n + 1;
Expand All @@ -296,7 +297,7 @@ int Queue::moveDown(int n, bool nolock) {
int Queue::moveUp(int n, bool nolock) {
if (n > 0) {
if (!nolock) m_lock.lockForWrite();
m_transfers.swap(n - 1, n);
std::swap(m_transfers[n - 1], m_transfers[n]);
if (!nolock) m_lock.unlock();
return n - 1;
} else
Expand Down
4 changes: 2 additions & 2 deletions src/QueueMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void QueueMgr::pauseAllTransfers() {
if (s == Transfer::Active || s == Transfer::ForcedActive ||
s == Transfer::Waiting) {
t->setState(Transfer::Paused);
m_paused[t->uuid()] = s;
m_paused[QUuid::fromString(t->uuid())] = s;
}
}

Expand All @@ -289,7 +289,7 @@ void QueueMgr::unpauseAllTransfers() {

for (int i = 0; i < q->size(); i++) {
Transfer* t = q->at(i);
QUuid uuid = t->uuid();
QUuid uuid = QUuid::fromString(t->uuid());
if (m_paused.contains(uuid) && t->state() == Transfer::Paused)
t->setState(m_paused[uuid]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ScheduledActionDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ void ScheduledActionDlg::save() {
if (index == -1)
m_action.queue = QUuid();
else
m_action.queue =
comboQueue->itemData(comboQueue->currentIndex()).toString();
m_action.queue = QUuid::fromString(
comboQueue->itemData(comboQueue->currentIndex()).toString());
m_action.name = lineName->text();
m_action.repeated = radioRepeated->isChecked();
m_action.whenRepeated = timeEdit->time();
Expand Down
Loading

0 comments on commit bd1e6d4

Please sign in to comment.