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