Allow default settings to be set via a global config file. This allows redistributors...
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 16 May 2008 10:15:20 +0000 (10:15 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 16 May 2008 10:15:20 +0000 (10:15 +0000)
While we're at it, refactor the path search code to be a little more maintainable.

Tested on Windows so far - expect bug fixes for other platforms :-p

git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7293 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/Makefile.am
pgadmin/debugger/dlgDirectDbg.cpp
pgadmin/frm/plugins.cpp
pgadmin/include/pgAdmin3.h
pgadmin/include/utils/sysSettings.h
pgadmin/pgAdmin3.cpp
pgadmin/pgAdmin3.vcproj
pgadmin/settings.ini [new file with mode: 0644]
pgadmin/ui/module.mk
pgadmin/utils/sysSettings.cpp

index d32913af5b683da230e4f0c303cb2d6d135c4e53..82b57d40ea0d22667a94e83bbd349abe1fb041b9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,6 +36,9 @@ Changes
 \r
 Date       Dev Ver    Change details\r
 ---------- --- -----  --------------\r
+2008-05-16 DP  1.9.0  Allow default settings to be set via a global config\r
+                      file. This allows redistributors and sysadmins to\r
+                      pre-configure an installation as required.\r
 2008-05-15 DP  1.9.0  Add support for TRUNCATE triggers on PostgreSQL 8.4+.\r
 2008-05-06 DP  1.9.0  Auto-discover Postgres Plus servers on Mac and Unix.\r
 2008-05-06 DP  1.8.3  Fix a corner case in which closing the debugger window\r
index d45aa709294d1963cebd61813cae6ceb720c662e..2051a7b8388651d01ff67f15c14d1988604b9eed 100644 (file)
@@ -20,6 +20,9 @@ EXTRA_DIST = \
        $(srcdir)/precomp.cpp \
        $(srcdir)/pgAdmin3.rc \
        $(srcdir)/ver_svn.bat
+       
+nobase_dist_pkgdata_DATA = \
+    $(srcdir)/settings.ini
 
 # Generate svnversion.h every time, but only if repo version has changed.
 .PHONY: $(srcdir)/include/svnversion.cpp
@@ -63,7 +66,7 @@ endif
 if !APPBUNDLE
 
 if BUILD_DEBUG
-nobase_dist_pkgdata_DATA = $(TMP_ui)
+nobase_dist_pkgdata_DATA += $(TMP_ui)
 endif
 AM_CXXFLAGS = -DDATA_DIR=\"$(pkgdatadir)/\" $(__CXXFLAGS) -I$(top_srcdir)/pgadmin/include $(__EDB_LIBPQ)
 AM_CFLAGS = -DDATA_DIR=\"$(pkgdatadir)/\" $(__CFLAGS) -I$(top_srcdir)/pgadmin/include $(__EDB_LIBPQ)
@@ -75,7 +78,7 @@ install-exec-hook:
 else
 
 if BUILD_DEBUG
-nobase_dist_data_DATA = $(TMP_ui)
+nobase_dist_data_DATA += $(TMP_ui)
 endif
 AM_CXXFLAGS = $(__CXXFLAGS) -I$(top_srcdir)/pgadmin/include $(__EDB_LIBPQ)
 AM_CFLAGS = $(__CFLAGS) -I$(top_srcdir)/pgadmin/include $(__EDB_LIBPQ)
index c585ce4f0795d10a376ebecc275f5911063ca99d..ae093df45e056f01c4cf8a8ccd8c4c1f693c3e05 100644 (file)
@@ -363,8 +363,6 @@ void dlgDirectDbg::saveSettings()
             settings->Write( wxString::Format( wxT( "Debugger/Proc/argValue%d" ),  count ), (arg.getValue() == wxT("NULL") ? wxEmptyString : arg.getValue().c_str()));
         }
     }
-
-    settings->Flush();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 198838394090e3659dccf8f00f8b84efb2750b42..c8b4353e9c3d0f66d2f21f17d546e7570cbe20e9 100644 (file)
@@ -25,8 +25,6 @@
 #include "schema/pgSchema.h"\r
 #include "schema/pgTable.h"\r
 \r
