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 editorFocusChanged(false);
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( QMultiLineEdit::FixedColumnWidth );
01493 mEditor->setWrapColumnOrWidth( GlobalSettings::self()->lineWrapWidth() );
01494 }
01495 else
01496 {
01497 mEditor->setWordWrap( QMultiLineEdit::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->QMultiLineEdit::wordWrap() == QMultiLineEdit::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
01820
01821 if ( mMsg->numBodyParts() == 0 && otp.textualContent().isEmpty() ) {
01822 mCharset=mMsg->charset();
01823 if ( mCharset.isEmpty() || mCharset == "default" )
01824 mCharset = mDefCharset;
01825
01826 QCString bodyDecoded = mMsg->bodyDecoded();
01827
01828 if( allowDecryption )
01829 decryptOrStripOffCleartextSignature( bodyDecoded );
01830
01831 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01832 if (codec) {
01833 mEditor->setText(codec->toUnicode(bodyDecoded));
01834 } else
01835 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01836 }
01837
01838
01839 #ifdef BROKEN_FOR_OPAQUE_SIGNED_OR_ENCRYPTED_MAILS
01840 const int num = mMsg->numBodyParts();
01841 kdDebug(5006) << "KMComposeWin::setMsg() mMsg->numBodyParts="
01842 << mMsg->numBodyParts() << endl;
01843
01844 if ( num > 0 ) {
01845 KMMessagePart bodyPart;
01846 int firstAttachment = 0;
01847
01848 mMsg->bodyPart(1, &bodyPart);
01849 if ( bodyPart.typeStr().lower() == "text" &&
01850 bodyPart.subtypeStr().lower() == "html" ) {
01851
01852 partNode *root = partNode::fromMessage( mMsg );
01853 partNode *node = root->findType( DwMime::kTypeText,
01854 DwMime::kSubtypeHtml );
01855 if ( node && node->parentNode() &&
01856 node->parentNode()->hasType( DwMime::kTypeMultipart ) &&
01857 node->parentNode()->hasSubType( DwMime::kSubtypeAlternative ) ) {
01858
01859 kdDebug(5006) << "KMComposeWin::setMsg() : text/html found" << endl;
01860 firstAttachment = 2;
01861 if ( mMsg->headerField( "X-KMail-Markup" ) == "true" )
01862 toggleMarkup( true );
01863 }
01864 delete root; root = 0;
01865 }
01866 if ( firstAttachment == 0 ) {
01867 mMsg->bodyPart(0, &bodyPart);
01868 if ( bodyPart.typeStr().lower() == "text" ) {
01869
01870 kdDebug(5006) << "KMComposeWin::setMsg() : text/* found" << endl;
01871 firstAttachment = 1;
01872 }
01873 }
01874
01875 if ( firstAttachment != 0 )
01876 {
01877 mCharset = bodyPart.charset();
01878 if ( mCharset.isEmpty() || mCharset == "default" )
01879 mCharset = mDefCharset;
01880
01881 QCString bodyDecoded = bodyPart.bodyDecoded();
01882
01883 if( allowDecryption )
01884 decryptOrStripOffCleartextSignature( bodyDecoded );
01885
01886
01887
01888
01889
01890
01891
01892 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01893 if (codec)
01894 mEditor->setText(codec->toUnicode(bodyDecoded));
01895 else
01896 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01897
01898 } else mEditor->setText("");
01899 for( int i = firstAttachment; i < num; ++i )
01900 {
01901 KMMessagePart *msgPart = new KMMessagePart;
01902 mMsg->bodyPart(i, msgPart);
01903 QCString mimeType = msgPart->typeStr().lower() + '/'
01904 + msgPart->subtypeStr().lower();
01905
01906
01907 if( mimeType != "application/pgp-signature" ) {
01908 addAttach(msgPart);
01909 }
01910 }
01911 } else{
01912 mCharset=mMsg->charset();
01913 if ( mCharset.isEmpty() || mCharset == "default" )
01914 mCharset = mDefCharset;
01915
01916 QCString bodyDecoded = mMsg->bodyDecoded();
01917
01918 if( allowDecryption )
01919 decryptOrStripOffCleartextSignature( bodyDecoded );
01920
01921 const QTextCodec *codec = KMMsgBase::codecForName(mCharset);
01922 if (codec) {
01923 mEditor->setText(codec->toUnicode(bodyDecoded));
01924 } else
01925 mEditor->setText(QString::fromLocal8Bit(bodyDecoded));
01926 }
01927
01928 setCharset(mCharset);
01929 #endif // BROKEN_FOR_OPAQUE_SIGNED_OR_ENCRYPTED_MAILS
01930
01931 if( (GlobalSettings::self()->autoTextSignature()=="auto") && mayAutoSign ) {
01932
01933
01934
01935
01936
01937
01938 QTimer::singleShot( 200, this, SLOT(slotAppendSignature()) );
01939 }
01940 setModified( isModified );
01941 }
01942
01943
01944
01945 void KMComposeWin::setFcc( const QString &idString )
01946 {
01947
01948 if ( ! idString.isEmpty() && kmkernel->findFolderById( idString ) ) {
01949 mFcc->setFolder( idString );
01950 } else {
01951 mFcc->setFolder( kmkernel->sentFolder() );
01952 }
01953 }
01954
01955
01956
01957 bool KMComposeWin::isModified() const
01958 {
01959 return ( mEditor->isModified() ||
01960 mEdtFrom->edited() ||
01961 ( mEdtReplyTo && mEdtReplyTo->edited() ) ||
01962 ( mEdtTo && mEdtTo->edited() ) ||
01963 ( mEdtCc && mEdtCc->edited() ) ||
01964 ( mEdtBcc && mEdtBcc->edited() ) ||
01965 ( mRecipientsEditor && mRecipientsEditor->isModified() ) ||
01966 mEdtSubject->edited() ||
01967 mAtmModified ||
01968 ( mTransport->lineEdit() && mTransport->lineEdit()->edited() ) );
01969 }
01970
01971
01972
01973 void KMComposeWin::setModified( bool modified )
01974 {
01975 mEditor->setModified( modified );
01976 if ( !modified ) {
01977 mEdtFrom->setEdited( false );
01978 if ( mEdtReplyTo ) mEdtReplyTo->setEdited( false );
01979 if ( mEdtTo ) mEdtTo->setEdited( false );
01980 if ( mEdtCc ) mEdtCc->setEdited( false );
01981 if ( mEdtBcc ) mEdtBcc->setEdited( false );
01982 if ( mRecipientsEditor ) mRecipientsEditor->clearModified();
01983 mEdtSubject->setEdited( false );
01984 mAtmModified = false ;
01985 if ( mTransport->lineEdit() )
01986 mTransport->lineEdit()->setEdited( false );
01987 }
01988 }
01989
01990
01991
01992 bool KMComposeWin::queryClose ()
01993 {
01994 if ( !mEditor->checkExternalEditorFinished() )
01995 return false;
01996 if (kmkernel->shuttingDown() || kapp->sessionSaving())
01997 return true;
01998
01999 if ( isModified() ) {
02000 const int rc = KMessageBox::warningYesNoCancel(this,
02001 i18n("Do you want to save the message for later or discard it?"),
02002 i18n("Close Composer"),
02003 KGuiItem(i18n("&Save as Draft"), "filesave", QString::null,
02004 i18n("Save this message in the Drafts folder. It can "
02005 "then be edited and sent at a later time.")),
02006 KStdGuiItem::discard() );
02007 if (rc == KMessageBox::Cancel)
02008 return false;
02009 else if (rc == KMessageBox::Yes) {
02010
02011 slotSaveDraft();
02012 return false;
02013 }
02014 }
02015 cleanupAutoSave();
02016 return true;
02017 }
02018
02019
02020 bool KMComposeWin::userForgotAttachment()
02021 {
02022 bool checkForForgottenAttachments = GlobalSettings::self()->showForgottenAttachmentWarning();
02023
02024 if ( !checkForForgottenAttachments || ( mAtmList.count() > 0 ) )
02025 return false;
02026
02027
02028 QStringList attachWordsList = GlobalSettings::self()->attachmentKeywords();
02029
02030 if ( attachWordsList.isEmpty() ) {
02031
02032 attachWordsList << QString::fromLatin1("attachment")
02033 << QString::fromLatin1("attached");
02034 if ( QString::fromLatin1("attachment") != i18n("attachment") )
02035 attachWordsList << i18n("attachment");
02036 if ( QString::fromLatin1("attached") != i18n("attached") )
02037 attachWordsList << i18n("attached");
02038 }
02039
02040 QRegExp rx ( QString::fromLatin1("\\b") +
02041 attachWordsList.join("\\b|\\b") +
02042 QString::fromLatin1("\\b") );
02043 rx.setCaseSensitive( false );
02044
02045 bool gotMatch = false;
02046
02047
02048
02049 QString subj = subject();
02050 gotMatch = ( KMMessage::stripOffPrefixes( subj ) == subj )
02051 && ( rx.search( subj ) >= 0 );
02052
02053 if ( !gotMatch ) {
02054
02055
02056 QRegExp quotationRx ("^([ \\t]*([|>:}#]|[A-Za-z]+>))+");
02057 for ( int i = 0; i < mEditor->numLines(); ++i ) {
02058 QString line = mEditor->textLine( i );
02059 gotMatch = ( quotationRx.search( line ) < 0 )
02060 && ( rx.search( line ) >= 0 );
02061 if ( gotMatch )
02062 break;
02063 }
02064 }
02065
02066 if ( !gotMatch )
02067 return false;
02068
02069 int rc = KMessageBox::warningYesNoCancel( this,
02070 i18n("The message you have composed seems to refer to an "
02071 "attached file but you have not attached anything.\n"
02072 "Do you want to attach a file to your message?"),
02073 i18n("File Attachment Reminder"),
02074 i18n("&Attach File..."),
02075 i18n("&Send as Is") );
02076 if ( rc == KMessageBox::Cancel )
02077 return true;
02078 if ( rc == KMessageBox::Yes ) {
02079 slotAttachFile();
02080
02081 return true;
02082 }
02083 return false;
02084 }
02085
02086
02087 void KMComposeWin::applyChanges( bool dontSignNorEncrypt, bool dontDisable )
02088 {
02089 kdDebug(5006) << "entering KMComposeWin::applyChanges" << endl;
02090
02091 if(!mMsg) {
02092 kdDebug(5006) << "KMComposeWin::applyChanges() : mMsg == 0!\n" << endl;
02093 emit applyChangesDone( false );
02094 return;
02095 }
02096
02097 if( mComposer ) {
02098 kdDebug(5006) << "KMComposeWin::applyChanges() : applyChanges called twice"
02099 << endl;
02100 return;
02101 }
02102
02103
02104 mComposer = new MessageComposer( this );
02105 connect( mComposer, SIGNAL( done( bool ) ),
02106 this, SLOT( slotComposerDone( bool ) ) );
02107
02108
02109
02110
02111 if ( !dontDisable ) setEnabled( false );
02112
02113 mComposer->setDisableBreaking( mDisableBreaking );
02114 mComposer->applyChanges( dontSignNorEncrypt );
02115 }
02116
02117 void KMComposeWin::slotComposerDone( bool rc )
02118 {
02119 deleteAll( mComposedMessages );
02120 mComposedMessages = mComposer->composedMessageList();
02121 emit applyChangesDone( rc );
02122 delete mComposer;
02123 mComposer = 0;
02124
02125
02126 setEnabled( true );
02127 }
02128
02129 const KPIM::Identity & KMComposeWin::identity() const {
02130 return kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
02131 }
02132
02133 uint KMComposeWin::identityUid() const {
02134 return mIdentity->currentIdentity();
02135 }
02136
02137 Kleo::CryptoMessageFormat KMComposeWin::cryptoMessageFormat() const {
02138 if ( !mCryptoModuleAction )
02139 return Kleo::AutoFormat;
02140 return cb2format( mCryptoModuleAction->currentItem() );
02141 }
02142
02143 bool KMComposeWin::encryptToSelf() const {
02144 return !Kpgp::Module::getKpgp() || Kpgp::Module::getKpgp()->encryptToSelf();
02145 }
02146
02147 bool KMComposeWin::queryExit ()
02148 {
02149 return true;
02150 }
02151
02152
02153 void KMComposeWin::addAttach(const KURL aUrl)
02154 {
02155 if ( !aUrl.isValid() ) {
02156 KMessageBox::sorry( this, i18n( "<qt><p>KMail could not recognize the location of the attachment (%1);</p>"
02157 "<p>you have to specify the full path if you wish to attach a file.</p></qt>" )
02158 .arg( aUrl.prettyURL() ) );
02159 return;
02160 }
02161 KIO::TransferJob *job = KIO::get(aUrl);
02162 KIO::Scheduler::scheduleJob( job );
02163 atmLoadData ld;
02164 ld.url = aUrl;
02165 ld.data = QByteArray();
02166 ld.insert = false;
02167 if( !aUrl.fileEncoding().isEmpty() )
02168 ld.encoding = aUrl.fileEncoding().latin1();
02169
02170 mMapAtmLoadData.insert(job, ld);
02171 connect(job, SIGNAL(result(KIO::Job *)),
02172 this, SLOT(slotAttachFileResult(KIO::Job *)));
02173 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
02174 this, SLOT(slotAttachFileData(KIO::Job *, const QByteArray &)));
02175 }
02176
02177
02178
02179 void KMComposeWin::addAttach(const KMMessagePart* msgPart)
02180 {
02181 mAtmList.append(msgPart);
02182
02183
02184 if (mAtmList.count()==1)
02185 {
02186 mAtmListView->resize(mAtmListView->width(), 50);
02187 mAtmListView->show();
02188 resize(size());
02189 }
02190
02191
02192 KMAtmListViewItem *lvi = new KMAtmListViewItem( mAtmListView );
02193 msgPartToItem(msgPart, lvi);
02194 mAtmItemList.append(lvi);
02195
02196
02197 if ( mTempDir != 0 ) {
02198 delete mTempDir;
02199 mTempDir = 0;
02200 }
02201
02202 connect( lvi, SIGNAL( compress( int ) ),
02203 this, SLOT( compressAttach( int ) ) );
02204 connect( lvi, SIGNAL( uncompress( int ) ),
02205 this, SLOT( uncompressAttach( int ) ) );
02206
02207 slotUpdateAttachActions();
02208 }
02209
02210
02211
02212 void KMComposeWin::slotUpdateAttachActions()
02213 {
02214 int selectedCount = 0;
02215 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it ) {
02216 if ( (*it)->isSelected() ) {
02217 ++selectedCount;
02218 }
02219 }
02220
02221 mAttachRemoveAction->setEnabled( selectedCount >= 1 );
02222 mAttachSaveAction->setEnabled( selectedCount == 1 );
02223 mAttachPropertiesAction->setEnabled( selectedCount == 1 );
02224 }
02225
02226
02227
02228
02229 QString KMComposeWin::prettyMimeType( const QString& type )
02230 {
02231 QString t = type.lower();
02232 KServiceType::Ptr st = KServiceType::serviceType( t );
02233 return st ? st->comment() : t;
02234 }
02235
02236 void KMComposeWin::msgPartToItem(const KMMessagePart* msgPart,
02237 KMAtmListViewItem *lvi, bool loadDefaults)
02238 {
02239 assert(msgPart != 0);
02240
02241 if (!msgPart->fileName().isEmpty())
02242 lvi->setText(0, msgPart->fileName());
02243 else
02244 lvi->setText(0, msgPart->name());
02245 lvi->setText(1, KIO::convertSize( msgPart->decodedSize()));
02246 lvi->setText(2, msgPart->contentTransferEncodingStr());
02247 lvi->setText(3, prettyMimeType(msgPart->typeStr() + "/" + msgPart->subtypeStr()));
02248
02249 if ( loadDefaults ) {
02250 if( canSignEncryptAttachments() ) {
02251 lvi->enableCryptoCBs( true );
02252 lvi->setEncrypt( mEncryptAction->isChecked() );
02253 lvi->setSign( mSignAction->isChecked() );
02254 } else {
02255 lvi->enableCryptoCBs( false );
02256 }
02257 }
02258 }
02259
02260
02261
02262 void KMComposeWin::removeAttach(const QString &aUrl)
02263 {
02264 int idx;
02265 KMMessagePart* msgPart;
02266 for(idx=0,msgPart=mAtmList.first(); msgPart;
02267 msgPart=mAtmList.next(),idx++) {
02268 if (msgPart->name() == aUrl) {
02269 removeAttach(idx);
02270 return;
02271 }
02272 }
02273 }
02274
02275
02276
02277 void KMComposeWin::removeAttach(int idx)
02278 {
02279 mAtmModified = TRUE;
02280 mAtmList.remove(idx);
02281 delete mAtmItemList.take(idx);
02282
02283 if( mAtmList.isEmpty() )
02284 {
02285 mAtmListView->hide();
02286 mAtmListView->setMinimumSize(0, 0);
02287 resize(size());
02288 }
02289 }
02290
02291
02292
02293 bool KMComposeWin::encryptFlagOfAttachment(int idx)
02294 {
02295 return (int)(mAtmItemList.count()) > idx
02296 ? static_cast<KMAtmListViewItem*>( mAtmItemList.at( idx ) )->isEncrypt()
02297 : false;
02298 }
02299
02300
02301
02302 bool KMComposeWin::signFlagOfAttachment(int idx)
02303 {
02304 return (int)(mAtmItemList.count()) > idx
02305 ? ((KMAtmListViewItem*)(mAtmItemList.at( idx )))->isSign()
02306 : false;
02307 }
02308
02309
02310
02311 void KMComposeWin::addrBookSelInto()
02312 {
02313 if ( mClassicalRecipients ) {
02314 if ( GlobalSettings::self()->addresseeSelectorType() ==
02315 GlobalSettings::EnumAddresseeSelectorType::New ) {
02316 addrBookSelIntoNew();
02317 } else {
02318 addrBookSelIntoOld();
02319 }
02320 } else {
02321 kdWarning() << "To be implemented: call recipients picker." << endl;
02322 }
02323 }
02324
02325 void KMComposeWin::addrBookSelIntoOld()
02326 {
02327 AddressesDialog dlg( this );
02328 QString txt;
02329 QStringList lst;
02330
02331 txt = to();
02332 if ( !txt.isEmpty() ) {
02333 lst = KPIM::splitEmailAddrList( txt );
02334 dlg.setSelectedTo( lst );
02335 }
02336
02337 txt = mEdtCc->text();
02338 if ( !txt.isEmpty() ) {
02339 lst = KPIM::splitEmailAddrList( txt );
02340 dlg.setSelectedCC( lst );
02341 }
02342
02343 txt = mEdtBcc->text();
02344 if ( !txt.isEmpty() ) {
02345 lst = KPIM::splitEmailAddrList( txt );
02346 dlg.setSelectedBCC( lst );
02347 }
02348
02349 dlg.setRecentAddresses( RecentAddresses::self( KMKernel::config() )->kabcAddresses() );
02350
02351 if (dlg.exec()==QDialog::Rejected) return;
02352
02353 mEdtTo->setText( dlg.to().join(", ") );
02354 mEdtTo->setEdited( true );
02355
02356 mEdtCc->setText( dlg.cc().join(", ") );
02357 mEdtCc->setEdited( true );
02358
02359 mEdtBcc->setText( dlg.bcc().join(", ") );
02360 mEdtBcc->setEdited( true );
02361
02362
02363 if ( !mEdtBcc->text().isEmpty() ) {
02364 mShowHeaders |= HDR_BCC;
02365 rethinkFields( false );
02366 }
02367 }
02368
02369 void KMComposeWin::addrBookSelIntoNew()
02370 {
02371 AddresseeEmailSelection selection;
02372
02373 AddresseeSelectorDialog dlg( &selection );
02374
02375 QString txt;
02376 QStringList lst;
02377
02378 txt = to();
02379 if ( !txt.isEmpty() ) {
02380 lst = KPIM::splitEmailAddrList( txt );
02381 selection.setSelectedTo( lst );
02382 }
02383
02384 txt = mEdtCc->text();
02385 if ( !txt.isEmpty() ) {
02386 lst = KPIM::splitEmailAddrList( txt );
02387 selection.setSelectedCC( lst );
02388 }
02389
02390 txt = mEdtBcc->text();
02391 if ( !txt.isEmpty() ) {
02392 lst = KPIM::splitEmailAddrList( txt );
02393 selection.setSelectedBCC( lst );
02394 }
02395
02396 if (dlg.exec()==QDialog::Rejected) return;
02397
02398 QStringList list = selection.to() + selection.toDistributionLists();
02399 mEdtTo->setText( list.join(", ") );
02400 mEdtTo->setEdited( true );
02401
02402 list = selection.cc() + selection.ccDistributionLists();
02403 mEdtCc->setText( list.join(", ") );
02404 mEdtCc->setEdited( true );
02405
02406 list = selection.bcc() + selection.bccDistributionLists();
02407 mEdtBcc->setText( list.join(", ") );
02408 mEdtBcc->setEdited( true );
02409
02410
02411 if ( !mEdtBcc->text().isEmpty() ) {
02412 mShowHeaders |= HDR_BCC;
02413 rethinkFields( false );
02414 }
02415 }
02416
02417
02418
02419 void KMComposeWin::setCharset(const QCString& aCharset, bool forceDefault)
02420 {
02421 if ((forceDefault && GlobalSettings::self()->forceReplyCharset()) || aCharset.isEmpty())
02422 mCharset = mDefCharset;
02423 else
02424 mCharset = aCharset.lower();
02425
02426 if ( mCharset.isEmpty() || mCharset == "default" )
02427 mCharset = mDefCharset;
02428
02429 if (mAutoCharset)
02430 {
02431 mEncodingAction->setCurrentItem( 0 );
02432 return;
02433 }
02434
02435 QStringList encodings = mEncodingAction->items();
02436 int i = 0;
02437 bool charsetFound = FALSE;
02438 for ( QStringList::Iterator it = encodings.begin(); it != encodings.end();
02439 ++it, i++ )
02440 {
02441 if (i > 0 && ((mCharset == "us-ascii" && i == 1) ||
02442 (i != 1 && KGlobal::charsets()->codecForName(
02443 KGlobal::charsets()->encodingForName(*it))
02444 == KGlobal::charsets()->codecForName(mCharset))))
02445 {
02446 mEncodingAction->setCurrentItem( i );
02447 slotSetCharset();
02448 charsetFound = TRUE;
02449 break;
02450 }
02451 }
02452 if (!aCharset.isEmpty() && !charsetFound) setCharset("", TRUE);
02453 }
02454
02455
02456
02457 void KMComposeWin::slotAddrBook()
02458 {
02459 KAddrBookExternal::openAddressBook(this);
02460 }
02461
02462
02463
02464 void KMComposeWin::slotAddrBookFrom()
02465 {
02466 addrBookSelInto();
02467 }
02468
02469
02470
02471 void KMComposeWin::slotAddrBookReplyTo()
02472 {
02473 addrBookSelInto();
02474 }
02475
02476
02477
02478 void KMComposeWin::slotAddrBookTo()
02479 {
02480 addrBookSelInto();
02481 }
02482
02483
02484 void KMComposeWin::slotAttachFile()
02485 {
02486
02487
02488
02489
02490 KFileDialog fdlg(QString::null, QString::null, this, 0, TRUE);
02491 fdlg.setOperationMode( KFileDialog::Other );
02492 fdlg.setCaption(i18n("Attach File"));
02493 fdlg.okButton()->setGuiItem(KGuiItem(i18n("&Attach"),"fileopen"));
02494 fdlg.setMode(KFile::Files);
02495 fdlg.exec();
02496 KURL::List files = fdlg.selectedURLs();
02497
02498 for (KURL::List::Iterator it = files.begin(); it != files.end(); ++it)
02499 addAttach(*it);
02500 }
02501
02502
02503
02504 void KMComposeWin::slotAttachFileData(KIO::Job *job, const QByteArray &data)
02505 {
02506 QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.find(job);
02507 assert(it != mMapAtmLoadData.end());
02508 QBuffer buff((*it).data);
02509 buff.open(IO_WriteOnly | IO_Append);
02510 buff.writeBlock(data.data(), data.size());
02511 buff.close();
02512 }
02513
02514
02515
02516 void KMComposeWin::slotAttachFileResult(KIO::Job *job)
02517 {
02518 QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.find(job);
02519 assert(it != mMapAtmLoadData.end());
02520 if (job->error())
02521 {
02522 mMapAtmLoadData.remove(it);
02523 job->showErrorDialog();
02524 return;
02525 }
02526 if ((*it).insert)
02527 {
02528 (*it).data.resize((*it).data.size() + 1);
02529 (*it).data[(*it).data.size() - 1] = '\0';
02530 if ( const QTextCodec * codec = KGlobal::charsets()->codecForName((*it).encoding) )
02531 mEditor->insert( codec->toUnicode( (*it).data ) );
02532 else
02533 mEditor->insert( QString::fromLocal8Bit( (*it).data ) );
02534 mMapAtmLoadData.remove(it);
02535 return;
02536 }
02537 const QCString partCharset = (*it).url.fileEncoding().isEmpty()
02538 ? mCharset
02539 : QCString((*it).url.fileEncoding().latin1());
02540
02541 KMMessagePart* msgPart;
02542
02543 KCursorSaver busy(KBusyPtr::busy());
02544 QString name( (*it).url.fileName() );
02545
02546 QString mimeType = static_cast<KIO::MimetypeJob*>(job)->mimetype();
02547
02548 if ( name.isEmpty() ) {
02549
02550
02551 if( mimeType == "text/html" )
02552 name = "index.html";
02553 else {
02554
02555 QStringList patterns( KMimeType::mimeType( mimeType )->patterns() );
02556 QString ext;
02557 if( !patterns.isEmpty() ) {
02558 ext = patterns[0];
02559 int i = ext.findRev( '.' );
02560 if( i == -1 )
02561 ext.prepend( '.' );
02562 else if( i > 0 )
02563 ext = ext.mid( i );
02564 }
02565 name = QString("unknown") += ext;
02566 }
02567 }
02568
02569 name.truncate( 256 );
02570
02571 QCString encoding = KMMsgBase::autoDetectCharset(partCharset,
02572 KMMessage::preferredCharsets(), name);
02573 if (encoding.isEmpty()) encoding = "utf-8";
02574
02575 QCString encName;
02576 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
02577 encName = KMMsgBase::encodeRFC2047String( name, encoding );
02578 else
02579 encName = KMMsgBase::encodeRFC2231String( name, encoding );
02580 bool RFC2231encoded = false;
02581 if ( !GlobalSettings::self()->outlookCompatibleAttachments() )
02582 RFC2231encoded = name != QString( encName );
02583
02584
02585 msgPart = new KMMessagePart;
02586 msgPart->setName(name);
02587 QValueList<int> allowedCTEs;
02588 msgPart->setBodyAndGuessCte((*it).data, allowedCTEs,
02589 !kmkernel->msgSender()->sendQuotedPrintable());
02590 kdDebug(5006) << "autodetected cte: " << msgPart->cteStr() << endl;
02591 int slash = mimeType.find( '/' );
02592 if( slash == -1 )
02593 slash = mimeType.length();
02594 msgPart->setTypeStr( mimeType.left( slash ).latin1() );
02595 msgPart->setSubtypeStr( mimeType.mid( slash + 1 ).latin1() );
02596 msgPart->setContentDisposition(QCString("attachment;\n\tfilename")
02597 + ((RFC2231encoded) ? "*" : "") + "=\"" + encName + "\"");
02598
02599 mMapAtmLoadData.remove(it);
02600
02601 msgPart->setCharset(partCharset);
02602
02603
02604 KConfigGroup composer(KMKernel::config(), "Composer");
02605 if ( GlobalSettings::self()->showMessagePartDialogOnAttach() ) {
02606 const KCursorSaver saver( QCursor::ArrowCursor );
02607 KMMsgPartDialogCompat dlg;
02608 int encodings = 0;
02609 for ( QValueListConstIterator<int> it = allowedCTEs.begin() ;
02610 it != allowedCTEs.end() ; ++it )
02611 switch ( *it ) {
02612 case DwMime::kCteBase64: encodings |= KMMsgPartDialog::Base64; break;
02613 case DwMime::kCteQp: encodings |= KMMsgPartDialog::QuotedPrintable; break;
02614 case DwMime::kCte7bit: encodings |= KMMsgPartDialog::SevenBit; break;
02615 case DwMime::kCte8bit: encodings |= KMMsgPartDialog::EightBit; break;
02616 default: ;
02617 }
02618 dlg.setShownEncodings( encodings );
02619 dlg.setMsgPart(msgPart);
02620 if (!dlg.exec()) {
02621 delete msgPart;
02622 msgPart = 0;
02623 return;
02624 }
02625 }
02626 mAtmModified = TRUE;
02627 if (msgPart->typeStr().lower() != "text") msgPart->setCharset(QCString());
02628
02629
02630 addAttach(msgPart);
02631 }
02632
02633
02634
02635 void KMComposeWin::slotInsertFile()
02636 {
02637 KFileDialog fdlg(QString::null, QString::null, this, 0, TRUE);
02638 fdlg.setOperationMode( KFileDialog::Opening );
02639 fdlg.okButton()->setText(i18n("&Insert"));
02640 fdlg.setCaption(i18n("Insert File"));
02641 fdlg.toolBar()->insertCombo(KMMsgBase::supportedEncodings(FALSE), 4711,
02642 false, 0, 0, 0);
02643 KComboBox *combo = fdlg.toolBar()->getCombo(4711);
02644 for (int i = 0; i < combo->count(); i++)
02645 if (KGlobal::charsets()->codecForName(KGlobal::charsets()->
02646 encodingForName(combo->text(i)))
02647 == QTextCodec::codecForLocale()) combo->setCurrentItem(i);
02648 if (!fdlg.exec()) return;
02649
02650 KURL u = fdlg.selectedURL();
02651 mRecentAction->addURL(u);
02652
02653 {
02654 KConfig *config = KMKernel::config();
02655 KConfigGroupSaver saver( config, "Composer" );
02656 QString encoding = KGlobal::charsets()->encodingForName(combo->currentText()).latin1();
02657 QStringList urls = config->readListEntry( "recent-urls" );
02658 QStringList encodings = config->readListEntry( "recent-encodings" );
02659
02660
02661 uint mMaxRecentFiles = 30;
02662 while (urls.count() > mMaxRecentFiles)
02663 urls.erase( urls.fromLast() );
02664 while (encodings.count() > mMaxRecentFiles)
02665 urls.erase( encodings.fromLast() );
02666
02667 if (urls.count() != encodings.count()) {
02668 urls.clear();
02669 encodings.clear();
02670 }
02671 urls.prepend( u.prettyURL() );
02672 encodings.prepend( encoding );
02673 config->writeEntry( "recent-urls", urls );
02674 config->writeEntry( "recent-encodings", encodings );
02675 mRecentAction->saveEntries( config );
02676 }
02677 slotInsertRecentFile(u);
02678 }
02679
02680
02681
02682 void KMComposeWin::slotInsertRecentFile(const KURL& u)
02683 {
02684 if (u.fileName().isEmpty()) return;
02685
02686 KIO::Job *job = KIO::get(u);
02687 atmLoadData ld;
02688 ld.url = u;
02689 ld.data = QByteArray();
02690 ld.insert = true;
02691
02692 {
02693 KConfig *config = KMKernel::config();
02694 KConfigGroupSaver saver( config, "Composer" );
02695 QStringList urls = config->readListEntry( "recent-urls" );
02696 QStringList encodings = config->readListEntry( "recent-encodings" );
02697 int index = urls.findIndex( u.prettyURL() );
02698 if (index != -1) {
02699 QString encoding = encodings[ index ];
02700 ld.encoding = encoding.latin1();
02701 }
02702 }
02703 mMapAtmLoadData.insert(job, ld);
02704 connect(job, SIGNAL(result(KIO::Job *)),
02705 this, SLOT(slotAttachFileResult(KIO::Job *)));
02706 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
02707 this, SLOT(slotAttachFileData(KIO::Job *, const QByteArray &)));
02708 }
02709
02710
02711
02712 void KMComposeWin::slotSetCharset()
02713 {
02714 if (mEncodingAction->currentItem() == 0)
02715 {
02716 mAutoCharset = true;
02717 return;
02718 }
02719 mAutoCharset = false;
02720
02721 mCharset = KGlobal::charsets()->encodingForName( mEncodingAction->
02722 currentText() ).latin1();
02723 }
02724
02725
02726
02727 void KMComposeWin::slotSelectCryptoModule( bool init )
02728 {
02729 if ( !init ) {
02730 setModified( true );
02731 }
02732 if( canSignEncryptAttachments() ) {
02733
02734 if( 0 == mAtmListView->columnWidth( mAtmColEncrypt ) ) {
02735
02736
02737 if( !mAtmList.isEmpty() ) {
02738 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02739 lvi;
02740 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02741 lvi->setSign( mSignAction->isChecked() );
02742 lvi->setEncrypt( mEncryptAction->isChecked() );
02743 }
02744 }
02745 int totalWidth = 0;
02746
02747 for( int col=0; col < mAtmColEncrypt; col++ )
02748 totalWidth += mAtmListView->columnWidth( col );
02749 int reducedTotalWidth = totalWidth - mAtmEncryptColWidth
02750 - mAtmSignColWidth;
02751
02752
02753 int usedWidth = 0;
02754 for( int col=0; col < mAtmColEncrypt-1; col++ ) {
02755 int newWidth = mAtmListView->columnWidth( col ) * reducedTotalWidth
02756 / totalWidth;
02757 mAtmListView->setColumnWidth( col, newWidth );
02758 usedWidth += newWidth;
02759 }
02760
02761
02762
02763 mAtmListView->setColumnWidth( mAtmColEncrypt-1,
02764 reducedTotalWidth - usedWidth );
02765 mAtmListView->setColumnWidth( mAtmColEncrypt, mAtmEncryptColWidth );
02766 mAtmListView->setColumnWidth( mAtmColSign, mAtmSignColWidth );
02767 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02768 lvi;
02769 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02770 lvi->enableCryptoCBs( true );
02771 }
02772 }
02773 } else {
02774
02775 if( 0 != mAtmListView->columnWidth( mAtmColEncrypt ) ) {
02776 mAtmEncryptColWidth = mAtmListView->columnWidth( mAtmColEncrypt );
02777 mAtmSignColWidth = mAtmListView->columnWidth( mAtmColSign );
02778 int totalWidth = 0;
02779
02780 for( int col=0; col < mAtmListView->columns(); col++ )
02781 totalWidth += mAtmListView->columnWidth( col );
02782 int reducedTotalWidth = totalWidth - mAtmEncryptColWidth
02783 - mAtmSignColWidth;
02784
02785
02786 int usedWidth = 0;
02787 for( int col=0; col < mAtmColEncrypt-1; col++ ) {
02788 int newWidth = mAtmListView->columnWidth( col ) * totalWidth
02789 / reducedTotalWidth;
02790 mAtmListView->setColumnWidth( col, newWidth );
02791 usedWidth += newWidth;
02792 }
02793
02794
02795
02796 mAtmListView->setColumnWidth( mAtmColEncrypt-1, totalWidth - usedWidth );
02797 mAtmListView->setColumnWidth( mAtmColEncrypt, 0 );
02798 mAtmListView->setColumnWidth( mAtmColSign, 0 );
02799 for( KMAtmListViewItem* lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
02800 lvi;
02801 lvi = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) ) {
02802 lvi->enableCryptoCBs( false );
02803 }
02804 }
02805 }
02806 }
02807
02808 static void showExportError( QWidget * w, const GpgME::Error & err ) {
02809 assert( err );
02810 const QString msg = i18n("<qt><p>An error occurred while trying to export "
02811 "the key from the backend:</p>"
02812 "<p><b>%1</b></p></qt>")
02813 .arg( QString::fromLocal8Bit( err.asString() ) );
02814 KMessageBox::error( w, msg, i18n("Key Export Failed") );
02815 }
02816
02817
02818
02819 void KMComposeWin::slotInsertMyPublicKey()
02820 {
02821
02822 mFingerprint =
02823 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() ).pgpEncryptionKey();
02824 if ( !mFingerprint.isEmpty() )
02825 startPublicKeyExport();
02826 }
02827
02828 void KMComposeWin::startPublicKeyExport() {
02829 if ( mFingerprint.isEmpty() )
02830 return;
02831 Kleo::ExportJob * job = Kleo::CryptoBackendFactory::instance()->openpgp()->publicKeyExportJob( true );
02832 assert( job );
02833
02834 connect( job, SIGNAL(result(const GpgME::Error&,const QByteArray&)),
02835 this, SLOT(slotPublicKeyExportResult(const GpgME::Error&,const QByteArray&)) );
02836
02837 const GpgME::Error err = job->start( mFingerprint );
02838 if ( err )
02839 showExportError( this, err );
02840 else
02841 (void)new Kleo::ProgressDialog( job, i18n("Exporting key..."), this );
02842 }
02843
02844 void KMComposeWin::slotPublicKeyExportResult( const GpgME::Error & err, const QByteArray & keydata ) {
02845 if ( err ) {
02846 showExportError( this, err );
02847 return;
02848 }
02849
02850
02851 KMMessagePart * msgPart = new KMMessagePart();
02852 msgPart->setName( i18n("OpenPGP key 0x%1").arg( mFingerprint ) );
02853 msgPart->setTypeStr("application");
02854 msgPart->setSubtypeStr("pgp-keys");
02855 QValueList<int> dummy;
02856 msgPart->setBodyAndGuessCte(keydata, dummy, false);
02857 msgPart->setContentDisposition( "attachment;\n\tfilename=0x" + QCString( mFingerprint.latin1() ) + ".asc" );
02858
02859
02860 addAttach(msgPart);
02861 rethinkFields();
02862 }
02863
02864
02865 void KMComposeWin::slotInsertPublicKey()
02866 {
02867 Kleo::KeySelectionDialog dlg( i18n("Attach Public OpenPGP Key"),
02868 i18n("Select the public key which should "
02869 "be attached."),
02870 std::vector<GpgME::Key>(),
02871 Kleo::KeySelectionDialog::PublicKeys|Kleo::KeySelectionDialog::OpenPGPKeys,
02872 false ,
02873 false ,
02874 this, "attach public key selection dialog" );
02875 if ( dlg.exec() != QDialog::Accepted )
02876 return;
02877
02878 mFingerprint = dlg.fingerprint();
02879 startPublicKeyExport();
02880 }
02881
02882
02883
02884 void KMComposeWin::slotAttachPopupMenu(QListViewItem *, const QPoint &, int)
02885 {
02886 if (!mAttachMenu)
02887 {
02888 mAttachMenu = new QPopupMenu(this);
02889
02890 mOpenId = mAttachMenu->insertItem(i18n("to open", "Open"), this,
02891 SLOT(slotAttachOpen()));
02892 mViewId = mAttachMenu->insertItem(i18n("to view", "View"), this,
02893 SLOT(slotAttachView()));
02894 mRemoveId = mAttachMenu->insertItem(i18n("Remove"), this, SLOT(slotAttachRemove()));
02895 mSaveAsId = mAttachMenu->insertItem( SmallIconSet("filesaveas"), i18n("Save As..."), this,
02896 SLOT( slotAttachSave() ) );
02897 mPropertiesId = mAttachMenu->insertItem( i18n("Properties"), this,
02898 SLOT( slotAttachProperties() ) );
02899 mAttachMenu->insertSeparator();
02900 mAttachMenu->insertItem(i18n("Add Attachment..."), this, SLOT(slotAttachFile()));
02901 }
02902
02903 int selectedCount = 0;
02904 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it ) {
02905 if ( (*it)->isSelected() ) {
02906 ++selectedCount;
02907 }
02908 }
02909
02910 mAttachMenu->setItemEnabled( mOpenId, selectedCount > 0 );
02911 mAttachMenu->setItemEnabled( mViewId, selectedCount > 0 );
02912 mAttachMenu->setItemEnabled( mRemoveId, selectedCount > 0 );
02913 mAttachMenu->setItemEnabled( mSaveAsId, selectedCount == 1 );
02914 mAttachMenu->setItemEnabled( mPropertiesId, selectedCount == 1 );
02915
02916 mAttachMenu->popup(QCursor::pos());
02917 }
02918
02919
02920 int KMComposeWin::currentAttachmentNum()
02921 {
02922 int i = 0;
02923 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i )
02924 if ( *it == mAtmListView->currentItem() )
02925 return i;
02926 return -1;
02927 }
02928
02929
02930 void KMComposeWin::slotAttachProperties()
02931 {
02932 int idx = currentAttachmentNum();
02933
02934 if (idx < 0) return;
02935
02936 KMMessagePart* msgPart = mAtmList.at(idx);
02937 msgPart->setCharset(mCharset);
02938
02939 KMMsgPartDialogCompat dlg;
02940 dlg.setMsgPart(msgPart);
02941 KMAtmListViewItem* listItem = (KMAtmListViewItem*)(mAtmItemList.at(idx));
02942 if( canSignEncryptAttachments() && listItem ) {
02943 dlg.setCanSign( true );
02944 dlg.setCanEncrypt( true );
02945 dlg.setSigned( listItem->isSign() );
02946 dlg.setEncrypted( listItem->isEncrypt() );
02947 } else {
02948 dlg.setCanSign( false );
02949 dlg.setCanEncrypt( false );
02950 }
02951 if (dlg.exec())
02952 {
02953 mAtmModified = TRUE;
02954
02955 if( listItem ) {
02956 msgPartToItem(msgPart, listItem);
02957 if( canSignEncryptAttachments() ) {
02958 listItem->setSign( dlg.isSigned() );
02959 listItem->setEncrypt( dlg.isEncrypted() );
02960 }
02961 }
02962 }
02963 if (msgPart->typeStr().lower() != "text") msgPart->setCharset(QCString());
02964 }
02965
02966
02967 void KMComposeWin::compressAttach( int idx )
02968 {
02969 if (idx < 0) return;
02970
02971 unsigned int i;
02972 for ( i = 0; i < mAtmItemList.count(); ++i )
02973 if ( mAtmItemList.at( i )->itemPos() == idx )
02974 break;
02975
02976 if ( i > mAtmItemList.count() )
02977 return;
02978
02979 KMMessagePart* msgPart;
02980 msgPart = mAtmList.at( i );
02981 QByteArray array;
02982 QBuffer dev( array );
02983 KZip zip( &dev );
02984 QByteArray decoded = msgPart->bodyDecodedBinary();
02985 if ( ! zip.open( IO_WriteOnly ) ) {
02986 KMessageBox::sorry(0, i18n("KMail could not compress the file.") );
02987 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
02988 return;
02989 }
02990
02991 zip.setCompression( KZip::DeflateCompression );
02992 if ( ! zip.writeFile( msgPart->name(), "", "", decoded.size(),
02993 decoded.data() ) ) {
02994 KMessageBox::sorry(0, i18n("KMail could not compress the file.") );
02995 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
02996 return;
02997 }
02998 zip.close();
02999 if ( array.size() >= decoded.size() ) {
03000 if ( KMessageBox::questionYesNo( this, i18n("The compressed file is larger "
03001 "than the original. Do you want to keep the original one?" ), QString::null, i18n("Keep"), i18n("Compress") )
03002 == KMessageBox::Yes ) {
03003 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setCompress( false );
03004 return;
03005 }
03006 }
03007 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setUncompressedCodec(
03008 msgPart->cteStr() );
03009
03010 msgPart->setCteStr( "base64" );
03011 msgPart->setBodyEncodedBinary( array );
03012 QString name = msgPart->name() + ".zip";
03013
03014 msgPart->setName( name );
03015
03016 QCString cDisp = "attachment;";
03017 QCString encoding = KMMsgBase::autoDetectCharset( msgPart->charset(),
03018 KMMessage::preferredCharsets(), name );
03019 kdDebug(5006) << "encoding: " << encoding << endl;
03020 if ( encoding.isEmpty() ) encoding = "utf-8";
03021 kdDebug(5006) << "encoding after: " << encoding << endl;
03022 QCString encName;
03023 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
03024 encName = KMMsgBase::encodeRFC2047String( name, encoding );
03025 else
03026 encName = KMMsgBase::encodeRFC2231String( name, encoding );
03027
03028 cDisp += "\n\tfilename";
03029 if ( name != QString( encName ) )
03030 cDisp += "*=" + encName;
03031 else
03032 cDisp += "=\"" + encName + '"';
03033 msgPart->setContentDisposition( cDisp );
03034
03035 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->setUncompressedMimeType(
03036 msgPart->typeStr(), msgPart->subtypeStr() );
03037 msgPart->setTypeStr( "application" );
03038 msgPart->setSubtypeStr( "x-zip" );
03039
03040 KMAtmListViewItem* listItem = static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) );
03041 msgPartToItem( msgPart, listItem, false );
03042 }
03043
03044
03045
03046 void KMComposeWin::uncompressAttach( int idx )
03047 {
03048 if (idx < 0) return;
03049
03050 unsigned int i;
03051 for ( i = 0; i < mAtmItemList.count(); ++i )
03052 if ( mAtmItemList.at( i )->itemPos() == idx )
03053 break;
03054
03055 if ( i > mAtmItemList.count() )
03056 return;
03057
03058 KMMessagePart* msgPart;
03059 msgPart = mAtmList.at( i );
03060
03061 QBuffer dev( msgPart->bodyDecodedBinary() );
03062 KZip zip( &dev );
03063 QByteArray decoded;
03064
03065 decoded = msgPart->bodyDecodedBinary();
03066 if ( ! zip.open( IO_ReadOnly ) ) {
03067 KMessageBox::sorry(0, i18n("KMail could not uncompress the file.") );
03068 static_cast<KMAtmListViewItem *>( mAtmItemList.at( i ) )->setCompress( true );
03069 return;
03070 }
03071 const KArchiveDirectory *dir = zip.directory();
03072
03073 KZipFileEntry *entry;
03074 if ( dir->entries().count() != 1 ) {
03075 KMessageBox::sorry(0, i18n("KMail could not uncompress the file.") );
03076 static_cast<KMAtmListViewItem *>( mAtmItemList.at( i ) )->setCompress( true );
03077 return;
03078 }
03079 entry = (KZipFileEntry*)dir->entry( dir->entries()[0] );
03080
03081 msgPart->setCteStr(
03082 static_cast<KMAtmListViewItem*>( mAtmItemList.at(i) )->uncompressedCodec() );
03083
03084 msgPart->setBodyEncodedBinary( entry->data() );
03085 QString name = entry->name();
03086 msgPart->setName( name );
03087
03088 zip.close();
03089
03090 QCString cDisp = "attachment;";
03091 QCString encoding = KMMsgBase::autoDetectCharset( msgPart->charset(),
03092 KMMessage::preferredCharsets(), name );
03093 if ( encoding.isEmpty() ) encoding = "utf-8";
03094
03095 QCString encName;
03096 if ( GlobalSettings::self()->outlookCompatibleAttachments() )
03097 encName = KMMsgBase::encodeRFC2047String( name, encoding );
03098 else
03099 encName = KMMsgBase::encodeRFC2231String( name, encoding );
03100
03101 cDisp += "\n\tfilename";
03102 if ( name != QString( encName ) )
03103 cDisp += "*=" + encName;
03104 else
03105 cDisp += "=\"" + encName + '"';
03106 msgPart->setContentDisposition( cDisp );
03107
03108 QCString type, subtype;
03109 static_cast<KMAtmListViewItem*>( mAtmItemList.at( i ) )->uncompressedMimeType( type,
03110 subtype );
03111
03112 msgPart->setTypeStr( type );
03113 msgPart->setSubtypeStr( subtype );
03114
03115 KMAtmListViewItem* listItem = static_cast<KMAtmListViewItem*>(mAtmItemList.at( i ));
03116 msgPartToItem( msgPart, listItem, false );
03117 }
03118
03119
03120
03121 void KMComposeWin::slotAttachView()
03122 {
03123 int i = 0;
03124 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i ) {
03125 if ( (*it)->isSelected() ) {
03126 viewAttach( i );
03127 }
03128 }
03129 }
03130
03131 void KMComposeWin::slotAttachOpen()
03132 {
03133 int i = 0;
03134 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ++it, ++i ) {
03135 if ( (*it)->isSelected() ) {
03136 openAttach( i );
03137 }
03138 }
03139 }
03140
03141
03142 bool KMComposeWin::inlineSigningEncryptionSelected() {
03143 if ( !mSignAction->isChecked() && !mEncryptAction->isChecked() )
03144 return false;
03145 return cryptoMessageFormat() == Kleo::InlineOpenPGPFormat;
03146 }
03147
03148
03149 void KMComposeWin::viewAttach( int index )
03150 {
03151 QString pname;
03152 KMMessagePart* msgPart;
03153 msgPart = mAtmList.at(index);
03154 pname = msgPart->name().stripWhiteSpace();
03155 if (pname.isEmpty()) pname=msgPart->contentDescription();
03156 if (pname.isEmpty()) pname="unnamed";
03157
03158 KTempFile* atmTempFile = new KTempFile();
03159 mAtmTempList.append( atmTempFile );
03160 atmTempFile->setAutoDelete( true );
03161 KPIM::kByteArrayToFile(msgPart->bodyDecodedBinary(), atmTempFile->name(), false, false,
03162 false);
03163 KMReaderMainWin *win = new KMReaderMainWin(msgPart, false,
03164 atmTempFile->name(), pname, mCharset );
03165 win->show();
03166 }
03167
03168
03169 void KMComposeWin::openAttach( int index )
03170 {
03171 KMMessagePart* msgPart = mAtmList.at(index);
03172 const QString contentTypeStr =
03173 ( msgPart->typeStr() + '/' + msgPart->subtypeStr() ).lower();
03174
03175 KMimeType::Ptr mimetype;
03176 mimetype = KMimeType::mimeType( contentTypeStr );
03177
03178 KTempFile* atmTempFile = new KTempFile();
03179 mAtmTempList.append( atmTempFile );
03180 const bool autoDelete = true;
03181 atmTempFile->setAutoDelete( autoDelete );
03182
03183 KURL url;
03184 url.setPath( atmTempFile->name() );
03185
03186 KPIM::kByteArrayToFile( msgPart->bodyDecodedBinary(), atmTempFile->name(), false, false,
03187 false );
03188 if ( ::chmod( QFile::encodeName( atmTempFile->name() ), S_IRUSR ) != 0) {
03189 QFile::remove(url.path());
03190 return;
03191 }
03192
03193 KService::Ptr offer =
03194 KServiceTypeProfile::preferredService( mimetype->name(), "Application" );
03195
03196 if ( !offer || mimetype->name() == "application/octet-stream" ) {
03197 if ( ( !KRun::displayOpenWithDialog( url, autoDelete ) ) && autoDelete ) {
03198 QFile::remove(url.path());
03199 }
03200 }
03201 else {
03202 if ( ( !KRun::run( *offer, url, autoDelete ) ) && autoDelete ) {
03203 QFile::remove( url.path() );
03204 }
03205 }
03206 }
03207
03208
03209 void KMComposeWin::slotAttachSave()
03210 {
03211 KMMessagePart* msgPart;
03212 QString fileName, pname;
03213 int idx = currentAttachmentNum();
03214
03215 if (idx < 0) return;
03216
03217 msgPart = mAtmList.at(idx);
03218 pname = msgPart->name();
03219 if (pname.isEmpty()) pname="unnamed";
03220
03221 KURL url = KFileDialog::getSaveURL(QString::null, QString::null, 0, i18n("Save Attachment As"));
03222
03223 if( url.isEmpty() )
03224 return;
03225
03226 kmkernel->byteArrayToRemoteFile(msgPart->bodyDecodedBinary(), url);
03227 }
03228
03229
03230
03231 void KMComposeWin::slotAttachRemove()
03232 {
03233 bool attachmentRemoved = false;
03234 int i = 0;
03235 for ( QPtrListIterator<QListViewItem> it(mAtmItemList); *it; ) {
03236 if ( (*it)->isSelected() ) {
03237 removeAttach( i );
03238 attachmentRemoved = true;
03239 }
03240 else {
03241 ++it;
03242 ++i;
03243 }
03244 }
03245
03246 if ( attachmentRemoved ) {
03247 setModified( true );
03248 slotUpdateAttachActions();
03249 }
03250 }
03251
03252
03253 void KMComposeWin::slotFind()
03254 {
03255 mEditor->search();
03256 }
03257
03258 void KMComposeWin::slotSearchAgain()
03259 {
03260 mEditor->repeatSearch();
03261 }
03262
03263
03264 void KMComposeWin::slotReplace()
03265 {
03266 mEditor->replace();
03267 }
03268
03269
03270 void KMComposeWin::slotUpdateFont()
03271 {
03272 kdDebug() << "KMComposeWin::slotUpdateFont " << endl;
03273 if ( ! mFixedFontAction ) {
03274 return;
03275 }
03276 mEditor->setFont( mFixedFontAction->isChecked() ? mFixedFont : mBodyFont );
03277 }
03278
03279 QString KMComposeWin::quotePrefixName() const
03280 {
03281 if ( !msg() )
03282 return QString::null;
03283
03284 int languageNr = GlobalSettings::self()->replyCurrentLanguage();
03285 ReplyPhrases replyPhrases( QString::number(languageNr) );
03286 replyPhrases.readConfig();
03287 QString quotePrefix = msg()->formatString(
03288 replyPhrases.indentPrefix() );
03289
03290 quotePrefix = msg()->formatString(quotePrefix);
03291 return quotePrefix;
03292 }
03293
03294 void KMComposeWin::slotPasteAsQuotation()
03295 {
03296 if( mEditor->hasFocus() && msg() )
03297 {
03298 QString s = QApplication::clipboard()->text();
03299 if (!s.isEmpty())
03300 mEditor->insert(addQuotesToText(s));
03301 }
03302 }
03303
03304 void KMComposeWin::slotPasteAsAttachment()
03305 {
03306 KURL url( QApplication::clipboard()->text( QClipboard::Clipboard ) );
03307 if ( url.isValid() ) {
03308 addAttach(QApplication::clipboard()->text( QClipboard::Clipboard ) );
03309 return;
03310 }
03311
03312 if ( QApplication::clipboard()->image().isNull() ) {
03313 bool ok;
03314 QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this );
03315 if ( !ok )
03316 return;
03317 KMMessagePart *msgPart = new KMMessagePart;
03318 msgPart->setName(attName);
03319 QValueList<int> dummy;
03320 msgPart->setBodyAndGuessCte(QCString(QApplication::clipboard()->text().latin1()), dummy,
03321 kmkernel->msgSender()->sendQuotedPrintable());
03322 addAttach(msgPart);
03323 }
03324 else
03325 addImageFromClipboard();
03326
03327 }
03328
03329 void KMComposeWin::slotAddQuotes()
03330 {
03331 if( mEditor->hasFocus() && msg() )
03332 {
03333 if ( mEditor->hasMarkedText()) {
03334 QString s = mEditor->markedText();
03335 if(!s.isEmpty())
03336 mEditor->insert(addQuotesToText(s));
03337 } else {
03338 int l = mEditor->currentLine();
03339 int c = mEditor->currentColumn();
03340 QString s = mEditor->textLine(l);
03341 s.prepend("> ");
03342 mEditor->insertLine(s,l);
03343 mEditor->removeLine(l+1);
03344 mEditor->setCursorPosition(l,c+2);
03345 }
03346 }
03347 }
03348
03349 QString KMComposeWin::addQuotesToText(const QString &inputText)
03350 {
03351 QString answer = QString( inputText );
03352 QString indentStr = quotePrefixName();
03353 answer.replace( '\n', '\n' + indentStr);
03354 answer.prepend( indentStr );
03355 answer += '\n';
03356 return KMMessage::smartQuote( answer, GlobalSettings::self()->lineWrapWidth() );
03357 }
03358
03359 void KMComposeWin::slotRemoveQuotes()
03360 {
03361 if( mEditor->hasFocus() && msg() )
03362 {
03363 QString quotePrefix = quotePrefixName();
03364 if (mEditor->hasMarkedText()) {
03365 QString s = mEditor->markedText();
03366 QString quotePrefix = quotePrefixName();
03367 if (s.left(2) == quotePrefix )
03368 s.remove(0,2);
03369 s.replace("\n"+quotePrefix,"\n");
03370 mEditor->insert(s);
03371 } else {
03372 int l = mEditor->currentLine();
03373 int c = mEditor->currentColumn();
03374 QString s = mEditor->textLine(l);
03375 if (s.left(2) == quotePrefix) {
03376 s.remove(0,2);
03377 mEditor->insertLine(s,l);
03378 mEditor->removeLine(l+1);
03379 mEditor->setCursorPosition(l,c-2);
03380 }
03381 }
03382 }
03383 }
03384
03385
03386
03387 void KMComposeWin::slotUndo()
03388 {
03389 QWidget* fw = focusWidget();
03390 if (!fw) return;
03391
03392 if ( ::qt_cast<KEdit*>(fw) )
03393 static_cast<QMultiLineEdit*>(fw)->undo();
03394 else if (::qt_cast<QLineEdit*>(fw))
03395 static_cast<QLineEdit*>(fw)->undo();
03396 }
03397
03398 void KMComposeWin::slotRedo()
03399 {
03400 QWidget* fw = focusWidget();
03401 if (!fw) return;
03402
03403 if (::qt_cast<KEdit*>(fw))
03404 static_cast<KEdit*>(fw)->redo();
03405 else if (::qt_cast<QLineEdit*>(fw))
03406 static_cast<QLineEdit*>(fw)->redo();
03407 }
03408
03409
03410 void KMComposeWin::slotCut()
03411 {
03412 QWidget* fw = focusWidget();
03413 if (!fw) return;
03414
03415 if (::qt_cast<KEdit*>(fw))
03416 static_cast<KEdit*>(fw)->cut();
03417 else if (::qt_cast<QLineEdit*>(fw))
03418 static_cast<QLineEdit*>(fw)->cut();
03419 }
03420
03421
03422
03423 void KMComposeWin::slotCopy()
03424 {
03425 QWidget* fw = focusWidget();
03426 if (!fw) return;
03427
03428 #ifdef KeyPress
03429 #undef KeyPress
03430 #endif
03431
03432 QKeyEvent k(QEvent::KeyPress, Key_C , 0 , ControlButton);
03433 kapp->notify(fw, &k);
03434 }
03435
03436
03437
03438 void KMComposeWin::slotPaste()
03439 {
03440 QWidget* fw = focusWidget();
03441 if (!fw) return;
03442
03443 if ( ! QApplication::clipboard()->image().isNull() ) {
03444 addImageFromClipboard();
03445 }
03446 else {
03447
03448 #ifdef KeyPress
03449 #undef KeyPress
03450 #endif
03451
03452 QKeyEvent k(QEvent::KeyPress, Key_V , 0 , ControlButton);
03453 kapp->notify(fw, &k);
03454 }
03455
03456 }
03457
03458
03459
03460 void KMComposeWin::slotMarkAll()
03461 {
03462 QWidget* fw = focusWidget();
03463 if (!fw) return;
03464
03465 if (::qt_cast<QLineEdit*>(fw))
03466 static_cast<QLineEdit*>(fw)->selectAll();
03467 else if (::qt_cast<KEdit*>(fw))
03468 static_cast<KEdit*>(fw)->selectAll();
03469 }
03470
03471
03472
03473 void KMComposeWin::slotClose()
03474 {
03475 close(FALSE);
03476 }
03477
03478
03479
03480 void KMComposeWin::slotNewComposer()
03481 {
03482 KMComposeWin* win;
03483 KMMessage* msg = new KMMessage;
03484
03485 msg->initHeader();
03486 win = new KMComposeWin(msg);
03487 win->show();
03488 }
03489
03490
03491
03492 void KMComposeWin::slotNewMailReader()
03493 {
03494 KMMainWin *kmmwin = new KMMainWin(0);
03495 kmmwin->show();
03496
03497 }
03498
03499
03500
03501 void KMComposeWin::slotUpdWinTitle(const QString& text)
03502 {
03503 if (text.isEmpty())
03504 setCaption("("+i18n("unnamed")+")");
03505 else setCaption(text);
03506 }
03507
03508
03509
03510 void KMComposeWin::slotEncryptToggled(bool on)
03511 {
03512 setEncryption( on, true );
03513 }
03514
03515
03516
03517 void KMComposeWin::setEncryption( bool encrypt, bool setByUser )
03518 {
03519 if ( setByUser )
03520 setModified( true );
03521 if ( !mEncryptAction->isEnabled() )
03522 encrypt = false;
03523
03524
03525 else if ( encrypt && encryptToSelf() && !mLastIdentityHasEncryptionKey ) {
03526 if ( setByUser )
03527 KMessageBox::sorry( this,
03528 i18n("<qt><p>You have requested that messages be "
03529 "encrypted to yourself, but the currently selected "
03530 "identity does not define an (OpenPGP or S/MIME) "
03531 "encryption key to use for this.</p>"
03532 "<p>Please select the key(s) to use "
03533 "in the identity configuration.</p>"
03534 "</qt>"),
03535 i18n("Undefined Encryption Key") );
03536 encrypt = false;
03537 }
03538
03539
03540 mEncryptAction->setChecked( encrypt );
03541
03542
03543 if ( encrypt )
03544 mEncryptAction->setIcon("encrypted");
03545 else
03546 mEncryptAction->setIcon("decrypted");
03547
03548
03549 if ( canSignEncryptAttachments() ) {
03550 for ( KMAtmListViewItem* entry =
03551 static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
03552 entry;
03553 entry = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) )
03554 entry->setEncrypt( encrypt );
03555 }
03556 }
03557
03558
03559
03560 void KMComposeWin::slotSignToggled(bool on)
03561 {
03562 setSigning( on, true );
03563 }
03564
03565
03566
03567 void KMComposeWin::setSigning( bool sign, bool setByUser )
03568 {
03569 if ( setByUser )
03570 setModified( true );
03571 if ( !mSignAction->isEnabled() )
03572 sign = false;
03573
03574
03575 if ( sign && !mLastIdentityHasSigningKey ) {
03576 if ( setByUser )
03577 KMessageBox::sorry( this,
03578 i18n("<qt><p>In order to be able to sign "
03579 "this message you first have to "
03580 "define the (OpenPGP or S/MIME) signing key "
03581 "to use.</p>"
03582 "<p>Please select the key to use "
03583 "in the identity configuration.</p>"
03584 "</qt>"),
03585 i18n("Undefined Signing Key") );
03586 sign = false;
03587 }
03588
03589
03590 mSignAction->setChecked( sign );
03591
03592
03593 if ( canSignEncryptAttachments() ) {
03594 for ( KMAtmListViewItem* entry =
03595 static_cast<KMAtmListViewItem*>( mAtmItemList.first() );
03596 entry;
03597 entry = static_cast<KMAtmListViewItem*>( mAtmItemList.next() ) )
03598 entry->setSign( sign );
03599 }
03600 }
03601
03602
03603
03604 void KMComposeWin::slotWordWrapToggled(bool on)
03605 {
03606 if (on)
03607 {
03608 mEditor->setWordWrap( QMultiLineEdit::FixedColumnWidth );
03609 mEditor->setWrapColumnOrWidth( GlobalSettings::self()->lineWrapWidth() );
03610 }
03611 else
03612 {
03613 mEditor->setWordWrap( QMultiLineEdit::NoWrap );
03614 }
03615 }
03616
03617
03618
03619 void KMComposeWin::slotPrint()
03620 {
03621 mMessageWasModified = isModified();
03622 connect( this, SIGNAL( applyChangesDone( bool ) ),
03623 this, SLOT( slotContinuePrint( bool ) ) );
03624 applyChanges( true );
03625 }
03626
03627 void KMComposeWin::slotContinuePrint( bool rc )
03628 {
03629 disconnect( this, SIGNAL( applyChangesDone( bool ) ),
03630 this, SLOT( slotContinuePrint( bool ) ) );
03631
03632 if( rc ) {
03633 if ( mComposedMessages.isEmpty() ) {
03634 kdDebug(5006) << "Composing the message failed." << endl;
03635 return;
03636 }
03637 KMCommand *command = new KMPrintCommand( this, mComposedMessages.first() );
03638 command->start();
03639 setModified( mMessageWasModified );
03640 }
03641 }
03642
03643
03644 bool KMComposeWin::validateAddresses( QWidget * parent, const QString & addresses )
03645 {
03646 QString brokenAddress;
03647 KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( KMMessage::expandAliases( addresses ), brokenAddress );
03648 if ( !( errorCode == KPIM::AddressOk || errorCode == KPIM::AddressEmpty ) ) {
03649 QString errorMsg( "<qt><p><b>" + brokenAddress +
03650 "</b></p><p>" + KPIM::emailParseResultToString( errorCode ) +
03651 "</p></qt>" );
03652 KMessageBox::sorry( parent, errorMsg, i18n("Invalid Email Address") );
03653 return false;
03654 }
03655 return true;
03656 }
03657
03658
03659 void KMComposeWin::doSend( KMail::MessageSender::SendMethod method, bool saveInDrafts)
03660 {
03661 if ( method != KMail::MessageSender::SendLater && kmkernel->isOffline() ) {
03662 KMessageBox::information( this,
03663 i18n("KMail is currently in offline mode,"
03664 "your messages will be kept in the outbox until you go online."),
03665 i18n("Online/Offline"), "kmailIsOffline" );
03666 mSendMethod = KMail::MessageSender::SendLater;
03667 } else {
03668 mSendMethod = method;
03669 }
03670 mSaveInDrafts = saveInDrafts;
03671
03672 if (!saveInDrafts)
03673 {
03674 if ( KPIM::getFirstEmailAddress( from() ).isEmpty() ) {
03675 if ( !( mShowHeaders & HDR_FROM ) ) {
03676 mShowHeaders |= HDR_FROM;
03677 rethinkFields( false );
03678 }
03679 mEdtFrom->setFocus();
03680 KMessageBox::sorry( this,
03681 i18n("You must enter your email address in the "
03682 "From: field. You should also set your email "
03683 "address for all identities, so that you do "
03684 "not have to enter it for each message.") );
03685 return;
03686 }
03687 if (to().isEmpty() && cc().isEmpty() && bcc().isEmpty())
03688 {
03689 if ( mEdtTo ) mEdtTo->setFocus();
03690 KMessageBox::information( this,
03691 i18n("You must specify at least one receiver,"
03692 "either in the To: field or as CC or as BCC.") );
03693 return;
03694 }
03695
03696
03697 if ( !validateAddresses( this, to().stripWhiteSpace() ) ) {
03698 return;
03699 }
03700
03701 if ( !validateAddresses( this, cc().stripWhiteSpace() ) ) {
03702 return;
03703 }
03704
03705 if ( !validateAddresses( this, bcc().stripWhiteSpace() ) ) {
03706 return;
03707 }
03708
03709 if (subject().isEmpty())
03710 {
03711 mEdtSubject->setFocus();
03712 int rc =
03713 KMessageBox::questionYesNo( this,
03714 i18n("You did not specify a subject. "
03715 "Send message anyway?"),
03716 i18n("No Subject Specified"),
03717 i18n("S&end as Is"),
03718 i18n("&Specify the Subject"),
03719 "no_subject_specified" );
03720 if( rc == KMessageBox::No )
03721 {
03722 return;
03723 }
03724 }
03725
03726 if ( userForgotAttachment() )
03727 return;
03728 }
03729
03730 KCursorSaver busy(KBusyPtr::busy());
03731 mMsg->setDateToday();
03732
03733
03734
03735
03736
03737
03738 QString hf = mMsg->headerField("X-KMail-Transport");
03739 if ((mTransport->currentText() != mTransport->text(0)) ||
03740 (!hf.isEmpty() && (hf != mTransport->text(0))))
03741 mMsg->setHeaderField("X-KMail-Transport", mTransport->currentText());
03742
03743 mDisableBreaking = saveInDrafts;
03744
03745 const bool neverEncrypt = ( saveInDrafts && GlobalSettings::self()->neverEncryptDrafts() )
03746 || mSigningAndEncryptionExplicitlyDisabled;
03747 connect( this, SIGNAL( applyChangesDone( bool ) ),
03748 SLOT( slotContinueDoSend( bool ) ) );
03749
03750 if ( mEditor->textFormat() == Qt::RichText )
03751 mMsg->setHeaderField( "X-KMail-Markup", "true" );
03752 else
03753 mMsg->removeHeaderField( "X-KMail-Markup" );
03754 if ( mEditor->textFormat() == Qt::RichText && inlineSigningEncryptionSelected() ) {
03755 QString keepBtnText = mEncryptAction->isChecked() ?
03756 mSignAction->isChecked() ? i18n( "&Keep markup, do not sign/encrypt" )
03757 : i18n( "&Keep markup, do not encrypt" )
03758 : i18n( "&Keep markup, do not sign" );
03759 QString yesBtnText = mEncryptAction->isChecked() ?
03760 mSignAction->isChecked() ? i18n("Sign/Encrypt (delete markup)")
03761 : i18n( "Encrypt (delete markup)" )
03762 : i18n( "Sign (delete markup)" );
03763 int ret = KMessageBox::warningYesNoCancel(this,
03764 i18n("<qt><p>Inline signing/encrypting of HTML messages is not possible;</p>"
03765 "<p>do you want to delete your markup?</p></qt>"),
03766 i18n("Sign/Encrypt Message?"),
03767 KGuiItem( yesBtnText ),
03768 KGuiItem( keepBtnText ) );
03769 if ( KMessageBox::Cancel == ret )
03770 return;
03771 if ( KMessageBox::No == ret ) {
03772 mEncryptAction->setChecked(false);
03773 mSignAction->setChecked(false);
03774 }
03775 else {
03776 toggleMarkup(false);
03777 }
03778 }
03779
03780 kdDebug(5006) << "KMComposeWin::doSend() - calling applyChanges()"
03781 << endl;
03782 applyChanges( neverEncrypt );
03783 }
03784
03785 void KMComposeWin::slotContinueDoSend( bool sentOk )
03786 {
03787 kdDebug(5006) << "KMComposeWin::slotContinueDoSend( " << sentOk << " )"
03788 << endl;
03789 disconnect( this, SIGNAL( applyChangesDone( bool ) ),
03790 this, SLOT( slotContinueDoSend( bool ) ) );
03791
03792 if ( !sentOk ) {
03793 mDisableBreaking = false;
03794 return;
03795 }
03796
03797 for ( QValueVector<KMMessage*>::iterator it = mComposedMessages.begin() ; it != mComposedMessages.end() ; ++it ) {
03798
03799
03800 (*it)->cleanupHeader();
03801
03802
03803 (*it)->setComplete( true );
03804
03805 if (mSaveInDrafts) {
03806 KMFolder* draftsFolder = 0, *imapDraftsFolder = 0;
03807
03808 if ( !(*it)->drafts().isEmpty() ) {
03809 draftsFolder = kmkernel->folderMgr()->findIdString( (*it)->drafts() );
03810 if ( draftsFolder == 0 )
03811
03812
03813 draftsFolder = kmkernel->dimapFolderMgr()->findIdString( (*it)->drafts() );
03814 if ( draftsFolder == 0 )
03815 imapDraftsFolder = kmkernel->imapFolderMgr()->findIdString( (*it)->drafts() );
03816 if ( !draftsFolder && !imapDraftsFolder ) {
03817 const KPIM::Identity & id = kmkernel->identityManager()
03818 ->identityForUoidOrDefault( (*it)->headerField( "X-KMail-Identity" ).stripWhiteSpace().toUInt() );
03819 KMessageBox::information(0, i18n("The custom drafts folder for identity "
03820 "\"%1\" does not exist (anymore); "
03821 "therefore, the default drafts folder "
03822 "will be used.")
03823 .arg( id.identityName() ) );
03824 }
03825 }
03826 if (imapDraftsFolder && imapDraftsFolder->noContent())
03827 imapDraftsFolder = 0;
03828
03829 if ( draftsFolder == 0 ) {
03830 draftsFolder = kmkernel->draftsFolder();
03831 } else {
03832 draftsFolder->open();
03833 }
03834 kdDebug(5006) << "saveindrafts: drafts=" << draftsFolder->name() << endl;
03835 if (imapDraftsFolder)
03836 kdDebug(5006) << "saveindrafts: imapdrafts="
03837 << imapDraftsFolder->name() << endl;
03838
03839 sentOk = !(draftsFolder->addMsg((*it)));
03840
03841
03842 draftsFolder->unGetMsg(draftsFolder->count() - 1);
03843 (*it) = draftsFolder->getMsg(draftsFolder->count() - 1);
03844
03845 if (imapDraftsFolder) {
03846
03847 imapDraftsFolder->moveMsg((*it));
03848 (static_cast<KMFolderImap*>(imapDraftsFolder->storage()))->getFolder();
03849 }
03850
03851 } else {
03852 (*it)->setTo( KMMessage::expandAliases( to() ));
03853 (*it)->setCc( KMMessage::expandAliases( cc() ));
03854 if( !mComposer->originalBCC().isEmpty() )
03855 (*it)->setBcc( KMMessage::expandAliases( mComposer->originalBCC() ));
03856 QString recips = (*it)->headerField( "X-KMail-Recipients" );
03857 if( !recips.isEmpty() ) {
03858 (*it)->setHeaderField( "X-KMail-Recipients", KMMessage::expandAliases( recips ), KMMessage::Address );
03859 }
03860 (*it)->cleanupHeader();
03861 sentOk = kmkernel->msgSender()->send((*it), mSendMethod);
03862 }
03863
03864 if (!sentOk)
03865 return;
03866
03867 *it = 0;
03868 }
03869
03870 RecentAddresses::self( KMKernel::config() )->add( bcc() );
03871 RecentAddresses::self( KMKernel::config() )->add( cc() );
03872 RecentAddresses::self( KMKernel::config() )->add( to() );
03873
03874 setModified( false );
03875 mAutoDeleteMsg = FALSE;
03876 mFolder = 0;
03877 cleanupAutoSave();
03878 close();
03879 return;
03880 }
03881
03882
03883
03884
03885 void KMComposeWin::slotSendLater()
03886 {
03887 if ( mEditor->checkExternalEditorFinished() )
03888 doSend( KMail::MessageSender::SendLater );
03889 }
03890
03891
03892
03893 void KMComposeWin::slotSaveDraft() {
03894 if ( mEditor->checkExternalEditorFinished() )
03895 doSend( KMail::MessageSender::SendLater, true );
03896 }
03897
03898
03899
03900 void KMComposeWin::slotSendNowVia( int item )
03901 {
03902 QStringList availTransports= KMail::TransportManager::transportNames();
03903 QString customTransport = availTransports[ item ];
03904
03905 mTransport->setCurrentText( customTransport );
03906 slotSendNow();
03907 }
03908
03909
03910 void KMComposeWin::slotSendLaterVia( int item )
03911 {
03912 QStringList availTransports= KMail::TransportManager::transportNames();
03913 QString customTransport = availTransports[ item ];
03914
03915 mTransport->setCurrentText( customTransport );
03916 slotSendLater();
03917 }
03918
03919
03920
03921 void KMComposeWin::slotSendNow() {
03922 if ( !mEditor->checkExternalEditorFinished() )
03923 return;
03924 if ( GlobalSettings::self()->confirmBeforeSend() )
03925 {
03926 int rc = KMessageBox::warningYesNoCancel( mMainWidget,
03927 i18n("About to send email..."),
03928 i18n("Send Confirmation"),
03929 i18n("&Send Now"),
03930 i18n("Send &Later") );
03931
03932 if ( rc == KMessageBox::Yes )
03933 doSend( KMail::MessageSender::SendImmediate );
03934 else if ( rc == KMessageBox::No )
03935 doSend( KMail::MessageSender::SendLater );
03936 }
03937 else
03938 doSend( KMail::MessageSender::SendImmediate );
03939 }
03940
03941
03942
03943 void KMComposeWin::slotAppendSignature()
03944 {
03945 bool mod = mEditor->isModified();
03946
03947 const KPIM::Identity & ident =
03948 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
03949 mOldSigText = ident.signatureText();
03950 if( !mOldSigText.isEmpty() )
03951 {
03952 mEditor->append(mOldSigText);
03953 mEditor->setModified(mod);
03954 mEditor->setContentsPos( 0, 0 );
03955 mEditor->sync();
03956 }
03957 }
03958
03959
03960
03961 void KMComposeWin::slotHelp()
03962 {
03963 kapp->invokeHelp();
03964 }
03965
03966
03967 void KMComposeWin::slotCleanSpace()
03968 {
03969 mEditor->cleanWhiteSpace();
03970 }
03971
03972
03973 void KMComposeWin::slotToggleMarkup()
03974 {
03975 if ( markupAction->isChecked() ) {
03976 mHtmlMarkup = true;
03977 toolBar("htmlToolBar")->show();
03978
03979 fontChanged( mEditor->currentFont().family() );
03980 fontAction->setFont( mEditor->currentFont().family() );
03981 fontSizeAction->setFontSize( mEditor->currentFont().pointSize() );
03982 mSaveFont = mEditor->currentFont();
03983 }
03984 else
03985 toggleMarkup(false);
03986
03987 }
03988
03989 void KMComposeWin::toggleMarkup(bool markup)
03990 {
03991 if ( markup ) {
03992 if ( !mUseHTMLEditor ) {
03993 kdDebug(5006) << "setting RichText editor" << endl;
03994 mUseHTMLEditor = true;
03995 mHtmlMarkup = true;
03996
03997
03998 int paraFrom, indexFrom, paraTo, indexTo;
03999 mEditor->getSelection ( ¶From, &indexFrom, ¶To, &indexTo);
04000 mEditor->selectAll();
04001
04002 bool _bold = textBoldAction->isChecked();
04003 bool _italic = textItalicAction->isChecked();
04004 mEditor->setColor(QColor(0,0,0));
04005 textBoldAction->setChecked(_bold);
04006 textItalicAction->setChecked(_italic);
04007 mEditor->setSelection ( paraFrom, indexFrom, paraTo, indexTo);
04008
04009 mEditor->setTextFormat(Qt::RichText);
04010 mEditor->setModified(true);
04011 markupAction->setChecked(true);
04012 toolBar( "htmlToolBar" )->show();
04013 mEditor->deleteAutoSpellChecking();
04014 mAutoSpellCheckingAction->setChecked(false);
04015 slotAutoSpellCheckingToggled(false);
04016 }
04017 } else {
04018 kdDebug(5006) << "setting PlainText editor" << endl;
04019 mHtmlMarkup = false;
04020 toolBar("htmlToolBar")->hide();
04021 if ( mUseHTMLEditor ) {
04022 mUseHTMLEditor = false;
04023 mEditor->setTextFormat(Qt::PlainText);
04024 QString text = mEditor->text();
04025 mEditor->setText(text);
04026 mEditor->setModified(true);
04027 slotAutoSpellCheckingToggled(true);
04028 }
04029 }
04030 }
04031
04032 void KMComposeWin::slotSubjectTextSpellChecked()
04033 {
04034 mSubjectTextWasSpellChecked = true;
04035 }
04036
04037
04038 void KMComposeWin::slotAutoSpellCheckingToggled( bool on )
04039 {
04040 if ( mEditor->autoSpellChecking(on) == -1 )
04041 mAutoSpellCheckingAction->setChecked(false);
04042 }
04043
04044 void KMComposeWin::slotSpellcheck()
04045 {
04046 if (mSpellCheckInProgress) return;
04047 mSubjectTextWasSpellChecked = false;
04048 mSpellCheckInProgress=TRUE;
04049
04050
04051
04052
04053
04054 mEditor->spellcheck();
04055 }
04056
04057 void KMComposeWin::polish()
04058 {
04059
04060 markupAction->setChecked(mHtmlMarkup);
04061 if (mHtmlMarkup)
04062 toolBar("htmlToolBar")->show();
04063 else
04064 toolBar("htmlToolBar")->hide();
04065 KMail::Composer::polish();
04066 }
04067
04068
04069 void KMComposeWin::slotSpellcheckDone(int result)
04070 {
04071 kdDebug(5006) << "spell check complete: result = " << result << endl;
04072 mSpellCheckInProgress=FALSE;
04073
04074 switch( result )
04075 {
04076 case KS_CANCEL:
04077 statusBar()->changeItem(i18n(" Spell check canceled."),0);
04078 break;
04079 case KS_STOP:
04080 statusBar()->changeItem(i18n(" Spell check stopped."),0);
04081 break;
04082 default:
04083 statusBar()->changeItem(i18n(" Spell check complete."),0);
04084 break;
04085 }
04086 QTimer::singleShot( 2000, this, SLOT(slotSpellcheckDoneClearStatus()) );
04087 }
04088
04089 void KMComposeWin::slotSpellcheckDoneClearStatus()
04090 {
04091 statusBar()->changeItem("", 0);
04092 }
04093
04094
04095
04096 void KMComposeWin::slotIdentityChanged( uint uoid )
04097 {
04098 const KPIM::Identity & ident =
04099 kmkernel->identityManager()->identityForUoid( uoid );
04100 if( ident.isNull() ) return;
04101
04102 if( !ident.fullEmailAddr().isNull() )
04103 mEdtFrom->setText(ident.fullEmailAddr());
04104
04105 if ( KPIM::getFirstEmailAddress( from() ).isEmpty() )
04106 mShowHeaders |= HDR_FROM;
04107 if ( mEdtReplyTo ) mEdtReplyTo->setText(ident.replyToAddr());
04108
04109 if ( mRecipientsEditor ) {
04110
04111 const KPIM::Identity & oldIdentity =
04112 kmkernel->identityManager()->identityForUoidOrDefault( mId );
04113 if ( oldIdentity.bcc() != ident.bcc() ) {
04114 mRecipientsEditor->removeRecipient( oldIdentity.bcc(), Recipient::Bcc );
04115 mRecipientsEditor->addRecipient( ident.bcc(), Recipient::Bcc );
04116 }
04117 }
04118
04119
04120
04121 if( mEdtBcc && !mEdtBcc->edited() && !ident.bcc().isEmpty() ) {
04122
04123
04124 if( !mEdtBcc->text().isEmpty() && mEdtBcc->text() != ident.bcc() && !mEdtBcc->edited() ) {
04125 mEdtBcc->setText( ident.bcc() );
04126 } else {
04127
04128
04129
04130 if ( mEdtBcc->text() != ident.bcc() && !mEdtBcc->text().isEmpty() ) {
04131 QString temp_string( mEdtBcc->text() + QString::fromLatin1(",") + ident.bcc() );
04132 mEdtBcc->setText( temp_string );
04133 } else {
04134
04135
04136 mEdtBcc->setText( ident.bcc() );
04137 }
04138 }
04139 }
04140
04141
04142
04143 if( mEdtBcc && mEdtBcc->edited() && !ident.bcc().isEmpty() ) {
04144 if( !mEdtBcc->text().isEmpty() ) {
04145 QString temp_string ( mEdtBcc->text() + QString::fromLatin1(",") + ident.bcc() );
04146 mEdtBcc->setText( temp_string );
04147 } else {
04148 mEdtBcc->setText( ident.bcc() );
04149 }
04150 }
04151
04152
04153
04154 if( mEdtBcc && !mEdtBcc->edited() && ident.bcc().isEmpty() ) {
04155 mEdtBcc->setText( ident.bcc() );
04156 }
04157
04158 if ( !ident.bcc().isEmpty() ) {
04159 mShowHeaders |= HDR_BCC;
04160 }
04161
04162 if ( ident.organization().isEmpty() )
04163 mMsg->removeHeaderField("Organization");
04164 else
04165 mMsg->setHeaderField("Organization", ident.organization());
04166
04167 if (!ident.isXFaceEnabled() || ident.xface().isEmpty())
04168 mMsg->removeHeaderField("X-Face");
04169 else
04170 {
04171 QString xface = ident.xface();
04172 if (!xface.isEmpty())
04173 {
04174 int numNL = ( xface.length() - 1 ) / 70;
04175 for ( int i = numNL; i > 0; --i )
04176 xface.insert( i*70, "\n\t" );
04177 mMsg->setHeaderField("X-Face", xface);
04178 }
04179 }
04180
04181 if ( !mBtnTransport->isChecked() ) {
04182 QString transp = ident.transport();
04183 if ( transp.isEmpty() )
04184 {
04185 mMsg->removeHeaderField("X-KMail-Transport");
04186 transp = mTransport->text(0);
04187 }
04188 else
04189 mMsg->setHeaderField("X-KMail-Transport", transp);
04190 bool found = false;
04191 int i;
04192 for (i = 0; i < mTransport->count(); i++) {
04193 if (mTransport->text(i) == transp) {
04194 found = true;
04195 mTransport->setCurrentItem(i);
04196 break;
04197 }
04198 }
04199 if (found == false) {
04200 if (i == mTransport->maxCount()) mTransport->setMaxCount(i + 1);
04201 mTransport->insertItem(transp,i);
04202 mTransport->setCurrentItem(i);
04203 }
04204 }
04205
04206 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
04207
04208 if ( !mBtnFcc->isChecked() ) {
04209 setFcc( ident.fcc() );
04210 }
04211
04212 QString edtText = mEditor->text();
04213 bool appendNewSig = true;
04214
04215 if( !mOldSigText.isEmpty() )
04216 {
04217 if( edtText.endsWith( mOldSigText ) )
04218 edtText.truncate( edtText.length() - mOldSigText.length() );
04219 else
04220 appendNewSig = false;
04221 }
04222
04223 mOldSigText = ident.signatureText();
04224 if( appendNewSig )
04225 {
04226 if( (!mOldSigText.isEmpty()) &&
04227 (GlobalSettings::self()->autoTextSignature()=="auto") )
04228 edtText.append( mOldSigText );
04229 mEditor->setText( edtText );
04230 }
04231
04232
04233
04234 bool bNewIdentityHasSigningKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
04235 bool bNewIdentityHasEncryptionKey = !ident.pgpSigningKey().isEmpty() || !ident.smimeSigningKey().isEmpty();
04236 mAttachMPK->setEnabled( Kleo::CryptoBackendFactory::instance()->openpgp() &&
04237 !ident.pgpEncryptionKey().isEmpty() );
04238
04239 if ( !bNewIdentityHasEncryptionKey && mLastIdentityHasEncryptionKey ) {
04240 mLastEncryptActionState = mEncryptAction->isChecked();
04241 setEncryption( false );
04242 }
04243 if ( !bNewIdentityHasSigningKey && mLastIdentityHasSigningKey ) {
04244 mLastSignActionState = mSignAction->isChecked();
04245 setSigning( false );
04246 }
04247
04248 if ( bNewIdentityHasEncryptionKey && !mLastIdentityHasEncryptionKey )
04249 setEncryption( mLastEncryptActionState );
04250 if ( bNewIdentityHasSigningKey && !mLastIdentityHasSigningKey )
04251 setSigning( mLastSignActionState );
04252
04253 mLastIdentityHasSigningKey = bNewIdentityHasSigningKey;
04254 mLastIdentityHasEncryptionKey = bNewIdentityHasEncryptionKey;
04255
04256 setModified( true );
04257 mId = uoid;
04258
04259
04260 rethinkFields( false );
04261 }
04262
04263
04264 void KMComposeWin::slotSpellcheckConfig()
04265 {
04266 KDialogBase dlg(KDialogBase::Plain, i18n("Spellchecker"),
04267 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok,
04268 this, 0, true, true );
04269 KWin kwin;
04270 QTabDialog qtd (this, "tabdialog", true);
04271 KSpellConfig mKSpellConfig (&qtd);
04272 mKSpellConfig.layout()->setMargin( KDialog::marginHint() );
04273
04274 qtd.addTab (&mKSpellConfig, i18n("Spellchecker"));
04275 qtd.setCancelButton ();
04276
04277 kwin.setIcons (qtd.winId(), kapp->icon(), kapp->miniIcon());
04278 qtd.setCancelButton(KStdGuiItem::cancel().text());
04279 qtd.setOkButton(KStdGuiItem::ok().text());
04280
04281 if (qtd.exec())
04282 mKSpellConfig.writeGlobalSettings();
04283 }
04284
04285
04286 void KMComposeWin::slotStatusMessage(const QString &message)
04287 {
04288 statusBar()->changeItem( message, 0 );
04289 }
04290
04291 void KMComposeWin::slotEditToolbars()
04292 {
04293 saveMainWindowSettings(KMKernel::config(), "Composer");
04294 KEditToolbar dlg(guiFactory(), this);
04295
04296 connect( &dlg, SIGNAL(newToolbarConfig()),
04297 SLOT(slotUpdateToolbars()) );
04298
04299 dlg.exec();
04300 }
04301
04302 void KMComposeWin::slotUpdateToolbars()
04303 {
04304 createGUI("kmcomposerui.rc");
04305 applyMainWindowSettings(KMKernel::config(), "Composer");
04306 }
04307
04308 void KMComposeWin::slotEditKeys()
04309 {
04310 KKeyDialog::configure( actionCollection(),
04311 false
04312 );
04313 }
04314
04315 void KMComposeWin::setReplyFocus( bool hasMessage )
04316 {
04317 mEditor->setFocus();
04318 if ( hasMessage )
04319 mEditor->setCursorPosition( 1, 0 );
04320 }
04321
04322 void KMComposeWin::setFocusToSubject()
04323 {
04324 mEdtSubject->setFocus();
04325 }
04326
04327 int KMComposeWin::autoSaveInterval() const
04328 {
04329 return GlobalSettings::self()->autosaveInterval() * 1000 * 60;
04330 }
04331
04332 void KMComposeWin::initAutoSave()
04333 {
04334 kdDebug(5006) << k_funcinfo << endl;
04335
04336 KMFolderMaildir::createMaildirFolders( KMKernel::localDataPath() + "autosave" );
04337 if ( mAutoSaveFilename.isEmpty() ) {
04338 mAutoSaveFilename = KMFolderMaildir::constructValidFileName();
04339 }
04340
04341 updateAutoSave();
04342 }
04343
04344 void KMComposeWin::updateAutoSave()
04345 {
04346 if ( autoSaveInterval() == 0 ) {
04347 delete mAutoSaveTimer; mAutoSaveTimer = 0;
04348 }
04349 else {
04350 if ( !mAutoSaveTimer ) {
04351 mAutoSaveTimer = new QTimer( this );
04352 connect( mAutoSaveTimer, SIGNAL( timeout() ),
04353 this, SLOT( autoSaveMessage() ) );
04354 }
04355 mAutoSaveTimer->start( autoSaveInterval() );
04356 }
04357 }
04358
04359 void KMComposeWin::setAutoSaveFilename( const QString & filename )
04360 {
04361 if ( !mAutoSaveFilename.isEmpty() )
04362 KMFolderMaildir::removeFile( KMKernel::localDataPath() + "autosave",
04363 mAutoSaveFilename );
04364 mAutoSaveFilename = filename;
04365 }
04366
04367 void KMComposeWin::cleanupAutoSave()
04368 {
04369 delete mAutoSaveTimer; mAutoSaveTimer = 0;
04370 if ( !mAutoSaveFilename.isEmpty() ) {
04371 kdDebug(5006) << k_funcinfo << "deleting autosave file "
04372 << mAutoSaveFilename << endl;
04373 KMFolderMaildir::removeFile( KMKernel::localDataPath() + "autosave",
04374 mAutoSaveFilename );
04375 mAutoSaveFilename = QString();
04376 }
04377 }
04378
04379 void KMComposeWin::slotCompletionModeChanged( KGlobalSettings::Completion mode)
04380 {
04381 GlobalSettings::self()->setCompletionMode( (int) mode );
04382
04383
04384 mEdtFrom->setCompletionMode( mode );
04385 mEdtReplyTo->setCompletionMode( mode );
04386 if ( mClassicalRecipients ) {
04387 mEdtTo->setCompletionMode( mode );
04388 mEdtCc->setCompletionMode( mode );
04389 mEdtBcc->setCompletionMode( mode );
04390 }
04391 }
04392
04393 void KMComposeWin::slotConfigChanged()
04394 {
04395 readConfig();
04396 updateAutoSave();
04397 rethinkFields();
04398 }
04399
04400
04401
04402
04403
04404 void KMComposeWin::slotFolderRemoved(KMFolder* folder)
04405 {
04406 if ( (mFolder) && (folder->idString() == mFolder->idString()) )
04407 {
04408 mFolder = kmkernel->draftsFolder();
04409 kdDebug(5006) << "restoring drafts to " << mFolder->idString() << endl;
04410 }
04411 if (mMsg) mMsg->setParent(0);
04412 }
04413
04414
04415 void KMComposeWin::editorFocusChanged(bool gained)
04416 {
04417 mPasteQuotation->setEnabled(gained);
04418 mAddQuoteChars->setEnabled(gained);
04419 mRemQuoteChars->setEnabled(gained);
04420 }
04421
04422 void KMComposeWin::slotSetAlwaysSend( bool bAlways )
04423 {
04424 mAlwaysSend = bAlways;
04425 }
04426
04427 void KMComposeWin::slotListAction( const QString& style )
04428 {
04429 toggleMarkup(true);
04430 if ( style == i18n( "Standard" ) )
04431 mEditor->setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc );
04432 else if ( style == i18n( "Bulleted List (Disc)" ) )
04433 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc );
04434 else if ( style == i18n( "Bulleted List (Circle)" ) )
04435 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListCircle );
04436 else if ( style == i18n( "Bulleted List (Square)" ) )
04437 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListSquare );
04438 else if ( style == i18n( "Ordered List (Decimal)" ))
04439 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal );
04440 else if ( style == i18n( "Ordered List (Alpha lower)" ) )
04441 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha );
04442 else if ( style == i18n( "Ordered List (Alpha upper)" ) )
04443 mEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha );
04444 mEditor->viewport()->setFocus();
04445 }
04446
04447 void KMComposeWin::slotFontAction( const QString& font)
04448 {
04449 toggleMarkup(true);
04450 mEditor->QTextEdit::setFamily( font );
04451 mEditor->viewport()->setFocus();
04452 }
04453
04454 void KMComposeWin::slotSizeAction( int size )
04455 {
04456 toggleMarkup(true);
04457 mEditor->setPointSize( size );
04458 mEditor->viewport()->setFocus();
04459 }
04460
04461 void KMComposeWin::slotAlignLeft()
04462 {
04463 toggleMarkup(true);
04464 mEditor->QTextEdit::setAlignment( AlignLeft );
04465 }
04466
04467 void KMComposeWin::slotAlignCenter()
04468 {
04469 toggleMarkup(true);
04470 mEditor->QTextEdit::setAlignment( AlignHCenter );
04471 }
04472
04473 void KMComposeWin::slotAlignRight()
04474 {
04475 toggleMarkup(true);
04476 mEditor->QTextEdit::setAlignment( AlignRight );
04477 }
04478
04479 void KMComposeWin::slotTextBold()
04480 {
04481 toggleMarkup(true);
04482 mEditor->QTextEdit::setBold( textBoldAction->isChecked() );
04483 }
04484
04485 void KMComposeWin::slotTextItalic()
04486 {
04487 toggleMarkup(true);
04488 mEditor->QTextEdit::setItalic( textItalicAction->isChecked() );
04489 }
04490
04491 void KMComposeWin::slotTextUnder()
04492 {
04493 toggleMarkup(true);
04494 mEditor->QTextEdit::setUnderline( textUnderAction->isChecked() );
04495 }
04496
04497 void KMComposeWin::slotFormatReset()
04498 {
04499 mEditor->setColor(mForeColor);
04500 mEditor->setCurrentFont( mSaveFont );
04501 }
04502 void KMComposeWin::slotTextColor()
04503 {
04504 QColor color = mEditor->color();
04505
04506 if ( KColorDialog::getColor( color, this ) ) {
04507 toggleMarkup(true);
04508 mEditor->setColor( color );
04509 }
04510 }
04511
04512 void KMComposeWin::fontChanged( const QFont &f )
04513 {
04514 QFontDatabase *fontdb = new QFontDatabase();
04515
04516 if ( fontdb->bold(f.family(), "Bold") ) {
04517 textBoldAction->setChecked( f.bold() );
04518 textBoldAction->setEnabled(true);
04519 }
04520 else
04521 textBoldAction->setEnabled(false);
04522
04523 if ( fontdb->italic(f.family(), "Italic") ) {
04524 textItalicAction->setChecked( f.italic() );
04525 textItalicAction->setEnabled(true);
04526 }
04527 else
04528 textItalicAction->setEnabled(false);
04529
04530 textUnderAction->setChecked( f.underline() );
04531
04532 fontAction->setFont( f.family() );
04533 fontSizeAction->setFontSize( f.pointSize() );
04534 delete fontdb;
04535 }
04536
04537 void KMComposeWin::alignmentChanged( int a )
04538 {
04539
04540 alignLeftAction->setChecked( ( a == AlignAuto ) || ( a & AlignLeft ) );
04541 alignCenterAction->setChecked( ( a & AlignHCenter ) );
04542 alignRightAction->setChecked( ( a & AlignRight ) );
04543 }
04544
04545 namespace {
04546 class KToggleActionResetter {
04547 KToggleAction * mAction;
04548 bool mOn;
04549 public:
04550 KToggleActionResetter( KToggleAction * action, bool on )
04551 : mAction( action ), mOn( on ) {}
04552 ~KToggleActionResetter() {
04553 if ( mAction )
04554 mAction->setChecked( mOn );
04555 }
04556 void disable() { mAction = 0; }
04557 };
04558 }
04559
04560 void KMComposeWin::slotEncryptChiasmusToggled( bool on ) {
04561 mEncryptWithChiasmus = false;
04562
04563 if ( !on )
04564 return;
04565
04566 KToggleActionResetter resetter( mEncryptChiasmusAction, false );
04567
04568 const Kleo::CryptoBackend::Protocol * chiasmus =
04569 Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" );
04570
04571 if ( !chiasmus ) {
04572 const QString msg = Kleo::CryptoBackendFactory::instance()->knowsAboutProtocol( "Chiasmus" )
04573 ? i18n( "Please configure a Crypto Backend to use for "
04574 "Chiasmus encryption first.\n"
04575 "You can do this in the Crypto Backends tab of "
04576 "the configure dialog's Security page." )
04577 : i18n( "It looks as though libkleopatra was compiled without "
04578 "Chiasmus support. You might want to recompile "
04579 "libkleopatra with --enable-chiasmus.");
04580 KMessageBox::information( this, msg, i18n("No Chiasmus Backend Configured" ) );
04581 return;
04582 }
04583
04584 STD_NAMESPACE_PREFIX auto_ptr<Kleo::SpecialJob> job( chiasmus->specialJob( "x-obtain-keys", QMap<QString,QVariant>() ) );
04585 if ( !job.get() ) {
04586 const QString msg = i18n( "Chiasmus backend does not offer the "
04587 "\"x-obtain-keys\" function. Please report this bug." );
04588 KMessageBox::error( this, msg, i18n( "Chiasmus Backend Error" ) );
04589 return;
04590 }
04591
04592 if ( job->exec() ) {
04593 job->showErrorDialog( this, i18n( "Chiasmus Backend Error" ) );
04594 return;
04595 }
04596
04597 const QVariant result = job->property( "result" );
04598 if ( result.type() != QVariant::StringList ) {
04599 const QString msg = i18n( "Unexpected return value from Chiasmus backend: "
04600 "The \"x-obtain-keys\" function did not return a "
04601 "string list. Please report this bug." );
04602 KMessageBox::error( this, msg, i18n( "Chiasmus Backend Error" ) );
04603 return;
04604 }
04605
04606 const QStringList keys = result.toStringList();
04607 if ( keys.empty() ) {
04608 const QString msg = i18n( "No keys have been found. Please check that a "
04609 "valid key path has been set in the Chiasmus "
04610 "configuration." );
04611 KMessageBox::information( this, msg, i18n( "No Chiasmus Keys Found" ) );
04612 return;
04613 }
04614
04615 ChiasmusKeySelector selectorDlg( this, i18n( "Chiasmus Encryption Key Selection" ),
04616 keys, GlobalSettings::chiasmusKey(),
04617 GlobalSettings::chiasmusOptions() );
04618 if ( selectorDlg.exec() != QDialog::Accepted )
04619 return;
04620
04621 GlobalSettings::setChiasmusOptions( selectorDlg.options() );
04622 GlobalSettings::setChiasmusKey( selectorDlg.key() );
04623 assert( !GlobalSettings::chiasmusKey().isEmpty() );
04624 mEncryptWithChiasmus = true;
04625 resetter.disable();
04626 }
04627
04628
04629