Start adding feature for sending simple e-mails.

This commit is contained in:
Martin Rotter 2019-07-02 10:48:12 +02:00
parent 688198d666
commit 6cc4d8919d
8 changed files with 188 additions and 27 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.5.9" date="2019-06-27"/>
<release version="3.5.9" date="2019-07-02"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -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 \

View File

@ -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

View File

@ -0,0 +1,37 @@
// For license of this file, see <project-root-folder>/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 <QComboBox>
#include <QHBoxLayout>
#include <QLineEdit>
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);
}

View File

@ -0,0 +1,27 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef EMAILRECIPIENTCONTROL_H
#define EMAILRECIPIENTCONTROL_H
#include <QWidget>
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

View File

@ -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<EmailRecipientControl*>(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);
}

View File

@ -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<EmailRecipientControl*> m_recipientControls;
};
#endif // FORMADDEDITEMAIL_H

View File

@ -1,42 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>FormAddEditEmail</class>
<widget name="FormAddEditEmail" class="QDialog">
<widget class="QDialog" name="FormAddEditEmail">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>552</width>
<height>491</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Write e-mail message</string>
</property>
<widget name="buttonBox" class="QDialogButtonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QFormLayout" name="m_layout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_txtSender">
<property name="placeholderText">
<string>Name and address of this e-mail message sender</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTextEdit" name="m_txtMessage">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Contents of your e-mail message</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="m_layoutAdder">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="PlainToolButton" name="m_btnAdder">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<pixmapfunction/>
<customwidgets>
<customwidget>
<class>PlainToolButton</class>
<extends>QToolButton</extends>
<header>plaintoolbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>m_buttonBox</sender>
<signal>accepted()</signal>
<receiver>FormAddEditEmail</receiver>
<slot>accept()</slot>
@ -52,7 +103,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>m_buttonBox</sender>
<signal>rejected()</signal>
<receiver>FormAddEditEmail</receiver>
<slot>reject()</slot>