-extern wxString utilitiesIni;\r
-\r
 void frmMain::LoadPluginUtilities()\r
 {\r
     if (utilitiesIni.IsEmpty())\r
index 28e6fb1a432c9574c4075c4fab34de74af0ff13a..c4ac7371fec0ec452418e77e8f925fcae67edc3a 100644 (file)
@@ -68,6 +68,8 @@ extern wxString loadPath;              // Where the program is loaded from
 extern wxString docPath;               // Where docs are stored
 extern wxString uiPath;                // Where ui data is stored
 extern wxString i18nPath;              // Where i18n data is stored
+extern wxString utilitiesIni;          // The plugins ini
+extern wxString settingsIni;           // The default settings file
 
 // 
 // Support for additional functions included in the EnterpriseDB
@@ -118,6 +120,7 @@ public:
 #endif
 
 private:
+       wxString LocatePath(const wxString &pathToFind, const bool isFile);
     wxString GenerateHelpPath(const wxString &file, const wxString &current, wxPathList stdPaths, wxPathList dbmsPaths);
     bool LoadAllXrc(const wxString dir);
 
@@ -126,7 +129,8 @@ private:
 #endif
        
 protected:
-    void InitPaths();
+    void InitAppPaths();
+    void InitXtraPaths();
     void InitHelp();
     void InitLogger();
     void InitNetwork();
index 47bb5259eb4c58393f431cdc96c3826a63b441a8..55e6524bcd6e03a21c8f5851da8e8752519e7131 100644 (file)
@@ -15,7 +15,7 @@
 // wxWindows headers
 #include <wx/wx.h>
 #include <wx/config.h>
-
+#include <wx/fileconf.h>
 
 // Class declarations
 class sysSettings : public wxConfig
@@ -142,17 +142,12 @@ public:
     bool Write(const wxString &key, const wxSize &size, const wxPoint &point)
         { Write(key, point); Write(key, size); return true;}
 
-    bool Read(const wxString& key, wxString* str, const wxString& defaultVal) const
-        { return wxConfig::Read(key, str, defaultVal); }
+    bool Read(const wxString& key, wxString* str, const wxString& defaultVal) const;
     bool Read(const wxString& key, bool* str, bool defaultVal) const;
-    bool Read(const wxString& key, int* i, int defaultVal) const
-        { return wxConfig::Read(key, i, defaultVal); }
-    bool Read(const wxString& key, long* l, long defaultVal) const
-        { return wxConfig::Read(key, l, defaultVal); }
-    wxString Read(const wxString& key, const wxString &defaultVal) const
-        { return wxConfig::Read(key, defaultVal); }
-    long Read(const wxString& key, long defaultVal) const
-        { return wxConfig::Read(key, defaultVal); }
+    bool Read(const wxString& key, int* i, int defaultVal) const;
+    bool Read(const wxString& key, long* l, long defaultVal) const;
+    wxString Read(const wxString& key, const wxString &defaultVal) const;
+    long Read(const wxString& key, long defaultVal) const;
     wxPoint Read(const wxString& key, const wxPoint &defaultVal) const;
     wxSize Read(const wxString& key, const wxSize &defaultVal) const;
 
@@ -192,6 +187,8 @@ private:
     bool moveStringValue(const wxChar *oldKey, const wxChar *newKey, int index=-1);
     bool moveLongValue(const wxChar *oldKey, const wxChar *newKey, int index=-1);
 
+       wxFileConfig *defaultSettings; 
+
     wxFont systemFont, sqlFont; 
 
     // Tip Of The Day
index b41b376b0a5e202e8a3f2f12f239cd7730a579e1..d44b613a2ab9d9b8bfaa414b438c9246d24d5664 100644 (file)
@@ -70,6 +70,7 @@
 #define I18N_DIR     wxT("/i18n")
 #define BRANDING_DIR wxT("/branding")
 #define UTILITIES_INI wxT("/plugins/utilities.ini")
+#define SETTINGS_INI wxT("/settings.ini")
 
 // Globals
 frmMain *winMain=0;
@@ -94,7 +95,8 @@ wxString docPath;               // Where docs are stored
 wxString uiPath;                // Where ui data is stored
 wxString i18nPath;              // Where i18n data is stored
 wxString brandingPath;                 // Where branding data is stored
-wxString utilitiesIni;           // The utilities.ini file
+wxString utilitiesIni;          // The utilities.ini file
+wxString settingsIni;           // The settings.ini file
 
 wxLog *logger;
 
@@ -201,6 +203,9 @@ bool pgAdmin3::OnInit()
                {wxCMD_LINE_NONE}
        };
 
