File indexing completed on 2024-04-28 15:29:09
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org> 0004 SPDX-FileCopyrightText: 2013-2015 Martin Klapetek <mklapetek@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KNOTIFICATION_H 0010 #define KNOTIFICATION_H 0011 0012 #include <knotifications_export.h> 0013 0014 #include <QList> 0015 #include <QObject> 0016 #include <QPair> 0017 #include <QPixmap> 0018 #include <QUrl> 0019 #include <QVariant> 0020 0021 #include <memory> 0022 0023 class QWidget; 0024 0025 class KNotificationReplyAction; 0026 0027 /** 0028 * @class KNotification knotification.h KNotification 0029 * 0030 * KNotification is the main class for creating notifications. 0031 */ 0032 class KNOTIFICATIONS_EXPORT KNotification : public QObject 0033 { 0034 Q_OBJECT 0035 /** 0036 * @copydoc setEventId 0037 * @since 5.88 0038 */ 0039 Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged) 0040 /** 0041 * @copydoc setTitle 0042 * @since 5.88 0043 */ 0044 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0045 /** 0046 * @copydoc setText 0047 * @since 5.88 0048 */ 0049 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) 0050 /** 0051 * @copydoc setIconName 0052 * @since 5.88 0053 */ 0054 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) 0055 /** 0056 * @copydoc setDefaultAction 0057 * @since 5.88 0058 */ 0059 Q_PROPERTY(QString defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged) 0060 /** 0061 * @copydoc setActions 0062 * @since 5.88 0063 */ 0064 Q_PROPERTY(QStringList actions READ actions WRITE setActions NOTIFY actionsChanged) 0065 /** 0066 * @copydoc setFlags 0067 * @since 5.88 0068 */ 0069 Q_PROPERTY(NotificationFlags flags READ flags WRITE setFlags NOTIFY flagsChanged) 0070 /** 0071 * @copydoc setComponentName 0072 * @since 5.88 0073 */ 0074 Q_PROPERTY(QString componentName READ componentName WRITE setComponentName NOTIFY componentNameChanged) 0075 /** 0076 * @copydoc setUrls 0077 * @since 5.88 0078 */ 0079 Q_PROPERTY(QList<QUrl> urls READ urls WRITE setUrls NOTIFY urlsChanged) 0080 /** 0081 * @copydoc setUrgency 0082 * @since 5.88 0083 */ 0084 Q_PROPERTY(Urgency urgency READ urgency WRITE setUrgency NOTIFY urgencyChanged) 0085 /** 0086 * @copydoc setAutoDelete 0087 * @since 5.88 0088 */ 0089 Q_PROPERTY(bool autoDelete READ isAutoDelete WRITE setAutoDelete NOTIFY autoDeleteChanged) 0090 /** 0091 * @since 5.90 0092 */ 0093 Q_PROPERTY(QString xdgActivationToken READ xdgActivationToken NOTIFY xdgActivationTokenChanged) 0094 /** 0095 * @copydoc setHint 0096 * @since 5.101 0097 */ 0098 Q_PROPERTY(QVariantMap hints READ hints WRITE setHints NOTIFY hintsChanged) 0099 0100 public: 0101 /** 0102 * Sometimes the user may want different notifications for the same event, 0103 * depending the source of the event. Example, you want to be notified for mails 0104 * that arrive in your folder "personal inbox" but not for those in "spam" folder 0105 * 0106 * A notification context is a pair of two strings. 0107 * The first string is a key from what the context is. example "group" or 0108 * "filter" (not translated). 0109 * The second is the id of the context. In our example, the group id or the 0110 * filter id in the applications. 0111 * These strings are the ones present in the config file, and are in theory not 0112 * shown in the user interface. 0113 * 0114 * The order of contexts in the list is is important, the most important context 0115 * should be placed first. They are processed in that order when the notification occurs. 0116 * 0117 * @see event 0118 */ 0119 typedef QPair<QString, QString> Context; 0120 typedef QList<Context> ContextList; 0121 0122 /** 0123 * @see NotificationFlags 0124 */ 0125 enum NotificationFlag { 0126 /** 0127 * When the notification is activated, raise the notification's widget. 0128 * 0129 * This will change the desktop, raise the window, and switch to the tab. 0130 * @todo doesn't work yet 0131 */ 0132 RaiseWidgetOnActivation = 0x01, 0133 0134 /** 0135 * The notification will be automatically closed after a timeout. (this is the default) 0136 */ 0137 CloseOnTimeout = 0x00, 0138 0139 /** 0140 * The notification will NOT be automatically closed after a timeout. 0141 * You will have to track the notification, and close it with the 0142 * close function manually when the event is done, otherwise there will be a memory leak 0143 */ 0144 Persistent = 0x02, 0145 0146 /** 0147 * The notification will be automatically closed if the widget() becomes 0148 * activated. 0149 * 0150 * If the widget is already activated when the notification occurs, the 0151 * notification will be closed after a small timeout. 0152 * 0153 * This only works if the widget is the toplevel widget 0154 * @todo make it work with tabulated widget 0155 */ 0156 CloseWhenWidgetActivated = 0x04, 0157 0158 /** 0159 * The audio plugin will loop the sound until the notification is closed 0160 */ 0161 LoopSound = 0x08, 0162 0163 /** 0164 * Sends a hint to Plasma to skip grouping for this notification 0165 * 0166 * @since 5.18 0167 */ 0168 SkipGrouping = 0x10, 0169 0170 /** 0171 * @internal 0172 * The event is a standard kde event, and not an event of the application 0173 */ 0174 DefaultEvent = 0xF000, 0175 0176 }; 0177 0178 /** 0179 * Stores a combination of #NotificationFlag values. 0180 */ 0181 Q_DECLARE_FLAGS(NotificationFlags, NotificationFlag) 0182 Q_FLAG(NotificationFlags) 0183 0184 /** 0185 * default events you can use in the event function 0186 */ 0187 enum StandardEvent { 0188 Notification, 0189 Warning, 0190 Error, 0191 Catastrophe, 0192 }; 0193 0194 /** 0195 * The urgency of a notification. 0196 * 0197 * @since 5.58 0198 * @sa setUrgency 0199 */ 0200 enum Urgency { 0201 DefaultUrgency = -1, 0202 LowUrgency = 10, 0203 NormalUrgency = 50, 0204 HighUrgency = 70, 0205 CriticalUrgency = 90, 0206 }; 0207 Q_ENUM(Urgency) 0208 0209 #if KNOTIFICATIONS_ENABLE_DEPRECATED_SINCE(5, 75) 0210 /** 0211 * Create a new notification. 0212 * 0213 * You have to use sendEvent to show the notification. 0214 * 0215 * The pointer is automatically deleted when the event is closed. 0216 * 0217 * Make sure you use one of the NotificationFlags CloseOnTimeOut or 0218 * CloseWhenWidgetActivated, if not, 0219 * you have to close the notification yourself. 0220 * 0221 * @param eventId is the name of the event 0222 * @param widget is a widget where the notification reports to 0223 * @param flags is a bitmask of NotificationFlag 0224 * @deprecated Since 5.75, use other constructor and call setWidget() explicitly 0225 */ 0226 KNOTIFICATIONS_DEPRECATED_VERSION(5, 75, "Use other constructor and call setWidget() explicitly") 0227 explicit KNotification(const QString &eventId, QWidget *widget, const NotificationFlags &flags = CloseOnTimeout); 0228 #endif 0229 0230 /** 0231 * Create a new notification. 0232 * 0233 * You have to use sendEvent to show the notification. 0234 * 0235 * The pointer is automatically deleted when the event is closed. 0236 * 0237 * The NotificationFlags is set to CloseOnTimeout. 0238 * 0239 * @param eventId is the name of the event 0240 * @since 5.75 0241 */ 0242 inline explicit KNotification(const QString &eventId) 0243 : KNotification(eventId, CloseOnTimeout, nullptr) 0244 { 0245 } 0246 // TODO KF6: remove thic constructor, in favour of other non-deprecated constructor 0247 // It is a helper constructor for software binary compatibility of code which called the 0248 // deprecated constructor so far due to it's second parameter "widget" having had 0249 // a default nullptr value. 0250 0251 /** 0252 * Create a new notification. 0253 * 0254 * You have to use sendEvent to show the notification. 0255 * 0256 * The pointer is automatically deleted when the event is closed. 0257 * 0258 * Make sure you use one of the NotificationFlags CloseOnTimeOut or 0259 * CloseWhenWidgetActivated, if not, 0260 * you have to close the notification yourself. 0261 * 0262 * @since 4.4 0263 * 0264 * @param eventId is the name of the event 0265 * @param flags is a bitmask of NotificationFlag 0266 * @param parent parent object 0267 */ 0268 explicit KNotification(const QString &eventId, const NotificationFlags &flags, QObject *parent = nullptr); 0269 // TODO KF6: pass flags by value instead of reference, set CloseOnTimeout as default value 0270 0271 ~KNotification() override; 0272 0273 /** 0274 * @brief the widget associated to the notification 0275 * 0276 * If the widget is destroyed, the notification will be automatically canceled. 0277 * If the widget is activated, the notification will be automatically closed if the NotificationFlags specify that 0278 * 0279 * When the notification is activated, the widget might be raised. 0280 * Depending on the configuration, the taskbar entry of the window containing the widget may blink. 0281 */ 0282 QWidget *widget() const; 0283 0284 /** 0285 * Set the widget associated to the notification. 0286 * The notification is reparented to the new widget. 0287 * \see widget() 0288 * @param widget the new widget 0289 */ 0290 void setWidget(QWidget *widget); 0291 0292 /** 0293 * @return the name of the event 0294 */ 0295 QString eventId() const; 0296 /** 0297 * Set the event id, if not already passed to the constructor. 0298 * @since 5.88 0299 */ 0300 void setEventId(const QString &eventId); 0301 0302 /** 0303 * @return the notification title 0304 * @see setTitle 0305 * @since 4.3 0306 */ 0307 QString title() const; 0308 0309 /** 0310 * Set the title of the notification popup. 0311 * If no title is set, the application name will be used. 0312 * 0313 * @param title The title of the notification 0314 * @since 4.3 0315 */ 0316 void setTitle(const QString &title); 0317 0318 /** 0319 * @return the notification text 0320 * @see setText 0321 */ 0322 QString text() const; 0323 0324 /** 0325 * Set the notification text that will appear in the popup. 0326 * 0327 * In Plasma workspace, the text is shown in a QML label which uses Text.StyledText, 0328 * ie. it supports a small subset of HTML entities (mostly just formatting tags) 0329 * 0330 * If the notifications server does not advertise "body-markup" capability, 0331 * all HTML tags are stripped before sending it to the server 0332 * 0333 * @param text The text to display in the notification popup 0334 */ 0335 void setText(const QString &text); 0336 0337 /** 0338 * \return the icon shown in the popup 0339 * \see setIconName 0340 * \since 5.4 0341 */ 0342 QString iconName() const; 0343 0344 /** 0345 * Set the icon that will be shown in the popup. 0346 * 0347 * @param icon the icon 0348 * @since 5.4 0349 */ 0350 void setIconName(const QString &icon); 0351 0352 /** 0353 * \return the pixmap shown in the popup 0354 * \see setPixmap 0355 */ 0356 QPixmap pixmap() const; 0357 /** 0358 * Set the pixmap that will be shown in the popup. If you want to use an icon from the icon theme use setIconName instead. 0359 * 0360 * @param pix the pixmap 0361 */ 0362 void setPixmap(const QPixmap &pix); 0363 0364 /** 0365 * @return the default action, or an empty string if not set 0366 * @since 5.31 0367 */ 0368 QString defaultAction() const; 0369 0370 /** 0371 * Set a default action that will be triggered when the notification is 0372 * activated (typically, by clicking on the notification popup). The default 0373 * action should raise a window belonging to the application that sent it. 0374 * 0375 * The string will be used as a label for the action, so ideally it should 0376 * be wrapped in i18n() or tr() calls. 0377 * 0378 * The visual representation of actions depends on the notification server. 0379 * In Plasma and Gnome desktops, the actions are performed by clicking on 0380 * the notification popup, and the label is not presented to the user. 0381 * 0382 * 0383 * @param action Label of the default action. The label might or might not 0384 * be displayed to the user by the notification server, depending on the 0385 * implementation. Passing an empty string disables the default action. 0386 * @since 5.31 0387 */ 0388 void setDefaultAction(const QString &defaultAction); 0389 0390 /** 0391 * @return the list of actions 0392 */ 0393 // KF6: Rename to "additionalActions"? 0394 QStringList actions() const; 0395 0396 /** 0397 * Set the list of actions shown in the popup. The strings passed 0398 * in that QStringList will be used as labels for those actions, 0399 * so ideally they should be wrapped in i18n() or tr() calls. 0400 * In Plasma workspace, these will be shown as buttons inside 0401 * the notification popup. 0402 * 0403 * The visual representation of actions however depends 0404 * on the notification server 0405 * 0406 * @param actions List of strings used as action labels 0407 */ 0408 // KF6: Rename to "setAdditionalActions"? 0409 void setActions(const QStringList &actions); 0410 0411 /** 0412 * @return the inline reply action. 0413 * @since 5.81 0414 */ 0415 KNotificationReplyAction *replyAction() const; 0416 0417 /** 0418 * @brief Add an inline reply action to the notification. 0419 * 0420 * On supported platforms this lets the user type a reply to a notification, 0421 * such as replying to a chat message, from the notification popup, for example: 0422 * 0423 * @code{.cpp} 0424 * KNotification *notification = new KNotification(QStringLiteral("notification")); 0425 * ... 0426 * auto replyAction = std::make_unique<KNotificationReplyAction>(i18nc("@action:button", "Reply")); 0427 * replyAction->setPlaceholderText(i18nc("@info:placeholder", "Reply to Dave...")); 0428 * QObject::connect(replyAction.get(), &KNotificationReplyAction::replied, [](const QString &text) { 0429 * qDebug() << "you replied with" << text; 0430 * }); 0431 * notification->setReplyAction(std::move(replyAction)); 0432 * @endcode 0433 * 0434 * @param replyAction the reply action to set 0435 * @since 5.81 0436 */ 0437 void setReplyAction(std::unique_ptr<KNotificationReplyAction> replyAction); 0438 0439 /** 0440 * @return the list of contexts, see KNotification::Context 0441 */ 0442 ContextList contexts() const; 0443 /** 0444 * set the list of contexts, see KNotification::Context 0445 * 0446 * The list of contexts must be set before calling sendEvent; 0447 */ 0448 void setContexts(const ContextList &contexts); 0449 /** 0450 * append a context at the list of contexts, see KNotification::Context 0451 * @param context the context which is added 0452 */ 0453 void addContext(const Context &context); 0454 /** 0455 * @overload 0456 * @param context_key is the key of the context 0457 * @param context_value is the value of the context 0458 */ 0459 void addContext(const QString &context_key, const QString &context_value); 0460 0461 /** 0462 * @return the notification flags. 0463 */ 0464 NotificationFlags flags() const; 0465 0466 /** 0467 * Set the notification flags. 0468 * These must be set before calling sendEvent() 0469 */ 0470 void setFlags(const NotificationFlags &flags); 0471 0472 /** 0473 * Returns the component name used to determine the location of the configuration file. 0474 * @since 5.88 0475 */ 0476 QString componentName() const; 0477 /** 0478 * The componentData is used to determine the location of the config file. 0479 * 0480 * If no componentName is set, the app name is used by default 0481 * 0482 * @param componentName the new component name 0483 */ 0484 void setComponentName(const QString &componentName); 0485 0486 /** 0487 * URLs associated with this notification 0488 * @since 5.29 0489 */ 0490 QList<QUrl> urls() const; 0491 0492 /** 0493 * Sets URLs associated with this notification 0494 * 0495 * For example, a screenshot application might want to provide the 0496 * URL to the file that was just taken so the notification service 0497 * can show a preview. 0498 * 0499 * @note This feature might not be supported by the user's notification service 0500 * 0501 * @param urls A list of URLs 0502 * @since 5.29 0503 */ 0504 void setUrls(const QList<QUrl> &urls); 0505 0506 /** 0507 * The urgency of the notification. 0508 * @since 5.58 0509 */ 0510 Urgency urgency() const; 0511 0512 /** 0513 * Sets the urgency of the notification. 0514 * 0515 * This defines the importance of the notification. For example, 0516 * a track change in a media player would be a low urgency. 0517 * "You have new mail" would be normal urgency. "Your battery level 0518 * is low" would be a critical urgency. 0519 * 0520 * Use critical notifications with care as they might be shown even 0521 * when giving a presentation or when notifications are turned off. 0522 * 0523 * @param urgency The urgency. 0524 * @since 5.58 0525 */ 0526 void setUrgency(Urgency urgency); 0527 0528 /** 0529 * @internal 0530 * the id given by the notification manager 0531 */ 0532 int id(); 0533 0534 /** 0535 * @internal 0536 * appname used for the D-Bus object 0537 */ 0538 QString appName() const; 0539 0540 /** 0541 * Returns whether this notification object will be automatically deleted after closing. 0542 * @since 5.88 0543 */ 0544 bool isAutoDelete() const; 0545 /** 0546 * Sets whether this notification object will be automatically deleted after closing. 0547 * This is on by default for C++, and off by default for QML. 0548 * @since 5.88 0549 */ 0550 void setAutoDelete(bool autoDelete); 0551 0552 /** 0553 * Returns the activation token to use to activate a window. 0554 * @since 5.90 0555 */ 0556 QString xdgActivationToken() const; 0557 0558 Q_SIGNALS: 0559 #if KNOTIFICATIONS_ENABLE_DEPRECATED_SINCE(5, 76) 0560 /** 0561 * Emitted only when the default activation has occurred 0562 * @deprecated Since 5.67, use defaultActivated() instead 0563 */ 0564 KNOTIFICATIONS_DEPRECATED_VERSION_BELATED(5, 76, 5, 67, "Use defaultActivated() instead") 0565 void activated(); // clazy:exclude=overloaded-signal 0566 #endif 0567 0568 /** 0569 * Emitted when the default action has been activated. 0570 * @since 5.67 0571 */ 0572 void defaultActivated(); 0573 0574 /** 0575 * Emitted when an action has been activated. 0576 * 0577 * The parameter passed by the signal is the index of the action 0578 * in the QStringList set by setActions() call. 0579 * 0580 * @param action will be 0 if the default action was activated, or the index of the action in the actions QStringList 0581 */ 0582 void activated(unsigned int action); // clazy:exclude=overloaded-signal 0583 0584 /** 0585 * Convenience signal that is emitted when the first action is activated. 0586 */ 0587 void action1Activated(); 0588 0589 /** 0590 * \overload 0591 */ 0592 void action2Activated(); 0593 0594 /** 0595 * \overload 0596 */ 0597 void action3Activated(); 0598 0599 /** 0600 * Emitted when the notification is closed. 0601 * 0602 * Can be closed either by the user clicking the close button, 0603 * the timeout running out or when an action was triggered. 0604 */ 0605 void closed(); 0606 0607 /** 0608 * The notification has been ignored 0609 */ 0610 void ignored(); 0611 0612 /** 0613 * Emitted when @c eventId changed. 0614 * @since 5.88 0615 */ 0616 void eventIdChanged(); 0617 /** 0618 * Emitted when @c title changed. 0619 * @since 5.88 0620 */ 0621 void titleChanged(); 0622 /** 0623 * Emitted when @c text changed. 0624 * @since 5.88 0625 */ 0626 void textChanged(); 0627 /** 0628 * Emitted when @c iconName changed. 0629 * @since 5.88 0630 */ 0631 void iconNameChanged(); 0632 /** 0633 * Emitted when @c defaultAction changed. 0634 * @since 5.88 0635 */ 0636 void defaultActionChanged(); 0637 /** 0638 * Emitted when @c actions changed. 0639 * @since 5.88 0640 */ 0641 void actionsChanged(); 0642 /** 0643 * Emitted when @p flags changed. 0644 * @since 5.88 0645 */ 0646 void flagsChanged(); 0647 /** 0648 * Emitted when @p componentName changed. 0649 * @since 5.88 0650 */ 0651 void componentNameChanged(); 0652 /** 0653 * Emitted when @p urls changed. 0654 * @since 5.88 0655 */ 0656 void urlsChanged(); 0657 /** 0658 * Emitted when @p urgency changed. 0659 * @since 5.88 0660 */ 0661 void urgencyChanged(); 0662 /** 0663 * Emitted when @p autoDelete changed. 0664 * @since 5.88 0665 */ 0666 void autoDeleteChanged(); 0667 /** 0668 * Emitted when @p xdgActivationToken changes. 0669 * @since 5.90 0670 */ 0671 void xdgActivationTokenChanged(); 0672 /** 0673 * Emitted when @p hints changes. 0674 * @since 5.101 0675 */ 0676 void hintsChanged(); 0677 0678 public Q_SLOTS: 0679 /** 0680 * @brief Activate the action specified action 0681 * If the action is zero, then the default action is activated 0682 */ 0683 void activate(unsigned int action = 0); 0684 0685 /** 0686 * Close the notification without activating it. 0687 * 0688 * This will delete the notification. 0689 */ 0690 void close(); 0691 0692 #if KNOTIFICATIONS_ENABLE_DEPRECATED_SINCE(5, 67) 0693 /** 0694 * @brief Raise the widget. 0695 * This will change the desktop, activate the window, and the tab if needed. 0696 * @deprecated since 5.67, use QWindow raise + requestActivate instead. 0697 */ 0698 KNOTIFICATIONS_DEPRECATED_VERSION(5, 67, "Use QWindow raise + requestActivate instead") 0699 void raiseWidget(); 0700 #endif 0701 0702 /** 0703 * The notification will automatically be closed if all presentations are finished. 0704 * if you want to show your own presentation in your application, you should use this 0705 * function, so it will not be automatically closed when there is nothing to show. 0706 * 0707 * Don't forget to deref, or the notification may be never closed if there is no timeout. 0708 * 0709 * @see deref 0710 */ 0711 void ref(); 0712 /** 0713 * Remove a reference made with ref(). If the ref counter hits zero, 0714 * the notification will be closed and deleted. 0715 * 0716 * @see ref 0717 */ 0718 void deref(); 0719 0720 /** 0721 * Send the notification to the server. 0722 * 0723 * This will cause all the configured plugins to execute their actions on this notification 0724 * (eg. a sound will play, a popup will show, a command will be executed etc). 0725 */ 0726 void sendEvent(); 0727 0728 /** 0729 * @internal 0730 * update the texts, the icon, and the actions of one existing notification 0731 */ 0732 void update(); 0733 0734 /** 0735 * @since 5.57 0736 * Adds a custom hint to the notification. Those are key-value pairs that can be interpreted by the respective notification backend to trigger additional, 0737 * non-standard features. 0738 * @param hint the hint's key 0739 * @param value the hint's value 0740 */ 0741 Q_INVOKABLE void setHint(const QString &hint, const QVariant &value); 0742 0743 /** 0744 * @since 5.57 0745 * Returns the custom hints set by setHint() 0746 */ 0747 QVariantMap hints() const; 0748 0749 /** 0750 * @since 5.101 0751 * Set custom hints on the notification. 0752 * @sa setHint 0753 */ 0754 void setHints(const QVariantMap &hints); 0755 0756 private: 0757 friend class KNotificationManager; 0758 struct Private; 0759 std::unique_ptr<Private> const d; 0760 0761 protected: 0762 /** 0763 * reimplemented for internal reasons 0764 */ 0765 bool eventFilter(QObject *watched, QEvent *event) override; 0766 static QString standardEventToEventId(StandardEvent event); 0767 static QString standardEventToIconName(StandardEvent event); 0768 0769 public: 0770 /** 0771 * @brief emit an event 0772 * 0773 * This method creates the KNotification, setting every parameter, and fire the event. 0774 * You don't need to call sendEvent 0775 * 0776 * A popup may be displayed or a sound may be played, depending the config. 0777 * 0778 * @return a KNotification . You may use that pointer to connect some signals or slot. 0779 * the pointer is automatically deleted when the event is closed. 0780 * 0781 * Make sure you use one of the CloseOnTimeOut or CloseWhenWidgetActivated, if not, 0782 * you have to close yourself the notification. 0783 * 0784 * @param eventId is the name of the event 0785 * @param title is title of the notification to show in the popup. 0786 * @param text is the text of the notification to show in the popup. 0787 * @param pixmap is a picture which may be shown in the popup. 0788 * @param widget is a widget where the notification reports to 0789 * @param flags is a bitmask of NotificationFlag 0790 * @param componentName used to determine the location of the config file. by default, appname is used 0791 * @since 4.4 0792 */ 0793 static KNotification *event(const QString &eventId, 0794 const QString &title, 0795 const QString &text, 0796 const QPixmap &pixmap = QPixmap(), 0797 QWidget *widget = nullptr, 0798 const NotificationFlags &flags = CloseOnTimeout, 0799 const QString &componentName = QString()); 0800 0801 /** 0802 * @brief emit a standard event 0803 * 0804 * @overload 0805 * 0806 * This will emit a standard event 0807 * 0808 * @param eventId is the name of the event 0809 * @param text is the text of the notification to show in the popup. 0810 * @param pixmap is a picture which may be shown in the popup. 0811 * @param widget is a widget where the notification reports to 0812 * @param flags is a bitmask of NotificationFlag 0813 * @param componentName used to determine the location of the config file. by default, plasma_workspace is used 0814 */ 0815 static KNotification *event(const QString &eventId, 0816 const QString &text = QString(), 0817 const QPixmap &pixmap = QPixmap(), 0818 QWidget *widget = nullptr, 0819 const NotificationFlags &flags = CloseOnTimeout, 0820 const QString &componentName = QString()); 0821 0822 /** 0823 * @brief emit a standard event 0824 * 0825 * @overload 0826 * 0827 * This will emit a standard event 0828 * 0829 * @param eventId is the name of the event 0830 * @param text is the text of the notification to show in the popup 0831 * @param pixmap is a picture which may be shown in the popup 0832 * @param widget is a widget where the notification reports to 0833 * @param flags is a bitmask of NotificationFlag 0834 */ 0835 static KNotification *event(StandardEvent eventId, 0836 const QString &text = QString(), 0837 const QPixmap &pixmap = QPixmap(), 0838 QWidget *widget = nullptr, 0839 const NotificationFlags &flags = CloseOnTimeout); 0840 0841 /** 0842 * @brief emit a standard event 0843 * 0844 * @overload 0845 * 0846 * This will emit a standard event 0847 * 0848 * @param eventId is the name of the event 0849 * @param title is title of the notification to show in the popup. 0850 * @param text is the text of the notification to show in the popup 0851 * @param pixmap is a picture which may be shown in the popup 0852 * @param widget is a widget where the notification reports to 0853 * @param flags is a bitmask of NotificationFlag 0854 * @since 4.4 0855 */ 0856 static KNotification *event(StandardEvent eventId, 0857 const QString &title, 0858 const QString &text, 0859 const QPixmap &pixmap, 0860 QWidget *widget = nullptr, 0861 const NotificationFlags &flags = CloseOnTimeout); 0862 0863 /** 0864 * @brief emit a standard event with the possibility of setting an icon by icon name 0865 * 0866 * @overload 0867 * 0868 * This will emit a standard event 0869 * 0870 * @param eventId is the name of the event 0871 * @param title is title of the notification to show in the popup. 0872 * @param text is the text of the notification to show in the popup 0873 * @param iconName a Freedesktop compatible icon name to be shown in the popup 0874 * @param widget is a widget where the notification reports to 0875 * @param flags is a bitmask of NotificationFlag 0876 * @param componentName used to determine the location of the config file. by default, plasma_workspace is used 0877 * @since 5.4 0878 */ 0879 static KNotification *event(const QString &eventId, 0880 const QString &title, 0881 const QString &text, 0882 const QString &iconName, 0883 QWidget *widget = nullptr, 0884 const NotificationFlags &flags = CloseOnTimeout, 0885 const QString &componentName = QString()); 0886 0887 /** 0888 * @brief emit a standard event with the possibility of setting an icon by icon name 0889 * 0890 * @overload 0891 * 0892 * This will emit a standard event with a custom icon 0893 * 0894 * @param eventId the type of the standard (not app-defined) event 0895 * @param title is title of the notification to show in the popup. 0896 * @param text is the text of the notification to show in the popup 0897 * @param iconName a Freedesktop compatible icon name to be shown in the popup 0898 * @param widget is a widget where the notification reports to 0899 * @param flags is a bitmask of NotificationFlag 0900 * @since 5.9 0901 */ 0902 static KNotification *event(StandardEvent eventId, 0903 const QString &title, 0904 const QString &text, 0905 const QString &iconName, 0906 QWidget *widget = nullptr, 0907 const NotificationFlags &flags = CloseOnTimeout); 0908 0909 /** 0910 * @brief emit a standard event 0911 * 0912 * @overload 0913 * 0914 * This will emit a standard event with its standard icon 0915 * 0916 * @param eventId the type of the standard (not app-defined) event 0917 * @param title is title of the notification to show in the popup. 0918 * @param text is the text of the notification to show in the popup 0919 * @param widget is a widget where the notification reports to 0920 * @param flags is a bitmask of NotificationFlag 0921 * @since 5.9 0922 */ 0923 static KNotification * 0924 event(StandardEvent eventId, const QString &title, const QString &text, QWidget *widget = nullptr, const NotificationFlags &flags = CloseOnTimeout); 0925 0926 /** 0927 * This is a simple substitution for QApplication::beep() 0928 * 0929 * @param reason a short text explaining what has happened (may be empty) 0930 * @param widget the widget the notification refers to 0931 */ 0932 static void beep(const QString &reason = QString(), QWidget *widget = nullptr); 0933 0934 // prevent warning 0935 using QObject::event; 0936 }; 0937 0938 Q_DECLARE_OPERATORS_FOR_FLAGS(KNotification::NotificationFlags) 0939 0940 #endif