diff --git a/plugins/telephony/CMakeLists.txt b/plugins/telephony/CMakeLists.txt index 7c8958c1b..e52da2958 100644 --- a/plugins/telephony/CMakeLists.txt +++ b/plugins/telephony/CMakeLists.txt @@ -2,6 +2,7 @@ find_package(KF5 REQUIRED COMPONENTS Notifications) set(kdeconnect_telephony_SRCS telephonyplugin.cpp + sendsmsdialog.cpp ) kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES ${kdeconnect_telephony_SRCS}) diff --git a/plugins/telephony/sendsmsdialog.cpp b/plugins/telephony/sendsmsdialog.cpp new file mode 100644 index 000000000..f0be3235c --- /dev/null +++ b/plugins/telephony/sendsmsdialog.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 "sendsmsdialog.h" + +#include +#include +#include +#include + +#include + +SendSmsDialog::SendSmsDialog(const QString& originalMessage, const QString& phoneNumber, const QString& contactName, QWidget* parent) + : QDialog(parent) + , mPhoneNumber(phoneNumber) +{ + QVBoxLayout* layout = new QVBoxLayout; + + QTextEdit* textView = new QTextEdit(this); + textView->setReadOnly(true); + textView->setText(contactName + ": \n" + originalMessage); + layout->addWidget(textView); + + mTextEdit = new QTextEdit(this); + layout->addWidget(mTextEdit); + + QPushButton* sendButton = new QPushButton(i18n("Send"), this); + connect(sendButton, SIGNAL(clicked(bool)), SLOT(sendButtonClicked())); + layout->addWidget(sendButton); + + setLayout(layout); + setWindowTitle(contactName); + setWindowIcon(QIcon::fromTheme("kdeconnect")); + setAttribute(Qt::WA_DeleteOnClose); +} + + +void SendSmsDialog::sendButtonClicked() +{ + emit sendSms(mPhoneNumber, mTextEdit->toPlainText()); + close(); +} + +QSize SendSmsDialog::sizeHint() const +{ + return QSize(512, 64); +} diff --git a/plugins/telephony/sendsmsdialog.h b/plugins/telephony/sendsmsdialog.h new file mode 100644 index 000000000..90acb1ac2 --- /dev/null +++ b/plugins/telephony/sendsmsdialog.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 SENDSMSDIALOG_H +#define SENDSMSDIALOG_H + +#include +#include + +class QTextEdit; +class QLineEdit; +class QPushButton; + +class SendSmsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SendSmsDialog(const QString& originalMessage, const QString& phoneNumber, const QString& contactName, QWidget *parent = 0); + virtual QSize sizeHint() const; + +private Q_SLOTS: + void sendButtonClicked(); + +Q_SIGNALS: + void sendSms(const QString& phoneNumber, const QString& messageBody); + +private: + QString mPhoneNumber; + QTextEdit *mTextEdit; +}; + +#endif diff --git a/plugins/telephony/telephonyplugin.cpp b/plugins/telephony/telephonyplugin.cpp index 157121ad8..d4f8793bd 100644 --- a/plugins/telephony/telephonyplugin.cpp +++ b/plugins/telephony/telephonyplugin.cpp @@ -20,13 +20,14 @@ #include "telephonyplugin.h" +#include "sendsmsdialog.h" + #include #include #include #include - K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_telephony.json", registerPlugin< TelephonyPlugin >(); ) Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony") @@ -39,29 +40,29 @@ TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args) KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np) { - const QString event = np.get("event"); const QString phoneNumber = np.get("phoneNumber", i18n("unknown number")); + const QString contactName = np.get("contactName", phoneNumber); QString content, type, icon; - KNotification::NotificationFlags flags = KNotification::CloseOnTimeout; + KNotification::NotificationFlags flags = KNotification::CloseOnTimeout | KNotification::CloseWhenWidgetActivated; const QString title = device()->name(); if (event == "ringing") { type = QStringLiteral("callReceived"); icon = QStringLiteral("call-start"); - content = i18n("Incoming call from %1", phoneNumber); + content = i18n("Incoming call from %1", contactName); } else if (event == "missedCall") { type = QStringLiteral("missedCall"); icon = QStringLiteral("call-start"); - content = i18n("Missed call from %1", phoneNumber); + content = i18n("Missed call from %1", contactName); flags |= KNotification::Persistent; } else if (event == "sms") { type = QStringLiteral("smsReceived"); icon = QStringLiteral("mail-receive"); QString messageBody = np.get("messageBody",""); - content = i18n("SMS from %1
%2", phoneNumber, messageBody); + content = i18n("SMS from %1
%2", contactName, messageBody); flags |= KNotification::Persistent; } else if (event == "talking") { return NULL; @@ -86,6 +87,12 @@ KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np) if (event == QLatin1String("ringing")) { notification->setActions( QStringList(i18n("Mute Call")) ); connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePackage); + } else if (event == QLatin1String("sms")) { + notification->setActions( QStringList(i18n("Reply")) ); + notification->setProperty("phoneNumber", phoneNumber); + notification->setProperty("contactName", contactName); + notification->setProperty("originalMessage", np.get("messageBody","")); + connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::showSendSmsDialog); } return notification; @@ -96,15 +103,11 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np) { if (np.get("isCancel")) { - //It would be awesome to remove the old notification from the system tray here, but there is no way to do it :( - //Now I realize why at the end of the day I have hundreds of notifications from facebook messages that I HAVE ALREADY READ, - //...it's just because the telepathy client has no way to remove them! even when it knows that I have read those messages! + //TODO: Clear the old notification } else { - KNotification* n = createNotification(np); if (n != NULL) n->sendEvent(); - } return true; @@ -118,4 +121,23 @@ void TelephonyPlugin::sendMutePackage() sendPackage(package); } +void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody) +{ + NetworkPackage np(PACKAGE_TYPE_TELEPHONY); + np.set("sendSms", true); + np.set("phoneNumber", phoneNumber); + np.set("messageBody", messageBody); + sendPackage(np); +} + +void TelephonyPlugin::showSendSmsDialog() +{ + QString phoneNumber = sender()->property("phoneNumber").toString(); + QString contactName = sender()->property("contactName").toString(); + QString originalMessage = sender()->property("originalMessage").toString(); + SendSmsDialog* dialog = new SendSmsDialog(originalMessage, phoneNumber, contactName); + connect(dialog, SIGNAL(sendSms(QString,QString)), this, SLOT(sendSms(QString,QString))); + dialog->show(); +} + #include "telephonyplugin.moc" diff --git a/plugins/telephony/telephonyplugin.h b/plugins/telephony/telephonyplugin.h index ce74e9e2f..520b99151 100644 --- a/plugins/telephony/telephonyplugin.h +++ b/plugins/telephony/telephonyplugin.h @@ -44,6 +44,10 @@ public Q_SLOTS: virtual void connected() { } void sendMutePackage(); +private Q_SLOTS: + void sendSms(const QString& phoneNumber, const QString& messageBody); + void showSendSmsDialog(); + private: KNotification* createNotification(const NetworkPackage& np);