+    // Setup the basic paths for the app installation. Required by settings!
+    InitAppPaths();
+
     // Load the Settings
 #ifdef __WXMSW__
     settings = new sysSettings(wxT("pgAdmin III"));
@@ -208,8 +213,8 @@ bool pgAdmin3::OnInit()
     settings = new sysSettings(wxT("pgadmin3"));
 #endif
 
-    // we are here
-    InitPaths();
+    // Setup additional helper paths etc. Requires settings!
+    InitXtraPaths();
 
     frmConfig::tryMode configMode=frmConfig::NONE;
        wxString configFile;
@@ -268,6 +273,7 @@ bool pgAdmin3::OnInit()
     wxLogInfo(wxT("Doc path     : %s"), docPath.c_str());
     wxLogInfo(wxT("Branding path: %s"), brandingPath.c_str());
     wxLogInfo(wxT("Utilities INI: %s"), utilitiesIni.c_str());
+       wxLogInfo(wxT("Settings INI : %s"), settingsIni.c_str());
 
     wxLogInfo(wxT("PG pg_dump    : %s"), pgBackupExecutable.c_str());
     wxLogInfo(wxT("PG pg_dumpall : %s"), pgBackupAllExecutable.c_str());
@@ -602,149 +608,20 @@ void pgAdmin3::MacOpenFile(const wxString &fileName)
 }
 #endif
 
