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

List:       kde-commits
Subject:    playground/base/plasma/applets/leavemsg
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2008-08-09 11:48:35
Message-ID: 1218282515.156450.1231.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 844329 by weilbach:

Use KNotification.
Minor fixes.


 M  +0 -3      CMakeLists.txt  
 M  +2 -1      SimpleMessageDaemon/CMakeLists.txt  
 M  +61 -32    SimpleMessageDaemon/dbus/DaemonDBusHandler.cpp  
 M  +9 -3      SimpleMessageDaemon/dbus/DaemonDBusHandler.h  
 A             SimpleMessageDaemon/simplemessagedaemon.notifyrc  
 D             plasma-applet-leavemsg.notifyrc  
 M  +15 -23    plasma-leavemsg.cpp  
 M  +0 -3      plasma-leavemsg.h  


--- trunk/playground/base/plasma/applets/leavemsg/CMakeLists.txt #844328:844329
@@ -31,9 +31,6 @@
 install(FILES plasma-applet-leavemsg.desktop
         DESTINATION ${SERVICES_INSTALL_DIR})
 
-install(FILES plasma-applet-leavemsg.notifyrc 
-        DESTINATION ${DATA_INSTALL_DIR}/plasma-applet-leavemsg)
-
 install(
     FILES leavemsg.svgz
     DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
--- trunk/playground/base/plasma/applets/leavemsg/SimpleMessageDaemon/CMakeLists.txt \
#844328:844329 @@ -8,9 +8,10 @@
 qt4_add_dbus_adaptor(simplemessagedaemon_SRCS \
dbus/org.freedesktop.SimpleMessageDaemon.root.xml dbus/RootDBusHandler.h \
SimpleMessageDaemon::RootDBusHandler RootAdaptor RootAdaptor)  \
qt4_add_dbus_adaptor(simplemessagedaemon_SRCS \
dbus/org.freedesktop.SimpleMessageDaemon.daemon.xml dbus/DaemonDBusHandler.h \
SimpleMessageDaemon::DaemonDBusHandler DaemonAdaptor DaemonAdaptor)  
-
 kde4_add_executable(simplemessagedaemon ${simplemessagedaemon_SRCS})
 target_link_libraries(simplemessagedaemon ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} )
+install(FILES simplemessagedaemon.notifyrc 
+        DESTINATION ${DATA_INSTALL_DIR}/simplemessagedaemon)
 install(TARGETS simplemessagedaemon ${INSTALL_TARGETS_DEFAULT_ARGS})
 install(FILES dbus/org.freedesktop.SimpleMessageDaemon.root.xml
               DESTINATION ${DBUS_INTERFACES_INSTALL_DIR})
\ No newline at end of file
--- trunk/playground/base/plasma/applets/leavemsg/SimpleMessageDaemon/dbus/DaemonDBusHandler.cpp \
#844328:844329 @@ -16,18 +16,19 @@
  ******************************************************************************/
 
 #include "DaemonDBusHandler.h"
-
 #include "DaemonAdaptor.h"
 
 #include <QtCore/QProcess>
 #include <QtCore/QTimer>
-#include <QtGui/QWidget>
-#include <QtGui/QVBoxLayout>
 #include <QtDBus/QDBusInterface>
 #include <QtDBus/QDBusReply>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QWidget>
 
+#include <KDebug>
+#include <KLocale>
 #include <KTextEdit>
