--Boundary-00=_TMcc/KWdCkTtbQL Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Here is the reworked patch (only the .cpp file as the rest is the same),=20 which: =2D - doesn't leak =2D - uses DCOPRef =2D - 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= =20 believe users will appreciate it. I'm also interested in other core devel=20 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. >=20 > Technically on the patch: >=20 > 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 >=20 > Anyway, just my 2 cents. >=20 > Simon >=20 >=20 >=20 >=20 >=20 >=20 =2D --=20 Quanta Plus developer - http://quanta.sourceforge.net K Desktop Environment - http://www.kde.org =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/ccMTTQdfac6L/08RAjD6AJ0fGzbY6Okpa++GiiDRtB1QVaPkWwCeL58c HZwThGU2Jp2BzyrSVUM09LQ=3D =3D059D =2D----END PGP SIGNATURE----- --Boundary-00=_TMcc/KWdCkTtbQL Content-Type: text/x-diff; charset="iso-8859-1"; name="kactionclassess.cpp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kactionclassess.cpp.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 +#include +#include +#include #include #include #include #include +#include +#include #include #include #include @@ -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 */ --Boundary-00=_TMcc/KWdCkTtbQL--