klipper Patch (2) - was: [Patch:] KClipboard / klipper / kpaint bug fixes

Helge Deller deller at gmx.de
Mon Oct 28 23:12:10 GMT 2002


The second patch - needs the KClipboard patch applied before it.

- uses the new qt3.1 interface of QClipboard 
- uses KClipboard::provides() to decide if it should copy text from selection to the clipboard
- re-integrated debugging messages on  Carsten's request

Helge
-------------- next part --------------
Index: toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/klipper/toplevel.cpp,v
retrieving revision 1.112
diff -u -p -r1.112 toplevel.cpp
--- toplevel.cpp	2002/09/30 12:16:02	1.112
+++ toplevel.cpp	2002/10/28 23:04:25
@@ -128,7 +128,8 @@ QString KlipperWidget::getClipboardConte
 
 void KlipperWidget::setClipboardContents(QString s)
 {
-    setClipboard( s, Clipboard | Selection);
+    setClipboard( s, QClipboard::Selection );
+    setClipboard( s, QClipboard::Clipboard );
     newClipData();
 }
 
@@ -212,8 +213,10 @@ void KlipperWidget::clickedMenu(int id)
             if ( it != m_clipDict.end() && it.data() != QSempty )
             {
                 QString data = it.data();
-                setClipboard( data, Clipboard | Selection );
+    		setClipboard( data, QClipboard::Selection );
+		setClipboard( data, QClipboard::Clipboard );
 
+
 		if (bURLGrabber && bReplayActionInHistory)
 		    myURLGrabber->checkNewData( data );
 
@@ -291,7 +294,8 @@ void KlipperWidget::readProperties(KConf
           m_lastSelection = dataList.first();
           m_lastClipboard = dataList.first();
           m_lastString    = dataList.first();
-          setClipboard( m_lastString, Clipboard | Selection );
+          setClipboard( m_lastString, QClipboard::Selection );
+          setClipboard( m_lastString, QClipboard::Clipboard );
       }
   }
 
@@ -544,25 +548,22 @@ void KlipperWidget::slotClearClipboard()
         m_popup->setItemEnabled(m_selectedItem, false);
 }
 
-QString KlipperWidget::clipboardContents( bool *isSelection )
+QString KlipperWidget::clipboardContents( QClipboard::Mode *mode )
 {
-    clip->setSelectionMode( true );
+    QString contents = clip->text(QClipboard::Selection);
+    if (mode)
+	*mode = QClipboard::Selection;
 
-    QString contents = clip->text();
-
-    if ( contents == m_lastSelection )
+    if ( contents == m_lastSelection && KClipboard::provides("text/") )
     {
-        clip->setSelectionMode( false );
-        QString clipContents = clip->text();
-        if ( clipContents != m_lastClipboard )
+        QString clipContents = clip->text(QClipboard::Clipboard);
+        if ( clipContents != m_lastClipboard ) {
             contents = clipContents;
-        else
-            clip->setSelectionMode( true );
+	    if (mode)
+		*mode = QClipboard::Clipboard;
+	}
     }
 
-    if ( isSelection )
-        *isSelection = clip->selectionModeEnabled();
-
     return contents;
 }
 
@@ -616,53 +617,57 @@ void KlipperWidget::slotMoveSelectedToTo
 // clipboard polling for legacy apps
 void KlipperWidget::newClipData()
 {
-    bool selectionMode;
-    QString clipContents = clipboardContents( &selectionMode );
-//     qDebug("**** newClipData polled: %s", clipContents.latin1());
-    checkClipData( clipContents, selectionMode );
+    QClipboard::Mode mode;
+    QString clipContents = clipboardContents( &mode );
+    // qDebug("**** newClipData polled: %s", clipContents.latin1());
+    checkClipData( clipContents, mode );
 }
 
-void KlipperWidget::clipboardSignalArrived( bool selectionMode )
+void KlipperWidget::clipboardSignalArrived( QClipboard::Mode mode )
 {
-//     qDebug("*** clipboardSignalArrived: %i", selectionMode);
+    // qDebug("*** clipboardSignalArrived: %s",
+    //		(mode==QClipboard::Selection)?"Selection":"Clipboard" );
+    bool check;
 
-    clip->setSelectionMode( selectionMode );
-    QString text = clip->text();
-//     qDebug("-> text is: %s", text.latin1());
-
-    checkClipData( text, selectionMode );
+    if (mode == QClipboard::Selection)
+	check = true;
+    else
+	check = KClipboard::provides("text/");
+    
+    if (check) {
+	QString text = clip->text(mode);
+	// qDebug("-> text is: %s", text.latin1());
+	checkClipData( text, mode );
+    }
     m_checkTimer->start(1000);
 }
 
