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