Package: kmail Version: 4:3.1.5-1 Severity: wishlist Tags: patch Hi,
I realy wish to have kvim as my editor in kmail. As far as I know it's planed vor 3.2 to have the choice to select the "Embedded Vim Component" inside kmail as your editor. But as I see ther's a little patch at http://freenux.org/kde/patchs/kmail-ktexteditor-3.1.diff which applyes this feature to kmail 3.1. I would realy like to see it in the next Debian Package ... ;-) Thank you in advance, Markus Hubig
diff -urN kmail-3.1/Makefile.am kmail+kvim/Makefile.am --- kmail-3.1/Makefile.am 2002-11-13 09:47:31.000000000 -0500 +++ kmail+kvim/Makefile.am 2003-01-04 18:03:04.000000000 -0500 @@ -2,7 +2,7 @@ SUBDIRS = . about pics profiles INCLUDES = -I$(top_srcdir)/libkdenetwork -I$(top_srcdir)/mimelib $(all_includes) -LDADD = $(LIB_KHTML) $(LIB_KSPELL) ../libkdenetwork/libkdenetwork.la ../mimelib/libmimelib.la -lkabc +LDADD = $(LIB_KHTML) $(LIB_KSPELL) ../libkdenetwork/libkdenetwork.la ../mimelib/libmimelib.la -lkabc -lktexteditor -lkutils bin_PROGRAMS = kmail diff -urN kmail-3.1/configuredialog.cpp kmail+kvim/configuredialog.cpp --- kmail-3.1/configuredialog.cpp 2002-12-07 04:56:17.000000000 -0500 +++ kmail+kvim/configuredialog.cpp 2003-01-04 18:00:08.000000000 -0500 @@ -97,6 +97,7 @@ #include <qlayout.h> #include <qtextcodec.h> #include <qheader.h> +#include <ktexteditor/editorchooser.h> #include <qlineedit.h> #include <qpopupmenu.h> #include <qcheckbox.h> @@ -2342,7 +2343,7 @@ // tmp. vars: QVBoxLayout *vlay; QHBoxLayout *hlay; - QGroupBox *group; + QGroupBox *group, *editor; QLabel *label; QHBox *hbox; @@ -2370,6 +2371,12 @@ connect( mWordWrapCheck, SIGNAL(toggled(bool)), mWrapColumnSpin, SLOT(setEnabled(bool)) ); + //ktexteditor stuff + editor = new QVGroupBox (i18n("Embedded Editor"), this); + editor->layout()->setSpacing( KDialog::spacingHint() ); + chooser = new KTextEditor::EditorChooser(editor, "Editor chooser"); + chooser->readAppSetting(); + // The "exteral editor" group: group = new QVGroupBox( i18n("External Editor"), this ); group->layout()->setSpacing( KDialog::spacingHint() ); @@ -2399,6 +2406,7 @@ connect( mExternalEditorCheck, SIGNAL(toggled(bool)), label, SLOT(setEnabled(bool)) ); + vlay->addWidget( editor ); vlay->addWidget( group ); vlay->addStretch( 100 ); } @@ -2445,6 +2453,9 @@ KConfigGroup general( kapp->config(), "General" ); KConfigGroup composer( kapp->config(), "Composer" ); + //ktexteditor + chooser->writeAppSetting(); + general.writeEntry( "use-external-editor", mExternalEditorCheck->isChecked() ); general.writeEntry( "external-editor", mEditorRequester->url() ); diff -urN kmail-3.1/configuredialog_p.h kmail+kvim/configuredialog_p.h --- kmail-3.1/configuredialog_p.h 2002-09-29 08:27:00.000000000 -0400 +++ kmail+kvim/configuredialog_p.h 2003-01-04 18:00:08.000000000 -0500 @@ -15,6 +15,7 @@ #include <kdialogbase.h> #include <klistview.h> +#include <ktexteditor/editorchooser.h> class QPushButton; class QLabel; @@ -557,6 +558,7 @@ void installProfile( KConfig * profile ); protected: + KTextEditor::EditorChooser *chooser; QCheckBox *mAutoAppSignFileCheck; QCheckBox *mSmartQuoteCheck; QCheckBox *mWordWrapCheck; diff -urN kmail-3.1/kmcomposewin.cpp kmail+kvim/kmcomposewin.cpp --- kmail-3.1/kmcomposewin.cpp 2002-12-14 14:49:22.000000000 -0500 +++ kmail+kvim/kmcomposewin.cpp 2003-01-04 19:26:48.000000000 -0500 @@ -82,9 +82,20 @@ #include "cryptplugwrapperlist.h" #include "klistboxdialog.h" -#include "kmcomposewin.moc" - +#include <ktexteditor/editor.h> +#include <ktexteditor/document.h> +#include <ktexteditor/view.h> +#include <ktexteditor/editinterface.h> +#include <ktexteditor/editorchooser.h> +#include <ktexteditor/viewcursorinterface.h> +#include <ktexteditor/searchinterface.h> +#include <klibloader.h> +#include <ktrader.h> +#include <kservice.h> +#include <kfinddialog.h> +#include <qregexp.h> +#include "kmcomposewin.moc" //----------------------------------------------------------------------------- KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) @@ -139,7 +150,6 @@ bAutoCharset = TRUE; fixedFontAction = 0; mEditor = new KMEdit(mMainWidget, this); - mEditor->setTextFormat(Qt::PlainText); disableBreaking = false; QString tip = i18n("Select email address(es)"); QToolTip::add( mBtnTo, tip ); @@ -221,8 +231,8 @@ connect(kernel->imapFolderMgr(),SIGNAL(removed(KMFolder*)), SLOT(slotFolderRemoved(KMFolder*))); - connect (mEditor, SIGNAL (spellcheck_done(int)), - this, SLOT (slotSpellcheckDone (int))); +//XXX connect (mEditor, SIGNAL (spellcheck_done(int)), +//XXX this, SLOT (slotSpellcheckDone (int))); mMainWidget->resize(480,510); setCentralWidget(mMainWidget); @@ -385,7 +395,7 @@ mEdtReplyTo->setPalette(mPalette); mEdtBcc->setPalette(mPalette); mTransport->setPalette(mPalette); - mEditor->setPalette(mPalette); +//XXX mEditor->setPalette(mPalette); mFcc->setPalette(mPalette); } @@ -1038,7 +1048,7 @@ //----------------------------------------------------------------------------- void KMComposeWin::updateCursorPosition() { - int col,line; + int col=0,line=0; QString temp; line = mEditor->currentLine(); col = mEditor->currentColumn(); @@ -1055,17 +1065,17 @@ //QPopupMenu* menu; mEditor->setModified(FALSE); QFontMetrics fm(mBodyFont); - mEditor->setTabStopWidth(fm.width(QChar(' ')) * 8); +//XXX mEditor->setTabStopWidth(fm.width(QChar(' ')) * 8); //mEditor->setFocusPolicy(QWidget::ClickFocus); if (mWordWrap) { - mEditor->setWordWrap( QMultiLineEdit::FixedColumnWidth ); - mEditor->setWrapColumnOrWidth(mLineBreak); +//XXX mEditor->setWordWrap( QMultiLineEdit::FixedColumnWidth ); +//XXX mEditor->setWrapColumnOrWidth(mLineBreak); } else { - mEditor->setWordWrap( QMultiLineEdit::NoWrap ); +//XXX mEditor->setWordWrap( QMultiLineEdit::NoWrap ); } // Font setup @@ -1093,7 +1103,7 @@ mEditor->installRBPopup(menu); */ updateCursorPosition(); - connect(mEditor,SIGNAL(CursorPositionChanged()),SLOT(updateCursorPosition())); +//XXX connect(mEditor,SIGNAL(CursorPositionChanged()),SLOT(updateCursorPosition())); } @@ -1103,7 +1113,8 @@ int maxLineLength = 0; int curPos; int oldPos = 0; - if (mEditor->QMultiLineEdit::wordWrap() == QMultiLineEdit::FixedColumnWidth) { +/*XXX function unused, no matter + if (mEditor->QMultiLineEdit::wordWrap() == QMultiLineEdit::FixedColumnWidth) { for (curPos = 0; curPos < (int)body.length(); ++curPos) if (body[curPos] == '\n') { if ((curPos - oldPos) > maxLineLength) @@ -1114,7 +1125,7 @@ maxLineLength = curPos - oldPos; if (mEditor->wrapColumnOrWidth() < maxLineLength) // column mEditor->setWrapColumnOrWidth(maxLineLength); - } + }*/ } //----------------------------------------------------------------------------- @@ -1268,13 +1279,12 @@ // are opened for editting in the composer (cf. Bug#41102) I comment it // out. Ingo, 2002-04-21 //verifyWordWrapLengthIsAdequate(bodyDecoded); - + QTextCodec *codec = KMMsgBase::codecForName(mCharset); if (codec) - mEditor->setText(codec->toUnicode(bodyDecoded)); + mEditor->setText(codec->toUnicode(bodyDecoded)+"\n"); else - mEditor->setText(QString::fromLocal8Bit(bodyDecoded)); - mEditor->insertLine("\n", -1); + mEditor->setText(QString::fromLocal8Bit(bodyDecoded)+"\n"); } else mEditor->setText(""); for(i=firstAttachment; i<num; i++) { @@ -1299,10 +1309,12 @@ mEditor->setText(QString::fromLocal8Bit(bodyDecoded)); } + kdDebug() << "setMsg :setCharset " << endl; setCharset(mCharset); if( mAutoSign && mayAutoSign ) { + kdDebug() << "setMsg : autoSign " << endl; // // Espen 2000-05-16 // Delay the signature appending. It may start a fileseletor. @@ -1311,6 +1323,7 @@ // QTimer::singleShot( 0, this, SLOT(slotAppendSignature()) ); } + kdDebug() << "setMsg : setModified " << endl; mEditor->setModified(FALSE); } @@ -2065,6 +2078,7 @@ bool KMComposeWin::queryExit () { + slotClose(); return true; } @@ -2731,7 +2745,8 @@ if (disableBreaking) text = mEditor->text(); else - text = mEditor->brokenText(); +//XXX text = mEditor->brokenText(); + text = mEditor->text(); text.truncate(text.length()); // to ensure text.size()==text.length()+1 @@ -3946,7 +3961,7 @@ } if ((*it).insert) { - int col, line; + uint col, line; mEditor->getCursorPosition(&line, &col); (*it).data.resize((*it).data.size() + 1); (*it).data[(*it).data.size() - 1] = '\0'; @@ -4374,8 +4389,9 @@ //----------------------------------------------------------------------------- void KMComposeWin::slotUpdateFont() { - mEditor->setFont( fixedFontAction && (fixedFontAction->isChecked()) - ? mFixedFont : mBodyFont ); + /*XXX Adding a font interface to KTextEditor would be great ;) + * mEditor->setFont( fixedFontAction && (fixedFontAction->isChecked()) + ? mFixedFont : mBodyFont ); */ } //----------------------------------------------------------------------------- @@ -4461,6 +4477,8 @@ //----------------------------------------------------------------------------- void KMComposeWin::slotClose() { + kdDebug(5006) << "KMComposeWin::slotClose(). " << endl; + if (mEditor) mEditor->closeURL(); close(FALSE); } @@ -4566,7 +4584,7 @@ //----------------------------------------------------------------------------- void KMComposeWin::slotWordWrapToggled(bool on) { - if (on) +/*XXX if (on) { mEditor->setWordWrap( QMultiLineEdit::FixedColumnWidth ); mEditor->setWrapColumnOrWidth(mLineBreak); @@ -4574,7 +4592,7 @@ else { mEditor->setWordWrap( QMultiLineEdit::NoWrap ); - } + }*/ } @@ -4718,7 +4736,8 @@ mAutoDeleteMsg = FALSE; mFolder = 0; - close(); + //close(); + slotClose(); return true; } @@ -4768,6 +4787,7 @@ //---------------------------------------------------------------------------- void KMComposeWin::slotAppendSignature() { + kdDebug() << "setMsg : appendSignature " << endl; bool mod = mEditor->isModified(); const KMIdentity & ident = @@ -4812,10 +4832,10 @@ mOldSigText = sigText; if( !sigText.isEmpty() ) { - mEditor->sync(); - mEditor->append("\n"); - mEditor->append(sigText); - mEditor->update(); +/*XXX mEditor->sync();*/ + mEditor->insertLine("\n",-1); + mEditor->insertLine(sigText,-1); +// mEditor->update(); mEditor->setModified(mod); mEditor->setContentsPos( 0, 0 ); } @@ -4831,7 +4851,7 @@ //----------------------------------------------------------------------------- void KMComposeWin::slotCleanSpace() { - mEditor->cleanWhiteSpace(); + //XXX mEditor->cleanWhiteSpace(); } @@ -4846,7 +4866,7 @@ this, SLOT (spell_progress (unsigned))); */ - mEditor->spellcheck(); +//XXX mEditor->spellcheck(); } @@ -5066,7 +5086,7 @@ { mEditor->setFocus(); if ( hasMessage ) - mEditor->setCursorPosition( 1, 0 ); + mEditor->setContentsPos( 1, 0 ); } void KMComposeWin::slotCompletionModeChanged( KGlobalSettings::Completion mode) @@ -5315,7 +5335,6 @@ return TRUE; } // ---sven's Return is same Tab and arrow key navigation end --- - } return KMLineEditInherited::eventFilter(o, e); } @@ -5592,6 +5611,7 @@ } +#if 0 //============================================================================= // // Class KMEdit @@ -5757,6 +5777,167 @@ proc = 0; delete mTempFile; mTempFile = 0; +#else + //============================================================================= + // + // Class KMEdit + // updated to KTextEditor by Mickael Marchand (Mikmak) <[EMAIL PROTECTED]> + // + //============================================================================= + KMEdit::KMEdit(QWidget *parent, KMComposeWin* composer, + const char *name): + QVBox(parent, name) + { + mComposer = composer; + extEditor = false; // the default is to use ourself + mKSpell = NULL; + mSpellingFilter = 0; + mTempFile = NULL; + mExtEditorProcess = NULL; + + editor=KTextEditor::EditorChooser::createDocument(this,"KTextEditor::Document"); + if (editor) editorView = editor->createView(this, "KTextEditor part"); + } + + //----------------------------------------------------------------------------- + KMEdit::~KMEdit() + { + kdDebug(5006) << "KMEdit::~KMEdit. " << endl; + if (mKSpell) delete mKSpell; + if (editor) { + editor->closeURL(); + delete editor; + } + } + + void KMEdit::closeURL() { + kdDebug(5006) << "KMEdit::closeURL(). " << endl; + editor->closeURL(); + } + + void KMEdit::setModified(bool rw) { + editor->setModified(rw); + } + + bool KMEdit::isModified() { + return editor->isModified(); + } + + QString KMEdit::text() { + KTextEditor::EditInterface *editiface = dynamic_cast<KTextEditor::EditInterface*>(editor); + QString text = editiface->text(); + kdDebug() << "got text : " << text << endl; + return text; + } + + void KMEdit::setText(QString text) { + kdDebug() << "kmail->setText "<< endl; + QString text2(text); + text2.setLength(text2.length()); + KTextEditor::EditInterface *editiface = dynamic_cast<KTextEditor::EditInterface*>(editor); + editiface->setText(text2); + kdDebug() << "kmail->setText success" << endl; + } + + int KMEdit::currentLine() { + KTextEditor::ViewCursorInterface *cursoriface = dynamic_cast<KTextEditor::ViewCursorInterface*>(editorView); + int line = cursoriface->cursorLine(); + kdDebug() << "current line : " << line << endl; + return line; + } + + int KMEdit::currentColumn() { + KTextEditor::ViewCursorInterface *cursoriface = dynamic_cast<KTextEditor::ViewCursorInterface*>(editorView); + int col = cursoriface->cursorColumn(); + kdDebug() << "current col : " << col << endl; + return col; + } + + void KMEdit::insertLine(QString text, int position) { + kdDebug(5006) << "KMEdit::insertLine(). " << position << endl; + KTextEditor::EditInterface *editiface = dynamic_cast<KTextEditor::EditInterface*>(editor); + editiface->insertLine(position,text); + } + + void KMEdit::getCursorPosition(uint *line, uint *column) { + KTextEditor::ViewCursorInterface *cursoriface = dynamic_cast<KTextEditor::ViewCursorInterface*>(editorView); + cursoriface->cursorPosition(line,column); + } + + void KMEdit::insertAt(QString text, int line, int column) { + kdDebug(5006) << "KMEdit::insertAt(). " << line << " " << column << endl; + KTextEditor::EditInterface *editiface = dynamic_cast<KTextEditor::EditInterface*>(editor); + editiface->insertText(line,column,text); + } + + void KMEdit::search() { + KTextEditor::SearchInterface *searchiface = dynamic_cast<KTextEditor::SearchInterface*>(editor); + if (searchiface==NULL) return; // no search support for this part + + //create the dialog + KFindDialog find (this, 0, KFindDialog::FromCursor | KFindDialog::CaseSensitive | KFindDialog::FindBackwards | KFindDialog::RegularExpression, QStringList(), false); + if (find.exec() != QDialog::Accepted) + return; + + //do the search + unsigned int *line; + unsigned int *column; + unsigned int *len; + unsigned int startLine=0; + unsigned int startColumn=0; + + bool stop=false; + long options = find.options(); + bool fromcursor=options & KFindDialog::FromCursor; + bool casesensitive=options & KFindDialog::CaseSensitive; + bool findbackwards=options & KFindDialog::FindBackwards; + bool regexp=options & KFindDialog::RegularExpression; + + if (fromcursor) { + unsigned int *l, *c; + getCursorPosition(l,c); + startLine = *l; + startColumn = *c; + } + + while (!stop) { + if (regexp) + stop = ! searchiface->searchText(startLine, startColumn, QRegExp(find.pattern(), casesensitive), line, column, len, findbackwards ); + else + stop = ! searchiface->searchText(startLine, startColumn, find.pattern(), line , column, len, casesensitive, findbackwards); + + startLine = *line; + startColumn = *column; + } + } + + void KMEdit::replace() { + //TODO + } + + void KMEdit::setContentsPos(int line, int column) { + KTextEditor::ViewCursorInterface *cursoriface = dynamic_cast<KTextEditor::ViewCursorInterface*>(editorView); + cursoriface->setCursorPosition(line,column); + } + + //----------------------------------------------------------------------------- + void KMEdit::slotExternalEditorDone(KProcess* proc) + { + assert(proc == mExtEditorProcess); + /*XXX setAutoUpdate(false);*/ + KTextEditor::EditInterface *editiface = dynamic_cast<KTextEditor::EditInterface*>(editor); + editiface->clear(); + + // read data back in from file + editiface->insertLine(-1, QString::fromLocal8Bit(kFileToString(mTempFile->name(), + TRUE, FALSE))); + + /*XXX setAutoUpdate(true);*/ + /* repaint();*/ + delete proc; + delete mTempFile; + mTempFile = NULL; +#endif mExtEditorProcess = 0; } @@ -5782,7 +5963,7 @@ //----------------------------------------------------------------------------- void KMEdit::slotSpellcheck2(KSpell*) { - spellcheck_start(); +//XXX spellcheck_start(); QString quotePrefix; if(mComposer && mComposer->msg()) @@ -5799,22 +5980,22 @@ } kdDebug(5006) << "spelling: new SpellingFilter with prefix=\"" << quotePrefix << "\"" << endl; - mSpellingFilter = new SpellingFilter(text(), quotePrefix, SpellingFilter::FilterUrls, + /*XXX mSpellingFilter = new SpellingFilter(text(), quotePrefix, SpellingFilter::FilterUrls, SpellingFilter::FilterEmailAddresses); - mKSpell->check(mSpellingFilter->filteredText()); + mKSpell->check(mSpellingFilter->filteredText());*/ } //----------------------------------------------------------------------------- void KMEdit::slotSpellResult(const QString &) { - spellcheck_stop(); +//XXX spellcheck_stop(); int dlgResult = mKSpell->dlgResult(); if ( dlgResult == KS_CANCEL ) { kdDebug(5006) << "spelling: canceled - restoring text from SpellingFilter" << endl; - setText(mSpellingFilter->originalText()); +//XXX setText(mSpellingFilter->originalText()); setModified(mWasModifiedBeforeSpellCheck); } @@ -5840,8 +6021,8 @@ } else if (status == KSpell::Crashed) { - spellcheck_stop(); +//XXX spellcheck_stop(); KMessageBox::sorry(this, i18n("ISpell/Aspell seems to have crashed.")); - emit spellcheck_done( KS_CANCEL ); +//XXX emit spellcheck_done( KS_CANCEL ); } } diff -urN kmail-3.1/kmcomposewin.h kmail+kvim/kmcomposewin.h --- kmail-3.1/kmcomposewin.h 2002-12-06 16:30:13.000000000 -0500 +++ kmail+kvim/kmcomposewin.h 2003-01-04 18:05:57.000000000 -0500 @@ -29,6 +29,11 @@ #include "cryptplugwrapper.h" +#include <ktexteditor/document.h> +#include <ktexteditor/view.h> +#include <qvbox.h> +class QVBox; + class _StringPair { public: QString name; @@ -65,10 +70,10 @@ typedef QPtrList<KMMessagePart> KMMsgPartList; - //----------------------------------------------------------------------------- #define KMEditInherited KEdit -class KMEdit: public KEdit + +class KMEdit: public QVBox { Q_OBJECT public: @@ -92,6 +97,29 @@ inline void setExternalEditor(bool extEd) { extEditor=extEd; } inline void setExternalEditorPath(QString path) { mExtEditor=path; } + void setModified(bool); + bool isModified(); + + void closeURL(); + QString text(); + + void setText(QString text); + + int currentLine(); + + int currentColumn(); + + void insertLine(QString text, int position); + + void getCursorPosition(uint *line, uint *column); + + void insertAt(QString text, int line, int column); + + void search(); + + void replace(); + void setContentsPos(int,int); + signals: void spellcheck_done(int result); public slots: @@ -104,7 +132,7 @@ /** * Event filter that does Tab-key handling. */ - virtual bool eventFilter(QObject*, QEvent*); +// virtual bool eventFilter(QObject*, QEvent*); KMComposeWin* mComposer; private: @@ -114,6 +142,8 @@ KProcess *mExtEditorProcess; bool extEditor; QString mExtEditor; + KTextEditor::Document *editor; + KTextEditor::View *editorView; bool mWasModifiedBeforeSpellCheck; };