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
00069
00070
00071
static QStringList stringList(
const char * headers[],
int numHeaders ) {
00072
QStringList sl;
00073
for (
int i = 0 ; i < numHeaders ; ++i )
00074 sl.push_back( headers[i] );
00075
return sl;
00076 }
00077
00078
00079
00080
00081
00082
00083
class AllHeaderStrategy :
public HeaderStrategy {
00084
friend class HeaderStrategy;
00085
protected:
00086 AllHeaderStrategy() : HeaderStrategy() {}
00087
virtual ~AllHeaderStrategy() {}
00088
00089
public:
00090
const char * name()
const {
return "all"; }
00091
const HeaderStrategy * next()
const {
return rich(); }
00092
const HeaderStrategy * prev()
const {
return custom(); }
00093
00094 DefaultPolicy defaultPolicy()
const {
return Display; }
00095
00096
bool showHeader(
const QString & )
const {
00097
return true;
00098 }
00099 };
00100
00101
00102
00103
00104
00105
00106
class RichHeaderStrategy :
public HeaderStrategy {
00107
friend class HeaderStrategy;
00108
protected:
00109 RichHeaderStrategy()
00110 : HeaderStrategy(),
00111 mHeadersToDisplay( stringList( richHeaders, numRichHeaders ) ) {}
00112
virtual ~RichHeaderStrategy() {}
00113
00114
public:
00115
const char * name()
const {
return "rich"; }
00116
const HeaderStrategy * next()
const {
return standard(); }
00117
const HeaderStrategy * prev()
const {
return all(); }
00118
00119
QStringList headersToDisplay()
const {
return mHeadersToDisplay; }
00120 DefaultPolicy defaultPolicy()
const {
return Hide; }
00121
00122
private:
00123
const QStringList mHeadersToDisplay;
00124 };
00125
00126
00127
00128
00129
00130
00131
class StandardHeaderStrategy :
public HeaderStrategy {
00132
friend class HeaderStrategy;
00133
protected:
00134 StandardHeaderStrategy()
00135 : HeaderStrategy(),
00136 mHeadersToDisplay( stringList( standardHeaders, numStandardHeaders) ) {}
00137
virtual ~StandardHeaderStrategy() {}
00138
00139
public:
00140
const char * name()
const {
return "standard"; }
00141
const HeaderStrategy * next()
const {
return brief(); }
00142
const HeaderStrategy * prev()
const {
return rich(); }
00143
00144
QStringList headersToDisplay()
const {
return mHeadersToDisplay; }
00145 DefaultPolicy defaultPolicy()
const {
return Hide; }
00146
00147
private:
00148
const QStringList mHeadersToDisplay;
00149 };
00150
00151
00152
00153
00154
00155
00156
class BriefHeaderStrategy :
public HeaderStrategy {
00157
friend class HeaderStrategy;
00158
protected:
00159 BriefHeaderStrategy()
00160 : HeaderStrategy(),
00161 mHeadersToDisplay( stringList( briefHeaders, numBriefHeaders ) ) {}
00162
virtual ~BriefHeaderStrategy() {}
00163
00164
public:
00165
const char * name()
const {
return "brief"; }
00166
const HeaderStrategy * next()
const {
return custom(); }
00167
const HeaderStrategy * prev()
const {
return standard(); }
00168
00169
QStringList headersToDisplay()
const {
return mHeadersToDisplay; }
00170 DefaultPolicy defaultPolicy()
const {
return Hide; }
00171
00172
private:
00173
const QStringList mHeadersToDisplay;
00174 };
00175
00176
00177
00178
00179
00180
00181
00182
class CustomHeaderStrategy :
public HeaderStrategy {
00183
friend class HeaderStrategy;
00184
protected:
00185 CustomHeaderStrategy();
00186
virtual ~CustomHeaderStrategy() {}
00187
00188
public:
00189
const char * name()
const {
return "custom"; }
00190
const HeaderStrategy * next()
const {
return all(); }
00191
const HeaderStrategy * prev()
const {
return brief(); }
00192
00193
QStringList headersToDisplay()
const {
return mHeadersToDisplay; }
00194
QStringList headersToHide()
const {
return mHeadersToHide; }
00195 DefaultPolicy defaultPolicy()
const {
return mDefaultPolicy; }
00196
00197
private:
00198
QStringList mHeadersToDisplay;
00199
QStringList mHeadersToHide;
00200 DefaultPolicy mDefaultPolicy;
00201 };
00202
00203
00204 CustomHeaderStrategy::CustomHeaderStrategy()
00205 : HeaderStrategy()
00206 {
00207 KConfigGroup customHeader( KMKernel::config(),
"Custom Headers" );
00208
if ( customHeader.hasKey(
"headers to display" ) ) {
00209 mHeadersToDisplay = customHeader.readListEntry(
"headers to display" );
00210
for ( QStringList::iterator it = mHeadersToDisplay.begin() ; it != mHeadersToDisplay.end() ; ++ it )
00211 *it = (*it).lower();
00212 }
else
00213 mHeadersToDisplay = stringList( standardHeaders, numStandardHeaders );
00214
00215
if ( customHeader.hasKey(
"headers to hide" ) ) {
00216 mHeadersToHide = customHeader.readListEntry(
"headers to hide" );
00217
for ( QStringList::iterator it = mHeadersToHide.begin() ; it != mHeadersToHide.end() ; ++ it )
00218 *it = (*it).lower();
00219 }
00220
00221 mDefaultPolicy = customHeader.readEntry(
"default policy",
"hide" ) ==
"display" ? Display : Hide ;
00222 }
00223
00224
00225
00226
00227
00228 HeaderStrategy::HeaderStrategy() {
00229
00230 }
00231
00232 HeaderStrategy::~HeaderStrategy() {
00233
00234 }
00235
00236
QStringList HeaderStrategy::headersToDisplay()
const {
00237
return QStringList();
00238 }
00239
00240
QStringList HeaderStrategy::headersToHide()
const {
00241
return QStringList();
00242 }
00243
00244
bool HeaderStrategy::showHeader(
const QString & header )
const {
00245
if ( headersToDisplay().contains( header.lower() ) )
return true;
00246
if ( headersToHide().contains( header.lower() ) )
return false;
00247
return defaultPolicy() == Display;
00248 }
00249
00250
const HeaderStrategy * HeaderStrategy::create( Type type ) {
00251
switch ( type ) {
00252
case All:
return all();
00253
case Rich:
return rich();
00254
case Standard:
return standard();
00255
case Brief:
return brief();
00256
case Custom:
return custom();
00257 }
00258 kdFatal( 5006 ) <<
"HeaderStrategy::create(): Unknown header strategy ( type == "
00259 << (
int)type <<
" ) requested!" << endl;
00260
return 0;
00261 }
00262
00263
const HeaderStrategy * HeaderStrategy::create(
const QString & type ) {
00264
QString lowerType = type.lower();
00265
if ( lowerType ==
"all" )
return all();
00266
if ( lowerType ==
"rich" )
return HeaderStrategy::rich();
00267
00268
if ( lowerType ==
"brief" )
return brief();
00269
if ( lowerType ==
"custom" )
return custom();
00270
00271
00272
return standard();
00273 }
00274
00275
static const HeaderStrategy * allStrategy = 0;
00276
static const HeaderStrategy * richStrategy = 0;
00277
static const HeaderStrategy * standardStrategy = 0;
00278
static const HeaderStrategy * briefStrategy = 0;
00279
static const HeaderStrategy * customStrategy = 0;
00280
00281
const HeaderStrategy * HeaderStrategy::all() {
00282
if ( !allStrategy )
00283 allStrategy =
new AllHeaderStrategy();
00284
return allStrategy;
00285 }
00286
00287
const HeaderStrategy * HeaderStrategy::rich() {
00288
if ( !richStrategy )
00289 richStrategy =
new RichHeaderStrategy();
00290
return richStrategy;
00291 }
00292
00293
const HeaderStrategy * HeaderStrategy::standard() {
00294
if ( !standardStrategy )
00295 standardStrategy =
new StandardHeaderStrategy();
00296
return standardStrategy;
00297 }
00298
00299
const HeaderStrategy * HeaderStrategy::brief() {
00300
if ( !briefStrategy )
00301 briefStrategy =
new BriefHeaderStrategy();
00302
return briefStrategy;
00303 }
00304
00305
const HeaderStrategy * HeaderStrategy::custom() {
00306
if ( !customStrategy )
00307 customStrategy =
new CustomHeaderStrategy();
00308
return customStrategy;
00309 }
00310
00311 }