Added a simple way to answer SMS messages from the notification
This commit is contained in:
parent
1a63d18ada
commit
866fdfb33f
5 changed files with 152 additions and 11 deletions
|
@ -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})
|
||||
|
|
64
plugins/telephony/sendsmsdialog.cpp
Normal file
64
plugins/telephony/sendsmsdialog.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Copyright 2015 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sendsmsdialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QLineEdit>
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
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);
|
||||
}
|
50
plugins/telephony/sendsmsdialog.h
Normal file
50
plugins/telephony/sendsmsdialog.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright 2015 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SENDSMSDIALOG_H
|
||||
#define SENDSMSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QSize>
|
||||
|
||||
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
|
|
@ -20,13 +20,14 @@
|
|||
|
||||
#include "telephonyplugin.h"
|
||||
|
||||
#include "sendsmsdialog.h"
|
||||
|
||||
#include <KLocalizedString>
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
||||
|
||||
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<QString>("event");
|
||||
const QString phoneNumber = np.get<QString>("phoneNumber", i18n("unknown number"));
|
||||
const QString contactName = np.get<QString>("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<QString>("messageBody","");
|
||||
content = i18n("SMS from %1<br>%2", phoneNumber, messageBody);
|
||||
content = i18n("SMS from %1<br>%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<QString>("messageBody",""));
|
||||
connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::showSendSmsDialog);
|
||||
}
|
||||
|
||||
return notification;
|
||||
|
@ -96,15 +103,11 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np)
|
|||
{
|
||||
if (np.get<bool>("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"
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue