1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00

(trunk, qt) #5194 'Qt: open folder: on single-file torrents opens the file, not directory, except on Windows and Mac' -- fixed with patch from basinilya

This commit is contained in:
Jordan Lee 2012-12-27 18:22:48 +00:00
parent ff3a6df7a6
commit a7d352269f

View file

@ -609,16 +609,24 @@ TrMainWindow :: setLocation( )
} }
// Open Folder & select torrent's file or top folder // Open Folder & select torrent's file or top folder
#undef HAVE_OPEN_SELECT
#if defined(Q_OS_WIN)
# define HAVE_OPEN_SELECT
static
void openSelect(const QString& path) void openSelect(const QString& path)
{ {
#if defined(Q_OS_WIN)
const QString explorer = "explorer"; const QString explorer = "explorer";
QString param; QString param;
if (!QFileInfo(path).isDir()) if (!QFileInfo(path).isDir())
param = QLatin1String("/select,"); param = QLatin1String("/select,");
param += QDir::toNativeSeparators(path); param += QDir::toNativeSeparators(path);
QProcess::startDetached(explorer, QStringList(param)); QProcess::startDetached(explorer, QStringList(param));
}
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
# define HAVE_OPEN_SELECT
static
void openSelect(const QString& path)
{
QStringList scriptArgs; QStringList scriptArgs;
scriptArgs << QLatin1String("-e") scriptArgs << QLatin1String("-e")
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"") << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
@ -628,10 +636,8 @@ void openSelect(const QString& path)
scriptArgs << QLatin1String("-e") scriptArgs << QLatin1String("-e")
<< QLatin1String("tell application \"Finder\" to activate"); << QLatin1String("tell application \"Finder\" to activate");
QProcess::execute("/usr/bin/osascript", scriptArgs); QProcess::execute("/usr/bin/osascript", scriptArgs);
#elif defined(Q_OS_UNIX)
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
#endif
} }
#endif
void void
TrMainWindow :: openFolder( ) TrMainWindow :: openFolder( )
@ -642,12 +648,17 @@ TrMainWindow :: openFolder( )
const FileList files = tor->files(); const FileList files = tor->files();
const QString firstfile = files.at(0).filename; const QString firstfile = files.at(0).filename;
int slashIndex = firstfile.indexOf('/'); int slashIndex = firstfile.indexOf('/');
if (files.size() == 1) if (files.size() > 1)
openSelect( path + "/" + files.at(0).filename ); {
else {
path = path + "/" + firstfile.left(slashIndex); path = path + "/" + firstfile.left(slashIndex);
openSelect( path );
} }
#ifdef HAVE_OPEN_SELECT
else {
openSelect( path + "/" + firstfile );
return;
}
#endif
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
} }
void void