diff --git a/src/app/upgrade.h b/src/app/upgrade.h index e9e0ae211..06657f71f 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -29,34 +29,34 @@ #ifndef UPGRADE_H #define UPGRADE_H +#include +#include #include + #if LIBTORRENT_VERSION_NUM >= 10100 #include -#endif -#include -#include -#if LIBTORRENT_VERSION_NUM < 10100 +#else #include #endif - #include #include +#include +#include + #ifndef DISABLE_GUI #include #endif -#include -#include #ifdef Q_OS_MAC #include #endif #include "base/logger.h" +#include "base/preferences.h" #include "base/profile.h" #include "base/utils/fs.h" #include "base/utils/misc.h" #include "base/utils/string.h" -#include "base/preferences.h" bool userAcceptsUpgrade() { @@ -114,8 +114,9 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent = bool v3_3 = false; int queuePosition = 0; QString outFilePath = filepath; - QRegExp rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(.+)$")); - if (rx.indexIn(filepath) != -1) { + static const QRegularExpression rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(.+)$")); + const QRegularExpressionMatch rxMatch = rx.match(filepath); + if (rxMatch.hasMatch()) { // Old v3.3.x format had a number at the end indicating the queue position. // The naming scheme was '.fastresume.'. // However, QSaveFile, which uses QTemporaryFile internally, might leave @@ -127,14 +128,14 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent = // and is deleted, because it may be a corrupted/incomplete fastresume. // NOTE: When the upgrade code is removed, we must continue to perform // cleanup of non-commited QSaveFile/QTemporaryFile fastresumes - queuePosition = rx.cap(2).toInt(); - if ((rx.cap(2).size() == 6) && (queuePosition <= 99999)) { + queuePosition = rxMatch.captured(2).toInt(); + if ((rxMatch.captured(2).size() == 6) && (queuePosition <= 99999)) { Utils::Fs::forceRemove(filepath); return true; } v3_3 = true; - outFilePath.replace(QRegExp("\\.fastresume\\..+$"), ".fastresume"); + outFilePath.replace(QRegularExpression("\\.fastresume\\..+$"), ".fastresume"); } else { queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0); @@ -198,13 +199,15 @@ bool upgrade(bool ask = true) QStringList backupFiles = backupFolderDir.entryList( QStringList(QLatin1String("*.fastresume")), QDir::Files, QDir::Unsorted); - QRegExp rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); + const QRegularExpression rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); foreach (QString backupFile, backupFiles) { - if (rx.indexIn(backupFile) != -1) { - if (upgradeResumeFile(backupFolderDir.absoluteFilePath(backupFile), oldResumeData[rx.cap(1)].toHash())) - oldResumeData.remove(rx.cap(1)); + const QRegularExpressionMatch rxMatch = rx.match(backupFile); + if (rxMatch.hasMatch()) { + const QString hashStr = rxMatch.captured(1); + if (upgradeResumeFile(backupFolderDir.absoluteFilePath(backupFile), oldResumeData[hashStr].toHash())) + oldResumeData.remove(hashStr); else - Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent with hash: %1").arg(rx.cap(1)), Log::WARNING); + Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent with hash: %1").arg(hashStr), Log::WARNING); } else { Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent. Invalid fastresume file name: %1").arg(backupFile), Log::WARNING); diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index a3a7c8325..b306792c0 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -26,16 +26,17 @@ * exception statement from your version. */ -#include -#include -#include +#include "magneturi.h" #include #include #include +#include +#include +#include + #include "base/utils/string.h" -#include "magneturi.h" namespace { @@ -69,8 +70,8 @@ MagnetUri::MagnetUri(const QString &source) qDebug("Creating magnet link from bc link"); m_url = bcLinkToMagnet(source); } - else if (((source.size() == 40) && !source.contains(QRegExp("[^0-9A-Fa-f]"))) - || ((source.size() == 32) && !source.contains(QRegExp("[^2-7A-Za-z]")))) { + else if (((source.size() == 40) && !source.contains(QRegularExpression("[^0-9A-Fa-f]"))) + || ((source.size() == 32) && !source.contains(QRegularExpression("[^2-7A-Za-z]")))) { m_url = "magnet:?xt=urn:btih:" + source; } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index d5b8cdd0c..02b7a452c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -692,8 +692,8 @@ QString Session::torrentTempPath(const TorrentInfo &torrentInfo) const bool Session::isValidCategoryName(const QString &name) { - QRegExp re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"); - if (!name.isEmpty() && (re.indexIn(name) != 0)) { + static const QRegularExpression re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"); + if (!name.isEmpty() && (name.indexOf(re) != 0)) { qDebug() << "Incorrect category name:" << name; return false; } @@ -3829,11 +3829,12 @@ void Session::startUpTorrents() QMap queuedResumeData; int nextQueuePosition = 1; int numOfRemappedFiles = 0; - QRegExp rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); + const QRegularExpression rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); foreach (const QString &fastresumeName, fastresumes) { - if (rx.indexIn(fastresumeName) == -1) continue; + const QRegularExpressionMatch rxMatch = rx.match(fastresumeName); + if (!rxMatch.hasMatch()) continue; - QString hash = rx.cap(1); + QString hash = rxMatch.captured(1); QString fastresumePath = resumeDataDir.absoluteFilePath(fastresumeName); QByteArray data; AddTorrentData resumeData; diff --git a/src/base/http/connection.cpp b/src/base/http/connection.cpp index a90cae331..1b98f3502 100644 --- a/src/base/http/connection.cpp +++ b/src/base/http/connection.cpp @@ -30,7 +30,6 @@ #include "connection.h" -#include #include #include "base/logger.h" diff --git a/src/base/net/dnsupdater.cpp b/src/base/net/dnsupdater.cpp index 7710befa9..bcdd5f509 100644 --- a/src/base/net/dnsupdater.cpp +++ b/src/base/net/dnsupdater.cpp @@ -26,15 +26,16 @@ * exception statement from your version. */ +#include "dnsupdater.h" + #include -#include +#include #include #include #include "base/logger.h" #include "base/net/downloadhandler.h" #include "base/net/downloadmanager.h" -#include "dnsupdater.h" using namespace Net; @@ -89,9 +90,9 @@ void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data) Q_UNUSED(url); // Parse response - QRegExp ipregex("Current IP Address:\\s+([^<]+)"); - if (ipregex.indexIn(data) >= 0) { - QString ipStr = ipregex.cap(1); + const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)").match(data); + if (ipRegexMatch.hasMatch()) { + QString ipStr = ipRegexMatch.captured(1); qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr; QHostAddress newIp(ipStr); if (!newIp.isNull()) { @@ -246,8 +247,8 @@ void DNSUpdater::updateCredentials() } if (m_domain != pref->getDynDomainName()) { m_domain = pref->getDynDomainName(); - QRegExp domain_regex("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"); - if (domain_regex.indexIn(m_domain) < 0) { + const QRegularExpressionMatch domainRegexMatch = QRegularExpression("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$").match(m_domain); + if (!domainRegexMatch.hasMatch()) { logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL); m_lastIP.clear(); m_ipCheckTimer.stop(); diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index ae044fdf2..9016b175c 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -45,6 +45,7 @@ #ifdef Q_OS_WIN #include #include +#include #endif #ifdef Q_OS_MAC @@ -1021,13 +1022,14 @@ bool Preferences::isMagnetLinkAssocSet() QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat); // Check magnet link assoc - QRegExp exe_reg("\"([^\"]+)\".*"); - QString shell_command = Utils::Fs::toNativePath(settings.value("magnet/shell/open/command/Default", "").toString()); - if (exe_reg.indexIn(shell_command) < 0) + const QString shellCommand = Utils::Fs::toNativePath(settings.value("magnet/shell/open/command/Default", "").toString()); + + const QRegularExpressionMatch exeRegMatch = QRegularExpression("\"([^\"]+)\".*").match(shellCommand); + if (!exeRegMatch.hasMatch()) return false; - QString assoc_exe = exe_reg.cap(1); - qDebug("exe: %s", qUtf8Printable(assoc_exe)); - if (assoc_exe.compare(Utils::Fs::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0) + + const QString assocExe = exeRegMatch.captured(1); + if (assocExe.compare(Utils::Fs::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0) return false; return true; diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 1e86f548b..73bfd8781 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -218,7 +219,7 @@ bool Utils::Fs::sameFiles(const QString &path1, const QString &path2) QString Utils::Fs::toValidFileSystemName(const QString &name, bool allowSeparators, const QString &pad) { - QRegExp regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+"); + const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+"); QString validName = name.trimmed(); validName.replace(regex, pad); @@ -231,7 +232,7 @@ bool Utils::Fs::isValidFileSystemName(const QString &name, bool allowSeparators) { if (name.isEmpty()) return false; - QRegExp regex(allowSeparators ? "[:?\"*<>|]" : "[\\\\/:?\"*<>|]"); + const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]" : "[\\\\/:?\"*<>|]"); return !name.contains(regex); } diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 85c38e2fa..000d937db 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -529,7 +528,7 @@ bool Utils::Misc::isUrl(const QString &s) QString Utils::Misc::parseHtmlLinks(const QString &rawText) { QString result = rawText; - static QRegExp reURL( + static const QRegularExpression reURL( "(\\s|^)" // start with whitespace or beginning of line "(" "(" // case 1 -- URL with scheme @@ -576,12 +575,11 @@ QString Utils::Misc::parseHtmlLinks(const QString &rawText) ")" ); - // Capture links result.replace(reURL, "\\1\\2"); // Capture links without scheme - static QRegExp reNoScheme(""); + static const QRegularExpression reNoScheme(""); result.replace(reNoScheme, ""); // to preserve plain text formatting @@ -632,7 +630,7 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath) || (output == "nautilus-folder-handler.desktop")) { proc.start("nautilus", {"--version"}); proc.waitForFinished(); - const QString nautilusVerStr = QString(proc.readLine()).remove(QRegExp("[^0-9.]")); + const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]")); using NautilusVersion = Utils::Version; if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28}) proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)}); diff --git a/src/gui/loglistwidget.cpp b/src/gui/loglistwidget.cpp index 59b3d906d..c93ebe4f6 100644 --- a/src/gui/loglistwidget.cpp +++ b/src/gui/loglistwidget.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2011 Christophe Dumez + * Copyright (C) 2011 Christophe Dumez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,17 +24,18 @@ * modify file(s), you may extend this exception to your version of the file(s), * but you are not obligated to do so. If you do not wish to do so, delete this * exception statement from your version. - * - * Contact : chris@qbittorrent.org */ -#include + +#include "loglistwidget.h" + +#include #include #include -#include +#include #include -#include -#include -#include "loglistwidget.h" +#include +#include + #include "guiiconprovider.h" LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent) @@ -94,10 +95,10 @@ void LogListWidget::appendLine(const QString &line, const Log::MsgType &type) void LogListWidget::copySelection() { - static QRegExp htmlTag("<[^>]+>"); + static const QRegularExpression htmlTag("<[^>]+>"); QStringList strings; foreach (QListWidgetItem* it, selectedItems()) - strings << static_cast(itemWidget(it))->text().replace(htmlTag, ""); + strings << static_cast(itemWidget(it))->text().remove(htmlTag); QApplication::clipboard()->setText(strings.join("\n")); } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 5942ce8e9..4abba63a6 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1599,8 +1600,8 @@ void MainWindow::downloadFromURLList(const QStringList &urlList) { const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled(); foreach (QString url, urlList) { - if (((url.size() == 40) && !url.contains(QRegExp("[^0-9A-Fa-f]"))) - || ((url.size() == 32) && !url.contains(QRegExp("[^2-7A-Za-z]")))) + if (((url.size() == 40) && !url.contains(QRegularExpression("[^0-9A-Fa-f]"))) + || ((url.size() == 32) && !url.contains(QRegularExpression("[^2-7A-Za-z]")))) url = "magnet:?xt=urn:btih:" + url; if (useTorrentAdditionDialog) diff --git a/src/gui/programupdater.cpp b/src/gui/programupdater.cpp index e2d8c0fc1..2d39cd984 100644 --- a/src/gui/programupdater.cpp +++ b/src/gui/programupdater.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez + * Copyright (C) 2010 Christophe Dumez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,20 +24,19 @@ * modify file(s), you may extend this exception to your version of the file(s), * but you are not obligated to do so. If you do not wish to do so, delete this * exception statement from your version. - * - * Contact : chris@qbittorrent.org */ -#include -#include +#include "programupdater.h" + #include -#include +#include +#include #include +#include -#include "base/utils/fs.h" -#include "base/net/downloadmanager.h" #include "base/net/downloadhandler.h" -#include "programupdater.h" +#include "base/net/downloadmanager.h" +#include "base/utils/fs.h" namespace { @@ -137,9 +136,9 @@ void ProgramUpdater::updateProgram() bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const { - QRegExp regVer("([0-9.]+)"); - if (regVer.indexIn(QBT_VERSION) >= 0) { - QString localVersion = regVer.cap(1); + const QRegularExpressionMatch regVerMatch = QRegularExpression("([0-9.]+)").match(QBT_VERSION); + if (regVerMatch.hasMatch()) { + QString localVersion = regVerMatch.captured(1); qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION; QStringList remoteParts = remoteVersion.split('.'); QStringList localParts = localVersion.split('.'); @@ -153,8 +152,8 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const if (remoteParts.size() > localParts.size()) return true; // versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2) - QRegExp regDevel("(alpha|beta|rc)"); - if (regDevel.indexIn(QBT_VERSION) >= 0) + const QRegularExpressionMatch regDevelMatch = QRegularExpression("(alpha|beta|rc)").match(QBT_VERSION); + if (regDevelMatch.hasMatch()) return true; } return false; diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index b243b4957..8a78f9a43 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -461,10 +462,10 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL } else { QString description = article->description(); - QRegExp rx; + QRegularExpression rx; // If description is plain text, replace BBCode tags with HTML and wrap everything in
 so it looks nice
