6 #include "kmmsgpartdlg.h"
10 #include "kmmsgpart.h"
11 #include "kcursorsaver.h"
16 #include <kmimetype.h>
17 #include <tdeapplication.h>
18 #include <kiconloader.h>
19 #include <tdeaboutdata.h>
20 #include <kstringvalidator.h>
21 #include <kcombobox.h>
27 #include <tqwhatsthis.h>
28 #include <klineedit.h>
29 #include <tqcheckbox.h>
36 const char * displayName;
38 { KMMsgPartDialog::SevenBit, I18N_NOOP(
"None (7-bit text)") },
39 { KMMsgPartDialog::EightBit, I18N_NOOP(
"None (8-bit text)") },
40 { KMMsgPartDialog::QuotedPrintable, I18N_NOOP(
"Quoted Printable") },
41 { KMMsgPartDialog::Base64, I18N_NOOP(
"Base 64") },
43 static const int numEncodingTypes =
44 sizeof encodingTypes /
sizeof *encodingTypes;
46 KMMsgPartDialog::KMMsgPartDialog(
const TQString & caption,
47 TQWidget * parent,
const char * name )
49 caption.isEmpty() ? i18n(
"Message Part Properties") : caption,
50 Ok|Cancel|Help,
Ok, parent, name, true, true)
57 setHelp( TQString::fromLatin1(
"attachments") );
59 for (
int i = 0 ; i < numEncodingTypes ; ++i )
60 mI18nizedEncodings << i18n( encodingTypes[i].displayName );
62 glay =
new TQGridLayout( plainPage(), 9 , 2 , spacingHint() );
63 glay->setColStretch( 1, 1 );
64 glay->setRowStretch( 8, 1 );
67 mIcon =
new TQLabel( plainPage() );
68 mIcon->setPixmap( DesktopIcon(
"unknown") );
69 glay->addMultiCellWidget( mIcon, 0, 1, 0, 0 );
72 mMimeType =
new KComboBox(
true, plainPage() );
73 mMimeType->setInsertionPolicy( TQComboBox::NoInsertion );
74 mMimeType->setValidator(
new KMimeTypeValidator( mMimeType ) );
75 mMimeType->insertStringList( TQStringList()
76 << TQString::fromLatin1(
"text/html")
77 << TQString::fromLatin1(
"text/plain")
78 << TQString::fromLatin1(
"image/gif")
79 << TQString::fromLatin1(
"image/jpeg")
80 << TQString::fromLatin1(
"image/png")
81 << TQString::fromLatin1(
"application/octet-stream")
82 << TQString::fromLatin1(
"application/x-gunzip")
83 << TQString::fromLatin1(
"application/zip") );
84 connect( mMimeType, TQ_SIGNAL(textChanged(
const TQString&)),
85 this, TQ_SLOT(slotMimeTypeChanged(
const TQString&)) );
86 glay->addWidget( mMimeType, 0, 1 );
88 msg = i18n(
"<qt><p>The <em>MIME type</em> of the file:</p>"
89 "<p>normally, you do not need to touch this setting, since the "
90 "type of the file is automatically checked; but, sometimes, %1 "
91 "may not detect the type correctly -- here is where you can fix "
92 "that.</p></qt>").arg( kapp->aboutData()->programName() );
93 TQWhatsThis::add( mMimeType, msg );
96 mSize =
new TQLabel( plainPage() );
97 setSize( TDEIO::filesize_t(0) );
98 glay->addWidget( mSize, 1, 1 );
100 msg = i18n(
"<qt><p>The size of the part:</p>"
101 "<p>sometimes, %1 will only give an estimated size here, "
102 "because calculating the exact size would take too much time; "
103 "when this is the case, it will be made visible by adding "
104 "\"(est.)\" to the size displayed.</p></qt>")
105 .arg( kapp->aboutData()->programName() );
106 TQWhatsThis::add( mSize, msg );
109 mFileName =
new KLineEdit( plainPage() );
110 label =
new TQLabel( mFileName, i18n(
"&Name:"), plainPage() );
111 glay->addWidget( label, 2, 0 );
112 glay->addWidget( mFileName, 2, 1 );
114 msg = i18n(
"<qt><p>The file name of the part:</p>"
115 "<p>although this defaults to the name of the attached file, "
116 "it does not specify the file to be attached; rather, it "
117 "suggests a file name to be used by the recipient's mail agent "
118 "when saving the part to disk.</p></qt>");
119 TQWhatsThis::add( label, msg );
120 TQWhatsThis::add( mFileName, msg );
123 mDescription =
new KLineEdit( plainPage() );
124 label =
new TQLabel( mDescription, i18n(
"&Description:"), plainPage() );
125 glay->addWidget( label, 3, 0 );
126 glay->addWidget( mDescription, 3, 1 );
128 msg = i18n(
"<qt><p>A description of the part:</p>"
129 "<p>this is just an informational description of the part, "
130 "much like the Subject is for the whole message; most "
131 "mail agents will show this information in their message "
132 "previews alongside the attachment's icon.</p></qt>");
133 TQWhatsThis::add( label, msg );
134 TQWhatsThis::add( mDescription, msg );
137 mEncoding =
new TQComboBox(
false, plainPage() );
138 mEncoding->insertStringList( mI18nizedEncodings );
139 label =
new TQLabel( mEncoding, i18n(
"&Encoding:"), plainPage() );
140 glay->addWidget( label, 4, 0 );
141 glay->addWidget( mEncoding, 4, 1 );
143 msg = i18n(
"<qt><p>The transport encoding of this part:</p>"
144 "<p>normally, you do not need to change this, since %1 will use "
145 "a decent default encoding, depending on the MIME type; yet, "
146 "sometimes, you can significantly reduce the size of the "
147 "resulting message, e.g. if a PostScript file does not contain "
148 "binary data, but consists of pure text -- in this case, choosing "
149 "\"quoted-printable\" over the default \"base64\" will save up "
150 "to 25% in resulting message size.</p></qt>")
151 .arg( kapp->aboutData()->programName() );
152 TQWhatsThis::add( label, msg );
153 TQWhatsThis::add( mEncoding, msg );
156 mInline =
new TQCheckBox( i18n(
"Suggest &automatic display"), plainPage() );
157 glay->addMultiCellWidget( mInline, 5, 5, 0, 1 );
159 msg = i18n(
"<qt><p>Check this option if you want to suggest to the "
160 "recipient the automatic (inline) display of this part in the "
161 "message preview, instead of the default icon view;</p>"
162 "<p>technically, this is carried out by setting this part's "
163 "<em>Content-Disposition</em> header field to \"inline\" "
164 "instead of the default \"attachment\".</p></qt>");
165 TQWhatsThis::add( mInline, msg );
168 mSigned =
new TQCheckBox( i18n(
"&Sign this part"), plainPage() );
169 glay->addMultiCellWidget( mSigned, 6, 6, 0, 1 );
171 msg = i18n(
"<qt><p>Check this option if you want this message part to be "
173 "<p>the signature will be made with the key that you associated "
174 "with the currently-selected identity.</p></qt>");
175 TQWhatsThis::add( mSigned, msg );
178 mEncrypted =
new TQCheckBox( i18n(
"Encr&ypt this part"), plainPage() );
179 glay->addMultiCellWidget( mEncrypted, 7, 7, 0, 1 );
181 msg = i18n(
"<qt><p>Check this option if you want this message part to be "
183 "<p>the part will be encrypted for the recipients of this "
185 TQWhatsThis::add( mEncrypted, msg );
190 KMMsgPartDialog::~KMMsgPartDialog() {}
194 return mMimeType->currentText();
200 if ( mMimeType->validator() && mMimeType->validator()->validate( tmp, dummy ) )
201 for (
int i = 0 ; i < mMimeType->count() ; ++i )
202 if ( mMimeType->text( i ) ==
mimeType ) {
203 mMimeType->setCurrentItem( i );
206 mMimeType->insertItem(
mimeType, 0 );
207 mMimeType->setCurrentItem( 0 );
212 const TQString & subtype ) {
213 setMimeType( TQString::fromLatin1(
"%1/%2").arg(type).arg(subtype) );
217 mMimeType->insertStringList( mimeTypes );
221 TQString text = TDEIO::convertSize( size );
223 text = i18n(
"%1: a filesize incl. unit (e.g. \"1.3 KB\")",
224 "%1 (est.)").arg( text );
225 mSize->setText( text );
229 return mFileName->text();
237 return mDescription->text();
245 TQString s = mEncoding->currentText();
246 for (
unsigned int i = 0 ; i < mI18nizedEncodings.count() ; ++i )
247 if ( s == *mI18nizedEncodings.at(i) )
248 return encodingTypes[i].encoding;
249 kdFatal(5006) <<
"KMMsgPartDialog::encoding(): Unknown encoding encountered!"
255 for (
int i = 0 ; i < numEncodingTypes ; ++i )
257 TQString text = *mI18nizedEncodings.at(i);
258 for (
int j = 0 ; j < mEncoding->count() ; ++j )
259 if ( mEncoding->text(j) == text ) {
260 mEncoding->setCurrentItem( j );
263 mEncoding->insertItem( text, 0 );
264 mEncoding->setCurrentItem( 0 );
266 kdFatal(5006) <<
"KMMsgPartDialog::setEncoding(): "
267 "Unknown encoding encountered!" << endl;
272 for (
int i = 0 ; i < numEncodingTypes ; ++i )
273 if ( encodingTypes[i].
encoding & encodings )
274 mEncoding->insertItem( *mI18nizedEncodings.at(i) );
278 return mInline->isChecked();
282 mInline->setChecked( inlined );
286 return mEncrypted->isChecked();
290 mEncrypted->setChecked( encrypted );
294 mEncrypted->setEnabled( enable );
298 return mSigned->isChecked();
302 mSigned->setChecked( sign );
306 mSigned->setEnabled( enable );
309 void KMMsgPartDialog::slotMimeTypeChanged(
const TQString & mimeType ) {
314 if (
mimeType.startsWith(
"message/") ) {
316 mEncoding->setEnabled(
false );
318 mEncoding->setEnabled( !mReadOnly );
324 if ( mMimeType->validator() && mMimeType->validator()->validate( tmp, dummy )
325 == TQValidator::Acceptable )
326 mIcon->setPixmap( KMimeType::mimeType(
mimeType )->pixmap( TDEIcon::Desktop ) );
328 mIcon->setPixmap( DesktopIcon(
"unknown") );
334 KMMsgPartDialogCompat::KMMsgPartDialogCompat( TQWidget * parent,
const char *,
bool readOnly)
340 mMimeType->setEditable(
false);
341 mMimeType->setEnabled(
false);
342 mFileName->setReadOnly(
true);
343 mDescription->setReadOnly(
true);
344 mEncoding->setEnabled(
false);
345 mInline->setEnabled(
false);
346 mEncrypted->setEnabled(
false);
347 mSigned->setEnabled(
false);
351 KMMsgPartDialogCompat::~KMMsgPartDialogCompat() {}
358 TQCString enc = mMsgPart->cteStr();
361 else if ( enc ==
"8bit" )
363 else if ( enc ==
"quoted-printable" )
370 setMimeType( mMsgPart->typeStr(), mMsgPart->subtypeStr() );
371 setSize( mMsgPart->decodedSize() );
372 setInline( mMsgPart->contentDisposition()
373 .find( TQRegExp(
"^\\s*inline",
false) ) >= 0 );
379 if (!mMsgPart)
return;
388 cDisp =
"attachment;";
391 if ( !name.isEmpty() || !mMsgPart->name().isEmpty()) {
392 mMsgPart->setName( name );
393 TQCString encName = KMMsgBase::encodeRFC2231StringAutoDetectCharset( name, mMsgPart->charset() );
395 cDisp +=
"\n\tfilename";
396 if ( name != TQString( encName ) )
397 cDisp +=
"*=" + encName;
399 cDisp +=
"=\"" + encName.replace(
'\\',
"\\\\" ).replace(
'"',
"\\\"" ) +
'"';
400 mMsgPart->setContentDisposition( cDisp );
405 if ( !desc.isEmpty() || !mMsgPart->contentDescription().isEmpty() )
406 mMsgPart->setContentDescription( desc );
409 TQCString type =
mimeType().latin1();
411 int idx = type.find(
'/');
415 subtype = type.mid( idx+1 );
416 type = type.left( idx );
418 mMsgPart->setTypeStr(type);
419 mMsgPart->setSubtypeStr(subtype);
423 if (subtype ==
"rfc822" && type ==
"message")
425 <<
"encoding on rfc822/message must be \"7bit\" or \"8bit\"" << endl;
427 case SevenBit: cte =
"7bit";
break;
428 case EightBit: cte =
"8bit";
break;
429 case QuotedPrintable: cte =
"quoted-printable";
break;
430 case Base64:
default: cte =
"base64";
break;
432 if ( cte != mMsgPart->cteStr().lower() ) {
433 TQByteArray body = mMsgPart->bodyDecodedBinary();
434 mMsgPart->setCteStr( cte );
435 mMsgPart->setBodyEncodedBinary( body );
441 void KMMsgPartDialogCompat::slotOk()
444 KMMsgPartDialog::slotOk();
449 #include "kmmsgpartdlg.moc"
sets a cursor and makes sure it's restored on destruction Create a KCursorSaver object when you want ...
void applyChanges(void)
Applies changes from the dialog to the message part.
void setMsgPart(KMMessagePart *msgPart)
Display information about this message part.
TQString mimeType() const
Get the currently selected mimetype.
TQString fileName() const
Returns the current file name of the attachment.
void setShownEncodings(int encodings)
Sets the list of encodings to be shown.
bool isSigned() const
Returns whether or not this attachment is or shall be signed.
Encoding encoding() const
Returns the current encoding.
void setCanSign(bool enable)
Sets whether or not this attachment can be signed.
void setEncoding(Encoding encoding)
Sets the encoding to use.
void setMimeType(const TQString &type, const TQString &subtype)
Sets the mime type to be displayed.
bool isInline() const
Returns true if the attchment has a content-disposition of "inline", false otherwise.
void setDescription(const TQString &description)
Sets the description of the attachment, ie.
void setFileName(const TQString &fileName)
Sets the file name of the attachment.
void setCanEncrypt(bool enable)
Sets whether or not this attachment can be encrypted.
void setEncrypted(bool encrypted)
Sets whether or not this attachment is or should be encrypted.
void setInline(bool inlined)
Sets whether this attachment has a content-disposition of "inline".
TQString description() const
Returns the content of the Content-Description header field.
void setSigned(bool sign)
Sets whether or not this attachment is or should be signed.
Encoding
The list of supported encodings.
void setMimeTypeList(const TQStringList &mimeTypes)
Sets the initial list of mime types to be displayed in the combobox.
bool isEncrypted() const
Returns whether or not this attachment is or shall be encrypted.
void setSize(TDEIO::filesize_t size, bool estimated=false)
Sets the size of the file to be attached in bytes.
@ Ok
The user rights/ACL have been fetched from the server sucessfully.