36 #include "attachmentstrategy.h"
39 #include "kmmsgpart.h"
48 static AttachmentStrategy::Display smartDisplay(
const partNode *node )
50 if ( node->hasContentDispositionInline() )
52 return AttachmentStrategy::Inline;
53 if ( node->isAttachment() )
55 return AttachmentStrategy::AsIcon;
56 if ( node->type() == DwMime::kTypeText &&
57 node->msgPart().fileName().stripWhiteSpace().isEmpty() &&
58 node->msgPart().name().stripWhiteSpace().isEmpty() )
60 return AttachmentStrategy::Inline;
61 return AttachmentStrategy::AsIcon;
69 class IconicAttachmentStrategy :
public AttachmentStrategy {
70 friend class ::KMail::AttachmentStrategy;
72 IconicAttachmentStrategy() : AttachmentStrategy() {}
73 virtual ~IconicAttachmentStrategy() {}
76 const char * name()
const {
return "iconic"; }
77 const AttachmentStrategy * next()
const {
return smart(); }
78 const AttachmentStrategy * prev()
const {
return headerOnly(); }
80 bool inlineNestedMessages()
const {
return false; }
81 Display defaultDisplay(
const partNode * )
const {
return AsIcon; }
91 class SmartAttachmentStrategy :
public AttachmentStrategy {
92 friend class ::KMail::AttachmentStrategy;
94 SmartAttachmentStrategy() : AttachmentStrategy() {}
95 virtual ~SmartAttachmentStrategy() {}
98 const char * name()
const {
return "smart"; }
99 const AttachmentStrategy * next()
const {
return inlined(); }
100 const AttachmentStrategy * prev()
const {
return iconic(); }
102 bool inlineNestedMessages()
const {
return true; }
103 Display defaultDisplay(
const partNode * node )
const {
104 return smartDisplay( node );
113 class InlinedAttachmentStrategy :
public AttachmentStrategy {
114 friend class ::KMail::AttachmentStrategy;
116 InlinedAttachmentStrategy() : AttachmentStrategy() {}
117 virtual ~InlinedAttachmentStrategy() {}
120 const char * name()
const {
return "inlined"; }
121 const AttachmentStrategy * next()
const {
return hidden(); }
122 const AttachmentStrategy * prev()
const {
return smart(); }
124 bool inlineNestedMessages()
const {
return true; }
125 Display defaultDisplay(
const partNode * )
const {
return Inline; }
133 class HiddenAttachmentStrategy :
public AttachmentStrategy {
134 friend class ::KMail::AttachmentStrategy;
136 HiddenAttachmentStrategy() : AttachmentStrategy() {}
137 virtual ~HiddenAttachmentStrategy() {}
140 const char * name()
const {
return "hidden"; }
141 const AttachmentStrategy * next()
const {
return headerOnly(); }
142 const AttachmentStrategy * prev()
const {
return inlined(); }
144 bool inlineNestedMessages()
const {
return false; }
145 Display defaultDisplay(
const partNode * )
const {
return None; }
148 class HeaderOnlyAttachmentStrategy :
public AttachmentStrategy {
149 friend class ::KMail::AttachmentStrategy;
151 HeaderOnlyAttachmentStrategy() : AttachmentStrategy() {}
152 virtual ~HeaderOnlyAttachmentStrategy() {}
155 const char * name()
const {
return "headerOnly"; }
156 const AttachmentStrategy * next()
const {
return iconic(); }
157 const AttachmentStrategy * prev()
const {
return hidden(); }
159 bool inlineNestedMessages()
const {
163 Display defaultDisplay(
const partNode *node )
const {
164 if ( node->isInEncapsulatedMessage() ) {
165 return smartDisplay( node );
168 partNode::AttachmentDisplayInfo info = node->attachmentDisplayInfo();
169 if ( info.displayInHeader ) {
174 return smartDisplay( node );
185 AttachmentStrategy::AttachmentStrategy() {
189 AttachmentStrategy::~AttachmentStrategy() {
193 const AttachmentStrategy * AttachmentStrategy::create( Type type ) {
195 case Iconic:
return iconic();
196 case Smart:
return smart();
197 case Inlined:
return inlined();
198 case Hidden:
return hidden();
199 case HeaderOnly:
return headerOnly();
201 kdFatal( 5006 ) <<
"AttachmentStrategy::create(): Unknown attachment startegy ( type == "
202 << (int)type <<
" ) requested!" << endl;
206 const AttachmentStrategy * AttachmentStrategy::create(
const TQString & type ) {
207 TQString lowerType = type.lower();
208 if ( lowerType ==
"iconic" )
return iconic();
210 if ( lowerType ==
"inlined" )
return inlined();
211 if ( lowerType ==
"hidden" )
return hidden();
212 if ( lowerType ==
"headeronly" )
return headerOnly();
218 static const AttachmentStrategy * iconicStrategy = 0;
219 static const AttachmentStrategy * smartStrategy = 0;
220 static const AttachmentStrategy * inlinedStrategy = 0;
221 static const AttachmentStrategy * hiddenStrategy = 0;
222 static const AttachmentStrategy * headerOnlyStrategy = 0;
224 const AttachmentStrategy * AttachmentStrategy::iconic() {
225 if ( !iconicStrategy )
226 iconicStrategy =
new IconicAttachmentStrategy();
227 return iconicStrategy;
230 const AttachmentStrategy * AttachmentStrategy::smart() {
231 if ( !smartStrategy )
232 smartStrategy =
new SmartAttachmentStrategy();
233 return smartStrategy;
236 const AttachmentStrategy * AttachmentStrategy::inlined() {
237 if ( !inlinedStrategy )
238 inlinedStrategy =
new InlinedAttachmentStrategy();
239 return inlinedStrategy;
242 const AttachmentStrategy * AttachmentStrategy::hidden() {
243 if ( !hiddenStrategy )
244 hiddenStrategy =
new HiddenAttachmentStrategy();
245 return hiddenStrategy;
248 const AttachmentStrategy * AttachmentStrategy::headerOnly() {
249 if ( !headerOnlyStrategy )
250 headerOnlyStrategy =
new HeaderOnlyAttachmentStrategy();
251 return headerOnlyStrategy;