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