-void pgAdmin3::InitPaths()
+// Setup the paths for the application itself
+void pgAdmin3::InitAppPaths()
 {
-    loadPath=wxPathOnly(argv[0]);
-       if (loadPath.IsEmpty())
-               loadPath = wxT(".");
-
-#ifdef __WXMSW__
-
-    // Search for the right paths. We check the following locations:
-    //
-    // 1) ./xxx               - Running as a standalone install
-    // 2) ../pgAdmin/xxx      - Running in a pgInstaller 8.1 installation 
-    //                          (with the .exe and dlls in the main bin dir)
-    // 3) ../../xxx or ../xxx - Running in a development environment
-    
-    if (wxDir::Exists(loadPath + I18N_DIR))
-        i18nPath = loadPath + I18N_DIR;
-    else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + I18N_DIR))
-        i18nPath = loadPath + wxT("/../pgAdmin III") + I18N_DIR;
-    else 
-        i18nPath = loadPath + wxT("/../..") + I18N_DIR;
-
-    if (wxDir::Exists(loadPath + DOC_DIR))
-        docPath = loadPath + DOC_DIR;
-    else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") DOC_DIR))
-        docPath = loadPath + wxT("/../pgAdmin III") DOC_DIR;
-    else
-        docPath = loadPath + wxT("/../..") DOC_DIR;
-
-    if (wxDir::Exists(loadPath + UI_DIR))
-        uiPath = loadPath + UI_DIR;
-    if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + UI_DIR))
-        uiPath = loadPath + wxT("/../pgAdmin III") + UI_DIR;
-    else
-        uiPath = loadPath + wxT("/..") UI_DIR;
-
-    if (wxDir::Exists(loadPath + BRANDING_DIR))
-        brandingPath = loadPath + BRANDING_DIR;
-    else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + BRANDING_DIR))
-        brandingPath = loadPath + wxT("/../pgAdmin III") + BRANDING_DIR;
-    else 
-        brandingPath = loadPath + wxT("/../..") + BRANDING_DIR;
-
-    // utilities.ini
-    if (wxFile::Exists(loadPath + UTILITIES_INI))
-        utilitiesIni = loadPath + UTILITIES_INI;
-    else if (wxFile::Exists(loadPath + wxT("/../pgAdmin III") + UTILITIES_INI))
-        utilitiesIni = loadPath + wxT("/../pgAdmin III") + UTILITIES_INI;
-    else if (wxFile::Exists(loadPath + wxT("/../..") + UTILITIES_INI))
-        utilitiesIni = loadPath + wxT("/../..") + UTILITIES_INI;
-#else
-
-    wxString dataDir;
-
-#ifdef __WXMAC__
-
-    // When using wxStandardPaths on OSX, wx default to the unix,
-    // not to the mac variants. Therefore, we request wxStandardPathsCF
-    // directly.
-    wxStandardPathsCF stdPaths ;
-    dataDir = stdPaths.GetDataDir() ;
-
-#else // other *ixes
-
-// Data path (defined by configure under Unix).
-#ifndef DATA_DIR
-#define DATA_DIR "./"
-#endif
-
-    dataDir = wxString::FromAscii(DATA_DIR);
-#endif
-  
-    // On unix systems, the search path is as follows:
-    //
-    // 1) DATADIR/xxx              - DATADIR being defined by configure
-    // 2) ./../share/pgadmin3/xxx  - The default 'make install' layout, but allowing for relocation
-    // 3) ./xxx                    - Windows-style standalone install
-    // 4) ./../xxx                 - Unix-style standalone install (with binaries in a bin directory)
-
-    if (wxDir::Exists(dataDir + I18N_DIR))
-        i18nPath = dataDir + I18N_DIR;
-    
-    if (wxDir::Exists(dataDir + UI_DIR))
-        uiPath = dataDir + UI_DIR;
-
-    if (wxDir::Exists(dataDir + DOC_DIR))
-        docPath = dataDir + DOC_DIR ;
-
-    if (wxDir::Exists(dataDir + BRANDING_DIR))
-        brandingPath = dataDir + BRANDING_DIR ;
-
-    if (wxFile::Exists(dataDir + UTILITIES_INI))
-        utilitiesIni = dataDir + UTILITIES_INI;
-
-    if (i18nPath.IsEmpty())
-    {
-        if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") I18N_DIR))
-            i18nPath = loadPath + wxT("/../share/pgadmin3") I18N_DIR;
-        else if (wxDir::Exists(loadPath + I18N_DIR))
-            i18nPath = loadPath + I18N_DIR;
-        else
-            i18nPath = loadPath + wxT("/..") I18N_DIR;
-    }
-    if (uiPath.IsEmpty())
-    {
-        if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") UI_DIR))
-            uiPath = loadPath + wxT("/../share/pgadmin3") UI_DIR;
-        else if (wxDir::Exists(loadPath + UI_DIR))
-            uiPath = loadPath + UI_DIR;
-        else 
-            uiPath = loadPath + wxT("/..") UI_DIR;
-    }
-    if (docPath.IsEmpty())
-    {
-        if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") DOC_DIR))
-            docPath = loadPath + wxT("/../share/pgadmin3") DOC_DIR;
-        else if (wxDir::Exists(loadPath + DOC_DIR))
-            docPath = loadPath + DOC_DIR ;
-        else
-            docPath = loadPath + wxT("/..") DOC_DIR ;
-    }
-    if (brandingPath.IsEmpty())
-    {
-        if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") BRANDING_DIR))
-            brandingPath = loadPath + wxT("/../share/pgadmin3") BRANDING_DIR;
-        else if (wxDir::Exists(loadPath + BRANDING_DIR))
-            brandingPath = loadPath + BRANDING_DIR ;
-        else
-            brandingPath = loadPath + wxT("/..") BRANDING_DIR ;
-    }
-
-    // utilities.ini
-    if (utilitiesIni.IsEmpty())
-    {
-        if (wxFile::Exists(loadPath + wxT("/../share/pgadmin3") UTILITIES_INI))
-            utilitiesIni = loadPath + wxT("/../share/pgadmin3") UTILITIES_INI;
-        else if (wxFile::Exists(loadPath + UTILITIES_INI))
-            utilitiesIni = loadPath + UTILITIES_INI;
-        else if (wxFile::Exists(loadPath + wxT("/..") UTILITIES_INI))
-            utilitiesIni = loadPath + wxT("/..") UTILITIES_INI;
-    }
-#endif
+       i18nPath = LocatePath(I18N_DIR, false);
+       docPath = LocatePath(DOC_DIR, false);
+       uiPath = LocatePath(UI_DIR, false);
+       brandingPath = LocatePath(BRANDING_DIR, false);
+       utilitiesIni = LocatePath(UTILITIES_INI, true);
+       settingsIni = LocatePath(SETTINGS_INI, true);
+}
 
