From 57927b7d73c486b434d2742c0589869f00af81a6 Mon Sep 17 00:00:00 2001 From: doitux Date: Fri, 20 Apr 2007 10:03:31 +0000 Subject: [PATCH] --- src/gui/qt/qttools/appdirpath/appdirpath.cpp | 82 ++++++++++++++++++++ src/gui/qt/qttools/appdirpath/appdirpath.h | 38 +++++++++ src/gui/qt/qttools/qttoolswrapper.cpp | 40 ++++++++++ src/gui/qt/qttools/qttoolswrapper.h | 45 +++++++++++ 4 files changed, 205 insertions(+) create mode 100644 src/gui/qt/qttools/appdirpath/appdirpath.cpp create mode 100644 src/gui/qt/qttools/appdirpath/appdirpath.h create mode 100644 src/gui/qt/qttools/qttoolswrapper.cpp create mode 100644 src/gui/qt/qttools/qttoolswrapper.h diff --git a/src/gui/qt/qttools/appdirpath/appdirpath.cpp b/src/gui/qt/qttools/appdirpath/appdirpath.cpp new file mode 100644 index 00000000..8ce36310 --- /dev/null +++ b/src/gui/qt/qttools/appdirpath/appdirpath.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2006 by Felix Hammer * + * f.hammer@web.de * + * * + * 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 "appdirpath.h" + +#include + +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#include +#endif + +using namespace std; + +AppDirPath::AppDirPath() +{ +#ifdef _WIN32 + // Pfad und Dateinamen setzen + const char *appDataPath = getenv("AppData"); + if (appDataPath && appDataPath[0] != 0) { + configFileName = appDataPath; + } + else { + const int MaxPathSize = 1024; + char curDir[MaxPathSize + 1]; + curDir[0] = 0; + _getcwd(curDir, MaxPathSize); + curDir[MaxPathSize] = 0; + configFileName = curDir; + // Testen ob das Verzeichnis beschreibbar ist + ofstream tmpFile; + const char *tmpFileName = "pokerth_test.tmp"; + tmpFile.open((configFileName + "\\" + tmpFileName).c_str()); + if (tmpFile) { + // Erfolgreich, Verzeichnis beschreibbar. + // Datei wieder loeschen. + tmpFile.close(); + remove((configFileName + "\\" + tmpFileName).c_str()); + } + else { + // Fehlgeschlagen, Verzeichnis nicht beschreibbar + curDir[0] = 0; + GetTempPathA(MaxPathSize, curDir); + curDir[MaxPathSize] = 0; + configFileName = curDir; + } + } +#else + const char *homePath = getenv("HOME"); + configFileName = homePath; +#endif + //UTF8 !!!! + QString tmpString = QString::fromStdString(configFileName); + configFileName = tmpString.toUtf8().constData(); + //UTF8 !!!! +} + +AppDirPath::~AppDirPath() +{ +} + diff --git a/src/gui/qt/qttools/appdirpath/appdirpath.h b/src/gui/qt/qttools/appdirpath/appdirpath.h new file mode 100644 index 00000000..7dcf56d8 --- /dev/null +++ b/src/gui/qt/qttools/appdirpath/appdirpath.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2006 by Felix Hammer * + * f.hammer@web.de * + * * + * 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. * + ***************************************************************************/ +#ifndef APPDIRPATH_H +#define APPDIRPATH_H + +#include + +class AppDirPath{ +public: + AppDirPath(); + + ~AppDirPath(); + + std::string getMyPath() const { return configFileName; }; + +private: + std::string configFileName; + +}; + +#endif diff --git a/src/gui/qt/qttools/qttoolswrapper.cpp b/src/gui/qt/qttools/qttoolswrapper.cpp new file mode 100644 index 00000000..0ee923d2 --- /dev/null +++ b/src/gui/qt/qttools/qttoolswrapper.cpp @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * 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 "qttoolswrapper.h" + +#include + +using namespace std; + + +QtToolsWrapper::QtToolsWrapper() : myAppDirPath(0) +{ + + myAppDirPath = new AppDirPath(); +} + + +QtToolsWrapper::~QtToolsWrapper() +{ +} + +std::string QtToolsWrapper::getMyAppDirPath() const { return myAppDirPath->getMyPath(); } + diff --git a/src/gui/qt/qttools/qttoolswrapper.h b/src/gui/qt/qttools/qttoolswrapper.h new file mode 100644 index 00000000..7275b5ea --- /dev/null +++ b/src/gui/qt/qttools/qttoolswrapper.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * 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. * + ***************************************************************************/ +#ifndef QTTOOLSWRAPPER_H +#define QTTOOLSWRAPPER_H + +#include + +#include +#include + +class AppDirPath; + +class QtToolsWrapper : public QtToolsInterface +{ +public: + QtToolsWrapper(); + + ~QtToolsWrapper(); + + std::string getMyAppDirPath() const; + +private: + + AppDirPath *myAppDirPath; + +}; + +#endif