From bd1e6d41f0f1917cb16833371d32f9944f522651 Mon Sep 17 00:00:00 2001 From: xiota Date: Sun, 19 Nov 2023 16:51:25 -0800 Subject: [PATCH] Port to Qt6 --- .clang-format | 1 + CMakeLists.txt | 86 ++++++++++++++------------- doc/generate.sh | 2 +- src/AutoActionForm.h | 1 + src/ClipboardMonitor.cpp | 15 +++-- src/ClipboardMonitor.h | 4 +- src/DropBox.cpp | 2 +- src/InfoBar.cpp | 2 +- src/MainTab.cpp | 2 +- src/MainWindow.cpp | 4 +- src/MyFileDialog.cpp | 2 +- src/MyTrayIcon.h | 1 + src/NetIface.cpp | 7 ++- src/NewTransferDlg.cpp | 6 +- src/Proxy.cpp | 4 +- src/Queue.cpp | 5 +- src/QueueMgr.cpp | 4 +- src/ScheduledActionDlg.cpp | 4 +- src/Scheduler.cpp | 4 +- src/Transfer.cpp | 2 +- src/Transfer.h | 1 + src/TransfersModel.cpp | 2 +- src/UserAuthDlg.h | 4 +- src/XmlRpc.cpp | 6 +- src/captcha/Captcha.cpp | 2 +- src/dbus/DbusAdaptor.h | 1 - src/dbus/DbusImpl.cpp | 6 +- src/engines/CurlDownload.cpp | 7 ++- src/engines/CurlPoller.cpp | 3 +- src/engines/CurlStat.cpp | 2 +- src/engines/CurlUpload.cpp | 5 +- src/engines/GeneralDownloadForms.cpp | 3 +- src/engines/HttpDetails.cpp | 8 ++- src/engines/HttpFtpSettings.cpp | 4 +- src/engines/HttpMirrorsDlg.cpp | 14 +++-- src/engines/JavaDownload.cpp | 9 +-- src/engines/JavaDownload.h | 2 +- src/engines/JavaExtractor.cpp | 4 +- src/engines/JavaExtractor.h | 4 +- src/engines/TorrentDownload.cpp | 31 +++++----- src/engines/TorrentDownload.h | 4 +- src/engines/TorrentSettings.cpp | 2 +- src/engines/UrlClient.cpp | 7 ++- src/fatrat.cpp | 8 +-- src/java/JClass.cpp | 4 +- src/java/JMap.cpp | 2 +- src/java/JObject.cpp | 2 +- src/java/JSettings.cpp | 3 +- src/remote/HttpService.cpp | 22 +++---- src/remote/HttpService.h | 8 +-- src/remote/XmlRpcService.cpp | 8 +-- src/rss/RssFetcher.cpp | 87 +++++++++++++++++----------- src/rss/RssFetcher.h | 6 +- src/rss/RssRegexpDlg.cpp | 21 ++++--- src/tools/TorrentSearch.cpp | 25 ++++---- src/tooltips/BaseToolTip.cpp | 5 +- src/util/BalloonTip.cpp | 10 ++-- 57 files changed, 278 insertions(+), 222 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..f6cb8ad9 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: Google diff --git a/CMakeLists.txt b/CMakeLists.txt index d92c84ad..3dd5db30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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) @@ -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") @@ -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) @@ -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 @@ -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) diff --git a/doc/generate.sh b/doc/generate.sh index 9796ef2e..13cafb6b 100755 --- a/doc/generate.sh +++ b/doc/generate.sh @@ -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 diff --git a/src/AutoActionForm.h b/src/AutoActionForm.h index 7e8c2b5c..b2c68355 100644 --- a/src/AutoActionForm.h +++ b/src/AutoActionForm.h @@ -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 { diff --git a/src/ClipboardMonitor.cpp b/src/ClipboardMonitor.cpp index 9701eb22..bf4cb6b5 100644 --- a/src/ClipboardMonitor.cpp +++ b/src/ClipboardMonitor.cpp @@ -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 nr; + QList nr; foreach (const QString& s, r) { - nr << QRegExp(s); + nr << QRegularExpression(s); } m_regexps = nr; } @@ -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]); diff --git a/src/ClipboardMonitor.h b/src/ClipboardMonitor.h index 8adff611..beb815ef 100644 --- a/src/ClipboardMonitor.h +++ b/src/ClipboardMonitor.h @@ -28,7 +28,7 @@ respects for all of the code used other than "OpenSSL". #define CLIPBOARDMONITOR_H #include #include -#include +#include class ClipboardMonitor : public QObject { Q_OBJECT @@ -44,7 +44,7 @@ class ClipboardMonitor : public QObject { private: QClipboard* m_clipboard; bool m_bEnabledGlobal, m_bEnabledSelection; - QList m_regexps; + QList m_regexps; static ClipboardMonitor* m_instance; }; diff --git a/src/DropBox.cpp b/src/DropBox.cpp index 67f68219..88200a36 100644 --- a/src/DropBox.cpp +++ b/src/DropBox.cpp @@ -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); } diff --git a/src/InfoBar.cpp b/src/InfoBar.cpp index 29379f04..73f73671 100644 --- a/src/InfoBar.cpp +++ b/src/InfoBar.cpp @@ -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; } diff --git a/src/MainTab.cpp b/src/MainTab.cpp index 0db62cba..3c75dd4a 100644 --- a/src/MainTab.cpp +++ b/src/MainTab.cpp @@ -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(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 839770f4..7826f8f6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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 @@ -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(); diff --git a/src/MyFileDialog.cpp b/src/MyFileDialog.cpp index 1a6f11b3..00e76b53 100644 --- a/src/MyFileDialog.cpp +++ b/src/MyFileDialog.cpp @@ -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 diff --git a/src/MyTrayIcon.h b/src/MyTrayIcon.h index 1ca2798c..eff187ce 100644 --- a/src/MyTrayIcon.h +++ b/src/MyTrayIcon.h @@ -26,6 +26,7 @@ respects for all of the code used other than "OpenSSL". #ifndef MYTRAYICON_H #define MYTRAYICON_H +#include #include #include diff --git a/src/NetIface.cpp b/src/NetIface.cpp index bbfc9406..37077398 100644 --- a/src/NetIface.cpp +++ b/src/NetIface.cpp @@ -27,6 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "NetIface.h" #include +#include #include #include @@ -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; @@ -57,7 +59,8 @@ QPair 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) { diff --git a/src/NewTransferDlg.cpp b/src/NewTransferDlg.cpp index 3bc70137..99749552 100644 --- a/src/NewTransferDlg.cpp +++ b/src/NewTransferDlg.cpp @@ -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); } */ diff --git a/src/Proxy.cpp b/src/Proxy.cpp index 287016fe..2732c4de 100644 --- a/src/Proxy.cpp +++ b/src/Proxy.cpp @@ -45,7 +45,7 @@ QList 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; } @@ -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(); diff --git a/src/Queue.cpp b/src/Queue.cpp index c9c3d2e4..9b9c1da5 100644 --- a/src/Queue.cpp +++ b/src/Queue.cpp @@ -34,6 +34,7 @@ respects for all of the code used other than "OpenSSL". #include #include #include +#include #include "QueueMgr.h" #include "Settings.h" @@ -285,7 +286,7 @@ void Queue::add(QList 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; @@ -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 diff --git a/src/QueueMgr.cpp b/src/QueueMgr.cpp index 8114b98a..65c4afc6 100644 --- a/src/QueueMgr.cpp +++ b/src/QueueMgr.cpp @@ -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; } } @@ -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]); } diff --git a/src/ScheduledActionDlg.cpp b/src/ScheduledActionDlg.cpp index 09117785..bd281c1e 100644 --- a/src/ScheduledActionDlg.cpp +++ b/src/ScheduledActionDlg.cpp @@ -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(); diff --git a/src/Scheduler.cpp b/src/Scheduler.cpp index 38839599..19258334 100644 --- a/src/Scheduler.cpp +++ b/src/Scheduler.cpp @@ -53,7 +53,7 @@ void Scheduler::loadActions(QList& list) { ScheduledAction a; g_settings->setArrayIndex(i); a.name = g_settings->value("name").toString(); - a.queue = g_settings->value("queueUUID").toString(); + a.queue = QUuid::fromString(g_settings->value("queueUUID").toString()); a.action = (ScheduledAction::ActionType)g_settings->value("action").toInt(); a.whenOneTime = QDateTime::fromString( g_settings->value("whenOneTime").toString(), Qt::ISODate); @@ -90,7 +90,7 @@ void Scheduler::saveActions(const QList& items) { for (int i = 0; i < 7; i++) days[i] = a.daysRepeated[i] ? '1' : '0'; days[7] = 0; - g_settings->setValue("daysRepeated", days); + g_settings->setValue("daysRepeated", QString::fromUtf8(days)); } g_settings->endArray(); diff --git a/src/Transfer.cpp b/src/Transfer.cpp index 0b7724bd..f38fb4c8 100644 --- a/src/Transfer.cpp +++ b/src/Transfer.cpp @@ -354,7 +354,7 @@ void Transfer::load(const QDomNode& map) { up = getXMLProperty(map, "uplimit").toInt(); m_strComment = getXMLProperty(map, "comment"); m_nTimeRunning = getXMLProperty(map, "timerunning").toLongLong(); - m_uuid = getXMLProperty(map, "uuid"); + m_uuid = QUuid::fromString(getXMLProperty(map, "uuid")); if (m_uuid.isNull()) m_uuid = QUuid::createUuid(); diff --git a/src/Transfer.h b/src/Transfer.h index 761bec98..586731a5 100644 --- a/src/Transfer.h +++ b/src/Transfer.h @@ -35,6 +35,7 @@ respects for all of the code used other than "OpenSSL". #include #include "Logger.h" +#include "WidgetHostChild.h" struct EngineEntry; class QObject; diff --git a/src/TransfersModel.cpp b/src/TransfersModel.cpp index d2dc6484..b552a94e 100644 --- a/src/TransfersModel.cpp +++ b/src/TransfersModel.cpp @@ -333,7 +333,7 @@ void ProgressDelegate::paint(QPainter* painter, const QModelIndex& index) const { if (index.column() == 1) { TransfersModel* model = (TransfersModel*)index.internalPointer(); - QStyleOptionProgressBarV2 opts; + QStyleOptionProgressBar opts; const int row = index.row(); if (row < model->m_lastData.size()) { diff --git a/src/UserAuthDlg.h b/src/UserAuthDlg.h index baaf9ac9..86d24cd7 100644 --- a/src/UserAuthDlg.h +++ b/src/UserAuthDlg.h @@ -28,7 +28,7 @@ respects for all of the code used other than "OpenSSL". #define _USERAUTHDLG_H #include #include -#include +#include #include "Auth.h" #include "ui_UserAuthDlg.h" @@ -60,7 +60,7 @@ class UserAuthDlg : public QDialog, Ui_UserAuthDlg { public slots: virtual void accept() { if (m_bRegExpMode) { - QRegExp re(lineRegExp->text()); + QRegularExpression re(lineRegExp->text()); if (!re.isValid()) { QMessageBox::warning( this, "FatRat", diff --git a/src/XmlRpc.cpp b/src/XmlRpc.cpp index edd7e639..e46cd2b1 100644 --- a/src/XmlRpc.cpp +++ b/src/XmlRpc.cpp @@ -77,7 +77,7 @@ QByteArray createCallOrResponse(const QList& args, void insertArgument(QDomDocument& doc, QDomElement& where, const QVariant& what) { - switch (what.type()) { + switch (what.metaType().id()) { case QMetaType::Bool: insertValue(doc, where, "boolean", what.toBool() ? "1" : "0"); break; @@ -156,7 +156,7 @@ void insertArgument(QDomDocument& doc, QDomElement& where, } break; default: qDebug() << "XmlRpc::insertArgument(): Unsupported QVariant type:" - << what.type(); + << what.metaType().id(); } } @@ -254,7 +254,7 @@ QVariant parseValue(const QDomElement& where) { QVariant parsed = parseValue(v); variantList << parsed; - allstring &= parsed.type() == QVariant::String; + allstring &= parsed.metaType().id() == QVariant::String; v = v.nextSiblingElement("value"); } diff --git a/src/captcha/Captcha.cpp b/src/captcha/Captcha.cpp index 8d8e8ae3..4cfab444 100644 --- a/src/captcha/Captcha.cpp +++ b/src/captcha/Captcha.cpp @@ -32,7 +32,7 @@ respects for all of the code used other than "OpenSSL". QMap Captcha::m_cb; QList Captcha::m_decoders; int Captcha::m_next = 1; -QMutex Captcha::m_mutex(QMutex::Recursive); +QMutex Captcha::m_mutex; int Captcha::processCaptcha(QString url, CallbackFn callback) { QMutexLocker l(&m_mutex); diff --git a/src/dbus/DbusAdaptor.h b/src/dbus/DbusAdaptor.h index fa8cefd1..12992624 100644 --- a/src/dbus/DbusAdaptor.h +++ b/src/dbus/DbusAdaptor.h @@ -46,7 +46,6 @@ class QList; template class QMap; class QString; -class QStringList; class QVariant; /* diff --git a/src/dbus/DbusImpl.cpp b/src/dbus/DbusImpl.cpp index 7966758c..012fbfac 100644 --- a/src/dbus/DbusImpl.cpp +++ b/src/dbus/DbusImpl.cpp @@ -27,7 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "DbusImpl.h" #include -#include +#include #include #include @@ -62,9 +62,9 @@ QString DbusImpl::addTransfersNonInteractive(QString uris, QString target, if (uris.isEmpty()) throw RuntimeException("No URIs were passed"); if (!getSettingsValue("link_separator").toInt()) - listUris = uris.split('\n', QString::SkipEmptyParts); + listUris = uris.split('\n', Qt::SkipEmptyParts); else - listUris = uris.split(QRegExp("\\s+"), QString::SkipEmptyParts); + listUris = uris.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts); for (int i = 0; i < listUris.size(); i++) listUris[i] = listUris[i].trimmed(); diff --git a/src/engines/CurlDownload.cpp b/src/engines/CurlDownload.cpp index 3fa98205..f7b9958d 100644 --- a/src/engines/CurlDownload.cpp +++ b/src/engines/CurlDownload.cpp @@ -97,7 +97,7 @@ void CurlDownload::init(QString uri, QString dest) { if (obj.url.userInfo().isEmpty()) { QList auths = Auth::loadAuths(); foreach (Auth a, auths) { - if (!QRegExp(a.strRegExp).exactMatch(uri)) continue; + if (!QRegularExpression(a.strRegExp).match(uri).hasMatch()) continue; obj.url.setUserName(a.strUser); obj.url.setPassword(a.strPassword); @@ -109,7 +109,8 @@ void CurlDownload::init(QString uri, QString dest) { } } - obj.proxy = getSettingsValue("httpftp/defaultproxy").toString(); + obj.proxy = + QUuid::fromString(getSettingsValue("httpftp/defaultproxy").toString()); obj.ftpMode = UrlClient::FtpPassive; m_dir.setPath(dest); @@ -352,7 +353,7 @@ void CurlDownload::load(const QDomNode& map) { obj.url = getXMLProperty(url, "address"); obj.strReferrer = getXMLProperty(url, "referrer"); - obj.proxy = getXMLProperty(url, "proxy"); + obj.proxy = QUuid::fromString(getXMLProperty(url, "proxy")); obj.ftpMode = (UrlClient::FtpMode)getXMLProperty(url, "ftpmode").toInt(); obj.strBindAddress = getXMLProperty(url, "bindip"); obj.effective = getXMLProperty(url, "effective"); diff --git a/src/engines/CurlPoller.cpp b/src/engines/CurlPoller.cpp index 351d80e6..e1c4f63e 100644 --- a/src/engines/CurlPoller.cpp +++ b/src/engines/CurlPoller.cpp @@ -35,8 +35,7 @@ CurlPoller* CurlPoller::m_instance = 0; int CurlPoller::m_nTransferTimeout = 20; -CurlPoller::CurlPoller() - : m_bAbort(false), m_timeout(0), m_usersLock(QMutex::Recursive) { +CurlPoller::CurlPoller() : m_bAbort(false), m_timeout(0), m_usersLock() { m_curlTimeout = 0; curl_global_init(CURL_GLOBAL_SSL); m_curlm = curl_multi_init(); diff --git a/src/engines/CurlStat.cpp b/src/engines/CurlStat.cpp index 34692109..e941bb7d 100644 --- a/src/engines/CurlStat.cpp +++ b/src/engines/CurlStat.cpp @@ -67,7 +67,7 @@ void CurlStat::timeProcess(SpeedData& data, size_t bytes) { if (data.accum.first > 1000000LL) { // if (!data.accum.second) // qDebug() << "Pushing 0 bytes from accum, time " << - //data.accum.first; + // data.accum.first; data.nextStat %= MAX_STATS; data.stats[data.nextStat++] = data.accum; diff --git a/src/engines/CurlUpload.cpp b/src/engines/CurlUpload.cpp index 046e15a0..99a662b9 100644 --- a/src/engines/CurlUpload.cpp +++ b/src/engines/CurlUpload.cpp @@ -28,6 +28,7 @@ respects for all of the code used other than "OpenSSL". #include #include +#include #include "Auth.h" #include "CurlPoller.h" @@ -67,7 +68,7 @@ void CurlUpload::init(QString source, QString target) { if (m_strTarget.userInfo().isEmpty()) { QList auths = Auth::loadAuths(); foreach (Auth a, auths) { - if (!QRegExp(a.strRegExp).exactMatch(target)) continue; + if (!QRegularExpression(a.strRegExp).match(target).hasMatch()) continue; m_strTarget.setUserName(a.strUser); m_strTarget.setPassword(a.strPassword); @@ -242,7 +243,7 @@ void CurlUpload::load(const QDomNode& map) { m_strName = getXMLProperty(map, "name"); m_mode = (FtpMode)getXMLProperty(map, "ftpmode").toInt(); m_nDone = getXMLProperty(map, "done").toLongLong(); - m_proxy = getXMLProperty(map, "proxy"); + m_proxy = QUuid::fromString(getXMLProperty(map, "proxy")); m_strBindAddress = getXMLProperty(map, "bindaddr"); try { diff --git a/src/engines/GeneralDownloadForms.cpp b/src/engines/GeneralDownloadForms.cpp index e1171cdb..d17fe44b 100644 --- a/src/engines/GeneralDownloadForms.cpp +++ b/src/engines/GeneralDownloadForms.cpp @@ -212,7 +212,8 @@ void HttpUrlOptsDlg::init() { comboProxy->setCurrentIndex(0); if (m_proxy.isNull() && m_multi != 0) { - m_proxy = getSettingsValue("httpftp/defaultproxy").toString(); + m_proxy = + QUuid::fromString(getSettingsValue("httpftp/defaultproxy").toString()); } for (int i = 0; i < listProxy.size(); i++) { diff --git a/src/engines/HttpDetails.cpp b/src/engines/HttpDetails.cpp index 6e22bfcb..9cd40ccb 100644 --- a/src/engines/HttpDetails.cpp +++ b/src/engines/HttpDetails.cpp @@ -392,15 +392,17 @@ QMap HttpDetails::loadMirrors() { if (!openDataFile(&file, "/data/mirrors.txt")) return rv; QString nextGrp; QStringList list; - QRegExp re("\\[([^\\]]+)\\]"); + QRegularExpression re("\\[([^\\]]+)\\]"); while (!file.atEnd()) { QString line = file.readLine().trimmed(); if (line.isEmpty()) continue; - if (re.exactMatch(line)) { + + QRegularExpressionMatch match = re.match(line); + if (match.hasMatch()) { if (!nextGrp.isEmpty()) rv[nextGrp] = list; list.clear(); - nextGrp = re.cap(1); + nextGrp = match.captured(1); } else list << line; } diff --git a/src/engines/HttpFtpSettings.cpp b/src/engines/HttpFtpSettings.cpp index 830ed9cc..206f19cd 100644 --- a/src/engines/HttpFtpSettings.cpp +++ b/src/engines/HttpFtpSettings.cpp @@ -27,6 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "HttpFtpSettings.h" #include +#include #include "Settings.h" #include "UserAuthDlg.h" @@ -49,7 +50,8 @@ void HttpFtpSettings::load() { // LOAD PROXYS m_listProxy = Proxy::loadProxys(); - m_defaultProxy = getSettingsValue("httpftp/defaultproxy").toString(); + m_defaultProxy = + QUuid::fromString(getSettingsValue("httpftp/defaultproxy").toString()); comboDefaultProxy->clear(); comboDefaultProxy->addItem(tr("None", "No proxy")); diff --git a/src/engines/HttpMirrorsDlg.cpp b/src/engines/HttpMirrorsDlg.cpp index f2c49376..92428647 100644 --- a/src/engines/HttpMirrorsDlg.cpp +++ b/src/engines/HttpMirrorsDlg.cpp @@ -27,7 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "HttpMirrorsDlg.h" #include -#include +#include #include #include #include @@ -95,8 +95,8 @@ HttpMirrorsDlg::ProbeThread::ProbeThread( HttpMirrorsDlg::ProbeThread::~ProbeThread() {} void HttpMirrorsDlg::ProbeThread::run() { - QRegExp reTime("time=([0-9\\.]+) ms"); - QRegExp reTtl("ttl=(\\d+)"); + QRegularExpression reTime("time=([0-9\\.]+) ms"); + QRegularExpression reTtl("ttl=(\\d+)"); for (QMap::iterator it = m_servers.begin(); it != m_servers.end(); it++) { @@ -114,9 +114,11 @@ void HttpMirrorsDlg::ProbeThread::run() { while (!prc.atEnd()) { QString line = prc.readLine(); - // qDebug() << line; - if (reTime.indexIn(line) != -1) ms = reTime.cap(1).toDouble(); - if (reTtl.indexIn(line) != -1) ttl = reTtl.cap(1).toInt(); + QRegularExpressionMatch matchTime = reTime.match(line); + QRegularExpressionMatch matchTtl = reTtl.match(line); + + if (matchTime.hasMatch()) ms = matchTime.captured(1).toDouble(); + if (matchTtl.hasMatch()) ttl = matchTtl.captured(1).toInt(); } QTreeWidgetItem* item = it.value(); diff --git a/src/engines/JavaDownload.cpp b/src/engines/JavaDownload.cpp index 004516a6..731ba417 100644 --- a/src/engines/JavaDownload.cpp +++ b/src/engines/JavaDownload.cpp @@ -205,7 +205,7 @@ int JavaDownload::acceptable(QString uri, bool, const EngineEntry* e) { .arg(QString::fromStdString(en.name)) .arg(e.what())); } - } else if (en.regexp.exactMatch(uri)) + } else if (en.regexp.match(uri).hasMatch()) return 3; return 0; @@ -296,7 +296,7 @@ void JavaDownload::globalInit() { JObject cfgDlg = obj.getAnnotation(annConfigDialog); JavaEngine e = {"EXT - " + name.toStdString(), clsName.toStdString(), - QRegExp(regexp)}; + QRegularExpression(regexp)}; e.forceSingleTransfer = ann.call("forceSingleTransfer", JSignature().retBoolean()).toBool(); e.truncate = @@ -385,8 +385,9 @@ bool JavaDownloadOptsForm::accept() { QString newUrl = lineURL->text(); if (newUrl != m_download->m_strOriginal) { - if (!JavaDownload::m_engines[m_download->m_strClass].regexp.exactMatch( - newUrl)) { + if (!JavaDownload::m_engines[m_download->m_strClass] + .regexp.match(newUrl) + .hasMatch()) { QMessageBox::warning(getMainWindow(), "FatRat", tr("Invalid URL.")); return false; } diff --git a/src/engines/JavaDownload.h b/src/engines/JavaDownload.h index f9c2ae13..16bc8b7b 100644 --- a/src/engines/JavaDownload.h +++ b/src/engines/JavaDownload.h @@ -100,7 +100,7 @@ class JavaDownload : public CurlDownload, protected JavaPersistentVariables { struct JavaEngine { std::string name, shortName; - QRegExp regexp; + QRegularExpression regexp; bool forceSingleTransfer, truncate; JObject ownAcceptable; QString configDialog; diff --git a/src/engines/JavaExtractor.cpp b/src/engines/JavaExtractor.cpp index 23c67f67..1b5e0c56 100644 --- a/src/engines/JavaExtractor.cpp +++ b/src/engines/JavaExtractor.cpp @@ -74,7 +74,7 @@ int JavaExtractor::acceptable(QString uri, bool, const EngineEntry* e) { .arg(QString::fromStdString(en.name)) .arg(e.what())); } - } else if (en.regexp.exactMatch(uri)) + } else if (en.regexp.match(uri).hasMatch()) return 3; return 0; @@ -129,7 +129,7 @@ void JavaExtractor::globalInit() { qDebug() << "Regexp:" << regexp; JavaEngine e = {"EXT - " + name.toStdString(), clsName.toStdString(), - QRegExp(regexp)}; + QRegularExpression(regexp)}; if (instance.instanceOf( "info.dolezel.fatrat.plugins.extra.URLAcceptableFilter")) diff --git a/src/engines/JavaExtractor.h b/src/engines/JavaExtractor.h index bb548655..a00078d7 100644 --- a/src/engines/JavaExtractor.h +++ b/src/engines/JavaExtractor.h @@ -28,7 +28,7 @@ respects for all of the code used other than "OpenSSL". #define JAVAEXTRACTOR_H #include -#include +#include #include #include "JavaPersistentVariables.h" @@ -81,7 +81,7 @@ class JavaExtractor : public StaticTransferMessage, private: struct JavaEngine { std::string name, shortName; - QRegExp regexp; + QRegularExpression regexp; JObject ownAcceptable; QString targetClass; }; diff --git a/src/engines/TorrentDownload.cpp b/src/engines/TorrentDownload.cpp index 073cb329..5746859d 100644 --- a/src/engines/TorrentDownload.cpp +++ b/src/engines/TorrentDownload.cpp @@ -70,8 +70,8 @@ respects for all of the code used other than "OpenSSL". #ifdef WITH_WEBINTERFACE #define XMLRPCSERVICE_AVOID_SHA_CONFLICT -#include "remote/XmlRpcService.h" #include "Queue.h" +#include "remote/XmlRpcService.h" extern QReadWriteLock g_queuesLock; #endif @@ -88,7 +88,7 @@ extern QReadWriteLock g_queuesLock; libtorrent::session* TorrentDownload::m_session = 0; TorrentWorker* TorrentDownload::m_worker = 0; bool TorrentDownload::m_bDHT = false; -QList TorrentDownload::m_listBTLinks; +QList TorrentDownload::m_listBTLinks; QLabel* TorrentDownload::m_labelDHTStats = 0; QMutex TorrentDownload::m_mutexAlerts; @@ -127,7 +127,7 @@ int TorrentDownload::acceptable(QString uri, bool) { istorrent = false; for (int i = 0; i < m_listBTLinks.size(); i++) { - if (m_listBTLinks[i].exactMatch(uri)) { + if (m_listBTLinks[i].match(uri).hasMatch()) { istorrent = true; break; } else @@ -147,14 +147,14 @@ int TorrentDownload::acceptable(QString uri, bool) { void TorrentDownload::fillSettings(libtorrent::settings_pack& settings) { QString ua = getSettingsValue("torrent/ua").toString(); short s1 = 0, s2 = 0, s3 = 0, s4 = 0; - QRegExp reVersion("(\\d)\\.(\\d)\\.(\\d)\\.?(\\d)?"); - - if (reVersion.indexIn(ua) != -1) { - QStringList caps = reVersion.capturedTexts(); - s1 = caps[1].toShort(); - s2 = caps[2].toShort(); - s3 = caps[3].toShort(); - if (caps.size() >= 5) s4 = caps[4].toShort(); + QRegularExpression reVersion("(\\d)\\.(\\d)\\.(\\d)\\.?(\\d)?"); + + QRegularExpressionMatch match = reVersion.match(ua); + if (match.hasMatch()) { + s1 = match.captured(1).toShort(); + s2 = match.captured(2).toShort(); + s3 = match.captured(3).toShort(); + if (match.lastCapturedIndex() >= 4) s4 = match.captured(4).toShort(); } std::string fingerprint = @@ -259,8 +259,8 @@ void TorrentDownload::fillSettings(libtorrent::settings_pack& settings) { // Proxy settings - const Proxy proxy = - Proxy::getProxy(getSettingsValue("torrent/proxy").toString()); + const Proxy proxy = Proxy::getProxy( + QUuid::fromString(getSettingsValue("torrent/proxy").toString())); if (proxy.nType != Proxy::ProxyNone) { settings.set_str(libtorrent::settings_pack::proxy_hostname, @@ -330,7 +330,7 @@ void TorrentDownload::globalInit() { while (!file.atEnd()) { QByteArray line = file.readLine().trimmed(); if (line.isEmpty()) continue; - m_listBTLinks << QRegExp(line); + m_listBTLinks << QRegularExpression(line); } } @@ -502,7 +502,8 @@ void TorrentDownload::init(QString source, QString target) { void TorrentDownload::downloadTorrent(QString source) { qDebug() << "downloadTorrent()"; - QUuid webseed = getSettingsValue("torrent/proxy_webseed").toString(); + QUuid webseed = + QUuid::fromString(getSettingsValue("torrent/proxy_webseed").toString()); Proxy pr = Proxy::getProxy(webseed); m_pFileDownload = new QNetworkAccessManager(this); diff --git a/src/engines/TorrentDownload.h b/src/engines/TorrentDownload.h index 857e702a..a08cebc5 100644 --- a/src/engines/TorrentDownload.h +++ b/src/engines/TorrentDownload.h @@ -34,7 +34,7 @@ respects for all of the code used other than "OpenSSL". #endif #include -#include +#include #include #include #include @@ -160,7 +160,7 @@ class TorrentDownload : public Transfer, static libtorrent::session* m_session; static TorrentWorker* m_worker; static bool m_bDHT; - static QList m_listBTLinks; + static QList m_listBTLinks; static QLabel* m_labelDHTStats; static QMutex m_mutexAlerts; diff --git a/src/engines/TorrentSettings.cpp b/src/engines/TorrentSettings.cpp index 40020b56..334d3c96 100644 --- a/src/engines/TorrentSettings.cpp +++ b/src/engines/TorrentSettings.cpp @@ -95,7 +95,7 @@ void TorrentSettings::load() { QUuid uuidProxy; - uuidProxy = getSettingsValue("torrent/proxy").toString(); + uuidProxy = QUuid::fromString(getSettingsValue("torrent/proxy").toString()); for (int i = 0; i < m_listProxy.size(); i++) { int index; diff --git a/src/engines/UrlClient.cpp b/src/engines/UrlClient.cpp index cb86fd34..5e92a56b 100644 --- a/src/engines/UrlClient.cpp +++ b/src/engines/UrlClient.cpp @@ -24,6 +24,7 @@ along with this program; if not, see . #include #include +#include #include #include "CurlPollingMaster.h" @@ -246,8 +247,10 @@ void UrlClient::processContentDisposition(const QByteArray& con) { if (pos != -1) { QString name = con.mid(pos + 9); - QRegExp quoted("\"([^\"]+)\".*"); - if (quoted.exactMatch(name)) name = quoted.cap(1); + QRegularExpression quoted("\"([^\"]+)\".*"); + + QRegularExpressionMatch match = quoted.match(name); + if (match.hasMatch()) name = match.captured(1); name.replace('/', '_'); qDebug() << "Automatically renaming to" << name; diff --git a/src/fatrat.cpp b/src/fatrat.cpp index b7cecd6a..d0e69aef 100644 --- a/src/fatrat.cpp +++ b/src/fatrat.cpp @@ -74,15 +74,15 @@ respects for all of the code used other than "OpenSSL". #endif #ifdef WITH_JPLUGINS -#include "java/JVM.h" #include "engines/JavaDownload.h" #include "engines/JavaExtractor.h" #include "engines/JavaUpload.h" -#include "tools/FileSharingSearch.h" -#include "java/JClass.h" -#include "java/JString.h" #include "java/JArray.h" +#include "java/JClass.h" #include "java/JScope.h" +#include "java/JString.h" +#include "java/JVM.h" +#include "tools/FileSharingSearch.h" #endif using namespace std; diff --git a/src/java/JClass.cpp b/src/java/JClass.cpp index 15538883..709ea828 100644 --- a/src/java/JClass.cpp +++ b/src/java/JClass.cpp @@ -184,7 +184,7 @@ QVariant JClass::callStatic(const char* name, const char* sig, JValue JClass::variantToValue(QVariant& v) { // JScope s; - switch (v.type()) { + switch (v.metaType().id()) { case QVariant::Int: case QVariant::UInt: return JValue(v.toInt()); @@ -283,7 +283,7 @@ void JClass::setStaticValue(const char* name, const char* sig, QVariant value) { switch (sig[0]) { case '[': case 'L': { - if (value.type() == QVariant::String) { + if (value.metaType().id() == QVariant::String) { JString js(value.toString()); env->SetStaticObjectField(m_class, fid, js); } else { diff --git a/src/java/JMap.cpp b/src/java/JMap.cpp index b0c657d1..a6991e20 100644 --- a/src/java/JMap.cpp +++ b/src/java/JMap.cpp @@ -48,7 +48,7 @@ void JMap::put(JObject key, JObject value) { } JObject JMap::nativeToBoxed(QVariant var) { - switch (var.type()) { + switch (var.metaType().id()) { case QVariant::Bool: return nativeToBoxed(var.toBool()); case QVariant::Double: diff --git a/src/java/JObject.cpp b/src/java/JObject.cpp index 24ffa75f..8aaa6274 100644 --- a/src/java/JObject.cpp +++ b/src/java/JObject.cpp @@ -400,7 +400,7 @@ void JObject::setValue(const char* name, const char* sig, QVariant value) { switch (sig[0]) { case '[': case 'L': { - if (value.type() == QVariant::String) { + if (value.metaType().id() == QVariant::String) { JString js(value.toString()); env->SetObjectField(m_object, fid, js); } else { diff --git a/src/java/JSettings.cpp b/src/java/JSettings.cpp index 536491e9..b4ba502c 100644 --- a/src/java/JSettings.cpp +++ b/src/java/JSettings.cpp @@ -85,7 +85,8 @@ jobject JSettings::getValue(JNIEnv* env, jclass, jstring jname, JString name(jname); QVariant v = getSettingsValue(name.str(), def); - if (v.type() == QVariant::String && v.toString() == def) return defValue; + if (v.metaType().id() == QVariant::String && v.toString() == def) + return defValue; JObject obj = JMap::nativeToBoxed(v); qDebug() << obj.getClass().getClassName(); diff --git a/src/remote/HttpService.cpp b/src/remote/HttpService.cpp index a90ff11d..8a8e9b51 100644 --- a/src/remote/HttpService.cpp +++ b/src/remote/HttpService.cpp @@ -91,23 +91,25 @@ HttpService::HttpService() : m_port(0), m_server(nullptr) { addSettingsPage(si); - addHandler(QRegExp("/xmlrpc"), + addHandler(QRegularExpression("/xmlrpc"), std::bind(&XmlRpcService::createHandler, &m_xmlRpc)); - addHandler(QRegExp("/log.*"), + addHandler(QRegularExpression("/log.*"), []() { return new LogService(QLatin1String("/log")); }); - addHandler(QRegExp("/subclass.*"), + addHandler(QRegularExpression("/subclass.*"), []() { return new SubclassService(QLatin1String("/subclass")); }); - addHandler(QRegExp("/browse.*"), []() { + addHandler(QRegularExpression("/browse.*"), []() { return new TransferTreeBrowserService(QLatin1String("/browse")); }); - addHandler(QRegExp("/download"), []() { + addHandler(QRegularExpression("/download"), []() { return new TransferDownloadService(QLatin1String("/download")); }); - addHandler(QRegExp("/copyrights"), []() { + addHandler(QRegularExpression("/copyrights"), []() { return new FileRequestHandler("/copyrights", DATA_LOCATION "/README"); }); - addHandler(QRegExp("/captcha"), []() { return new CaptchaService; }); - addHandler(QRegExp("/websocket"), []() { return new WebSocketService; }); + addHandler(QRegularExpression("/captcha"), + []() { return new CaptchaService; }); + addHandler(QRegularExpression("/websocket"), + []() { return new WebSocketService; }); XmlRpcService::registerFunction( "HttpService.generateCertificate", generateCertificate, @@ -238,8 +240,8 @@ HTTPRequestHandler* HttpService::createRequestHandler( m_handlersMutex.lock(); - for (const QPair& e : m_handlers) { - if (e.first.exactMatch(uri)) { + for (const QPair& e : m_handlers) { + if (e.first.match(uri).hasMatch()) { m_handlersMutex.unlock(); return e.second(); } diff --git a/src/remote/HttpService.h b/src/remote/HttpService.h index 35f31552..b5394ec0 100644 --- a/src/remote/HttpService.h +++ b/src/remote/HttpService.h @@ -36,7 +36,7 @@ respects for all of the code used other than "OpenSSL". #include #include #include -#include +#include #include #include #include @@ -92,8 +92,8 @@ class HttpService : public QObject, public HTTPRequestHandlerFactory { void killCaptchaClients(); typedef std::function handler_t; - void addHandler(const QRegExp& path, handler_t handler) { - m_handlers << QPair(path, handler); + void addHandler(const QRegularExpression& path, handler_t handler) { + m_handlers << QPair(path, handler); } void logService(HTTPServerRequest& req, HTTPServerResponse& resp); @@ -112,7 +112,7 @@ class HttpService : public QObject, public HTTPRequestHandlerFactory { HTTPServer* m_server; std::unique_ptr m_socket; - QList> m_handlers; + QList> m_handlers; QMutex m_handlersMutex; XmlRpcService m_xmlRpc; diff --git a/src/remote/XmlRpcService.cpp b/src/remote/XmlRpcService.cpp index 08d92c11..05d6c156 100644 --- a/src/remote/XmlRpcService.cpp +++ b/src/remote/XmlRpcService.cpp @@ -63,20 +63,20 @@ static void checkArguments(const QList& args, .arg(args.size()) .arg(ntypes)); for (int i = 0; i < ntypes; i++) { - if (args[i].type() != types[i] && !args[i].canConvert(types[i])) + if (args[i].metaType().id() != types[i] && !args[i].canConvert(types[i])) throw XmlRpcService::XmlRpcError( 3, QString("Invalid argument type - #%1, received %2, expected %3") .arg(i) - .arg(args[i].type()) + .arg(args[i].metaType().id()) .arg(types[i])); } } static void checkType(QVariant var, QVariant::Type type) { - if (var.type() != type) { + if (var.metaType().id() != type) { throw XmlRpcService::XmlRpcError( 4, QString("Invalid subargument type - %1 instead of %2") - .arg(var.type()) + .arg(var.metaType().id()) .arg(type)); } } diff --git a/src/rss/RssFetcher.cpp b/src/rss/RssFetcher.cpp index 4f84cb7c..239b06de 100644 --- a/src/rss/RssFetcher.cpp +++ b/src/rss/RssFetcher.cpp @@ -31,6 +31,7 @@ respects for all of the code used other than "OpenSSL". #include #include #include +#include #include #include #include @@ -173,8 +174,8 @@ void RssFetcher::processItems() { void RssFetcher::processItem(QList& regexps, const RssItem& item) { for (int i = 0; i < regexps.size(); i++) { - if (regexps[i].regexp.indexIn(item.title) != -1 && - item.source == regexps[i].source) { + QRegularExpressionMatch match = regexps[i].regexp.match(item.title); + if (match.hasMatch() && item.source == regexps[i].source) { if (regexps[i].tvs != RssRegexp::None) { QString epid = generateEpisodeName(regexps[i], item.title); qDebug() << "Generated an episode name" << epid << "from" << item.title; @@ -188,13 +189,16 @@ void RssFetcher::processItem(QList& regexps, const RssItem& item) { QStringList urls; - if (!regexps[i].linkRegexp.isEmpty()) { + if (!regexps[i].linkRegexp.pattern().isEmpty()) { int index = 0; - while ((index = regexps[i].linkRegexp.indexIn(item.descr, index)) != - -1) { - QString link = regexps[i].linkRegexp.cap(0); + QRegularExpressionMatch match = + regexps[i].linkRegexp.match(item.descr, index); + + while (match.hasMatch()) { + QString link = match.captured(0); urls << link; - index += link.size(); + index = match.capturedEnd(0); + match = regexps[i].linkRegexp.match(item.descr, index); } } else urls << item.url; @@ -249,8 +253,9 @@ void RssFetcher::loadRegexps(QList& items) { RssRegexp item; g_settings->setArrayIndex(i); - item.regexp = - QRegExp(g_settings->value("regexp").toString(), Qt::CaseInsensitive); + item.regexp = QRegularExpression(g_settings->value("regexp").toString()); + item.regexp.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + item.queueUUID = g_settings->value("queueUUID").toString(); item.source = g_settings->value("source").toString(); item.target = g_settings->value("target").toString(); @@ -263,8 +268,11 @@ void RssFetcher::loadRegexps(QList& items) { item.excludeManuals = g_settings->value("excludeManuals").toBool(); item.queueIndex = -1; item.addPaused = g_settings->value("addPaused").toBool(); - item.linkRegexp = QRegExp(g_settings->value("linkRegexp").toString(), - Qt::CaseInsensitive); + + item.linkRegexp = + QRegularExpression(g_settings->value("linkRegexp").toString()); + item.linkRegexp.setPatternOptions( + QRegularExpression::CaseInsensitiveOption); items << item; } @@ -318,7 +326,7 @@ void RssFetcher::performManualCheck(QString torrentName) { loadRegexps(re); for (int i = 0; i < re.size(); i++) { - if (!re[i].excludeManuals || re[i].regexp.indexIn(torrentName) < 0) + if (!re[i].excludeManuals || !re[i].regexp.match(torrentName).hasMatch()) continue; QString episode = generateEpisodeName(re[i], torrentName); @@ -339,50 +347,61 @@ QString RssFetcher::generateEpisodeName(const RssRegexp& match, if (match.tvs == RssRegexp::None) return QString(); else if (match.tvs == RssRegexp::SeasonBased) { - QRegExp matcher1("(\\d+)x(\\d+)"), matcher2("S(\\d+)E(\\d+)"); - if (matcher1.indexIn(itemName) != -1) + QRegularExpression matcher1("(\\d+)x(\\d+)"), matcher2("S(\\d+)E(\\d+)"); + QRegularExpressionMatch match1 = matcher1.match(itemName); + QRegularExpressionMatch match2 = matcher2.match(itemName); + + if (match1.hasMatch()) rval = QString("S%1E%2") - .arg(matcher1.cap(1).toInt(), 2, 10, zero) - .arg(matcher1.cap(2).toInt(), 2, 10, zero); - else if (matcher2.indexIn(itemName) != -1) + .arg(match1.captured(1).toInt(), 2, 10, zero) + .arg(match1.captured(2).toInt(), 2, 10, zero); + else if (match2.hasMatch()) rval = QString("S%1E%2") - .arg(matcher2.cap(1).toInt(), 2, 10, zero) - .arg(matcher2.cap(2).toInt(), 2, 10, zero); + .arg(match2.captured(1).toInt(), 2, 10, zero) + .arg(match2.captured(2).toInt(), 2, 10, zero); } else if (match.tvs == RssRegexp::EpisodeBased) { - QRegExp matcher("\\d+"); - if (matcher.indexIn(itemName) != -1) - rval = QString("%1").arg(matcher.cap(1).toInt(), 4, 10, zero); + QRegularExpression matcher("\\d+"); + QRegularExpressionMatch match = matcher.match(itemName); + + if (match.hasMatch()) + rval = QString("%1").arg(match.captured(0).toInt(), 4, 10, zero); } else if (match.tvs == RssRegexp::DateBased) { - QRegExp matcher1("(\\d{4})[\\-\\. ](\\d\\d)[\\-\\. ](\\d\\d)"), + QRegularExpression matcher1("(\\d{4})[\\-\\. ](\\d\\d)[\\-\\. ](\\d\\d)"), matcher2("(\\d\\d)[\\-\\. ](\\d\\d)[\\-\\. ](\\d{2,4})"), matcher3("(\\d\\d?)[\\-\\. ](\\w{3,})[\\-\\. ](\\d{2,4})"); - if (matcher1.indexIn(itemName) != -1) { - int month = matcher1.cap(2).toInt(), day = matcher1.cap(3).toInt(); + + QRegularExpressionMatch matched1 = matcher1.match(itemName); + QRegularExpressionMatch matched2 = matcher2.match(itemName); + QRegularExpressionMatch matched3 = matcher3.match(itemName); + + if (matched1.hasMatch()) { + int month = matched1.captured(2).toInt(), + day = matched1.captured(3).toInt(); dayMonthHeuristics(day, month); rval = QString("%1-%2-%3") - .arg(matcher1.cap(1).toInt()) + .arg(matched1.captured(1).toInt()) .arg(month, 2, 10, zero) .arg(day, 2, 10, zero); - } else if (matcher2.indexIn(itemName) != -1) { - int year = matcher2.cap(3).toInt(); + } else if (matched2.hasMatch()) { + int year = matched2.captured(3).toInt(); if (year < 100) year += 2000; - int day = matcher2.cap(1).toInt(); - int month = matcher2.cap(2).toInt(); + int day = matched2.captured(1).toInt(); + int month = matched2.captured(2).toInt(); dayMonthHeuristics(day, month); rval = QString("%1-%2-%3") .arg(year) .arg(month, 2, 10, zero) .arg(day, 2, 10, zero); - } else if (matcher3.indexIn(itemName) != -1) { + } else if (matched3.hasMatch()) { const char* months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int month = 0; - int year = matcher3.cap(3).toInt(); + int year = matched3.captured(3).toInt(); if (year < 100) year += 2000; - QString m = matcher3.cap(2); + QString m = matched3.captured(2); for (int i = 0; i < 12; i++) { QString sshort = months[i]; sshort.resize(3); @@ -398,7 +417,7 @@ QString RssFetcher::generateEpisodeName(const RssRegexp& match, rval = QString("%1-%2-%3") .arg(year) .arg(month, 2, 10, zero) - .arg(matcher3.cap(1).toInt(), 2, 10, zero); + .arg(matched3.captured(1).toInt(), 2, 10, zero); } } } diff --git a/src/rss/RssFetcher.h b/src/rss/RssFetcher.h index 936316aa..48264a46 100644 --- a/src/rss/RssFetcher.h +++ b/src/rss/RssFetcher.h @@ -28,7 +28,7 @@ respects for all of the code used other than "OpenSSL". #define RSSFETCHER_H #include #include -#include +#include #include #include @@ -46,10 +46,10 @@ struct RssItem { struct RssRegexp { QString source, target; - QRegExp regexp; + QRegularExpression regexp; QString queueUUID, from, to; QStringList epDone; - QRegExp linkRegexp; + QRegularExpression linkRegexp; int queueIndex; bool excludeManuals, includeTrailers, includeRepacks, addPaused; diff --git a/src/rss/RssRegexpDlg.cpp b/src/rss/RssRegexpDlg.cpp index dc4994d5..141566ad 100644 --- a/src/rss/RssRegexpDlg.cpp +++ b/src/rss/RssRegexpDlg.cpp @@ -27,6 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "RssRegexpDlg.h" #include +#include #include #include @@ -170,7 +171,7 @@ int RssRegexpDlg::exec() { checkTVSNoManuals->setChecked(m_regexp.excludeManuals); checkAddPaused->setChecked(m_regexp.addPaused); - if (!m_regexp.linkRegexp.isEmpty()) { + if (!m_regexp.linkRegexp.pattern().isEmpty()) { radioParsingExtract->setChecked(true); lineParsingRegexp->setText(m_regexp.linkRegexp.pattern()); } @@ -182,7 +183,9 @@ int RssRegexpDlg::exec() { updateParsing(); if ((r = QDialog::exec()) == QDialog::Accepted) { - m_regexp.regexp = QRegExp(lineExpression->text(), Qt::CaseInsensitive); + m_regexp.regexp = QRegularExpression(lineExpression->text()); + m_regexp.regexp.setPatternOptions( + QRegularExpression::CaseInsensitiveOption); m_regexp.target = lineTarget->text(); m_regexp.queueUUID = @@ -206,8 +209,9 @@ int RssRegexpDlg::exec() { m_regexp.includeTrailers = checkTVSTrailers->isChecked(); m_regexp.excludeManuals = checkTVSNoManuals->isChecked(); m_regexp.addPaused = checkAddPaused->isChecked(); - m_regexp.linkRegexp = - QRegExp(lineParsingRegexp->text(), Qt::CaseInsensitive); + m_regexp.linkRegexp = QRegularExpression(lineParsingRegexp->text()); + m_regexp.linkRegexp.setPatternOptions( + QRegularExpression::CaseInsensitiveOption); } return r; @@ -230,8 +234,9 @@ void RssRegexpDlg::browse() { } void RssRegexpDlg::test() { - QRegExp r(lineExpression->text(), Qt::CaseInsensitive); - labelMatch->setPixmap((r.indexIn(lineText->text()) != -1) - ? QPixmap(":/states/completed.png") - : QPixmap(":/menu/delete.png")); + QRegularExpression r(lineExpression->text()); + r.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch match = r.match(lineText->text()); + labelMatch->setPixmap(match.hasMatch() ? QPixmap(":/states/completed.png") + : QPixmap(":/menu/delete.png")); } diff --git a/src/tools/TorrentSearch.cpp b/src/tools/TorrentSearch.cpp index 75cd905d..bee08961 100644 --- a/src/tools/TorrentSearch.cpp +++ b/src/tools/TorrentSearch.cpp @@ -36,7 +36,7 @@ respects for all of the code used other than "OpenSSL". #include #include #include -#include +#include #include #include #include @@ -95,8 +95,8 @@ TorrentSearch::TorrentSearch() : m_bSearching(false) { QTimer::singleShot(100, this, SLOT(setSearchFocus())); m_network = new QNetworkAccessManager(this); - m_network->setProxy( - Proxy::getProxy(g_settings->value("torrent/proxy_tracker").toString())); + m_network->setProxy(Proxy::getProxy(QUuid::fromString( + g_settings->value("torrent/proxy_tracker").toString()))); connect(m_network, SIGNAL(finished(QNetworkReply*)), this, SLOT(searchDone(QNetworkReply*))); } @@ -267,12 +267,12 @@ void TorrentSearch::parseResults(Engine* e, const QByteArray& data) { try { int end, start; - start = data.indexOf(e->beginning); + start = data.indexOf(e->beginning.toUtf8()); if (start < 0) throw RuntimeException( "Error parsing search engine's response - 'start'"); - end = data.indexOf(e->ending, start); + end = data.indexOf(e->ending.toUtf8(), start); if (end < 0) throw RuntimeException("Error parsing search engine's response - 'end'"); @@ -291,27 +291,28 @@ void TorrentSearch::parseResults(Engine* e, const QByteArray& data) { for (QMap::iterator it = e->regexps.begin(); it != e->regexps.end(); it++) { - QRegExp re(it.value().regexp); + QRegularExpression re(it.value().regexp); int pos = 0; + QRegularExpressionMatch match; for (int k = 0; k < it.value().match + 1; k++) { - pos = re.indexIn(ar, pos); + match = re.match(ar, pos); - if (pos < 0) + if (!match.hasMatch()) throw RuntimeException(QString("Failed to match \"%1\" in \"%2\"") .arg(it.key()) .arg(QString(ar))); else - pos++; // FIXME + pos = match.capturedEnd(0); // Move to the end of the match } QString text; if (e->formats.contains(it.key())) { text = e->formats[it.key()]; for (int i = 0; i < re.captureCount(); i++) - text = text.arg(re.cap(i + 1)); + text = text.arg(match.captured(i + 1)); } else { - text = re.cap(it.value().field + 1); + text = match.captured(it.value().field + 1); } QTextDocument doc; // FIXME: ineffective? @@ -406,7 +407,7 @@ QList TorrentSearch::splitArray(const QByteArray& src, int n, split = 0; QList out; - while ((n = src.indexOf(sep, split)) != -1) { + while ((n = src.indexOf(sep.toUtf8(), split)) != -1) { out << src.mid(split, n - split); split = n + sep.size(); } diff --git a/src/tooltips/BaseToolTip.cpp b/src/tooltips/BaseToolTip.cpp index 2f8a263d..25aadbd9 100644 --- a/src/tooltips/BaseToolTip.cpp +++ b/src/tooltips/BaseToolTip.cpp @@ -27,7 +27,7 @@ respects for all of the code used other than "OpenSSL". #include "BaseToolTip.h" #include -#include +#include BaseToolTip::BaseToolTip(QObject* master, QWidget* parent) : QLabel(parent) { setWindowFlags(Qt::ToolTip); @@ -47,8 +47,7 @@ void BaseToolTip::mousePressEvent(QMouseEvent*) { hide(); } void BaseToolTip::placeMe() // from Qt { QPoint pos = QCursor::pos(); - int s = QApplication::desktop()->screenNumber(pos); - QRect screen = QApplication::desktop()->screenGeometry(s); + QRect screen = QGuiApplication::primaryScreen()->geometry(); QPoint p = pos; p += QPoint(2, 16); diff --git a/src/util/BalloonTip.cpp b/src/util/BalloonTip.cpp index c8afb990..dd3394f2 100644 --- a/src/util/BalloonTip.cpp +++ b/src/util/BalloonTip.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include BalloonTip::BalloonTip(QWidget *parent, QIcon si, const QString &title, @@ -50,7 +50,7 @@ BalloonTip::BalloonTip(QWidget *parent, QIcon si, const QString &title, // smart size for the message label int limit = - QApplication::desktop()->availableGeometry(msgLabel).size().width() / 3; + QGuiApplication::primaryScreen()->availableGeometry().size().width() / 3; if (msgLabel->sizeHint().width() > limit) { msgLabel->setWordWrap(true); @@ -73,7 +73,7 @@ BalloonTip::BalloonTip(QWidget *parent, QIcon si, const QString &title, QLabel *iconLabel = new QLabel; iconLabel->setPixmap(si.pixmap(iconSize, iconSize)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - iconLabel->setMargin(2); + iconLabel->setContentsMargins(2, 2, 2, 2); layout->addWidget(iconLabel, 0, 0); layout->addWidget(titleLabel, 0, 1); } else { @@ -83,7 +83,7 @@ BalloonTip::BalloonTip(QWidget *parent, QIcon si, const QString &title, layout->addWidget(closeButton, 0, 2); layout->addWidget(msgLabel, 1, 0, 1, 3); layout->setSizeConstraint(QLayout::SetFixedSize); - layout->setMargin(3); + layout->setContentsMargins(3, 3, 3, 3); setLayout(layout); QPalette pal = palette(); @@ -109,7 +109,7 @@ void BalloonTip::paintEvent(QPaintEvent *) { void BalloonTip::resizeEvent(QResizeEvent *ev) { QWidget::resizeEvent(ev); } void BalloonTip::balloon(const QPoint &pos, int msecs, bool showArrow) { - QRect scr = QApplication::desktop()->screenGeometry(pos); + QRect scr = QGuiApplication::screenAt(pos)->geometry(); QSize sh = sizeHint(); const int border = 1; const int ah = 18, ao = 18, aw = 18, rc = 7;