+// Setup the paths for the helper apps etc.
+void pgAdmin3::InitXtraPaths()
+{
     //////////////////////////////////
     // Now setup the app helper paths
     //////////////////////////////////
@@ -822,6 +699,9 @@ void pgAdmin3::InitPaths()
         wxPathList path;
 
 #ifdef __WXMSW__
+               path.Add(wxT("C:\\PostgresPlus\\8.4\\dbserver\\bin"));
+        path.Add(wxT("C:\\PostgresPlus\\8.3\\dbserver\\bin"));
+               path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.4\\bin"));
         path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.3\\bin"));
         path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.2\\bin"));
         path.Add(wxT("C:\\Program Files\\PostgreSQL\\8.1\\bin"));
@@ -829,6 +709,14 @@ void pgAdmin3::InitPaths()
 
         wxFileName tmp = path.FindValidPath(wxT("pg_dump.exe"));
 #else
+        // Mac paths
+               path.Add(wxT("/Library/PostgresPlus/8.4/dbserver/bin"));
+               path.Add(wxT("/Library/PostgresPlus/8.3/bin"));
+
+               // Generic Unix paths
+               path.Add(wxT("/opt/PostgresPlus/8.4/dbserver/bin"));
+               path.Add(wxT("/opt/PostgresPlus/8.3/dbserver/bin"));
+               path.Add(wxT("/opt/PostgresPlus/8.3/bin"));
         path.Add(wxT("/usr/local/pgsql/bin"));
         path.Add(wxT("/usr/local/bin"));
         path.Add(wxT("/usr/bin"));
@@ -852,14 +740,21 @@ void pgAdmin3::InitPaths()
         wxPathList path;
 
 #ifdef __WXMSW__
-        path.Add(wxT("C:\\EnterpriseDB\\8.3\\dbserver\\bin"));
+               path.Add(wxT("C:\\PostgresPlus\\8.4AS\\dbserver\\bin"));
+        path.Add(wxT("C:\\PostgresPlus\\8.3AS\\dbserver\\bin"));
         path.Add(wxT("C:\\EnterpriseDB\\8.2\\dbserver\\bin"));
         path.Add(wxT("C:\\EnterpriseDB\\8.1\\dbserver\\bin"));
         path.Add(wxT("C:\\EnterpriseDB\\8.0\\dbserver\\bin"));
 
         wxFileName tmp = path.FindValidPath(wxT("pg_dump.exe"));
 #else
-        path.Add(wxT("/opt/EnterpriseDB/8.3/dbserver/bin"));
+        // Mac paths
+               path.Add(wxT("/Library/PostgresPlus/8.4AS/dbserver/bin"));
+               path.Add(wxT("/Library/PostgresPlus/8.3AS/dbserver/bin"));
+
+               // Generic Unix paths
+               path.Add(wxT("/opt/PostgresPlus/8.4AS/dbserver/bin"));
+               path.Add(wxT("/opt/PostgresPlus/8.3AS/dbserver/bin"));
         path.Add(wxT("/usr/local/enterpriseDB/bin"));
         path.Add(wxT("/usr/local/enterprisedb/bin"));
         path.Add(wxT("/usr/local/edb/bin"));
@@ -912,14 +807,109 @@ void pgAdmin3::InitPaths()
         edbBackupAllExecutable = wxEmptyString;
     if (!isEdbApp(edbRestoreExecutable))
         edbRestoreExecutable = wxEmptyString;
+}
+
+wxString pgAdmin3::LocatePath(const wxString &pathToFind, const bool isFile)
+{
+       loadPath = wxPathOnly(argv[0]);
+
+       if (loadPath.IsEmpty())
+               loadPath = wxT(".");
+
+       loadPath = sanitizePath(loadPath);
+
+#if defined(__WXMSW__)
+
+    // Search for the right paths. We check the following locations:
+    //
+    // 1) ./xxx               - Running as a standalone install
+    // 2) ../pgAdmin/xxx      - Running in a pgInstaller 8.1 installation 
+    //                          (with the .exe and dlls in the main bin dir)
+    // 3) ../xxx or ../../xxx - Running in a development environment
+    
+       if (!isFile)
+       {
+               if (wxDir::Exists(loadPath + pathToFind))
+                       return sanitizePath(loadPath + pathToFind);
+               else if (wxDir::Exists(loadPath + wxT("/../pgAdmin III") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/../pgAdmin III") + pathToFind);
+               else if (wxDir::Exists(loadPath + wxT("/..") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/..") + pathToFind);
+               else if (wxDir::Exists(loadPath + wxT("/../..") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/../..") + pathToFind);
+               else
+                       return wxEmptyString;
+       }
+       else
+       {
+               if (wxFile::Exists(loadPath + pathToFind))
+                       return sanitizePath(loadPath + pathToFind);
+               else if (wxFile::Exists(loadPath + wxT("/../pgAdmin III") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/../pgAdmin III") + pathToFind);
+               else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/..") + pathToFind);
+               else if (wxFile::Exists(loadPath + wxT("/../..") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/../..") + pathToFind);
+               else 
+                       return wxEmptyString;
+       }
+
+#else
+    wxString dataDir, thePath;
+
+#ifdef __WXMAC__
 
-    // Now sanitize all the paths
-    loadPath = sanitizePath(loadPath);
-    docPath = sanitizePath(docPath);
-    uiPath = sanitizePath(uiPath);
-    i18nPath = sanitizePath(i18nPath);
-    brandingPath = sanitizePath(brandingPath);
-    utilitiesIni = sanitizePath(utilitiesIni);
+    // When using wxStandardPaths on OSX, wx default to the unix,
+    // not to the mac variants. Therefore, we request wxStandardPathsCF
+    // directly.
+    wxStandardPathsCF stdPaths ;
+    dataDir = stdPaths.GetDataDir() ;
+
+#else // other *ixes
+
+// Data path (defined by configure under Unix).
+#ifndef DATA_DIR
+#define DATA_DIR "./"
+#endif
+
+    dataDir = wxString::FromAscii(DATA_DIR);
+#endif
+  
+    // On unix systems, the search path is as follows:
+    //
+    // 1) DATADIR/xxx              - DATADIR being defined by configure
+    // 2) ./../share/pgadmin3/xxx  - The default 'make install' layout, but allowing for relocation
+    // 3) ./xxx                    - Windows-style standalone install
+    // 4) ./../xxx                 - Unix-style standalone install (with binaries in a bin directory)
+
+       if (!isFile)
+       {
+           if (wxDir::Exists(dataDir + pathToFind))
+            return sanitizePath(dataDir + pathToFind);
+               else if (wxDir::Exists(loadPath + wxT("/../share/pgadmin3") + pathToFind))
+            return sanitizePath(loadPath + wxT("/../share/pgadmin3") + pathToFind);
+        else if (wxDir::Exists(loadPath + pathToFind))
+            return sanitizePath(loadPath + pathToFind);
+        else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+            return sanitizePath(loadPath + wxT("/..") + pathToFind);
+               else 
+                       return wxEmptyString;
+       }
+       else
+       {
+           if (wxFile::Exists(dataDir + pathToFind))
+            return sanitizePath(dataDir + pathToFind);
+        else if (wxFile::Exists(loadPath + wxT("/../share/pgadmin3") + pathToFind))
+                       return sanitizePath(loadPath + wxT("/../share/pgadmin3") + pathToFind);
+        else if (wxFile::Exists(loadPath + pathToFind))
+            return sanitizePath(loadPath + pathToFind);
+        else if (wxFile::Exists(loadPath + wxT("/..") + pathToFind))
+            return sanitizePath(loadPath + wxT("/..") pathToFind);
+               else 
+                       return wxEmptyString;
+       }
+
+#endif
 }
 
 void pgAdmin3::InitHelp()
index a18905ed9bc2cc71e7f66e3cc2b2889e14e85c63..0ab373a750371f8ffc12c011bf57ab590d667be0 100644 (file)
                                />\r
                        </FileConfiguration>\r
                </File>\r
+               <File\r
+                       RelativePath=".\settings.ini"\r
+                       >\r
+               </File>\r
                <File\r
                        RelativePath=".\ver_svn.bat"\r
                        >\r
diff --git a/pgadmin/settings.ini b/pgadmin/settings.ini
new file mode 100644 (file)
index 0000000..9856af4
--- /dev/null
@@ -0,0 +1,32 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
+;\r
+; pgAdmin III - PostgreSQL Tools\r
+; RCS-ID:      $Id$\r
+; Copyright (C) 2002 - 2008, The pgAdmin Development Team\r
+; This software is released under the Artistic Licence\r
+;\r
+; settings.ini\r
+;\r
+; This file, if present, specifies the default configuration settings that\r
+; pgAdmin will use if the user doesn't have a value already stored in their\r
+; preferences file (or the registry on Windows). If a value is not present in\r
+; this file, a hard-coded default is used. \r
+;\r
+; This file should be located alongside pgAdmin3.exe on Windows, and in the\r
+; program data directory (normally called 'share') on Unix platforms.\r
+;\r
+; Use the familiar .ini file format, with settings paths in section names if\r
+; required, eg.\r
+;\r
+; ShowTipOfTheDay=false\r
+; LogFile=/tmp/pgadmin3.log\r
+;\r
+; [Servers]\r
+; Count=99\r
+;\r
+; [Servers/1]\r
+; Server=127.0.0.1\r
+; Description=Development\r
+; Port=5432\r
+;\r
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\ No newline at end of file
index 4e764c9496090473be92ed14ab82584ed2d4b251..b566803ef08a8245cf8cefeabfa6481ec8134d0f 100644 (file)
@@ -21,7 +21,7 @@ TMP_ui += \
        $(srcdir)/ui/dlgConnect.xrc \
        $(srcdir)/ui/dlgConversion.xrc \
        $(srcdir)/ui/dlgDatabase.xrc \
-        $(srcdir)/ui/dlgDirectDbg.xrc \
+    $(srcdir)/ui/dlgDirectDbg.xrc \
        $(srcdir)/ui/dlgDomain.xrc \
        $(srcdir)/ui/dlgEditGridOptions.xrc \
        $(srcdir)/ui/dlgFindReplace.xrc \
@@ -80,7 +80,7 @@ TMP_ui += \
        $(srcdir)/ui/frmStatus.xrc
 
 EXTRA_DIST += \
-        $(srcdir)/ui/module.mk \
+    $(srcdir)/ui/module.mk \
        $(srcdir)/ui/embed-xrc \
        $(srcdir)/ui/embed-xrc.bat
 
index 1499c00837b6a4de80b6dbfb955a85b2fa56d180..f49ce8f03a3e7439ab8be7d98d675542335b1323 100644 (file)
 // wxWindows headers
 #include <wx/wx.h>
 #include <wx/config.h>
+#include <wx/fileconf.h>
 #include <wx/url.h>
 #include <wx/stdpaths.h>
+#include <wx/wfstream.h>
 
 // App headers
 #include "utils/sysSettings.h"
 #include "utils/sysLogger.h"
 #include "utils/misc.h"
 
-extern wxString docPath;
-
-
-
 sysSettings::sysSettings(const wxString& name) : wxConfig(name)
 {
+       // Open the default settings file
+       defaultSettings = NULL;
+       if (!settingsIni.IsEmpty())
+       {
+           wxFileStream fst(settingsIni);
+        defaultSettings = new wxFileConfig(fst);
+       }       
 
     // Convert setting from pre-1.3
 #ifdef __WXMSW__
@@ -72,7 +77,6 @@ sysSettings::sysSettings(const wxString& name) : wxConfig(name)
             moveLongValue(wxT("Servers/SSL%d"), wxT("Servers/%d/SSL"), i);
         }
     }
-
         
     // Tip Of The Day
     Read(wxT("ShowTipOfTheDay"), &showTipOfTheDay, true); 
@@ -487,19 +491,129 @@ void sysSettings::Save()
         Write(wxT("Font"), fontName);
 }
 
+// Read a string value
+bool sysSettings::Read(const wxString& key, wxString* str, const wxString& defaultVal) const
+{ 
+       wxString actualDefault = defaultVal;
+
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, defaultVal);
+
+       return wxConfig::Read(key, str, actualDefault); 
+}
+
+// Return a string value
+wxString sysSettings::Read(const wxString& key, const wxString &defaultVal) const
+{ 
+       wxString actualDefault = defaultVal;
+
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+    if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, defaultVal);
+
+       return wxConfig::Read(key, actualDefault); 
+}
+
+// Read an int value
+bool sysSettings::Read(const wxString& key, int* i, int defaultVal) const
+{ 
+       int actualDefault = defaultVal;
+       
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, defaultVal);
+
+       return wxConfig::Read(key, i, actualDefault); 
+}
+
+// Read a long value
+bool sysSettings::Read(const wxString& key, long* l, long defaultVal) const
+{ 
+       long actualDefault = defaultVal;
+       
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, defaultVal);
+
+       return wxConfig::Read(key, l, actualDefault); 
+}
+
+
+// Return a long value
+long sysSettings::Read(const wxString& key, long defaultVal) const
+{ 
+       long actualDefault = defaultVal;
+       
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, defaultVal);
+
+       return wxConfig::Read(key, actualDefault); 
+}
+
+// Read a boolean value
 bool sysSettings::Read(const wxString& key, bool *val, bool defaultVal) const
 {
+       wxString actualDefault = BoolToStr(defaultVal);
     wxString str;
-    Read(key, &str, BoolToStr(defaultVal));
+
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+    if (defaultSettings)
+        defaultSettings->Read(key, &actualDefault, BoolToStr(defaultVal));
+
+    Read(key, &str, actualDefault);
     *val = StrToBool(str);
     return true;
 }
 
+// Read a point value
+wxPoint sysSettings::Read(const wxString& key, const wxPoint &defaultVal) const
+{
+       wxPoint actualDefault = defaultVal;
+
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+       {
+           actualDefault.x = defaultSettings->Read(key + wxT("/Left"), defaultVal.x);
+        actualDefault.y = defaultSettings->Read(key + wxT("/Top"), defaultVal.y);
+       }
+
+    return wxPoint(wxConfig::Read(key + wxT("/Left"), actualDefault.x), 
+                   wxConfig::Read(key + wxT("/Top"), actualDefault.y));
+}
+
+// Read a size value
+wxSize sysSettings::Read(const wxString& key, const wxSize &defaultVal) const
+{
+       wxSize actualDefault = defaultVal;
+
+       // Get the default from the defaults file, in preference 
+       // to the hardcoded value
+       if (defaultSettings)
+       {
+        actualDefault.x = defaultSettings->Read(key + wxT("/Width"), defaultVal.x);
+        actualDefault.y = defaultSettings->Read(key + wxT("/Height"), defaultVal.y);
+       }
+
+    return wxSize(wxConfig::Read(key + wxT("/Width"), actualDefault.x), 
+                  wxConfig::Read(key + wxT("/Height"), actualDefault.y));
+}
+
+// Write a boolean value
 bool sysSettings::Write(const wxString &key, bool value)
 {
     return Write(key, BoolToStr(value));
 }
 
+// Write a point value
 bool sysSettings::Write(const wxString &key, const wxPoint &value)
 {
     bool rc=wxConfig::Write(key + wxT("/Left"), value.x);
@@ -508,7 +622,7 @@ bool sysSettings::Write(const wxString &key, const wxPoint &value)
     return rc;
 }
 
-
+// Write a size value
 bool sysSettings::Write(const wxString &key, const wxSize &value)
 {
     bool rc=wxConfig::Write(key + wxT("/Width"), value.x);
@@ -517,20 +631,6 @@ bool sysSettings::Write(const wxString &key, const wxSize &value)
     return rc;
 }
 
-
-wxPoint sysSettings::Read(const wxString& key, const wxPoint &defaultVal) const
-{
-    return wxPoint(wxConfig::Read(key + wxT("/Left"), defaultVal.x), 
-                   wxConfig::Read(key + wxT("/Top"), defaultVal.y));
-}
-
-
-wxSize sysSettings::Read(const wxString& key, const wxSize &defaultVal) const
-{
-    return wxSize(wxConfig::Read(key + wxT("/Width"), defaultVal.x), 
-                  wxConfig::Read(key + wxT("/Height"), defaultVal.y));
-}
-
 //////////////////////////////////////////////////////////////////////////
 // Tip of the Day
 //////////////////////////////////////////////////////////////////////////