Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14952/src/classes
Modified Files:
ConfigSourcesAll.cpp
Log Message:
added SetSources()
Index: ConfigSourcesAll.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ConfigSourcesAll.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -u -2 -r1.2 -r1.3
--- ConfigSourcesAll.cpp 5 Jul 2005 12:34:35 -0000 1.2
+++ ConfigSourcesAll.cpp 5 Jul 2005 15:30:29 -0000 1.3
@@ -35,4 +35,5 @@
extern const MOption MP_CONFIG_SOURCE_PRIO;
+extern const MOption MP_CONFIG_SOURCE_TYPE;
// ----------------------------------------------------------------------------
@@ -351,5 +352,6 @@
ConfigSource::EnumData cookie;
const String key(M_CONFIGSRC_CONFIG_SECTION),
- valuePrio(_T('/') + GetOptionName(MP_CONFIG_SOURCE_PRIO));
+ slash(_T('/')),
+ valuePrio(slash + GetOptionName(MP_CONFIG_SOURCE_PRIO));
String name;
@@ -358,5 +360,5 @@
cont = configLocal->GetNextGroup(name, cookie) )
{
- const String subkey = key + _T('/') + name;
+ const String subkey = key + slash + name;
ConfigSource *config = ConfigSource::Create(*configLocal, subkey);
@@ -698,3 +700,62 @@
}
+// ----------------------------------------------------------------------------
+// changing configuration sources
+// ----------------------------------------------------------------------------
+
+bool
+AllConfigSources::SetSources(const wxArrayString& names,
+ const wxArrayString& types,
+ const wxArrayString& specs)
+{
+ const size_t count = names.size();
+ CHECK( types.size() == count && specs.size() == count, false,
+ _T("array size mismatch") );
+
+ ConfigSource& config = **m_sources.begin();
+
+ // we need just the name for RenameGroup()
+ String configsBackup(_T("Configs.Old"));
+ config.RenameGroup(M_CONFIGSRC_CONFIG_SECTION, configsBackup);
+
+ // but make full path now
+ const String slash(_T('/'));
+ configsBackup = String(M_CONFIGSRC_CONFIG_SECTION).BeforeLast(_T('/'))
+ + slash + configsBackup;
+ const String pathType = slash + GetOptionName(MP_CONFIG_SOURCE_TYPE);
+ const String pathPrio = slash + GetOptionName(MP_CONFIG_SOURCE_PRIO);
+
+ // auto assign the priorities to ensure that the sources are in order but
+ // leave gaps between them to also allow for manual editing
+ int prio = 10;
+ for ( size_t n = 0; n < count; n++, prio += 10 )
+ {
+ String path;
+ path << M_CONFIGSRC_CONFIG_SECTION << slash << names[n];
+
+ const String type = types[n];
+ ConfigSourceFactory_obj factory(ConfigSourceFactory::Find(type));
+
+ if ( !factory ||
+ !factory->Save(config, path, specs[n]) ||
+ !config.Write(path + pathType, type) ||
+ !config.Write(path + pathPrio, prio) )
+ {
+ if ( !factory )
+ {
+ wxLogError(_("Unknown configuration source type \"%s\"."),
+ type.c_str());
+ }
+
+ // restore old config sources
+ config.DeleteGroup(M_CONFIGSRC_CONFIG_SECTION);
+ config.RenameGroup(configsBackup,
+
String(M_CONFIGSRC_CONFIG_SECTION).AfterLast(_T('/')));
+ return false;
+ }
+ }
+
+ config.DeleteGroup(configsBackup);
+ return true;
+}
-------------------------------------------------------
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