# # # rename "guitone/src/util/OpenFile.cpp" # to "guitone/src/util/Platform.cpp" # # rename "guitone/src/util/OpenFile.h" # to "guitone/src/util/Platform.h" # # patch "guitone/guitone.pro" # from [795b23dd7f3e7c4cd881176e16e051a70e8ed88a] # to [222143e6cb858ecebff9b72dab79d01c0fb372fb] # # patch "guitone/res/i18n/guitone_de.ts" # from [b5823e3c8a31134b5d3e66183dc31cbca87667fc] # to [e15c00f4a4cbec868a3c3ac13cb3833750843765] # # patch "guitone/src/util/Platform.cpp" # from [4a53360ee1f4a743ae068e1b79a662f2a8790cf7] # to [9777c5d001afd2de304f58b7caf3740d35f084da] # # patch "guitone/src/util/Platform.h" # from [f56a5026655603e84c3eb9cc18d94afd952c030e] # to [d01ea9bdf4b801be54df7f565f367ca51101992d] # # patch "guitone/src/view/InventoryView.cpp" # from [9be0f6fa4e8f46a92a588a7e5ac99ee2abb962a8] # to [c563cc7b4a82cc584eaff1f205ffccd568500fb5] # # patch "guitone/src/view/dialogs/RevisionManifest.cpp" # from [0b56310b9fb25eac8930946f251eafbdb0264fde] # to [b4676e478d3937d42c6b94e17a79abf62bc5c460] # ============================================================ --- guitone/guitone.pro 795b23dd7f3e7c4cd881176e16e051a70e8ed88a +++ guitone/guitone.pro 222143e6cb858ecebff9b72dab79d01c0fb372fb @@ -52,7 +52,7 @@ HEADERS += src/view/MainWindow.h \ src/util/Settings.h \ src/util/DiffParser.h \ src/util/SignalWaiter.h \ - src/util/OpenFile.h \ + src/util/Platform.h \ src/util/TreeBuilder.h \ src/util/DebugLog.h \ src/util/StdioParser.h @@ -96,7 +96,7 @@ SOURCES += src/view/MainWindow.cpp \ src/util/Settings.cpp \ src/util/DiffParser.cpp \ src/util/SignalWaiter.cpp \ - src/util/OpenFile.cpp \ + src/util/Platform.cpp \ src/util/TreeBuilder.cpp \ src/util/DebugLog.cpp \ src/util/StdioParser.cpp \ ============================================================ --- guitone/res/i18n/guitone_de.ts b5823e3c8a31134b5d3e66183dc31cbca87667fc +++ guitone/res/i18n/guitone_de.ts e15c00f4a4cbec868a3c3ac13cb3833750843765 @@ -1118,22 +1118,22 @@ monotone gab zurück: RevisionManifest - + Error Fehler - + Unable to open files on your platform - please contact the author about this problem. Kann keine Dateien auf Ihrer Plattform öffnen - bitte kontaktieren Sie den Autor über dieses Problem. - + Please close this message to remove the temporary file. - + Information ============================================================ --- guitone/src/util/OpenFile.cpp 4a53360ee1f4a743ae068e1b79a662f2a8790cf7 +++ guitone/src/util/Platform.cpp 9777c5d001afd2de304f58b7caf3740d35f084da @@ -1,25 +1,64 @@ -#include "OpenFile.h" +/*************************************************************************** +* Copyright (C) 2007 by Thomas Keller * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ -#include -#include +#include "Platform.h" +#include + +#ifdef Q_WS_X11 +#include +#endif + #ifdef Q_WS_WIN #include +#include #endif -bool OpenFile::open(QWidget *widget, const QString &filename) +#ifdef Q_WS_MACX +#include +#include +#endif + +#include + +using namespace std; + +// +// The following code is public domain, with slight modifications, taken from +// http://hrabia.ibib.waw.pl/~winnie/qtopen.html +// It opens a file with the associated program on the specific platform +// Original author: Chris Thompson +// +bool Platform::openFile(QWidget *widget, const QString &filename) { bool retval = false; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -#ifdef Q_WS_X11 +#ifdef Q_WS_X11 Q_UNUSED(widget); // due to a bug in KDE < 3.5.3 we can't trust the return value kfmclient // gives us back (its always 1!) - if (system("which kfmclient") == 0) + if (system("which kfmclient >/dev/null 2>&1") == 0) { - qDebug("OpenFile::open: using kfmclient"); + qDebug("Platform::openFile: using kfmclient"); string s("kfmclient exec \""); s += filename.toUtf8().data(); s += "\""; @@ -28,9 +67,9 @@ bool OpenFile::open(QWidget *widget, con retval = true; } else - if (system("which gnome-open") == 0) + if (system("which gnome-open >/dev/null 2>&1") == 0) { - qDebug("OpenFile::open: using gnome-open"); + qDebug("Platform::openFile: using gnome-open"); string s("gnome-open \""); s += filename.toUtf8().data(); s += "\""; @@ -38,7 +77,7 @@ bool OpenFile::open(QWidget *widget, con } else { - qDebug("OpenFile::open: neither kfmclient nor gnome-open found"); + qDebug("Platform::openFile: neither kfmclient nor gnome-open found"); } #endif @@ -66,3 +105,47 @@ bool OpenFile::open(QWidget *widget, con return retval; } +// +// the following code is loosely based on David Wright's code snippet +// on the Qt interest mailing list +// (http://lists.trolltech.com/qt-interest/2002-12/thread00130-0.html) +// +QString Platform::getUsername() +{ + QString username; + +#ifdef Q_WS_WIN +#if defined(UNICODE) + if ( qWinVersion() & Qt::WV_NT_based ) + { + TCHAR winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H + DWORD winUserNameSize = sizeof(winUserName); + GetUserName( winUserName, &winUserNameSize ); + userName = qt_winQString( winUserName ); + } else +#endif + { + char winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H + DWORD winUserNameSize = sizeof(winUserName); + GetUserNameA( winUserName, &winUserNameSize ); + userName = QString::fromLocal8Bit( winUserName ); + } +#endif + +#ifdef Q_WS_X11 +#define IS_UNIX +#endif + +#ifdef Q_WS_MACX +#define IS_UNIX +#endif + +#ifdef IS_UNIX + username = QString::fromAscii(getenv("USER")); +#endif + + qDebug("Platform::getUsername: found username %s", qPrintable(username)); + + return username; +} + ============================================================ --- guitone/src/util/OpenFile.h f56a5026655603e84c3eb9cc18d94afd952c030e +++ guitone/src/util/Platform.h d01ea9bdf4b801be54df7f565f367ca51101992d @@ -1,54 +1,44 @@ -// -// The following code is public domain, with slight modifications, taken from -// http://hrabia.ibib.waw.pl/~winnie/qtopen.html -// It opens a file with the associated program on the specific platform -// Original author: Chris Thompson -// -#ifndef OPENFILE_H -#define OPENFILE_H +/*************************************************************************** +* Copyright (C) 2007 by Thomas Keller * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ -#include -#include +#ifndef PLATFORM_H +#define PLATFORM_H -#ifdef Q_WS_X11 -#include -#endif +#include +#include -#ifdef Q_WS_MACX -#include -#include -#endif - -#include - -using namespace std; - - -/*! -* \class OpenFile -* \version $Revision$ -* \brief Open a given file using the underlying operating -* system's default method. We would typically use this -* to open a URL using the default browser, for example. -* Its use is undefined if the operating system does not -* know how to handle the file we pass it. -*/ -class OpenFile +class Platform { public: - /*! - * \brief Open the specified URL. This will attempt to open - * the specified url in the user's favourite browser using - * operating-system dependent techniques. It is theorised - * that files could be opened, at least on the Windows - * platform, using this code without any modifications. - * \warning The URL is assumed to be valid. No security - * checks are performed. - * \arg QWidget *widget The parent to the browser. This is - * not used on some platforms. - * \arg const string &filename The URL to open. - */ - static bool open(QWidget *widget, const QString &filename); + /** + * Opens a file or URL with the default registered handler + * The URL is assumed to be valid. No security checks are performed. + * @arg QWidget *widget The parent to the browser. This is + * not used on some platforms. + * @arg const string &filename The URL to open. + */ + static bool openFile(QWidget *widget, const QString &filename); + /** + * Returns the name of the currently logged in user of the system + */ + static QString getUsername(); }; #endif ============================================================ --- guitone/src/view/InventoryView.cpp 9be0f6fa4e8f46a92a588a7e5ac99ee2abb962a8 +++ guitone/src/view/InventoryView.cpp c563cc7b4a82cc584eaff1f205ffccd568500fb5 @@ -20,7 +20,7 @@ #include "InventoryView.h" #include "Settings.h" -#include "OpenFile.h" +#include "Platform.h" #include "InventoryItem.h" #include "Monotone.h" #include "FileDiff.h" @@ -342,7 +342,7 @@ void InventoryView::slotOpen(void) return; } - if (!OpenFile::open(this, file.absoluteFilePath())) + if (!Platform::openFile(this, file.absoluteFilePath())) { QMessageBox::critical( this, ============================================================ --- guitone/src/view/dialogs/RevisionManifest.cpp 0b56310b9fb25eac8930946f251eafbdb0264fde +++ guitone/src/view/dialogs/RevisionManifest.cpp b4676e478d3937d42c6b94e17a79abf62bc5c460 @@ -20,7 +20,7 @@ #include "RevisionManifest.h" #include "Monotone.h" -#include "OpenFile.h" +#include "Platform.h" #include #include @@ -114,10 +114,27 @@ void RevisionManifest::openFile(const QM return; } - QString tempFile = QDir::tempPath(); - tempFile.append(QDir::separator()).append(entry->filename()); + // + // FIXME: temporary files are currently saved into /tmp/guitone-/.ext + // on unices and somewhere in %WINDIR%\temp\guitone- or similar under Win32. + // We need to check that + // a) user A can't read the temp files of user B (unsure in Win32...) + // b) what we do if two different instances of guitone run for the same + // user which both want the same filename + // + QString tempPath = QDir::tempPath(); + tempPath.append(QDir::separator()).append("guitone-").append(Platform::getUsername()); + QFileInfo path(tempPath); + if (!path.isDir() && !QDir().mkpath(tempPath)) + { + qCritical("RevisionManifest::openFile: Could not create temporary guitone directory"); + return; + } + tempPath.append(QDir::separator()).append(entry->filename()); - QFile file(tempFile); + QFile file(tempPath); + if (file.exists()) file.remove(); + if (!file.open(QIODevice::WriteOnly)) { qCritical("RevisionManifest::openFile: can't open temporary file for writing"); @@ -129,7 +146,7 @@ void RevisionManifest::openFile(const QM file.write(mtn->getRawDataAndReset()); file.close(); - if (!OpenFile::open(this, tempFile)) + if (!Platform::openFile(this, tempPath)) { QMessageBox::critical( this,