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