qtutilities/misc/desktoputils.cpp

28 lines
835 B
C++
Raw Normal View History

#include "desktoputils.h"
#include <c++utilities/application/global.h>
#include <QDesktopServices>
#include <QUrl>
namespace DesktopUtils {
/*!
* \brief Shows the specified file or directory using the default file browser.
2016-02-05 20:23:02 +01:00
* \remarks \a path musn't be specified as URL. (Conversion to URL is the purpose of this function).
*/
bool LIB_EXPORT openLocalFileOrDir(const QString &path)
{
#ifdef Q_OS_WIN32
// backslashes are commonly used under Windows
// -> replace backslashes with slashes to support Windows paths
QString tmp(path);
tmp.replace(QChar('\\'), QChar('/'));
return QDesktopServices::openUrl(QUrl(QStringLiteral("file:///") + path, QUrl::TolerantMode));
#else
return QDesktopServices::openUrl(QUrl(QStringLiteral("file://") + path, QUrl::TolerantMode));
#endif
}
}