mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 14:38:04 -06:00
Convert all foreach() to range-based for()
This commit is contained in:
@@ -284,7 +284,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_prioSeparatorMenu = m_ui->menuEdit->insertSeparator(m_ui->actionTopPriority);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
foreach (QAction *action, m_ui->toolBar->actions()) {
|
||||
for (QAction *action : copyAsConst(m_ui->toolBar->actions())) {
|
||||
if (action->isSeparator()) {
|
||||
QWidget *spacer = new QWidget(this);
|
||||
spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
@@ -1239,7 +1239,7 @@ bool MainWindow::event(QEvent *e)
|
||||
qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr);
|
||||
// Check if there is a modal window
|
||||
bool hasModalWindow = false;
|
||||
foreach (QWidget *widget, QApplication::allWidgets()) {
|
||||
for (QWidget *widget : copyAsConst(QApplication::allWidgets())) {
|
||||
if (widget->isModal()) {
|
||||
hasModalWindow = true;
|
||||
break;
|
||||
@@ -1285,7 +1285,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
// remove scheme
|
||||
QStringList files;
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
foreach (const QUrl &url, event->mimeData()->urls()) {
|
||||
for (const QUrl &url : copyAsConst(event->mimeData()->urls())) {
|
||||
if (url.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -1300,7 +1300,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
|
||||
// differentiate ".torrent" files/links & magnet links from others
|
||||
QStringList torrentFiles, otherFiles;
|
||||
foreach (const QString &file, files) {
|
||||
for (const QString &file : qAsConst(files)) {
|
||||
const bool isTorrentLink = (file.startsWith("magnet:", Qt::CaseInsensitive)
|
||||
|| file.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)
|
||||
|| Utils::Misc::isUrl(file));
|
||||
@@ -1312,7 +1312,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
|
||||
// Download torrents
|
||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||
foreach (const QString &file, torrentFiles) {
|
||||
for (const QString &file : qAsConst(torrentFiles)) {
|
||||
if (useTorrentAdditionDialog)
|
||||
AddNewTorrentDialog::show(file, this);
|
||||
else
|
||||
@@ -1321,7 +1321,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
if (!torrentFiles.isEmpty()) return;
|
||||
|
||||
// Create torrent
|
||||
foreach (const QString &file, otherFiles) {
|
||||
for (const QString &file : qAsConst(otherFiles)) {
|
||||
createTorrentTriggered(file);
|
||||
|
||||
// currently only hande the first entry
|
||||
@@ -1333,7 +1333,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
// Decode if we accept drag 'n drop or not
|
||||
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
foreach (const QString &mime, event->mimeData()->formats())
|
||||
for (const QString &mime : copyAsConst(event->mimeData()->formats()))
|
||||
qDebug("mimeData: %s", mime.toLocal8Bit().data());
|
||||
if (event->mimeData()->hasFormat("text/plain") || event->mimeData()->hasFormat("text/uri-list"))
|
||||
event->acceptProposedAction();
|
||||
@@ -1382,7 +1382,7 @@ void MainWindow::on_actionOpen_triggered()
|
||||
|
||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||
if (!pathsList.isEmpty()) {
|
||||
foreach (QString file, pathsList) {
|
||||
for (const QString &file : pathsList) {
|
||||
qDebug("Dropped file %s on download list", qUtf8Printable(file));
|
||||
if (useTorrentAdditionDialog)
|
||||
AddNewTorrentDialog::show(file, this);
|
||||
@@ -1635,7 +1635,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
|
||||
void MainWindow::downloadFromURLList(const QStringList &urlList)
|
||||
{
|
||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||
foreach (QString url, urlList) {
|
||||
for (QString url : urlList) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user