mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
Fix "Open containing folder" opened the wrong path for folder item
Previously that action is the same as "Open" action which is wrong behavior, it should be opening the parent folder instead. The wrong behavior is observed on nautilus 3.36.3 and nemo 4.6.5.
This commit is contained in:
parent
3c6e6ae872
commit
ef6dfa9b54
@ -108,7 +108,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
|
|||||||
connect(m_ui->filesList, &QAbstractItemView::clicked
|
connect(m_ui->filesList, &QAbstractItemView::clicked
|
||||||
, m_ui->filesList, qOverload<const QModelIndex &>(&QAbstractItemView::edit));
|
, m_ui->filesList, qOverload<const QModelIndex &>(&QAbstractItemView::edit));
|
||||||
connect(m_ui->filesList, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFilesListMenu);
|
connect(m_ui->filesList, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFilesListMenu);
|
||||||
connect(m_ui->filesList, &QAbstractItemView::doubleClicked, this, &PropertiesWidget::openDoubleClickedFile);
|
connect(m_ui->filesList, &QAbstractItemView::doubleClicked, this, &PropertiesWidget::openItem);
|
||||||
connect(m_ui->filesList->header(), &QHeaderView::sectionMoved, this, &PropertiesWidget::saveSettings);
|
connect(m_ui->filesList->header(), &QHeaderView::sectionMoved, this, &PropertiesWidget::saveSettings);
|
||||||
connect(m_ui->filesList->header(), &QHeaderView::sectionResized, this, &PropertiesWidget::saveSettings);
|
connect(m_ui->filesList->header(), &QHeaderView::sectionResized, this, &PropertiesWidget::saveSettings);
|
||||||
connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings);
|
connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings);
|
||||||
@ -517,65 +517,41 @@ void PropertiesWidget::loadUrlSeeds()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) const
|
QString PropertiesWidget::getFullPath(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || !m_torrent || !m_torrent->hasMetadata()) return;
|
if (m_propListModel->itemType(index) == TorrentContentModelItem::FileType) {
|
||||||
|
const int fileIdx = m_propListModel->getFileIndex(index);
|
||||||
if (m_propListModel->itemType(index) == TorrentContentModelItem::FileType)
|
const QString filename {m_torrent->filePath(fileIdx)};
|
||||||
openFile(index);
|
const QDir saveDir {m_torrent->savePath(true)};
|
||||||
else
|
const QString fullPath {Utils::Fs::expandPath(saveDir.absoluteFilePath(filename))};
|
||||||
openFolder(index, false);
|
return fullPath;
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::openFile(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
int i = m_propListModel->getFileIndex(index);
|
|
||||||
const QDir saveDir(m_torrent->savePath(true));
|
|
||||||
const QString filename = m_torrent->filePath(i);
|
|
||||||
const QString filePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(filename));
|
|
||||||
qDebug("Trying to open file at %s", qUtf8Printable(filePath));
|
|
||||||
// Flush data
|
|
||||||
m_torrent->flushCache();
|
|
||||||
Utils::Gui::openPath(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
if (pathItems.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QDir saveDir(m_torrent->savePath(true));
|
|
||||||
const QString relativePath = pathItems.join('/');
|
|
||||||
absolutePath = Utils::Fs::expandPath(saveDir.absoluteFilePath(relativePath));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush data
|
// folder type
|
||||||
m_torrent->flushCache();
|
const QModelIndex nameIndex {index.sibling(index.row(), TorrentContentModelItem::COL_NAME)};
|
||||||
|
QString folderPath {nameIndex.data().toString()};
|
||||||
|
for (QModelIndex modelIdx = m_propListModel->parent(nameIndex); modelIdx.isValid(); modelIdx = modelIdx.parent())
|
||||||
|
folderPath.prepend(modelIdx.data().toString() + '/');
|
||||||
|
|
||||||
|
const QDir saveDir {m_torrent->savePath(true)};
|
||||||
|
const QString fullPath {Utils::Fs::expandPath(saveDir.absoluteFilePath(folderPath))};
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::openItem(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
m_torrent->flushCache(); // Flush data
|
||||||
|
Utils::Gui::openPath(getFullPath(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::openParentFolder(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const QString path = getFullPath(index);
|
||||||
|
m_torrent->flushCache(); // Flush data
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
Q_UNUSED(containingFolder);
|
MacUtils::openFiles({path});
|
||||||
MacUtils::openFiles(QSet<QString> {absolutePath});
|
|
||||||
#else
|
#else
|
||||||
if (containingFolder)
|
Utils::Gui::openFolderSelect(path);
|
||||||
Utils::Gui::openFolderSelect(absolutePath);
|
|
||||||
else
|
|
||||||
Utils::Gui::openPath(absolutePath);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,10 +569,10 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
|
|||||||
const QModelIndex index = selectedRows[0];
|
const QModelIndex index = selectedRows[0];
|
||||||
|
|
||||||
const QAction *actOpen = menu->addAction(UIThemeManager::instance()->getIcon("folder-documents"), tr("Open"));
|
const QAction *actOpen = menu->addAction(UIThemeManager::instance()->getIcon("folder-documents"), tr("Open"));
|
||||||
connect(actOpen, &QAction::triggered, this, [this, index]() { openDoubleClickedFile(index); });
|
connect(actOpen, &QAction::triggered, this, [this, index]() { openItem(index); });
|
||||||
|
|
||||||
const QAction *actOpenContainingFolder = menu->addAction(UIThemeManager::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
|
const QAction *actOpenContainingFolder = menu->addAction(UIThemeManager::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
|
||||||
connect(actOpenContainingFolder, &QAction::triggered, this, [this, index]() { openFolder(index, true); });
|
connect(actOpenContainingFolder, &QAction::triggered, this, [this, index]() { openParentFolder(index); });
|
||||||
|
|
||||||
const QAction *actRename = menu->addAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."));
|
const QAction *actRename = menu->addAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."));
|
||||||
connect(actRename, &QAction::triggered, this, [this]() { m_ui->filesList->renameSelectedFile(m_torrent); });
|
connect(actRename, &QAction::triggered, this, [this]() { m_ui->filesList->renameSelectedFile(m_torrent); });
|
||||||
@ -688,7 +664,7 @@ void PropertiesWidget::openSelectedFile()
|
|||||||
const QModelIndexList selectedIndexes = m_ui->filesList->selectionModel()->selectedRows(0);
|
const QModelIndexList selectedIndexes = m_ui->filesList->selectionModel()->selectedRows(0);
|
||||||
if (selectedIndexes.size() != 1)
|
if (selectedIndexes.size() != 1)
|
||||||
return;
|
return;
|
||||||
openDoubleClickedFile(selectedIndexes.first());
|
openItem(selectedIndexes.first());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesWidget::configure()
|
void PropertiesWidget::configure()
|
||||||
|
@ -82,7 +82,7 @@ public slots:
|
|||||||
void readSettings();
|
void readSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void reloadPreferences();
|
void reloadPreferences();
|
||||||
void openDoubleClickedFile(const QModelIndex &index) const;
|
void openItem(const QModelIndex &index) const;
|
||||||
void loadTrackers(BitTorrent::TorrentHandle *const torrent);
|
void loadTrackers(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
@ -107,8 +107,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QPushButton *getButtonFromIndex(int index);
|
QPushButton *getButtonFromIndex(int index);
|
||||||
void applyPriorities();
|
void applyPriorities();
|
||||||
void openFile(const QModelIndex &index) const;
|
void openParentFolder(const QModelIndex &index) const;
|
||||||
void openFolder(const QModelIndex &index, bool containingFolder) const;
|
QString getFullPath(const QModelIndex &index) const;
|
||||||
|
|
||||||
Ui::PropertiesWidget *m_ui;
|
Ui::PropertiesWidget *m_ui;
|
||||||
BitTorrent::TorrentHandle *m_torrent;
|
BitTorrent::TorrentHandle *m_torrent;
|
||||||
|
@ -175,12 +175,14 @@ void Utils::Gui::openPath(const QString &absolutePath)
|
|||||||
// (if possible) the item at the given path
|
// (if possible) the item at the given path
|
||||||
void Utils::Gui::openFolderSelect(const QString &absolutePath)
|
void Utils::Gui::openFolderSelect(const QString &absolutePath)
|
||||||
{
|
{
|
||||||
const QString path = Utils::Fs::toUniformPath(absolutePath);
|
QString path {Utils::Fs::toUniformPath(absolutePath)};
|
||||||
|
const QFileInfo pathInfo {path};
|
||||||
// If the item to select doesn't exist, try to open its parent
|
// If the item to select doesn't exist, try to open its parent
|
||||||
if (!QFileInfo::exists(path)) {
|
if (!pathInfo.exists(path)) {
|
||||||
openPath(path.left(path.lastIndexOf('/')));
|
openPath(path.left(path.lastIndexOf('/')));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||||
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
|
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
|
||||||
@ -200,6 +202,8 @@ void Utils::Gui::openFolderSelect(const QString &absolutePath)
|
|||||||
}
|
}
|
||||||
else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
|
else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
|
||||||
|| (output == "nautilus-folder-handler.desktop")) {
|
|| (output == "nautilus-folder-handler.desktop")) {
|
||||||
|
if (pathInfo.isDir())
|
||||||
|
path = path.left(path.lastIndexOf('/'));
|
||||||
proc.start("nautilus", {"--version"});
|
proc.start("nautilus", {"--version"});
|
||||||
proc.waitForFinished();
|
proc.waitForFinished();
|
||||||
const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]"));
|
const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]"));
|
||||||
@ -210,6 +214,8 @@ void Utils::Gui::openFolderSelect(const QString &absolutePath)
|
|||||||
proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)});
|
proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)});
|
||||||
}
|
}
|
||||||
else if (output == "nemo.desktop") {
|
else if (output == "nemo.desktop") {
|
||||||
|
if (pathInfo.isDir())
|
||||||
|
path = path.left(path.lastIndexOf('/'));
|
||||||
proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)});
|
proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)});
|
||||||
}
|
}
|
||||||
else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) {
|
else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user