Mercurial > hg > forks > UniversalIndentGUI
changeset 360:a3efe6d16a2b
- Easier handle differentiating between portable and multiuser mode by using a portablemode flag and a globalfilepath definition.
- Made the translation files be loaded from the correct path depending on whether in portable mode.
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@584 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Tue, 15 Jan 2008 11:41:15 +0000 |
parents | 90430239f1f5 |
children | cd9ea3a02066 |
files | src/highlighter.cpp src/highlighter.h src/mainwindow.cpp src/mainwindow.h src/uiguisettings.cpp src/uiguisettings.h |
diffstat | 6 files changed, 44 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/highlighter.cpp Tue Jan 15 11:33:01 2008 +0000 +++ b/src/highlighter.cpp Tue Jan 15 11:41:15 2008 +0000 @@ -32,28 +32,21 @@ /*! \brief The constructor initializes some regular expressions and keywords to identify cpp tokens */ -Highlighter::Highlighter(QsciScintilla *parent, QString applicationBinaryPath, QSettings *settings) +Highlighter::Highlighter(QsciScintilla *parent, bool portableMode, QString globalFilesDirectoryStr) : QObject(parent) { this->parent = parent; - // If a settings file/object is given along with the constructor parameters, use it... - if ( settings != NULL ) { - this->settings = settings; - } - // ... else create a new own one. + // If a "indenters" subdir in the applications binary path exists, use local config files (portable mode) + if ( portableMode ) { + this->settings = new QSettings(globalFilesDirectoryStr + "/config/UiGuiSyntaxHighlightConfig.ini", QSettings::IniFormat, this); + } + // ... otherwise use the users application data default dir. else { - QString settingsSubDir = applicationBinaryPath + "/config/UiGuiSyntaxHighlightConfig.ini"; - // If a "indenters" subdir in the applications binary path exists, use local config files (portable mode) - if ( QFile::exists( applicationBinaryPath + "/indenters" ) ) { - this->settings = new QSettings(settingsSubDir, QSettings::IniFormat, this); - } - // ... otherwise use the users application data default dir. - else { - this->settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), "UiGuiSyntaxHighlightConfig", this); - } + this->settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), "UiGuiSyntaxHighlightConfig", this); } + highlightningIsOn = true; mapHighlighternameToExtension["Bash"] = QStringList() << "sh";
--- a/src/highlighter.h Tue Jan 15 11:33:01 2008 +0000 +++ b/src/highlighter.h Tue Jan 15 11:41:15 2008 +0000 @@ -53,7 +53,7 @@ Q_OBJECT public: - Highlighter(QsciScintilla *parent, QString applicationBinaryPath, QSettings *settings=0); + Highlighter(QsciScintilla *parent, bool portableMode, QString globalFilesDirectoryStr); void turnHighlightOff(); void turnHighlightOn();
--- a/src/mainwindow.cpp Tue Jan 15 11:33:01 2008 +0000 +++ b/src/mainwindow.cpp Tue Jan 15 11:41:15 2008 +0000 @@ -41,7 +41,7 @@ QDate buildDate(2007, 11, 22); buildDateStr = buildDate.toString("d. MMMM yyyy"); - // If a settings file in the subdir of the applications dir exists, use this one (portable mode) + // 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 @@ -53,11 +53,14 @@ // Cut off after the first slash that was in front of ".app" (noramlly this is the word "UniversalIndentGUI") applicationBinaryPath = applicationBinaryPath.left( applicationBinaryPath.lastIndexOf("/") ); } - QMessageBox::warning(this, "", "Applicationpath =" + applicationBinaryPath); #endif + + // If the "indenters" directory is a subdir of the applications binary path, use this one (portable mode) indenterDirctoryStr = applicationBinaryPath + "/indenters"; if ( QFile::exists( indenterDirctoryStr ) ) { + portableMode = true; QDir dirCreator; + globalFilesDirectoryStr = applicationBinaryPath; settingsDirctoryStr = applicationBinaryPath + "/config"; dirCreator.mkpath( settingsDirctoryStr ); tempDirctoryStr = applicationBinaryPath + "/temp"; @@ -66,23 +69,24 @@ } // ... otherwise use the system specific global application data path. else { + portableMode = false; QDir dirCreator; #ifdef Q_OS_WIN settingsDirctoryStr = QDir::fromNativeSeparators( qgetenv("APPDATA") ) + "/UniversalIndentGUI"; QStringList commonAppBasePathComponents = QDir::fromNativeSeparators( qgetenv("APPDATA") ).split("/"); commonAppBasePathComponents.replace( commonAppBasePathComponents.count()-2, "All Users" ); - QString commonAppBasePath = commonAppBasePathComponents.join("/"); + globalFilesDirectoryStr = commonAppBasePathComponents.join("/") + "/UniversalIndentGUI"; #else settingsDirctoryStr = QDir::homePath() + "/.config/UniversalIndentGUI"; - QString commonAppBasePath = "/etc"; + globalFilesDirectoryStr = "/etc/UniversalIndentGUI"; #endif dirCreator.mkpath( settingsDirctoryStr ); // If a highlighter config file does not exist in the users home config dir // copy the default config file overthere. if ( !QFile::exists(settingsDirctoryStr+"/UiGuiSyntaxHighlightConfig.ini") ) { - QFile::copy( commonAppBasePath+"/UniversalIndentGUI/config/UiGuiSyntaxHighlightConfig.ini", settingsDirctoryStr+"/UiGuiSyntaxHighlightConfig.ini" ); + QFile::copy( globalFilesDirectoryStr+"/config/UiGuiSyntaxHighlightConfig.ini", settingsDirctoryStr+"/UiGuiSyntaxHighlightConfig.ini" ); } - indenterDirctoryStr = commonAppBasePath + "/UniversalIndentGUI/indenters"; + indenterDirctoryStr = globalFilesDirectoryStr + "/indenters"; tempDirctoryStr = QDir::tempPath() + "/UniversalIndentGUI"; dirCreator.mkpath( tempDirctoryStr ); } @@ -97,7 +101,7 @@ QCoreApplication::setApplicationName("UniversalIndentGUI"); // Create the settings object, which loads all UiGui settings from a file. - settings = new UiGuiSettings( indenterDirctoryStr, applicationBinaryPath ); + settings = new UiGuiSettings( portableMode, globalFilesDirectoryStr ); // Initialize the language of the application. initApplicationLanguage(); @@ -287,7 +291,7 @@ */ void MainWindow::initSyntaxHighlighter() { // Create the highlighter. - highlighter = new Highlighter(txtedSourceCode, applicationBinaryPath); + highlighter = new Highlighter(txtedSourceCode, portableMode, globalFilesDirectoryStr); // Handle if syntax highlighting is enabled bool syntaxHighlightningEnabled = settings->getValueByName("SyntaxHighlightningEnabled").toBool(); @@ -334,14 +338,15 @@ // Load the Qt own translation file and set it for the application. qTTranslator = new QTranslator(); - bool translationFileLoaded = qTTranslator->load( QString("./translations/qt_") + languageShort ); + bool translationFileLoaded; + translationFileLoaded = qTTranslator->load( globalFilesDirectoryStr + "/translations/qt_" + languageShort ); if ( translationFileLoaded ) { qApp->installTranslator(qTTranslator); } // Load the uigui translation file and set it for the application. uiGuiTranslator = new QTranslator(); - translationFileLoaded = uiGuiTranslator->load( QString("./translations/universalindent_") + languageShort ); + translationFileLoaded = uiGuiTranslator->load( globalFilesDirectoryStr + "/translations/universalindent_" + languageShort ); if ( translationFileLoaded ) { qApp->installTranslator(uiGuiTranslator); } @@ -1138,13 +1143,14 @@ qApp->removeTranslator( uiGuiTranslator ); // Load the Qt own translation file and set it for the application. - bool translationFileLoaded = qTTranslator->load( QString("./translations/qt_") + languageShort ); + bool translationFileLoaded; + translationFileLoaded = qTTranslator->load( globalFilesDirectoryStr + "/translations/qt_" + languageShort ); if ( translationFileLoaded ) { qApp->installTranslator(qTTranslator); } // Load the uigui translation file and set it for the application. - translationFileLoaded = uiGuiTranslator->load( QString("./translations/universalindent_") + languageShort ); + translationFileLoaded = uiGuiTranslator->load( globalFilesDirectoryStr + "/translations/universalindent_" + languageShort ); if ( translationFileLoaded ) { qApp->installTranslator(uiGuiTranslator); }
--- a/src/mainwindow.h Tue Jan 15 11:33:01 2008 +0000 +++ b/src/mainwindow.h Tue Jan 15 11:41:15 2008 +0000 @@ -82,7 +82,9 @@ QString version; QString revision; QString buildDateStr; + bool portableMode; QString applicationBinaryPath; + QString globalFilesDirectoryStr; QString indenterDirctoryStr; QString tempDirctoryStr; QString settingsDirctoryStr;
--- a/src/uiguisettings.cpp Tue Jan 15 11:33:01 2008 +0000 +++ b/src/uiguisettings.cpp Tue Jan 15 11:41:15 2008 +0000 @@ -17,7 +17,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "uiguisettings.h" +#include "uiguisettings.h" //! \defgroup grp_Settings All concerning the settings. @@ -30,18 +30,19 @@ /*! \brief The constructor for the settings. */ -UiGuiSettings::UiGuiSettings(QString indenterDirctoryStr, QString applicationBinaryPath) : QObject() { - QString settingsSubDir = applicationBinaryPath + "/config/UniversalIndentGUI.ini"; +UiGuiSettings::UiGuiSettings(bool portableMode, QString globalFilesDirectoryStr) : QObject() { // If a "indenters" subdir in the applications binary path exists, use local config files (portable mode) - if ( QFile::exists( applicationBinaryPath + "/indenters" ) ) { - qsettings = new QSettings(settingsSubDir, QSettings::IniFormat, this); + if ( portableMode ) { + qsettings = new QSettings(globalFilesDirectoryStr + "/config/UniversalIndentGUI.ini", QSettings::IniFormat, this); } // ... otherwise use the users application data default dir. else { qsettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName(), this); } - - this->indenterDirctoryStr = indenterDirctoryStr; + + this->globalFilesDirectoryStr = globalFilesDirectoryStr; + this->portableMode = portableMode; + indenterDirctoryStr = globalFilesDirectoryStr + "/indenters"; readAvailableTranslations(); loadSettings(); } @@ -68,8 +69,8 @@ languageFileList << "universalindent_en.qm"; // Find all translation files in the "translations" directory. - QDir translationDirectory = QDir("./translations"); - languageFileList << translationDirectory.entryList( QStringList("universalindent_*.qm") ); + QDir translationDirectory = QDir( globalFilesDirectoryStr + "/translations" ); + languageFileList << translationDirectory.entryList( QStringList("universalindent_*.qm") ); // Loop for each found translation file foreach ( languageShort, languageFileList ) {
--- a/src/uiguisettings.h Tue Jan 15 11:33:01 2008 +0000 +++ b/src/uiguisettings.h Tue Jan 15 11:41:15 2008 +0000 @@ -35,7 +35,7 @@ Q_OBJECT public: - UiGuiSettings(QString indenterDirctoryStr, QString applicationBinaryPath); + UiGuiSettings(bool portableMode, QString globalFilesDirectoryStr); virtual ~UiGuiSettings(); bool loadSettings(); bool saveSettings(); @@ -84,8 +84,10 @@ //! This map holds all possible settings defined by their name as QString. The value is of the type QVariant. QMap<QString, QVariant> settings; - - QString indenterDirctoryStr; + + QString globalFilesDirectoryStr; + QString indenterDirctoryStr; + bool portableMode; }; #endif // UIGUISETTINGS_H