Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13704/include
Modified Files:
MFolder.h Profile.h
Log Message:
removed ConfigSource parameter from Profile::writeEntty(); added Profile:: and
MFolder::SetConfigSourceForWriting()
Index: MFolder.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/MFolder.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -b -u -2 -r1.60 -r1.61
--- MFolder.h 18 Sep 2003 16:30:40 -0000 1.60
+++ MFolder.h 7 Jul 2005 18:48:43 -0000 1.61
@@ -195,4 +195,16 @@
virtual void SetTreeIndex(int /* pos */) { }
+ //@}
+
+ /** @name Profile stuff */
+ //@{
+
+ /**
+ Set the config source to use for saving changes.
+
+ @sa Profile::SetConfigSourceForWriting().
+ */
+ virtual void SetConfigSourceForWriting(ConfigSource *config) = 0;
+
/**
Get the profile associated with this folder: it will never be NULL (as
Index: Profile.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/Profile.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -b -u -2 -r1.84 -r1.85
--- Profile.h 7 Oct 2003 22:49:40 -0000 1.84
+++ Profile.h 7 Jul 2005 18:48:43 -0000 1.85
@@ -181,12 +181,8 @@
/// Write back the character value.
- virtual bool writeEntry(const String& key,
- const String& value,
- ConfigSource *config = NULL) = 0;
+ virtual bool writeEntry(const String& key, const String& value) = 0;
/// Write back the int value.
- virtual bool writeEntry(const String& key,
- long value,
- ConfigSource *config = NULL) = 0;
+ virtual bool writeEntry(const String& key, long value) = 0;
/**
@@ -199,11 +195,33 @@
@param key the key to modify
@param value the new value
- @param defvalue the default value for this key
+ @param def the default value for this key
@return true if ok, false if an error occured
*/
- virtual bool writeEntryIfNeeded(const String& key,
- long value,
- long defvalue,
- ConfigSource *config = NULL) = 0;
+ virtual bool writeEntryIfNeeded(const String& key, long value, long def) =0;
+
+ /**
+ Change the config source used for saving the changes.
+
+ Normally all keys written by writeEntry() are saved to the default
+ (global) config. This method allows to change it and save them to some
+ other config instead.
+
+ This function is dangerous because it modifies not just this Profile but
+ also of all the other pointers to the same object because of ref-counted
+ sharing Profiles use. However it's the only way we have to save changes
+ to non default config source and we do need this for options dialogs.
+ Do use ProfileConfigSourceChange helper class to ensure that the old
+ config source is restored after finishing with writing changes to
+ user-specified source.
+
+ @param config source to use for saving changes from now on
+ @return config source used previously (may be NULL, must not be deleted)
+ */
+ ConfigSource *SetConfigSourceForWriting(ConfigSource *config)
+ {
+ ConfigSource *configOld = m_configForWriting;
+ m_configForWriting = config;
+ return configOld;
+ }
//@}
@@ -329,5 +347,5 @@
virtual bool IsAncestor(Profile *profile) const = 0;
- /// get the name of the folder his profile is for or an empty string
+ /// get the name of the folder this profile is for or an empty string
virtual String GetFolderName() const = 0;
@@ -363,6 +381,6 @@
protected:
- // egcs wants this
- Profile() { }
+ /// ctor is protected, we're only created with CreateXXX() static methods
+ Profile() { m_configForWriting = NULL; m_expandEnvVars = false; }
/// provide access to ProfileEnumDataImpl for the derived classes
@@ -373,8 +391,14 @@
String ExpandEnvVarsIfNeeded(const String& val) const;
+ /// get config source for saving changes
+ ConfigSource *GetConfigSourceForWriting() const { return
m_configForWriting; }
+
private:
/// helper for GetAllIdentities/GetAllFilters
static wxArrayString GetAllGroupsUnder(const String& path);
+ /// the config source for saving changes
+ ConfigSource *m_configForWriting;
+
/// should we expand the environment variables in string values?
bool m_expandEnvVars;
@@ -446,4 +470,35 @@
// ----------------------------------------------------------------------------
+// ProfileConfigSourceChange: another helper which ensures that config source
+// is not only set but unset as well
+// ----------------------------------------------------------------------------
+
+class ProfileConfigSourceChange
+{
+public:
+ /**
+ Changes the config source to the specified one if it is not NULL.
+ */
+ ProfileConfigSourceChange(Profile *profile, ConfigSource *config)
+ : m_profile(profile)
+ {
+ m_changed = config != NULL;
+ if ( m_changed )
+ m_config = profile->SetConfigSourceForWriting(config);
+ }
+
+ ~ProfileConfigSourceChange()
+ {
+ if ( m_changed )
+ m_profile->SetConfigSourceForWriting(m_config);
+ }
+
+private:
+ Profile *m_profile;
+ ConfigSource *m_config;
+ bool m_changed;
+};
+
+// ----------------------------------------------------------------------------
// helper functions
// ----------------------------------------------------------------------------
-------------------------------------------------------
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