[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    KClipboard/Klipper patch: clipboard->selection syncing
From:       Lubos Lunak <l.lunak () suse ! cz>
Date:       2002-11-01 14:05:57
[Download RAW message or body]

Hello,

 please review the attached patches for kdelibs/kdecore and kdebase/klipper. 
They remove the GUI option for clipboard->selection syncing, the GUI option 
for selection->clipboard syncing stays (off by default). Die-hard KDE2 style 
fans can read the top of kclipboard.cpp and still enable even the 
clipboard->selection syncing, so that Neil won't have his 'bad regression of 
broken behavior' (even though the mail from Magnus shows that this feature 
wasn't in KDE3.0.1+ anyway).

 Please test a bit, a tried to check the separate and selection->clipboard 
variants. It would be bad it it broke more things than it fixes.

i18n:
 This patch doesn't change the strings for the GUI option for syncing, so 
they're slighly misleading at least. I18n folks, is it still ok to change 
them (two strings in kdebase/klipper.po , maybe even only the tooltip one 
would be enough)?

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/

["kclipboard.patch" (text/x-diff)]

--- kclipboard.cpp.sav	Fri Nov  1 12:06:20 2002
+++ kclipboard.cpp	Fri Nov  1 14:37:46 2002
@@ -22,7 +22,22 @@
 
 #include "kclipboard.h"
 
-
+/*
+ * This class provides an automatic synchronization of the X11 Clipboard and Selection
+ * buffers. There are two configuration options in the kdeglobals configuration file,
+ * in the [General] section:
+ * - SynchronizeClipboardAndSelection - whenever the Selection changes, Clipboard is
+ *   set to the same value. This can be also enabled in Klipper.
+ * - ClipboardSetSelection - whenever the Clipboard changes, Selection is set
+ *   to the same value. This setting is only for die-hard fans of the old broken
+ *   KDE1/2 behavior, which can potentionally leads to unexpected problems,
+ *   and this setting therefore can be enabled only in the configuration dialog.
+ *
+ *  Whenever reporting any bug only remotely related to clipboard, first make
+ *  sure you can reproduce it when both these two options are turned off,
+ *  especially the second one. 
+ */
+ 
 class KClipboard::MimeSource : public QMimeSource
 {
 public:
@@ -82,7 +97,7 @@ private:
 
 KClipboard * KClipboard::s_self = 0L;
 bool KClipboard::s_sync = false;
-bool KClipboard::s_implicitSelection = false;
+bool KClipboard::s_selectionSetting = false;
 bool KClipboard::s_blocked = false;
 
 KClipboard * KClipboard::self()
@@ -100,14 +115,10 @@ KClipboard::KClipboard( QObject *parent,
 
     KConfigGroup config( KGlobal::config(), "General" );
     s_sync = config.readBoolEntry( "SynchronizeClipboardAndSelection", s_sync);
-    s_implicitSelection = config.readBoolEntry( "ImplicitlySetSelection",
-                                                s_implicitSelection );
+    s_selectionSetting = config.readBoolEntry( "ClipboardSetSelection",
+                                                s_selectionSetting );
 
-    QClipboard *clip = QApplication::clipboard();
-    connect( clip, SIGNAL( selectionChanged() ),
-             SLOT( slotSelectionChanged() ));
-    connect( clip, SIGNAL( dataChanged() ),
-             SLOT( slotClipboardChanged() ));
+    setupSignals();
 }
 
 KClipboard::~KClipboard()
@@ -116,6 +127,18 @@ KClipboard::~KClipboard()
         s_self = 0L;
 }
 
+void KClipboard::setupSignals()
+{
+    QClipboard *clip = QApplication::clipboard();
+    disconnect( clip, NULL, this, NULL );
+    if( s_sync )
+        connect( clip, SIGNAL( selectionChanged() ),
+                 SLOT( slotSelectionChanged() ));
+    if( s_selectionSetting )
+        connect( clip, SIGNAL( dataChanged() ),
+                 SLOT( slotClipboardChanged() ));
+}
+
 void KClipboard::slotSelectionChanged()
 {
     QClipboard *clip = QApplication::clipboard();
@@ -124,11 +147,8 @@ void KClipboard::slotSelectionChanged()
     if ( s_blocked || !clip->ownsSelection() )
         return;
 
-    if ( s_sync )
-    {
-        setClipboard( new MimeSource( clip->data( QClipboard::Selection) ),
-                      QClipboard::Clipboard );
-    }
+    setClipboard( new MimeSource( clip->data( QClipboard::Selection) ),
+                  QClipboard::Clipboard );
 }
 
 void KClipboard::slotClipboardChanged()
@@ -139,11 +159,8 @@ void KClipboard::slotClipboardChanged()
     if ( s_blocked || !clip->ownsClipboard() )
         return;
 
-    if ( s_implicitSelection || s_sync )
-    {
-        setClipboard( new MimeSource( clip->data( QClipboard::Clipboard ) ),
-                      QClipboard::Selection );
-    }
+    setClipboard( new MimeSource( clip->data( QClipboard::Clipboard ) ),
+                  QClipboard::Selection );
 }
 
 void KClipboard::setClipboard( QMimeSource *data, QClipboard::Mode mode )
