Mercurial > hg > forks > UniversalIndentGUI
changeset 490:0d58db39775f
Added a separate static class from that all necessary paths can be retrieved.
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@730 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Mon, 16 Jun 2008 07:23:56 +0000 |
parents | 5fe3aefed089 |
children | e3215923077a |
files | src/SettingsPaths.cpp src/SettingsPaths.h src/UniversalIndentGUI.vcproj src/mainwindow.cpp src/mainwindow.h |
diffstat | 5 files changed, 199 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SettingsPaths.cpp Mon Jun 16 07:23:56 2008 +0000 @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#include "SettingsPaths.h" + + +bool SettingsPaths::alreadyInitialized = false; +QString SettingsPaths::applicationBinaryPath = ""; +QString SettingsPaths::settingsPath = ""; +QString SettingsPaths::globalFilesPath = ""; +QString SettingsPaths::indenterPath = ""; +QString SettingsPaths::tempPath = ""; +bool SettingsPaths::portableMode = false; + + +void SettingsPaths::init() { + // Get the applications binary path, with respect to MacOSXs use of the .app folder. + applicationBinaryPath = QCoreApplication::applicationDirPath(); +#ifdef Q_OS_MAC + // Because on Mac universal binaries are used, the binary path is not equal + // to the applications (.app) path. So get the .apps path here. + int indexOfDotApp = applicationBinaryPath.indexOf(".app"); + if ( indexOfDotApp != -1 ) { + // Cut off after the dot of ".app". + applicationBinaryPath = applicationBinaryPath.left( indexOfDotApp-1 ); + // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI") + applicationBinaryPath = applicationBinaryPath.left( applicationBinaryPath.lastIndexOf("/") ); + } +#endif + + // If the "config" directory is a subdir of the applications binary path, use this one (portable mode) + settingsPath = applicationBinaryPath + "/config"; + if ( QFile::exists( settingsPath ) ) { + portableMode = true; + QDir dirCreator; + globalFilesPath = applicationBinaryPath; + indenterPath = applicationBinaryPath + "/indenters"; + dirCreator.mkpath( settingsPath ); + tempPath = applicationBinaryPath + "/temp"; + //TODO: If the portable drive has write protection, use local temp path and clean it up on exit. + dirCreator.mkpath( tempPath ); + } + // ... otherwise use the system specific global application data path. + else { + portableMode = false; + QDir dirCreator; +#ifdef Q_OS_WIN + // Get the local users application settings directory. + settingsPath = QDir::fromNativeSeparators( qgetenv("APPDATA") ) + "/UniversalIndentGUI"; + // On windows systems the directories "indenters", "translations" are subdirs of the applicationBinaryPath. + globalFilesPath = applicationBinaryPath; +#else + settingsPath = QDir::homePath() + "/.universalindentgui"; + globalFilesPath = "/usr/share/universalindentgui"; +#endif + dirCreator.mkpath( settingsPath ); + // If a highlighter config file does not exist in the users home config dir + // copy the default config file over there. + if ( !QFile::exists(settingsPath+"/UiGuiSyntaxHighlightConfig.ini") ) { + QFile::copy( globalFilesPath+"/config/UiGuiSyntaxHighlightConfig.ini", settingsPath+"/UiGuiSyntaxHighlightConfig.ini" ); + } + indenterPath = globalFilesPath + "/indenters"; +#ifdef Q_OS_WIN + tempPath = QDir::tempPath() + "/UniversalIndentGUI"; +#else + tempPath = QDir::tempPath() + "UniversalIndentGUI"; +#endif + dirCreator.mkpath( tempPath ); + } +} + + +const QString SettingsPaths::getApplicationBinaryPath() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return applicationBinaryPath; +} + + +const QString SettingsPaths::getSettingsPath() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return settingsPath; +} + + +const QString SettingsPaths::getGlobalFilesPath() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return globalFilesPath; +} + + +const QString SettingsPaths::getIndenterPath() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return indenterPath; +} + + +const QString SettingsPaths::getTempPath() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return tempPath; +} + + +bool SettingsPaths::getPortableMode() { + if ( !alreadyInitialized ) { + SettingsPaths::init(); + } + return portableMode; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SettingsPaths.h Mon Jun 16 07:23:56 2008 +0000 @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef SETTINGSPATHS_H +#define SETTINGSPATHS_H + +#include <QString> +#include <QCoreApplication> +#include <QFile> +#include <QDir> + +class SettingsPaths +{ +public: + static void init(); + static const QString getApplicationBinaryPath(); + static const QString getSettingsPath(); + static const QString getGlobalFilesPath(); + static const QString getIndenterPath(); + static const QString getTempPath(); + static bool getPortableMode(); + +private: + static bool alreadyInitialized; + static QString applicationBinaryPath; + static QString settingsPath; + static QString globalFilesPath; + static QString indenterPath; + static QString tempPath; + static bool portableMode; +}; + +#endif // SETTINGSPATHS_H \ No newline at end of file
--- a/src/UniversalIndentGUI.vcproj Sun Jun 15 17:15:35 2008 +0000 +++ b/src/UniversalIndentGUI.vcproj Mon Jun 16 07:23:56 2008 +0000 @@ -241,6 +241,10 @@ > </File> <File + RelativePath=".\SettingsPaths.cpp" + > + </File> + <File RelativePath=".\uiguierrormessage.cpp" > </File> @@ -295,6 +299,10 @@ > </File> <File + RelativePath=".\SettingsPaths.h" + > + </File> + <File RelativePath=".\templateBatchScript.h" > </File>
--- a/src/mainwindow.cpp Sun Jun 15 17:15:35 2008 +0000 +++ b/src/mainwindow.cpp Mon Jun 16 07:23:56 2008 +0000 @@ -41,64 +41,12 @@ QDate buildDate(2008, 05, 26); buildDateStr = buildDate.toString("d. MMMM yyyy"); - // Get the applications binary path, with respect to MacOSXs use of the .app folder. - applicationBinaryPath = QCoreApplication::applicationDirPath(); -#ifdef Q_OS_MAC - // Because on Mac universal binaries are used, the binary path is not equal - // to the applications (.app) path. So get the .apps path here. - int indexOfDotApp = applicationBinaryPath.indexOf(".app"); - if ( indexOfDotApp != -1 ) { - // Cut off after the dot of ".app". - applicationBinaryPath = applicationBinaryPath.left( indexOfDotApp-1 ); - // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI") - applicationBinaryPath = applicationBinaryPath.left( applicationBinaryPath.lastIndexOf("/") ); - } -#endif - - // If the "config" directory is a subdir of the applications binary path, use this one (portable mode) - settingsDirctoryStr = applicationBinaryPath + "/config"; - if ( QFile::exists( settingsDirctoryStr ) ) { - portableMode = true; - QDir dirCreator; - globalFilesDirectoryStr = applicationBinaryPath; - indenterDirctoryStr = applicationBinaryPath + "/indenters"; - dirCreator.mkpath( settingsDirctoryStr ); - tempDirctoryStr = applicationBinaryPath + "/temp"; - //TODO: If the portable drive has write protection, use local temp path and clean it up on exit. - dirCreator.mkpath( tempDirctoryStr ); - } - // ... otherwise use the system specific global application data path. - else { - portableMode = false; - QDir dirCreator; -#ifdef Q_OS_WIN - // Get the local users application settings directory. - settingsDirctoryStr = QDir::fromNativeSeparators( qgetenv("APPDATA") ) + "/UniversalIndentGUI"; - // On windows systems the directories "indenters", "translations" are subdirs of the applicationBinaryPath. - globalFilesDirectoryStr = applicationBinaryPath; -#else - settingsDirctoryStr = QDir::homePath() + "/.universalindentgui"; - globalFilesDirectoryStr = "/usr/share/universalindentgui"; -#endif - dirCreator.mkpath( settingsDirctoryStr ); - // If a highlighter config file does not exist in the users home config dir - // copy the default config file over there. - if ( !QFile::exists(settingsDirctoryStr+"/UiGuiSyntaxHighlightConfig.ini") ) { - QFile::copy( globalFilesDirectoryStr+"/config/UiGuiSyntaxHighlightConfig.ini", settingsDirctoryStr+"/UiGuiSyntaxHighlightConfig.ini" ); - } - indenterDirctoryStr = globalFilesDirectoryStr + "/indenters"; -#ifdef Q_OS_WIN - tempDirctoryStr = QDir::tempPath() + "/UniversalIndentGUI"; -#else - tempDirctoryStr = QDir::tempPath() + "UniversalIndentGUI"; -#endif - dirCreator.mkpath( tempDirctoryStr ); - } - - qDebug() << "Using directories:\nsettings = " << settingsDirctoryStr; - qDebug() << "globalFiles = " << globalFilesDirectoryStr; - qDebug() << "indenterDirctoryStr = " << indenterDirctoryStr; - qDebug() << "tempDirctoryStr = " << tempDirctoryStr; + // Get all necessary paths. + settingsDirctoryStr = SettingsPaths::getSettingsPath(); + globalFilesDirectoryStr = SettingsPaths::getGlobalFilesPath(); + indenterDirctoryStr = SettingsPaths::getIndenterPath(); + tempDirctoryStr = SettingsPaths::getTempPath(); + portableMode = SettingsPaths::getPortableMode(); // Init of some variables. sourceCodeChanged = false;
--- a/src/mainwindow.h Sun Jun 15 17:15:35 2008 +0000 +++ b/src/mainwindow.h Mon Jun 16 07:23:56 2008 +0000 @@ -31,6 +31,7 @@ #include "highlighter.h" #include "indenthandler.h" #include "updatecheckdialog.h" +#include "SettingsPaths.h" #include <QWidget> #include <QString> @@ -85,7 +86,6 @@ QString revision; QString buildDateStr; bool portableMode; - QString applicationBinaryPath; QString globalFilesDirectoryStr; QString indenterDirctoryStr; QString tempDirctoryStr;