Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29047/src/classes
Modified Files:
ConfigSource.cpp MApplication.cpp
Log Message:
extracted ConfigSourceLocal into its own header as well; added
ConfigSource::GetType() and GetSpec() and ConfigSourceFactory::Save()
Index: ConfigSource.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ConfigSource.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -b -u -2 -r1.16 -r1.17
--- ConfigSource.cpp 4 Jul 2005 20:58:27 -0000 1.16
+++ ConfigSource.cpp 5 Jul 2005 12:34:13 -0000 1.17
@@ -52,15 +52,9 @@
#include "ConfigSource.h"
+#include "ConfigSourceLocal.h"
class MOption;
// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// the type of the local config source
-#define CONFIG_SOURCE_TYPE_LOCAL _T("local")
-
-// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
@@ -69,6 +63,15 @@
{
public:
- virtual const wxChar *GetType() const { return CONFIG_SOURCE_TYPE_LOCAL; }
+ // the type of the local config source
+ static const wxChar *Type() { return gettext_noop("file"); }
+
+ virtual const wxChar *GetType() const { return Type(); }
virtual ConfigSource *Create(const ConfigSource& config, const String&
name);
+ virtual bool
+ Save(ConfigSource& config, const String& name, const String& spec);
+
+private:
+ // the path used for storing the file name in config
+ static const wxChar *FileNamePath() { return _T("/FileName"); }
};
@@ -316,17 +319,13 @@
// ----------------------------------------------------------------------------
-ConfigSourceLocal::ConfigSourceLocal(wxConfigBase *config, const String& name)
- : ConfigSource(name)
+ConfigSourceLocal::ConfigSourceLocal(const String& name)
+ : ConfigSource(name, ConfigSourceLocalFactory::Type())
{
- ASSERT_MSG( config, _T("NULL config in ConfigSourceLocal?") );
-
- m_config = config;
+ m_config = NULL;
}
-
-/* static */
-wxConfigBase *ConfigSourceLocal::CreateDefaultConfig(const String& filename)
+bool ConfigSourceLocal::InitDefault(const String& filename)
{
- wxConfigBase *config = NULL;
+ bool rc = false;
String localFilePath = filename,
@@ -496,37 +495,40 @@
if ( localFilePath.empty() )
{
- config = CreateRegConfig();
+ rc = InitRegistry();
// one extra complication: the user wants to always want to use config
// file instead of the registry, this is indicated by the presence of
+ if ( rc )
+ {
String key(M_PROFILE_CONFIG_SECTION);
key << _T('/') << GetOptionName(MP_USE_CONFIG_FILE);
- if ( config->Read(key, &localFilePath) )
+ if ( m_config->Read(key, &localFilePath) )
{
// we want to use wxFileConfig finally...
- delete config;
- config = NULL; // not needed now, but safer if code is changed later
+ delete m_config;
+ m_config = NULL; // not really needed now, but safer
+ rc = false;
}
//else: do use wxRegConfig created above
}
+ }
#else // !Windows, !Unix
#error "Don't know default config file location for this platform"
#endif // OS
- if ( !config )
+ if ( !rc )
{
- config = CreateFileConfig(localFilePath, globalFilePath);
+ rc = InitFile(localFilePath, globalFilePath);
}
- return config;
+ return rc;
}
-/* static */
-wxConfigBase *
-ConfigSourceLocal::CreateFileConfig(const String& localFilePath,
+bool
+ConfigSourceLocal::InitFile(const String& localFilePath,
const String& globalFilePath)
{
ASSERT_MSG( !localFilePath.empty(),
- _T("invalid file path in CreateFileConfig") );
+ _T("invalid local config file path") );
wxFileConfig *fileconf = new wxFileConfig
@@ -549,5 +551,7 @@
fileconf->SetExpandEnvVars(false);
- return fileconf;
+ DoInit(fileconf, localFilePath);
+
+ return true;
}
@@ -555,7 +559,5 @@
#ifdef OS_WIN
-/* static */
-wxConfigBase *
-ConfigSourceLocal::CreateRegConfig()
+bool ConfigSourceLocal::InitRegistry()
{
// don't give explicit name, but rather use the default logic (it's
@@ -574,5 +576,7 @@
regconf->SetExpandEnvVars(false);
- return regconf;
+ DoInit(regconf);
+
+ return true;
}
@@ -582,7 +586,5 @@
{
if ( this == gs_configSourceGlobal )
- {
gs_configSourceGlobal = NULL;
- }
delete m_config;
@@ -593,4 +595,9 @@
// ----------------------------------------------------------------------------
+String ConfigSourceLocal::GetSpec() const
+{
+ return m_path;
+}
+
bool ConfigSourceLocal::IsOk() const
{
@@ -753,5 +760,5 @@
{
String filename;
- if ( !config.Read(name + _T("/FileName"), &filename) )
+ if ( !config.Read(name + FileNamePath(), &filename) )
{
wxLogError(_("No filename for local config source \"%s\"."),
@@ -770,2 +777,12 @@
}
+bool
+ConfigSourceLocalFactory::Save(ConfigSource& config,
+ const String& name,
+ const String& spec)
+{
+ // TODO: check file name validity?
+
+ return config.Write(name + FileNamePath(), spec);
+}
+
Index: MApplication.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MApplication.cpp,v
retrieving revision 1.300
retrieving revision 1.301
diff -b -u -2 -r1.300 -r1.301
--- MApplication.cpp 4 Jul 2005 19:52:26 -0000 1.300
+++ MApplication.cpp 5 Jul 2005 12:34:13 -0000 1.301
@@ -44,5 +44,5 @@
#include "Composer.h" // for RestoreAll()
#include "SendMessage.h"
-#include "ConfigSource.h"
+#include "ConfigSourceLocal.h"
#include "MAtExit.h"
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates