Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement open & select file in file manager #744

Merged
merged 3 commits into from
Nov 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/properties/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ void PropertiesWidget::openFile(const QModelIndex &index) {
// Flush data
h.flush_cache();
if (QFile::exists(file_path)) {
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
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 file does not exist yet."));
Expand All @@ -449,21 +450,38 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_fold
}
if (path_items.isEmpty())
return;

#ifndef Q_OS_WIN
if (containing_folder)
path_items.removeLast();
#endif

const QDir saveDir(h.save_path());
const QString filename = path_items.join("/");
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open folder at %s", qPrintable(file_path));
// Flush data
h.flush_cache();
if (QFile::exists(file_path)) {
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
QDesktopServices::openUrl(QUrl::fromLocalFile(p));

#ifdef Q_OS_WIN
if (containing_folder) {
// 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 {
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&) {
Expand All @@ -477,7 +495,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
QAction *actOpenContainingFolder = 0;
QAction *actRename = 0;
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"));
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
myFilesLlistMenu.addSeparator();
Expand Down
6 changes: 4 additions & 2 deletions src/transferlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,10 @@ void TransferListWidget::askNewLabelForSelection() {
bool TransferListWidget::openUrl(const QString &_path) const {
const QString path = fsutils::fromNativePath(_path);
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = path.startsWith("//") ? QString("file:") + path : path;
return QDesktopServices::openUrl(QUrl::fromLocalFile(p));
if (path.startsWith("//"))
return QDesktopServices::openUrl(fsutils::toNativePath("file:" + path));
else
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}

void TransferListWidget::renameSelectedTorrent() {
Expand Down