From bd9dcf1247f848136d13959518611a56a7159e31 Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Sun, 10 Nov 2013 23:53:38 +0400 Subject: [PATCH] Hack around QDesktopServices::openUrl to support network shares --- src/properties/propertieswidget.cpp | 8 ++++++-- src/transferlistwidget.cpp | 15 +++++++++++---- src/transferlistwidget.h | 3 +++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index c98c23bdd..76667620a 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -419,7 +419,9 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { // Flush data h.flush_cache(); if (QFile::exists(file_path)) { - QDesktopServices::openUrl(QUrl::fromLocalFile(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)); } else { QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet.")); } @@ -439,7 +441,9 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { // Flush data h.flush_cache(); if (QFile::exists(file_path)) { - QDesktopServices::openUrl(QUrl::fromLocalFile(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)); } else { QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet.")); } diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 0893e3c57..a183865bf 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -177,7 +177,7 @@ TorrentModel* TransferListWidget::getSourceModel() const { } void TransferListWidget::previewFile(QString filePath) { - QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); + openUrl(filePath); } void TransferListWidget::setRefreshInterval(int t) { @@ -235,8 +235,8 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) { } break; case OPEN_DEST: - QDesktopServices::openUrl(QUrl::fromLocalFile(h.root_path())); - break; + const QString path = h.root_path(); + openUrl(path); } } @@ -439,7 +439,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const { qDebug("Opening path at %s", qPrintable(rootFolder)); if (!pathsList.contains(rootFolder)) { pathsList.insert(rootFolder); - QDesktopServices::openUrl(QUrl::fromLocalFile(rootFolder)); + openUrl(rootFolder); } } } @@ -644,6 +644,13 @@ void TransferListWidget::askNewLabelForSelection() { }while(invalid); } +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)); +} + void TransferListWidget::renameSelectedTorrent() { const QModelIndexList selectedIndexes = selectionModel()->selectedRows(); if (selectedIndexes.size() != 1) return; diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 7b817ed17..8ec26755a 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -106,6 +106,9 @@ protected slots: void toggleSelectedFirstLastPiecePrio() const; void askNewLabelForSelection(); +private: + bool openUrl(const QString& _path) const; + signals: void currentTorrentChanged(const QTorrentHandle &h);