@@ -166,11 +183,23 @@ void KClipboard::setClipboard( QMimeSour
     s_blocked = false;
 }
 
+void KClipboard::setSynchronizing( bool sync )
+{
+    s_sync = sync;
+    self()->setupSignals();
+}
+
+void KClipboard::setSelectionSetting( bool enable )
+{
+    s_selectionSetting = enable;
+    self()->setupSignals();
+}
+
 // private, called by KApplication
 void KClipboard::newConfiguration( int config )
 {
     s_sync = (config & Synchronize);
-    s_implicitSelection = (config & ImplicitSelection);
+    self()->setupSignals();
 }
 
 #include "kclipboard.moc"
--- kclipboard.h.sav	Fri Nov  1 12:06:20 2002
+++ kclipboard.h	Fri Nov  1 14:34:02 2002
@@ -25,18 +25,7 @@
 #include <qstrlist.h>
 
 /**
- * This class is mostly of internal use. You probably don't need it :)
- *
- * It provides an automatic synchronization of the X11 Clipboard and Selection
- * buffers. It connects to the selectionChanged() and dataChanged() signals of
- * QClipboard and copies the buffer's contents to the other buffer, if configured.
- *
- * Additionally to keeping them in sync, there is the option to automatically copy
- * the clipboard buffer to the selection buffer, when your application sets the
- * clipboard buffer. That is the default behavior in KDE.
- *
- * If you don't want any synchronizing or implicit copying, you can disable this
- * with the methods below.
+ * This class is only for internal use.
  *
  * @short Allowing to automatically synchronize the X11 Clipboard and Selection buffers.
  * @author Carsten Pfeiffer <pfeiffer@kde.org>
@@ -57,16 +46,13 @@ public:
     static KClipboard *self();
 
     /**
-     * Configures KClipboard to synchronize the Clipboard and Selection buffers
-     * whenever one changes.
+     * Configures KClipboard to synchronize the Selection to Clipboard whenever
+     * it changes.
      *
      * Default is false.
      * @see #isSynchronizing
      */
-    static void setSynchronizing( bool sync )
-    {
-        s_sync = sync;
-    }
+    static void setSynchronizing( bool sync );
 
     /**
      * Checks whether Clipboard and Selection will be synchronized upon changes.
@@ -86,25 +72,23 @@ public:
      *
      * @param enable true to enable implicit selection, false otherwise.
      * Default is true.
-     * @see #implicitSelection
+     * @see #selectionSetting
      */
-    static void setImplicitSelection( bool enable )
-    {
-        s_implicitSelection = enable;
-    }
+    static void setSelectionSetting( bool enable );
 
     /**
      * Checks whether the  Clipboard buffer will be copied to the Selection
      * buffer upon changes.
      * @returns whether the Clipboard buffer will be copied to the Selection
      * buffer upon changes.
-     * @see #setImplicitSelection
+     * @see #setSelectionSetting
      */
-    static bool implicitSelection()
+    static bool selectionSetting()
     {
-        return s_implicitSelection;
+        return s_selectionSetting;
     }
 
