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

List:       kde-core-devel
Subject:    Re: [PATCH] Show the clipboard history when pressing the Paste
From:       Andras Mantia <amantia () kde ! org>
Date:       2003-09-24 16:15:15
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here is the reworked patch (only the .cpp file as the rest is the same), 
which:
- - doesn't leak
- - uses DCOPRef
- - doesn't try to attach to the DCOP server if it's not attached

Are you really think that this is such a bad idea? I kind of like it and I 
believe users will appreciate it. I'm also interested in other core devel 
opinions if there are any.

Andras

On Tuesday 23 September 2003 10:36, Simon Hausmann wrote:
[...]
> I have to admit that I for one don't really like the idea of such a
> dependency. (What if klipper gets removed one day?) . Plus the menu
> will always be visible, even if klipper is not running. It will
> appear as empty menu, which looks really ugly.
> 
> Technically on the patch:
> 
> 1) The popupmenu appears to be leaked.
> 2) It's _much_ easier to perform dcop calls with DCOPRef than to do
>    the (de)marshalling of the data manually
> 3) The if ( !client->isAttached() ) client->attach() is superfluous
>    IMHO
> 
> Anyway, just my 2 cents.
> 
> Simon
> 
> 
> 
> 
> 
> 

- -- 
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/ccMTTQdfac6L/08RAjD6AJ0fGzbY6Okpa++GiiDRtB1QVaPkWwCeL58c
HZwThGU2Jp2BzyrSVUM09LQ=
=059D
-----END PGP SIGNATURE-----

["kactionclassess.cpp.diff" (text/x-diff)]

--- kactionclasses.cpp.orig	2003-09-21 13:14:40.000000000 +0300
+++ kactionclasses.cpp	2003-09-24 19:05:39.000000000 +0300
@@ -27,11 +27,16 @@
 
 #include <assert.h>
 
+#include <qcstring.h>
+#include <qclipboard.h>
+#include <qdatastream.h>
 #include <qfontdatabase.h>
 #include <qobjectlist.h>
 #include <qwhatsthis.h>
 #include <qtimer.h>
 
+#include <dcopclient.h>
+#include <dcopref.h>
 #include <kaccel.h>
 #include <kapplication.h>
 #include <kconfig.h>
@@ -1976,6 +2056,99 @@
   return -1;
 }
 
+KPasteAction::KPasteAction( const QString& text,
+                            const QString& icon,
+                            const KShortcut& cut,
+                            const QObject* receiver,
+                            const char* slot, QObject* parent,
+                            const char* name)
+  : KAction( text, icon, cut, receiver, slot, parent, name )
+{  
+  m_popup = new KPopupMenu;
+  connect(m_popup, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
+  connect(m_popup, SIGNAL(activated(int)), this, SLOT(menuItemActivated(int)));  
+  m_popup->setCheckable(true);
+}            
+
+KPasteAction::~KPasteAction()
+{
+  delete m_popup;
+}    
+
+int KPasteAction::plug( QWidget *widget, int index )
+{
+  if (kapp && !kapp->authorizeKAction(name()))
+    return -1;
+  // This is very related to KActionMenu::plug.
+  // In fact this class could be an interesting base class for KActionMenu
+  if ( widget->inherits( "KToolBar" ) )
+  {
+    KToolBar *bar = (KToolBar *)widget;
+
+    int id_ = KAction::getToolButtonID();
+
+    KInstance * instance;
+    if ( m_parentCollection )
+        instance = m_parentCollection->instance();
+    else
+        instance = KGlobal::instance();
+
+    bar->insertButton( icon(), id_, SIGNAL( clicked() ), this,
+                       SLOT( slotActivated() ), isEnabled(), plainText(),
+                       index, instance );
+
+    addContainer( bar, id_ );
+
+    connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
+
+    bar->setDelayedPopup( id_, m_popup, true );
+
+    if ( !whatsThis().isEmpty() )
+        QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
+
+    return containerCount() - 1;
+  }
+
+  return KAction::plug( widget, index );
+}
+     
+void KPasteAction::menuAboutToShow()
+{
+    m_popup->clear();
+    QStringList list;
+    DCOPClient *client = kapp->dcopClient();
+    if (client->isAttached() && client->isApplicationRegistered("klipper")) {
+      DCOPRef klipper("klipper","klipper");
+      DCOPReply reply = klipper.call("getClipboardHistoryMenu");
+      if (reply.isValid())
+        list = reply;          
+    }
+    QString clipboardText = qApp->clipboard()->text(QClipboard::Clipboard);
+    if (list.isEmpty())
+        list << clipboardText;
+    bool found = false;        
+    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 
+    {
+      int id = m_popup->insertItem(*it);
+      if (!found && *it == clipboardText)
+      {
+        m_popup->setItemChecked(id, true);
+        found = true;
+      }
+    }
+}
+
+void KPasteAction::menuItemActivated( int id)
+{
+    DCOPClient *client = kapp->dcopClient();
+    if (client->isAttached() && client->isApplicationRegistered("klipper")) {
+      DCOPRef klipper("klipper","klipper");
+      if (klipper.send("setClipboardContents", m_popup->text(id)))
+        kdDebug(129) << "Clipboard: " << qApp->clipboard()->text(QClipboard::Clipboard) << endl;    
+    }
+    QTimer::singleShot(20, this, SLOT(slotActivated())); 
+}
+
 void KToggleAction::virtual_hook( int id, void* data )
 { KAction::virtual_hook( id, data ); }
 
@@ -2015,6 +2188,7 @@
 void KActionSeparator::virtual_hook( int id, void* data )
 { KAction::virtual_hook( id, data ); }
 
+
 /* vim: et sw=2 ts=2
  */
 


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

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