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