File indexing completed on 2024-12-08 04:34:37
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "notificationwidget.h" 0007 #include <KNotification> 0008 #include <KNotificationReplyAction> 0009 #include <QDebug> 0010 #include <QHBoxLayout> 0011 #include <QLineEdit> 0012 #include <QPushButton> 0013 0014 NotificationWidget::NotificationWidget(QWidget *parent) 0015 : QWidget(parent) 0016 , mLineEdit(new QLineEdit(this)) 0017 { 0018 auto mainLayout = new QHBoxLayout(this); 0019 mainLayout->addWidget(mLineEdit); 0020 0021 auto sendNotification = new QPushButton(QStringLiteral("Send"), this); 0022 mainLayout->addWidget(sendNotification); 0023 0024 connect(sendNotification, &QPushButton::clicked, this, &NotificationWidget::slotSendNotification); 0025 } 0026 0027 NotificationWidget::~NotificationWidget() = default; 0028 0029 void NotificationWidget::slotSendNotification() 0030 { 0031 const QString str = mLineEdit->text(); 0032 if (!str.isEmpty()) { 0033 auto notification = new KNotification(QStringLiteral("new-notification"), KNotification::CloseOnTimeout); 0034 notification->setTitle(QStringLiteral("test")); 0035 notification->setText(str); 0036 auto action = notification->addDefaultAction(QStringLiteral("Open Channel")); 0037 connect(action, &KNotificationAction::activated, this, []() { 0038 qDebug() << " default Activated !!!!!!"; 0039 }); 0040 connect(notification, &KNotification::closed, this, []() { 0041 qDebug() << " CLOSED!!!!!!!!!!!!!!!!!!!!!!!!!"; 0042 }); 0043 0044 std::unique_ptr<KNotificationReplyAction> replyAction(new KNotificationReplyAction(QStringLiteral("Reply"))); 0045 replyAction->setPlaceholderText(QStringLiteral("Reply...")); 0046 QObject::connect(replyAction.get(), &KNotificationReplyAction::replied, this, [](const QString &text) { 0047 qDebug() << " reply " << text; 0048 }); 0049 notification->setReplyAction(std::move(replyAction)); 0050 notification->sendEvent(); 0051 } 0052 } 0053 0054 #include "moc_notificationwidget.cpp"