00001
00002
00003
00004
00005
00006 #undef GrayScale
00007 #undef Color
00008 #include <config.h>
00009
00010 #define REALLY_WANT_KMCOMPOSEWIN_H
00011 #include "kmcomposewin.h"
00012 #undef REALLY_WANT_KMCOMPOSEWIN_H
00013
00014 #include "kmedit.h"
00015 #include "kmlineeditspell.h"
00016 #include "kmatmlistview.h"
00017
00018 #include "kmmainwin.h"
00019 #include "kmreadermainwin.h"
00020 #include "messagesender.h"
00021 #include "kmmsgpartdlg.h"
00022 #include <kpgpblock.h>
00023 #include <kaddrbook.h>
00024 #include "kmaddrbook.h"
00025 #include "kmmsgdict.h"
00026 #include "kmfolderimap.h"
00027 #include "kmfoldermgr.h"
00028 #include "kmfoldercombobox.h"
00029 #include "kmtransport.h"
00030 #include "kmcommands.h"
00031 #include "kcursorsaver.h"
00032 #include "partNode.h"
00033 #include "attachmentlistview.h"
00034 #include "transportmanager.h"
00035 using KMail::AttachmentListView;
00036 #include "dictionarycombobox.h"
00037 using KMail::DictionaryComboBox;
00038 #include "addressesdialog.h"
00039 using KPIM::AddressesDialog;
00040 #include "addresseeemailselection.h"
00041 using KPIM::AddresseeEmailSelection;
00042 using KPIM::AddresseeSelectorDialog;
00043 #include <maillistdrag.h>
00044 using KPIM::MailListDrag;
00045 #include "recentaddresses.h"
00046 using KRecentAddress::RecentAddresses;
00047 #include "kleo_util.h"
00048 #include "stl_util.h"
00049 #include "recipientseditor.h"
00050
00051 #include "attachmentcollector.h"
00052 #include "objecttreeparser.h"
00053
00054 #include "kmfoldermaildir.h"
00055
00056 #include <libkpimidentities/identitymanager.h>
00057 #include <libkpimidentities/identitycombo.h>
00058 #include <libkpimidentities/identity.h>
00059 #include <libkdepim/kfileio.h>
00060 #include <libemailfunctions/email.h>
00061 #include <kleo/cryptobackendfactory.h>
00062 #include <kleo/exportjob.h>
00063 #include <kleo/specialjob.h>
00064 #include <ui/progressdialog.h>
00065 #include <ui/keyselectiondialog.h>
00066
00067 #include <gpgmepp/context.h>
00068 #include <gpgmepp/key.h>
00069
00070 #include <kabc/vcardconverter.h>
00071 #include <libkdepim/kvcarddrag.h>
00072 #include <kio/netaccess.h>
00073
00074
00075 #include "klistboxdialog.h"
00076
00077 #include "messagecomposer.h"
00078 #include "chiasmuskeyselector.h"
00079
00080 #include <kcharsets.h>
00081 #include <kcompletionbox.h>
00082 #include <kcursor.h>
00083 #include <kcombobox.h>
00084 #include <kstdaccel.h>
00085 #include <kpopupmenu.h>
00086 #include <kedittoolbar.h>
00087 #include <kkeydialog.h>
00088 #include <kdebug.h>
00089 #include <kfiledialog.h>
00090 #include <kwin.h>
00091 #include <kinputdialog.h>
00092 #include <kmessagebox.h>
00093 #include <kurldrag.h>
00094 #include <kio/scheduler.h>
00095 #include <ktempfile.h>
00096 #include <klocale.h>
00097 #include <kapplication.h>
00098 #include <kstatusbar.h>
00099 #include <kaction.h>
00100 #include <kstdaction.h>
00101 #include <kdirwatch.h>
00102 #include <kstdguiitem.h>
00103 #include <kiconloader.h>
00104 #include <kpushbutton.h>
00105 #include <kuserprofile.h>
00106 #include <krun.h>
00107 #include <ktempdir.h>
00108
00109 #include "globalsettings.h"
00110 #include "replyphrases.h"
00111
00112 #include <kspell.h>
00113 #include <kspelldlg.h>
00114 #include <spellingfilter.h>
00115 #include <ksyntaxhighlighter.h>
00116 #include <kcolordialog.h>
00117 #include <kzip.h>
00118 #include <ksavefile.h>
00119
00120 #include <qtabdialog.h>
00121 #include <qregexp.h>
00122 #include <qbuffer.h>
00123 #include <qtooltip.h>
00124 #include <qtextcodec.h>
00125 #include <qheader.h>
00126 #include <qwhatsthis.h>
00127 #include <qfontdatabase.h>
00128
00129 #include <mimelib/mimepp.h>
00130
00131 #include <algorithm>
00132 #include <memory>
00133
00134 #include <sys/stat.h>
00135 #include <sys/types.h>
00136 #include <stdlib.h>
00137 #include <unistd.h>
00138 #include <errno.h>
00139 #include <fcntl.h>
00140 #include <assert.h>
00141
00142 #include "kmcomposewin.moc"
00143
00144 KMail::Composer * KMail::makeComposer( KMMessage * msg, uint identitiy ) {
00145 return KMComposeWin::create( msg, identitiy );
00146 }
00147
00148 KMail::Composer * KMComposeWin::create( KMMessage * msg, uint identitiy ) {
00149 return new KMComposeWin( msg, identitiy );
00150 }
00151
00152
00153 KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id )
00154 : MailComposerIface(), KMail::Composer( "kmail-composer#" ),
00155 mSpellCheckInProgress( false ),
00156 mDone( false ),
00157 mAtmModified( false ),
00158 mMsg( 0 ),
00159 mAttachMenu( 0 ),
00160 mSigningAndEncryptionExplicitlyDisabled( false ),
00161 mFolder( 0 ),
00162 mUseHTMLEditor( false ),
00163 mId( id ),
00164 mAttachPK( 0 ), mAttachMPK( 0 ),
00165 mAttachRemoveAction( 0 ), mAttachSaveAction( 0 ), mAttachPropertiesAction( 0 ),
00166 mSignAction( 0 ), mEncryptAction( 0 ), mRequestMDNAction( 0 ),
00167 mUrgentAction( 0 ), mAllFieldsAction( 0 ), mFromAction( 0 ),
00168 mReplyToAction( 0 ), mToAction( 0 ), mCcAction( 0 ), mBccAction( 0 ),
00169 mSubjectAction( 0 ),
00170 mIdentityAction( 0 ), mTransportAction( 0 ), mFccAction( 0 ),
00171 mWordWrapAction( 0 ), mFixedFontAction( 0 ), mAutoSpellCheckingAction( 0 ),
00172 mDictionaryAction( 0 ),
00173 mEncodingAction( 0 ),
00174 mCryptoModuleAction( 0 ),
00175 mEncryptChiasmusAction( 0 ),
00176 mEncryptWithChiasmus( false ),
00177 mComposer( 0 ),
00178 mLabelWidth( 0 ),
00179 mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 )
00180 {
00181 mClassicalRecipients = GlobalSettings::self()->recipientsEditorType() ==
00182 GlobalSettings::EnumRecipientsEditorType::Classic;
00183
00184 mSubjectTextWasSpellChecked = false;
00185 if (kmkernel->xmlGuiInstance())
00186 setInstance( kmkernel->xmlGuiInstance() );
00187 mMainWidget = new QWidget(this);
00188 mIdentity = new KPIM::IdentityCombo(kmkernel->identityManager(), mMainWidget);
00189 mDictionaryCombo = new DictionaryComboBox( mMainWidget );
00190 mFcc = new KMFolderComboBox(mMainWidget);
00191 mFcc->showOutboxFolder( FALSE );
00192 mTransport = new QComboBox(true, mMainWidget);
00193 mEdtFrom = new KMLineEdit(false,mMainWidget, "fromLine");
00194
00195 mEdtReplyTo = new KMLineEdit(true,mMainWidget, "replyToLine");
00196 mLblReplyTo = new QLabel(mMainWidget);
00197 mBtnReplyTo = new QPushButton("...",mMainWidget);
00198 mBtnReplyTo->setFocusPolicy(QWidget::NoFocus);
00199 connect(mBtnReplyTo,SIGNAL(clicked()),SLOT(slotAddrBookReplyTo()));
00200 connect(mEdtReplyTo,SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
00201 SLOT(slotCompletionModeChanged(KGlobalSettings::Completion)));
00202
00203 if ( mClassicalRecipients ) {
00204 mRecipientsEditor = 0;
00205
00206 mEdtTo = new KMLineEdit(true,mMainWidget, "toLine");
00207 mEdtCc = new KMLineEdit(true,mMainWidget, "ccLine");
00208 mEdtBcc = new KMLineEdit(true,mMainWidget, "bccLine");
00209
00210 mLblTo = new QLabel(mMainWidget);
00211 mLblCc = new QLabel(mMainWidget);
00212 mLblBcc = new QLabel(mMainWidget);
00213
00214 mBtnTo = new QPushButton("...",mMainWidget);
00215 mBtnCc = new QPushButton("...",mMainWidget);
00216 mBtnBcc = new QPushButton("...",mMainWidget);
00217
00218
00219 QString tip = i18n("Select email address(es)");
00220 QToolTip::add( mBtnTo, tip );
00221 QToolTip::add( mBtnCc, tip );
00222 QToolTip::add( mBtnBcc, tip );
00223 QToolTip::add( mBtnReplyTo, tip );
00224
00225 mBtnTo->setFocusPolicy(QWidget::NoFocus);
00226 mBtnCc->setFocusPolicy(QWidget::NoFocus);
00227 mBtnBcc->setFocusPolicy(QWidget::NoFocus);
00228
00229
00230 connect(mBtnTo,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
00231 connect(mBtnCc,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
00232 connect(mBtnBcc,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
00233
00234
00235 connect(mEdtTo,SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
00236 SLOT(slotCompletionModeChanged(KGlobalSettings::Completion)));
00237 connect(mEdtCc,SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
00238 SLOT(slotCompletionModeChanged(KGlobalSettings::Completion)));
00239 connect(mEdtBcc,SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
00240 SLOT(slotCompletionModeChanged(KGlobalSettings::Completion)));
00241
00242 mEdtTo->setFocus();
00243 } else {
00244 mEdtTo = 0;
00245 mEdtCc = 0;
00246 mEdtBcc = 0;
00247
00248 mLblTo = 0;
00249 mLblCc = 0;
00250 mLblBcc = 0;
00251
00252 mBtnTo = 0;
00253 mBtnCc = 0;
00254 mBtnBcc = 0;
00255
00256
00257 mRecipientsEditor = new RecipientsEditor( mMainWidget );
00258
00259 mRecipientsEditor->setFocus();
00260 }
00261 mEdtSubject = new KMLineEditSpell(false,mMainWidget, "subjectLine");
00262 mLblIdentity = new QLabel(mMainWidget);
00263 mDictionaryLabel = new QLabel( mMainWidget );
00264 mLblFcc = new QLabel(mMainWidget);
00265 mLblTransport = new QLabel(mMainWidget);
00266 mLblFrom = new QLabel(mMainWidget);
00267 mLblSubject = new QLabel(mMainWidget);
00268 QString sticky = i18n("Sticky");
00269 mBtnIdentity = new QCheckBox(sticky,mMainWidget);
00270 mBtnFcc = new QCheckBox(sticky,mMainWidget);
00271 mBtnTransport = new QCheckBox(sticky,mMainWidget);
00272
00273
00274 mHtmlMarkup = GlobalSettings::self()->useHtmlMarkup();
00275 mShowHeaders = GlobalSettings::self()->headers();
00276 mDone = false;
00277 mGrid = 0;
00278 mAtmListView = 0;
00279 mAtmList.setAutoDelete(TRUE);
00280 mAtmTempList.setAutoDelete(TRUE);
00281 mAtmModified = FALSE;
00282 mAutoDeleteMsg = FALSE;
00283 mFolder = 0;
00284 mAutoCharset = TRUE;
00285 mFixedFontAction = 0;
00286 mTempDir = 0;
00287 mSplitter = new QSplitter( Qt::Vertical, mMainWidget, "mSplitter" );
00288 mEditor = new KMEdit( mSplitter, this, mDictionaryCombo->spellConfig() );
00289 mSplitter->moveToFirst( mEditor );
00290 mSplitter->setOpaqueResize( true );
00291
00292 mEditor->initializeAutoSpellChecking();
00293 mEditor->setTextFormat(Qt::PlainText);
00294 mEditor->setAcceptDrops( true );
00295
00296 QWhatsThis::add( mBtnIdentity,
00297 GlobalSettings::self()->stickyIdentityItem()->whatsThis() );
00298 QWhatsThis::add( mBtnFcc,
00299 GlobalSettings::self()->stickyFccItem()->whatsThis() );
00300 QWhatsThis::add( mBtnTransport,
00301 GlobalSettings::self()->stickyTransportItem()->whatsThis() );
00302
00303 mSpellCheckInProgress=FALSE;
00304
00305 setCaption( i18n("Composer") );
00306 setMinimumSize(200,200);
00307
00308 mBtnIdentity->setFocusPolicy(QWidget::NoFocus);
00309 mBtnFcc->setFocusPolicy(QWidget::NoFocus);
00310 mBtnTransport->setFocusPolicy(QWidget::NoFocus);
00311
00312 mAtmListView = new AttachmentListView( this, mSplitter,
00313 "attachment list view" );
00314 mAtmListView->setSelectionMode( QListView::Extended );
00315 mAtmListView->addColumn( i18n("Name"), 200 );
00316 mAtmListView->addColumn( i18n("Size"), 80 );
00317 mAtmListView->addColumn( i18n("Encoding"), 120 );
00318 int atmColType = mAtmListView->addColumn( i18n("Type"), 120 );
00319
00320 mAtmListView->header()->setStretchEnabled( true, atmColType );
00321 mAtmEncryptColWidth = 80;
00322 mAtmSignColWidth = 80;
00323 mAtmCompressColWidth = 100;
00324 mAtmColCompress = mAtmListView->addColumn( i18n("Compress"),
00325 mAtmCompressColWidth );
00326 mAtmColEncrypt = mAtmListView->addColumn( i18n("Encrypt"),
00327 mAtmEncryptColWidth );
00328 mAtmColSign = mAtmListView->addColumn( i18n("Sign"),
00329 mAtmSignColWidth );
00330 mAtmListView->setColumnWidth( mAtmColEncrypt, 0 );
00331 mAtmListView->setColumnWidth( mAtmColSign, 0 );
00332 mAtmListView->setAllColumnsShowFocus( true );
00333
00334 connect( mAtmListView,
00335 SIGNAL( doubleClicked( QListViewItem* ) ),
00336 SLOT( slotAttachProperties() ) );
00337 connect( mAtmListView,
00338 SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ),
00339 SLOT( slotAttachPopupMenu( QListViewItem*, const QPoint&, int ) ) );
00340 connect( mAtmListView,
00341 SIGNAL( selectionChanged() ),
00342 SLOT( slotUpdateAttachActions() ) );
00343 connect( mAtmListView,
00344 SIGNAL( attachmentDeleted() ),
00345 SLOT( slotAttachRemove() ) );
00346 mAttachMenu = 0;
00347
00348 readConfig();
00349 setupStatusBar();
00350 setupActions();
00351 setupEditor();
00352
00353 applyMainWindowSettings(KMKernel::config(), "Composer");
00354
00355 connect( mEdtSubject, SIGNAL( subjectTextSpellChecked() ),
00356 SLOT( slotSubjectTextSpellChecked() ) );
00357 connect(mEdtSubject,SIGNAL(textChanged(const QString&)),
00358 SLOT(slotUpdWinTitle(const QString&)));
00359 connect(mIdentity,SIGNAL(identityChanged(uint)),
00360 SLOT(slotIdentityChanged(uint)));
00361 connect( kmkernel->identityManager(), SIGNAL(changed(uint)),
00362 SLOT(slotIdentityChanged(uint)));
00363
00364 connect(mEdtFrom,SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
00365 SLOT(slotCompletionModeChanged(KGlobalSettings::Completion)));
00366 connect(kmkernel->folderMgr(),SIGNAL(folderRemoved(KMFolder*)),
00367 SLOT(slotFolderRemoved(KMFolder*)));
00368 connect(kmkernel->imapFolderMgr(),SIGNAL(folderRemoved(KMFolder*)),
00369 SLOT(slotFolderRemoved(KMFolder*)));
00370 connect(kmkernel->dimapFolderMgr(),SIGNAL(folderRemoved(KMFolder*)),
00371 SLOT(slotFolderRemoved(KMFolder*)));
00372 connect( kmkernel, SIGNAL( configChanged() ),
00373 this, SLOT( slotConfigChanged() ) );
00374
00375 connect (mEditor, SIGNAL (spellcheck_done(int)),
00376 this, SLOT (slotSpellcheckDone (int)));
00377 connect (mEditor, SIGNAL( pasteImage() ),
00378 this, SLOT (slotPaste() ) );
00379 connect (mEditor, SIGNAL( focusChanged(bool) ),
00380 this, SLOT (editorFocusChanged(bool)) );
00381
00382 mMainWidget->resize(480,510);
00383 setCentralWidget(mMainWidget);
00384 rethinkFields();
00385
00386 if ( !mClassicalRecipients ) {
00387
00388
00389 rethinkFields();
00390 }
00391
00392 if ( GlobalSettings::self()->useExternalEditor() ) {
00393 mEditor->setUseExternalEditor(true);
00394 mEditor->setExternalEditorPath( GlobalSettings::self()->externalEditor() );
00395 }
00396
00397 initAutoSave();
00398
00399 mMsg = 0;
00400 if (aMsg)
00401 setMsg(aMsg);
00402
00403 mDone = true;
00404 }
00405
00406
00407 KMComposeWin::~KMComposeWin()
00408 {
00409 writeConfig();
00410 if (mFolder && mMsg)
00411 {
00412 mAutoDeleteMsg = FALSE;
00413 mFolder->addMsg(mMsg);
00414
00415 mFolder->unGetMsg( mFolder->count() - 1 );
00416 }
00417 if (mAutoDeleteMsg) {
00418 delete mMsg;
00419 mMsg = 0;
00420 }
00421 QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.begin();
00422 while ( it != mMapAtmLoadData.end() )
00423 {
00424 KIO::Job *job = it.key();
00425 mMapAtmLoadData.remove( it );
00426 job->kill();
00427 it = mMapAtmLoadData.begin();
00428 }
00429 deleteAll( mComposedMessages );
00430 }
00431
00432 void KMComposeWin::setAutoDeleteWindow( bool f )
00433 {
00434 if ( f )
00435 setWFlags( getWFlags() | WDestructiveClose );
00436 else
00437 setWFlags( getWFlags() & ~WDestructiveClose );
00438 }
00439
00440
00441 void KMComposeWin::send(int how)
00442 {
00443 switch (how) {
00444 case 1:
00445 slotSendNow();
00446 break;
00447 default:
00448 case 0:
00449
00450 case 2:
00451 slotSendLater();
00452 break;
00453 }
00454 }
00455
00456
00457 void KMComposeWin::addAttachment(KURL url,QString )
00458 {
00459 addAttach(url);
00460 }
00461
00462
00463 void KMComposeWin::addAttachment(const QString &name,
00464 const QCString &,
00465 const QByteArray &data,
00466 const QCString &type,
00467 const QCString &subType,
00468 const QCString ¶mAttr,
00469 const QString ¶mValue,
00470 const QCString &contDisp)
00471 {
00472 if (!data.isEmpty()) {
00473 KMMessagePart *msgPart = new KMMessagePart;
00474 msgPart->setName(name);
00475 QValueList<int> dummy;
00476 msgPart->setBodyAndGuessCte(data, dummy,
00477 kmkernel->msgSender()->sendQuotedPrintable());
00478 msgPart->setTypeStr(type);
00479 msgPart->setSubtypeStr(subType);
00480 msgPart->setParameter(paramAttr,paramValue);
00481 msgPart->setContentDisposition(contDisp);
00482 addAttach(msgPart);
00483 }
00484 }
00485
00486 void KMComposeWin::addImageFromClipboard()
00487 {
00488 bool ok;
00489 QFile *tmpFile;
00490
00491 QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this );
00492 if ( !ok )
00493 return;
00494
00495 mTempDir = new KTempDir();
00496 mTempDir->setAutoDelete( true );
00497
00498 if ( attName.lower().endsWith(".png") )
00499 tmpFile = new QFile(mTempDir->name() + attName );
00500 else
00501 tmpFile = new QFile(mTempDir->name() + attName + ".png" );
00502
00503 if ( !QApplication::clipboard()->image().save( tmpFile->name(), "PNG" ) ) {
00504 KMessageBox::error( this, i18n("Unknown error trying to save image."), i18n("Attaching Image Failed") );
00505 delete mTempDir;
00506 mTempDir = 0;
00507 return;
00508 }
00509
00510 addAttach( tmpFile->name() );
00511 }
00512
00513 void KMComposeWin::setBody(QString body)
00514 {
00515 mEditor->setText(body);
00516 }
00517
00518
00519 bool KMComposeWin::event(QEvent *e)
00520 {
00521 if (e->type() == QEvent::ApplicationPaletteChange)
00522 {
00523 readColorConfig();
00524 }
00525 return KMail::Composer::event(e);
00526 }
00527
00528
00529
00530 void KMComposeWin::readColorConfig(void)
00531 {
00532 if ( GlobalSettings::self()->useDefaultColors() ) {
00533 mForeColor = QColor(kapp->palette().active().text());
00534 mBackColor = QColor(kapp->palette().active().base());
00535 } else {
00536 mForeColor = GlobalSettings::self()->foregroundColor();
00537 mBackColor = GlobalSettings::self()->backgroundColor();
00538 }
00539
00540
00541 mPalette = kapp->palette();
00542 QColorGroup cgrp = mPalette.active();
00543 cgrp.setColor( QColorGroup::Base, mBackColor);
00544 cgrp.setColor( QColorGroup::Text, mForeColor);
00545 mPalette.setDisabled(cgrp);
00546 mPalette.setActive(cgrp);
00547 mPalette.setInactive(cgrp);
00548
00549 mEdtFrom->setPalette(mPalette);
00550 mEdtReplyTo->setPalette(mPalette);
00551 if ( mClassicalRecipients ) {
00552 mEdtTo->setPalette(mPalette);
00553 mEdtCc->setPalette(mPalette);
00554 mEdtBcc->setPalette(mPalette);
00555 }
00556 mEdtSubject->setPalette(mPalette);
00557 mTransport->setPalette(mPalette);
00558 mEditor->setPalette(mPalette);
00559 mFcc->setPalette(mPalette);
00560 }
00561
00562
00563 void KMComposeWin::readConfig(void)
00564 {
00565 mDefCharset = KMMessage::defaultCharset();
00566 mBtnIdentity->setChecked( GlobalSettings::self()->stickyIdentity() );
00567 if (mBtnIdentity->isChecked()) {
00568 mId = (GlobalSettings::self()->previousIdentity()!=0) ?
00569 GlobalSettings::self()->previousIdentity() : mId;
00570 }
00571 mBtnFcc->setChecked( GlobalSettings::self()->stickyFcc() );
00572 mBtnTransport->setChecked( GlobalSettings::self()->stickyTransport() );
00573 QStringList transportHistory = GlobalSettings::self()->transportHistory();
00574 QString currentTransport = GlobalSettings::self()->currentTransport();
00575
00576 mEdtFrom->setCompletionMode( (KGlobalSettings::Completion)GlobalSettings::self()->completionMode() );
00577 mEdtReplyTo->setCompletionMode( (KGlobalSettings::Completion)GlobalSettings::self()->completionMode() );
00578 if ( mClassicalRecipients ) {
00579 mEdtTo->setCompletionMode( (KGlobalSettings::Completion)GlobalSettings::self()->completionMode() );
00580 mEdtCc->setCompletionMode( (KGlobalSettings::Completion)GlobalSettings::self()->completionMode() );
00581 mEdtBcc->setCompletionMode( (KGlobalSettings::Completion)GlobalSettings::self()->completionMode() );
00582 }
00583
00584 readColorConfig();
00585
00586 if ( GlobalSettings::self()->useDefaultFonts() ) {
00587 mBodyFont = KGlobalSettings::generalFont();
00588 mFixedFont = KGlobalSettings::fixedFont();
00589 } else {
00590 mBodyFont = GlobalSettings::self()->composerFont();
00591 mFixedFont = GlobalSettings::self()->fixedFont();
00592 }
00593
00594 slotUpdateFont();
00595 mEdtFrom->setFont(mBodyFont);
00596 mEdtReplyTo->setFont(mBodyFont);
00597 if ( mClassicalRecipients ) {
00598 mEdtTo->setFont(mBodyFont);
00599 mEdtCc->setFont(mBodyFont);
00600 mEdtBcc->setFont(mBodyFont);
00601 }
00602 mEdtSubject->setFont(mBodyFont);
00603
00604 QSize siz = GlobalSettings::self()->composerSize();
00605 if (siz.width() < 200) siz.setWidth(200);
00606 if (siz.height() < 200) siz.setHeight(200);
00607 resize(siz);
00608
00609 mIdentity->setCurrentIdentity( mId );
00610
00611 kdDebug(5006) << "KMComposeWin::readConfig. " << mIdentity->currentIdentityName() << endl;
00612 const KPIM::Identity & ident =
00613 kmkernel->identityManager()->identityForUoid( mIdentity->currentIdentity() );
00614
00615 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
00616
00617 mTransport->clear();
00618 mTransport->insertStringList( KMTransportInfo::availableTransports() );
00619 while ( transportHistory.count() > (uint)GlobalSettings::self()->maxTransportEntries() )
00620 transportHistory.remove( transportHistory.last() );
00621 mTransport->insertStringList( transportHistory );
00622 if (mBtnTransport->isChecked() && !currentTransport.isEmpty())
00623 {
00624 for (int i = 0; i < mTransport->count(); i++)
00625 if (mTransport->text(i) == currentTransport)
00626 mTransport->setCurrentItem(i);
00627 mTransport->setEditText( currentTransport );
00628 }
00629
00630 if ( !mBtnTransport->isChecked() ) {
00631 mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() );
00632 }
00633
00634 QString fccName = "";
00635 if ( mBtnFcc->isChecked() ) {
00636 fccName = GlobalSettings::self()->previousFcc();
00637 } else if ( !ident.fcc().isEmpty() ) {
00638 fccName = ident.fcc();
00639 }
00640
00641 setFcc( fccName );
00642 }
00643
00644
00645 void KMComposeWin::writeConfig(void)
00646 {
00647 GlobalSettings::self()->setHeaders( mShowHeaders );
00648 GlobalSettings::self()->setStickyTransport( mBtnTransport->isChecked() );
00649 GlobalSettings::self()->setStickyIdentity( mBtnIdentity->isChecked() );
00650 GlobalSettings::self()->setStickyFcc( mBtnFcc->isChecked() );
00651 GlobalSettings::self()->setPreviousIdentity( mIdentity->currentIdentity() );
00652 GlobalSettings::self()->setCurrentTransport( mTransport->currentText() );
00653 GlobalSettings::self()->setPreviousFcc( mFcc->getFolder()->idString() );
00654 GlobalSettings::self()->setAutoSpellChecking(
00655 mAutoSpellCheckingAction->isChecked() );
00656 QStringList transportHistory = GlobalSettings::self()->transportHistory();
00657 transportHistory.remove(mTransport->currentText());
00658 if (KMTransportInfo::availableTransports().findIndex(mTransport
00659 ->currentText()) == -1) {
00660 transportHistory.prepend(mTransport->currentText());
00661 }
00662 GlobalSettings::self()->setTransportHistory( transportHistory );
00663 GlobalSettings::self()->setUseFixedFont( mFixedFontAction->isChecked() );
00664 GlobalSettings::self()->setUseHtmlMarkup( mHtmlMarkup );
00665 GlobalSettings::self()->setComposerSize( size() );
00666
00667 KConfigGroupSaver saver( KMKernel::config(), "Geometry" );
00668 saveMainWindowSettings( KMKernel::config(), "Composer" );
00669 }
00670
00671
00672 void KMComposeWin::autoSaveMessage()
00673 {
00674 kdDebug(5006) << k_funcinfo << endl;
00675 if ( !mMsg || mComposer || mAutoSaveFilename.isEmpty() )
00676 return;
00677 kdDebug(5006) << k_funcinfo << "autosaving message" << endl;
00678
00679 if ( mAutoSaveTimer )
00680 mAutoSaveTimer->stop();
00681 connect( this, SIGNAL( applyChangesDone( bool ) ),
00682 this, SLOT( slotContinueAutoSave( bool ) ) );
00683
00684
00685
00686 applyChanges( true, true );
00687
00688
00689 qApp->enter_loop();
00690
00691
00692 if ( mComposedMessages.isEmpty() ) {
00693 kdDebug(5006) << "Composing the message failed." << endl;
00694 return;
00695 }
00696 KMMessage *msg = mComposedMessages.first();
00697
00698 kdDebug(5006) << k_funcinfo << "opening autoSaveFile " << mAutoSaveFilename
00699 << endl;
00700 const QString filename =
00701 KMKernel::localDataPath() + "autosave/cur/" + mAutoSaveFilename;
00702 KSaveFile autoSaveFile( filename, 0600 );
00703 int status = autoSaveFile.status();
00704 kdDebug(5006) << k_funcinfo << "autoSaveFile.status() = " << status << endl;
00705 if ( status == 0 ) {
00706 kdDebug(5006) << "autosaving message in " << filename << endl;
00707 int fd = autoSaveFile.handle();
00708 QCString msgStr = msg->asString();
00709 if ( ::write( fd, msgStr, msgStr.length() ) == -1 )
00710 status = errno;
00711 }
00712 if ( status == 0 ) {
00713 kdDebug(5006) << k_funcinfo << "closing autoSaveFile" << endl;
00714 autoSaveFile.close();
00715 mLastAutoSaveErrno = 0;
00716 }
00717 else {
00718 kdDebug(5006) << k_funcinfo << "autosaving failed" << endl;
00719 autoSaveFile.abort();
00720 if ( status != mLastAutoSaveErrno ) {
00721
00722 KMessageBox::queuedMessageBox( 0, KMessageBox::Sorry,
00723 i18n("Autosaving the message as %1 "
00724 "failed.\n"
00725 "Reason: %2" )
00726 .arg( filename, strerror( status ) ),
00727 i18n("Autosaving Failed") );
00728 mLastAutoSaveErrno = status;
00729 }
00730 }
00731
00732 if ( autoSaveInterval() > 0 )
00733 mAutoSaveTimer->start( autoSaveInterval() );
00734 }
00735
00736 void KMComposeWin::slotContinueAutoSave( bool )
00737 {
00738 disconnect( this, SIGNAL( applyChangesDone( bool ) ),
00739 this, SLOT( slotContinueAutoSave( bool ) ) );
00740 qApp->exit_loop();
00741 }
00742
00743
00744 void KMComposeWin::slotView(void)
00745 {
00746 if (!mDone)
00747 return;
00748
00749 int id;
00750
00751
00752
00753 if (!sender()->isA("KToggleAction"))
00754 return;
00755 KToggleAction *act = (KToggleAction *) sender();
00756
00757 if (act == mAllFieldsAction)
00758 id = 0;
00759 else if (act == mIdentityAction)
00760 id = HDR_IDENTITY;
00761 else if (act == mTransportAction)
00762 id = HDR_TRANSPORT;
00763 else if (act == mFromAction)
00764 id = HDR_FROM;
00765 else if (act == mReplyToAction)
00766 id = HDR_REPLY_TO;
00767 else if (act == mToAction)
00768 id = HDR_TO;
00769 else if (act == mCcAction)
00770 id = HDR_CC;
00771 else if (act == mBccAction)
00772 id = HDR_BCC;
00773 else if (act == mSubjectAction)
00774 id = HDR_SUBJECT;
00775 else if (act == mFccAction)
00776 id = HDR_FCC;
00777 else if ( act == mDictionaryAction )
00778 id = HDR_DICTIONARY;
00779 else
00780 {
00781 id = 0;
00782 kdDebug(5006) << "Something is wrong (Oh, yeah?)" << endl;
00783 return;
00784 }
00785
00786
00787
00788
00789 if (!act->isChecked())
00790 {
00791
00792 if (id > 0) mShowHeaders = mShowHeaders & ~id;
00793 else mShowHeaders = abs(mShowHeaders);
00794 }
00795 else
00796 {
00797
00798 if (id > 0) mShowHeaders |= id;
00799 else mShowHeaders = -abs(mShowHeaders);
00800 }
00801 rethinkFields(true);
00802 }
00803
00804 int KMComposeWin::calcColumnWidth(int which, long allShowing, int width)
00805 {
00806 if ( (allShowing & which) == 0 )
00807 return width;
00808
00809 QLabel *w;
00810 if ( which == HDR_IDENTITY )
00811 w = mLblIdentity;
00812 else if ( which == HDR_DICTIONARY )
00813 w = mDictionaryLabel;
00814 else if ( which == HDR_FCC )
00815 w = mLblFcc;
00816 else if ( which == HDR_TRANSPORT )
00817 w = mLblTransport;
00818 else if ( which == HDR_FROM )
00819 w = mLblFrom;
00820 else if ( which == HDR_REPLY_TO )
00821 w = mLblReplyTo;
00822 else if ( which == HDR_SUBJECT )
00823 w = mLblSubject;
00824 else
00825 return width;
00826
00827 w->setBuddy( mEditor );
00828 w->adjustSize();
00829 w->show();
00830 return QMAX( width, w->sizeHint().width() );
00831 }
00832
00833 void KMComposeWin::rethinkFields(bool fromSlot)
00834 {
00835
00836 int mask, row, numRows;
00837 long showHeaders;
00838
00839 if (mShowHeaders < 0)
00840 showHeaders = HDR_ALL;
00841 else
00842 showHeaders = mShowHeaders;
00843
00844 for (mask=1,mNumHeaders=0; mask<=showHeaders; mask<<=1)
00845 if ((showHeaders&mask) != 0) mNumHeaders++;
00846
00847 numRows = mNumHeaders + 1;
00848
00849 delete mGrid;
00850 mGrid = new QGridLayout(mMainWidget, numRows, 3, KDialogBase::marginHint()/2, KDialogBase::spacingHint());
00851 mGrid->setColStretch(0, 1);
00852 mGrid->setColStretch(1, 100);
00853 mGrid->setColStretch(2, 1);
00854 mGrid->setRowStretch(mNumHeaders, 100);
00855
00856 row = 0;
00857 kdDebug(5006) << "KMComposeWin::rethinkFields" << endl;
00858 if (mRecipientsEditor)
00859 mLabelWidth = mRecipientsEditor->setFirstColumnWidth( 0 );
00860 mLabelWidth = calcColumnWidth( HDR_IDENTITY, showHeaders, mLabelWidth );
00861 mLabelWidth = calcColumnWidth( HDR_DICTIONARY, showHeaders, mLabelWidth );
00862 mLabelWidth = calcColumnWidth( HDR_FCC, showHeaders, mLabelWidth );
00863 mLabelWidth = calcColumnWidth( HDR_TRANSPORT, showHeaders, mLabelWidth );
00864 mLabelWidth = calcColumnWidth( HDR_FROM, showHeaders, mLabelWidth );
00865 mLabelWidth = calcColumnWidth( HDR_REPLY_TO, showHeaders, mLabelWidth );
00866 mLabelWidth = calcColumnWidth( HDR_SUBJECT, showHeaders, mLabelWidth );
00867
00868 if (!fromSlot) mAllFieldsAction->setChecked(showHeaders==HDR_ALL);
00869
00870 if (!fromSlot) mIdentityAction->setChecked(abs(mShowHeaders)&HDR_IDENTITY);
00871 rethinkHeaderLine(showHeaders,HDR_IDENTITY, row, i18n("&Identity:"),
00872 mLblIdentity, mIdentity, mBtnIdentity);
00873
00874 if (!fromSlot) mDictionaryAction->setChecked(abs(mShowHeaders)&HDR_DICTIONARY);
00875 rethinkHeaderLine(showHeaders,HDR_DICTIONARY, row, i18n("&Dictionary:"),
00876 mDictionaryLabel, mDictionaryCombo, 0 );
00877
00878 if (!fromSlot) mFccAction->setChecked(abs(mShowHeaders)&HDR_FCC);
00879 rethinkHeaderLine(showHeaders,HDR_FCC, row, i18n("&Sent-Mail folder:"),
00880 mLblFcc, mFcc, mBtnFcc);
00881
00882 if (!fromSlot) mTransportAction->setChecked(abs(mShowHeaders)&HDR_TRANSPORT);
00883 rethinkHeaderLine(showHeaders,HDR_TRANSPORT, row, i18n("&Mail transport:"),
00884 mLblTransport, mTransport, mBtnTransport);
00885
00886 if (!fromSlot) mFromAction->setChecked(abs(mShowHeaders)&HDR_FROM);
00887 rethinkHeaderLine(showHeaders,HDR_FROM, row, i18n("sender address field", "&From:"),
00888 mLblFrom, mEdtFrom );
00889
00890 QWidget *prevFocus = mEdtFrom;
00891
00892 if (!fromSlot) mReplyToAction->setChecked(abs(mShowHeaders)&HDR_REPLY_TO);
00893 rethinkHeaderLine(showHeaders,HDR_REPLY_TO,row,i18n("&Reply to:"),
00894 mLblReplyTo, mEdtReplyTo, mBtnReplyTo);
00895 if ( showHeaders & HDR_REPLY_TO ) {
00896 prevFocus = connectFocusMoving( prevFocus, mEdtReplyTo );
00897 }
00898
00899 if ( mClassicalRecipients ) {
00900 if (!fromSlot) mToAction->setChecked(abs(mShowHeaders)&HDR_TO);
00901 rethinkHeaderLine(showHeaders, HDR_TO, row, i18n("recipient address field", "&To:"),
00902 mLblTo, mEdtTo, mBtnTo,
00903 i18n("Primary Recipients"),
00904 i18n("<qt>The email addresses you put "
00905 "in this field receive a copy of the email.</qt>"));
00906 if ( showHeaders & HDR_TO ) {
00907 prevFocus = connectFocusMoving( prevFocus, mEdtTo );
00908 }
00909
00910 if (!fromSlot) mCcAction->setChecked(abs(mShowHeaders)&HDR_CC);
00911 rethinkHeaderLine(showHeaders, HDR_CC, row, i18n("&Copy to (CC):"),
00912 mLblCc, mEdtCc, mBtnCc,
00913 i18n("Additional Recipients"),
00914 i18n("<qt>The email addresses you put "
00915 "in this field receive a copy of the email. "
00916 "Technically it is the same thing as putting all the "
00917 "addresses in the <b>To:</b> field but differs in "
00918 "that it usually symbolises the receiver of the "
00919 "Carbon Copy (CC) is a listener, not the main "
00920 "recipient.</qt>"));
00921 if ( showHeaders & HDR_CC ) {
00922 prevFocus = connectFocusMoving( prevFocus, mEdtCc );
00923 }
00924
00925 if (!fromSlot) mBccAction->setChecked(abs(mShowHeaders)&HDR_BCC);
00926 rethinkHeaderLine(showHeaders,HDR_BCC, row, i18n("&Blind copy to (BCC):"),
00927 mLblBcc, mEdtBcc, mBtnBcc,
00928 i18n("Hidden Recipients"),
00929 i18n("<qt>Essentially the same thing "
00930 "as the <b>Copy To:</b> field but differs in that "
00931 "all other recipients do not see who receives a "
00932 "blind copy.</qt>"));
00933 if ( showHeaders & HDR_BCC ) {
00934 prevFocus = connectFocusMoving( prevFocus, mEdtBcc );
00935 }
00936 } else {
00937 mGrid->addMultiCellWidget( mRecipientsEditor, row, row, 0, 2 );
00938 ++row;
00939
00940 if ( showHeaders & HDR_REPLY_TO ) {
00941 connect( mEdtReplyTo, SIGNAL( focusDown() ), mRecipientsEditor,
00942 SLOT( setFocusTop() ) );
00943 } else {
00944 connect( mEdtFrom, SIGNAL( focusDown() ), mRecipientsEditor,
00945 SLOT( setFocusTop() ) );
00946 }
00947 if ( showHeaders & HDR_REPLY_TO ) {
00948 connect( mRecipientsEditor, SIGNAL( focusUp() ), mEdtReplyTo, SLOT( setFocus() ) );
00949 } else {
00950 connect( mRecipientsEditor, SIGNAL( focusUp() ), mEdtFrom, SLOT( setFocus() ) );
00951 }
00952
00953 connect( mRecipientsEditor, SIGNAL( focusDown() ), mEdtSubject,
00954 SLOT( setFocus() ) );
00955 connect( mEdtSubject, SIGNAL( focusUp() ), mRecipientsEditor,
00956 SLOT( setFocusBottom() ) );
00957
00958 prevFocus = mRecipientsEditor;
00959 }
00960 if (!fromSlot) mSubjectAction->setChecked(abs(mShowHeaders)&HDR_SUBJECT);
00961 rethinkHeaderLine(showHeaders,HDR_SUBJECT, row, i18n("S&ubject:"),
00962 mLblSubject, mEdtSubject);
00963 connectFocusMoving( mEdtSubject, mEditor );
00964
00965 assert(row<=mNumHeaders);
00966
00967 mGrid->addMultiCellWidget(mSplitter, row, mNumHeaders, 0, 2);
00968
00969 if( !mAtmList.isEmpty() )
00970 mAtmListView->show();
00971 else
00972 mAtmListView->hide();
00973 resize(this->size());
00974 repaint();
00975
00976 mGrid->activate();
00977
00978 slotUpdateAttachActions();
00979 mIdentityAction->setEnabled(!mAllFieldsAction->isChecked());
00980 mDictionaryAction->setEnabled( !mAllFieldsAction->isChecked() );
00981 mTransportAction->setEnabled(!mAllFieldsAction->isChecked());
00982 mFromAction->setEnabled(!mAllFieldsAction->isChecked());
00983 if ( mReplyToAction ) mReplyToAction->setEnabled(!mAllFieldsAction->isChecked());
00984 if ( mToAction ) mToAction->setEnabled(!mAllFieldsAction->isChecked());
00985 if ( mCcAction ) mCcAction->setEnabled(!mAllFieldsAction->isChecked());
00986 if ( mBccAction ) mBccAction->setEnabled(!mAllFieldsAction->isChecked());
00987 mFccAction->setEnabled(!mAllFieldsAction->isChecked());
00988 mSubjectAction->setEnabled(!mAllFieldsAction->isChecked());
00989 if (mRecipientsEditor)
00990 mRecipientsEditor->setFirstColumnWidth( mLabelWidth );
00991 }
00992
00993 QWidget *KMComposeWin::connectFocusMoving( QWidget *prev, QWidget *next )
00994 {
00995 connect( prev, SIGNAL( focusDown() ), next, SLOT( setFocus() ) );
00996 connect( next, SIGNAL( focusUp() ), prev, SLOT( setFocus() ) );
00997
00998 return next;
00999 }
01000
01001
01002 void KMComposeWin::rethinkHeaderLine(int aValue, int aMask, int& aRow,
01003 const QString &aLabelStr, QLabel* aLbl,
01004 QLineEdit* aEdt, QPushButton* aBtn,
01005 const QString &toolTip, const QString &whatsThis )
01006 {
01007 if (aValue & aMask)
01008 {
01009 aLbl->setText(aLabelStr);
01010 if ( !toolTip.isEmpty() )
01011 QToolTip::add( aLbl, toolTip );
01012 if ( !whatsThis.isEmpty() )
01013 QWhatsThis::add( aLbl, whatsThis );
01014 aLbl->setFixedWidth( mLabelWidth );
01015 aLbl->setBuddy(aEdt);
01016 mGrid->addWidget(aLbl, aRow, 0);
01017 aEdt->setBackgroundColor( mBackColor );
01018 aEdt->show();
01019
01020 if (aBtn) {
01021 mGrid->addWidget(aEdt, aRow, 1);
01022
01023 mGrid->addWidget(aBtn, aRow, 2);
01024 aBtn->show();
01025 } else {
01026 mGrid->addMultiCellWidget(aEdt, aRow, aRow, 1, 2 );
01027 }
01028 aRow++;
01029 }
01030 else
01031 {
01032 aLbl->hide();
01033 aEdt->hide();
01034 if (aBtn) aBtn->hide();
01035 }
01036 }
01037
01038
01039 void KMComposeWin::rethinkHeaderLine(int aValue, int aMask, int& aRow,
01040 const QString &aLabelStr, QLabel* aLbl,
01041 QComboBox* aCbx, QCheckBox* aChk)
01042 {
01043 if (aValue & aMask)
01044 {
01045 aLbl->setText(aLabelStr);
01046 aLbl->adjustSize();
01047 aLbl->resize((int)aLbl->sizeHint().width(),aLbl->sizeHint().height() + 6);
01048 aLbl->setMinimumSize(aLbl->size());
01049 aLbl->show();
01050 aLbl->setBuddy(aCbx);
01051 mGrid->addWidget(aLbl, aRow, 0);
01052 aCbx->show();
01053 aCbx->setMinimumSize(100, aLbl->height()+2);
01054
01055 mGrid->addWidget(aCbx, aRow, 1);
01056 if ( aChk ) {
01057 mGrid->addWidget(aChk, aRow, 2);
01058 aChk->setFixedSize(aChk->sizeHint().width(), aLbl->height());
01059 aChk->show();
01060 }
01061 aRow++;
01062 }
01063 else
01064 {
01065 aLbl->hide();
01066 aCbx->hide();
01067 if ( aChk )
01068 aChk->hide();
01069 }
01070 }
01071
01072
01073 void KMComposeWin::getTransportMenu()
01074 {
01075 QStringList availTransports;
01076
01077 mActNowMenu->clear();
01078 mActLaterMenu->clear();
01079 availTransports = KMail::TransportManager::transportNames();
01080 QStringList::Iterator it;
01081 int id = 0;
01082 for(it = availTransports.begin(); it != availTransports.end() ; ++it, id++)
01083 {
01084 mActNowMenu->insertItem((*it).replace("&", "&&"), id);
01085 mActLaterMenu->insertItem((*it).replace("&", "&&"), id);
01086 }
01087 }
01088
01089
01090
01091 void KMComposeWin::setupActions(void)
01092 {
01093 KActionMenu *actActionNowMenu, *actActionLaterMenu;
01094
01095 if (kmkernel->msgSender()->sendImmediate())
01096 {
01097
01098 ( void ) new KAction( i18n("&Send Mail"), "mail_send", CTRL+Key_Return,
01099 this, SLOT(slotSendNow()), actionCollection(),"send_default");
01100
01101
01102 actActionNowMenu = new KActionMenu (i18n("&Send Mail Via"), "mail_send",
01103 actionCollection(), "send_default_via" );
01104
01105 (void) new KAction (i18n("Send &Later"), "queue", 0, this,
01106 SLOT(slotSendLater()), actionCollection(),"send_alternative");
01107 actActionLaterMenu = new KActionMenu (i18n("Send &Later Via"), "queue",
01108 actionCollection(), "send_alternative_via" );
01109
01110 }
01111 else
01112 {
01113
01114 (void) new KAction (i18n("Send &Later"), "queue",
01115 CTRL+Key_Return,
01116 this, SLOT(slotSendLater()), actionCollection(),"send_default");
01117 actActionLaterMenu = new KActionMenu (i18n("Send &Later Via"), "queue",
01118 actionCollection(), "send_default_via" );
01119
01120 ( void ) new KAction( i18n("&Send Mail"), "mail_send", 0,
01121 this, SLOT(slotSendNow()), actionCollection(),"send_alternative");
01122
01123
01124 actActionNowMenu = new KActionMenu (i18n("&Send Mail Via"), "mail_send",
01125 actionCollection(), "send_alternative_via" );
01126
01127 }
01128
01129
01130 actActionNowMenu->setDelayed(true);
01131 actActionLaterMenu->setDelayed(true);
01132
01133 connect( actActionNowMenu, SIGNAL( activated() ), this,
01134 SLOT( slotSendNow() ) );
01135 connect( actActionLaterMenu, SIGNAL( activated() ), this,
01136 SLOT( slotSendLater() ) );
01137
01138
01139 mActNowMenu = actActionNowMenu->popupMenu();
01140 mActLaterMenu = actActionLaterMenu->popupMenu();
01141
01142 connect( mActNowMenu, SIGNAL( activated( int ) ), this,
01143 SLOT( slotSendNowVia( int ) ) );
01144 connect( mActNowMenu, SIGNAL( aboutToShow() ), this,
01145 SLOT( getTransportMenu() ) );
01146
01147 connect( mActLaterMenu, SIGNAL( activated( int ) ), this,
01148 SLOT( slotSendLaterVia( int ) ) );
01149 connect( mActLaterMenu, SIGNAL( aboutToShow() ), this,
01150 SLOT( getTransportMenu() ) );
01151
01152
01153
01154
01155 (void) new KAction (i18n("Save in &Drafts Folder"), "filesave", 0,
01156 this, SLOT(slotSaveDraft()),
01157 actionCollection(), "save_in_drafts");
01158 (void) new KAction (i18n("&Insert File..."), "fileopen", 0,
01159 this, SLOT(slotInsertFile()),
01160 actionCollection(), "insert_file");
01161 mRecentAction = new KRecentFilesAction (i18n("&Insert File Recent"),
01162 "fileopen", 0,
01163 this, SLOT(slotInsertRecentFile(const KURL&)),
01164 actionCollection(), "insert_file_recent");
01165
01166 mRecentAction->loadEntries( KMKernel::config() );
01167
01168 (void) new KAction (i18n("&Address Book"), "contents",0,
01169 this, SLOT(slotAddrBook()),
01170 actionCollection(), "addressbook");
01171 (void) new KAction (i18n("&New Composer"), "mail_new",
01172 KStdAccel::shortcut(KStdAccel::New),
01173 this, SLOT(slotNewComposer()),
01174 actionCollection(), "new_composer");
01175 (void) new KAction (i18n("New Main &Window"), "window_new", 0,
01176 this, SLOT(slotNewMailReader()),
01177 actionCollection(), "open_mailreader");
01178
01179 if ( !mClassicalRecipients ) {
01180 new KAction( i18n("Select &Recipients..."), CTRL + Key_L, mRecipientsEditor,
01181 SLOT( selectRecipients() ), actionCollection(), "select_recipients" );
01182 new KAction( i18n("Save &Distribution List..."), 0, mRecipientsEditor,
01183 SLOT( saveDistributionList() ), actionCollection(),
01184 "save_distribution_list" );
01185 }
01186
01187
01188 KStdAction::print (this, SLOT(slotPrint()), actionCollection());
01189 KStdAction::close (this, SLOT(slotClose()), actionCollection());
01190
01191 KStdAction::undo (this, SLOT(slotUndo()), actionCollection());
01192 KStdAction::redo (this, SLOT(slotRedo()), actionCollection());
01193 KStdAction::cut (this, SLOT(slotCut()), actionCollection());
01194 KStdAction::copy (this, SLOT(slotCopy()), actionCollection());
01195 KStdAction::pasteText (this, SLOT(slotPaste()), actionCollection());
01196 KStdAction::selectAll (this, SLOT(slotMarkAll()), actionCollection());
01197
01198 KStdAction::find (this, SLOT(slotFind()), actionCollection());
01199 KStdAction::findNext(this, SLOT(slotSearchAgain()), actionCollection());
01200
01201 KStdAction::replace (this, SLOT(slotReplace()), actionCollection());
01202 KStdAction::spelling (this, SLOT(slotSpellcheck()), actionCollection(), "spellcheck");
01203
01204 mPasteQuotation = new KAction (i18n("Pa&ste as Quotation"),0,this,SLOT( slotPasteAsQuotation()),
01205 actionCollection(), "paste_quoted");
01206
01207 (void) new KAction (i18n("Paste as Attac&hment"),0,this,SLOT( slotPasteAsAttachment()),
01208 actionCollection(), "paste_att");
01209
01210 mAddQuoteChars = new KAction(i18n("Add &Quote Characters"), 0, this,
01211 SLOT(slotAddQuotes()), actionCollection(), "tools_quote");
01212
01213 mRemQuoteChars = new KAction(i18n("Re&move Quote Characters"), 0, this,
01214 SLOT(slotRemoveQuotes()), actionCollection(), "tools_unquote");
01215
01216
01217 (void) new KAction (i18n("Cl&ean Spaces"), 0, this, SLOT(slotCleanSpace()),
01218 actionCollection(), "clean_spaces");
01219
01220 mFixedFontAction = new KToggleAction( i18n("Use Fi&xed Font"), 0, this,
01221 SLOT(slotUpdateFont()), actionCollection(), "toggle_fixedfont" );
01222 mFixedFontAction->setChecked( GlobalSettings::self()->useFixedFont() );
01223
01224
01225 mUrgentAction = new KToggleAction (i18n("&Urgent"), 0,
01226 actionCollection(),
01227 "urgent");
01228 mRequestMDNAction = new KToggleAction ( i18n("&Request Disposition Notification"), 0,
01229 actionCollection(),
01230 "options_request_mdn");
01231 mRequestMDNAction->setChecked(GlobalSettings::self()->requestMDN());
01232
01233 mEncodingAction = new KSelectAction( i18n( "Se&t Encoding" ), "charset",
01234 0, this, SLOT(slotSetCharset() ),
01235 actionCollection(), "charsets" );
01236 mWordWrapAction = new KToggleAction (i18n("&Wordwrap"), 0,
01237 actionCollection(), "wordwrap");
01238 mWordWrapAction->setChecked(GlobalSettings::self()->wordWrap());
01239 connect(mWordWrapAction, SIGNAL(toggled(bool)), SLOT(slotWordWrapToggled(bool)));
01240
01241 mAutoSpellCheckingAction =
01242 new KToggleAction( i18n( "&Automatic Spellchecking" ), "spellcheck", 0,
01243 actionCollection(), "options_auto_spellchecking" );
01244 const bool spellChecking = GlobalSettings::self()->autoSpellChecking();
01245 mAutoSpellCheckingAction->setEnabled( !GlobalSettings::self()->useExternalEditor() );
01246 mAutoSpellCheckingAction->setChecked( !GlobalSettings::self()->useExternalEditor() && spellChecking );
01247 slotAutoSpellCheckingToggled( !GlobalSettings::self()->useExternalEditor() && spellChecking );
01248 connect( mAutoSpellCheckingAction, SIGNAL( toggled( bool ) ),
01249 this, SLOT( slotAutoSpellCheckingToggled( bool ) ) );
01250
01251 QStringList encodings = KMMsgBase::supportedEncodings(TRUE);
01252 encodings.prepend( i18n("Auto-Detect"));
01253 mEncodingAction->setItems( encodings );
01254 mEncodingAction->setCurrentItem( -1 );
01255
01256
01257 markupAction = new KToggleAction (i18n("Formatting (HTML)"), 0, this,
01258 SLOT(slotToggleMarkup()),
01259 actionCollection(), "html");
01260
01261 mAllFieldsAction = new KToggleAction (i18n("&All Fields"), 0, this,
01262 SLOT(slotView()),
01263 actionCollection(), "show_all_fields");
01264 mIdentityAction = new KToggleAction (i18n("&Identity"), 0, this,
01265 SLOT(slotView()),
01266 actionCollection(), "show_identity");
01267 mDictionaryAction = new KToggleAction (i18n("&Dictionary"), 0, this,
01268 SLOT(slotView()),
01269 actionCollection(), "show_dictionary");
01270 mFccAction = new KToggleAction (i18n("&Sent-Mail Folder"), 0, this,
01271 SLOT(slotView()),
01272 actionCollection(), "show_fcc");
01273 mTransportAction = new KToggleAction (i18n("&Mail Transport"), 0, this,
01274 SLOT(slotView()),
01275 actionCollection(), "show_transport");
01276 mFromAction = new KToggleAction (i18n("&From"), 0, this,
01277 SLOT(slotView()),
01278 actionCollection(), "show_from");
01279 mReplyToAction = new KToggleAction (i18n("&Reply To"), 0, this,
01280 SLOT(slotView()),
01281 actionCollection(), "show_reply_to");
01282 if ( mClassicalRecipients ) {
01283 mToAction = new KToggleAction (i18n("&To"), 0, this,
01284 SLOT(slotView()),
01285 actionCollection(), "show_to");
01286 mCcAction = new KToggleAction (i18n("&CC"), 0, this,
01287 SLOT(slotView()),
01288 actionCollection(), "show_cc");
01289 mBccAction = new KToggleAction (i18n("&BCC"), 0, this,
01290 SLOT(slotView()),
01291 actionCollection(), "show_bcc");
01292 }
01293 mSubjectAction = new KToggleAction (i18n("S&ubject"), 0, this,
01294 SLOT(slotView()),
01295 actionCollection(), "show_subject");
01296
01297
01298 (void) new KAction (i18n("Append S&ignature"), 0, this,
01299 SLOT(slotAppendSignature()),
01300 actionCollection(), "append_signature");
01301 mAttachPK = new KAction (i18n("Attach &Public Key..."), 0, this,
01302 SLOT(slotInsertPublicKey()),
01303 actionCollection(), "attach_public_key");
01304 mAttachMPK = new KAction (i18n("Attach &My Public Key"), 0, this,
01305 SLOT(slotInsertMyPublicKey()),
01306 actionCollection(), "attach_my_public_key");
01307 (void) new KAction (i18n("&Attach File..."), "attach",
01308 0, this, SLOT(slotAttachFile()),
01309 actionCollection(), "attach");
01310 mAttachRemoveAction = new KAction (i18n("&Remove Attachment"), 0, this,
01311 SLOT(slotAttachRemove()),
01312 actionCollection(), "remove");
01313 mAttachSaveAction = new KAction (i18n("&Save Attachment As..."), "filesave",0,
01314 this, SLOT(slotAttachSave()),
01315 actionCollection(), "attach_save");
01316 mAttachPropertiesAction = new KAction (i18n("Attachment Pr&operties"), 0, this,
01317 SLOT(slotAttachProperties()),
01318 actionCollection(), "attach_properties");
01319
01320 setStandardToolBarMenuEnabled(true);
01321
01322 KStdAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
01323 KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
01324 KStdAction::preferences(kmkernel, SLOT(slotShowConfigurationDialog()), actionCollection());
01325
01326 (void) new KAction (i18n("&Spellchecker..."), 0, this, SLOT(slotSpellcheckConfig()),
01327 actionCollection(), "setup_spellchecker");
01328
01329 if ( Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" ) ) {
01330 KToggleAction * a = new KToggleAction( i18n( "Encrypt Message with Chiasmus..." ),
01331 "chidecrypted", 0, actionCollection(),
01332 "encrypt_message_chiasmus" );
01333 a->setCheckedState( KGuiItem( i18n( "Encrypt Message with Chiasmus..." ), "chiencrypted" ) );
01334 mEncryptChiasmusAction = a;
01335 connect( mEncryptChiasmusAction, SIGNAL(toggled(bool)),
01336 this, SLOT(slotEncryptChiasmusToggled(bool)) );
01337 } else {
01338 mEncryptChiasmusAction = 0;
01339 }
01340
01341 mEncryptAction = new KToggleAction (i18n("&Encrypt Message"),
01342 "decrypted", 0,
01343 actionCollection(), "encrypt_message");
01344 mSignAction = new KToggleAction (i18n("&Sign Message"),
01345 "signature", 0,
01346 actionCollection(), "sign_message");
01347
01348 const KPIM::Identity & ident =
01349 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
01350
01351
01352 mLastIdentityHasSigningKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
01353 mLastIdentityHasEncryptionKey = !ident.pgpEncryptionKey().isEmpty() || !ident.smimeEncryptionKey().isEmpty();
01354
01355 mLastEncryptActionState = false;
01356 mLastSignActionState = GlobalSettings::self()->pgpAutoSign();
01357
01358
01359 mAttachPK->setEnabled( Kleo::CryptoBackendFactory::instance()->openpgp() );
01360
01361
01362
01363 mAttachMPK->setEnabled( Kleo::CryptoBackendFactory::instance()->openpgp() &&
01364 !ident.pgpEncryptionKey().isEmpty() );
01365
01366 if ( !Kleo::CryptoBackendFactory::instance()->openpgp() && !Kleo::CryptoBackendFactory::instance()->smime() ) {
01367
01368 mEncryptAction->setEnabled( false );
01369 setEncryption( false );
01370 mSignAction->setEnabled( false );
01371 setSigning( false );
01372 } else {
01373 const bool canOpenPGPSign = Kleo::CryptoBackendFactory::instance()->openpgp()
01374 && !ident.pgpSigningKey().isEmpty();
01375 const bool canSMIMESign = Kleo::CryptoBackendFactory::instance()->smime()
01376 && !ident.smimeSigningKey().isEmpty();
01377
01378 setEncryption( false );
01379 setSigning( ( canOpenPGPSign || canSMIMESign ) && GlobalSettings::self()->pgpAutoSign() );
01380 }
01381
01382 connect(mEncryptAction, SIGNAL(toggled(bool)),
01383 SLOT(slotEncryptToggled( bool )));
01384 connect(mSignAction, SIGNAL(toggled(bool)),
01385 SLOT(slotSignToggled( bool )));
01386
01387 QStringList l;
01388 for ( int i = 0 ; i < numCryptoMessageFormats ; ++i )
01389 l.push_back( Kleo::cryptoMessageFormatToLabel( cryptoMessageFormats[i] ) );
01390
01391 mCryptoModuleAction = new KSelectAction( i18n( "&Cryptographic Message Format" ), 0,
01392 this, SLOT(slotSelectCryptoModule()),
01393 actionCollection(), "options_select_crypto" );
01394 mCryptoModuleAction->setItems( l );
01395 mCryptoModuleAction->setCurrentItem( format2cb( ident.preferredCryptoMessageFormat() ) );
01396 slotSelectCryptoModule( true );
01397
01398 QStringList styleItems;
01399 styleItems << i18n( "Standard" );
01400 styleItems << i18n( "Bulleted List (Disc)" );
01401 styleItems << i18n( "Bulleted List (Circle)" );
01402 styleItems << i18n( "Bulleted List (Square)" );
01403 styleItems << i18n( "Ordered List (Decimal)" );
01404 styleItems << i18n( "Ordered List (Alpha lower)" );
01405 styleItems << i18n( "Ordered List (Alpha upper)" );
01406
01407 listAction = new KSelectAction( i18n( "Select Style" ), 0, actionCollection(),
01408 "text_list" );
01409 listAction->setItems( styleItems );
01410 connect( listAction, SIGNAL( activated( const QString& ) ),
01411 SLOT( slotListAction( const QString& ) ) );
01412 fontAction = new KFontAction( "Select Font", 0, actionCollection(),
01413 "text_font" );
01414 connect( fontAction, SIGNAL( activated( const QString& ) ),
01415 SLOT( slotFontAction( const QString& ) ) );
01416 fontSizeAction = new KFontSizeAction( "Select Size", 0, actionCollection(),
01417 "text_size" );
01418 connect( fontSizeAction, SIGNAL( fontSizeChanged( int ) ),
01419 SLOT( slotSizeAction( int ) ) );
01420
01421 alignLeftAction = new KToggleAction (i18n("Align Left"), "text_left", 0,
01422 this, SLOT(slotAlignLeft()), actionCollection(),
01423 "align_left");
01424 alignLeftAction->setChecked( TRUE );
01425 alignRightAction = new KToggleAction (i18n("Align Right"), "text_right", 0,
01426 this, SLOT(slotAlignRight()), actionCollection(),
01427 "align_right");
01428 alignCenterAction = new KToggleAction (i18n("Align Center"), "text_center", 0,
01429 this, SLOT(slotAlignCenter()), actionCollection(),
01430 "align_center");
01431 textBoldAction = new KToggleAction( i18n("&Bold"), "text_bold", CTRL+Key_B,
01432 this, SLOT(slotTextBold()),
01433 actionCollection(), "text_bold");
01434 textItalicAction = new KToggleAction( i18n("&Italic"), "text_italic", CTRL+Key_I,
01435 this, SLOT(slotTextItalic()),
01436 actionCollection(), "text_italic");
01437 textUnderAction = new KToggleAction( i18n("&Underline"), "text_under", CTRL+Key_U,
01438 this, SLOT(slotTextUnder()),
01439 actionCollection(), "text_under");
01440 actionFormatReset = new KAction( i18n( "Reset Font Settings" ), "eraser", 0,
01441 this, SLOT( slotFormatReset() ),
01442 actionCollection(), "format_reset");
01443 actionFormatColor = new KAction( i18n( "Text Color..." ), "colorize", 0,
01444 this, SLOT( slotTextColor() ),
01445 actionCollection(), "format_color");
01446
01447
01448 createGUI("kmcomposerui.rc");
01449
01450
01451 KAction* configureAction = actionCollection()->action("options_configure" );
01452 if ( configureAction )
01453 configureAction->setText( i18n("Configure KMail" ) );
01454 }
01455
01456
01457 void KMComposeWin::setupStatusBar(void)
01458 {
01459 statusBar()->insertItem("", 0, 1);
01460 statusBar()->setItemAlignment(0, AlignLeft | AlignVCenter);
01461
01462 statusBar()->insertItem(i18n(" Column: %1 ").arg(" "),2,0,true);
01463 statusBar()->insertItem(i18n(" Line: %1 ").arg(" "),1,0,true);
01464 }
01465
01466
01467
01468 void KMComposeWin::updateCursorPosition()
01469 {
01470 int col,line;
01471 QString temp;
01472 line = mEditor->currentLine();
01473 col = mEditor->currentColumn();
01474 temp = i18n(" Line: %1 ").arg(line+1);
01475 statusBar()->changeItem(temp,1);
01476 temp = i18n(" Column: %1 ").arg(col+1);
01477 statusBar()->changeItem(temp,2);
01478 }
01479
01480
01481
01482 void KMComposeWin::setupEditor(void)
01483 {
01484
01485 mEditor->setModified(FALSE);
01486 QFontMetrics fm(mBodyFont);
01487 mEditor->setTabStopWidth(fm.width(QChar(' ')) * 8);
01488
01489
01490 if (GlobalSettings::self()->wordWrap())
01491 {
01492 mEditor->setWordWrap( QTextEdit::FixedColumnWidth );
01493 mEditor->setWrapColumnOrWidth( GlobalSettings::self()->lineWrapWidth() );
01494 }
01495 else
01496 {
01497 mEditor->setWordWrap( QTextEdit::NoWrap );
01498 }
01499
01500
01501 slotUpdateFont();
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524 updateCursorPosition();
01525 connect(mEditor,SIGNAL(CursorPositionChanged()),SLOT(updateCursorPosition()));
01526 connect( mEditor, SIGNAL( currentFontChanged( const QFont & ) ),
01527 this, SLOT( fontChanged( const QFont & ) ) );
01528 connect( mEditor, SIGNAL( currentAlignmentChanged( int ) ),
01529 this, SLOT( alignmentChanged( int ) ) );
01530
01531 }
01532
01533
01534
01535 static QString cleanedUpHeaderString( const QString & s )
01536 {
01537
01538 QString res( s );
01539 res.replace( '\r', "" );
01540 res.replace( '\n', " " );
01541 return res.stripWhiteSpace();
01542 }
01543
01544
01545 QString KMComposeWin::subject() const
01546 {
01547 return cleanedUpHeaderString( mEdtSubject->text() );
01548 }
01549
01550
01551 QString KMComposeWin::to() const
01552 {
01553 if ( mEdtTo ) {
01554 return cleanedUpHeaderString( mEdtTo->text() );
01555 } else if ( mRecipientsEditor ) {
01556 return mRecipientsEditor->recipientString( Recipient::To );
01557 } else {
01558 return QString::null;
01559 }
01560 }
01561
01562
01563 QString KMComposeWin::cc() const
01564 {
01565 if ( mEdtCc && !mEdtCc->isHidden() ) {
01566 return cleanedUpHeaderString( mEdtCc->text() );
01567 } else if ( mRecipientsEditor ) {
01568 return mRecipientsEditor->recipientString( Recipient::Cc );
01569 } else {
01570 return QString::null;
01571 }
01572 }
01573
01574
01575 QString KMComposeWin::bcc() const
01576 {
01577 if ( mEdtBcc && !mEdtBcc->isHidden() ) {
01578 return cleanedUpHeaderString( mEdtBcc->text() );
01579 } else if ( mRecipientsEditor ) {
01580 return mRecipientsEditor->recipientString( Recipient::Bcc );
01581 } else {
01582 return QString::null;
01583 }
01584 }
01585
01586
01587 QString KMComposeWin::from() const
01588 {
01589 return cleanedUpHeaderString( mEdtFrom->text() );
01590 }
01591
01592
01593 QString KMComposeWin::replyTo() const
01594 {
01595 if ( mEdtReplyTo ) {
01596 return cleanedUpHeaderString( mEdtReplyTo->text() );
01597 } else {
01598 return QString::null;
01599 }
01600 }
01601
01602
01603 void KMComposeWin::verifyWordWrapLengthIsAdequate(const QString &body)
01604 {
01605 int maxLineLength = 0;
01606 int curPos;
01607 int oldPos = 0;
01608 if (mEditor->QTextEdit::wordWrap() == QTextEdit::FixedColumnWidth) {
01609 for (curPos = 0; curPos < (int)body.length(); ++curPos)
01610 if (body[curPos] == '\n') {
01611 if ((curPos - oldPos) > maxLineLength)
01612 maxLineLength = curPos - oldPos;
01613 oldPos = curPos;
01614 }
01615 if ((curPos - oldPos) > maxLineLength)
01616 maxLineLength = curPos - oldPos;
01617 if (mEditor->wrapColumnOrWidth() < maxLineLength)
01618 mEditor->setWrapColumnOrWidth(maxLineLength);
01619 }
01620 }
01621
01622
01623 void KMComposeWin::decryptOrStripOffCleartextSignature( QCString& body )
01624 {
01625 QPtrList<Kpgp::Block> pgpBlocks;
01626 QStrList nonPgpBlocks;
01627 if( Kpgp::Module::prepareMessageForDecryption( body,
01628 pgpBlocks, nonPgpBlocks ) )
01629 {
01630
01631
01632 if( pgpBlocks.count() == 1 )
01633 {
01634 Kpgp::Block* block = pgpBlocks.first();
01635 if( ( block->type() == Kpgp::PgpMessageBlock ) ||
01636 ( block->type() == Kpgp::ClearsignedBlock ) )
01637 {
01638 if( block->type() == Kpgp::PgpMessageBlock )
01639
01640 block->decrypt();
01641 else
01642
01643 block->verify();
01644
01645 body = nonPgpBlocks.first()
01646 + block->text()
01647 + nonPgpBlocks.last();
01648 }
01649 }
01650 }
01651 }
01652
01653
01654 void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign,
01655 bool allowDecryption, bool isModified)
01656 {
01657
01658 if(!newMsg)
01659 {
01660 kdDebug(5006) << "KMComposeWin::setMsg() : newMsg == 0!" << endl;
01661 return;
01662 }
01663 mMsg = newMsg;
01664
01665 mEdtFrom->setText(mMsg->from());
01666 mEdtReplyTo->setText(mMsg->replyTo());
01667 if ( mClassicalRecipients ) {
01668 mEdtTo->setText(mMsg->to());
01669 mEdtCc->setText(mMsg->cc());
01670 mEdtBcc->setText(mMsg->bcc());
01671 } else {
01672 mRecipientsEditor->setRecipientString( mMsg->to(), Recipient::To );
01673 mRecipientsEditor->setRecipientString( mMsg->cc(), Recipient::Cc );
01674 mRecipientsEditor->setRecipientString( mMsg->bcc(), Recipient::Bcc );
01675 }
01676 mEdtSubject->setText(mMsg->subject());
01677
01678 if (!mBtnIdentity->isChecked() && !newMsg->headerField("X-KMail-Identity").isEmpty())
01679 mId = newMsg->headerField("X-KMail-Identity").stripWhiteSpace().toUInt();
01680
01681
01682
01683 if ( !mBtnIdentity->isChecked() ) {
01684 disconnect(mIdentity,SIGNAL(identityChanged(uint)),
01685 this, SLOT(slotIdentityChanged(uint)));
01686 }
01687 mIdentity->setCurrentIdentity( mId );
01688 if ( !mBtnIdentity->isChecked() ) {
01689 connect(mIdentity,SIGNAL(identityChanged(uint)),
01690 this, SLOT(slotIdentityChanged(uint)));
01691 }
01692 else {
01693
01694
01695
01696 slotIdentityChanged( mId );
01697 }
01698
01699 KPIM::IdentityManager * im = kmkernel->identityManager();
01700
01701 const KPIM::Identity & ident = im->identityForUoid( mIdentity->currentIdentity() );
01702
01703
01704
01705 QString mdnAddr = newMsg->headerField("Disposition-Notification-To");
01706 mRequestMDNAction->setChecked( ( !mdnAddr.isEmpty() &&
01707 im->thatIsMe( mdnAddr ) ) ||
01708 GlobalSettings::self()->requestMDN() );
01709
01710
01711 mUrgentAction->setChecked( newMsg->isUrgent() );
01712
01713 if (!ident.isXFaceEnabled() || ident.xface().isEmpty())
01714 mMsg->removeHeaderField("X-Face");
01715 else
01716 {
01717 QString xface = ident.xface();
01718 if (!xface.isEmpty())
01719 {
01720 int numNL = ( xface.length() - 1 ) / 70;
01721 for ( int i = numNL; i > 0; --i )
01722 xface.insert( i*70, "\n\t" );
01723 mMsg->setHeaderField("X-Face", xface);
01724 }
01725 }
01726
01727
01728 switch ( mMsg->encryptionState() ) {
01729 case KMMsgFullyEncrypted:
01730 case KMMsgPartiallyEncrypted:
01731 mLastEncryptActionState = true;
01732 break;
01733 case KMMsgNotEncrypted:
01734 mLastEncryptActionState = false;
01735 break;
01736 default:
01737 break;
01738 }
01739
01740
01741 switch ( mMsg->signatureState() ) {
01742 case KMMsgFullySigned:
01743 case KMMsgPartiallySigned:
01744 mLastSignActionState = true;
01745 break;
01746 case KMMsgNotSigned:
01747 mLastSignActionState = false;
01748 break;
01749 default:
01750 break;
01751 }
01752
01753 mLastIdentityHasSigningKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
01754 mLastIdentityHasEncryptionKey = !ident.pgpEncryptionKey().isEmpty() || !ident.smimeEncryptionKey().isEmpty();
01755
01756 if ( Kleo::CryptoBackendFactory::instance()->openpgp() || Kleo::CryptoBackendFactory::instance()->smime() ) {
01757 const bool canOpenPGPSign = Kleo::CryptoBackendFactory::instance()->openpgp()
01758 && !ident.pgpSigningKey().isEmpty();
01759 const bool canSMIMESign = Kleo::CryptoBackendFactory::instance()->smime()
01760 && !ident.smimeSigningKey().isEmpty();
01761
01762 setEncryption( mLastEncryptActionState );
01763 setSigning( ( canOpenPGPSign || canSMIMESign ) && mLastSignActionState );
01764 }
01765
01766
01767
01768 mAttachMPK->setEnabled( Kleo::CryptoBackendFactory::instance()->openpgp() &&
01769 !ident.pgpEncryptionKey().isEmpty() );
01770
01771 QString transport = newMsg->headerField("X-KMail-Transport");
01772 if (!mBtnTransport->isChecked() && !transport.isEmpty())
01773 {
01774 for (int i = 0; i < mTransport->count(); i++)
01775 if (mTransport->text(i) == transport)
01776 mTransport->setCurrentItem(i);
01777 mTransport->setEditText( transport );
01778 }
01779
01780 if (!mBtnFcc->isChecked())
01781 {
01782 if (!mMsg->fcc().isEmpty())
01783 setFcc(mMsg->fcc());
01784 else
01785 setFcc(ident.fcc());
01786 }
01787
01788 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
01789
01790 partNode * root = partNode::fromMessage( mMsg );
01791
01792 KMail::ObjectTreeParser otp;
01793 otp.parseObjectTree( root );
01794
01795 KMail::AttachmentCollector ac;
01796 ac.setDiveIntoEncryptions( true );
01797 ac.setDiveIntoSignatures( true );
01798 ac.setDiveIntoMessages( false );
01799
01800 ac.collectAttachmentsFrom( root );
01801
01802 for ( std::vector<partNode*>::const_iterator it = ac.attachments().begin() ; it != ac.attachments().end() ; ++it )
01803 addAttach( new KMMessagePart( (*it)->msgPart() ) );
01804
01805 mEditor->setText( otp.textualContent() );
01806 mCharset = otp.textualContentCharset();
01807 if ( mCharset.isEmpty() )
01808 mCharset = mMsg->charset();
01809 if ( mCharset.isEmpty() )
01810 mCharset = mDefCharset;
01811 setCharset( mCharset );
01812
01813 if ( partNode * n = root->findType( DwMime::kTypeText, DwMime::kSubtypeHtml ) )
01814 if ( partNode * p = n->parentNode() )
01815 if ( p->hasType( DwMime::kTypeMultipart ) &&
01816 p->hasSubType( DwMime::kSubtypeAlternative ) )
01817 if ( mMsg->headerField( "X-KMail-Markup" ) == "true" ) {
01818 toggleMarkup( true );
01819 mEditor->setText(n->encodedBody() );
01820 }
01821
01822 if ( mMsg->numBodyParts() == 0 && otp.textualContent().isEmpty() ) {
01823 mCharset=mMsg->charset();
01824 if ( mCharset.isEmpty() || mCharset == "default" )
01825 mCharset = mDefCharset;
01826
01827 QCString bodyDecoded = mMsg->bodyDecoded();
01828
01829 if( allowDecryption )
01830 decryptOrStripOffCleartextSignature( bodyDecoded );
01831
01832 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01833 if (codec) {
01834 mEditor->setText(codec->toUnicode(bodyDecoded));
01835 } else
01836 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01837 }
01838
01839
01840 #ifdef BROKEN_FOR_OPAQUE_SIGNED_OR_ENCRYPTED_MAILS
01841 const int num = mMsg->numBodyParts();
01842 kdDebug(5006) << "KMComposeWin::setMsg() mMsg->numBodyParts="
01843 << mMsg->numBodyParts() << endl;
01844
01845 if ( num > 0 ) {
01846 KMMessagePart bodyPart;
01847 int firstAttachment = 0;
01848
01849 mMsg->bodyPart(1, &bodyPart);
01850 if ( bodyPart.typeStr().lower() == "text" &&
01851 bodyPart.subtypeStr().lower() == "html" ) {
01852
01853 partNode *root = partNode::fromMessage( mMsg );
01854 partNode *node = root->findType( DwMime::kTypeText,
01855 DwMime::kSubtypeHtml );
01856 if ( node && node->parentNode() &&
01857 node->parentNode()->hasType( DwMime::kTypeMultipart ) &&
01858 node->parentNode()->hasSubType( DwMime::kSubtypeAlternative ) ) {
01859
01860 kdDebug(5006) << "KMComposeWin::setMsg() : text/html found" << endl;
01861 firstAttachment = 2;
01862 if ( mMsg->headerField( "X-KMail-Markup" ) == "true" )
01863 toggleMarkup( true );
01864 }
01865 delete root; root = 0;
01866 }
01867 if ( firstAttachment == 0 ) {
01868 mMsg->bodyPart(0, &bodyPart);
01869 if ( bodyPart.typeStr().lower() == "text" ) {
01870
01871 kdDebug(5006) << "KMComposeWin::setMsg() : text/* found" << endl;
01872 firstAttachment = 1;
01873 }
01874 }
01875
01876 if ( firstAttachment != 0 )
01877 {
01878 mCharset = bodyPart.charset();
01879 if ( mCharset.isEmpty() || mCharset == "default" )
01880 mCharset = mDefCharset;
01881
01882 QCString bodyDecoded = bodyPart.bodyDecoded();
01883
01884 if( allowDecryption )
01885 decryptOrStripOffCleartextSignature( bodyDecoded );
01886
01887
01888
01889
01890
01891
01892
01893 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01894 if (codec)
01895 mEditor->setText(codec->toUnicode(bodyDecoded));
01896 else
01897 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01898
01899 } else mEditor->setText("");
01900 for( int i = firstAttachment; i < num; ++i )
01901 {
01902 KMMessagePart *msgPart = new KMMessagePart;
01903 mMsg->bodyPart(i, msgPart);
01904 QCString mimeType = msgPart->typeStr().lower() + '/'
01905 + msgPart->subtypeStr().lower();
01906
01907
01908 if( mimeType != "application/pgp-signature" ) {
01909 addAttach(msgPart);
01910 }
01911 }
01912 } else{
01913 mCharset=mMsg->charset();
01914 if ( mCharset.isEmpty() || mCharset == "default" )
01915 mCharset = mDefCharset;
01916
01917 QCString bodyDecoded = mMsg->bodyDecoded();
01918
01919 if( allowDecryption )
01920 decryptOrStripOffCleartextSignature( bodyDecoded );
01921
01922 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01923 if (codec) {
01924 mEditor->setText(codec->toUnicode(bodyDecoded));
01925 } else
01926 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01927 }
01928
01929 setCharset(mCharset);
01930 #endif // BROKEN_FOR_OPAQUE_SIGNED_OR_ENCRYPTED_MAILS
01931
01932 if( (GlobalSettings::self()->autoTextSignature()=="auto") && mayAutoSign ) {
01933
01934
01935
01936
01937
01938
01939 QTimer::singleShot( 200, this, SLOT(slotAppendSignature()) );
01940 }
01941 setModified( isModified );
01942 }
01943
01944
01945
01946 void KMComposeWin::setFcc( const QString &idString )
01947 {
01948
01949 if ( ! idString.isEmpty() && kmkernel->findFolderById( idString ) ) {
01950 mFcc->setFolder( idString );
01951 } else {
01952 mFcc->setFolder( kmkernel->sentFolder() );
01953 }
01954 }
01955
01956
01957
01958 bool KMComposeWin::isModified() const
01959 {
01960 return ( mEditor->isModified() ||
01961 mEdtFrom->edited() ||
01962 ( mEdtReplyTo && mEdtReplyTo->edited() ) ||
01963 ( mEdtTo && mEdtTo->edited() ) ||
01964 ( mEdtCc && mEdtCc->edited() ) ||
01965 ( mEdtBcc && mEdtBcc->edited() ) ||
01966 ( mRecipientsEditor && mRecipientsEditor->isModified() ) ||
01967 mEdtSubject->edited() ||
01968 mAtmModified ||
01969 ( mTransport->lineEdit() && mTransport->lineEdit()->edited() ) );
01970 }
01971
01972
01973
01974 void KMComposeWin::setModified( bool modified )
01975 {
01976 mEditor->setModified( modified );
01977 if ( !modified ) {
01978 mEdtFrom->setEdited( false );
01979 if ( mEdtReplyTo ) mEdtReplyTo->setEdited( false );
01980 if ( mEdtTo ) mEdtTo->setEdited( false );
01981 if ( mEdtCc ) mEdtCc->setEdited( false );
01982 if ( mEdtBcc ) mEdtBcc->setEdited( false );
01983 if ( mRecipientsEditor ) mRecipientsEditor->clearModified();
01984 mEdtSubject->setEdited( false );
01985 mAtmModified = false ;
01986 if ( mTransport->lineEdit() )
01987 mTransport->lineEdit()->setEdited( false );
01988 }
01989 }
01990
01991
01992
01993 bool KMComposeWin::queryClose ()
01994 {
01995 if ( !mEditor->checkExternalEditorFinished() )
01996 return false;
01997 if (kmkernel->shuttingDown() || kapp->sessionSaving())
01998 return true;
01999
02000 if ( isModified() ) {
02001 const int rc = KMessageBox::warningYesNoCancel(this,
02002 i18n("Do you want to save the message for later or discard it?"),
02003 i18n("Close Composer"),
02004 KGuiItem(i18n("&Save as Draft"), "filesave", QString::null,
02005 i18n("Save this message in the Drafts folder. It can "
02006 "then be edited and sent at a later time.")),
02007 KStdGuiItem::discard() );
02008 if (rc == KMessageBox::Cancel)
02009 return false;
02010 else if (rc == KMessageBox::Yes) {
02011
02012 slotSaveDraft();
02013 return false;
02014 }
02015 }
02016 cleanupAutoSave();
02017 return true;
02018 }
02019
02020
02021 bool KMComposeWin::userForgotAttachment()
02022 {
02023 bool checkForForgottenAttachments = GlobalSettings::self()->showForgottenAttachmentWarning();
02024
02025 if ( !checkForForgottenAttachments || ( mAtmList.count() > 0 ) )
02026 return false;
02027
02028
02029 QStringList attachWordsList = GlobalSettings::self()->attachmentKeywords();
02030
02031 if ( attachWordsList.isEmpty() ) {
02032
02033 attachWordsList << QString::fromLatin1("attachment")
02034 << QString::fromLatin1("attached");
02035 if ( QString::fromLatin1("attachment") != i18n("attachment") )
02036 attachWordsList << i18n("attachment");
02037 if ( QString::fromLatin1("attached") != i18n("attached") )
02038 attachWordsList << i18n("attached");
02039 }
02040
02041 QRegExp rx ( QString::fromLatin1("\\b") +
02042 attachWordsList.join("\\b|\\b") +
02043 QString::fromLatin1("\\b") );
02044 rx.setCaseSensitive( false );
02045
02046 bool gotMatch = false;
02047
02048
02049
02050 QString subj = subject();
02051 gotMatch = ( KMMessage::stripOffPrefixes( subj ) == subj )
02052 && ( rx.search( subj ) >= 0 );
02053
02054 if ( !gotMatch ) {
02055
02056
02057 QRegExp quotationRx ("^([ \\t]*([|>:}#]|[A-Za-z]+>))+");
02058 for ( int i = 0; i < mEditor->numLines(); ++i ) {
02059 QString line = mEditor->textLine( i );
02060 gotMatch = ( quotationRx.search( line ) < 0 )
02061 && ( rx.search( line ) >= 0 );
02062 if ( gotMatch )
02063 break;
02064 }
02065 }
02066
02067 if ( !gotMatch )
02068 return false;
02069
02070 int rc = KMessageBox::warningYesNoCancel( this,
02071 i18n("The message you have composed seems to refer to an "
02072 "attached file but you have not attached anything.\n"
02073 "Do you want to attach a file to your message?"),
02074 i18n("File Attachment Reminder"),
02075 i18n("&Attach File..."),
02076 i18n("&Send as Is") );
02077 if ( rc == KMessageBox::Cancel )
02078 return true;
02079 if ( rc == KMessageBox::Yes ) {
02080 slotAttachFile();
02081
02082 return true;
02083 }
02084 return false;
02085 }
02086
02087
02088 void KMComposeWin::applyChanges( bool dontSignNorEncrypt, bool dontDisable )
02089 {
02090 kdDebug(5006) << "entering KMComposeWin::applyChanges" << endl;
02091
02092 if(!mMsg) {
02093 kdDebug(5006) << "KMComposeWin::applyChanges() : mMsg == 0!\n" << endl;
02094 emit applyChangesDone( false );
02095 return;
02096 }
02097
02098 if( mComposer ) {
02099 kdDebug(5006) << "KMComposeWin::applyChanges() : applyChanges called twice"
02100 << endl;
02101 return;
02102 }
02103
02104
02105 mComposer = new MessageComposer( this );
02106 connect( mComposer, SIGNAL( done( bool ) ),
02107 this, SLOT( slotComposerDone( bool ) ) );
02108
02109
02110
02111
02112 if ( !dontDisable ) setEnabled( false );
02113
02114 mComposer->setDisableBreaking( mDisableBreaking );
02115 mComposer->applyChanges( dontSignNorEncrypt );
02116 }
02117
02118 void KMComposeWin::slotComposerDone( bool rc )
02119 {
02120 deleteAll( mComposedMessages );
02121 mComposedMessages = mComposer->composedMessageList();
02122 emit applyChangesDone( rc );
02123 delete mComposer;
02124 mComposer = 0;
02125
02126
02127 setEnabled( true );
02128 }
02129
02130 const KPIM::Identity & KMComposeWin::identity() const {
02131 return kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
02132 }
02133
02134 uint KMComposeWin::identityUid() const {
02135 return mIdentity->currentIdentity();
02136 }
02137
02138 Kleo::CryptoMessageFormat KMComposeWin::cryptoMessageFormat() const {
02139 if ( !mCryptoModuleAction )
02140 return Kleo::AutoFormat;
02141 return cb2format( mCryptoModuleAction->currentItem() );
02142 }
02143
02144 bool KMComposeWin::encryptToSelf() const {
02145 return !Kpgp::Module::getKpgp() || Kpgp::Module::getKpgp()->encryptToSelf();
02146 }
02147
02148 bool KMComposeWin::queryExit ()
02149 {
02150 return true;
02151 }
02152
02153
02154 void KMComposeWin::addAttach(const KURL aUrl)
02155 {
02156 if ( !aUrl.isValid() ) {
02157 KMessageBox::sorry( this, i18n( "<qt><p>KMail could not recognize the location of the attachment (%1);</p>"
02158 "<p>you have to specify the full path if you wish to attach a file.</p></qt>" )
02159 .arg( aUrl.prettyURL() ) );
02160 return;
02161 }
02162 KIO::TransferJob *job = KIO::get(aUrl);
02163 KIO::Scheduler::scheduleJob( job );
02164 atmLoadData ld;
02165 ld.url = aUrl;
02166 ld.data = QByteArray();
02167 ld.insert = false;
02168 if( !aUrl.fileEncoding().isEmpty() )
02169 ld.encoding = aUrl.fileEncoding().latin1();
02170
02171 mMapAtmLoadData.insert(job, ld);
02172 connect(job, SIGNAL(result(KIO::Job *)),
02173 this, SLOT(slotAttachFileResult(KIO::Job *)));
02174 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
02175 this, SLOT(slotAttachFileData(KIO::Job *, const QByteArray &)));
02176 }
02177
02178
02179
02180 void KMComposeWin::addAttach(const KMMessagePart* msgPart)
02181 {
02182 mAtmList.append(msgPart);
02183
02184
02185 if (mAtmList.count()==1)
02186 {
02187 mAtmListView->resize(mAtmListView->width(), 50);
02188 mAtmListView->show();
02189 resize(size());
02190 }
02191
02192
02193 KMAtmListViewItem *lvi = new KMAtmListViewItem( mAtmListView );
02194 msgPartToItem(msgPart, lvi);
02195 mAtmItemList.append(lvi);
02196
02197
02198 if ( mTempDir != 0 ) {
02199 delete mTempDir;
02200 mTempDir = 0;
02201 }
02202
02203 connect( lvi, SIGNAL( compress( int ) ),
02204 this, SLOT( compressAttach( int ) ) );
02205 connect( lvi, SIGNAL( uncompress( int ) ),
02206 this, SLOT( uncompressAttach( int ) ) );
02207
02208 slotUpdateAttachActions();
02209 }
02210
02211
02212
02213 void KMComposeWin::slotUpdateAttachActions()
02214 {
02215 int selectedCount = 0;
02216 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it ) {
02217 if ( (*it)->isSelected() ) {
02218 ++selectedCount;
02219 }
02220 }
02221
02222 mAttachRemoveAction->setEnabled( selectedCount >= 1 );
02223 mAttachSaveAction->setEnabled( selectedCount == 1 );
02224 mAttachPropertiesAction->setEnabled( selectedCount == 1 );
02225 }
02226
02227
02228
02229
02230 QString KMComposeWin::prettyMimeType( const QString& type )
02231 {
02232 QString t = type.lower();
02233 KServiceType::Ptr st = KServiceType::serviceType( t );
02234 return st ? st->comment() : t;
02235 }
02236
02237 void KMComposeWin::msgPartToItem(const KMMessagePart* msgPart,
02238 KMAtmListViewItem *lvi, bool loadDefaults)
02239 {
02240 assert(msgPart != 0);
02241
02242 if (!msgPart->fileName().isEmpty())
02243 lvi->setText(0, msgPart->fileName());
02244 else
02245 lvi->setText(0, msgPart->name());
02246 lvi->setText(1, KIO::convertSize( msgPart->decodedSize()));
02247 lvi->setText(2, msgPart->contentTransferEncodingStr());
02248 lvi->setText(3, prettyMimeType(msgPart->typeStr() + "/" + msgPart->subtypeStr()));
02249
02250 if ( loadDefaults ) {
02251 if( canSignEncryptAttachments() ) {
02252 lvi->enableCryptoCBs( true );
02253 lvi->setEncrypt( mEncryptAction->isChecked() );
02254 lvi->setSign( mSignAction->isChecked() );
02255 } else {
02256 lvi->enableCryptoCBs( false );
02257 }
02258 }
02259 }
02260
02261
02262
02263 void KMComposeWin::removeAttach(const QString &aUrl)
02264 {
02265 int idx;
02266 KMMessagePart* msgPart;
02267 for(idx=0,msgPart=mAtmList.first(); msgPart;
02268 msgPart=mAtmList.next(),idx++) {
02269 if (msgPart->name() == aUrl) {
02270 removeAttach(idx);
02271 return;
02272 }
02273 }
02274 }
02275
02276
02277
02278 void KMComposeWin::removeAttach(int idx)
02279 {
02280 mAtmModified = TRUE;
02281 mAtmList.remove(idx);
02282 delete mAtmItemList.take(idx);
02283
02284 if( mAtmList.isEmpty() )
02285 {
02286 mAtmListView->hide();
02287 mAtmListView->setMinimumSize(0, 0);
02288 resize(size());
02289 }
02290 }
02291
02292
02293
02294 bool KMComposeWin::encryptFlagOfAttachment(int idx)
02295 {
02296 return (int)(mAtmItemList.count()) > idx
02297 ? static_cast<KMAtmListViewItem*>( mAtmItemList.at( idx ) )->isEncrypt()
02298 : false;
02299 }
02300
02301
02302
02303 bool KMComposeWin::signFlagOfAttachment(int idx)
02304 {
02305 return (int)(mAtmItemList.count()) > idx
02306 ? ((KMAtmListViewItem*)(mAtmItemList.at( idx )))->isSign()
02307 : false;
02308 }
02309
02310
02311
02312 void KMComposeWin::addrBookSelInto()
02313 {
02314 if ( mClassicalRecipients ) {
02315 if ( GlobalSettings::self()->addresseeSelectorType() ==
02316 GlobalSettings::EnumAddresseeSelectorType::New ) {
02317 addrBookSelIntoNew();
02318 } else {
02319 addrBookSelIntoOld();
02320 }
02321 } else {
02322 kdWarning() << "To be implemented: call recipients picker." << endl;
02323 }
02324 }
02325
02326 void KMComposeWin::addrBookSelIntoOld()
02327 {
02328 AddressesDialog dlg( this );
02329 QString txt;
02330 QStringList lst;
02331
02332 txt = to();
02333 if ( !txt.isEmpty() ) {
02334 lst = KPIM::splitEmailAddrList( txt );
02335 dlg.setSelectedTo( lst );
02336 }
02337
02338 txt = mEdtCc->text();
02339 if ( !txt.isEmpty() ) {
02340 lst = KPIM::splitEmailAddrList( txt );
02341 dlg.setSelectedCC( lst );
02342 }
02343
02344 txt = mEdtBcc->text();
02345 if ( !txt.isEmpty() ) {
02346 lst = KPIM::splitEmailAddrList( txt );
02347 dlg.setSelectedBCC( lst );
02348 }
02349
02350 dlg.setRecentAddresses( RecentAddresses::self( KMKernel::config() )->kabcAddresses() );
02351
02352 if (dlg.exec()==QDialog::Rejected) return;
02353
02354 mEdtTo->setText( dlg.to().join(", ") );
02355 mEdtTo->setEdited( true );
02356
02357 mEdtCc->setText( dlg.cc().join(", ") );
02358 mEdtCc->setEdited( true );
02359
02360 mEdtBcc->setText( dlg.bcc().join(", ") );
02361 mEdtBcc->setEdited( true );
02362
02363
02364 if ( !mEdtBcc->text().isEmpty() ) {
02365 mShowHeaders |= HDR_BCC;
02366 rethinkFields( false );
02367 }
02368 }
02369
02370 void KMComposeWin::addrBookSelIntoNew()
02371 {
02372 AddresseeEmailSelection selection;
02373
02374 AddresseeSelectorDialog dlg( &selection );
02375
02376 QString txt;
02377 QStringList lst;
02378
02379 txt = to();
02380 if ( !txt.isEmpty() ) {
02381 lst = KPIM::splitEmailAddrList( txt );
02382 selection.setSelectedTo( lst );
02383 }
02384
02385 txt = mEdtCc->text();
02386 if ( !txt.isEmpty() ) {
02387 lst = KPIM::splitEmailAddrList( txt );
02388 selection.setSelectedCC( lst );
02389 }
02390
02391 txt = mEdtBcc->text();
02392 if ( !txt.isEmpty() ) {
02393 lst = KPIM::splitEmailAddrList( txt );
02394 selection.setSelectedBCC( lst );
02395 }
02396
02397 if (dlg.exec()==QDialog::Rejected) return;
02398
02399 QStringList list = selection.to() + selection.toDistributionLists();
02400 mEdtTo->setText( list.join(", ") );
02401 mEdtTo->setEdited( true );
02402
02403 list = selection.cc() + selection.ccDistributionLists();
02404 mEdtCc->setText( list.join(", ") );
02405 mEdtCc->setEdited( true );
02406
02407 list = selection.bcc() + selection.bccDistributionLists();
02408 mEdtBcc->setText( list.join(", ") );
02409 mEdtBcc->setEdited( true );
02410
02411
02412 if ( !mEdtBcc->text().isEmpty() ) {
02413 mShowHeaders |= HDR_BCC;
02414 rethinkFields( false );
02415 }
02416 }
02417
02418
02419
02420 void KMComposeWin::setCharset(const QCString& aCharset, bool forceDefault)
02421 {
02422 if ((forceDefault && GlobalSettings::self()->forceReplyCharset()) || aCharset.isEmpty())
02423 mCharset = mDefCharset;
02424 else
02425 mCharset = aCharset.lower();
02426
02427 if ( mCharset.isEmpty() || mCharset == "default" )
02428 mCharset = mDefCharset;
02429
02430 if (mAutoCharset)
02431 {
02432 mEncodingAction->setCurrentItem( 0 );
02433 return;
02434 }
02435
02436 QStringList encodings = mEncodingAction->items();
02437 int i = 0;
02438 bool charsetFound = FALSE;
02439 for ( QStringList::Iterator it = encodings.begin(); it != encodings.end();
02440 ++it, i++ )
02441 {
02442 if (i > 0 && ((mCharset == "us-ascii" && i == 1) ||
02443 (i != 1 && KGlobal::charsets()->codecForName(
02444 KGlobal::charsets()->encodingForName(*it))
02445 == KGlobal::charsets()->codecForName(mCharset))))
02446 {
02447 mEncodingAction->setCurrentItem( i );
02448 slotSetCharset();
02449 charsetFound = TRUE;
02450 break;
02451 }
02452 }
02453 if (!aCharset.isEmpty() && !charsetFound) setCharset("", TRUE);
02454 }
02455
02456
02457
02458 void KMComposeWin::slotAddrBook()
02459 {
02460 KAddrBookExternal::openAddressBook(this);
02461 }
02462
02463
02464
02465 void KMComposeWin::slotAddrBookFrom()
02466 {
02467 addrBookSelInto();
02468 }
02469
02470
02471
02472 void KMComposeWin::slotAddrBookReplyTo()
02473 {
02474 addrBookSelInto();
02475 }
02476
02477
02478
02479 void KMComposeWin::slotAddrBookTo()
02480 {
02481 addrBookSelInto();
02482 }
02483
02484
02485 void KMComposeWin::slotAttachFile()
02486 {
02487
02488
02489
02490
02491 KFileDialog fdlg(QString::null, QString::null, this, 0, TRUE);
02492 fdlg.setOperationMode( KFileDialog::Other );
02493 fdlg.setCaption(i18n("Attach File"));
02494 fdlg.okButton()->setGuiItem(KGuiItem(i18n("&Attach"),"fileopen"));
02495 fdlg.setMode(KFile::Files);
02496 fdlg.exec();
02497 KURL::List files = fdlg.selectedURLs();
02498
02499 for (KURL::List::Iterator it = files.begin(); it != files.end(); ++it)
02500 addAttach(*it);
02501 }
02502
02503
02504
02505 void KMComposeWin::slotAttachFileData(KIO::Job *job, const QByteArray &data)
02506 {
02507 QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.find(job);
02508 assert(it != mMapAtmLoadData.end());
02509 QBuffer buff((*it).data);
02510 buff.open(IO_WriteOnly | IO_Append);
02511 buff.writeBlock(data.data(), data.size());
02512 buff.close();
02513 }
02514
02515
02516
02517 void KMComposeWin::slotAttachFileResult(KIO::Job *job)
02518 {
02519 QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.find(job);
02520 assert(it != mMapAtmLoadData.end());
02521 if (job->error())
02522 {
02523 mMapAtmLoadData.remove(it);
02524 job->showErrorDialog();
02525 return;
02526 }
02527 if ((*it).insert)
02528 {
02529 (*it).data.resize((*it).data.size() + 1);
02530 (*it).data[(*it).data.size() - 1] = '\0';
02531 if ( const QTextCodec * codec = KGlobal::charsets()->codecForName((*it).encoding) )
02532 mEditor->insert( codec->toUnicode( (*it).data ) );
02533 else
02534 mEditor->insert( QString::fromLocal8Bit( (*it).data ) );
02535 mMapAtmLoadData.remove(it);
02536 return;
02537 }
02538 const QCString partCharset = (*it).url.fileEncoding().isEmpty()
02539 ? mCharset
02540 : QCString((*it).url.fileEncoding().latin1());
02541
02542 KMMessagePart* msgPart;
02543
02544 KCursorSaver busy(KBusyPtr::busy());
02545 QString name( (*it).url.fileName() );
02546
02547 QString mimeType = static_cast<KIO::MimetypeJob*>(job)->mimetype();
02548
02549 if ( name.isEmpty() ) {
02550
02551
02552 if( mimeType == "text/html" )
02553 name = "index.html";
02554 else {
02555
02556 QStringList patterns( KMimeType::mimeType( mimeType )->patterns() );
02557 QString ext;
02558 if( !patterns.isEmpty() ) {
02559 ext = patterns[0];
02560 int i = ext.findRev( '.' );
02561 if( i == -1 )
02562 ext.prepend( '.' );
02563 else if( i > 0 )
02564 ext = ext.mid( i );
02565 }
02566 name = QString("unknown") += ext;
02567 }
02568 }
02569
02570 name.truncate( 256 );
02571
02572 QCString encoding = KMMsgBase::autoDetectCharset(partCharset,
02573 KMMessage::preferredCharsets(), name);
02574 if (encoding.isEmpty()) encoding = "utf-8";
02575
02576 QCString encName;
02577 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
02578 encName = KMMsgBase::encodeRFC2047String( name, encoding );
02579 else
02580 encName = KMMsgBase::encodeRFC2231String( name, encoding );
02581 bool RFC2231encoded = false;
02582 if ( !GlobalSettings::self()->outlookCompatibleAttachments() )
02583 RFC2231encoded = name != QString( encName );
02584
02585
02586 msgPart = new KMMessagePart;
02587 msgPart->setName(name);
02588 QValueList<int> allowedCTEs;
02589 msgPart->setBodyAndGuessCte((*it).data, allowedCTEs,
02590 !kmkernel->msgSender()->sendQuotedPrintable());
02591 kdDebug(5006) << "autodetected cte: " << msgPart->cteStr() << endl;
02592 int slash = mimeType.find( '/' );
02593 if( slash == -1 )
02594 slash = mimeType.length();
02595 msgPart->setTypeStr( mimeType.left( slash ).latin1() );
02596 msgPart->setSubtypeStr( mimeType.mid( slash + 1 ).latin1() );
02597 msgPart->setContentDisposition(QCString("attachment;\n\tfilename")
02598 + ((RFC2231encoded) ? "*" : "") + "=\"" + encName + "\"");
02599
02600 mMapAtmLoadData.remove(it);
02601
02602 msgPart->setCharset(partCharset);
02603
02604
02605 KConfigGroup composer(KMKernel::config(), "Composer");
02606 if ( GlobalSettings::self()->showMessagePartDialogOnAttach() ) {
02607 const KCursorSaver saver( QCursor::ArrowCursor );
02608 KMMsgPartDialogCompat dlg;
02609 int encodings = 0;
02610 for ( QValueListConstIterator<int> it = allowedCTEs.begin() ;
02611 it != allowedCTEs.end() ; ++it )
02612 switch ( *it ) {
02613 case DwMime::kCteBase64: encodings |= KMMsgPartDialog::Base64; break;
02614 case DwMime::kCteQp: encodings |= KMMsgPartDialog::QuotedPrintable; break;
02615 case DwMime::kCte7bit: encodings |= KMMsgPartDialog::SevenBit; break;
02616 case DwMime::kCte8bit: encodings |= KMMsgPartDialog::EightBit; break;
02617 default: ;
02618 }
02619 dlg.setShownEncodings( encodings );
02620 dlg.setMsgPart(msgPart);
02621 if (!dlg.exec()) {
02622 delete msgPart;
02623 msgPart = 0;
02624 return;
02625 }
02626 }
02627 mAtmModified = TRUE;
02628 if (msgPart->typeStr().lower() != "text") msgPart->setCharset(QCString());
02629
02630
02631 addAttach(msgPart);
02632 }
02633
02634
02635
02636 void KMComposeWin::slotInsertFile()
02637 {
02638 KFileDialog fdlg(QString::null, QString::null, this, 0, TRUE);
02639 fdlg.setOperationMode( KFileDialog::Opening );
02640 fdlg.okButton()->setText(i18n("&Insert"));
02641 fdlg.setCaption(i18n("Insert File"));
02642 fdlg.toolBar()->insertCombo(KMMsgBase::supportedEncodings(FALSE), 4711,
02643 false, 0, 0, 0);
02644 KComboBox *combo = fdlg.toolBar()->getCombo(4711);
02645 for (int i = 0; i < combo->count(); i++)
02646 if (KGlobal::charsets()->codecForName(KGlobal::charsets()->
02647 encodingForName(combo->text(i)))
02648 == QTextCodec::codecForLocale()) combo->setCurrentItem(i);
02649 if (!fdlg.exec()) return;
02650
02651 KURL u = fdlg.selectedURL();
02652 mRecentAction->addURL(u);
02653
02654 {
02655 KConfig *config = KMKernel::config();
02656 KConfigGroupSaver saver( config, "Composer" );
02657 QString encoding = KGlobal::charsets()->encodingForName(combo->currentText()).latin1();
02658 QStringList urls = config->readListEntry( "recent-urls" );
02659 QStringList encodings = config->readListEntry( "recent-encodings" );
02660
02661
02662 uint mMaxRecentFiles = 30;
02663 while (urls.count() > mMaxRecentFiles)
02664 urls.erase( urls.fromLast() );
02665 while (encodings.count() > mMaxRecentFiles)
02666 encodings.erase( encodings.fromLast() );
02667
02668 if (urls.count() != encodings.count()) {
02669 urls.clear();
02670 encodings.clear();
02671 }
02672 urls.prepend( u.prettyURL() );
02673 encodings.prepend( encoding );
02674 config->writeEntry( "recent-urls", urls );
02675 config->writeEntry( "recent-encodings", encodings );
02676 mRecentAction->saveEntries( config );
02677 }
02678 slotInsertRecentFile(u);
02679 }
02680
02681
02682
02683 void KMComposeWin::slotInsertRecentFile(const KURL& u)
02684 {
02685 if (u.fileName().isEmpty()) return;
02686
02687 KIO::Job *job = KIO::get(u);
02688 atmLoadData ld;
02689 ld.url = u;
02690 ld.data = QByteArray();
02691 ld.insert = true;
02692
02693 {
02694 KConfig *config = KMKernel::config();
02695 KConfigGroupSaver saver( config, "Composer" );
02696 QStringList urls = config->readListEntry( "recent-urls" );
02697 QStringList encodings = config->readListEntry( "recent-encodings" );
02698 int index = urls.findIndex( u.prettyURL() );
02699 if (index != -1) {
02700 QString encoding = encodings[ index ];
02701 ld.encoding = encoding.latin1();
02702 }
02703 }
02704 mMapAtmLoadData.insert(job, ld);
02705 connect(job, SIGNAL(result(KIO::Job *)),
02706 this, SLOT(slotAttachFileResult(KIO::Job *)));
02707 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
02708 this, SLOT(slotAttachFileData(KIO::Job *, const QByteArray &)));
02709 }
02710
02711
02712
02713 void KMComposeWin::slotSetCharset()
02714 {
02715 if (mEncodingAction->currentItem() == 0)
02716 {
02717 mAutoCharset = true;
02718 return;
02719 }
02720 mAutoCharset = false;
02721
02722 mCharset = KGlobal::charsets()->encodingForName( mEncodingAction->
02723 currentText() ).latin1();
02724 }
02725
02726
02727
02728 void KMComposeWin::slotSelectCryptoModule( bool init )
02729 {
02730 if ( !init ) {
02731 setModified( true );
02732 }
02733 if( canSignEncryptAttachments() ) {
02734
02735 if( 0 == mAtmListView->columnWidth( mAtmColEncrypt ) ) {
02736
02737
02738 if( !mAtmList.isEmpty() ) {
02739 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02740 lvi;
02741 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02742 lvi->setSign( mSignAction->isChecked() );
02743 lvi->setEncrypt( mEncryptAction->isChecked() );
02744 }
02745 }
02746 int totalWidth = 0;
02747
02748 for( int col=0; col < mAtmColEncrypt; col++ )
02749 totalWidth += mAtmListView->columnWidth( col );
02750 int reducedTotalWidth = totalWidth - mAtmEncryptColWidth
02751 - mAtmSignColWidth;
02752
02753
02754 int usedWidth = 0;
02755 for( int col=0; col < mAtmColEncrypt-1; col++ ) {
02756 int newWidth = mAtmListView->columnWidth( col ) * reducedTotalWidth
02757 / totalWidth;
02758 mAtmListView->setColumnWidth( col, newWidth );
02759 usedWidth += newWidth;
02760 }
02761
02762
02763
02764 mAtmListView->setColumnWidth( mAtmColEncrypt-1,
02765 reducedTotalWidth - usedWidth );
02766 mAtmListView->setColumnWidth( mAtmColEncrypt, mAtmEncryptColWidth );
02767 mAtmListView->setColumnWidth( mAtmColSign, mAtmSignColWidth );
02768 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02769 lvi;
02770 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02771 lvi->enableCryptoCBs( true );
02772 }
02773 }
02774 } else {
02775
02776 if( 0 != mAtmListView->columnWidth( mAtmColEncrypt ) ) {
02777 mAtmEncryptColWidth = mAtmListView->columnWidth( mAtmColEncrypt );
02778 mAtmSignColWidth = mAtmListView->columnWidth( mAtmColSign );
02779 int totalWidth = 0;
02780
02781 for( int col=0; col < mAtmListView->columns(); col++ )
02782 totalWidth += mAtmListView->columnWidth( col );
02783 int reducedTotalWidth = totalWidth - mAtmEncryptColWidth
02784 - mAtmSignColWidth;
02785
02786
02787 int usedWidth = 0;
02788 for( int col=0; col < mAtmColEncrypt-1; col++ ) {
02789 int newWidth = mAtmListView->columnWidth( col ) * totalWidth
02790 / reducedTotalWidth;
02791 mAtmListView->setColumnWidth( col, newWidth );
02792 usedWidth += newWidth;
02793 }
02794
02795
02796
02797 mAtmListView->setColumnWidth( mAtmColEncrypt-1, totalWidth - usedWidth );
02798 mAtmListView->setColumnWidth( mAtmColEncrypt, 0 );
02799 mAtmListView->setColumnWidth( mAtmColSign, 0 );
02800 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02801 lvi;
02802 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02803 lvi->enableCryptoCBs( false );
02804 }
02805 }
02806 }
02807 }
02808
02809 static void showExportError( QWidget * w, const GpgME::Error & err ) {
02810 assert( err );
02811 const QString msg = i18n("<qt><p>An error occurred while trying to export "
02812 "the key from the backend:</p>"
02813 "<p><b>%1</b></p></qt>")
02814 .arg( QString::fromLocal8Bit( err.asString() ) );
02815 KMessageBox::error( w, msg, i18n("Key Export Failed") );
02816 }
02817
02818
02819
02820 void KMComposeWin::slotInsertMyPublicKey()
02821 {
02822
02823 mFingerprint =
02824 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() ).pgpEncryptionKey();
02825 if ( !mFingerprint.isEmpty() )
02826 startPublicKeyExport();
02827 }
02828
02829 void KMComposeWin::startPublicKeyExport() {
02830 if ( mFingerprint.isEmpty() )
02831 return;
02832 Kleo::ExportJob * job = Kleo::CryptoBackendFactory::instance()->openpgp()->publicKeyExportJob( true );
02833 assert( job );
02834
02835 connect( job, SIGNAL(result(const GpgME::Error&,const QByteArray&)),
02836 this, SLOT(slotPublicKeyExportResult(const GpgME::Error&,const QByteArray&)) );
02837
02838 const GpgME::Error err = job->start( mFingerprint );
02839 if ( err )
02840 showExportError( this, err );
02841 else
02842 (void)new Kleo::ProgressDialog( job, i18n("Exporting key..."), this );
02843 }
02844
02845 void KMComposeWin::slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata ) {
02846 if ( err ) {
02847 showExportError( this, err );
02848 return;
02849 }
02850
02851
02852 KMMessagePart * msgPart = new KMMessagePart();
02853 msgPart->setName( i18n("OpenPGP key 0x%1").arg( mFingerprint ) );
02854 msgPart->setTypeStr("application");
02855 msgPart->setSubtypeStr("pgp-keys");
02856 QValueList<int> dummy;
02857 msgPart->setBodyAndGuessCte(keydata, dummy, false);
02858 msgPart->setContentDisposition( "attachment;\n\tfilename=0x" + QCString( mFingerprint.latin1() ) + ".asc" );
02859
02860
02861 addAttach(msgPart);
02862 rethinkFields();
02863 }
02864
02865
02866 void KMComposeWin::slotInsertPublicKey()
02867 {
02868 Kleo::KeySelectionDialog dlg( i18n("Attach Public OpenPGP Key"),
02869 i18n("Select the public key which should "
02870 "be attached."),
02871 std::vector<GpgME::Key>(),
02872 Kleo::KeySelectionDialog::PublicKeys|Kleo::KeySelectionDialog::OpenPGPKeys,
02873 false ,
02874 false ,
02875 this, "attach public key selection dialog" );
02876 if ( dlg.exec() != QDialog::Accepted )
02877 return;
02878
02879 mFingerprint = dlg.fingerprint();
02880 startPublicKeyExport();
02881 }
02882
02883
02884
02885 void KMComposeWin::slotAttachPopupMenu(QListViewItem *, const QPoint &, int)
02886 {
02887 if (!mAttachMenu)
02888 {
02889 mAttachMenu = new QPopupMenu(this);
02890
02891 mOpenId = mAttachMenu->insertItem(i18n("to open", "Open"), this,
02892 SLOT(slotAttachOpen()));
02893 mViewId = mAttachMenu->insertItem(i18n("to view", "View"), this,
02894 SLOT(slotAttachView()));
02895 mRemoveId = mAttachMenu->insertItem(i18n("Remove"), this, SLOT(slotAttachRemove()));
02896 mSaveAsId = mAttachMenu->insertItem( SmallIconSet("filesaveas"), i18n("Save As..."), this,
02897 SLOT( slotAttachSave() ) );
02898 mPropertiesId = mAttachMenu->insertItem( i18n("Properties"), this,
02899 SLOT( slotAttachProperties() ) );
02900 mAttachMenu->insertSeparator();
02901 mAttachMenu->insertItem(i18n("Add Attachment..."), this, SLOT(slotAttachFile()));
02902 }
02903
02904 int selectedCount = 0;
02905 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it ) {
02906 if ( (*it)->isSelected() ) {
02907 ++selectedCount;
02908 }
02909 }
02910
02911 mAttachMenu->setItemEnabled( mOpenId, selectedCount > 0 );
02912 mAttachMenu->setItemEnabled( mViewId, selectedCount > 0 );
02913 mAttachMenu->setItemEnabled( mRemoveId, selectedCount > 0 );
02914 mAttachMenu->setItemEnabled( mSaveAsId, selectedCount == 1 );
02915 mAttachMenu->setItemEnabled( mPropertiesId, selectedCount == 1 );
02916
02917 mAttachMenu->popup(QCursor::pos());
02918 }
02919
02920
02921 int KMComposeWin::currentAttachmentNum()
02922 {
02923 int i = 0;
02924 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i )
02925 if ( *it == mAtmListView->currentItem() )
02926 return i;
02927 return -1;
02928 }
02929
02930
02931 void KMComposeWin::slotAttachProperties()
02932 {
02933 int idx = currentAttachmentNum();
02934
02935 if (idx < 0) return;
02936
02937 KMMessagePart* msgPart = mAtmList.at(idx);
02938 msgPart->setCharset(mCharset);
02939
02940 KMMsgPartDialogCompat dlg;
02941 dlg.setMsgPart(msgPart);
02942 KMAtmListViewItem* listItem = (KMAtmListViewItem*)(mAtmItemList.at(idx));
02943 if( canSignEncryptAttachments() && listItem ) {
02944 dlg.setCanSign( true );
02945 dlg.setCanEncrypt( true );
02946 dlg.setSigned( listItem->isSign() );
02947 dlg.setEncrypted( listItem->isEncrypt() );
02948 } else {
02949 dlg.setCanSign( false );
02950 dlg.setCanEncrypt( false );
02951 }
02952 if (dlg.exec())
02953 {
02954 mAtmModified = TRUE;
02955
02956 if( listItem ) {
02957 msgPartToItem(msgPart, listItem);
02958 if( canSignEncryptAttachments() ) {
02959 listItem->setSign( dlg.isSigned() );
02960 listItem->setEncrypt( dlg.isEncrypted() );
02961 }
02962 }
02963 }
02964 if (msgPart->typeStr().lower() != "text") msgPart->setCharset(QCString());
02965 }
02966
02967
02968 void KMComposeWin::compressAttach( int idx )
02969 {
02970 if (idx < 0) return;
02971
02972 unsigned int i;
02973 for ( i = 0; i < mAtmItemList.count(); ++i )
02974 if ( mAtmItemList.at( i )->itemPos() == idx )
02975 break;
02976
02977 if ( i > mAtmItemList.count() )
02978 return;
02979
02980 KMMessagePart* msgPart;
02981 msgPart = mAtmList.at( i );
02982 QByteArray array;
02983 QBuffer dev( array );
02984 KZip zip( &dev );
02985 QByteArray decoded = msgPart->bodyDecodedBinary();
02986 if ( ! zip.open( IO_WriteOnly ) ) {
02987 KMessageBox::sorry(0, i18n("KMail could not compress the file.") );
02988 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
02989 return;
02990 }
02991
02992 zip.setCompression( KZip::DeflateCompression );
02993 if ( ! zip.writeFile( msgPart->name(), "", "", decoded.size(),
02994 decoded.data() ) ) {
02995 KMessageBox::sorry(0, i18n("KMail could not compress the file.") );
02996 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
02997 return;
02998 }
02999 zip.close();
03000 if ( array.size() >= decoded.size() ) {
03001 if ( KMessageBox::questionYesNo( this, i18n("The compressed file is larger "
03002 "than the original. Do you want to keep the original one?" ), QString::null, i18n("Keep"), i18n("Compress") )
03003 == KMessageBox::Yes ) {
03004 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
03005 return;
03006 }
03007 }
03008 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setUncompressedCodec(
03009 msgPart->cteStr() );
03010
03011 msgPart->setCteStr( "base64" );
03012 msgPart->setBodyEncodedBinary( array );
03013 QString name = msgPart->name() + ".zip";
03014
03015 msgPart->setName( name );
03016
03017 QCString cDisp = "attachment;";
03018 QCString encoding = KMMsgBase::autoDetectCharset( msgPart->charset(),
03019 KMMessage::preferredCharsets(), name );
03020 kdDebug(5006) << "encoding: " << encoding << endl;
03021 if ( encoding.isEmpty() ) encoding = "utf-8";
03022 kdDebug(5006) << "encoding after: " << encoding << endl;
03023 QCString encName;
03024 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
03025 encName = KMMsgBase::encodeRFC2047String( name, encoding );
03026 else
03027 encName = KMMsgBase::encodeRFC2231String( name, encoding );
03028
03029 cDisp += "\n\tfilename";
03030 if ( name != QString( encName ) )
03031 cDisp += "*=" + encName;
03032 else
03033 cDisp += "=\"" + encName + '"';
03034 msgPart->setContentDisposition( cDisp );
03035
03036 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setUncompressedMimeType(
03037 msgPart->typeStr(), msgPart->subtypeStr() );
03038 msgPart->setTypeStr( "application" );
03039 msgPart->setSubtypeStr( "x-zip" );
03040
03041 KMAtmListViewItem* listItem = static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) );
03042 msgPartToItem( msgPart, listItem, false );
03043 }
03044
03045
03046
03047 void KMComposeWin::uncompressAttach( int idx )
03048 {
03049 if (idx < 0) return;
03050
03051 unsigned int i;
03052 for ( i = 0; i < mAtmItemList.count(); ++i )
03053 if ( mAtmItemList.at( i )->itemPos() == idx )
03054 break;
03055
03056 if ( i > mAtmItemList.count() )
03057 return;
03058
03059 KMMessagePart* msgPart;
03060 msgPart = mAtmList.at( i );
03061
03062 QBuffer dev( msgPart->bodyDecodedBinary() );
03063 KZip zip( &dev );
03064 QByteArray decoded;
03065
03066 decoded = msgPart->bodyDecodedBinary();
03067 if ( ! zip.open( IO_ReadOnly ) ) {
03068 KMessageBox::sorry(0, i18n("KMail could not uncompress the file.") );
03069 static_cast<KMAtmListViewItem *>( mAtmItemList.at( i ) )->setCompress( true );
03070 return;
03071 }
03072 const KArchiveDirectory *dir = zip.directory();
03073
03074 KZipFileEntry *entry;
03075 if ( dir->entries().count() != 1 ) {
03076 KMessageBox::sorry(0, i18n("KMail could not uncompress the file.") );
03077 static_cast<KMAtmListViewItem *>( mAtmItemList.at( i ) )->setCompress( true );
03078 return;
03079 }
03080 entry = (KZipFileEntry*)dir->entry( dir->entries()[0] );
03081
03082 msgPart->setCteStr(
03083 static_cast<KMAtmListViewItem*>( mAtmItemList.at(i) )->uncompressedCodec() );
03084
03085 msgPart->setBodyEncodedBinary( entry->data() );
03086 QString name = entry->name();
03087 msgPart->setName( name );
03088
03089 zip.close();
03090
03091 QCString cDisp = "attachment;";
03092 QCString encoding = KMMsgBase::autoDetectCharset( msgPart->charset(),
03093 KMMessage::preferredCharsets(), name );
03094 if ( encoding.isEmpty() ) encoding = "utf-8";
03095
03096 QCString encName;
03097 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
03098 encName = KMMsgBase::encodeRFC2047String( name, encoding );
03099 else
03100 encName = KMMsgBase::encodeRFC2231String( name, encoding );
03101
03102 cDisp += "\n\tfilename";
03103 if ( name != QString( encName ) )
03104 cDisp += "*=" + encName;
03105 else
03106 cDisp += "=\"" + encName + '"';
03107 msgPart->setContentDisposition( cDisp );
03108
03109 QCString type, subtype;
03110 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->uncompressedMimeType( type,
03111 subtype );
03112
03113 msgPart->setTypeStr( type );
03114 msgPart->setSubtypeStr( subtype );
03115
03116 KMAtmListViewItem* listItem = static_cast<KMAtmListViewItem*>(mAtmItemList.at( i ));
03117 msgPartToItem( msgPart, listItem, false );
03118 }
03119
03120
03121
03122 void KMComposeWin::slotAttachView()
03123 {
03124 int i = 0;
03125 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i ) {
03126 if ( (*it)->isSelected() ) {
03127 viewAttach( i );
03128 }
03129 }
03130 }
03131
03132 void KMComposeWin::slotAttachOpen()
03133 {
03134 int i = 0;
03135 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i ) {
03136 if ( (*it)->isSelected() ) {
03137 openAttach( i );
03138 }
03139 }
03140 }
03141
03142
03143 bool KMComposeWin::inlineSigningEncryptionSelected() {
03144 if ( !mSignAction->isChecked() && !mEncryptAction->isChecked() )
03145 return false;
03146 return cryptoMessageFormat() == Kleo::InlineOpenPGPFormat;
03147 }
03148
03149
03150 void KMComposeWin::viewAttach( int index )
03151 {
03152 QString pname;
03153 KMMessagePart* msgPart;
03154 msgPart = mAtmList.at(index);
03155 pname = msgPart->name().stripWhiteSpace();
03156 if (pname.isEmpty()) pname=msgPart->contentDescription();
03157 if (pname.isEmpty()) pname="unnamed";
03158
03159 KTempFile* atmTempFile = new KTempFile();
03160 mAtmTempList.append( atmTempFile );
03161 atmTempFile->setAutoDelete( true );
03162 KPIM::kByteArrayToFile(msgPart->bodyDecodedBinary(), atmTempFile->name(), false, false,
03163 false);
03164 KMReaderMainWin *win = new KMReaderMainWin(msgPart, false,
03165 atmTempFile->name(), pname, mCharset );
03166 win->show();
03167 }
03168
03169
03170 void KMComposeWin::openAttach( int index )
03171 {
03172 KMMessagePart* msgPart = mAtmList.at(index);
03173 const QString contentTypeStr =
03174 ( msgPart->typeStr() + '/' + msgPart->subtypeStr() ).lower();
03175
03176 KMimeType::Ptr mimetype;
03177 mimetype = KMimeType::mimeType( contentTypeStr );
03178
03179 KTempFile* atmTempFile = new KTempFile();
03180 mAtmTempList.append( atmTempFile );
03181 const bool autoDelete = true;
03182 atmTempFile->setAutoDelete( autoDelete );
03183
03184 KURL url;
03185 url.setPath( atmTempFile->name() );
03186
03187 KPIM::kByteArrayToFile( msgPart->bodyDecodedBinary(), atmTempFile->name(), false, false,
03188 false );
03189 if ( ::chmod( QFile::encodeName( atmTempFile->name() ), S_IRUSR ) != 0) {
03190 QFile::remove(url.path());
03191 return;
03192 }
03193
03194 KService::Ptr offer =
03195 KServiceTypeProfile::preferredService( mimetype->name(), "Application" );
03196
03197 if ( !offer || mimetype->name() == "application/octet-stream" ) {
03198 if ( ( !KRun::displayOpenWithDialog( url, autoDelete ) ) && autoDelete ) {
03199 QFile::remove(url.path());
03200 }
03201 }
03202 else {
03203 if ( ( !KRun::run( *offer, url, autoDelete ) ) && autoDelete ) {
03204 QFile::remove( url.path() );
03205 }
03206 }
03207 }
03208
03209
03210 void KMComposeWin::slotAttachSave()
03211 {
03212 KMMessagePart* msgPart;
03213 QString fileName, pname;
03214 int idx = currentAttachmentNum();
03215
03216 if (idx < 0) return;
03217
03218 msgPart = mAtmList.at(idx);
03219 pname = msgPart->name();
03220 if (pname.isEmpty()) pname="unnamed";
03221
03222 KURL url = KFileDialog::getSaveURL(QString::null, QString::null, 0, i18n("Save Attachment As"));
03223
03224 if( url.isEmpty() )
03225 return;
03226
03227 kmkernel->byteArrayToRemoteFile(msgPart->bodyDecodedBinary(), url);
03228 }
03229
03230
03231
03232 void KMComposeWin::slotAttachRemove()
03233 {
03234 bool attachmentRemoved = false;
03235 int i = 0;
03236 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ) {
03237 if ( (*it)->isSelected() ) {
03238 removeAttach( i );
03239 attachmentRemoved = true;
03240 }
03241 else {
03242 ++it;
03243 ++i;
03244 }
03245 }
03246
03247 if ( attachmentRemoved ) {
03248 setModified( true );
03249 slotUpdateAttachActions();
03250 }
03251 }
03252
03253
03254 void KMComposeWin::slotFind()
03255 {
03256 mEditor->search();
03257 }
03258
03259 void KMComposeWin::slotSearchAgain()
03260 {
03261 mEditor->repeatSearch();
03262 }
03263
03264
03265 void KMComposeWin::slotReplace()
03266 {
03267 mEditor->replace();
03268 }
03269
03270
03271 void KMComposeWin::slotUpdateFont()
03272 {
03273 kdDebug() << "KMComposeWin::slotUpdateFont " << endl;
03274 if ( ! mFixedFontAction ) {
03275 return;
03276 }
03277 mEditor->setFont( mFixedFontAction->isChecked() ? mFixedFont : mBodyFont );
03278 }
03279
03280 QString KMComposeWin::quotePrefixName() const
03281 {
03282 if ( !msg() )
03283 return QString::null;
03284
03285 int languageNr = GlobalSettings::self()->replyCurrentLanguage();
03286 ReplyPhrases replyPhrases( QString::number(languageNr) );
03287 replyPhrases.readConfig();
03288 QString quotePrefix = msg()->formatString(
03289 replyPhrases.indentPrefix() );
03290
03291 quotePrefix = msg()->formatString(quotePrefix);
03292 return quotePrefix;
03293 }
03294
03295 void KMComposeWin::slotPasteAsQuotation()
03296 {
03297 if( mEditor->hasFocus() && msg() )
03298 {
03299 QString s = QApplication::clipboard()->text();
03300 if (!s.isEmpty())
03301 mEditor->insert(addQuotesToText(s));
03302 }
03303 }
03304
03305 void KMComposeWin::slotPasteAsAttachment()
03306 {
03307 KURL url( QApplication::clipboard()->text( QClipboard::Clipboard ) );
03308 if ( url.isValid() ) {
03309 addAttach(QApplication::clipboard()->text( QClipboard::Clipboard ) );
03310 return;
03311 }
03312
03313 if ( QApplication::clipboard()->image().isNull() ) {
03314 bool ok;
03315 QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this );
03316 if ( !ok )
03317 return;
03318 KMMessagePart *msgPart = new KMMessagePart;
03319 msgPart->setName(attName);
03320 QValueList<int> dummy;
03321 msgPart->setBodyAndGuessCte(QCString(QApplication::clipboard()->text().latin1()), dummy,
03322 kmkernel->msgSender()->sendQuotedPrintable());
03323 addAttach(msgPart);
03324 }
03325 else
03326 addImageFromClipboard();
03327
03328 }
03329
03330 void KMComposeWin::slotAddQuotes()
03331 {
03332 if( mEditor->hasFocus() && msg() )
03333 {
03334
03335
03336
03337
03338 if ( mEditor->hasMarkedText() ) {
03339 QString s = mEditor->markedText();
03340 if(!s.isEmpty())
03341 mEditor->insert(addQuotesToText(s));
03342 } else {
03343 int l = mEditor->currentLine();
03344 int c = mEditor->currentColumn();
03345 QString s = mEditor->textLine(l);
03346 s.prepend(quotePrefixName());
03347 mEditor->insertLine(s,l);
03348 mEditor->removeLine(l+1);
03349 mEditor->setCursorPosition(l,c+2);
03350 }
03351 }
03352 }
03353
03354 QString KMComposeWin::addQuotesToText(const QString &inputText)
03355 {
03356 QString answer = QString( inputText );
03357 QString indentStr = quotePrefixName();
03358 answer.replace( '\n', '\n' + indentStr);
03359 answer.prepend( indentStr );
03360 answer += '\n';
03361 return KMMessage::smartQuote( answer, GlobalSettings::self()->lineWrapWidth() );
03362 }
03363
03364 QString KMComposeWin::removeQuotesFromText(const QString &inputText)
03365 {
03366 QString s = inputText;
03367
03368
03369 QString quotePrefix = '^' + quotePrefixName();
03370 QRegExp rx(quotePrefix);
03371 s.remove(rx);
03372
03373
03374 quotePrefix = '\n' + quotePrefixName();
03375 rx = quotePrefix;
03376 s.replace(rx, "\n");
03377
03378 return s;
03379 }
03380
03381 void KMComposeWin::slotRemoveQuotes()
03382 {
03383 if( mEditor->hasFocus() && msg() )
03384 {
03385
03386
03387
03388
03389 if ( mEditor->hasMarkedText() ) {
03390 QString s = mEditor->markedText();
03391 mEditor->insert(removeQuotesFromText(s));
03392 } else {
03393 int l = mEditor->currentLine();
03394 int c = mEditor->currentColumn();
03395 QString s = mEditor->textLine(l);
03396 mEditor->insertLine(removeQuotesFromText(s),l);
03397 mEditor->removeLine(l+1);
03398 mEditor->setCursorPosition(l,c-2);
03399 }
03400 }
03401 }
03402
03403
03404 void KMComposeWin::slotUndo()
03405 {
03406 QWidget* fw = focusWidget();
03407 if (!fw) return;
03408
03409 if ( ::qt_cast<KEdit*>(fw) )
03410 static_cast<QTextEdit*>(fw)->undo();
03411 else if (::qt_cast<QLineEdit*>(fw))
03412 static_cast<QLineEdit*>(fw)->undo();
03413 }
03414
03415 void KMComposeWin::slotRedo()
03416 {
03417 QWidget* fw = focusWidget();
03418 if (!fw) return;
03419
03420 if (::qt_cast<KEdit*>(fw))
03421 static_cast<KEdit*>(fw)->redo();
03422 else if (::qt_cast<QLineEdit*>(fw))
03423 static_cast<QLineEdit*>(fw)->redo();
03424 }
03425
03426
03427 void KMComposeWin::slotCut()
03428 {
03429 QWidget* fw = focusWidget();
03430 if (!fw) return;
03431
03432 if (::qt_cast<KEdit*>(fw))
03433 static_cast<KEdit*>(fw)->cut();
03434 else if (::qt_cast<QLineEdit*>(fw))
03435 static_cast<QLineEdit*>(fw)->cut();
03436 }
03437
03438
03439
03440 void KMComposeWin::slotCopy()
03441 {
03442 QWidget* fw = focusWidget();
03443 if (!fw) return;
03444
03445 #ifdef KeyPress
03446 #undef KeyPress
03447 #endif
03448
03449 QKeyEvent k(QEvent::KeyPress, Key_C , 0 , ControlButton);
03450 kapp->notify(fw, &k);
03451 }
03452
03453
03454
03455 void KMComposeWin::slotPaste()
03456 {
03457 QWidget* fw = focusWidget();
03458 if (!fw) return;
03459
03460 if ( ! QApplication::clipboard()->image().isNull() ) {
03461 addImageFromClipboard();
03462 }
03463 else {
03464
03465 #ifdef KeyPress
03466 #undef KeyPress
03467 #endif
03468
03469 QKeyEvent k(QEvent::KeyPress, Key_V , 0 , ControlButton);
03470 kapp->notify(fw, &k);
03471 }
03472
03473 }
03474
03475
03476
03477 void KMComposeWin::slotMarkAll()
03478 {
03479 QWidget* fw = focusWidget();
03480 if (!fw) return;
03481
03482 if (::qt_cast<QLineEdit*>(fw))
03483 static_cast<QLineEdit*>(fw)->selectAll();
03484 else if (::qt_cast<KEdit*>(fw))
03485 static_cast<KEdit*>(fw)->selectAll();
03486 }
03487
03488
03489
03490 void KMComposeWin::slotClose()
03491 {
03492 close(FALSE);
03493 }
03494
03495
03496
03497 void KMComposeWin::slotNewComposer()
03498 {
03499 KMComposeWin* win;
03500 KMMessage* msg = new KMMessage;
03501
03502 msg->initHeader();
03503 win = new KMComposeWin(msg);
03504 win->show();
03505 }
03506
03507
03508
03509 void KMComposeWin::slotNewMailReader()
03510 {
03511 KMMainWin *kmmwin = new KMMainWin(0);
03512 kmmwin->show();
03513
03514 }
03515
03516
03517
03518 void KMComposeWin::slotUpdWinTitle(const QString& text)
03519 {
03520 if (text.isEmpty())
03521 setCaption("("+i18n("unnamed")+")");
03522 else setCaption(text);
03523 }
03524
03525
03526
03527 void KMComposeWin::slotEncryptToggled(bool on)
03528 {
03529 setEncryption( on, true );
03530 }
03531
03532
03533
03534 void KMComposeWin::setEncryption( bool encrypt, bool setByUser )
03535 {
03536 if ( setByUser )
03537 setModified( true );
03538 if ( !mEncryptAction->isEnabled() )
03539 encrypt = false;
03540
03541
03542 else if ( encrypt && encryptToSelf() && !mLastIdentityHasEncryptionKey ) {
03543 if ( setByUser )
03544 KMessageBox::sorry( this,
03545 i18n("<qt><p>You have requested that messages be "
03546 "encrypted to yourself, but the currently selected "
03547 "identity does not define an (OpenPGP or S/MIME) "
03548 "encryption key to use for this.</p>"
03549 "<p>Please select the key(s) to use "
03550 "in the identity configuration.</p>"
03551 "</qt>"),
03552 i18n("Undefined Encryption Key") );
03553 encrypt = false;
03554 }
03555
03556
03557 mEncryptAction->setChecked( encrypt );
03558
03559
03560 if ( encrypt )
03561 mEncryptAction->setIcon("encrypted");
03562 else
03563 mEncryptAction->setIcon("decrypted");
03564
03565
03566 if ( canSignEncryptAttachments() ) {
03567 for ( KMAtmListViewItem* entry =
03568 static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
03569 entry;
03570 entry = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) )
03571 entry->setEncrypt( encrypt );
03572 }
03573 }
03574
03575
03576
03577 void KMComposeWin::slotSignToggled(bool on)
03578 {
03579 setSigning( on, true );
03580 }
03581
03582
03583
03584 void KMComposeWin::setSigning( bool sign, bool setByUser )
03585 {
03586 if ( setByUser )
03587 setModified( true );
03588 if ( !mSignAction->isEnabled() )
03589 sign = false;
03590
03591
03592 if ( sign && !mLastIdentityHasSigningKey ) {
03593 if ( setByUser )
03594 KMessageBox::sorry( this,
03595 i18n("<qt><p>In order to be able to sign "
03596 "this message you first have to "
03597 "define the (OpenPGP or S/MIME) signing key "
03598 "to use.</p>"
03599 "<p>Please select the key to use "
03600 "in the identity configuration.</p>"
03601 "</qt>"),
03602 i18n("Undefined Signing Key") );
03603 sign = false;
03604 }
03605
03606
03607 mSignAction->setChecked( sign );
03608
03609
03610 if ( canSignEncryptAttachments() ) {
03611 for ( KMAtmListViewItem* entry =
03612 static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
03613 entry;
03614 entry = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) )
03615 entry->setSign( sign );
03616 }
03617 }
03618
03619
03620
03621 void KMComposeWin::slotWordWrapToggled(bool on)
03622 {
03623 if (on)
03624 {
03625 mEditor->setWordWrap( QTextEdit::FixedColumnWidth );
03626 mEditor->setWrapColumnOrWidth( GlobalSettings::self()->lineWrapWidth() );
03627 }
03628 else
03629 {
03630 mEditor->setWordWrap( QTextEdit::NoWrap );
03631 }
03632 }
03633
03634
03635
03636 void KMComposeWin::slotPrint()
03637 {
03638 mMessageWasModified = isModified();
03639 connect( this, SIGNAL( applyChangesDone( bool ) ),
03640 this, SLOT( slotContinuePrint( bool ) ) );
03641 applyChanges( true );
03642 }
03643
03644 void KMComposeWin::slotContinuePrint( bool rc )
03645 {
03646 disconnect( this, SIGNAL( applyChangesDone( bool ) ),
03647 this, SLOT( slotContinuePrint( bool ) ) );
03648
03649 if( rc ) {
03650 if ( mComposedMessages.isEmpty() ) {
03651 kdDebug(5006) << "Composing the message failed." << endl;
03652 return;
03653 }
03654 KMCommand *command = new KMPrintCommand( this, mComposedMessages.first() );
03655 command->start();
03656 setModified( mMessageWasModified );
03657 }
03658 }
03659
03660
03661 bool KMComposeWin::validateAddresses( QWidget * parent, const QString & addresses )
03662 {
03663 QString brokenAddress;
03664 KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( KMMessage::expandAliases( addresses ), brokenAddress );
03665 if ( !( errorCode == KPIM::AddressOk || errorCode == KPIM::AddressEmpty ) ) {
03666 QString errorMsg( "<qt><p><b>" + brokenAddress +
03667 "</b></p><p>" + KPIM::emailParseResultToString( errorCode ) +
03668 "</p></qt>" );
03669 KMessageBox::sorry( parent, errorMsg, i18n("Invalid Email Address") );
03670 return false;
03671 }
03672 return true;
03673 }
03674
03675
03676 void KMComposeWin::doSend( KMail::MessageSender::SendMethod method, bool saveInDrafts)
03677 {
03678 if ( method != KMail::MessageSender::SendLater && kmkernel->isOffline() ) {
03679 KMessageBox::information( this,
03680 i18n("KMail is currently in offline mode,"
03681 "your messages will be kept in the outbox until you go online."),
03682 i18n("Online/Offline"), "kmailIsOffline" );
03683 mSendMethod = KMail::MessageSender::SendLater;
03684 } else {
03685 mSendMethod = method;
03686 }
03687 mSaveInDrafts = saveInDrafts;
03688
03689 if (!saveInDrafts)
03690 {
03691 if ( KPIM::getFirstEmailAddress( from() ).isEmpty() ) {
03692 if ( !( mShowHeaders & HDR_FROM ) ) {
03693 mShowHeaders |= HDR_FROM;
03694 rethinkFields( false );
03695 }
03696 mEdtFrom->setFocus();
03697 KMessageBox::sorry( this,
03698 i18n("You must enter your email address in the "
03699 "From: field. You should also set your email "
03700 "address for all identities, so that you do "
03701 "not have to enter it for each message.") );
03702 return;
03703 }
03704 if (to().isEmpty() && cc().isEmpty() && bcc().isEmpty())
03705 {
03706 if ( mEdtTo ) mEdtTo->setFocus();
03707 KMessageBox::information( this,
03708 i18n("You must specify at least one receiver,"
03709 "either in the To: field or as CC or as BCC.") );
03710 return;
03711 }
03712
03713
03714 if ( !validateAddresses( this, to().stripWhiteSpace() ) ) {
03715 return;
03716 }
03717
03718 if ( !validateAddresses( this, cc().stripWhiteSpace() ) ) {
03719 return;
03720 }
03721
03722 if ( !validateAddresses( this, bcc().stripWhiteSpace() ) ) {
03723 return;
03724 }
03725
03726 if (subject().isEmpty())
03727 {
03728 mEdtSubject->setFocus();
03729 int rc =
03730 KMessageBox::questionYesNo( this,
03731 i18n("You did not specify a subject. "
03732 "Send message anyway?"),
03733 i18n("No Subject Specified"),
03734 i18n("S&end as Is"),
03735 i18n("&Specify the Subject"),
03736 "no_subject_specified" );
03737 if( rc == KMessageBox::No )
03738 {
03739 return;
03740 }
03741 }
03742
03743 if ( userForgotAttachment() )
03744 return;
03745 }
03746
03747 KCursorSaver busy(KBusyPtr::busy());
03748 mMsg->setDateToday();
03749
03750
03751
03752
03753
03754
03755 QString hf = mMsg->headerField("X-KMail-Transport");
03756 if ((mTransport->currentText() != mTransport->text(0)) ||
03757 (!hf.isEmpty() && (hf != mTransport->text(0))))
03758 mMsg->setHeaderField("X-KMail-Transport", mTransport->currentText());
03759
03760 mDisableBreaking = saveInDrafts;
03761
03762 const bool neverEncrypt = ( saveInDrafts && GlobalSettings::self()->neverEncryptDrafts() )
03763 || mSigningAndEncryptionExplicitlyDisabled;
03764 connect( this, SIGNAL( applyChangesDone( bool ) ),
03765 SLOT( slotContinueDoSend( bool ) ) );
03766
03767 if ( mEditor->textFormat() == Qt::RichText )
03768 mMsg->setHeaderField( "X-KMail-Markup", "true" );
03769 else
03770 mMsg->removeHeaderField( "X-KMail-Markup" );
03771 if ( mEditor->textFormat() == Qt::RichText && inlineSigningEncryptionSelected() ) {
03772 QString keepBtnText = mEncryptAction->isChecked() ?
03773 mSignAction->isChecked() ? i18n( "&Keep markup, do not sign/encrypt" )
03774 : i18n( "&Keep markup, do not encrypt" )
03775 : i18n( "&Keep markup, do not sign" );
03776 QString yesBtnText = mEncryptAction->isChecked() ?
03777 mSignAction->isChecked() ? i18n("Sign/Encrypt (delete markup)")
03778 : i18n( "Encrypt (delete markup)" )
03779 : i18n( "Sign (delete markup)" );
03780 int ret = KMessageBox::warningYesNoCancel(this,
03781 i18n("<qt><p>Inline signing/encrypting of HTML messages is not possible;</p>"
03782 "<p>do you want to delete your markup?</p></qt>"),
03783 i18n("Sign/Encrypt Message?"),
03784 KGuiItem( yesBtnText ),
03785 KGuiItem( keepBtnText ) );
03786 if ( KMessageBox::Cancel == ret )
03787 return;
03788 if ( KMessageBox::No == ret ) {
03789 mEncryptAction->setChecked(false);
03790 mSignAction->setChecked(false);
03791 }
03792 else {
03793 toggleMarkup(false);
03794 }
03795 }
03796
03797 kdDebug(5006) << "KMComposeWin::doSend() - calling applyChanges()"
03798 << endl;
03799 applyChanges( neverEncrypt );
03800 }
03801
03802 void KMComposeWin::slotContinueDoSend( bool sentOk )
03803 {
03804 kdDebug(5006) << "KMComposeWin::slotContinueDoSend( " << sentOk << " )"
03805 << endl;
03806 disconnect( this, SIGNAL( applyChangesDone( bool ) ),
03807 this, SLOT( slotContinueDoSend( bool ) ) );
03808
03809 if ( !sentOk ) {
03810 mDisableBreaking = false;
03811 return;
03812 }
03813
03814 for ( QValueVector<KMMessage*>::iterator it = mComposedMessages.begin() ; it != mComposedMessages.end() ; ++it ) {
03815
03816
03817 (*it)->cleanupHeader();
03818
03819
03820 (*it)->setComplete( true );
03821
03822 if (mSaveInDrafts) {
03823 KMFolder* draftsFolder = 0, *imapDraftsFolder = 0;
03824
03825 if ( !(*it)->drafts().isEmpty() ) {
03826 draftsFolder = kmkernel->folderMgr()->findIdString( (*it)->drafts() );
03827 if ( draftsFolder == 0 )
03828
03829
03830 draftsFolder = kmkernel->dimapFolderMgr()->findIdString( (*it)->drafts() );
03831 if ( draftsFolder == 0 )
03832 imapDraftsFolder = kmkernel->imapFolderMgr()->findIdString( (*it)->drafts() );
03833 if ( !draftsFolder && !imapDraftsFolder ) {
03834 const KPIM::Identity & id = kmkernel->identityManager()
03835 ->identityForUoidOrDefault( (*it)->headerField( "X-KMail-Identity" ).stripWhiteSpace().toUInt() );
03836 KMessageBox::information(0, i18n("The custom drafts folder for identity "
03837 "\"%1\" does not exist (anymore); "
03838 "therefore, the default drafts folder "
03839 "will be used.")
03840 .arg( id.identityName() ) );
03841 }
03842 }
03843 if (imapDraftsFolder && imapDraftsFolder->noContent())
03844 imapDraftsFolder = 0;
03845
03846 if ( draftsFolder == 0 ) {
03847 draftsFolder = kmkernel->draftsFolder();
03848 } else {
03849 draftsFolder->open();
03850 }
03851 kdDebug(5006) << "saveindrafts: drafts=" << draftsFolder->name() << endl;
03852 if (imapDraftsFolder)
03853 kdDebug(5006) << "saveindrafts: imapdrafts="
03854 << imapDraftsFolder->name() << endl;
03855
03856 sentOk = !(draftsFolder->addMsg((*it)));
03857
03858
03859 draftsFolder->unGetMsg(draftsFolder->count() - 1);
03860 (*it) = draftsFolder->getMsg(draftsFolder->count() - 1);
03861
03862 if (imapDraftsFolder) {
03863
03864 imapDraftsFolder->moveMsg((*it));
03865 (static_cast<KMFolderImap*>(imapDraftsFolder->storage()))->getFolder();
03866 }
03867
03868 } else {
03869 (*it)->setTo( KMMessage::expandAliases( to() ));
03870 (*it)->setCc( KMMessage::expandAliases( cc() ));
03871 if( !mComposer->originalBCC().isEmpty() )
03872 (*it)->setBcc( KMMessage::expandAliases( mComposer->originalBCC() ));
03873 QString recips = (*it)->headerField( "X-KMail-Recipients" );
03874 if( !recips.isEmpty() ) {
03875 (*it)->setHeaderField( "X-KMail-Recipients", KMMessage::expandAliases( recips ), KMMessage::Address );
03876 }
03877 (*it)->cleanupHeader();
03878 sentOk = kmkernel->msgSender()->send((*it), mSendMethod);
03879 }
03880
03881 if (!sentOk)
03882 return;
03883
03884 *it = 0;
03885 }
03886
03887 RecentAddresses::self( KMKernel::config() )->add( bcc() );
03888 RecentAddresses::self( KMKernel::config() )->add( cc() );
03889 RecentAddresses::self( KMKernel::config() )->add( to() );
03890
03891 setModified( false );
03892 mAutoDeleteMsg = FALSE;
03893 mFolder = 0;
03894 cleanupAutoSave();
03895 close();
03896 return;
03897 }
03898
03899
03900
03901
03902 void KMComposeWin::slotSendLater()
03903 {
03904 if ( mEditor->checkExternalEditorFinished() )
03905 doSend( KMail::MessageSender::SendLater );
03906 }
03907
03908
03909
03910 void KMComposeWin::slotSaveDraft() {
03911 if ( mEditor->checkExternalEditorFinished() )
03912 doSend( KMail::MessageSender::SendLater, true );
03913 }
03914
03915
03916
03917 void KMComposeWin::slotSendNowVia( int item )
03918 {
03919 QStringList availTransports= KMail::TransportManager::transportNames();
03920 QString customTransport = availTransports[ item ];
03921
03922 mTransport->setCurrentText( customTransport );
03923 slotSendNow();
03924 }
03925
03926
03927 void KMComposeWin::slotSendLaterVia( int item )
03928 {
03929 QStringList availTransports= KMail::TransportManager::transportNames();
03930 QString customTransport = availTransports[ item ];
03931
03932 mTransport->setCurrentText( customTransport );
03933 slotSendLater();
03934 }
03935
03936
03937
03938 void KMComposeWin::slotSendNow() {
03939 if ( !mEditor->checkExternalEditorFinished() )
03940 return;
03941 if ( GlobalSettings::self()->confirmBeforeSend() )
03942 {
03943 int rc = KMessageBox::warningYesNoCancel( mMainWidget,
03944 i18n("About to send email..."),
03945 i18n("Send Confirmation"),
03946 i18n("&Send Now"),
03947 i18n("Send &Later") );
03948
03949 if ( rc == KMessageBox::Yes )
03950 doSend( KMail::MessageSender::SendImmediate );
03951 else if ( rc == KMessageBox::No )
03952 doSend( KMail::MessageSender::SendLater );
03953 }
03954 else
03955 doSend( KMail::MessageSender::SendImmediate );
03956 }
03957
03958
03959
03960 void KMComposeWin::slotAppendSignature()
03961 {
03962 bool mod = mEditor->isModified();
03963
03964 const KPIM::Identity & ident =
03965 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
03966 mOldSigText = ident.signatureText();
03967 if( !mOldSigText.isEmpty() )
03968 {
03969 mEditor->append(mOldSigText);
03970 mEditor->setModified(mod);
03971 mEditor->setContentsPos( 0, 0 );
03972 mEditor->sync();
03973 }
03974 }
03975
03976
03977
03978 void KMComposeWin::slotHelp()
03979 {
03980 kapp->invokeHelp();
03981 }
03982
03983
03984 void KMComposeWin::slotCleanSpace()
03985 {
03986
03987
03988
03989
03990
03991
03992
03993
03994 QString s;
03995 if ( mEditor->hasMarkedText() ) {
03996 s = mEditor->markedText();
03997 if( s.isEmpty() )
03998 return;
03999 } else {
04000 s = mEditor->text();
04001 }
04002
04003
04004 QString sig;
04005 bool restore = false;
04006 const KPIM::Identity & ident =
04007 kmkernel->identityManager()->identityForUoid( mId );
04008 if ( !ident.isNull() ) {
04009 sig = ident.signatureText();
04010 if( !sig.isEmpty() ) {
04011 if( s.endsWith( sig ) ) {
04012 s.truncate( s.length() - sig.length() );
04013 restore = true;
04014 }
04015 }
04016 }
04017
04018
04019 QRegExp squeeze( "[\t, ]+" );
04020 s.replace( squeeze, QChar( ' ' ) );
04021
04022
04023 QRegExp trailing( "\\s+$" );
04024 s.replace( trailing, QChar( '\n' ) );
04025
04026
04027 QRegExp singleSpace( "[\n]{2,}" );
04028 s.replace( singleSpace, QChar( '\n' ) );
04029
04030
04031 if ( restore )
04032 s.append( sig );
04033
04034
04035
04036
04037
04038
04039
04040
04041 if ( !mEditor->hasMarkedText() )
04042 mEditor->clear();
04043 mEditor->insert( s );
04044 }
04045
04046
04047 void KMComposeWin::slotToggleMarkup()
04048 {
04049 if ( markupAction->isChecked() ) {
04050 mHtmlMarkup = true;
04051 toolBar("htmlToolBar")->show();
04052
04053 fontChanged( mEditor->currentFont().family() );
04054 fontAction->setFont( mEditor->currentFont().family() );
04055 fontSizeAction->setFontSize( mEditor->currentFont().pointSize() );
04056 mSaveFont = mEditor->currentFont();
04057 }
04058 else
04059 toggleMarkup(false);
04060
04061 }
04062
04063 void KMComposeWin::toggleMarkup(bool markup)
04064 {
04065 if ( markup ) {
04066 if ( !mUseHTMLEditor ) {
04067 kdDebug(5006) << "setting RichText editor" << endl;
04068 mUseHTMLEditor = true;
04069 mHtmlMarkup = true;
04070
04071
04072 int paraFrom, indexFrom, paraTo, indexTo;
04073 mEditor->getSelection ( ¶From, &indexFrom, ¶To, &indexTo);
04074 mEditor->selectAll();
04075
04076 bool _bold = textBoldAction->isChecked();
04077 bool _italic = textItalicAction->isChecked();
04078 mEditor->setColor(QColor(0,0,0));
04079 textBoldAction->setChecked(_bold);
04080 textItalicAction->setChecked(_italic);
04081 mEditor->setSelection ( paraFrom, indexFrom, paraTo, indexTo);
04082
04083 mEditor->setTextFormat(Qt::RichText);
04084 mEditor->setModified(true);
04085 markupAction->setChecked(true);
04086 toolBar( "htmlToolBar" )->show();
04087 mEditor->deleteAutoSpellChecking();
04088 mAutoSpellCheckingAction->setChecked(false);
04089 slotAutoSpellCheckingToggled(false);
04090 }
04091 } else {
04092 kdDebug(5006) << "setting PlainText editor" << endl;
04093 mHtmlMarkup = false;
04094 toolBar("htmlToolBar")->hide();
04095 if ( mUseHTMLEditor ) {
04096 mUseHTMLEditor = false;
04097 mEditor->setTextFormat(Qt::PlainText);
04098 QString text = mEditor->text();
04099 mEditor->setText(text);
04100 mEditor->setModified(true);
04101 slotAutoSpellCheckingToggled(true);
04102 }
04103 }
04104 }
04105
04106 void KMComposeWin::slotSubjectTextSpellChecked()
04107 {
04108 mSubjectTextWasSpellChecked = true;
04109 }
04110
04111
04112 void KMComposeWin::slotAutoSpellCheckingToggled( bool on )
04113 {
04114 if ( mEditor->autoSpellChecking(on) == -1 )
04115 mAutoSpellCheckingAction->setChecked(false);
04116 }
04117
04118 void KMComposeWin::slotSpellcheck()
04119 {
04120 if (mSpellCheckInProgress) return;
04121 mSubjectTextWasSpellChecked = false;
04122 mSpellCheckInProgress=TRUE;
04123
04124
04125
04126
04127
04128 mEditor->spellcheck();
04129 }
04130
04131 void KMComposeWin::polish()
04132 {
04133
04134 markupAction->setChecked(mHtmlMarkup);
04135 if (mHtmlMarkup)
04136 toolBar("htmlToolBar")->show();
04137 else
04138 toolBar("htmlToolBar")->hide();
04139 KMail::Composer::polish();
04140 }
04141
04142
04143 void KMComposeWin::slotSpellcheckDone(int result)
04144 {
04145 kdDebug(5006) << "spell check complete: result = " << result << endl;
04146 mSpellCheckInProgress=FALSE;
04147
04148 switch( result )
04149 {
04150 case KS_CANCEL:
04151 statusBar()->changeItem(i18n(" Spell check canceled."),0);
04152 break;
04153 case KS_STOP:
04154 statusBar()->changeItem(i18n(" Spell check stopped."),0);
04155 break;
04156 default:
04157 statusBar()->changeItem(i18n(" Spell check complete."),0);
04158 break;
04159 }
04160 QTimer::singleShot( 2000, this, SLOT(slotSpellcheckDoneClearStatus()) );
04161 }
04162
04163 void KMComposeWin::slotSpellcheckDoneClearStatus()
04164 {
04165 statusBar()->changeItem("", 0);
04166 }
04167
04168
04169
04170 void KMComposeWin::slotIdentityChanged( uint uoid )
04171 {
04172 const KPIM::Identity & ident =
04173 kmkernel->identityManager()->identityForUoid( uoid );
04174 if( ident.isNull() ) return;
04175
04176 if( !ident.fullEmailAddr().isNull() )
04177 mEdtFrom->setText(ident.fullEmailAddr());
04178
04179 if ( KPIM::getFirstEmailAddress( from() ).isEmpty() )
04180 mShowHeaders |= HDR_FROM;
04181 if ( mEdtReplyTo ) mEdtReplyTo->setText(ident.replyToAddr());
04182
04183 if ( mRecipientsEditor ) {
04184
04185 const KPIM::Identity & oldIdentity =
04186 kmkernel->identityManager()->identityForUoidOrDefault( mId );
04187 if ( oldIdentity.bcc() != ident.bcc() ) {
04188 mRecipientsEditor->removeRecipient( oldIdentity.bcc(), Recipient::Bcc );
04189 mRecipientsEditor->addRecipient( ident.bcc(), Recipient::Bcc );
04190 }
04191 }
04192
04193
04194
04195 if( mEdtBcc && !mEdtBcc->edited() && !ident.bcc().isEmpty() ) {
04196
04197
04198 if( !mEdtBcc->text().isEmpty() && mEdtBcc->text() != ident.bcc() && !mEdtBcc->edited() ) {
04199 mEdtBcc->setText( ident.bcc() );
04200 } else {
04201
04202
04203
04204 if ( mEdtBcc->text() != ident.bcc() && !mEdtBcc->text().isEmpty() ) {
04205 QString temp_string( mEdtBcc->text() + QString::fromLatin1(",") + ident.bcc() );
04206 mEdtBcc->setText( temp_string );
04207 } else {
04208
04209
04210 mEdtBcc->setText( ident.bcc() );
04211 }
04212 }
04213 }
04214
04215
04216
04217 if( mEdtBcc && mEdtBcc->edited() && !ident.bcc().isEmpty() ) {
04218 if( !mEdtBcc->text().isEmpty() ) {
04219 QString temp_string ( mEdtBcc->text() + QString::fromLatin1(",") + ident.bcc() );
04220 mEdtBcc->setText( temp_string );
04221 } else {
04222 mEdtBcc->setText( ident.bcc() );
04223 }
04224 }
04225
04226
04227
04228 if( mEdtBcc && !mEdtBcc->edited() && ident.bcc().isEmpty() ) {
04229 mEdtBcc->setText( ident.bcc() );
04230 }
04231
04232 if ( !ident.bcc().isEmpty() ) {
04233 mShowHeaders |= HDR_BCC;
04234 }
04235
04236 if ( ident.organization().isEmpty() )
04237 mMsg->removeHeaderField("Organization");
04238 else
04239 mMsg->setHeaderField("Organization", ident.organization());
04240
04241 if (!ident.isXFaceEnabled() || ident.xface().isEmpty())
04242 mMsg->removeHeaderField("X-Face");
04243 else
04244 {
04245 QString xface = ident.xface();
04246 if (!xface.isEmpty())
04247 {
04248 int numNL = ( xface.length() - 1 ) / 70;
04249 for ( int i = numNL; i > 0; --i )
04250 xface.insert( i*70, "\n\t" );
04251 mMsg->setHeaderField("X-Face", xface);
04252 }
04253 }
04254
04255 if ( !mBtnTransport->isChecked() ) {
04256 QString transp = ident.transport();
04257 if ( transp.isEmpty() )
04258 {
04259 mMsg->removeHeaderField("X-KMail-Transport");
04260 transp = mTransport->text(0);
04261 }
04262 else
04263 mMsg->setHeaderField("X-KMail-Transport", transp);
04264 bool found = false;
04265 int i;
04266 for (i = 0; i < mTransport->count(); i++) {
04267 if (mTransport->text(i) == transp) {
04268 found = true;
04269 mTransport->setCurrentItem(i);
04270 break;
04271 }
04272 }
04273 if (found == false) {
04274 if (i == mTransport->maxCount()) mTransport->setMaxCount(i + 1);
04275 mTransport->insertItem(transp,i);
04276 mTransport->setCurrentItem(i);
04277 }
04278 }
04279
04280 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
04281
04282 if ( !mBtnFcc->isChecked() ) {
04283 setFcc( ident.fcc() );
04284 }
04285
04286 QString edtText = mEditor->text();
04287 bool appendNewSig = true;
04288
04289 if( !mOldSigText.isEmpty() )
04290 {
04291 if( edtText.endsWith( mOldSigText ) )
04292 edtText.truncate( edtText.length() - mOldSigText.length() );
04293 else
04294 appendNewSig = false;
04295 }
04296
04297 mOldSigText = ident.signatureText();
04298 if( appendNewSig )
04299 {
04300 if( (!mOldSigText.isEmpty()) &&
04301 (GlobalSettings::self()->autoTextSignature()=="auto") )
04302 edtText.append( mOldSigText );
04303 mEditor->setText( edtText );
04304 }
04305
04306
04307
04308 bool bNewIdentityHasSigningKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
04309 bool bNewIdentityHasEncryptionKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
04310 mAttachMPK->setEnabled( Kleo::CryptoBackendFactory::instance()->openpgp() &&
04311 !ident.pgpEncryptionKey().isEmpty() );
04312
04313 if ( !bNewIdentityHasEncryptionKey && mLastIdentityHasEncryptionKey ) {
04314 mLastEncryptActionState = mEncryptAction->isChecked();
04315 setEncryption( false );
04316 }
04317 if ( !bNewIdentityHasSigningKey && mLastIdentityHasSigningKey ) {
04318 mLastSignActionState = mSignAction->isChecked();
04319 setSigning( false );
04320 }
04321
04322 if ( bNewIdentityHasEncryptionKey && !mLastIdentityHasEncryptionKey )
04323 setEncryption( mLastEncryptActionState );
04324 if ( bNewIdentityHasSigningKey && !mLastIdentityHasSigningKey )
04325 setSigning( mLastSignActionState );
04326
04327 mLastIdentityHasSigningKey = bNewIdentityHasSigningKey;
04328 mLastIdentityHasEncryptionKey = bNewIdentityHasEncryptionKey;
04329
04330 setModified( true );
04331 mId = uoid;
04332
04333
04334 rethinkFields( false );
04335 }
04336
04337
04338 void KMComposeWin::slotSpellcheckConfig()
04339 {
04340 KDialogBase dlg(KDialogBase::Plain, i18n("Spellchecker"),
04341 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok,
04342 this, 0, true, true );
04343 KWin kwin;
04344 QTabDialog qtd (this, "tabdialog", true);
04345 KSpellConfig mKSpellConfig (&qtd);
04346 mKSpellConfig.layout()->setMargin( KDialog::marginHint() );
04347
04348 qtd.addTab (&mKSpellConfig, i18n("Spellchecker"));
04349 qtd.setCancelButton ();
04350
04351 kwin.setIcons (qtd.winId(), kapp->icon(), kapp->miniIcon());
04352 qtd.setCancelButton(KStdGuiItem::cancel().text());
04353 qtd.setOkButton(KStdGuiItem::ok().text());
04354
04355 if (qtd.exec())
04356 mKSpellConfig.writeGlobalSettings();
04357 }
04358
04359
04360 void KMComposeWin::slotStatusMessage(const QString &message)
04361 {
04362 statusBar()->changeItem( message, 0 );
04363 }
04364
04365 void KMComposeWin::slotEditToolbars()
04366 {
04367 saveMainWindowSettings(KMKernel::config(), "Composer");
04368 KEditToolbar dlg(guiFactory(), this);
04369
04370 connect( &dlg, SIGNAL(newToolbarConfig()),
04371 SLOT(slotUpdateToolbars()) );
04372
04373 dlg.exec();
04374 }
04375
04376 void KMComposeWin::slotUpdateToolbars()
04377 {
04378 createGUI("kmcomposerui.rc");
04379 applyMainWindowSettings(KMKernel::config(), "Composer");
04380 }
04381
04382 void KMComposeWin::slotEditKeys()
04383 {
04384 KKeyDialog::configure( actionCollection(),
04385 false
04386 );
04387 }
04388
04389 void KMComposeWin::setReplyFocus( bool hasMessage )
04390 {
04391 mEditor->setFocus();
04392 if ( hasMessage )
04393 mEditor->setCursorPosition( 1, 0 );
04394 }
04395
04396 void KMComposeWin::setFocusToSubject()
04397 {
04398 mEdtSubject->setFocus();
04399 }
04400
04401 int KMComposeWin::autoSaveInterval() const
04402 {
04403 return GlobalSettings::self()->autosaveInterval() * 1000 * 60;
04404 }
04405
04406 void KMComposeWin::initAutoSave()
04407 {
04408 kdDebug(5006) << k_funcinfo << endl;
04409
04410 KMFolderMaildir::createMaildirFolders( KMKernel::localDataPath() + "autosave" );
04411 if ( mAutoSaveFilename.isEmpty() ) {
04412 mAutoSaveFilename = KMFolderMaildir::constructValidFileName();
04413 }
04414
04415 updateAutoSave();
04416 }
04417
04418 void KMComposeWin::updateAutoSave()
04419 {
04420 if ( autoSaveInterval() == 0 ) {
04421 delete mAutoSaveTimer; mAutoSaveTimer = 0;
04422 }
04423 else {
04424 if ( !mAutoSaveTimer ) {
04425 mAutoSaveTimer = new QTimer( this );
04426 connect( mAutoSaveTimer, SIGNAL( timeout() ),
04427 this, SLOT( autoSaveMessage() ) );
04428 }
04429 mAutoSaveTimer->start( autoSaveInterval() );
04430 }
04431 }
04432
04433 void KMComposeWin::setAutoSaveFilename( const QString & filename )
04434 {
04435 if ( !mAutoSaveFilename.isEmpty() )
04436 KMFolderMaildir::removeFile( KMKernel::localDataPath() + "autosave",
04437 mAutoSaveFilename );
04438 mAutoSaveFilename = filename;
04439 }
04440
04441 void KMComposeWin::cleanupAutoSave()
04442 {
04443 delete mAutoSaveTimer; mAutoSaveTimer = 0;
04444 if ( !mAutoSaveFilename.isEmpty() ) {
04445 kdDebug(5006) << k_funcinfo << "deleting autosave file "
04446 << mAutoSaveFilename << endl;
04447 KMFolderMaildir::removeFile( KMKernel::localDataPath() + "autosave",
04448 mAutoSaveFilename );
04449 mAutoSaveFilename = QString();
04450 }
04451 }
04452
04453 void KMComposeWin::slotCompletionModeChanged( KGlobalSettings::Completion mode)
04454 {
04455 GlobalSettings::self()->setCompletionMode( (int) mode );
04456
04457
04458 mEdtFrom->setCompletionMode( mode );
04459 mEdtReplyTo->setCompletionMode( mode );
04460 if ( mClassicalRecipients ) {
04461 mEdtTo->setCompletionMode( mode );
04462 mEdtCc->setCompletionMode( mode );
04463 mEdtBcc->setCompletionMode( mode );
04464 }
04465 }
04466
04467 void KMComposeWin::slotConfigChanged()
04468 {
04469 readConfig();
04470 updateAutoSave();
04471 rethinkFields();
04472 }
04473
04474
04475
04476
04477
04478 void KMComposeWin::slotFolderRemoved(KMFolder* folder)
04479 {
04480 if ( (mFolder) && (folder->idString() == mFolder->idString()) )
04481 {
04482 mFolder = kmkernel->draftsFolder();
04483 kdDebug(5006) << "restoring drafts to " << mFolder->idString() << endl;
04484 }
04485 if (mMsg) mMsg->setParent(0);
04486 }
04487
04488
04489 void KMComposeWin::editorFocusChanged(bool gained)
04490 {
04491 mPasteQuotation->setEnabled(gained);
04492 mAddQuoteChars->setEnabled(gained);
04493 mRemQuoteChars->setEnabled(gained);
04494 }
04495
04496 void KMComposeWin::slotSetAlwaysSend( bool bAlways )
04497 {
04498 mAlwaysSend = bAlways;
04499 }
04500
04501 void KMComposeWin::slotListAction( const QString& style )
04502 {
04503 toggleMarkup(true);
04504 if ( style == i18n( "Standard" ) )
04505 mEditor->setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc );
04506 else if ( style == i18n( "Bulleted List (Disc)" ) )
04507 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc );
04508 else if ( style == i18n( "Bulleted List (Circle)" ) )
04509 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListCircle );
04510 else if ( style == i18n( "Bulleted List (Square)" ) )
04511 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListSquare );
04512 else if ( style == i18n( "Ordered List (Decimal)" ))
04513 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal );
04514 else if ( style == i18n( "Ordered List (Alpha lower)" ) )
04515 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha );
04516 else if ( style == i18n( "Ordered List (Alpha upper)" ) )
04517 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha );
04518 mEditor->viewport()->setFocus();
04519 }
04520
04521 void KMComposeWin::slotFontAction( const QString& font)
04522 {
04523 toggleMarkup(true);
04524 mEditor->QTextEdit::setFamily( font );
04525 mEditor->viewport()->setFocus();
04526 }
04527
04528 void KMComposeWin::slotSizeAction( int size )
04529 {
04530 toggleMarkup(true);
04531 mEditor->setPointSize( size );
04532 mEditor->viewport()->setFocus();
04533 }
04534
04535 void KMComposeWin::slotAlignLeft()
04536 {
04537 toggleMarkup(true);
04538 mEditor->QTextEdit::setAlignment( AlignLeft );
04539 }
04540
04541 void KMComposeWin::slotAlignCenter()
04542 {
04543 toggleMarkup(true);
04544 mEditor->QTextEdit::setAlignment( AlignHCenter );
04545 }
04546
04547 void KMComposeWin::slotAlignRight()
04548 {
04549 toggleMarkup(true);
04550 mEditor->QTextEdit::setAlignment( AlignRight );
04551 }
04552
04553 void KMComposeWin::slotTextBold()
04554 {
04555 toggleMarkup(true);
04556 mEditor->QTextEdit::setBold( textBoldAction->isChecked() );
04557 }
04558
04559 void KMComposeWin::slotTextItalic()
04560 {
04561 toggleMarkup(true);
04562 mEditor->QTextEdit::setItalic( textItalicAction->isChecked() );
04563 }
04564
04565 void KMComposeWin::slotTextUnder()
04566 {
04567 toggleMarkup(true);
04568 mEditor->QTextEdit::setUnderline( textUnderAction->isChecked() );
04569 }
04570
04571 void KMComposeWin::slotFormatReset()
04572 {
04573 mEditor->setColor(mForeColor);
04574 mEditor->setCurrentFont( mSaveFont );
04575 }
04576 void KMComposeWin::slotTextColor()
04577 {
04578 QColor color = mEditor->color();
04579
04580 if ( KColorDialog::getColor( color, this ) ) {
04581 toggleMarkup(true);
04582 mEditor->setColor( color );
04583 }
04584 }
04585
04586 void KMComposeWin::fontChanged( const QFont &f )
04587 {
04588 QFontDatabase *fontdb = new QFontDatabase();
04589
04590 if ( fontdb->bold(f.family(), "Bold") ) {
04591 textBoldAction->setChecked( f.bold() );
04592 textBoldAction->setEnabled(true);
04593 }
04594 else
04595 textBoldAction->setEnabled(false);
04596
04597 if ( fontdb->italic(f.family(), "Italic") ) {
04598 textItalicAction->setChecked( f.italic() );
04599 textItalicAction->setEnabled(true);
04600 }
04601 else
04602 textItalicAction->setEnabled(false);
04603
04604 textUnderAction->setChecked( f.underline() );
04605
04606 fontAction->setFont( f.family() );
04607 fontSizeAction->setFontSize( f.pointSize() );
04608 delete fontdb;
04609 }
04610
04611 void KMComposeWin::alignmentChanged( int a )
04612 {
04613
04614 alignLeftAction->setChecked( ( a == AlignAuto ) || ( a & AlignLeft ) );
04615 alignCenterAction->setChecked( ( a & AlignHCenter ) );
04616 alignRightAction->setChecked( ( a & AlignRight ) );
04617 }
04618
04619 namespace {
04620 class KToggleActionResetter {
04621 KToggleAction * mAction;
04622 bool mOn;
04623 public:
04624 KToggleActionResetter( KToggleAction * action, bool on )
04625 : mAction( action ), mOn( on ) {}
04626 ~KToggleActionResetter() {
04627 if ( mAction )
04628 mAction->setChecked( mOn );
04629 }
04630 void disable() { mAction = 0; }
04631 };
04632 }
04633
04634 void KMComposeWin::slotEncryptChiasmusToggled( bool on ) {
04635 mEncryptWithChiasmus = false;
04636
04637 if ( !on )
04638 return;
04639
04640 KToggleActionResetter resetter( mEncryptChiasmusAction, false );
04641
04642 const Kleo::CryptoBackend::Protocol * chiasmus =
04643 Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" );
04644
04645 if ( !chiasmus ) {
04646 const QString msg = Kleo::CryptoBackendFactory::instance()->knowsAboutProtocol( "Chiasmus" )
04647 ? i18n( "Please configure a Crypto Backend to use for "
04648 "Chiasmus encryption first.\n"
04649 "You can do this in the Crypto Backends tab of "
04650 "the configure dialog's Security page." )
04651 : i18n( "It looks as though libkleopatra was compiled without "
04652 "Chiasmus support. You might want to recompile "
04653 "libkleopatra with --enable-chiasmus.");
04654 KMessageBox::information( this, msg, i18n("No Chiasmus Backend Configured" ) );
04655 return;
04656 }
04657
04658 STD_NAMESPACE_PREFIX auto_ptr<Kleo::SpecialJob> job( chiasmus->specialJob( "x-obtain-keys", QMap<QString,QVariant>() ) );
04659 if ( !job.get() ) {
04660 const QString msg = i18n( "Chiasmus backend does not offer the "
04661 "\"x-obtain-keys\" function. Please report this bug." );
04662 KMessageBox::error( this, msg, i18n( "Chiasmus Backend Error" ) );
04663 return;
04664 }
04665
04666 if ( job->exec() ) {
04667 job->showErrorDialog( this, i18n( "Chiasmus Backend Error" ) );
04668 return;
04669 }
04670
04671 const QVariant result = job->property( "result" );
04672 if ( result.type() != QVariant::StringList ) {
04673 const QString msg = i18n( "Unexpected return value from Chiasmus backend: "
04674 "The \"x-obtain-keys\" function did not return a "
04675 "string list. Please report this bug." );
04676 KMessageBox::error( this, msg, i18n( "Chiasmus Backend Error" ) );
04677 return;
04678 }
04679
04680 const QStringList keys = result.toStringList();
04681 if ( keys.empty() ) {
04682 const QString msg = i18n( "No keys have been found. Please check that a "
04683 "valid key path has been set in the Chiasmus "
04684 "configuration." );
04685 KMessageBox::information( this, msg, i18n( "No Chiasmus Keys Found" ) );
04686 return;
04687 }
04688
04689 ChiasmusKeySelector selectorDlg( this, i18n( "Chiasmus Encryption Key Selection" ),
04690 keys, GlobalSettings::chiasmusKey(),
04691 GlobalSettings::chiasmusOptions() );
04692 if ( selectorDlg.exec() != QDialog::Accepted )
04693 return;
04694
04695 GlobalSettings::setChiasmusOptions( selectorDlg.options() );
04696 GlobalSettings::setChiasmusKey( selectorDlg.key() );
04697 assert( !GlobalSettings::chiasmusKey().isEmpty() );
04698 mEncryptWithChiasmus = true;
04699 resetter.disable();
04700 }
04701
04702
04703