-void KlipperWidget::checkClipData( const QString& text, bool selectionMode )
+void KlipperWidget::checkClipData( const QString& text, QClipboard::Mode mode )
 {
-   clip->setSelectionMode( selectionMode );
+    QString lastClipRef = (mode == QClipboard::Selection) ? m_lastSelection : m_lastClipboard;
 
     if ( ignoreClipboardChanges() ) // internal to klipper, ignoring QSpinBox selections
     {
         // keep our old clipboard, thanks
-        setClipboard( selectionMode ? m_lastSelection : m_lastClipboard,
-                      selectionMode );
+        setClipboard( lastClipRef, mode );
         return;
     }
 
-
     bool clipEmpty = (clip->data()->format() == 0L);
-//     qDebug("checkClipData(%i): %s, empty: %i (lastClip: %s, lastSel: %s)", selectionMode, text.latin1(), clipEmpty, m_lastClipboard.latin1(), m_lastSelection.latin1() );
 
-//     const char *format;
-//     int i = 0;
-//     while ( (format = clip->data()->format( i++ )) )
-//     {
-//         qDebug( "    format: %s", format);
-//     }
+#if 0
+    qDebug("checkClipData(%i): empty: %i (lastClip: %s, lastSel: %s)",
+	mode, clipEmpty, m_lastClipboard.latin1(), m_lastSelection.latin1() );
+    const char *format;
+    int i = 0;
+    while ( (format = clip->data()->format( i++ )) )
+	qDebug( "    format: %s", format);
+#endif
 
-    QString lastClipRef = selectionMode ? m_lastSelection : m_lastClipboard;
-
     if ( text != lastClipRef ) {
         // keep old clipboard after someone set it to null
         if ( clipEmpty && bNoNullClipboard )
-            setClipboard( lastClipRef, selectionMode );
+            setClipboard( lastClipRef, mode );
         else
             lastClipRef = text;
     }
@@ -671,7 +676,7 @@ void KlipperWidget::checkClipData( const
 
 
     // this must be below the "bNoNullClipboard" handling code!
-    if ( selectionMode && bIgnoreSelection )
+    if ( mode == QClipboard::Selection && bIgnoreSelection )
         return;
 
 
@@ -689,8 +694,8 @@ void KlipperWidget::checkClipData( const
     }
 
     // store old contents:
-    if ( selectionMode )
-        m_lastSelection = lastClipRef;
+    if ( mode == QClipboard::Selection )
+	m_lastSelection = lastClipRef;
     else
         m_lastClipboard = lastClipRef;
 
@@ -698,34 +703,14 @@ void KlipperWidget::checkClipData( const
         applyClipChanges( lastClipRef );
     }
 }
-
-void KlipperWidget::setClipboard( const QString& text, bool selectionMode )
-{
-    setClipboard( text, selectionMode ? Selection : Clipboard );
-}
 
-void KlipperWidget::setClipboard( const QString& text, int mode )
+void KlipperWidget::setClipboard( const QString& text, QClipboard::Mode mode )
 {
     bool blocked = clip->signalsBlocked();
     clip->blockSignals( true ); // ### this might break other kicker applets
-
-    KClipboard *klip = KClipboard::self();
-    bool implicit = klip->implicitSelection();
-    bool synchronize = klip->isSynchronizing();
-    klip->setImplicitSelection( false );
-    klip->setSynchronizing( false );
-
-    if ( mode & Selection ) {
-        clip->setSelectionMode( true );
-        clip->setText( text );
-    }
-    if ( mode & Clipboard ) {
-        clip->setSelectionMode( false );
-        clip->setText( text );
-    }
 
-    klip->setImplicitSelection( implicit );
-    klip->setSynchronizing( synchronize );
+    // KClipboard::setClipboard() does the locking for us.
+    KClipboard::setClipboard( text, mode );
 
     clip->blockSignals( blocked );
 }
Index: toplevel.h
===================================================================
RCS file: /home/kde/kdebase/klipper/toplevel.h,v
retrieving revision 1.39
diff -u -p -r1.39 toplevel.h
--- toplevel.h	2002/09/30 12:16:02	1.39
+++ toplevel.h	2002/10/28 23:04:25
@@ -19,8 +19,8 @@
 #include <qtimer.h>
 #include <qpixmap.h>
 #include <dcopobject.h>
+#include <qclipboard.h>
 
-class QClipboard;
 class KToggleAction;
 class URLGrabber;
 
@@ -56,17 +56,16 @@ protected:
      * @returns the contents of the selection or, if empty, the contents of
      * the clipboard.
      */
-    QString clipboardContents( bool *isSelection = 0L );
+    QString clipboardContents( QClipboard::Mode *mode = 0L );
 
     void removeFromHistory( const QString& text );
     void setEmptyClipboard();
 
-    void clipboardSignalArrived( bool selectionMode );
-    void checkClipData( const QString& text, bool selectionMode );
+    void clipboardSignalArrived( QClipboard::Mode mode );
+    void checkClipData( const QString& text, QClipboard::Mode mode );
     void applyClipChanges( const QString& text );
 
-    void setClipboard( const QString& text, int mode );
-    void setClipboard( const QString& text, bool selectionMode );
+    void setClipboard( const QString& text, QClipboard::Mode mode );
     bool ignoreClipboardChanges() const;
     
     KConfig* config() const { return m_config; }
@@ -89,16 +88,14 @@ private slots:
     void slotMoveSelectedToTop();
 
     void slotSelectionChanged() {
-        clipboardSignalArrived( true );
+        clipboardSignalArrived( QClipboard::Selection );
     }
     void slotClipboardChanged() {
-        clipboardSignalArrived( false );
+        clipboardSignalArrived( QClipboard::Clipboard );
     }
 
 
 private:
-    enum SelectionMode { Clipboard = 1, Selection = 2 };
-
     QClipboard *clip;
 
     QString m_lastString;


More information about the kde-core-devel mailing list