2018-07-14 06:06:33 +00:00
|
|
|
#include "Common.hpp"
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QObject>
|
2018-07-31 08:04:43 +00:00
|
|
|
#include <QProcess>
|
2018-07-14 06:06:33 +00:00
|
|
|
|
|
|
|
boo::SystemString QStringToSysString(const QString& str)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return (wchar_t*)str.utf16();
|
|
|
|
#else
|
|
|
|
return str.toUtf8().toStdString();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SysStringToQString(const boo::SystemString& str)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return QString::fromStdWString(str);
|
|
|
|
#else
|
|
|
|
return QString::fromStdString(str);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-17 04:48:38 +00:00
|
|
|
bool MkPath(const QString& path, UIMessenger& messenger)
|
2018-07-14 06:06:33 +00:00
|
|
|
{
|
|
|
|
QFileInfo fInfo(path);
|
2018-07-17 04:48:38 +00:00
|
|
|
return MkPath(fInfo.dir(), fInfo.fileName(), messenger);
|
2018-07-14 06:06:33 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 04:48:38 +00:00
|
|
|
bool MkPath(const QDir& dir, const QString& file, UIMessenger& messenger)
|
2018-07-14 06:06:33 +00:00
|
|
|
{
|
|
|
|
if (!dir.mkpath(file))
|
|
|
|
{
|
2018-07-17 04:48:38 +00:00
|
|
|
QString msg = QString(QObject::tr("A directory at '%1/%2' could not be created.")).arg(dir.path()).arg(file);
|
|
|
|
messenger.critical(QObject::tr("Unable to create directory"), msg);
|
2018-07-14 06:06:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-31 08:04:43 +00:00
|
|
|
|
|
|
|
void ShowInGraphicalShell(QWidget* parent, const QString& pathIn)
|
|
|
|
{
|
|
|
|
const QFileInfo fileInfo(pathIn);
|
|
|
|
// Mac, Windows support folder or file.
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
const FileName explorer = Environment::systemEnvironment().searchInPath(QLatin1String("explorer.exe"));
|
|
|
|
if (explorer.isEmpty()) {
|
|
|
|
QMessageBox::warning(parent,
|
|
|
|
QApplication::translate("Core::Internal",
|
|
|
|
"Launching Windows Explorer Failed"),
|
|
|
|
QApplication::translate("Core::Internal",
|
|
|
|
"Could not find explorer.exe in path to launch Windows Explorer."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QStringList param;
|
|
|
|
if (!fileInfo.isDir())
|
|
|
|
param += QLatin1String("/select,");
|
|
|
|
param += QDir::toNativeSeparators(fileInfo.canonicalFilePath());
|
|
|
|
QProcess::startDetached(explorer.toString(), param);
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
QStringList scriptArgs;
|
|
|
|
scriptArgs << QLatin1String("-e")
|
|
|
|
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
|
|
|
|
.arg(fileInfo.canonicalFilePath());
|
|
|
|
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
|
|
|
|
scriptArgs.clear();
|
|
|
|
scriptArgs << QLatin1String("-e")
|
|
|
|
<< QLatin1String("tell application \"Finder\" to activate");
|
|
|
|
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
|
|
|
|
#else
|
|
|
|
// we cannot select a file here, because no file browser really supports it...
|
|
|
|
const QString folder = fileInfo.isDir() ? fileInfo.absoluteFilePath() : fileInfo.filePath();
|
|
|
|
QProcess browserProc;
|
|
|
|
const QString browserArgs = QStringLiteral("xdg-open \"%1\"").arg(QFileInfo(folder).path());
|
|
|
|
browserProc.startDetached(browserArgs);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ShowInGraphicalShellString()
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
return QObject::tr("Show in Explorer");
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
return QObject::tr("Show in Finder");
|
|
|
|
#else
|
|
|
|
return QObject::tr("Show in Browser");
|
|
|
|
#endif
|
|
|
|
}
|