mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
Merge pull request #744 from Gelmir/open_select
[Windows] Implement open & select file in file manager
This commit is contained in:
commit
bba8e18812
2 changed files with 31 additions and 11 deletions
|
@ -430,9 +430,10 @@ void PropertiesWidget::openFile(const QModelIndex &index) {
|
||||||
// Flush data
|
// Flush data
|
||||||
h.flush_cache();
|
h.flush_cache();
|
||||||
if (QFile::exists(file_path)) {
|
if (QFile::exists(file_path)) {
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
if (file_path.startsWith("//"))
|
||||||
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
QDesktopServices::openUrl(fsutils::toNativePath("file:" + file_path));
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
else
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
||||||
|
@ -450,21 +451,38 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_fold
|
||||||
}
|
}
|
||||||
if (path_items.isEmpty())
|
if (path_items.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
if (containing_folder)
|
if (containing_folder)
|
||||||
path_items.removeLast();
|
path_items.removeLast();
|
||||||
|
#endif
|
||||||
|
|
||||||
const QDir saveDir(h.save_path());
|
const QDir saveDir(h.save_path());
|
||||||
const QString filename = path_items.join("/");
|
const QString filename = path_items.join("/");
|
||||||
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
||||||
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
||||||
// Flush data
|
// Flush data
|
||||||
h.flush_cache();
|
h.flush_cache();
|
||||||
if (QFile::exists(file_path)) {
|
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
#ifdef Q_OS_WIN
|
||||||
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
if (containing_folder) {
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
|
||||||
|
// Dir separators MUST be win-style slashes
|
||||||
|
QProcess::startDetached("explorer.exe", QStringList() << "/select," << fsutils::toNativePath(file_path));
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
#endif
|
||||||
|
if (QFile::exists(file_path)) {
|
||||||
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
|
if (file_path.startsWith("//"))
|
||||||
|
QDesktopServices::openUrl(fsutils::toNativePath("file:" + file_path));
|
||||||
|
else
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
||||||
|
}
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||||
|
@ -478,7 +496,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||||
QAction *actOpenContainingFolder = 0;
|
QAction *actOpenContainingFolder = 0;
|
||||||
QAction *actRename = 0;
|
QAction *actRename = 0;
|
||||||
if (selectedRows.size() == 1) {
|
if (selectedRows.size() == 1) {
|
||||||
actOpen = myFilesLlistMenu.addAction(tr("Open"));
|
actOpen = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("folder-documents"), tr("Open"));
|
||||||
actOpenContainingFolder = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
|
actOpenContainingFolder = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
|
||||||
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
||||||
myFilesLlistMenu.addSeparator();
|
myFilesLlistMenu.addSeparator();
|
||||||
|
|
|
@ -633,8 +633,10 @@ void TransferListWidget::askNewLabelForSelection() {
|
||||||
bool TransferListWidget::openUrl(const QString &_path) const {
|
bool TransferListWidget::openUrl(const QString &_path) const {
|
||||||
const QString path = fsutils::fromNativePath(_path);
|
const QString path = fsutils::fromNativePath(_path);
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
const QString p = path.startsWith("//") ? QString("file:") + path : path;
|
if (path.startsWith("//"))
|
||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
return QDesktopServices::openUrl(fsutils::toNativePath("file:" + path));
|
||||||
|
else
|
||||||
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::renameSelectedTorrent() {
|
void TransferListWidget::renameSelectedTorrent() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue