changeset 343:7bbcb5714983

Adaptions to retrieve the correct application base path oh MacOSX using universal binaries. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@567 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Sat, 12 Jan 2008 18:38:50 +0000
parents fc20f90fe609
children 56ad08f98050
files src/highlighter.cpp src/highlighter.h src/mainwindow.cpp src/mainwindow.h src/uiguisettings.cpp src/uiguisettings.h
diffstat 6 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/highlighter.cpp	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/highlighter.cpp	Sat Jan 12 18:38:50 2008 +0000
@@ -32,7 +32,7 @@
 /*!
     \brief The constructor initializes some regular expressions and keywords to identify cpp tokens
  */
-Highlighter::Highlighter(QsciScintilla *parent, QSettings *settings)
+Highlighter::Highlighter(QsciScintilla *parent, QString applicationBinaryPath, QSettings *settings)
 : QObject(parent)
 {
     this->parent = parent;
@@ -43,9 +43,9 @@
     }
     // ... else create a new own one.
     else {
-        QString settingsSubDir = QCoreApplication::applicationDirPath() + "/config/UiGuiSyntaxHighlightConfig.ini";
+        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( QCoreApplication::applicationDirPath() + "/indenters" ) ) {
+        if ( QFile::exists( applicationBinaryPath + "/indenters" ) ) {
             this->settings = new QSettings(settingsSubDir, QSettings::IniFormat, this);
         } 
         // ... otherwise use the users application data default dir.
--- a/src/highlighter.h	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/highlighter.h	Sat Jan 12 18:38:50 2008 +0000
@@ -53,7 +53,7 @@
     Q_OBJECT
 
 public:
-    Highlighter(QsciScintilla *parent, QSettings *settings=0);
+    Highlighter(QsciScintilla *parent, QString applicationBinaryPath, QSettings *settings=0);
     void turnHighlightOff();
     void turnHighlightOn();
 	
--- a/src/mainwindow.cpp	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/mainwindow.cpp	Sat Jan 12 18:38:50 2008 +0000
@@ -42,12 +42,23 @@
     buildDateStr = buildDate.toString("d. MMMM yyyy");
 
     // If a settings file in the subdir of the applications dir exists, use this one (portable mode)
-    indenterDirctoryStr = QCoreApplication::applicationDirPath() + "/indenters";
+	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 ) {
+	    //TODO: go back to next slash and not only substract 19, which is the length of "UniversalIndentGUI"
+	    applicationBinaryPath = applicationBinaryPath.left( indexOfDotApp-19 );
+	}
+	QMessageBox::warning(this, "", "Applicationpath =" + applicationBinaryPath);
+#endif
+    indenterDirctoryStr = applicationBinaryPath + "/indenters";
     if ( QFile::exists( indenterDirctoryStr ) ) {
         QDir dirCreator;
-        settingsDirctoryStr = QCoreApplication::applicationDirPath() + "/config";
+        settingsDirctoryStr = applicationBinaryPath + "/config";
         dirCreator.mkpath( settingsDirctoryStr );
-        tempDirctoryStr = QCoreApplication::applicationDirPath() + "/temp";
+        tempDirctoryStr = applicationBinaryPath + "/temp";
         dirCreator.mkpath( tempDirctoryStr );
     }
     // ... otherwise use the system specific global application data path.
@@ -77,7 +88,7 @@
     QCoreApplication::setApplicationName("UniversalIndentGUI");
 
     // Create the settings object, which loads all UiGui settings from a file.
-	settings = new UiGuiSettings( indenterDirctoryStr );
+	settings = new UiGuiSettings( indenterDirctoryStr, applicationBinaryPath );
 
     // Initialize the language of the application.
     initApplicationLanguage();
@@ -267,7 +278,7 @@
  */
 void MainWindow::initSyntaxHighlighter() {
     // Create the highlighter.
-    highlighter = new Highlighter(txtedSourceCode);
+    highlighter = new Highlighter(txtedSourceCode, applicationBinaryPath);
 
     // Handle if syntax highlighting is enabled
 	bool syntaxHighlightningEnabled = settings->getValueByName("SyntaxHighlightningEnabled").toBool();
--- a/src/mainwindow.h	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/mainwindow.h	Sat Jan 12 18:38:50 2008 +0000
@@ -82,6 +82,7 @@
     QString version;
     QString revision;
     QString buildDateStr;
+	QString applicationBinaryPath;
 	QString indenterDirctoryStr;
     QString tempDirctoryStr;
     QString settingsDirctoryStr;
--- a/src/uiguisettings.cpp	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/uiguisettings.cpp	Sat Jan 12 18:38:50 2008 +0000
@@ -30,10 +30,10 @@
 /*!
 	\brief The constructor for the settings.
 */
-UiGuiSettings::UiGuiSettings(QString indenterDirctoryStr) : QObject() {
-    QString settingsSubDir = QCoreApplication::applicationDirPath() + "/config/UniversalIndentGUI.ini";
+UiGuiSettings::UiGuiSettings(QString indenterDirctoryStr, QString applicationBinaryPath) : QObject() {
+    QString settingsSubDir = applicationBinaryPath + "/config/UniversalIndentGUI.ini";
     // If a "indenters" subdir in the applications binary path exists, use local config files (portable mode)
-    if ( QFile::exists( QCoreApplication::applicationDirPath() + "/indenters" ) ) {
+    if ( QFile::exists( applicationBinaryPath + "/indenters" ) ) {
         qsettings = new QSettings(settingsSubDir, QSettings::IniFormat, this);
     } 
     // ... otherwise use the users application data default dir.
--- a/src/uiguisettings.h	Sat Jan 12 17:15:03 2008 +0000
+++ b/src/uiguisettings.h	Sat Jan 12 18:38:50 2008 +0000
@@ -35,7 +35,7 @@
 	Q_OBJECT
 
 public:
-	UiGuiSettings(QString indenterDirctoryStr);
+	UiGuiSettings(QString indenterDirctoryStr, QString applicationBinaryPath);
     virtual ~UiGuiSettings();
     bool loadSettings();
     bool saveSettings();