From 001813c3648ec3c2847a36b7534059b373eb222e Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 7 Apr 2012 00:16:14 +0000 Subject: [PATCH] (trunk, qt) fix #4824 'Open Folder bug' with a patch from rb07 --- qt/mainwin.cc | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 41768eb46..a239376c2 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -579,13 +579,45 @@ TrMainWindow :: setLocation( ) d->show( ); } +// Open Folder & select torrent's file or top folder +void openSelect(const QString& path) +{ +#if defined(Q_OS_WIN) + const QString explorer = "explorer"; + QString param; + if (!QFileInfo(path).isDir()) + param = QLatin1String("/select,"); + param += QDir::toNativeSeparators(path); + QProcess::startDetached(explorer, QStringList(param)); +#elif defined(Q_OS_MAC) + QStringList scriptArgs; + scriptArgs << QLatin1String("-e") + << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"") + .arg(path); + QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs); + scriptArgs.clear(); + scriptArgs << QLatin1String("-e") + << QLatin1String("tell application \"Finder\" to activate"); + QProcess::execute("/usr/bin/osascript", scriptArgs); +#elif defined(Q_OS_UNIX) + QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) ); +#endif +} + void TrMainWindow :: openFolder( ) { const int torrentId( *getSelectedTorrents().begin() ); const Torrent * tor( myModel.getTorrentFromId( torrentId ) ); const QString path( tor->getPath( ) ); - QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) ); + const FileList files = tor->files(); + if (files.size() == 1) + openSelect( path + "/" + files.at(0).filename ); + else { + QDir dir( path + "/" + files.at(0).filename ); + dir.cdUp(); + openSelect( dir.path() ); + } } void