From 6cc4d8919debfe93fc973d9d916264d1a40d4db7 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 2 Jul 2019 10:48:12 +0200 Subject: [PATCH] Start adding feature for sending simple e-mails. --- .../desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/librssguard.pro | 2 + src/librssguard/services/gmail/definitions.h | 7 ++ .../gmail/gui/emailrecipientcontrol.cpp | 37 +++++++ .../gmail/gui/emailrecipientcontrol.h | 27 +++++ .../services/gmail/gui/formaddeditemail.cpp | 31 ++++++ .../services/gmail/gui/formaddeditemail.h | 6 + .../services/gmail/gui/formaddeditemail.ui | 103 +++++++++++++----- 8 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 src/librssguard/services/gmail/gui/emailrecipientcontrol.cpp create mode 100644 src/librssguard/services/gmail/gui/emailrecipientcontrol.h diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 905697c40..78fccfc5c 100755 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro index da2caf724..c1e63fdc7 100644 --- a/src/librssguard/librssguard.pro +++ b/src/librssguard/librssguard.pro @@ -131,6 +131,7 @@ HEADERS += core/feeddownloader.h \ services/gmail/gmailentrypoint.h \ services/gmail/gmailfeed.h \ services/gmail/gmailserviceroot.h \ + services/gmail/gui/emailrecipientcontrol.h \ services/gmail/gui/formeditgmailaccount.h \ services/gmail/network/gmailnetworkfactory.h \ services/inoreader/definitions.h \ @@ -269,6 +270,7 @@ SOURCES += core/feeddownloader.cpp \ services/gmail/gmailentrypoint.cpp \ services/gmail/gmailfeed.cpp \ services/gmail/gmailserviceroot.cpp \ + services/gmail/gui/emailrecipientcontrol.cpp \ services/gmail/gui/formeditgmailaccount.cpp \ services/gmail/network/gmailnetworkfactory.cpp \ services/inoreader/gui/formeditinoreaderaccount.cpp \ diff --git a/src/librssguard/services/gmail/definitions.h b/src/librssguard/services/gmail/definitions.h index 4322d98fa..828375e1d 100644 --- a/src/librssguard/services/gmail/definitions.h +++ b/src/librssguard/services/gmail/definitions.h @@ -30,4 +30,11 @@ #define GMAIL_CONTENT_TYPE_HTTP "application/http" #define GMAIL_CONTENT_TYPE_JSON "application/json" +enum class RecipientType { + To, + Cc, + Bcc, + ReplyTo +}; + #endif // GMAIL_DEFINITIONS_H diff --git a/src/librssguard/services/gmail/gui/emailrecipientcontrol.cpp b/src/librssguard/services/gmail/gui/emailrecipientcontrol.cpp new file mode 100644 index 000000000..e4fd2e138 --- /dev/null +++ b/src/librssguard/services/gmail/gui/emailrecipientcontrol.cpp @@ -0,0 +1,37 @@ +// For license of this file, see /LICENSE.md. + +#include "services/gmail/gui/emailrecipientcontrol.h" + +#include "gui/plaintoolbutton.h" +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" +#include "services/gmail/definitions.h" + +#include +#include +#include + +EmailRecipientControl::EmailRecipientControl(const QString& recipient, QWidget* parent) : QWidget(parent) { + QHBoxLayout* lay = new QHBoxLayout(this); + + lay->addWidget(m_cmbRecipientType = new QComboBox(this)); + lay->addWidget(m_txtRecipient = new QLineEdit(this), 1); + lay->addWidget(m_btnCloseMe = new PlainToolButton(this)); + lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); + + m_btnCloseMe->setToolTip("Remove this recipient."); + m_btnCloseMe->setIcon(qApp->icons()->fromTheme(QSL("list-remove"))); + + connect(m_btnCloseMe, &PlainToolButton::clicked, this, &EmailRecipientControl::removalRequested); + + m_cmbRecipientType->addItem(tr("To"), int(RecipientType::To)); + m_cmbRecipientType->addItem(tr("Cc"), int(RecipientType::Cc)); + m_cmbRecipientType->addItem(tr("Bcc"), int(RecipientType::Bcc)); + m_cmbRecipientType->addItem(tr("Reply-to"), int(RecipientType::ReplyTo)); + + setTabOrder(m_cmbRecipientType, m_txtRecipient); + setTabOrder(m_txtRecipient, m_btnCloseMe); + + setLayout(lay); +} diff --git a/src/librssguard/services/gmail/gui/emailrecipientcontrol.h b/src/librssguard/services/gmail/gui/emailrecipientcontrol.h new file mode 100644 index 000000000..4eeed1ee1 --- /dev/null +++ b/src/librssguard/services/gmail/gui/emailrecipientcontrol.h @@ -0,0 +1,27 @@ +// For license of this file, see /LICENSE.md. + +#ifndef EMAILRECIPIENTCONTROL_H +#define EMAILRECIPIENTCONTROL_H + +#include + +class QComboBox; +class QLineEdit; +class PlainToolButton; + +class EmailRecipientControl : public QWidget { + Q_OBJECT + + public: + explicit EmailRecipientControl(const QString& recipient, QWidget* parent = nullptr); + + signals: + void removalRequested(); + + private: + QComboBox* m_cmbRecipientType; + QLineEdit* m_txtRecipient; + PlainToolButton* m_btnCloseMe; +}; + +#endif // EMAILRECIPIENTCONTROL_H diff --git a/src/librssguard/services/gmail/gui/formaddeditemail.cpp b/src/librssguard/services/gmail/gui/formaddeditemail.cpp index dfa186829..ae5318dc3 100644 --- a/src/librssguard/services/gmail/gui/formaddeditemail.cpp +++ b/src/librssguard/services/gmail/gui/formaddeditemail.cpp @@ -2,12 +2,43 @@ #include "services/gmail/gui/formaddeditemail.h" +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" #include "services/gmail/gmailserviceroot.h" +#include "services/gmail/gui/emailrecipientcontrol.h" FormAddEditEmail::FormAddEditEmail(GmailServiceRoot* root, QWidget* parent) : QDialog(parent), m_root(root) { m_ui.setupUi(this); + + m_ui.m_layoutAdder->setMargin(0); + m_ui.m_layoutAdder->setContentsMargins(0, 0, 0, 0); + + m_ui.m_btnAdder->setIcon(qApp->icons()->fromTheme(QSL("list-add"))); + m_ui.m_btnAdder->setToolTip(tr("Add new recipient.")); + + connect(m_ui.m_btnAdder, &PlainToolButton::clicked, this, [=]() { + addRecipientRow(); + }); } void FormAddEditEmail::execForAdd() { + addRecipientRow(); exec(); } + +void FormAddEditEmail::removeRecipientRow() { + EmailRecipientControl* sndr = static_cast(sender()); + + m_ui.m_layout->takeRow(sndr); + m_recipientControls.removeOne(sndr); + + sndr->deleteLater(); +} + +void FormAddEditEmail::addRecipientRow(const QString& recipient) { + auto* mail_rec = new EmailRecipientControl(recipient, this); + + connect(mail_rec, &EmailRecipientControl::removalRequested, this, &FormAddEditEmail::removeRecipientRow); + + m_ui.m_layout->insertRow(m_ui.m_layout->indexOf(m_ui.m_txtMessage) - 1, mail_rec); +} diff --git a/src/librssguard/services/gmail/gui/formaddeditemail.h b/src/librssguard/services/gmail/gui/formaddeditemail.h index 6fc36b305..3dbf28ad6 100644 --- a/src/librssguard/services/gmail/gui/formaddeditemail.h +++ b/src/librssguard/services/gmail/gui/formaddeditemail.h @@ -12,6 +12,7 @@ namespace Ui { } class GmailServiceRoot; +class EmailRecipientControl; class FormAddEditEmail : public QDialog { Q_OBJECT @@ -22,10 +23,15 @@ class FormAddEditEmail : public QDialog { public slots: void execForAdd(); + private slots: + void removeRecipientRow(); + void addRecipientRow(const QString& recipient = QString()); + private: GmailServiceRoot* m_root; Ui::FormAddEditEmail m_ui; + QList m_recipientControls; }; #endif // FORMADDEDITEMAIL_H diff --git a/src/librssguard/services/gmail/gui/formaddeditemail.ui b/src/librssguard/services/gmail/gui/formaddeditemail.ui index add1c4d29..5216e45ac 100644 --- a/src/librssguard/services/gmail/gui/formaddeditemail.ui +++ b/src/librssguard/services/gmail/gui/formaddeditemail.ui @@ -1,42 +1,93 @@ + - - - FormAddEditEmail - + 0 0 - 400 - 300 + 552 + 491 - Dialog + Write e-mail message - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + From + + + + + + + Name and address of this e-mail message sender + + + + + + + + 0 + 1 + + + + Contents of your e-mail message + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + + + - + + + PlainToolButton + QToolButton +
plaintoolbutton.h
+
+
- buttonBox + m_buttonBox accepted() FormAddEditEmail accept() @@ -52,7 +103,7 @@ - buttonBox + m_buttonBox rejected() FormAddEditEmail reject()