From 307ca61c869702897899649a0b34f5dbb02d6a5b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 27 Aug 2020 00:06:54 +0800 Subject: [PATCH 1/2] Code clean up --- src/base/utils/string.h | 8 ++++---- src/gui/properties/propertieswidget.cpp | 14 +++++++------- src/gui/properties/propertieswidget.h | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/base/utils/string.h b/src/base/utils/string.h index 53e6392da..de77fc900 100644 --- a/src/base/utils/string.h +++ b/src/base/utils/string.h @@ -30,7 +30,7 @@ #ifndef UTILS_STRING_H #define UTILS_STRING_H -#include +#include #include class QString; @@ -54,13 +54,13 @@ namespace Utils QString wildcardToRegex(const QString &pattern); template - T unquote(const T &str, const QString "es = QLatin1String("\"")) + T unquote(const T &str, const QString "es = QChar('"')) { if (str.length() < 2) return str; - for (const auto "e : quotes) { + for (const QChar quote : quotes) { if (str.startsWith(quote) && str.endsWith(quote)) - return str.mid(1, str.length() - 2); + return str.mid(1, (str.length() - 2)); } return str; diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 75784cb02..e3a1efc9b 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -517,7 +517,7 @@ void PropertiesWidget::loadUrlSeeds() } } -void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) +void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) const { if (!index.isValid() || !m_torrent || !m_torrent->hasMetadata()) return; @@ -527,7 +527,7 @@ void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) openFolder(index, false); } -void PropertiesWidget::openFile(const QModelIndex &index) +void PropertiesWidget::openFile(const QModelIndex &index) const { int i = m_propListModel->getFileIndex(index); const QDir saveDir(m_torrent->savePath(true)); @@ -539,14 +539,13 @@ void PropertiesWidget::openFile(const QModelIndex &index) Utils::Gui::openPath(filePath); } -void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolder) +void PropertiesWidget::openFolder(const QModelIndex &index, const bool containingFolder) const { QString absolutePath; // FOLDER if (m_propListModel->itemType(index) == TorrentContentModelItem::FolderType) { // Generate relative path to selected folder - QStringList pathItems; - pathItems << index.data().toString(); + QStringList pathItems {index.data().toString()}; QModelIndex parent = m_propListModel->parent(index); while (parent.isValid()) { pathItems.prepend(parent.data().toString()); @@ -554,12 +553,13 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde } if (pathItems.isEmpty()) return; + const QDir saveDir(m_torrent->savePath(true)); const QString relativePath = pathItems.join('/'); absolutePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(relativePath)); } else { - int i = m_propListModel->getFileIndex(index); + const int i = m_propListModel->getFileIndex(index); const QDir saveDir(m_torrent->savePath(true)); const QString relativePath = m_torrent->filePath(i); absolutePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(relativePath)); @@ -569,7 +569,7 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde m_torrent->flushCache(); #ifdef Q_OS_MACOS Q_UNUSED(containingFolder); - MacUtils::openFiles(QSet{absolutePath}); + MacUtils::openFiles(QSet {absolutePath}); #else if (containingFolder) Utils::Gui::openFolderSelect(absolutePath); diff --git a/src/gui/properties/propertieswidget.h b/src/gui/properties/propertieswidget.h index 673e8f718..2600d46dc 100644 --- a/src/gui/properties/propertieswidget.h +++ b/src/gui/properties/propertieswidget.h @@ -82,7 +82,7 @@ public slots: void readSettings(); void saveSettings(); void reloadPreferences(); - void openDoubleClickedFile(const QModelIndex &); + void openDoubleClickedFile(const QModelIndex &index) const; void loadTrackers(BitTorrent::TorrentHandle *const torrent); protected slots: @@ -107,8 +107,8 @@ private slots: private: QPushButton *getButtonFromIndex(int index); void applyPriorities(); - void openFile(const QModelIndex &index); - void openFolder(const QModelIndex &index, bool containingFolder); + void openFile(const QModelIndex &index) const; + void openFolder(const QModelIndex &index, bool containingFolder) const; Ui::PropertiesWidget *m_ui; BitTorrent::TorrentHandle *m_torrent; From eb1a3e2b297004fe6cab37fa17fd1918ee5b0a38 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 29 Aug 2020 19:57:38 +0800 Subject: [PATCH 2/2] Fix open path won't work correctly Previously, if double click on the Size number in torrent content tab the path would be an incorrect value and as such open path functionality won't work, this commit fixes it. --- src/gui/properties/propertieswidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index e3a1efc9b..53b36922a 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -545,8 +545,9 @@ void PropertiesWidget::openFolder(const QModelIndex &index, const bool containin // FOLDER if (m_propListModel->itemType(index) == TorrentContentModelItem::FolderType) { // Generate relative path to selected folder - QStringList pathItems {index.data().toString()}; - QModelIndex parent = m_propListModel->parent(index); + const QModelIndex nameIndex {index.sibling(index.row(), TorrentContentModelItem::COL_NAME)}; + QStringList pathItems {nameIndex.data().toString()}; + QModelIndex parent = m_propListModel->parent(nameIndex); while (parent.isValid()) { pathItems.prepend(parent.data().toString()); parent = m_propListModel->parent(parent);