From 659c03fca1fc21a2272795021b2ffee1c5b0489b Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Sun, 26 Oct 2003 11:56:13 +0000 Subject: [PATCH] - Make it possible to easily change the dictionary which is used for as-you-type spell-checking. This also makes it possible to use different dictionaries in different composer windows. - Add identity-dependant spell-checking dictionary. Note that you need an up-to-date kdelibs/kdeui in order to compile this. svn path=/trunk/kdepim/; revision=262136 --- Makefile.am | 2 +- identitydialog.cpp | 12 ++++++++++- identitydialog.h | 4 +++- kmcomposerui.rc | 3 ++- kmcomposewin.cpp | 53 +++++++++++++++++++++++++++++++++++----------- kmcomposewin.h | 9 ++++++-- kmglobal.h | 3 ++- kmidentity.cpp | 21 ++++++++++++++---- kmidentity.h | 8 ++++++- 9 files changed, 91 insertions(+), 24 deletions(-) diff --git a/Makefile.am b/Makefile.am index 281c69250..2787080ec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,7 +82,7 @@ libkmailprivate_la_SOURCES = kmmessage.cpp kmmainwin.cpp configuredialog.cpp \ folderIface.cpp folderIface.skel mailserviceimpl.cpp \ attachmentlistview.cpp ssllabel.cpp \ iobserver.cpp isubject.cpp bodyvisitor.cpp \ - urlhandlermanager.cpp + urlhandlermanager.cpp dictionarycombobox.cpp kmail_SOURCES = main.cpp diff --git a/identitydialog.cpp b/identitydialog.cpp index 173e94c2f..b9823c994 100644 --- a/identitydialog.cpp +++ b/identitydialog.cpp @@ -1,4 +1,4 @@ -/* -*- c-basic-offset: 2 -*- +/* -*- mode: C++; c-file-style: "gnu" -*- identitydialog.cpp This file is part of KMail, the KDE mail client. @@ -37,6 +37,7 @@ #include "kmfoldermgr.h" #include "transportmanager.h" #include "kmkernel.h" +#include "dictionarycombobox.h" // other kdenetwork headers: @@ -194,6 +195,13 @@ namespace KMail { glay->addWidget( label, row, 0 ); glay->addWidget( mPgpKeyRequester, row, 1 ); + // "Dictionary" combo box and label: + ++row; + mDictionaryCombo = new DictionaryComboBox( tab ); + glay->addWidget( mDictionaryCombo, row, 1 ); + glay->addWidget( new QLabel( mDictionaryCombo, i18n("D&ictionary:"), tab ), + row, 0 ); + // "Sent-mail Folder" combo box and label: ++row; mFccCombo = new KMFolderComboBox( tab ); @@ -269,6 +277,7 @@ namespace KMail { mTransportCheck->setChecked( !ident.transport().isEmpty() ); mTransportCombo->setEditText( ident.transport() ); mTransportCombo->setEnabled( !ident.transport().isEmpty() ); + mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); if ( ident.fcc().isEmpty() || !checkFolderExists( ident.fcc(), @@ -324,6 +333,7 @@ namespace KMail { ident.setBcc( mBccEdit->text() ); ident.setTransport( ( mTransportCheck->isChecked() ) ? mTransportCombo->currentText() : QString::null ); + ident.setDictionary( mDictionaryCombo->currentDictionary() ); ident.setFcc( mFccCombo->getFolder() ? mFccCombo->getFolder()->idString() : QString::null ); ident.setDrafts( mDraftsCombo->getFolder() ? diff --git a/identitydialog.h b/identitydialog.h index 13270b0b5..e25dd7e6a 100644 --- a/identitydialog.h +++ b/identitydialog.h @@ -1,4 +1,4 @@ -/* -*- c++ -*- +/* -*- mode: C++; c-file-style: "gnu" -*- identitydialog.h This file is part of KMail, the KDE mail client. @@ -46,6 +46,7 @@ namespace Kpgp { } namespace KMail { class SignatureConfigurator; + class DictionaryComboBox; } namespace KMail { @@ -75,6 +76,7 @@ namespace KMail { QLineEdit *mReplyToEdit; QLineEdit *mBccEdit; Kpgp::SecretKeyRequester *mPgpKeyRequester; + KMail::DictionaryComboBox *mDictionaryCombo; KMFolderComboBox *mFccCombo; KMFolderComboBox *mDraftsCombo; QCheckBox *mTransportCheck; diff --git a/kmcomposerui.rc b/kmcomposerui.rc index fab50ccd0..7345c2ecb 100644 --- a/kmcomposerui.rc +++ b/kmcomposerui.rc @@ -1,4 +1,4 @@ - + &Message @@ -41,6 +41,7 @@ + diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index a249827cd..debb97d7e 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -35,6 +35,8 @@ #include "kmkernel.h" #include "attachmentlistview.h" using KMail::AttachmentListView; +#include "dictionarycombobox.h" +using KMail::DictionaryComboBox; #include "addressesdialog.h" using KPIM::AddressesDialog; #include @@ -96,6 +98,7 @@ using KRecentAddress::RecentAddresses; //----------------------------------------------------------------------------- KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) : MailComposerIface(), KMTopLevelWidget("kmail-composer#"), + mMsg( 0 ), mAutoRequestMDN( false ), mId( id ), mNeverSign( false ), mNeverEncrypt( false ) { @@ -108,6 +111,7 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) mSelectedCryptPlug = kmkernel->cryptPlugList() ? kmkernel->cryptPlugList()->active() : 0; mIdentity = new IdentityCombo(mMainWidget); + mDictionaryCombo = new DictionaryComboBox( mMainWidget ); mFcc = new KMFolderComboBox(mMainWidget); mFcc->showOutboxFolder( FALSE ); mTransport = new QComboBox(true, mMainWidget); @@ -118,6 +122,7 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) mEdtBcc = new KMLineEdit(this,true,mMainWidget); mEdtSubject = new KMLineEditSpell(this,false,mMainWidget, "subjectLine"); mLblIdentity = new QLabel(mMainWidget); + mDictionaryLabel = new QLabel( mMainWidget ); mLblFcc = new QLabel(mMainWidget); mLblTransport = new QLabel(mMainWidget); mLblFrom = new QLabel(mMainWidget); @@ -147,9 +152,10 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) mFolder = 0; mAutoCharset = TRUE; mFixedFontAction = 0; - mEditor = new KMEdit(mMainWidget, this); + mEditor = new KMEdit( mMainWidget, this, mDictionaryCombo->spellConfig() ); mEditor->setTextFormat(Qt::PlainText); mEditor->setAcceptDrops( true ); + mDisableBreaking = false; QString tip = i18n("Select email address(es)"); QToolTip::add( mBtnTo, tip ); @@ -505,6 +511,12 @@ void KMComposeWin::readConfig(void) mIdentity->setCurrentIdentity( mId ); + kdDebug(5006) << "KMComposeWin::readConfig. " << mIdentity->currentIdentityName() << endl; + const KMIdentity & ident = + kmkernel->identityManager()->identityForUoid( mIdentity->currentIdentity() ); + + mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); + mTransport->clear(); mTransport->insertStringList( KMTransportInfo::availableTransports() ); while (mTransportHistory.count() > (uint)maxTransportItems) @@ -520,9 +532,6 @@ void KMComposeWin::readConfig(void) if ( !mBtnFcc->isChecked() ) { - kdDebug(5006) << "KMComposeWin::readConfig. " << mIdentity->currentIdentityName() << endl; - const KMIdentity & ident = - kmkernel->identityManager()->identityForUoid( mIdentity->currentIdentity() ); kdDebug(5006) << "KMComposeWin::readConfig: identity.fcc()='" << ident.fcc() << "'" << endl; if ( ident.fcc().isEmpty() ) @@ -644,6 +653,8 @@ void KMComposeWin::slotView(void) id = HDR_SUBJECT; else if (act == mFccAction) id = HDR_FCC; + else if ( act == mDictionaryAction ) + id = HDR_DICTIONARY; else { id = 0; @@ -701,8 +712,11 @@ void KMComposeWin::rethinkFields(bool fromSlot) if (!fromSlot) mIdentityAction->setChecked(abs(mShowHeaders)&HDR_IDENTITY); rethinkHeaderLine(showHeaders,HDR_IDENTITY, row, i18n("&Identity:"), mLblIdentity, mIdentity, mBtnIdentity); + if (!fromSlot) mDictionaryAction->setChecked(abs(mShowHeaders)&HDR_DICTIONARY); + rethinkHeaderLine(showHeaders,HDR_DICTIONARY, row, i18n("&Dictionary:"), + mDictionaryLabel, mDictionaryCombo, 0 ); if (!fromSlot) mFccAction->setChecked(abs(mShowHeaders)&HDR_FCC); - rethinkHeaderLine(showHeaders,HDR_FCC, row, i18n("Sent-Mail fol&der:"), + rethinkHeaderLine(showHeaders,HDR_FCC, row, i18n("Se&nt-Mail folder:"), mLblFcc, mFcc, mBtnFcc); if (!fromSlot) mTransportAction->setChecked(abs(mShowHeaders)&HDR_TRANSPORT); rethinkHeaderLine(showHeaders,HDR_TRANSPORT, row, i18n("Mai&l transport:"), @@ -741,6 +755,7 @@ void KMComposeWin::rethinkFields(bool fromSlot) slotUpdateAttachActions(); mIdentityAction->setEnabled(!mAllFieldsAction->isChecked()); + mDictionaryAction->setEnabled( !mAllFieldsAction->isChecked() ); mTransportAction->setEnabled(!mAllFieldsAction->isChecked()); mFromAction->setEnabled(!mAllFieldsAction->isChecked()); mReplyToAction->setEnabled(!mAllFieldsAction->isChecked()); @@ -809,16 +824,19 @@ void KMComposeWin::rethinkHeaderLine(int aValue, int aMask, int& aRow, aCbx->setMinimumSize(100, aLbl->height()+2); mGrid->addWidget(aCbx, aRow, 1); - mGrid->addWidget(aChk, aRow, 2); - aChk->setFixedSize(aChk->sizeHint().width(), aLbl->height()); - aChk->show(); + if ( aChk ) { + mGrid->addWidget(aChk, aRow, 2); + aChk->setFixedSize(aChk->sizeHint().width(), aLbl->height()); + aChk->show(); + } aRow++; } else { aLbl->hide(); aCbx->hide(); - aChk->hide(); + if ( aChk ) + aChk->hide(); } } @@ -937,6 +955,9 @@ void KMComposeWin::setupActions(void) mIdentityAction = new KToggleAction (i18n("&Identity"), 0, this, SLOT(slotView()), actionCollection(), "show_identity"); + mDictionaryAction = new KToggleAction (i18n("&Dictionary"), 0, this, + SLOT(slotView()), + actionCollection(), "show_dictionary"); mFccAction = new KToggleAction (i18n("Sent-Mail F&older"), 0, this, SLOT(slotView()), actionCollection(), "show_fcc"); @@ -1314,6 +1335,8 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign, setFcc(ident.fcc()); } + mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); + num = mMsg->numBodyParts(); if (num > 0) @@ -5034,6 +5057,7 @@ void KMComposeWin::slotSpellcheckDoneClearStatus() statusBar()->changeItem("", 0); } + //----------------------------------------------------------------------------- void KMComposeWin::focusNextPrevEdit(const QWidget* aCur, bool aNext) { @@ -5103,6 +5127,8 @@ void KMComposeWin::slotIdentityChanged(uint uoid) } } + mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); + if ( !mBtnFcc->isChecked() ) { if ( ident.fcc().isEmpty() ) @@ -5644,6 +5670,7 @@ void KMLineEditSpell::spellCheckerCorrected( const QString &old, const QString & // //============================================================================= KMEdit::KMEdit(QWidget *parent, KMComposeWin* composer, + KSpellConfig* autoSpellConfig, const char *name) : KEdit( parent, name ), mComposer( composer ), @@ -5660,11 +5687,11 @@ KMEdit::KMEdit(QWidget *parent, KMComposeWin* composer, installEventFilter(this); KCursor::setAutoHideCursor( this, true, true ); - initializeAutoSpellChecking(); + initializeAutoSpellChecking( autoSpellConfig ); } //----------------------------------------------------------------------------- -void KMEdit::initializeAutoSpellChecking() +void KMEdit::initializeAutoSpellChecking( KSpellConfig* autoSpellConfig ) { KConfigGroup readerConfig( KMKernel::config(), "Reader" ); QColor defaultColor1( 0x00, 0x80, 0x00 ); // defaults from kmreaderwin.cpp @@ -5682,7 +5709,8 @@ void KMEdit::initializeAutoSpellChecking() /*autoEnabled*/ false, /*spellColor*/ misspelled, /*colorQuoting*/ true, - col1, col2, col3, col4 ); + col1, col2, col3, col4, + autoSpellConfig ); connect( mSpellChecker, SIGNAL(activeChanged(const QString &)), mComposer, SLOT(slotStatusMessage(const QString &))); connect( mSpellChecker, SIGNAL(newSuggestions(const QString&, const QStringList&, unsigned int)), @@ -5877,6 +5905,7 @@ void KMEdit::slotAutoSpellCheckingToggled( bool on ) mSpellChecker->setActive( on ); } + //----------------------------------------------------------------------------- void KMEdit::slotExternalEditorTempFileChanged( const QString & fileName ) { if ( !mExtEditorTempFile ) diff --git a/kmcomposewin.h b/kmcomposewin.h index 5bf9d9fd6..53bbc09fa 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -70,7 +70,8 @@ class SpellingFilter; class CryptPlugWrapperList; namespace KMail { -class AttachmentListView; + class AttachmentListView; + class DictionaryComboBox; } typedef QPtrList KMMsgPartList; @@ -82,6 +83,7 @@ class KMEdit: public KEdit Q_OBJECT public: KMEdit(QWidget *parent=0,KMComposeWin* composer=0, + KSpellConfig* spellConfig = 0, const char *name=0); virtual ~KMEdit(); @@ -143,7 +145,7 @@ private slots: private: void killExternalEditor(); - void initializeAutoSpellChecking(); + void initializeAutoSpellChecking( KSpellConfig* autoSpellConfig ); private: KSpell *mKSpell; @@ -736,12 +738,14 @@ private: protected: QWidget *mMainWidget; QComboBox *mTransport; + KMail::DictionaryComboBox *mDictionaryCombo; IdentityCombo *mIdentity; KMFolderComboBox *mFcc; KMLineEdit *mEdtFrom, *mEdtReplyTo, *mEdtTo, *mEdtCc, *mEdtBcc; KMLineEditSpell *mEdtSubject; QLabel *mLblIdentity, *mLblTransport, *mLblFcc; QLabel *mLblFrom, *mLblReplyTo, *mLblTo, *mLblCc, *mLblBcc, *mLblSubject; + QLabel *mDictionaryLabel; QCheckBox *mBtnIdentity, *mBtnTransport, *mBtnFcc; QPushButton *mBtnTo, *mBtnCc, *mBtnBcc, *mBtnFrom, *mBtnReplyTo; bool mSpellCheckInProgress; @@ -796,6 +800,7 @@ protected: KToggleAction *mSubjectAction; KToggleAction *mIdentityAction, *mTransportAction, *mFccAction; KToggleAction *mWordWrapAction, *mFixedFontAction, *mAutoSpellCheckingAction; + KToggleAction *mDictionaryAction; KSelectAction *mEncodingAction; KSelectAction *mCryptoModuleAction; diff --git a/kmglobal.h b/kmglobal.h index d96face68..465991790 100644 --- a/kmglobal.h +++ b/kmglobal.h @@ -64,7 +64,8 @@ typedef enum { #define HDR_IDENTITY 0x100 #define HDR_TRANSPORT 0x200 #define HDR_FCC 0x400 -#define HDR_ALL 0x7ff +#define HDR_DICTIONARY 0x800 +#define HDR_ALL 0xfff #define HDR_STANDARD (HDR_SUBJECT|HDR_TO|HDR_CC) diff --git a/kmidentity.cpp b/kmidentity.cpp index 4d72ff4e2..d4e8e7067 100644 --- a/kmidentity.cpp +++ b/kmidentity.cpp @@ -1,3 +1,4 @@ +// -*- mode: C++; c-file-style: "gnu" -*- // kmidentity.cpp #include "kmidentity.h" @@ -225,7 +226,8 @@ bool KMIdentity::isNull() const { mOrganization.isNull() && mReplyToAddr.isNull() && mBcc.isNull() && mVCardFile.isNull() && mPgpIdentity.isNull() && mFcc.isNull() && mDrafts.isNull() && - mTransport.isNull() && mSignature.type() == Signature::Disabled; + mTransport.isNull() && mDictionary.isNull() && + mSignature.type() == Signature::Disabled; } bool KMIdentity::operator==( const KMIdentity & other ) const { @@ -236,7 +238,7 @@ bool KMIdentity::operator==( const KMIdentity & other ) const { mVCardFile == other.mVCardFile && mPgpIdentity == other.mPgpIdentity && mFcc == other.mFcc && mDrafts == other.mDrafts && mTransport == other.mTransport && - mSignature == other.mSignature; + mDictionary == other.mDictionary && mSignature == other.mSignature; } KMIdentity::KMIdentity( const QString & id, const QString & fullName, @@ -273,6 +275,7 @@ void KMIdentity::readConfig( const KConfigBase * config ) if( mDrafts.isEmpty() ) mDrafts = "drafts"; mTransport = config->readEntry("Transport"); + mDictionary = config->readEntry( "Dictionary" ); mSignature.readConfig( config ); kdDebug(5006) << "KMIdentity::readConfig(): UOID = " << mUoid @@ -295,6 +298,7 @@ void KMIdentity::writeConfig( KConfigBase * config ) const config->writeEntry("Transport", mTransport); config->writeEntry("Fcc", mFcc); config->writeEntry("Drafts", mDrafts); + config->writeEntry( "Dictionary", mDictionary ); mSignature.writeConfig( config ); } @@ -312,7 +316,8 @@ QDataStream & operator<<( QDataStream & stream, const KMIdentity & i ) { << i.transport() << i.fcc() << i.drafts() - << i.mSignature; + << i.mSignature + << i.dictionary(); } QDataStream & operator>>( QDataStream & stream, KMIdentity & i ) { @@ -335,7 +340,8 @@ QDataStream & operator>>( QDataStream & stream, KMIdentity & i ) { >> i.mTransport >> i.mFcc >> i.mDrafts - >> i.mSignature; + >> i.mSignature + >> i.mDictionary; } //----------------------------------------------------------------------------- @@ -458,6 +464,13 @@ void KMIdentity::setDrafts(const QString &str) } +//----------------------------------------------------------------------------- +void KMIdentity::setDictionary( const QString &str ) +{ + mDictionary = str; +} + + //----------------------------------------------------------------------------- QString KMIdentity::signatureText( bool * ok ) const { diff --git a/kmidentity.h b/kmidentity.h index 3a3911a46..4246c2f44 100644 --- a/kmidentity.h +++ b/kmidentity.h @@ -1,4 +1,5 @@ -/* User identity information -*- c++ -*- +/* -*- mode: C++; c-file-style: "gnu" -*- + * User identity information * * Author: Stefan Taferner * This code is under GPL @@ -239,6 +240,10 @@ public: QString drafts() const { return mDrafts; } void setDrafts(const QString&); + /** dictionary which should be used for spell checking */ + QString dictionary() const { return mDictionary; } + void setDictionary( const QString& ); + static KMIdentity null; bool isNull() const; protected: @@ -253,6 +258,7 @@ protected: QString mVCardFile; QCString mPgpIdentity; QString mFcc, mDrafts, mTransport; + QString mDictionary; Signature mSignature; bool mIsDefault; };