[prev in list] [next in list] [prev in thread] [next in thread]
List: knode-devel
Subject: [Knode-devel] KDE/kdepim
From: Thomas McGuire <Thomas.McGuire () gmx ! net>
Date: 2007-12-04 19:33:26
Message-ID: 1196796806.186387.14720.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 744882 by tmcguire:
- Make KMeditor ready to insert signatures at start, end and at the cursor (with \
APIDOX)
- Fix cursor positioning when inserting signatures
- Adapt KMail and KNode to these changes
- In KMail, add slots to insert signature at start, end and at the cursor, but don't \
add GUI options for this yet.
Many thanks to Scott <firebrnr@gmail.com>, who ported this to KDE4.
The rest (GUI options etc) will follow later.
CCMAIL: firebrnr@gmail.com
M +33 -13 kmail/kmcomposewin.cpp
M +28 -13 kmail/kmcomposewin.h
M +1 -1 knode/kncomposer.cpp
M +1 -1 libkdepim/CMakeLists.txt
M +41 -16 libkdepim/kmeditor.cpp
M +37 -1 libkdepim/kmeditor.h
--- trunk/KDE/kdepim/kmail/kmcomposewin.cpp #744881:744882
@@ -163,8 +163,7 @@
mEncryptWithChiasmus( false ),
mComposer( 0 ),
mLabelWidth( 0 ),
- mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 ),
- mPreserveUserCursorPosition( false )
+ mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 )
{
(void) new MailcomposerAdaptor( this );
mdbusObjectPath = "/Composer_" + QString::number( ++s_composerNumber );
@@ -1818,11 +1817,11 @@
QTimer::singleShot( 200, this, SLOT(slotAppendSignature()) );
}
- if ( mMsg->getCursorPos() > 0 ) {
- // The message has a cursor position explicitly set, so avoid
- // changing it when appending the signature.
- mPreserveUserCursorPosition = true;
- }
+ // Make sure the cursor is at the correct position, which is set by
+ // the template parser.
+ if ( mMsg->getCursorPos() > 0 )
+ mEditor->setCursorPositionFromStart( mMsg->getCursorPos() );
+
setModified( isModified );
}
@@ -3717,12 +3716,33 @@
//----------------------------------------------------------------------------
void KMComposeWin::slotAppendSignature()
{
- const KPIMIdentities::Identity &ident =
- kmkernel->identityManager()->identityForUoidOrDefault( \
mIdentity->currentIdentity() );
- mOldSigText = ident.signatureText();
- mPreserveUserCursorPosition = mEditor->appendSignature(mOldSigText, \
mPreserveUserCursorPosition); + insertSignatureHelper( KPIM::KMeditor::End );
}
+//----------------------------------------------------------------------------
+void KMComposeWin::slotPrependSignature()
+{
+ insertSignatureHelper( KPIM::KMeditor::Start );
+}
+
+//----------------------------------------------------------------------------
+void KMComposeWin::slotInsertSignatureAtCursor()
+{
+ insertSignatureHelper( KPIM::KMeditor::AtCursor );
+}
+
+//----------------------------------------------------------------------------
+void KMComposeWin::insertSignatureHelper( KPIM::KMeditor::Placement placement )
+{
+ // Identity::signature() is not const, although it should be, therefore the
+ // const_cast.
+ KPIMIdentities::Identity &ident = const_cast<KPIMIdentities::Identity&>(
+ kmkernel->identityManager()->identityForUoidOrDefault(
+ mIdentity->currentIdentity() ) );
+
+ mEditor->insertSignature( ident.signature(), placement );
+}
+
//-----------------------------------------------------------------------------
void KMComposeWin::slotHelp()
{
@@ -4087,9 +4107,9 @@
void KMComposeWin::setReplyFocus( bool hasMessage )
{
+ // The cursor position is already set by setMsg(), so we only need to set the
+ // focus here.
mEditor->setFocus();
- if ( hasMessage )
- mEditor->setCursorPositionFromStart( (unsigned int) mMsg->getCursorPos() );
}
void KMComposeWin::setFocusToSubject()
--- trunk/KDE/kdepim/kmail/kmcomposewin.h #744881:744882
@@ -27,16 +27,24 @@
# endif
#endif*/
+// KMail includes
#include "composer.h"
#include "messagesender.h"
+// Qt includes
#include <QFont>
#include <QList>
#include <QPalette>
#include <QPointer>
#include <QTextListFormat>
+// KDE includes
#include <kglobalsettings.h>
+
+// LIBKDEPIM includes
+#include <libkdepim/kmeditor.h>
+
+// Other includes
#include "kleo/enum.h"
class QByteArray;
@@ -213,9 +221,7 @@
public: // kmcommand
/**
- * Sets the focus to the edit-widget and the cursor below the
- * "On ... you wrote" line when hasMessage is true.
- * Make sure you call this _after_ setMsg().
+ * Sets the focus to the edit-widget.
*/
void setReplyFocus( bool hasMessage = true );
@@ -372,11 +378,21 @@
private slots:
/**
- * Append signature file to the end of the text in the editor.
+ * Append signature to the end of the text in the editor.
*/
void slotAppendSignature();
/**
+ * Prepend signature at the beginning of the text in the editor.
+ */
+ void slotPrependSignature();
+
+ /**
+ * Insert signature at the cursor position of the text in the editor.
+ */
+ void slotInsertSignatureAtCursor();
+
+ /**
* Attach sender's public key.
*/
void slotInsertMyPublicKey();
@@ -641,6 +657,14 @@
*/
static bool validateAddresses( QWidget *parent, const QString &addresses );
+ /**
+ * Helper to insert the signature of the current identity arbitrarily
+ * in the editor, connecting slot functions to KMeditor::insertSignature().
+ * @param placement the position of the signature
+ */
+ void insertSignatureHelper( KPIM::KMeditor::Placement = KPIM::KMeditor::End );
+
+
private slots:
/**
* Compress an attachemnt with the given index
@@ -806,15 +830,6 @@
QMenu *mActNowMenu;
QMenu *mActLaterMenu;
- /** If the message in this composer has a cursor position set (for
- * instance because it comes from a template containing %CURSOR)
- * then we need to preserve that cursor position even when auto-
- * appending (or prepending) the signature during composer setup.
- * Set to true *once* (and only in setMsg() at that) to avoid
- * accidentally moving the cursor.
- */
- bool mPreserveUserCursorPosition;
-
QString mdbusObjectPath;
static int s_composerNumber;
--- trunk/KDE/kdepim/knode/kncomposer.cpp #744881:744882
@@ -1118,7 +1118,7 @@
void KNComposer::slotAppendSig()
{
- v_iew->e_dit->appendSignature(s_ignature);
+ v_iew->e_dit->insertSignature(s_ignature);
}
--- trunk/KDE/kdepim/libkdepim/CMakeLists.txt #744881:744882
@@ -92,7 +92,7 @@
kde4_add_library(kdepim SHARED ${kdepim_LIB_SRCS})
-target_link_libraries(kdepim ${KDE4_KDE3SUPPORT_LIBS} ${QT_QTDESIGNER_LIBRARY} \
${KDE4_KRESOURCES_LIBS} ${KDE4_KABC_LIBS} ${KDE4_KCAL_LIBS} kimproxy \
${KDE4_KPIMUTILS_LIBS} ${KDE4_KLDAP_LIBS}) +target_link_libraries(kdepim \
${KDE4_KDE3SUPPORT_LIBS} ${QT_QTDESIGNER_LIBRARY} ${KDE4_KRESOURCES_LIBS} \
${KDE4_KABC_LIBS} ${KDE4_KCAL_LIBS} kimproxy ${KDE4_KPIMUTILS_LIBS} \
${KDE4_KLDAP_LIBS} ${KDE4_KPIMIDENTITIES_LIBS})
set_target_properties(kdepim PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION \
${GENERIC_LIB_SOVERSION}) install(TARGETS kdepim DESTINATION ${LIB_INSTALL_DIR})
--- trunk/KDE/kdepim/libkdepim/kmeditor.cpp #744881:744882
@@ -25,6 +25,9 @@
#include "kmutils.h"
#include <maillistdrag.h>
+//kdepimlibs includes
+#include <kpimidentities/signature.h>
+
//kdelibs includes
#include <kdebug.h>
#include <kfind.h>
@@ -916,31 +919,53 @@
//TODO
}
-bool KMeditor::appendSignature( const QString &sig, bool preserveUserCursorPos )
+void KMeditor::insertSignature( const KPIMIdentities::Signature &sig,
+ Placement placement, bool addSeparator )
{
- if ( !sig.isEmpty() )
- {
- bool mod = document()->isModified();
+ QString signature;
+ if ( addSeparator )
+ signature = sig.withSeparator();
+ else
+ signature = sig.rawText();
+
+ insertSignature( signature, placement );
+}
+
+void KMeditor::insertSignature( QString signature, Placement placement )
+{
+ if ( !signature.isEmpty() ) {
+
+ // Save the modified state of the document, as inserting a signature
+ // shouldn't change this. Restore it at the end of this function.
+ bool isModified = document()->isModified();
+
+ // Move to the desired position, where the signature should be inserted
QTextCursor cursor = textCursor();
- int position = cursor.position();
- cursor.movePosition( QTextCursor::End );
+ int oldPosition = cursor.position();
+ if ( placement == End )
+ cursor.movePosition( QTextCursor::End );
+ else if ( placement == Start )
+ cursor.movePosition( QTextCursor::Start );
setTextCursor( cursor );
- if ( !preserveUserCursorPos ) position = cursor.position();
- insertPlainText( '\n' + sig );
- cursor.setPosition( position );
+ // Insert the signature and newlines depending on where it was inserted.
+ if ( placement == End )
+ insertPlainText( '\n' + signature );
+ else if ( placement == Start || placement == AtCursor )
+ insertPlainText( '\n' + signature + '\n' );
+
+ // Adjust the cursor position if the signature was inserted before the
+ // cursor
+ if ( placement == Start )
+ oldPosition += signature.length() + 1;
+
+ cursor.setPosition( oldPosition );
setTextCursor( cursor );
ensureCursorVisible();
- document()->setModified( mod );
- // Only keep the cursor from the mMsg *once* based on the
- // preserve-cursor-position setting; this handles the case where
- // the message comes from a template with a specific cursor
- // position set and the signature is appended automatically.
- preserveUserCursorPos = false;
+ document()->setModified( isModified );
}
- return preserveUserCursorPos;
}
#include "kmeditor.moc"
--- trunk/KDE/kdepim/libkdepim/kmeditor.h #744881:744882
@@ -29,6 +29,10 @@
class KFindDialog;
class KUrl;
+namespace KPIMIdentities {
+ class Signature;
+}
+
namespace KPIM {
class KMeditorPrivate;
@@ -40,6 +44,15 @@
public:
/**
+ * Describes the placement of a text which is to be inserted into this
+ * textedit
+ */
+ enum Placement { Start, ///< The text is placed at the start of the textedit
+ End, ///< The text is placed at the end of the textedit
+ AtCursor ///< The text is placed at the current cursor \
position + };
+
+ /**
* Constructs a KMeditor object
*/
explicit KMeditor( const QString& text, QWidget *parent = 0 );
@@ -85,8 +98,31 @@
int linePosition();
int columnNumber();
void setCursorPosition( int linePos, int columnPos );
- bool appendSignature( const QString &sig, bool preserveUserCursorPos = false );
+ /**
+ * Inserts the signature @p sig into the textedit.
+ * The cursor position is preserved.
+ * A leading or trailing newline is also added automatically, depending on
+ * the placement.
+ * @param placement defines where in the textedit the signature should be
+ * inserted.
+ * @param addSeparator if true, the separator '-- \n' will be added in front
+ * of the signature
+ */
+ void insertSignature( const KPIMIdentities::Signature &sig,
+ Placement placement = End, bool addSeparator = true );
+
+ /**
+ * Inserts the signature @p sig into the textedit.
+ * The cursor position is preserved.
+ * A leading or trailing newline is also added automatically, depending on
+ * the placement.
+ * A separator is not added.
+ * @param placement defines where in the textedit the signature should be
+ * inserted.
+ */
+ void insertSignature( QString signature, Placement placement = End );
+
public Q_SLOTS:
void slotAddQuotes();
_______________________________________________
Knode-devel mailing list
Knode-devel@kde.org
https://mail.kde.org/mailman/listinfo/knode-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic