headerstrategy.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035
00036 #include "headerstrategy.h"
00037
00038 #include "kmkernel.h"
00039
00040 #include <kdebug.h>
00041 #include <kconfig.h>
00042
00043 namespace KMail {
00044
00045
00046
00047
00048
00049 static const char * briefHeaders[] = {
00050 "subject", "from", "cc", "bcc", "date"
00051 };
00052 static const int numBriefHeaders = sizeof briefHeaders / sizeof *briefHeaders;
00053
00054
00055 static const char * standardHeaders[] = {
00056 "subject", "from", "cc", "bcc", "to"
00057 };
00058 static const int numStandardHeaders = sizeof standardHeaders / sizeof *standardHeaders;
00059
00060
00061 static const char * richHeaders[] = {
00062 "subject", "date", "from", "cc", "bcc", "to",
00063 "organization", "organisation", "reply-to", "status"
00064 };
00065 static const int numRichHeaders = sizeof richHeaders / sizeof *richHeaders;
00066
00067
00068 static const char * minimalHeaders[] = {
00069 "subject", "date", "from", "to"
00070 };
00071 static const int numMinimalHeaders = sizeof minimalHeaders / sizeof *minimalHeaders;
00072
00073
00074
00075
00076
00077 static QStringList stringList( const char * headers[], int numHeaders ) {
00078 QStringList sl;
00079 for ( int i = 0 ; i < numHeaders ; ++i )
00080 sl.push_back( headers[i] );
00081 return sl;
00082 }
00083
00084
00085
00086
00087
00088
00089 class AllHeaderStrategy : public HeaderStrategy {
00090 friend class HeaderStrategy;
00091 protected:
00092 AllHeaderStrategy() : HeaderStrategy() {}
00093 virtual ~AllHeaderStrategy() {}
00094
00095 public:
00096 const char * name() const { return "all"; }
00097 const HeaderStrategy * next() const { return rich(); }
00098 const HeaderStrategy * prev() const { return minimal(); }
00099
00100 DefaultPolicy defaultPolicy() const { return Display; }
00101
00102 bool showHeader( const QString & ) const {
00103 return true;
00104 }
00105 };
00106
00107
00108
00109
00110
00111
00112 class RichHeaderStrategy : public HeaderStrategy {
00113 friend class HeaderStrategy;
00114 protected:
00115 RichHeaderStrategy()
00116 : HeaderStrategy(),
00117 mHeadersToDisplay( stringList( richHeaders, numRichHeaders ) ) {}
00118 virtual ~RichHeaderStrategy() {}
00119
00120 public:
00121 const char * name() const { return "rich"; }
00122 const HeaderStrategy * next() const { return standard(); }
00123 const HeaderStrategy * prev() const { return all(); }
00124
00125 QStringList headersToDisplay() const { return mHeadersToDisplay; }
00126 DefaultPolicy defaultPolicy() const { return Hide; }
00127
00128 private:
00129 const QStringList mHeadersToDisplay;
00130 };
00131
00132
00133
00134
00135
00136
00137 class StandardHeaderStrategy : public HeaderStrategy {
00138 friend class HeaderStrategy;
00139 protected:
00140 StandardHeaderStrategy()
00141 : HeaderStrategy(),
00142 mHeadersToDisplay( stringList( standardHeaders, numStandardHeaders) ) {}
00143 virtual ~StandardHeaderStrategy() {}
00144
00145 public:
00146 const char * name() const { return "standard"; }
00147 const HeaderStrategy * next() const { return brief(); }
00148 const HeaderStrategy * prev() const { return rich(); }
00149
00150 QStringList headersToDisplay() const { return mHeadersToDisplay; }
00151 DefaultPolicy defaultPolicy() const { return Hide; }
00152
00153 private:
00154 const QStringList mHeadersToDisplay;
00155 };
00156
00157
00158
00159
00160
00161
00162 class BriefHeaderStrategy : public HeaderStrategy {
00163 friend class HeaderStrategy;
00164 protected:
00165 BriefHeaderStrategy()
00166 : HeaderStrategy(),
00167 mHeadersToDisplay( stringList( briefHeaders, numBriefHeaders ) ) {}
00168 virtual ~BriefHeaderStrategy() {}
00169
00170 public:
00171 const char * name() const { return "brief"; }
00172 const HeaderStrategy * next() const { return custom(); }
00173 const HeaderStrategy * prev() const { return standard(); }
00174
00175 QStringList headersToDisplay() const { return mHeadersToDisplay; }
00176 DefaultPolicy defaultPolicy() const { return Hide; }
00177
00178 private:
00179 const QStringList mHeadersToDisplay;
00180 };
00181
00182
00183
00184
00185
00186
00187
00188 class CustomHeaderStrategy : public HeaderStrategy {
00189 friend class HeaderStrategy;
00190 protected:
00191 CustomHeaderStrategy();
00192 virtual ~CustomHeaderStrategy() {}
00193
00194 public:
00195 const char * name() const { return "custom"; }
00196 const HeaderStrategy * next() const { return minimal(); }
00197 const HeaderStrategy * prev() const { return brief(); }
00198
00199 QStringList headersToDisplay() const { return mHeadersToDisplay; }
00200 QStringList headersToHide() const { return mHeadersToHide; }
00201 DefaultPolicy defaultPolicy() const { return mDefaultPolicy; }
00202
00203 private:
00204 QStringList mHeadersToDisplay;
00205 QStringList mHeadersToHide;
00206 DefaultPolicy mDefaultPolicy;
00207 };
00208
00209
00210 CustomHeaderStrategy::CustomHeaderStrategy()
00211 : HeaderStrategy()
00212 {
00213 KConfigGroup customHeader( KMKernel::config(), "Custom Headers" );
00214 if ( customHeader.hasKey( "headers to display" ) ) {
00215 mHeadersToDisplay = customHeader.readListEntry( "headers to display" );
00216 for ( QStringList::iterator it = mHeadersToDisplay.begin() ; it != mHeadersToDisplay.end() ; ++ it )
00217 *it = (*it).lower();
00218 } else
00219 mHeadersToDisplay = stringList( standardHeaders, numStandardHeaders );
00220
00221 if ( customHeader.hasKey( "headers to hide" ) ) {
00222 mHeadersToHide = customHeader.readListEntry( "headers to hide" );
00223 for ( QStringList::iterator it = mHeadersToHide.begin() ; it != mHeadersToHide.end() ; ++ it )
00224 *it = (*it).lower();
00225 }
00226
00227 mDefaultPolicy = customHeader.readEntry( "default policy", "hide" ) == "display" ? Display : Hide ;
00228 }
00229
00230
00231
00232
00233
00234 class MinimalHeaderStrategy : public HeaderStrategy {
00235 friend class HeaderStrategy;
00236 protected :
00237 MinimalHeaderStrategy()
00238 : HeaderStrategy(),
00239 mHeadersToDisplay( stringList( standardHeaders, numStandardHeaders) ) {}
00240 virtual ~MinimalHeaderStrategy() {}
00241
00242 public:
00243 const char * name() const { return "minimal"; }
00244 const HeaderStrategy * next() const { return all(); }
00245 const HeaderStrategy * prev() const { return custom(); }
00246
00247 QStringList headersToDisplay() const { return mHeadersToDisplay; }
00248 DefaultPolicy defaultPolicy() const { return Hide; }
00249
00250 private:
00251 const QStringList mHeadersToDisplay;
00252 };
00253
00254
00255
00256
00257
00258
00259 HeaderStrategy::HeaderStrategy() {
00260
00261 }
00262
00263 HeaderStrategy::~HeaderStrategy() {
00264
00265 }
00266
00267 QStringList HeaderStrategy::headersToDisplay() const {
00268 return QStringList();
00269 }
00270
00271 QStringList HeaderStrategy::headersToHide() const {
00272 return QStringList();
00273 }
00274
00275 bool HeaderStrategy::showHeader( const QString & header ) const {
00276 if ( headersToDisplay().contains( header.lower() ) ) return true;
00277 if ( headersToHide().contains( header.lower() ) ) return false;
00278 return defaultPolicy() == Display;
00279 }
00280
00281 const HeaderStrategy * HeaderStrategy::create( Type type ) {
00282 switch ( type ) {
00283 case All: return all();
00284 case Rich: return rich();
00285 case Standard: return standard();
00286 case Brief: return brief();
00287 case Custom: return custom();
00288 case Minimal: return minimal();
00289 }
00290 kdFatal( 5006 ) << "HeaderStrategy::create(): Unknown header strategy ( type == "
00291 << (int)type << " ) requested!" << endl;
00292 return 0;
00293 }
00294
00295 const HeaderStrategy * HeaderStrategy::create( const QString & type ) {
00296 QString lowerType = type.lower();
00297 if ( lowerType == "all" ) return all();
00298 if ( lowerType == "rich" ) return HeaderStrategy::rich();
00299
00300 if ( lowerType == "brief" ) return brief();
00301 if ( lowerType == "custom" ) return custom();
00302 if ( lowerType == "minimal" ) return minimal();
00303
00304
00305 return standard();
00306 }
00307
00308 static const HeaderStrategy * allStrategy = 0;
00309 static const HeaderStrategy * richStrategy = 0;
00310 static const HeaderStrategy * standardStrategy = 0;
00311 static const HeaderStrategy * briefStrategy = 0;
00312 static const HeaderStrategy * customStrategy = 0;
00313 static const HeaderStrategy * minimalStrategy = 0;
00314
00315 const HeaderStrategy * HeaderStrategy::all() {
00316 if ( !allStrategy )
00317 allStrategy = new AllHeaderStrategy();
00318 return allStrategy;
00319 }
00320
00321 const HeaderStrategy * HeaderStrategy::rich() {
00322 if ( !richStrategy )
00323 richStrategy = new RichHeaderStrategy();
00324 return richStrategy;
00325 }
00326
00327 const HeaderStrategy * HeaderStrategy::standard() {
00328 if ( !standardStrategy )
00329 standardStrategy = new StandardHeaderStrategy();
00330 return standardStrategy;
00331 }
00332
00333 const HeaderStrategy * HeaderStrategy::brief() {
00334 if ( !briefStrategy )
00335 briefStrategy = new BriefHeaderStrategy();
00336 return briefStrategy;
00337 }
00338
00339 const HeaderStrategy * HeaderStrategy::custom() {
00340 if ( !customStrategy )
00341 customStrategy = new CustomHeaderStrategy();
00342 return customStrategy;
00343 }
00344
00345 const HeaderStrategy * HeaderStrategy::minimal() {
00346 if ( !minimalStrategy )
00347 minimalStrategy = new MinimalHeaderStrategy();
00348 return minimalStrategy;
00349 }
00350 }
This file is part of the documentation for kmail Library Version 3.3.2.