On Thursday 29 April 2010, Aaron J. Seigo wrote:
> On April 29, 2010, Marco Martin wrote:
> > i think i like more the second option.
> > the only problem is that the ui for it would be rather clunky (there would
> > be two distinct shortcut configurations in 2 different places that do
> > almost the same thing)
> 
> yes, a little clunky. perhaps room for improvement in the future. bonus 
> points 
> for working with any entry in the system tray though ;)
> 
> which reminds me: someday we really ought to implement some keyboard 
> navigation :)

I like this option as well. Keyboard shortcuts are important for
accessability, so this is something that really should work with all
icons and not just with klipper.

Anyway, I've attached the current version of the Klipper patch.
Aside from the keyboard shortcut there's also the issue that the
dbus menu isn't always updated when the clipboard history changes.
Sometimes it is, sometimes it isn't.

I'm hoping Aurélien has some idea about that.

Regards,
Fredrik

Index: klipper.cpp
===================================================================
--- klipper.cpp	(revision 1121129)
+++ klipper.cpp	(working copy)
@@ -356,27 +356,17 @@
     Q_ASSERT( menu != 0L );
 
     QSize size = menu->sizeHint(); // geometry is not valid until it's shown
-    if (m_bPopupAtMouse) {
-        QPoint g = QCursor::pos();
-        if ( size.height() < g.y() )
-            menu->popup(QPoint( g.x(), g.y() - size.height()));
-        else
-            menu->popup(QPoint(g.x(), g.y()));
-    } else {
-        if( KSystemTrayIcon* tray = dynamic_cast< KSystemTrayIcon* >( parent())) {
-            QRect g = tray->geometry();
-            QRect screen = KGlobalSettings::desktopGeometry(g.center());
+    QPoint pos;
 
-            if ( g.x()-screen.x() > screen.width()/2 &&
-                 g.y()-screen.y() + size.height() > screen.height() )
-                menu->popup(QPoint( g.x(), g.y() - size.height()));
-            else
-                menu->popup(QPoint( g.x() + g.width(), g.y() + g.height()));
-        } else
-            abort();
+    if ( m_bPopupAtMouse )
+        pos = QCursor::pos();
+    else
+        pos = m_trayPos;
 
-        //      menu->exec(mapToGlobal(QPoint( width()/2, height()/2 )));
-    }
+    if ( size.height() < pos.y() )
+        pos.ry() -= size.height();
+
+    menu->popup(pos);
 }
 
 bool Klipper::loadHistory() {
@@ -581,6 +571,11 @@
     showPopupMenu( popup );
 }
 
+void Klipper::slotPopupMenu(bool active, const QPoint &pos) {
+    Q_UNUSED(active)
+    m_trayPos = pos;
+    slotPopupMenu();
+}
 
 void Klipper::slotRepeatAction()
 {
Index: tray.cpp
===================================================================
--- tray.cpp	(revision 1121129)
+++ tray.cpp	(working copy)
@@ -28,16 +28,23 @@
 
 #include "klipper.h"
 #include "history.h"
-#include <KPassivePopup>
+#include "klipperpopup.h"
 
+#include <KNotification>
+
 KlipperTray::KlipperTray()
-    : KSystemTrayIcon( "klipper" )
+    : KStatusNotifierItem()
 {
     m_klipper = new Klipper( this, KGlobal::config());
-    setContextMenu( NULL );
-    show();
-    connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason )), m_klipper,
-        SLOT( slotPopupMenu()));
+    setTitle( i18n( "Klipper" ) );
+    setIconByName( "klipper" );
+    setToolTip( "klipper", i18n( "Clipboard Contents" ), i18n( "Clipboard is empty" ) );
+    setCategory( SystemServices );
+    setStatus( Active );
+    setStandardActionsEnabled( false );
+    setContextMenu( m_klipper->history()->popup() );
+    connect( this, SIGNAL( activateRequested( bool, QPoint )), m_klipper,
+        SLOT( slotPopupMenu( bool, QPoint)));
     connect( m_klipper->history(), SIGNAL(changed()), SLOT(slotSetToolTipFromHistory()));
     slotSetToolTipFromHistory();
     connect( m_klipper, SIGNAL(passivePopup(QString,QString)), SLOT(passive_popup(QString,QString)));
@@ -46,17 +53,22 @@
 void KlipperTray::slotSetToolTipFromHistory()
 {
     if (m_klipper->history()->empty()) {
-      setToolTip( i18n("Clipboard is empty"));
+      setToolTipSubTitle( i18n("Clipboard is empty"));
     } else {
       const HistoryItem* top = m_klipper->history()->first();
-      setToolTip(top->text());
+      setToolTipSubTitle(top->text());
     }
-
 }
 
 void KlipperTray::passive_popup(const QString& caption, const QString& text)
 {
-    KPassivePopup::message(KPassivePopup::Boxed, caption, text, icon().pixmap(QSize(16,16)), this);
+    if (m_notification) {
+        m_notification->setTitle(caption);
+        m_notification->setText(text);
+    } else {
+        m_notification = KNotification::event(KNotification::Notification, caption, text,
+                                              KIcon("klipper").pixmap(QSize(16, 16)));
+    }
 }
 
 #include "tray.moc"
Index: klipper.h
===================================================================
--- klipper.h	(revision 1121129)
+++ klipper.h	(working copy)
@@ -156,6 +156,7 @@
 
 public Q_SLOTS:
     void slotPopupMenu();
+    void slotPopupMenu(bool active, const QPoint &pos);
     void slotAskClearHistory();
 protected Q_SLOTS:
     void showPopupMenu( QMenu * );
@@ -237,6 +238,7 @@
     KlipperSessionManager* m_session_managed;
     KActionCollection *m_collection;
     KlipperEmptyDetector m_empty_detector;
+    QPoint m_trayPos;
 };
 
 #endif
Index: tray.h
===================================================================
--- tray.h	(revision 1121129)
+++ tray.h	(working copy)
@@ -21,11 +21,13 @@
 #ifndef _TRAY_H_
 #define _TRAY_H_
 
-#include <ksystemtrayicon.h>
+#include <KStatusNotifierItem>
+#include <KNotification>
+#include <QPointer>
 
 class Klipper;
 
-class KlipperTray : public KSystemTrayIcon
+class KlipperTray : public KStatusNotifierItem
 {
     Q_OBJECT
 
@@ -36,6 +38,7 @@
     void passive_popup(const QString& caption, const QString& text);
 private:
     Klipper* m_klipper;
+    QPointer<KNotification> m_notification;
 };
 
 #endif
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to