# # # patch "src/util/Platform.cpp" # from [ebe032e1b8f3f8971dfe9db035e31d5684b2d331] # to [2c86bf985ac1f54de537bed0321530d9e55c83c0] # ============================================================ --- src/util/Platform.cpp ebe032e1b8f3f8971dfe9db035e31d5684b2d331 +++ src/util/Platform.cpp 2c86bf985ac1f54de537bed0321530d9e55c83c0 @@ -23,24 +23,17 @@ #include #include #include +#include -#ifdef Q_WS_X11 -#include -#endif - #ifdef Q_WS_WIN #include #include -#include #endif -#ifdef Q_WS_MACX +#ifdef Q_WS_X11 #include -#endif - -#include - using namespace std; +#endif // // The following code is public domain, with slight modifications, taken from @@ -109,7 +102,7 @@ bool Platform::openFile(const QString & } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - bool retval = false; + int retval = -1; #ifdef Q_WS_X11 // due to a bug in KDE < 3.5.3 we can't trust the return value kfmclient @@ -122,7 +115,7 @@ bool Platform::openFile(const QString & s += "\""; // just cross your fingers system(s.c_str()); - retval = true; + retval = 0; } else if (system("which gnome-open >/dev/null 2>&1") == 0) @@ -131,7 +124,7 @@ bool Platform::openFile(const QString & string s("gnome-open \""); s += filename.toUtf8().data(); s += "\""; - retval = (system(s.c_str()) == 0); + retval = system(s.c_str()); } else { @@ -140,11 +133,14 @@ bool Platform::openFile(const QString & #endif #ifdef Q_WS_MACX - // Running on a Mac in OS X - string s("open \""); - s += filename.toUtf8().data(); - s += "\""; - retval = (system(s.c_str()) == 0); + retval = QProcess::execute("open", QStringList() << filename); + // if a regular open failed, try to open the file in the system's + // default editor + if (retval != 0) + { + D(QString("try to open %1 in text editor").arg(filename)); + retval = QProcess::execute("open", QStringList() << "-t" << filename); + } #endif #ifdef Q_WS_WIN @@ -161,19 +157,19 @@ bool Platform::openFile(const QString & // try to open in with the "Open With" dialog if (code > 32) { - retval = true; + retval = 0; } else { QStringList arguments; arguments << "shell32.dll,OpenAs_RunDLL" << winfilename; - retval = QProcess::startDetached("rundll32.exe", arguments); + retval = QProcess::execute("rundll32.exe", arguments); } #endif QApplication::restoreOverrideCursor(); - if (!retval) + if (retval != 0) { QMessageBox::critical( NULL, @@ -199,19 +195,19 @@ QString Platform::getUsername() #ifdef Q_WS_WIN #if defined(UNICODE) - if ( QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) + if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) { TCHAR winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H DWORD winUserNameSize = sizeof(winUserName); - GetUserNameW( winUserName, &winUserNameSize ); - username = QString::fromStdWString( winUserName ); + GetUserNameW(winUserName, &winUserNameSize); + username = QString::fromStdWString(winUserName); } else #endif { char winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H DWORD winUserNameSize = sizeof(winUserName); - GetUserNameA( winUserName, &winUserNameSize ); - username = QString::fromLocal8Bit( winUserName ); + GetUserNameA(winUserName, &winUserNameSize); + username = QString::fromLocal8Bit(winUserName); } #endif