From d0617d0ad6926c250e29d1a40db93733fa911e5d Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Wed, 9 Mar 2016 16:35:53 +0100 Subject: rename composer -> composercontroller --- components/package/contents/ui/Composer.qml | 2 +- framework/domain/CMakeLists.txt | 2 +- framework/domain/composer.cpp | 199 ---------------------------- framework/domain/composer.h | 93 ------------- framework/domain/composercontroller.cpp | 199 ++++++++++++++++++++++++++++ framework/domain/composercontroller.h | 93 +++++++++++++ framework/domain/mailplugin.cpp | 4 +- 7 files changed, 296 insertions(+), 296 deletions(-) delete mode 100644 framework/domain/composer.cpp delete mode 100644 framework/domain/composer.h create mode 100644 framework/domain/composercontroller.cpp create mode 100644 framework/domain/composercontroller.h diff --git a/components/package/contents/ui/Composer.qml b/components/package/contents/ui/Composer.qml index 6f085a63..8c7aa36b 100644 --- a/components/package/contents/ui/Composer.qml +++ b/components/package/contents/ui/Composer.qml @@ -48,7 +48,7 @@ Item { } } - KubeFramework.Composer { + KubeFramework.ComposerController { id: composer originalMessage: retriever.value } diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index 75fcef09..361b816b 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt @@ -7,7 +7,7 @@ set(mailplugin_SRCS objecttreesource.cpp stringhtmlwriter.cpp csshelper.cpp - composer.cpp + composercontroller.cpp messageparser.cpp mailtransport.cpp mailtemplates.cpp diff --git a/framework/domain/composer.cpp b/framework/domain/composer.cpp deleted file mode 100644 index 2f4fe2e9..00000000 --- a/framework/domain/composer.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - Copyright (c) 2016 Michael Bohlender - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - - -#include "composer.h" -#include -#include -#include -#include -#include -#include -#include - -#include "mailtemplates.h" - -Composer::Composer(QObject *parent) : QObject(parent) -{ - m_identityModel << "Kuberich " << "Uni " << "Spam "; -} - -QString Composer::to() const -{ - return m_to; -} - -void Composer::setTo(const QString &to) -{ - if(m_to != to) { - m_to = to; - emit toChanged(); - } -} - -QString Composer::cc() const -{ - return m_cc; -} - -void Composer::setCc(const QString &cc) -{ - if(m_cc != cc) { - m_cc = cc; - emit ccChanged(); - } -} - -QString Composer::bcc() const -{ - return m_bcc; -} - -void Composer::setBcc(const QString &bcc) -{ - if(m_bcc != bcc) { - m_bcc = bcc; - emit bccChanged(); - } -} - -QString Composer::subject() const -{ - return m_subject; -} - -void Composer::setSubject(const QString &subject) -{ - if(m_subject != subject) { - m_subject = subject; - emit subjectChanged(); - } -} - -QString Composer::body() const -{ - return m_body; -} - -void Composer::setBody(const QString &body) -{ - if(m_body != body) { - m_body = body; - emit bodyChanged(); - } -} - -QStringList Composer::identityModel() const -{ - return m_identityModel; -} - -int Composer::fromIndex() const -{ - return m_fromIndex; -} - -void Composer::setFromIndex(int fromIndex) -{ - if(m_fromIndex != fromIndex) { - m_fromIndex = fromIndex; - emit fromIndexChanged(); - } -} - -QVariant Composer::originalMessage() const -{ - return m_originalMessage; -} - -void Composer::setOriginalMessage(const QVariant &originalMessage) -{ - const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); - if (!mailData.isEmpty()) { - KMime::Message::Ptr mail(new KMime::Message); - mail->setContent(mailData); - mail->parse(); - auto reply = MailTemplates::reply(mail); - //We assume reply - setTo(reply->to(true)->asUnicodeString()); - setCc(reply->cc(true)->asUnicodeString()); - setSubject(reply->subject(true)->asUnicodeString()); - setBody(reply->body()); - m_msg = QVariant::fromValue(reply); - } else { - m_msg = QVariant(); - } -} - -KMime::Message::Ptr Composer::assembleMessage() -{ - auto mail = m_msg.value(); - if (!mail) { - mail = KMime::Message::Ptr::create(); - } - for (const auto &to : KEmailAddress::splitAddressList(m_to)) { - QByteArray displayName; - QByteArray addrSpec; - QByteArray comment; - KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); - mail->to(true)->addAddress(addrSpec, displayName); - } - mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); - mail->setBody(m_body.toUtf8()); - mail->assemble(); - return mail; -} - -void Composer::send() -{ - auto mail = assembleMessage(); - Kube::ApplicationContext settings; - auto account = settings.currentAccount(); - auto identity = account.primaryIdentity(); - auto transport = identity.transport(); - - Kube::Context context; - context.setProperty("message", QVariant::fromValue(mail)); - - context.setProperty("username", transport.username()); - context.setProperty("password", transport.password()); - context.setProperty("server", transport.server()); - - Kube::Action("org.kde.kube.actions.sendmail", context).execute(); - clear(); -} - -void Composer::saveAsDraft() -{ - auto mail = assembleMessage(); - Kube::Context context; - context.setProperty("message", QVariant::fromValue(mail)); - Kube::Action("org.kde.kube.actions.saveasdraft", context).execute(); - clear(); -} - -void Composer::clear() -{ - setSubject(""); - setBody(""); - setTo(""); - setCc(""); - setBcc(""); - setFromIndex(-1); -} diff --git a/framework/domain/composer.h b/framework/domain/composer.h deleted file mode 100644 index dd066b2e..00000000 --- a/framework/domain/composer.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2016 Michael Bohlender - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#pragma once - -#include -#include -#include -#include - -namespace KMime { -class Message; -} - -class Composer : public QObject -{ - Q_OBJECT - Q_PROPERTY (QVariant originalMessage READ originalMessage WRITE setOriginalMessage) - Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) - Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) - Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) - Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) - Q_PROPERTY (QStringList identityModel READ identityModel) - Q_PROPERTY (int fromIndex READ fromIndex WRITE setFromIndex NOTIFY fromIndexChanged) - -public: - explicit Composer(QObject *parent = Q_NULLPTR); - - QString to() const; - void setTo(const QString &to); - - QString cc() const; - void setCc(const QString &cc); - - QString bcc() const; - void setBcc(const QString &bcc); - - QString subject() const; - void setSubject(const QString &subject); - - QString body() const; - void setBody(const QString &body); - - QStringList identityModel() const; - - int fromIndex() const; - void setFromIndex(int fromIndex); - - QVariant originalMessage() const; - void setOriginalMessage(const QVariant &originalMessage); - -signals: - void subjectChanged(); - void bodyChanged(); - void toChanged(); - void ccChanged(); - void bccChanged(); - void fromIndexChanged(); - -public slots: - void send(); - void saveAsDraft(); - void clear(); - -private: - QSharedPointer assembleMessage(); - QString m_to; - QString m_cc; - QString m_bcc; - QString m_subject; - QString m_body; - QStringList m_identityModel; - int m_fromIndex; - QVariant m_originalMessage; - QVariant m_msg; -}; diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp new file mode 100644 index 00000000..78c20246 --- /dev/null +++ b/framework/domain/composercontroller.cpp @@ -0,0 +1,199 @@ +/* + Copyright (c) 2016 Michael Bohlender + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#include "composercontroller.h" +#include +#include +#include +#include +#include +#include +#include + +#include "mailtemplates.h" + +ComposerController::ComposerController(QObject *parent) : QObject(parent) +{ + m_identityModel << "Kuberich " << "Uni " << "Spam "; +} + +QString ComposerController::to() const +{ + return m_to; +} + +void ComposerController::setTo(const QString &to) +{ + if(m_to != to) { + m_to = to; + emit toChanged(); + } +} + +QString ComposerController::cc() const +{ + return m_cc; +} + +void ComposerController::setCc(const QString &cc) +{ + if(m_cc != cc) { + m_cc = cc; + emit ccChanged(); + } +} + +QString ComposerController::bcc() const +{ + return m_bcc; +} + +void ComposerController::setBcc(const QString &bcc) +{ + if(m_bcc != bcc) { + m_bcc = bcc; + emit bccChanged(); + } +} + +QString ComposerController::subject() const +{ + return m_subject; +} + +void ComposerController::setSubject(const QString &subject) +{ + if(m_subject != subject) { + m_subject = subject; + emit subjectChanged(); + } +} + +QString ComposerController::body() const +{ + return m_body; +} + +void ComposerController::setBody(const QString &body) +{ + if(m_body != body) { + m_body = body; + emit bodyChanged(); + } +} + +QStringList ComposerController::identityModel() const +{ + return m_identityModel; +} + +int ComposerController::fromIndex() const +{ + return m_fromIndex; +} + +void ComposerController::setFromIndex(int fromIndex) +{ + if(m_fromIndex != fromIndex) { + m_fromIndex = fromIndex; + emit fromIndexChanged(); + } +} + +QVariant ComposerController::originalMessage() const +{ + return m_originalMessage; +} + +void ComposerController::setOriginalMessage(const QVariant &originalMessage) +{ + const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); + if (!mailData.isEmpty()) { + KMime::Message::Ptr mail(new KMime::Message); + mail->setContent(mailData); + mail->parse(); + auto reply = MailTemplates::reply(mail); + //We assume reply + setTo(reply->to(true)->asUnicodeString()); + setCc(reply->cc(true)->asUnicodeString()); + setSubject(reply->subject(true)->asUnicodeString()); + setBody(reply->body()); + m_msg = QVariant::fromValue(reply); + } else { + m_msg = QVariant(); + } +} + +KMime::Message::Ptr ComposerController::assembleMessage() +{ + auto mail = m_msg.value(); + if (!mail) { + mail = KMime::Message::Ptr::create(); + } + for (const auto &to : KEmailAddress::splitAddressList(m_to)) { + QByteArray displayName; + QByteArray addrSpec; + QByteArray comment; + KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); + mail->to(true)->addAddress(addrSpec, displayName); + } + mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); + mail->setBody(m_body.toUtf8()); + mail->assemble(); + return mail; +} + +void ComposerController::send() +{ + auto mail = assembleMessage(); + Kube::ApplicationContext settings; + auto account = settings.currentAccount(); + auto identity = account.primaryIdentity(); + auto transport = identity.transport(); + + Kube::Context context; + context.setProperty("message", QVariant::fromValue(mail)); + + context.setProperty("username", transport.username()); + context.setProperty("password", transport.password()); + context.setProperty("server", transport.server()); + + Kube::Action("org.kde.kube.actions.sendmail", context).execute(); + clear(); +} + +void ComposerController::saveAsDraft() +{ + auto mail = assembleMessage(); + Kube::Context context; + context.setProperty("message", QVariant::fromValue(mail)); + Kube::Action("org.kde.kube.actions.saveasdraft", context).execute(); + clear(); +} + +void ComposerController::clear() +{ + setSubject(""); + setBody(""); + setTo(""); + setCc(""); + setBcc(""); + setFromIndex(-1); +} diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h new file mode 100644 index 00000000..711a74e1 --- /dev/null +++ b/framework/domain/composercontroller.h @@ -0,0 +1,93 @@ +/* + Copyright (c) 2016 Michael Bohlender + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace KMime { +class Message; +} + +class ComposerController : public QObject +{ + Q_OBJECT + Q_PROPERTY (QVariant originalMessage READ originalMessage WRITE setOriginalMessage) + Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) + Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) + Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) + Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) + Q_PROPERTY (QStringList identityModel READ identityModel) + Q_PROPERTY (int fromIndex READ fromIndex WRITE setFromIndex NOTIFY fromIndexChanged) + +public: + explicit ComposerController(QObject *parent = Q_NULLPTR); + + QString to() const; + void setTo(const QString &to); + + QString cc() const; + void setCc(const QString &cc); + + QString bcc() const; + void setBcc(const QString &bcc); + + QString subject() const; + void setSubject(const QString &subject); + + QString body() const; + void setBody(const QString &body); + + QStringList identityModel() const; + + int fromIndex() const; + void setFromIndex(int fromIndex); + + QVariant originalMessage() const; + void setOriginalMessage(const QVariant &originalMessage); + +signals: + void subjectChanged(); + void bodyChanged(); + void toChanged(); + void ccChanged(); + void bccChanged(); + void fromIndexChanged(); + +public slots: + void send(); + void saveAsDraft(); + void clear(); + +private: + QSharedPointer assembleMessage(); + QString m_to; + QString m_cc; + QString m_bcc; + QString m_subject; + QString m_body; + QStringList m_identityModel; + int m_fromIndex; + QVariant m_originalMessage; + QVariant m_msg; +}; diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index eaebd843..c45666c1 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp @@ -22,7 +22,7 @@ #include "maillistmodel.h" #include "folderlistmodel.h" -#include "composer.h" +#include "composercontroller.h" #include "messageparser.h" #include "retriever.h" @@ -34,7 +34,7 @@ void MailPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "FolderListModel"); qmlRegisterType(uri, 1, 0, "MailListModel"); - qmlRegisterType(uri, 1, 0, "Composer"); + qmlRegisterType(uri, 1, 0, "ComposerController"); qmlRegisterType(uri, 1, 0, "MessageParser"); qmlRegisterType(uri, 1, 0, "Retriever"); } -- cgit v1.2.3