-#include <KDebug>
+#include <KNotification>
 
 namespace SimpleMessageDaemon
 {
@@ -36,7 +37,8 @@
 
     DaemonDBusHandler::DaemonDBusHandler()
            : mUseKNotes(true),
-             timer(0)
+             mTimer(0),
+             mNotification(0)
     {
         s_instance = this;
         setObjectName("DaemonDBusHandler");
@@ -46,7 +48,8 @@
     }
 
     DaemonDBusHandler::~DaemonDBusHandler(){
-        delete timer;
+        delete mNotification;
+        delete mTimer;
     }
 
 
@@ -60,9 +63,9 @@
 
         /* load KNotes if desired and unloaded */
         if(!reply.isValid() && mUseKNotes){
-            msgCache[title]=msg;
+            mMsgCache[title]=msg;
             /* check if we are loading KNotes already then cache the msg*/
-            if(timer && timer->isActive()){
+            if(mTimer && mTimer->isActive()){
                 return;
             }
 
@@ -72,39 +75,65 @@
             knotes.waitForStarted();
 
             /* wait for the dbus interface to settle */
-            timer->singleShot( 10000, this, SLOT(slotWaitForKNotes()) );
+            mTimer->singleShot( 10000, this, SLOT(slotWaitForKNotes()) );
 
         }
         else
             newMessageSender( title, msg );
      }
 
-     void DaemonDBusHandler::slotWaitForKNotes(){
-         /* now we can empty the message cash */
-         QHash<QString, QString>::iterator i;
-         for (i = msgCache.begin(); i != msgCache.end(); ++i)
-             newMessageSender( i.key(), i.value() );
-         msgCache.clear();
-     }
+    void DaemonDBusHandler::slotWaitForKNotes(){
+        /* now we can empty the message cash */
+        QHash<QString, QString>::iterator i;
+        for (i = mMsgCache.begin(); i != mMsgCache.end(); ++i)
+            newMessageSender( i.key(), i.value() );
+        mMsgCache.clear();
+    }
 
-     void DaemonDBusHandler::newMessageSender( const QString& title, const QString& \
                msg ){
-         if(/*mUseKNotes*/false){
-             QDBusInterface knotesDBus( "org.kde.knotes", "/KNotes", \
                "org.kde.KNotes" );
-             knotesDBus.call( "newNote", title, msg );
-         }
-         else{
-             QWidget* widget = new QWidget(0);
-             widget->setAttribute( Qt::WA_QuitOnClose, false );
-             widget->setWindowTitle( title );
-             KTextEdit *msgTextEdit = new KTextEdit( msg, widget );
-             msgTextEdit->setReadOnly( true );
-             QVBoxLayout *layout = new QVBoxLayout();
-             layout->addWidget( msgTextEdit );
-             widget->setLayout( layout );
-             widget->show();
-         }
+    void DaemonDBusHandler::newMessageSender( const QString& title, const QString& \
msg ){ +        if( ! mNotification )
+        {
+            delete mNotification;
+        }
+
+        mNotification= new KNotification ( "incomingNote", 0L,
+                                            KNotification::Persistent );
+        mNotification->setText( i18n( "Left note: %1", msg ) );
+        mNotification->setActions( QStringList() << i18n( "Load" )
+                                                 << i18n( "Delete" ) );
+        connect(mNotification, SIGNAL(activated(unsigned int)), 
+                this , SLOT(slotNotificationAction(unsigned int) ) );
+        mNotificationToNote[qobject_cast<QObject*>(mNotification)]=QPair<QString,QString>(title,msg);
 +        mNotification->sendEvent();
     }
 
+    void DaemonDBusHandler::slotNotificationAction(unsigned int action){
+        QString title = mNotificationToNote[sender()].first;
+        QString msg = mNotificationToNote[sender()].second;
+        mNotificationToNote.remove(mNotification);
+
+        switch(action){
+            case 1:
+                if(mUseKNotes){
+                    QDBusInterface knotesDBus( "org.kde.knotes", "/KNotes", \
"org.kde.KNotes" ); +                    knotesDBus.call( "newNote", title, msg );
+                }
+                else{
+                    QWidget* widget = new QWidget(0);
+                    widget->setAttribute( Qt::WA_QuitOnClose, false );
+                    widget->setWindowTitle( title );
+                    KTextEdit *msgTextEdit = new KTextEdit( msg, widget );
+                    msgTextEdit->setReadOnly( true );
+                    QVBoxLayout *layout = new QVBoxLayout();
+                    layout->addWidget( msgTextEdit );
+                    widget->setLayout( layout );
+                    widget->show();
+                }
+            default:
+                return;
+        };
+    }
+
 } // namespace SimpleMessageDaemon
 
 #include "DaemonDBusHandler.moc"
--- trunk/playground/base/plasma/applets/leavemsg/SimpleMessageDaemon/dbus/DaemonDBusHandler.h \
#844328:844329 @@ -18,10 +18,13 @@
 #ifndef DAEMON_DBUS_HANDLER_H
 #define DAEMON_DBUS_HANDLER_H
 
+#include <QtCore/QHash>
 #include <QtCore/QObject>
-#include <QtCore/QHash>
+#include <QtCore/QPair>
 #include <QtCore/QTimer>
 
+#include <KNotification>
+
 namespace SimpleMessageDaemon
 {
     class DaemonDBusHandler : public QObject
@@ -37,12 +40,15 @@
         private slots:
             void slotWaitForKNotes();
             void newMessageSender( const QString& title, const QString& msg );
+            void slotNotificationAction( unsigned int );
 
         private:
             static DaemonDBusHandler* s_instance;
             bool mUseKNotes;
-            QTimer *timer;
-            QHash<QString,QString> msgCache;       
+            QTimer *mTimer;
+            QHash<QString,QString> mMsgCache;
+            QHash<QObject*,QPair<QString,QString> > mNotificationToNote;
+            KNotification *mNotification;
     };
 
 } // namespace 