+
 protected:
     ~KClipboard();
 
@@ -114,24 +98,23 @@ private slots:
 
 private:
     KClipboard( QObject *parent = 0, const char *name = 0L );
+    void setupSignals();
 
-    // does not restore the old selection mode.
     static void setClipboard( QMimeSource* data, QClipboard::Mode mode );
 
     static KClipboard *s_self;
     static bool s_sync;
-    static bool s_implicitSelection;
+    static bool s_selectionSetting;
     static bool s_blocked;
 
     class MimeSource;
 
 private:
     // needed by klipper
-    enum Configuration { Synchronize = 1, ImplicitSelection = 2 };
+    enum Configuration { Synchronize = 1 };
     // called by KApplication upon kipc message, invoked by klipper
     static void newConfiguration( int config );
 
-
 };
 
 #endif // KCLIPBOARD_H

["klipper.patch" (text/x-diff)]

--- configdialog.cpp.sav	Fri Sep 13 15:10:59 2002
+++ configdialog.cpp	Fri Nov  1 14:10:53 2002
@@ -131,12 +131,6 @@ GeneralWidget::GeneralWidget( QWidget *p
       i18n("Selecting this option synchronizes these two buffers, so they "
            "work the same way as in KDE 1.x and 2.x.") );
 
-    cbImplicitSelection = new QRadioButton(
-        i18n("When the clipboard is set, set the selection as well"), group );
-    QWhatsThis::add( cbImplicitSelection,
-        i18n("Selecting this option will set both clipboard and selection, "
-             "when choosing e.g. \"Copy\" in a menubar.") );
-
     cbSeparate = new QRadioButton(
         i18n("Separate clipboard and selection"), group );
     QWhatsThis::add(
@@ -146,10 +140,7 @@ GeneralWidget::GeneralWidget( QWidget *p
              "in a menubar.") );
 
     cbSynchronize->setChecked( KClipboard::isSynchronizing() );
-    cbImplicitSelection->setChecked( !KClipboard::isSynchronizing() &&
-                                     KClipboard::implicitSelection() );
-    cbSeparate->setChecked( !cbSynchronize->isChecked() &&
-                            !cbImplicitSelection->isChecked() );
+    cbSeparate->setChecked( !cbSynchronize->isChecked() );
 
     popupTimeout = new KIntNumInput( this );
     popupTimeout->setLabel( i18n( "Tim&eout for action popups:" ) );
--- toplevel.cpp.sav	Thu Oct  3 19:47:53 2002
+++ toplevel.cpp	Fri Nov  1 14:43:09 2002
@@ -444,8 +444,6 @@ void KlipperWidget::slotConfigure()
         m_config->setGroup("General");
         m_config->writeEntry("SynchronizeClipboardAndSelection",
                              dlg->synchronize(), true, true );
-        m_config->writeEntry("ImplicitlySetSelection",
-                             dlg->implicitSelection(), true, true );
 
         writeConfiguration( m_config ); // syncs
 
@@ -453,8 +451,6 @@ void KlipperWidget::slotConfigure()
         int message = 0;
         if ( dlg->synchronize() )
             message |= KClipboard::Synchronize;
-        if ( dlg->implicitSelection() )
-            message |= KClipboard::ImplicitSelection;
 
         KIPC::sendMessageAll( KIPC::ClipboardConfigChanged, message );
     }
@@ -710,9 +706,9 @@ void KlipperWidget::setClipboard( const 
     clip->blockSignals( true ); // ### this might break other kicker applets
 
     KClipboard *klip = KClipboard::self();
-    bool implicit = klip->implicitSelection();
+    bool selection = klip->selectionSetting();
     bool synchronize = klip->isSynchronizing();
-    klip->setImplicitSelection( false );
+    klip->setSelectionSetting( false );
     klip->setSynchronizing( false );
 
     if ( mode & Selection ) {
@@ -724,7 +720,7 @@ void KlipperWidget::setClipboard( const 
         clip->setText( text );
     }
 
-    klip->setImplicitSelection( implicit );
+    klip->setSelectionSetting( selection );
     klip->setSynchronizing( synchronize );
 
     clip->blockSignals( blocked );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic