diff --git a/plugins/notifications/CMakeLists.txt b/plugins/notifications/CMakeLists.txt index a9598bb8..a3932a4b 100644 --- a/plugins/notifications/CMakeLists.txt +++ b/plugins/notifications/CMakeLists.txt @@ -1,17 +1,18 @@ find_package(KF5 REQUIRED COMPONENTS Notifications KCMUtils I18n IconThemes Config) set(kdeconnect_notifications_SRCS notification.cpp notificationsplugin.cpp notificationsdbusinterface.cpp + sendreplydialog.cpp ) kdeconnect_add_plugin(kdeconnect_notifications JSON kdeconnect_notifications.json SOURCES ${kdeconnect_notifications_SRCS}) target_link_libraries(kdeconnect_notifications kdeconnectcore Qt5::DBus KF5::Notifications KF5::I18n KF5::IconThemes ) diff --git a/plugins/notifications/kdeconnect_notifications.json b/plugins/notifications/kdeconnect_notifications.json index abae5c31..52832853 100644 --- a/plugins/notifications/kdeconnect_notifications.json +++ b/plugins/notifications/kdeconnect_notifications.json @@ -1,91 +1,92 @@ { "Encoding": "UTF-8", "KPlugin": { "Authors": [ { "Email": "albertvaka@gmail.com", "Name": "Albert Vaca", "Name[sr@ijekavian]": "Алберт Вака Синтора", "Name[sr@ijekavianlatin]": "Albert Vaka Sintora", "Name[sr@latin]": "Albert Vaka Sintora", "Name[sr]": "Алберт Вака Синтора", "Name[x-test]": "xxAlbert Vacaxx" } ], "Description": "Show device's notifications on this computer and keep them in sync", "Description[ar]": "أظهر إخطارات الجهاز على هذا الحاسوب وأبقها متزامنة", "Description[ca@valencia]": "Mostra les notificacions del dispositiu a l'ordinador i les manté sincronitzades", "Description[ca]": "Mostra les notificacions del dispositiu a l'ordinador i les manté sincronitzades", "Description[cs]": "Zobrazit upozornění telefonu v počítači a udržovat je synchronizovaná", "Description[da]": "Vis enhedens bekendtgørelser på denne computer og hold dem synkroniseret", "Description[de]": "Benachrichtigungen des Geräts auf diesem Rechner anzeigen und abgleichen", "Description[el]": "Εμφάνιση ειδοποιήσεων συσκευής στον υπολογιστή αυτόν και συγχρονισμός τους", "Description[es]": "Mostrar notificaciones del dispositivo en este equipo y mantenerlas en sincronía", "Description[et]": "Seadme märguannete näitamine arvutis ja nende sünkroonis hoidmine", "Description[fi]": "Näytä laitteen ilmoitukset tällä tietokoneella ja pidä ne ajan tasalla", "Description[gl]": "Mostrar as notificacións do dispositivo neste computador e mantelas sincronizadas.", "Description[it]": "Mostra le notifiche del telefono sul tuo computer e tienile sincronizzate", "Description[ko]": "휴대폰 알림을 컴퓨터에 표시하고 동기화하기", "Description[nl]": "Apparaatmeldingen op deze computer tonen en ze gesynchroniseerd houden", "Description[nn]": "Vis telefonvarslingar på datamaskina og hald dei synkronisert", "Description[pl]": "Pokaż powiadomienia urządzenia na swoim komputerze i synchronizuj je", "Description[pt]": "Mostrar as notificações do dispositivo neste computador e mantê-las sincronizadas", "Description[pt_BR]": "Mostra as notificações do aparelho neste computador e as mantém sincronizadas", "Description[ru]": "Показ уведомлений с устройства на компьютере и их синхронизация", "Description[sk]": "Zobraziť oznámenia telefónu na vašom počítači a udržať ich synchronizované", "Description[sr@ijekavian]": "Приказује обавештења са уређаја на рачунару и одржава их ажурним", "Description[sr@ijekavianlatin]": "Prikazuje obaveštenja sa uređaja na računaru i održava ih ažurnim", "Description[sr@latin]": "Prikazuje obaveštenja sa uređaja na računaru i održava ih ažurnim", "Description[sr]": "Приказује обавештења са уређаја на рачунару и одржава их ажурним", "Description[sv]": "Visa enhetens underrättelser på datorn och håll dem synkroniserade", "Description[uk]": "Показ сповіщень з пристрою на цьому комп’ютері та підтримання синхронізації даних сповіщень", "Description[x-test]": "xxShow device's notifications on this computer and keep them in syncxx", "Description[zh_CN]": "在电脑显示手机通知并保持同步", "Description[zh_TW]": "在電腦上顯示裝置通知並且保持同步", "EnabledByDefault": true, "Icon": "preferences-desktop-notification", "Id": "kdeconnect_notifications", "License": "GPL", "Name": "Receive notifications", "Name[ar]": "استقبل الإخطارات", "Name[ca@valencia]": "Recepció de les notificacions", "Name[ca]": "Recepció de les notificacions", "Name[cs]": "Přijímat oznámení", "Name[da]": "Modtag bekendtgørelser", "Name[de]": "Benachrichtigungen empfangen", "Name[el]": "Λήψη ειδοποιήσεων", "Name[es]": "Recibir notificaciones", "Name[et]": "Märguannete vastuvõtmine", "Name[fi]": "Vastaanota ilmoituksia", "Name[gl]": "Recibir notificacións", "Name[it]": "Ricevi notifiche", "Name[ko]": "알림 받기", "Name[nl]": "Meldingen ontvangen", "Name[nn]": "Få varslingar", "Name[pl]": "Otrzymuj powiadomienia", "Name[pt]": "Receber as notificações", "Name[pt_BR]": "Receber notificações", "Name[ru]": "Получение уведомлений", "Name[sk]": "Prijať upozornenia", "Name[sr@ijekavian]": "Пријем обавештења", "Name[sr@ijekavianlatin]": "Prijem obaveštenja", "Name[sr@latin]": "Prijem obaveštenja", "Name[sr]": "Пријем обавештења", "Name[sv]": "Ta emot underrättelser", "Name[uk]": "Отримати сповіщення", "Name[x-test]": "xxReceive notificationsxx", "Name[zh_CN]": "接收通知", "Name[zh_TW]": "收到通知", "ServiceTypes": [ "KdeConnect/Plugin" ], "Version": "0.1", "Website": "http://albertvaka.wordpress.com" }, "X-KdeConnect-OutgoingPackageType": [ - "kdeconnect.notification.request" + "kdeconnect.notification.request", + "kdeconnect.notification.reply" ], "X-KdeConnect-SupportedPackageType": [ "kdeconnect.notification" ] } diff --git a/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp index 6b82538d..df1b6df6 100644 --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -1,142 +1,149 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "notification.h" #include #include #include #include #include +#include #include Notification::Notification(const NetworkPackage& np, QObject* parent) : QObject(parent) { mImagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect")); mImagesDir.mkpath(mImagesDir.absolutePath()); mClosed = false; parseNetworkPackage(np); createKNotification(false, np); } Notification::~Notification() { } void Notification::dismiss() { if (mDismissable) { Q_EMIT dismissRequested(mInternalId); } } void Notification::show() { if (!mSilent) { mClosed = false; mNotification->sendEvent(); } } void Notification::applyIconAndShow() { if (!mSilent) { QPixmap icon(mIconPath, "PNG"); mNotification->setPixmap(icon); show(); } } void Notification::update(const NetworkPackage &np) { parseNetworkPackage(np); createKNotification(!mClosed, np); } KNotification* Notification::createKNotification(bool update, const NetworkPackage &np) { if (!update) { mNotification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); mNotification->setComponentName(QStringLiteral("kdeconnect")); } QString escapedTitle = mTitle.toHtmlEscaped(); QString escapedText = mText.toHtmlEscaped(); QString escapedTicker = mTicker.toHtmlEscaped(); mNotification->setTitle(mAppName.toHtmlEscaped()); if (mTitle.isEmpty() && mText.isEmpty()) { mNotification->setText(escapedTicker); } else if (mAppName==mTitle) { mNotification->setText(escapedText); } else if (mTitle.isEmpty()){ mNotification->setText(escapedText); } else if (mText.isEmpty()){ mNotification->setText(escapedTitle); } else { mNotification->setText(escapedTitle+": "+escapedText); } if (!mHasIcon) { mNotification->setIconName(QStringLiteral("preferences-desktop-notification")); show(); } else { QString filename = mPayloadHash; if (filename.isEmpty()) { mHasIcon = false; } else { mIconPath = mImagesDir.absoluteFilePath(filename); QUrl destinationUrl(mIconPath); FileTransferJob* job = np.createPayloadTransferJob(destinationUrl); job->start(); connect(job, &FileTransferJob::result, this, &Notification::applyIconAndShow); } } + + if(!mRequestReplyId.isEmpty()) { + mNotification->setActions( QStringList(i18n("Reply")) ); + connect(mNotification, &KNotification::action1Activated, this, &Notification::replyRequested); + } connect(mNotification, &KNotification::closed, this, &Notification::closed); return mNotification; } void Notification::closed() { mClosed = true; } void Notification::parseNetworkPackage(const NetworkPackage &np) { mInternalId = np.get(QStringLiteral("id")); mAppName = np.get(QStringLiteral("appName")); mTicker = np.get(QStringLiteral("ticker")); mTitle = np.get(QStringLiteral("title")); mText = np.get(QStringLiteral("text")); mDismissable = np.get(QStringLiteral("isClearable")); mHasIcon = np.hasPayload(); mSilent = np.get(QStringLiteral("silent")); mPayloadHash = np.get(QStringLiteral("payloadHash")); + mRequestReplyId = np.get(QStringLiteral("requestReplyId"), QString()); } diff --git a/plugins/notifications/notification.h b/plugins/notifications/notification.h index 12ebf268..967f4630 100644 --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -1,89 +1,93 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef NOTIFICATION_H #define NOTIFICATION_H #include #include #include #include #include class Notification : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications.notification") Q_PROPERTY(QString internalId READ internalId) Q_PROPERTY(QString appName READ appName) Q_PROPERTY(QString ticker READ ticker) Q_PROPERTY(QString title READ title) Q_PROPERTY(QString text READ text) Q_PROPERTY(QString iconPath READ iconPath) Q_PROPERTY(bool dismissable READ dismissable) Q_PROPERTY(bool hasIcon READ hasIcon) Q_PROPERTY(bool silent READ silent) + Q_PROPERTY(QString replyId READ replyId) public: Notification(const NetworkPackage& np, QObject* parent); ~Notification() override; QString internalId() const { return mInternalId; } QString appName() const { return mAppName; } QString ticker() const { return mTicker; } QString title() const { return mTitle; } QString text() const { return mText; } QString iconPath() const { return mIconPath; } bool dismissable() const { return mDismissable; } + QString replyId() const { return mRequestReplyId; } bool hasIcon() const { return mHasIcon; } void show(); bool silent() const { return mSilent; } void update(const NetworkPackage &np); KNotification* createKNotification(bool update, const NetworkPackage &np); public Q_SLOTS: Q_SCRIPTABLE void dismiss(); Q_SCRIPTABLE void applyIconAndShow(); void closed(); Q_SIGNALS: void dismissRequested(const QString& mInternalId); + void replyRequested(); private: QString mInternalId; QString mAppName; QString mTicker; QString mTitle; QString mText; QString mIconPath; + QString mRequestReplyId; bool mDismissable; bool mHasIcon; KNotification* mNotification; QDir mImagesDir; bool mSilent; bool mClosed; QString mPayloadHash; void parseNetworkPackage(const NetworkPackage& np); }; #endif diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp index 69b08ac2..3654551c 100644 --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -1,152 +1,176 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "notificationsdbusinterface.h" #include "notification_debug.h" #include "notification.h" #include + #include #include #include "notificationsplugin.h" +#include "sendreplydialog.h" NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin) : QDBusAbstractAdaptor(const_cast(plugin->device())) , mDevice(plugin->device()) , mPlugin(plugin) , mLastId(0) { } NotificationsDbusInterface::~NotificationsDbusInterface() { qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface"; } void NotificationsDbusInterface::clearNotifications() { qDeleteAll(mNotifications); mNotifications.clear(); Q_EMIT allNotificationsRemoved(); } QStringList NotificationsDbusInterface::activeNotifications() { return mNotifications.keys(); } void NotificationsDbusInterface::processPackage(const NetworkPackage& np) { if (np.get(QStringLiteral("isCancel"))) { QString id = np.get(QStringLiteral("id")); // cut off kdeconnect-android's prefix if there: if (id.startsWith(QLatin1String("org.kde.kdeconnect_tp::"))) id = id.mid(id.indexOf(QLatin1String("::")) + 2); removeNotification(id); } else if (np.get(QStringLiteral("isRequest"))) { Q_FOREACH (const auto& n, mNotifications) { NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST, { {"id", n->internalId()}, {"appName", n->appName()}, {"ticker", n->ticker()}, {"isClearable", n->dismissable()}, {"requestAnswer", true} }); mPlugin->sendPackage(np); } } else if(np.get(QStringLiteral("requestAnswer"), false)) { } else { QString id = np.get(QStringLiteral("id")); if (!mInternalIdToPublicId.contains(id)) { Notification* noti = new Notification(np, this); addNotification(noti); } else { QString pubId = mInternalIdToPublicId[id]; mNotifications[pubId]->update(np); } } } void NotificationsDbusInterface::addNotification(Notification* noti) { const QString& internalId = noti->internalId(); if (mInternalIdToPublicId.contains(internalId)) { removeNotification(internalId); } //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; connect(noti, &Notification::dismissRequested, this, &NotificationsDbusInterface::dismissRequested); + + connect(noti, &Notification::replyRequested, this, [this,noti]{ + replyRequested(noti); + }); const QString& publicId = newId(); mNotifications[publicId] = noti; mInternalIdToPublicId[internalId] = publicId; QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); Q_EMIT notificationPosted(publicId); } void NotificationsDbusInterface::removeNotification(const QString& internalId) { //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId; if (!mInternalIdToPublicId.contains(internalId)) { qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId; return; } QString publicId = mInternalIdToPublicId.take(internalId); Notification* noti = mNotifications.take(publicId); if (!noti) { qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId; return; } //Deleting the notification will unregister it automatically //QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); noti->deleteLater(); Q_EMIT notificationRemoved(publicId); } void NotificationsDbusInterface::dismissRequested(const QString& internalId) { NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST); np.set(QStringLiteral("cancel"), internalId); mPlugin->sendPackage(np); //Workaround: we erase notifications without waiting a repsonse from the //phone because we won't receive a response if we are out of sync and this //notification no longer exists. Ideally, each time we reach the phone //after some time disconnected we should re-sync all the notifications. removeNotification(internalId); } +void NotificationsDbusInterface::replyRequested(Notification* noti) +{ + QString replyId = noti->replyId(); + QString appName = noti->appName(); + QString originalMessage = noti->ticker(); + SendReplyDialog* dialog = new SendReplyDialog(originalMessage, replyId, appName); + connect(dialog, &SendReplyDialog::sendReply, this, &NotificationsDbusInterface::sendReply); + dialog->show(); +} + +void NotificationsDbusInterface::sendReply(const QString& replyId, const QString& message) +{ + NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REPLY); + np.set(QStringLiteral("requestReplyId"), replyId); + np.set(QStringLiteral("message"), message); + mPlugin->sendPackage(np); +} + QString NotificationsDbusInterface::newId() { return QString::number(++mLastId); } diff --git a/plugins/notifications/notificationsdbusinterface.h b/plugins/notifications/notificationsdbusinterface.h index 1c92ba17..f320a305 100644 --- a/plugins/notifications/notificationsdbusinterface.h +++ b/plugins/notifications/notificationsdbusinterface.h @@ -1,70 +1,72 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef NOTIFICATIONSDBUSINTERFACE_H #define NOTIFICATIONSDBUSINTERFACE_H #include #include #include #include #include #include "notification.h" class KdeConnectPlugin; class Device; class NotificationsDbusInterface : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications") public: explicit NotificationsDbusInterface(KdeConnectPlugin* plugin); ~NotificationsDbusInterface() override; void processPackage(const NetworkPackage& np); void clearNotifications(); void dismissRequested(const QString& notification); + void replyRequested(Notification* noti); void addNotification(Notification* noti); public Q_SLOTS: Q_SCRIPTABLE QStringList activeNotifications(); + Q_SCRIPTABLE void sendReply(const QString& replyId, const QString& message); Q_SIGNALS: Q_SCRIPTABLE void notificationPosted(const QString& publicId); Q_SCRIPTABLE void notificationRemoved(const QString& publicId); Q_SCRIPTABLE void allNotificationsRemoved(); private /*methods*/: void removeNotification(const QString& internalId); QString newId(); //Generates successive identifitiers to use as public ids private /*attributes*/: const Device* mDevice; KdeConnectPlugin* mPlugin; QHash mNotifications; QHash mInternalIdToPublicId; int mLastId; }; #endif diff --git a/plugins/notifications/notificationsplugin.h b/plugins/notifications/notificationsplugin.h index 13731f23..5f2b101c 100644 --- a/plugins/notifications/notificationsplugin.h +++ b/plugins/notifications/notificationsplugin.h @@ -1,56 +1,57 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef NOTIFICATIONSPLUGIN_H #define NOTIFICATIONSPLUGIN_H #include #include #define PACKAGE_TYPE_NOTIFICATION_REQUEST QStringLiteral("kdeconnect.notification.request") +#define PACKAGE_TYPE_NOTIFICATION_REPLY QStringLiteral("kdeconnect.notification.reply") /* * This class is just a proxy for NotificationsDbusInterface * because it can not inherit from QDBusAbstractAdaptor and * KdeConnectPlugin at the same time (both are QObject) */ class NotificationsDbusInterface; class NotificationsListener; class NotificationsPlugin : public KdeConnectPlugin { Q_OBJECT public: explicit NotificationsPlugin(QObject *parent, const QVariantList &args); ~NotificationsPlugin() override; bool receivePackage(const NetworkPackage& np) override; void connected() override; protected: NotificationsDbusInterface* notificationsDbusInterface; NotificationsListener* notificationsListener; }; #endif diff --git a/plugins/notifications/sendreplydialog.cpp b/plugins/notifications/sendreplydialog.cpp new file mode 100644 index 00000000..e40c2170 --- /dev/null +++ b/plugins/notifications/sendreplydialog.cpp @@ -0,0 +1,64 @@ +/** + * Copyright 2015 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sendreplydialog.h" + +#include +#include +#include +#include + +#include + +SendReplyDialog::SendReplyDialog(const QString& originalMessage, const QString& replyId, const QString& topicName, QWidget* parent) + : QDialog(parent) + , mReplyId(replyId) +{ + QVBoxLayout* layout = new QVBoxLayout; + + QTextEdit* textView = new QTextEdit(this); + textView->setReadOnly(true); + textView->setText(topicName + ": \n" + originalMessage); + layout->addWidget(textView); + + mTextEdit = new QTextEdit(this); + layout->addWidget(mTextEdit); + + QPushButton* sendButton = new QPushButton(i18n("Send"), this); + connect(sendButton, &QAbstractButton::clicked, this, &SendReplyDialog::sendButtonClicked); + layout->addWidget(sendButton); + + setLayout(layout); + setWindowTitle(topicName); + setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect"))); + setAttribute(Qt::WA_DeleteOnClose); +} + + +void SendReplyDialog::sendButtonClicked() +{ + Q_EMIT sendReply(mReplyId, mTextEdit->toPlainText()); + close(); +} + +QSize SendReplyDialog::sizeHint() const +{ + return QSize(512, 64); +} diff --git a/plugins/notifications/sendreplydialog.h b/plugins/notifications/sendreplydialog.h new file mode 100644 index 00000000..8540d5a5 --- /dev/null +++ b/plugins/notifications/sendreplydialog.h @@ -0,0 +1,50 @@ +/** + * Copyright 2015 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SENDREPLYDIALOG_H +#define SENDREPLYDIALOG_H + +#include +#include + +class QTextEdit; +class QLineEdit; +class QPushButton; + +class SendReplyDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SendReplyDialog(const QString& originalMessage, const QString& replyId, const QString& topicName, QWidget *parent = nullptr); + QSize sizeHint() const override; + +private Q_SLOTS: + void sendButtonClicked(); + +Q_SIGNALS: + void sendReply(const QString& replyId, const QString& messageBody); + +private: + QString mReplyId; + QTextEdit *mTextEdit; +}; + +#endif