[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/plasma/applets/leavenote
From: Christian Weilbach <christian () whiletaker ! homeip ! net>
Date: 2008-08-14 1:56:50
Message-ID: 1218679010.069623.15560.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 846744 by weilbach:
Add bool switches for KNotes and KNOtificiaton integration to the DBus daemon and add \
a config integration to the plasmoid.
M +1 -0 CMakeLists.txt
M +55 -28 LeaveNoteHelperDaemon/dbus/DaemonDBusHandler.cpp
M +7 -4 LeaveNoteHelperDaemon/dbus/DaemonDBusHandler.h
M +2 -0 LeaveNoteHelperDaemon/dbus/org.kde.LeaveNoteHelperDaemon.daemon.xml
M +6 -1 LeaveNoteHelperDaemon/main.cpp
M +27 -4 plasma-leavenote.cpp
M +13 -0 plasma-leavenote.h
A widget.ui
--- trunk/playground/base/plasma/applets/leavenote/CMakeLists.txt #846743:846744
@@ -20,6 +20,7 @@
set(leavenote_SRCS plasma-leavenote.cpp)
# Now make sure all files get to the right place
+kde4_add_ui_files(leavenote_SRCS widget.ui)
kde4_add_plugin(plasma_applet_leavenote ${leavenote_SRCS})
target_link_libraries(plasma_applet_leavenote
--- trunk/playground/base/plasma/applets/leavenote/LeaveNoteHelperDaemon/dbus/DaemonDBusHandler.cpp \
#846743:846744 @@ -53,7 +53,8 @@
}
- void DaemonDBusHandler::newMessage( const QString& title, const QString& msg ){
+ void DaemonDBusHandler::newMessage( const QString& title, const QString& msg,
+ bool useKNotes, bool useNotification ){
/* test for the dbus interface */
QDBusInterface knotesDBusTest( "org.kde.knotes", "/KNotes", \
"org.freedesktop.DBus.Introspectable" ); QDBusReply<QString>reply = \
knotesDBusTest.call( "Introspect" ); @@ -62,8 +63,14 @@
kDebug() << "KNotes DBus interface test error: " << reply.error();
/* load KNotes if desired and unloaded */
- if(!reply.isValid() && mUseKNotes){
- mMsgCache[title]=msg;
+ if(!reply.isValid() && useKNotes){
+ QHash<QString,QVariant> hash;
+ hash["title"]=title;
+ hash["msg"]=msg;
+ hash["useKNotes"]=useKNotes;
+ hash["useNotificaiton"]=useNotification;
+ mMsgCache<<hash;
+
/* check if we are loading KNotes already then cache the msg*/
if(mTimer && mTimer->isActive()){
return;
@@ -79,18 +86,30 @@
}
else
- newMessageSender( title, msg );
+ if( useNotification )
+ notificationSender( title, msg, useKNotes );
+ else
+ createNote( title, msg, useKNotes );
}
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() );
+ QList<QHash<QString,QVariant> >::iterator i;
+ for (i = mMsgCache.begin(); i != mMsgCache.end(); ++i){
+ if( ( *i )["useNotification"].toBool() )
+ notificationSender( ( *i )["title"].toString(),
+ ( *i )["msg"].toString(),
+ ( *i )["useKNotes"].toBool() );
+ else
+ createNote( ( *i )["title"].toString(),
+ ( *i )["msg"].toString(),
+ ( *i )["useKNotes"].toBool() );
+ }
mMsgCache.clear();
}
- void DaemonDBusHandler::newMessageSender( const QString& title, const QString& \
msg ){ + void DaemonDBusHandler::notificationSender( const QString& title, const \
QString& msg, + bool useKNotes ){
mNotification= new KNotification ( "incomingNote", 0L,
KNotification::Persistent );
mNotification->setText( i18n( "Left note: %1", msg ) );
@@ -101,39 +120,47 @@
<< i18n( "Delete" ) );
connect(mNotification, SIGNAL(activated(unsigned int)),
this , SLOT(slotNotificationAction(unsigned int) ) );
- mNotificationToNote[qobject_cast<QObject*>(mNotification)]=QPair<QString,QString>(title,msg);
+ mNotificationToNote[qobject_cast<QObject*>(mNotification)]["title"]=title;
+ mNotificationToNote[qobject_cast<QObject*>(mNotification)]["msg"]=msg;
+ mNotificationToNote[qobject_cast<QObject*>(mNotification)]["useKNotes"]=useKNotes;
mNotification->sendEvent();
}
void DaemonDBusHandler::slotNotificationAction(unsigned int action){
- QString title = mNotificationToNote[sender()].first;
- QString msg = mNotificationToNote[sender()].second;
- mNotificationToNote.remove(sender());
- qobject_cast<KNotification*>(sender())->close();
+ QString title = mNotificationToNote[sender()]["title"].toString();
+ QString msg = mNotificationToNote[sender()]["msg"].toString();
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();
- }
+ createNote( title, msg, \
mNotificationToNote[sender()]["useKNotes"].toBool()); break;
default:
return;
};
+
+ mNotificationToNote.remove(sender());
+ qobject_cast<KNotification*>(sender())->close();
}
+ void DaemonDBusHandler::createNote( const QString& title, const QString& msg,
+ bool useKNotes ){
+ if( useKNotes ){
+ 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 ); // TODO remove
+ widget->setWindowTitle( title );
+ KTextEdit *msgTextEdit = new KTextEdit( msg, widget );
+ msgTextEdit->setReadOnly( true );
+ QVBoxLayout *layout = new QVBoxLayout();
+ layout->addWidget( msgTextEdit );
+ widget->setLayout( layout );
+ widget->show();
+ }
+ }
+
} // namespace LeaveNoteHelperDaemon
#include "DaemonDBusHandler.moc"
--- trunk/playground/base/plasma/applets/leavenote/LeaveNoteHelperDaemon/dbus/DaemonDBusHandler.h \
#846743:846744 @@ -22,6 +22,7 @@
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <QtCore/QTimer>
+#include <QtCore/QVariant>
#include <KNotification>
@@ -35,19 +36,21 @@
~DaemonDBusHandler();
public slots:
- void newMessage(const QString& title, const QString& msg);
+ void newMessage(const QString& title, const QString& msg, bool \
useKNotes, bool useNotification);
private slots:
void slotWaitForKNotes();
- void newMessageSender( const QString& title, const QString& msg );
void slotNotificationAction( unsigned int );
private:
+ void notificationSender( const QString& title, const QString& msg, bool \
useKNotes ); + void createNote( const QString& title, const QString& msg, \
bool useKNotes ); +
static DaemonDBusHandler* s_instance;
bool mUseKNotes;
QTimer *mTimer;
- QHash<QString,QString> mMsgCache;
- QHash<QObject*,QPair<QString,QString> > mNotificationToNote;
+ QList<QHash<QString,QVariant> > mMsgCache;
+ QHash<QObject*,QHash<QString,QVariant> > mNotificationToNote;
KNotification *mNotification;
};
--- trunk/playground/base/plasma/applets/leavenote/LeaveNoteHelperDaemon/dbus/org.kde.LeaveNoteHelperDaemon.daemon.xml \
#846743:846744 @@ -8,6 +8,8 @@
<method name="newMessage">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
+ <arg type="b" direction="in"/>
+ <arg type="b" direction="in"/>
</method>
</interface>
--- trunk/playground/base/plasma/applets/leavenote/LeaveNoteHelperDaemon/main.cpp \
#846743:846744 @@ -30,10 +30,15 @@
KUniqueApplication::addCmdLineOptions();
if( !KUniqueApplication::start() ) {
- fprintf( stderr, "LeaveNoteHelperDaemon is already running!\n" );
+ kDebug() << "LeaveNoteHelperDaemon is already running!";
return 0;
}
Daemon app;
+
+ // This app is started automatically, no need for session management
+ app.disableSessionManagement();
+ app.setQuitOnLastWindowClosed( false );
+
return app.exec();
}
--- trunk/playground/base/plasma/applets/leavenote/plasma-leavenote.cpp \
#846743:846744 @@ -37,6 +37,7 @@
#include <Plasma/Svg>
#include <Plasma/TextEdit>
+#include <KConfigDialog>
#include <KDateTime>
#include <KDebug>
#include <KPushButton>
@@ -47,7 +48,8 @@
LeaveNote::LeaveNote(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
- mTheme(this), mTextEdit(0)
+ mTheme(this), mTextEdit(0),
+ mUseKNotes(false),mUseNotification(false)
{
// this will get us the standard applet background, for free!
setBackgroundHints(NoBackground);
@@ -61,6 +63,7 @@
void LeaveNote::init()
{
+ setHasConfigurationInterface(true);
/* start the simplemessagedaemon to keep track of the messages
* even after the applet has vanished (screen unlock) */
QProcess smd;
@@ -119,18 +122,38 @@
}
}
+void LeaveNote::createConfigurationInterface(KConfigDialog *dialog)
+{ /* Thanks: Luna - WindowsUninstall, jackrabbit, aseigo */
+ QWidget *widget = new QWidget();
+ ui.setupUi(widget);
+/* from example in http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKDialog.html \
*/ + dialog->setMainWidget( widget );
+ dialog->setButtons(KDialog::Ok | KDialog::Cancel ); // | KDialog::Apply
+ connect(dialog, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
+ connect(dialog, SIGNAL(okClicked()), this, SLOT(configAccepted()));
+
+ dialog->addPage(widget, dialog->windowTitle(), icon());
+}
+
+
+void LeaveNote::configAccepted()
+{
+ mUseKNotes = ui.useKNotesCheckBox->isChecked();
+ mUseNotification = ui.useNotificationCheckBox->isChecked();
+}
+
void LeaveNote::slotSend()
{
if(mTextEdit->nativeWidget()->toPlainText().isEmpty())
return;
QString time = KGlobal::locale()->formatTime(KDateTime::currentLocalDateTime().time());
- QDBusInterface smdDBus( "org.kde.leavenotehelperdaemon", "/Daemon",
+ QDBusInterface lnhdDBus( "org.kde.leavenotehelperdaemon", "/Daemon",
"org.kde.LeaveNoteHelperDaemon" );
- smdDBus.call( "newMessage",
+ lnhdDBus.call( "newMessage",
i18nc("String + time",
"Somebody has left a note at %1", time),
- mTextEdit->text());
+ mTextEdit->text(), mUseKNotes, mUseNotification );
mTextEdit->setText(QString());
}
--- trunk/playground/base/plasma/applets/leavenote/plasma-leavenote.h #846743:846744
@@ -24,6 +24,7 @@
#include <Plasma/Applet>
#include <Plasma/Svg>
+#include "ui_widget.h"
class QGraphicsLinearLayout;
namespace Plasma {
@@ -47,7 +48,14 @@
const QRect& contentsRect);
protected:
void constraintsEvent(Plasma::Constraints constraints);
+ void createConfigurationInterface(KConfigDialog *parent);
+ protected slots:
+ void configAccepted();
+
+ protected:
+
+
private slots:
void slotSend();
void slotLimitMessageLength();
@@ -64,6 +72,11 @@
Plasma::PushButton *mSendButton;
QGraphicsLinearLayout* mLayout;
+
+ /* bools for the dbus daemon */
+ bool mUseKNotes, mUseNotification;
+
+ Ui::leavenoteConfig ui;
};
// 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