-        rx.setMinimal(true);
-        rx.setCaseSensitivity(Qt::CaseInsensitive);
+        rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
+            | QRegularExpression::CaseInsensitiveOption);
 
         rx.setPattern("\\[img\\](.+)\\[/img\\]");
         description = description.replace(rx, "");
diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp
index b44eb8b0c..4ac7bbe01 100644
--- a/src/gui/search/searchwidget.cpp
+++ b/src/gui/search/searchwidget.cpp
@@ -29,6 +29,8 @@
 
 #include "searchwidget.h"
 
+#include 
+
 #ifdef Q_OS_WIN
 #include 
 #endif
@@ -41,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -320,7 +323,7 @@ void SearchWidget::on_searchButton_clicked()
     m_allTabs.append(newTab);
 
     QString tabName = pattern;
-    tabName.replace(QRegExp("&{1}"), "&&");
+    tabName.replace(QRegularExpression("&{1}"), "&&");
     m_ui->tabWidget->addTab(newTab, tabName);
     m_ui->tabWidget->setCurrentWidget(newTab);
 
diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp
index 45cdc3eed..4f86d05e3 100644
--- a/src/gui/transferlistwidget.cpp
+++ b/src/gui/transferlistwidget.cpp
@@ -1,6 +1,6 @@
 /*
  * Bittorrent Client using Qt4 and libtorrent.
- * Copyright (C) 2006  Christophe Dumez
+ * Copyright (C) 2006  Christophe Dumez 
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -24,8 +24,6 @@
  * modify file(s), you may extend this exception to your version of the file(s),
  * but you are not obligated to do so. If you do not wish to do so, delete this
  * exception statement from your version.
- *
- * Contact : chris@qbittorrent.org
  */
 
 #include "transferlistwidget.h"
