Use the same dialog for SendReply and SendSms

This commit is contained in:
Aleix Pol 2017-08-05 02:11:27 +02:00
parent 824eac228e
commit ec97af93a6
4 changed files with 8 additions and 118 deletions

View file

@ -1,12 +1,15 @@
find_package(KF5 REQUIRED COMPONENTS Notifications)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../notifications/) # needed for the sendreplydialog
kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES telephonyplugin.cpp sendsmsdialog.cpp)
ki18n_wrap_ui(kdeconnect_telephony_SRCS ../notifications/sendreplydialog.ui)
kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES telephonyplugin.cpp ../notifications/sendreplydialog.cpp ${kdeconnect_telephony_SRCS})
target_link_libraries(kdeconnect_telephony
kdeconnectcore
KF5::I18n
KF5::Notifications
Qt5::DBus
Qt5::Widgets
)

View file

@ -1,64 +0,0 @@
/**
* 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, &QAbstractButton::clicked, this, &SendSmsDialog::sendButtonClicked);
layout->addWidget(sendButton);
setLayout(layout);
setWindowTitle(contactName);
setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
setAttribute(Qt::WA_DeleteOnClose);
}
void SendSmsDialog::sendButtonClicked()
{
Q_EMIT sendSms(mPhoneNumber, mTextEdit->toPlainText());
close();
}
QSize SendSmsDialog::sizeHint() const
{
return QSize(512, 64);
}

View file

@ -1,50 +0,0 @@
/**
* 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 = nullptr);
QSize sizeHint() const override;
private Q_SLOTS:
void sendButtonClicked();
Q_SIGNALS:
void sendSms(const QString& phoneNumber, const QString& messageBody);
private:
QString mPhoneNumber;
QTextEdit *mTextEdit;
};
#endif

View file

@ -20,7 +20,7 @@
#include "telephonyplugin.h"
#include "sendsmsdialog.h"
#include "sendreplydialog.h"
#include <KLocalizedString>
#include <QIcon>
@ -156,9 +156,10 @@ 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, &SendSmsDialog::sendSms, this, &TelephonyPlugin::sendSms);
SendReplyDialog* dialog = new SendReplyDialog(originalMessage, phoneNumber, contactName);
connect(dialog, &SendReplyDialog::sendReply, this, &TelephonyPlugin::sendSms);
dialog->show();
dialog->raise();
}
QString TelephonyPlugin::dbusPath() const