--- trunk/playground/base/plasma/applets/leavemsg/plasma-leavemsg.cpp #844328:844329
@@ -37,7 +37,6 @@
 
 #include <KDateTime>
 #include <KDebug>
-#include <KNotification>
 #include <KPushButton>
 #include <KTextEdit>
 #include <KLocale>
@@ -46,7 +45,7 @@
 
 PlasmaLeavemsg::PlasmaLeavemsg(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args),
-      mTheme(this), mTextEdit(0), mNotification(0)
+      mTheme(this), mTextEdit(0)
 {
     // this will get us the standard applet background, for free!
    setBackgroundHints(NoBackground);
@@ -111,33 +110,26 @@
     setBackgroundHints(Plasma::Applet::NoBackground);
     if (constraints & Plasma::SizeConstraint) {
         mTheme.resize(geometry().size());
-        mLayout->setContentsMargins(.1*geometry().width(),
-                                    .12*geometry().height(),
-                                    .1*geometry().width(),
-                                    .1*geometry().height());
+        mLayout->setContentsMargins(.08*geometry().width(),
+                                    .08*geometry().height(),
+                                    .08*geometry().width(),
+                                    .08*geometry().height());
     }
 }
 
 void PlasmaLeavemsg::slotSend()
 {
-     QString time = \
                KGlobal::locale()->formatTime(KDateTime::currentLocalDateTime().time());
                
-     QDBusInterface smdDBus( "org.kde.simplemessagedaemon", "/Daemon", 
-                                "org.kde.SimpleMessageDaemon" );
-     smdDBus.call( "newMessage", 
-                   i18nc("String + time",
-                         "Somebody has left a note at %1", time),
-                   mTextEdit->text());
-//     if(mTextEdit->nativeWidget()->toPlainText().isEmpty()) return;
-//     if( ! mNotification )
-//     {
-//        mNotification= new KNotification ( "incomingMessage", 0L,
-//                                                      KNotification::Persistent );
-//        mNotification->setComponentData( KComponentData( "plasma-applet-leavemsg" \
                )); 
-//     }
-//     mNotification->setText( mTextEdit->text() );
+    if(mTextEdit->nativeWidget()->toPlainText().isEmpty())
+       return;
+
+    QString time = KGlobal::locale()->formatTime(KDateTime::currentLocalDateTime().time());
 +    QDBusInterface smdDBus( "org.kde.simplemessagedaemon", "/Daemon", 
+                               "org.kde.SimpleMessageDaemon" );
+    smdDBus.call( "newMessage", 
+                  i18nc("String + time",
+                        "Somebody has left a note at %1", time),
+                  mTextEdit->text());
     mTextEdit->setText(QString());
-//     mNotification->setActions( QStringList( i18n( "Close" ) ) );
-//     mNotification->sendEvent();
 }
 
 void PlasmaLeavemsg::slotLimitMessageLength()
--- trunk/playground/base/plasma/applets/leavemsg/plasma-leavemsg.h #844328:844329
@@ -32,8 +32,6 @@
     class TextEdit;
 }
 
-class KNotification;
-
 // Define our plasma Applet
 class PlasmaLeavemsg : public Plasma::Applet
 {
@@ -66,7 +64,6 @@
       Plasma::PushButton *mSendButton;
 
       QGraphicsLinearLayout* mLayout;
-      KNotification *mNotification;
 };
 
 // This is the command that links your applet to the .desktop file


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

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