@@ -35,14 +33,14 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
-#include "autoexpandabledialog.h"
 #include "base/bittorrent/session.h"
 #include "base/bittorrent/torrenthandle.h"
 #include "base/logger.h"
@@ -50,6 +48,7 @@
 #include "base/torrentfilter.h"
 #include "base/utils/fs.h"
 #include "base/utils/string.h"
+#include "autoexpandabledialog.h"
 #include "deletionconfirmationdlg.h"
 #include "guiiconprovider.h"
 #include "mainwindow.h"
@@ -832,7 +831,7 @@ void TransferListWidget::renameSelectedTorrent()
     bool ok;
     QString name = AutoExpandableDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, torrent->name(), &ok);
     if (ok && !name.isEmpty()) {
-        name.replace(QRegExp("\r?\n|\r"), " ");
+        name.replace(QRegularExpression("\r?\n|\r"), " ");
         // Rename the torrent
         m_listModel->setData(mi, name, Qt::DisplayRole);
     }
diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp
index 983f9caaf..4d7e3b588 100644
--- a/src/webui/webapplication.cpp
+++ b/src/webui/webapplication.cpp
@@ -97,8 +97,8 @@ namespace
 
     void translateDocument(const QString &locale, QString &data)
     {
-        const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
-        const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
+        const QRegularExpression regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
+        const QRegularExpression mnemonic("\\(?&([a-zA-Z]?\\))?");
 
         const bool isTranslationNeeded = !locale.startsWith("en")
             || locale.startsWith("en_AU") || locale.startsWith("en_GB");
@@ -106,23 +106,24 @@ namespace
         int i = 0;
         bool found = true;
         while (i < data.size() && found) {
-            i = regex.indexIn(data, i);
+            QRegularExpressionMatch regexMatch;
+            i = data.indexOf(regex, i, ®exMatch);
             if (i >= 0) {
-                const QString word = regex.cap(1);
-                const QString context = regex.cap(4);
+                const QString word = regexMatch.captured(1);
+                const QString context = regexMatch.captured(4);
 
                 QString translation = isTranslationNeeded
                     ? qApp->translate(context.toUtf8().constData(), word.toUtf8().constData(), nullptr, 1)
                     : word;
 
                 // Remove keyboard shortcuts
-                translation.replace(mnemonic, "");
+                translation.remove(mnemonic);
 
                 // Use HTML code for quotes to prevent issues with JS
                 translation.replace('\'', "'");
                 translation.replace('\"', """);
 
-                data.replace(i, regex.matchedLength(), translation);
+                data.replace(i, regexMatch.capturedLength(), translation);
                 i += translation.length();
             }
             else {