From 4dc074f4095e2ffddbefdf7a700b32b64d81f814 Mon Sep 17 00:00:00 2001 From: Michael Jansen Date: Wed, 8 Jul 2009 14:08:35 +0200 Subject: [PATCH] Implement KNotification constructor that takes an QObject for the parent. --- kdeui/util/knotification.cpp | 15 +++++ kdeui/util/knotification.h | 116 ++++++++++++++++++++++++------------------ 2 files changed, 82 insertions(+), 49 deletions(-) diff --git a/kdeui/util/knotification.cpp b/kdeui/util/knotification.cpp index ae06437..fbb6e1c 100644 --- a/kdeui/util/knotification.cpp +++ b/kdeui/util/knotification.cpp @@ -89,6 +89,21 @@ KNotification::KNotification(const QString& eventId, QWidget *parent, const Noti d->updateTimer.setInterval(100); } +KNotification::KNotification( + const QString& eventId, + const NotificationFlags& flags, + QObject *parent) + : QObject(parent), + d(new Private) +{ + d->eventId=eventId; + d->flags=flags; + connect(&d->updateTimer,SIGNAL(timeout()), this, SLOT(update())); + d->updateTimer.setSingleShot(true); + d->updateTimer.setInterval(100); +} + + KNotification::~KNotification() { kDebug( 299 ) << d->id; diff --git a/kdeui/util/knotification.h b/kdeui/util/knotification.h index 4a21153..abb3b1c 100644 --- a/kdeui/util/knotification.h +++ b/kdeui/util/knotification.h @@ -32,7 +32,7 @@ class QDBusError; /** * KNotification is used to notify the user of an event. - * + * * \section introduction * * There are two main kinds of notifications: @@ -89,9 +89,9 @@ class QDBusError; * The Comment field will be used in KControl to describe the application. * The Name field is optional and may be used as the application name for popup, * if Name is not present, Comment is used instead - * + * * \subsection context Context information - * + * * This part consists of hints for the configuration widget *
 		   [Context/group]
@@ -141,7 +141,7 @@ class QDBusError;
  * \subsection event Events configuration
  *   This contains the configuration of events for the user.
  *   It contains the same fields as the description file.
- *    The key of groups is in the form 
+ *    The key of groups is in the form
  *  Event/<EventName>/<ContextName>/<ContextValue>
  * 
 		   [Event/contactOnline]
@@ -151,26 +151,26 @@ class QDBusError;
 		   [Event/contactOnline/group/1]
 		   Action=Popup|Sound
  * 
- * + * * \section example Example of code - * + * * This portion of code will fire the event for the "contactOnline" event - * + * * @code KNotification *notification= new KNotification ( "contactOnline", widget ); notification->setText( i18n("The contact %1 has gone online").arg( contact->name() ) ); notification->setPixmap( contact->pixmap() ); notification->setActions( QStringList( i18n( "Open chat" ) ) ); - + foreach( const QString &group , contact->groups() ) { notification->addContext( "group" , group ) ; } - + connect(notification, SIGNAL(activated(unsigned int )), contact , SLOT(slotOpenChat()) ); - + notification->sendEvent(); * @endcode - * + * * @author Olivier Goffart \ */ class KDEUI_EXPORT KNotification : public QObject @@ -182,16 +182,16 @@ public: * Sometimes the user may want different notifications for the same event, * depending the source of the event. Example, you want to be notified for mails * that arrive in your folder "personal inbox" but not for those in "spam" folder - * + * * A notification context is a pair of two strings. - * The first string is a key from what the context is. example "group" or + * The first string is a key from what the context is. example "group" or * "filter" (not translated). - * The second is the id of the context. In our example, the group id or the + * The second is the id of the context. In our example, the group id or the * filter id in the applications. - * These strings are the ones present in the config file, and are in theory not + * These strings are the ones present in the config file, and are in theory not * shown in the user interface. - * - * The order of contexts in the list is is important, the most important context + * + * The order of contexts in the list is is important, the most important context * should be placed first. They are processed in that order when the notification occurs. * * @see event @@ -213,10 +213,10 @@ public: * The notification will be automatically closed after a timeout. (this is the default) */ CloseOnTimeout=0x00, - + /** * The notification will NOT be automatically closed after a timeout. - * You will have to track the notification, and close it with the + * You will have to track the notification, and close it with the * close function manually when the event is done, otherwise there will be a memory leak */ Persistent=0x02, @@ -227,7 +227,7 @@ public: * * If the widget is already activated when the notification occurs, the * notification will be closed after a small timeout. - * + * * This only works if the widget is the toplevel widget * @todo make it work with tabulated widget */ @@ -241,23 +241,24 @@ public: * The event is a standard kde event, and not an event of the application */ DefaultEvent=0xF000 - + }; - + Q_DECLARE_FLAGS(NotificationFlags , NotificationFlag) /** * default events you can use in the event function */ enum StandardEvent { Notification , Warning , Error , Catastrophe }; + /** * Create a new notification. - * + * * You have to use sendEvent to show the notification. - * + * * The pointer is automatically deleted when the event is closed. * - * Make sure you use one of the NotificationFlags CloseOnTimeOut or + * Make sure you use one of the NotificationFlags CloseOnTimeOut or * CloseWhenWidgetActivated, if not, * you have to close the notification yourself. * @@ -267,6 +268,23 @@ public: */ explicit KNotification(const QString & eventId , QWidget *widget=0L, const NotificationFlags &flags=CloseOnTimeout); + /** + * Create a new notification. + * + * You have to use sendEvent to show the notification. + * + * The pointer is automatically deleted when the event is closed. + * + * Make sure you use one of the NotificationFlags CloseOnTimeOut or + * CloseWhenWidgetActivated, if not, + * you have to close the notification yourself. + * + * @param eventId is the name of the event + * @param widget is a widget where the notification reports to + * @param flags is a bitmask of NotificationFlag + */ + explicit KNotification(const QString & eventId , const NotificationFlags &flags=CloseOnTimeout, QObject *parent = NULL ); + ~KNotification(); /** @@ -279,7 +297,7 @@ public: * Depending on the configuration, the taskbar entry of the window containing the widget may blink. */ QWidget *widget() const; - + /** * Set the widget associated to the notification. * The notification is reparented to the new widget. @@ -287,8 +305,8 @@ public: * @param widget the new widget */ void setWidget(QWidget *widget); - - + + /** * @return the name of the event */ @@ -315,17 +333,17 @@ public: * @see setText */ QString text() const ; - + /** * Set the notification text that will appear in the popup. - * + * * The text is shown in a QLabel, you should make sure to escape any html that is needed. * You can use some of the qt basic html tags. * * @param text the text */ void setText(const QString &text); - + /** * \return the pixmap shown in the popup * \see setPixmap @@ -336,25 +354,25 @@ public: * @param pix the pixmap */ void setPixmap(const QPixmap &pix); - + /** * @return the list of actions */ QStringList actions() const; - + /** * Set the list of actions link shown in the popup. * @param actions the list of actions */ void setActions(const QStringList& actions); - + /** * @return the list of contexts, see KNotification::Context */ ContextList contexts() const; /** * set the list of contexts, see KNotification::Context - * + * * The list of contexts must be set before calling sendEvent; */ void setContexts( const ContextList &contexts); @@ -369,12 +387,12 @@ public: * @param context_value is the value of the context */ void addContext( const QString & context_key, const QString & context_value ); - + /** * @return the notification flags. */ NotificationFlags flags() const; - + /** * Set the notification flags. * should be called before sendEvent(). @@ -397,12 +415,12 @@ public: * @param action will be 0 is the default aciton was activated, or any action id */ void activated(unsigned int action); - + /** * Convenience signal that is emitted when the first action is activated. */ void action1Activated(); - + /** * \overload */ @@ -447,7 +465,7 @@ public Q_SLOTS: * The notification will automatically be closed if all presentations are finished. * if you want to show your own presentation in your application, you should use this * function, so it will not be automatically closed when there is nothing to show. - * + * * don't forgot to deref, or the notification may be never closed if there is no timeout. * @see ref */ @@ -458,12 +476,12 @@ public Q_SLOTS: * @see ref */ void deref(); - + /** * Emit or re-emit the event. */ void sendEvent(); - + /** * @internal * update the texts, the icon, and the actions of one existing notification @@ -473,11 +491,11 @@ public Q_SLOTS: private Q_SLOTS: void slotReceivedId(int); void slotReceivedIdError(const QDBusError&); - + private: struct Private; Private *const d; - + protected: /** * reimplemented for internal reasons @@ -488,7 +506,7 @@ protected: public: /** * @brief emit an event - * + * * This method creates the KNotification, setting every parameter, and fire the event. * You don't need to call sendEvent * @@ -524,20 +542,20 @@ public: * @param text is the text of the notification to show in the popup * @param pixmap is a picture which may be shown in the popup * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag + * @param flags is a bitmask of NotificationFlag */ static KNotification *event( StandardEvent eventId , const QString& text=QString(), const QPixmap& pixmap=QPixmap(), QWidget *widget=0L, const NotificationFlags& flags=CloseOnTimeout); - + /** * This is a simple substitution for QApplication::beep() - * + * * @param reason a short text explaining what has happened (may be empty) * @param widget the widget the notification refers to */ static void beep( const QString& reason = QString() , QWidget *widget=0L); - + //prevent warning using QObject::event; }; -- 1.6.0.2