Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1214/src/gui
Modified Files:
wxSpamOptions.cpp
Log Message:
reorganized code to allow adding extra entries for spam options
Index: wxSpamOptions.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxSpamOptions.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -u -2 -r1.14 -r1.15
--- wxSpamOptions.cpp 15 May 2004 16:42:11 -0000 1.14
+++ wxSpamOptions.cpp 15 May 2004 22:59:21 -0000 1.15
@@ -91,12 +91,43 @@
}
+BOUND_ARRAY(ConfigValueNone,ConfigValueArray);
+BOUND_ARRAY(wxOptionsPage::FieldInfo,FieldInfoArray);
+
+
+/*
+ Represents a single spam option.
+
+ This is an ABC, derived classes below are for the concrete options.
+ */
class SpamOption
{
public:
+ /// Is it on or off by default?
virtual bool DefaultValue() const = 0;
+
+ /// The token used in spam filter string for this option
virtual const wxChar *Token() const = 0;
- virtual const wxChar *ProfileHackName() const = 0;
- virtual const wxChar *Title() const = 0;
+ /// The name of the profile entry used to pass the value to config dialog
+ virtual const wxChar *TempProfileEntryName() const = 0;
+
+ /// The label of the correponding checkbox in the dialog
+ virtual const wxChar *DialogLabel() const = 0;
+
+ /// The number of entries created by BuildFields()
+ virtual size_t GetEntriesCount() const { return 1; }
+
+ /// Initialize the entries needed by this option in fieldInfo
+ virtual size_t BuildFieldInfo(FieldInfoArray& fields, size_t n) const
+ {
+ wxOptionsPage::FieldInfo& info = fields[n];
+ info.label = DialogLabel();
+ info.flags = wxOptionsPage::Field_Bool;
+ info.enable = -1;
+
+ return 1;
+ }
+
+ /// Is it currently active/checked?
bool m_active;
};
@@ -109,7 +140,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_SPAMASSASSIN; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamAssassin"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Been tagged as spam by Spam&Assassin"); }
};
@@ -122,7 +153,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_SUBJ8BIT; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("Spam8BitSubject"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Too many &8 bit characters in subject"); }
};
@@ -135,7 +166,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_SUBJCAPS; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamCapsSubject"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Only &capitals in subject"); }
};
@@ -148,7 +179,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_SUBJENDJUNK; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("JunkEndSubject"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("&Junk at end of subject"); }
};
@@ -161,7 +192,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_KOREAN; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamKoreanCharset"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("&Korean charset"); }
};
@@ -172,7 +203,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_EXECUTABLE_ATTACHMENT; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamExeAttachment"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("E&xecutable attachment"); }
};
@@ -184,7 +215,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_XAUTHWARN; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamXAuthWarning"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("X-Authentication-&Warning header"); }
};
@@ -197,7 +228,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_RECEIVED; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamReceived"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Suspicious \"&Received\" headers"); }
};
@@ -210,7 +241,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_HTML; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamHtml"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Only &HTML content"); }
};
@@ -223,7 +254,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_MIME; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamMime"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Unusual &MIME structure"); }
};
@@ -236,7 +267,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_WHITE_LIST; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpameWhiteList"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("No match in &whitelist"); }
};
@@ -251,7 +282,7 @@
virtual const wxChar *Token() const
{ return SPAM_TEST_RBL; }
- virtual const wxChar *ProfileHackName() const
+ virtual const wxChar *TempProfileEntryName() const
{ return _T("SpamIsInRBL"); }
- virtual const wxChar *Title() const
+ virtual const wxChar *DialogLabel() const
{ return gettext_noop("Been &blacklisted by RBL"); }
};
@@ -281,9 +312,7 @@
void DeleteProfile(Profile *profile);
- size_t ConfigEntryCount() const { return ms_count+1; }
+ size_t GetConfigEntryCount();
- BOUND_ARRAY(ConfigValueNone,ConfigValueArray);
ConfigValueArray m_configValues;
- BOUND_ARRAY(wxOptionsPage::FieldInfo,FieldInfoArray);
FieldInfoArray m_fieldInfo;
@@ -326,4 +355,9 @@
#endif // USE_RBL
+ // the number of entries in controls/config arrats we need, initially 0 but
+ // computed by GetConfigEntryCount() when it is called for the first time
+ size_t m_nEntries;
+
+
typedef SpamOption *(SpamOptionManagerBody::*PickMember)();
static const PickMember ms_members[];
@@ -374,13 +408,33 @@
-IMPLEMENT_BOUND_ARRAY(SpamOptionManagerBody::ConfigValueArray)
-IMPLEMENT_BOUND_ARRAY(SpamOptionManagerBody::FieldInfoArray)
+IMPLEMENT_BOUND_ARRAY(ConfigValueArray)
+IMPLEMENT_BOUND_ARRAY(FieldInfoArray)
SpamOptionManagerBody::SpamOptionManagerBody()
{
+ m_nEntries = 0;
+
BuildConfigValues();
BuildFieldInfo();
}
+size_t SpamOptionManagerBody::GetConfigEntryCount()
+{
+ if ( !m_nEntries )
+ {
+ // sum up the entries of all option
+ for ( SpamOptionManagerBody::Iterator
+ option(this); !option.IsEnd(); ++option )
+ {
+ m_nEntries += option->GetEntriesCount();
+ }
+
+ // for the explanation text in the beginning
+ m_nEntries++;
+ }
+
+ return m_nEntries;
+}
+
void SpamOptionManagerBody::SetDefaults()
{
@@ -461,5 +515,5 @@
!option.IsEnd(); ++option )
{
- profile->writeEntry(option->ProfileHackName(), option->m_active);
+ profile->writeEntry(option->TempProfileEntryName(), option->m_active);
}
}
@@ -471,5 +525,5 @@
{
option->m_active = profile->readEntry(
- option->ProfileHackName(), 0l) != 0l;
+ option->TempProfileEntryName(), 0l) != 0l;
}
}
@@ -480,5 +534,5 @@
!option.IsEnd(); ++option )
{
- profile->DeleteEntry(option->ProfileHackName());
+ profile->DeleteEntry(option->TempProfileEntryName());
}
}
@@ -486,12 +540,17 @@
void SpamOptionManagerBody::BuildConfigValues()
{
- m_configValues.Initialize(ConfigEntryCount());
+ m_configValues.Initialize(GetConfigEntryCount());
+ size_t n = 1;
for ( SpamOptionManagerBody::Iterator option(this);
!option.IsEnd(); ++option )
{
- ConfigValueDefault &value = m_configValues[option.Index()+1];
- value = ConfigValueDefault(
- option->ProfileHackName(),option->DefaultValue());
+ ConfigValueDefault& value = m_configValues[n];
+ value = ConfigValueDefault
+ (
+ option->TempProfileEntryName(),
+ option->DefaultValue()
+ );
+ n += option->GetEntriesCount();
}
}
@@ -499,5 +558,5 @@
void SpamOptionManagerBody::BuildFieldInfo()
{
- m_fieldInfo.Initialize(ConfigEntryCount());
+ m_fieldInfo.Initialize(GetConfigEntryCount());
m_fieldInfo[0].label
@@ -510,11 +569,9 @@
m_fieldInfo[0].enable = -1;
+ size_t n = 1;
for ( SpamOptionManagerBody::Iterator option(this);
!option.IsEnd(); ++option )
{
- wxOptionsPage::FieldInfo &info = m_fieldInfo[option.Index()+1];
- info.label = option->Title();
- info.flags = wxOptionsPage::Field_Bool;
- info.enable = -1;
+ n += option->BuildFieldInfo(m_fieldInfo, n);
}
}
@@ -540,5 +597,5 @@
m_fieldInfo.Get(),
m_configValues.Get(),
- ConfigEntryCount()
+ GetConfigEntryCount()
);
-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates