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

List:       kde-commits
Subject:    KDE/kdebase/workspace/klipper
From:       Fredrik Höglund <fredrik () kde ! org>
Date:       2010-05-10 21:52:57
Message-ID: 20100510215257.BEE54AC8B2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1125178 by fredrik:

- Port Klipper to KStatusNotifierItem.
- Remove the shortcut for showing the menu, and the option for showing
  the menu at the cursor position when the shortcut is triggered.
  (The shortcut is now configured in the systray settings.)


 M  +0 -7      generalconfig.ui  
 M  +6 -25     klipper.cpp  
 M  +0 -1      klipper.h  
 M  +0 -4      klipper.kcfg  
 M  +21 -10    tray.cpp  
 M  +5 -2      tray.h  


--- trunk/KDE/kdebase/workspace/klipper/generalconfig.ui #1125177:1125178
@@ -12,13 +12,6 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
-    <widget class="QCheckBox" name="kcfg_PopupAtMousePosition">
-     <property name="text">
-      <string>Popup menu at mouse-cursor position</string>
-     </property>
-    </widget>
-   </item>
-   <item>
     <widget class="QCheckBox" name="kcfg_KeepClipboardContents">
      <property name="text">
       <string>Save clipboard contents on exit</string>
--- trunk/KDE/kdebase/workspace/klipper/klipper.cpp #1125177:1125178
@@ -191,11 +191,6 @@
     // if it's too old, drop it and just use load history
     readProperties(m_config.data());
 
-    KAction* a = m_collection->addAction("show_klipper_popup");
-    a->setText(i18n("Show Klipper Popup-Menu"));
-    a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_V));
-    connect(a, SIGNAL(triggered()), SLOT(slotPopupMenu()));
-
     m_repeatAction = m_collection->addAction("repeat_action");
     m_repeatAction->setText(i18n("Manually Invoke Action on Current Clipboard"));
     qobject_cast<KAction*>(m_repeatAction)->setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_R));
@@ -308,7 +303,6 @@
         saveHistory(true);
     }
 
-    m_bPopupAtMouse = KlipperSettings::popupAtMousePosition();
     m_bKeepContents = KlipperSettings::keepClipboardContents();
     m_bReplayActionInHistory = KlipperSettings::replayActionInHistory();
     m_bNoNullClipboard = KlipperSettings::preventEmptyClipboard();
@@ -356,28 +350,15 @@
     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 = QCursor::pos();
+    // ### We can't know where the systray icon is (since it can be hidden or shown 
+    //     in several places), so the cursor position is the only option.
 
-            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 ( size.height() < pos.y() )
+        pos.ry() -= size.height();
 
-        //      menu->exec(mapToGlobal(QPoint( width()/2, height()/2 )));
+    menu->popup(pos);
     }
-}
 
 bool Klipper::loadHistory() {
     static const char* const failed_load_warning =
--- trunk/KDE/kdebase/workspace/klipper/klipper.h #1125177:1125178
@@ -203,7 +203,6 @@
     KAction* m_cycleNextAction;
     KAction* m_cyclePrevAction;
     QPixmap m_pixmap;
-    bool m_bPopupAtMouse :1;
     bool m_bKeepContents :1;
     bool m_bURLGrabber   :1;
     bool m_bReplayActionInHistory :1;
--- trunk/KDE/kdebase/workspace/klipper/klipper.kcfg #1125177:1125178
@@ -8,10 +8,6 @@
     <entry name="Version" type="String">
       <label>Klipper version</label>
     </entry>
-    <entry name="PopupAtMousePosition" type="Bool">
-      <label>Popup at mouse position</label>
-      <default>false</default>
-    </entry>
     <entry name="KeepClipboardContents" type="Bool">
       <label>Keep clipboard contents</label>
       <default>true</default>
--- trunk/KDE/kdebase/workspace/klipper/tray.cpp #1125177:1125178
@@ -28,16 +28,22 @@
 
 #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() );
+    setAssociatedWidget( m_klipper->history()->popup() );
     connect( m_klipper->history(), SIGNAL(changed()), SLOT(slotSetToolTipFromHistory()));
     slotSetToolTipFromHistory();
     connect( m_klipper, SIGNAL(passivePopup(QString,QString)), SLOT(passive_popup(QString,QString)));
@@ -46,17 +52,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"
--- trunk/KDE/kdebase/workspace/klipper/tray.h #1125177:1125178
@@ -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
[prev in list] [next in list] [prev in thread] [next in thread] 

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