Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21481/src/classes

Modified Files:
        MessageTemplate.cpp 
Log Message:
use Profile instead of using wxConfig directly as the latter doesn't work with 
multiple config sources

Index: MessageTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageTemplate.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -b -u -2 -r1.35 -r1.36
--- MessageTemplate.cpp 23 Oct 2004 23:29:59 -0000      1.35
+++ MessageTemplate.cpp 20 Jul 2005 17:26:29 -0000      1.36
@@ -25,9 +25,7 @@
 #   include "Mcommon.h"
 #   include "Profile.h"
-#   include "MApplication.h"
 
 #   include <wx/string.h>       // for wxString
 #   include <wx/log.h>          // for wxLogWarning
-#   include <wx/config.h>
 #endif // USE_PCH
 
@@ -579,21 +577,10 @@
 }
 
-// returns the path to the section containing the templates of the given kind
-static String GetTemplateKindSection(MessageTemplateKind kind)
-{
-   String path;
-   path << Profile::GetTemplatesPath() << '/' << GetTemplateKindPath(kind);
-
-   return path;
-}
-
-// returns the path to the value of the template of the given kind and name in
-// the profile
-static String GetTemplateValuePath(MessageTemplateKind kind, const String& 
name)
+// returns the profile for the templates of given kind
+//
+// the pointer must be DecRef()'d by caller if not NULL
+static Profile *GetTemplateProfile(MessageTemplateKind kind)
 {
-   String path;
-   path << GetTemplateKindSection(kind) << '/' << name;
-
-   return path;
+   return Profile::CreateTemplateProfile(GetTemplateKindPath(kind));
 }
 
@@ -609,5 +596,6 @@
 {
    // first read the template name
-   String name = profile->readEntry(GetTemplateNamePath(kind), 
STANDARD_TEMPLATE_NAME);
+   String name = profile->readEntry(GetTemplateNamePath(kind),
+                                    STANDARD_TEMPLATE_NAME);
 
    return GetMessageTemplate(kind, name);
@@ -618,11 +606,17 @@
 GetMessageTemplate(MessageTemplateKind kind, const String& name)
 {
+   String value;
+
+   Profile *profile(GetTemplateProfile(kind));
+   if ( profile )
+   {
    // the templates contain '$'s so disable variable expansion for now
-   Profile *profile = mApplication->GetProfile();
    ProfileEnvVarSave noEnvVarExpansion(profile);
 
-   wxConfigBase *config = profile->GetConfig();
+      value = profile->readEntry(name);
+
+      profile->DecRef();
+   }
 
-   String value = config->Read(GetTemplateValuePath(kind, name), _T(""));
    if ( value.empty() )
    {
@@ -679,6 +673,9 @@
    }
 
-   wxConfigBase *config = mApplication->GetProfile()->GetConfig();
-   config->Write(GetTemplateValuePath(kind, name), value);
+   Profile_obj profileTemplate(GetTemplateProfile(kind));
+   if ( profileTemplate )
+   {
+      profileTemplate->writeEntry(name, value);
+   }
 }
 
@@ -686,6 +683,8 @@
 DeleteMessageTemplate(MessageTemplateKind kind, const String& name)
 {
-   wxConfigBase *config = mApplication->GetProfile()->GetConfig();
-   config->DeleteEntry(GetTemplateValuePath(kind, name));
+   // TODO: check that no profile uses it?
+   Profile_obj profileTemplate(GetTemplateProfile(kind));
+   if ( profileTemplate )
+      profileTemplate->DeleteEntry(name);
 
    return true;
@@ -700,11 +699,9 @@
    names.Add(STANDARD_TEMPLATE_NAME);
 
-   wxConfigBase *config = mApplication->GetProfile()->GetConfig();
-
-   config->SetPath(GetTemplateKindSection(kind));
+   Profile_obj profileTemplate(GetTemplateProfile(kind));
 
    wxString name;
-   long cookie;
-   bool cont = config->GetFirstEntry(name, cookie);
+   Profile::EnumData cookie;
+   bool cont = profileTemplate->GetFirstEntry(name, cookie);
    while ( cont )
    {
@@ -715,5 +712,5 @@
       }
 
-      cont = config->GetNextEntry(name, cookie);
+      cont = profileTemplate->GetNextEntry(name, cookie);
    }
 



-------------------------------------------------------
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

Reply via email to