36 #include "headerstrategy.h"
41 #include <tdeconfig.h>
49 static const char * briefHeaders[] = {
50 "subject",
"from",
"cc",
"bcc",
"date"
52 static const int numBriefHeaders =
sizeof briefHeaders /
sizeof *briefHeaders;
55 static const char * standardHeaders[] = {
56 "subject",
"from",
"cc",
"bcc",
"to"
58 static const int numStandardHeaders =
sizeof standardHeaders /
sizeof *standardHeaders;
61 static const char * richHeaders[] = {
62 "subject",
"date",
"from",
"cc",
"bcc",
"to",
63 "organization",
"organisation",
"reply-to",
64 "user-agent",
"x-mailer"
66 static const int numRichHeaders =
sizeof richHeaders /
sizeof *richHeaders;
72 static TQStringList stringList(
const char * headers[],
int numHeaders ) {
74 for (
int i = 0 ; i < numHeaders ; ++i )
75 sl.push_back( headers[i] );
84 class AllHeaderStrategy :
public HeaderStrategy {
85 friend class ::KMail::HeaderStrategy;
87 AllHeaderStrategy() : HeaderStrategy() {}
88 virtual ~AllHeaderStrategy() {}
91 const char * name()
const {
return "all"; }
92 const HeaderStrategy * next()
const {
return rich(); }
93 const HeaderStrategy * prev()
const {
return custom(); }
95 DefaultPolicy defaultPolicy()
const {
return Display; }
97 bool showHeader(
const TQString & )
const {
107 class RichHeaderStrategy :
public HeaderStrategy {
108 friend class ::KMail::HeaderStrategy;
112 mHeadersToDisplay( stringList( richHeaders, numRichHeaders ) ) {}
113 virtual ~RichHeaderStrategy() {}
116 const char * name()
const {
return "rich"; }
117 const HeaderStrategy * next()
const {
return standard(); }
118 const HeaderStrategy * prev()
const {
return all(); }
120 TQStringList headersToDisplay()
const {
return mHeadersToDisplay; }
121 DefaultPolicy defaultPolicy()
const {
return Hide; }
124 const TQStringList mHeadersToDisplay;
132 class StandardHeaderStrategy :
public HeaderStrategy {
133 friend class ::KMail::HeaderStrategy;
135 StandardHeaderStrategy()
137 mHeadersToDisplay( stringList( standardHeaders, numStandardHeaders) ) {}
138 virtual ~StandardHeaderStrategy() {}
141 const char * name()
const {
return "standard"; }
142 const HeaderStrategy * next()
const {
return brief(); }
143 const HeaderStrategy * prev()
const {
return rich(); }
145 TQStringList headersToDisplay()
const {
return mHeadersToDisplay; }
146 DefaultPolicy defaultPolicy()
const {
return Hide; }
149 const TQStringList mHeadersToDisplay;
157 class BriefHeaderStrategy :
public HeaderStrategy {
158 friend class ::KMail::HeaderStrategy;
160 BriefHeaderStrategy()
162 mHeadersToDisplay( stringList( briefHeaders, numBriefHeaders ) ) {}
163 virtual ~BriefHeaderStrategy() {}
166 const char * name()
const {
return "brief"; }
167 const HeaderStrategy * next()
const {
return custom(); }
168 const HeaderStrategy * prev()
const {
return standard(); }
170 TQStringList headersToDisplay()
const {
return mHeadersToDisplay; }
171 DefaultPolicy defaultPolicy()
const {
return Hide; }
174 const TQStringList mHeadersToDisplay;
183 class CustomHeaderStrategy :
public HeaderStrategy {
184 friend class ::KMail::HeaderStrategy;
186 CustomHeaderStrategy();
187 virtual ~CustomHeaderStrategy() {}
190 const char * name()
const {
return "custom"; }
191 const HeaderStrategy * next()
const {
return all(); }
192 const HeaderStrategy * prev()
const {
return brief(); }
194 TQStringList headersToDisplay()
const {
return mHeadersToDisplay; }
195 TQStringList headersToHide()
const {
return mHeadersToHide; }
196 DefaultPolicy defaultPolicy()
const {
return mDefaultPolicy; }
199 TQStringList mHeadersToDisplay;
200 TQStringList mHeadersToHide;
201 DefaultPolicy mDefaultPolicy;
205 CustomHeaderStrategy::CustomHeaderStrategy()
208 TDEConfigGroup customHeader( KMKernel::config(),
"Custom Headers" );
209 if ( customHeader.hasKey(
"headers to display" ) ) {
210 mHeadersToDisplay = customHeader.readListEntry(
"headers to display" );
211 for ( TQStringList::iterator it = mHeadersToDisplay.begin() ; it != mHeadersToDisplay.end() ; ++ it )
214 mHeadersToDisplay = stringList( standardHeaders, numStandardHeaders );
216 if ( customHeader.hasKey(
"headers to hide" ) ) {
217 mHeadersToHide = customHeader.readListEntry(
"headers to hide" );
218 for ( TQStringList::iterator it = mHeadersToHide.begin() ; it != mHeadersToHide.end() ; ++ it )
222 mDefaultPolicy = customHeader.readEntry(
"default policy",
"hide" ) ==
"display" ? Display : Hide ;
229 HeaderStrategy::HeaderStrategy() {
233 HeaderStrategy::~HeaderStrategy() {
237 TQStringList HeaderStrategy::headersToDisplay()
const {
238 return TQStringList();
241 TQStringList HeaderStrategy::headersToHide()
const {
242 return TQStringList();
245 bool HeaderStrategy::showHeader(
const TQString & header )
const {
246 if ( headersToDisplay().contains( header.lower() ) )
return true;
247 if ( headersToHide().contains( header.lower() ) )
return false;
248 return defaultPolicy() == Display;
251 const HeaderStrategy * HeaderStrategy::create( Type type ) {
253 case All:
return all();
254 case Rich:
return rich();
255 case Standard:
return standard();
256 case Brief:
return brief();
257 case Custom:
return custom();
259 kdFatal( 5006 ) <<
"HeaderStrategy::create(): Unknown header strategy ( type == "
260 << (int)type <<
" ) requested!" << endl;
264 const HeaderStrategy * HeaderStrategy::create(
const TQString & type ) {
265 TQString lowerType = type.lower();
266 if ( lowerType ==
"all" )
return all();
267 if ( lowerType ==
"rich" )
return HeaderStrategy::rich();
269 if ( lowerType ==
"brief" )
return brief();
270 if ( lowerType ==
"custom" )
return custom();
276 static const HeaderStrategy * allStrategy = 0;
277 static const HeaderStrategy * richStrategy = 0;
278 static const HeaderStrategy * standardStrategy = 0;
279 static const HeaderStrategy * briefStrategy = 0;
280 static const HeaderStrategy * customStrategy = 0;
282 const HeaderStrategy * HeaderStrategy::all() {
284 allStrategy =
new AllHeaderStrategy();
288 const HeaderStrategy * HeaderStrategy::rich() {
290 richStrategy =
new RichHeaderStrategy();
294 const HeaderStrategy * HeaderStrategy::standard() {
295 if ( !standardStrategy )
296 standardStrategy =
new StandardHeaderStrategy();
297 return standardStrategy;
300 const HeaderStrategy * HeaderStrategy::brief() {
301 if ( !briefStrategy )
302 briefStrategy =
new BriefHeaderStrategy();
303 return briefStrategy;
306 const HeaderStrategy * HeaderStrategy::custom() {
307 if ( !customStrategy )
308 customStrategy =
new CustomHeaderStrategy();
309 return customStrategy;