From e9b4b2d564c46e1b75c46376e7d4f7fdac757e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 12 Jan 2016 16:54:19 +0100 Subject: Replace links to akonadi2common with propper cmake package --- framework/CMakeLists.txt | 3 +++ framework/mail/CMakeLists.txt | 5 +++-- framework/settings/CMakeLists.txt | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'framework') diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 3a441f99..c91ee0d1 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -16,6 +16,9 @@ include(KDEInstallDirs) find_package(Qt5 COMPONENTS REQUIRED Core Qml) +find_package(Akonadi2Common CONFIG REQUIRED) +find_package(KF5Async) + set(CMAKE_AUTOMOC ON) add_definitions("-Wall -std=c++0x -g") include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common) diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt index 38ba3935..a8a4b3e8 100644 --- a/framework/mail/CMakeLists.txt +++ b/framework/mail/CMakeLists.txt @@ -5,14 +5,15 @@ set(mailplugin_SRCS singlemailcontroller.cpp folderlistmodel.cpp folderlistcontroller.cpp + filehtmlwriter.cpp + objecttreesource.cpp ) add_library(mailplugin SHARED ${mailplugin_SRCS}) qt5_use_modules(mailplugin Core Quick Qml) -target_link_libraries(mailplugin /work/install/lib64/libakonadi2common.so) -#target_link_libraries(mailplugin /home/mike/projects/_install/lib/x86_64-linux-gnu/libakonadi2common.so) +target_link_libraries(mailplugin KF5::akonadi2common) install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) diff --git a/framework/settings/CMakeLists.txt b/framework/settings/CMakeLists.txt index b0a8fe28..5d61851f 100644 --- a/framework/settings/CMakeLists.txt +++ b/framework/settings/CMakeLists.txt @@ -9,8 +9,7 @@ add_library(settingsplugin SHARED ${settingsplugin_SRCS}) qt5_use_modules(settingsplugin Core Quick Qml) -target_link_libraries(settingsplugin /work/install/lib64/libakonadi2common.so) -#target_link_libraries(settingsplugin /home/mike/projects/_install/lib/x86_64-linux-gnu/libakonadi2common.so) +target_link_libraries(settingsplugin KF5::akonadi2common) install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings) \ No newline at end of file -- cgit v1.2.3 From 06201e4d405cef119207b528f76f8f993c09e527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 12 Jan 2016 16:55:57 +0100 Subject: render mail to html --- framework/CMakeLists.txt | 7 ++ framework/mail/CMakeLists.txt | 2 +- framework/mail/filehtmlwriter.cpp | 111 +++++++++++++++++++++++++++++++ framework/mail/filehtmlwriter.h | 64 ++++++++++++++++++ framework/mail/maillistmodel.cpp | 46 +++++++++++++ framework/mail/maillistmodel.h | 3 +- framework/mail/objecttreesource.cpp | 129 ++++++++++++++++++++++++++++++++++++ framework/mail/objecttreesource.h | 55 +++++++++++++++ 8 files changed, 415 insertions(+), 2 deletions(-) create mode 100644 framework/mail/filehtmlwriter.cpp create mode 100644 framework/mail/filehtmlwriter.h create mode 100644 framework/mail/objecttreesource.cpp create mode 100644 framework/mail/objecttreesource.h (limited to 'framework') diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index c91ee0d1..8301392a 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -16,14 +16,21 @@ include(KDEInstallDirs) find_package(Qt5 COMPONENTS REQUIRED Core Qml) +find_package(KF5Otp "5.1.42" CONFIG REQUIRED) +find_package(KF5Mime "4.87.0" CONFIG REQUIRED) find_package(Akonadi2Common CONFIG REQUIRED) find_package(KF5Async) +find_package(KF5Libkleo) set(CMAKE_AUTOMOC ON) add_definitions("-Wall -std=c++0x -g") include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common) include_directories(SYSTEM /work/install/include/) include_directories(SYSTEM /work/install/include/KF5/) +include_directories(SYSTEM /work/install/include/KF5/KIconThemes) +include_directories(SYSTEM /work/install/include/KF5/KMime) +include_directories(SYSTEM /work/install/include/KF5/KService) +include_directories(SYSTEM /work/install/include/KF5/KCoreAddons) enable_testing() diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt index a8a4b3e8..e7286763 100644 --- a/framework/mail/CMakeLists.txt +++ b/framework/mail/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(mailplugin SHARED ${mailplugin_SRCS}) qt5_use_modules(mailplugin Core Quick Qml) -target_link_libraries(mailplugin KF5::akonadi2common) +target_link_libraries(mailplugin KF5::akonadi2common KF5::Otp) install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) diff --git a/framework/mail/filehtmlwriter.cpp b/framework/mail/filehtmlwriter.cpp new file mode 100644 index 00000000..e435e1be --- /dev/null +++ b/framework/mail/filehtmlwriter.cpp @@ -0,0 +1,111 @@ +/* -*- c++ -*- + filehtmlwriter.cpp + + This file is part of KMail, the KDE mail client. + Copyright (c) 2003 Marc Mutz + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "filehtmlwriter.h" + +#include + +FileHtmlWriter::FileHtmlWriter(const QString &filename) + : MessageViewer::HtmlWriter(), + mFile(filename.isEmpty() ? QStringLiteral("filehtmlwriter.out") : filename) +{ + mStream.setCodec("UTF-8"); +} + +FileHtmlWriter::~FileHtmlWriter() +{ + if (mFile.isOpen()) { + mStream.setDevice(0); + mFile.close(); + } +} + +void FileHtmlWriter::begin(const QString &css) +{ + openOrWarn(); + if (!css.isEmpty()) { + write(QLatin1String("\n")); + } +} + +void FileHtmlWriter::end() +{ + flush(); + mStream.setDevice(0); + mFile.close(); +} + +void FileHtmlWriter::reset() +{ + if (mFile.isOpen()) { + mStream.setDevice(0); + mFile.close(); + } +} + +void FileHtmlWriter::write(const QString &str) +{ + mStream << str.toUtf8(); + flush(); +} + +void FileHtmlWriter::queue(const QString &str) +{ + write(str); +} + +void FileHtmlWriter::flush() +{ + mStream.flush(); + mFile.flush(); +} + +void FileHtmlWriter::openOrWarn() +{ + if (mFile.isOpen()) { + mStream.setDevice(0); + mFile.close(); + } + if (!mFile.open(QIODevice::WriteOnly)) { + } else { + mStream.setDevice(&mFile); + } +} + +void FileHtmlWriter::embedPart(const QByteArray &contentId, const QString &url) +{ + mStream << "" << endl; + flush(); +} +void FileHtmlWriter::extraHead(const QString &) +{ + +} \ No newline at end of file diff --git a/framework/mail/filehtmlwriter.h b/framework/mail/filehtmlwriter.h new file mode 100644 index 00000000..8bda39f8 --- /dev/null +++ b/framework/mail/filehtmlwriter.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- + filehtmlwriter.h + + This file is part of KMail, the KDE mail client. + Copyright (c) 2003 Marc Mutz + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __MESSAGEVIEWER_FILEHTMLWRITER_H__ +#define __MESSAGEVIEWER_FILEHTMLWRITER_H__ + +#include + +#include +#include + +class QString; + +class FileHtmlWriter : public MessageViewer::HtmlWriter +{ +public: + explicit FileHtmlWriter(const QString &filename); + virtual ~FileHtmlWriter(); + + void begin(const QString &cssDefs) Q_DECL_OVERRIDE; + void end() Q_DECL_OVERRIDE; + void reset() Q_DECL_OVERRIDE; + void write(const QString &str) Q_DECL_OVERRIDE; + void queue(const QString &str) Q_DECL_OVERRIDE; + void flush() Q_DECL_OVERRIDE; + void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE; + void extraHead(const QString &str) Q_DECL_OVERRIDE; +private: + void openOrWarn(); + +private: + QFile mFile; + QTextStream mStream; +}; + +#endif // __MESSAGEVIEWER_FILEHTMLWRITER_H__ diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp index e6a9c218..c37e2be4 100644 --- a/framework/mail/maillistmodel.cpp +++ b/framework/mail/maillistmodel.cpp @@ -1,6 +1,12 @@ #include "maillistmodel.h" +#include "filehtmlwriter.h" +#include "objecttreesource.h" + #include +#include +#include +#include MailListModel::MailListModel(QObject *parent) : QIdentityProxyModel() @@ -25,6 +31,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const roles[Important] = "important"; roles[Id] = "id"; roles[MimeMessage] = "mimeMessage"; + roles[RenderedMessage] = "renderedMessage"; roles[DomainObject] = "domainObject"; return roles; @@ -61,6 +68,45 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const } return "Failed to read mail."; } + case RenderedMessage: { + auto filename = srcIdx.sibling(srcIdx.row(), 6).data(Qt::DisplayRole).toString(); + QFile file(filename); + if (file.open(QFile::ReadOnly)) { + const auto mailData = KMime::CRLFtoLF(file.readAll()); + KMime::Message::Ptr msg(new KMime::Message); + msg->setContent(mailData); + msg->parse(); + + // render the mail + const QString fname("/tmp/test.html"); + FileHtmlWriter htmlWriter(fname); + QImage paintDevice; + MessageViewer::CSSHelper cssHelper(&paintDevice); + MessageViewer::NodeHelper nodeHelper; + ObjectTreeSource source(&htmlWriter, &cssHelper); + MessageViewer::ObjectTreeParser otp(&source, &nodeHelper); + + htmlWriter.begin(QString()); + htmlWriter.queue(cssHelper.htmlHead(false)); + + otp.parseObjectTree(msg.data()); + + htmlWriter.queue(QStringLiteral("")); + htmlWriter.flush(); + htmlWriter.end(); + + QFile file(fname); + if (file.open(QFile::ReadOnly)) { + const auto content = file.readAll(); + return content; + } else { + qWarning() << "Failed to open the file"; + } + } else { + qWarning() << "Failed to open the file"; + } + return "Failed to read mail."; + } } return QIdentityProxyModel::data(idx, role); } diff --git a/framework/mail/maillistmodel.h b/framework/mail/maillistmodel.h index 7718477c..7eb55ffd 100644 --- a/framework/mail/maillistmodel.h +++ b/framework/mail/maillistmodel.h @@ -27,7 +27,8 @@ public: Important, Id, MimeMessage, - DomainObject + DomainObject, + RenderedMessage }; QHash roleNames() const; diff --git a/framework/mail/objecttreesource.cpp b/framework/mail/objecttreesource.cpp new file mode 100644 index 00000000..cde4775a --- /dev/null +++ b/framework/mail/objecttreesource.cpp @@ -0,0 +1,129 @@ +/* + Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net + Copyright (c) 2009 Andras Mantia + + 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) any later version. + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "objecttreesource.h" + +#include + +class ObjectSourcePrivate +{ +public: + ObjectSourcePrivate() + : mWriter(0) + , mCSSHelper(0) + , mAllowDecryption(false) + , mHtmlLoadExternal(false) + , mHtmlMail(false) + { + + } + MessageViewer::HtmlWriter *mWriter; + MessageViewer::CSSHelper *mCSSHelper; + bool mAllowDecryption; + bool mHtmlLoadExternal; + bool mHtmlMail; +}; + +ObjectTreeSource::ObjectTreeSource(MessageViewer::HtmlWriter *writer, + MessageViewer::CSSHelper *cssHelper) + : MessageViewer::ObjectTreeSourceIf() + , d(new ObjectSourcePrivate) + { + d->mWriter = writer; + d->mCSSHelper = cssHelper; + } + +ObjectTreeSource::~ObjectTreeSource() +{ + delete d; +} + +void ObjectTreeSource::setAllowDecryption(bool allowDecryption) +{ + d->mAllowDecryption = allowDecryption; +} + +MessageViewer::HtmlWriter *ObjectTreeSource::htmlWriter() +{ + return d->mWriter; +} +MessageViewer::CSSHelper *ObjectTreeSource::cssHelper() +{ + return d->mCSSHelper; +} + +bool ObjectTreeSource::htmlLoadExternal() +{ + return d->mHtmlLoadExternal; +} + +void ObjectTreeSource::setHtmlLoadExternal(bool loadExternal) +{ + d->mHtmlLoadExternal = loadExternal; +} + +bool ObjectTreeSource::htmlMail() +{ + return d->mHtmlMail; +} + +void ObjectTreeSource::setHtmlMail(bool htmlMail) +{ + d->mHtmlMail = htmlMail; +} + +bool ObjectTreeSource::decryptMessage() +{ + return d->mAllowDecryption; +} + +bool ObjectTreeSource::showSignatureDetails() +{ + return true; +} + +int ObjectTreeSource::levelQuote() +{ + return 1; +} + +const QTextCodec *ObjectTreeSource::overrideCodec() +{ + return Q_NULLPTR; +} + +QString ObjectTreeSource::createMessageHeader(KMime::Message *message) +{ + return QString(); +} + +const MessageViewer::AttachmentStrategy *ObjectTreeSource::attachmentStrategy() +{ + return MessageViewer::AttachmentStrategy::smart(); +} + +QObject *ObjectTreeSource::sourceObject() +{ + return Q_NULLPTR; +} + +void ObjectTreeSource::setHtmlMode(MessageViewer::Util::HtmlMode mode) +{ + Q_UNUSED(mode); +} \ No newline at end of file diff --git a/framework/mail/objecttreesource.h b/framework/mail/objecttreesource.h new file mode 100644 index 00000000..c61ba715 --- /dev/null +++ b/framework/mail/objecttreesource.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net + Copyright (c) 2009 Andras Mantia + + 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) any later version. + + 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef MAILVIEWER_OBJECTTREEEMPTYSOURCE_H +#define MAILVIEWER_OBJECTTREEEMPTYSOURCE_H + +#include + +class QString; + +class ObjectSourcePrivate; +class ObjectTreeSource : public MessageViewer::ObjectTreeSourceIf +{ +public: + ObjectTreeSource(MessageViewer::HtmlWriter *writer, + MessageViewer::CSSHelper *cssHelper); + virtual ~ObjectTreeSource(); + void setHtmlLoadExternal(bool loadExternal); + void setHtmlMail(bool htmlMail); + bool htmlMail() Q_DECL_OVERRIDE; + bool decryptMessage() Q_DECL_OVERRIDE; + bool htmlLoadExternal() Q_DECL_OVERRIDE; + bool showSignatureDetails() Q_DECL_OVERRIDE; + void setHtmlMode(MessageViewer::Util::HtmlMode mode) Q_DECL_OVERRIDE; + void setAllowDecryption(bool allowDecryption); + int levelQuote() Q_DECL_OVERRIDE; + const QTextCodec *overrideCodec() Q_DECL_OVERRIDE; + QString createMessageHeader(KMime::Message *message) Q_DECL_OVERRIDE; + const MessageViewer::AttachmentStrategy *attachmentStrategy() Q_DECL_OVERRIDE; + MessageViewer::HtmlWriter *htmlWriter() Q_DECL_OVERRIDE; + MessageViewer::CSSHelper *cssHelper() Q_DECL_OVERRIDE; + QObject *sourceObject() Q_DECL_OVERRIDE; + +private: + ObjectSourcePrivate *const d; +}; + +#endif + -- cgit v1.2.3 From e8ce86ccdf23fad155cf4888cb4db657b99c8bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Fri, 15 Jan 2016 13:02:24 +0100 Subject: Render HTML directly to string and not via indirecton of a file --- framework/mail/CMakeLists.txt | 2 +- framework/mail/filehtmlwriter.cpp | 111 ----------------------------- framework/mail/filehtmlwriter.h | 64 ----------------- framework/mail/maillistmodel.cpp | 14 +--- framework/mail/stringhtmlwriter.cpp | 134 ++++++++++++++++++++++++++++++++++++ framework/mail/stringhtmlwriter.h | 68 ++++++++++++++++++ 6 files changed, 206 insertions(+), 187 deletions(-) delete mode 100644 framework/mail/filehtmlwriter.cpp delete mode 100644 framework/mail/filehtmlwriter.h create mode 100644 framework/mail/stringhtmlwriter.cpp create mode 100644 framework/mail/stringhtmlwriter.h (limited to 'framework') diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt index e7286763..0abc6880 100644 --- a/framework/mail/CMakeLists.txt +++ b/framework/mail/CMakeLists.txt @@ -5,8 +5,8 @@ set(mailplugin_SRCS singlemailcontroller.cpp folderlistmodel.cpp folderlistcontroller.cpp - filehtmlwriter.cpp objecttreesource.cpp + stringhtmlwriter.cpp ) add_library(mailplugin SHARED ${mailplugin_SRCS}) diff --git a/framework/mail/filehtmlwriter.cpp b/framework/mail/filehtmlwriter.cpp deleted file mode 100644 index e435e1be..00000000 --- a/framework/mail/filehtmlwriter.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- c++ -*- - filehtmlwriter.cpp - - This file is part of KMail, the KDE mail client. - Copyright (c) 2003 Marc Mutz - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#include "filehtmlwriter.h" - -#include - -FileHtmlWriter::FileHtmlWriter(const QString &filename) - : MessageViewer::HtmlWriter(), - mFile(filename.isEmpty() ? QStringLiteral("filehtmlwriter.out") : filename) -{ - mStream.setCodec("UTF-8"); -} - -FileHtmlWriter::~FileHtmlWriter() -{ - if (mFile.isOpen()) { - mStream.setDevice(0); - mFile.close(); - } -} - -void FileHtmlWriter::begin(const QString &css) -{ - openOrWarn(); - if (!css.isEmpty()) { - write(QLatin1String("\n")); - } -} - -void FileHtmlWriter::end() -{ - flush(); - mStream.setDevice(0); - mFile.close(); -} - -void FileHtmlWriter::reset() -{ - if (mFile.isOpen()) { - mStream.setDevice(0); - mFile.close(); - } -} - -void FileHtmlWriter::write(const QString &str) -{ - mStream << str.toUtf8(); - flush(); -} - -void FileHtmlWriter::queue(const QString &str) -{ - write(str); -} - -void FileHtmlWriter::flush() -{ - mStream.flush(); - mFile.flush(); -} - -void FileHtmlWriter::openOrWarn() -{ - if (mFile.isOpen()) { - mStream.setDevice(0); - mFile.close(); - } - if (!mFile.open(QIODevice::WriteOnly)) { - } else { - mStream.setDevice(&mFile); - } -} - -void FileHtmlWriter::embedPart(const QByteArray &contentId, const QString &url) -{ - mStream << "" << endl; - flush(); -} -void FileHtmlWriter::extraHead(const QString &) -{ - -} \ No newline at end of file diff --git a/framework/mail/filehtmlwriter.h b/framework/mail/filehtmlwriter.h deleted file mode 100644 index 8bda39f8..00000000 --- a/framework/mail/filehtmlwriter.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- c++ -*- - filehtmlwriter.h - - This file is part of KMail, the KDE mail client. - Copyright (c) 2003 Marc Mutz - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifndef __MESSAGEVIEWER_FILEHTMLWRITER_H__ -#define __MESSAGEVIEWER_FILEHTMLWRITER_H__ - -#include - -#include -#include - -class QString; - -class FileHtmlWriter : public MessageViewer::HtmlWriter -{ -public: - explicit FileHtmlWriter(const QString &filename); - virtual ~FileHtmlWriter(); - - void begin(const QString &cssDefs) Q_DECL_OVERRIDE; - void end() Q_DECL_OVERRIDE; - void reset() Q_DECL_OVERRIDE; - void write(const QString &str) Q_DECL_OVERRIDE; - void queue(const QString &str) Q_DECL_OVERRIDE; - void flush() Q_DECL_OVERRIDE; - void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE; - void extraHead(const QString &str) Q_DECL_OVERRIDE; -private: - void openOrWarn(); - -private: - QFile mFile; - QTextStream mStream; -}; - -#endif // __MESSAGEVIEWER_FILEHTMLWRITER_H__ diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp index c37e2be4..d3b60187 100644 --- a/framework/mail/maillistmodel.cpp +++ b/framework/mail/maillistmodel.cpp @@ -1,6 +1,6 @@ #include "maillistmodel.h" -#include "filehtmlwriter.h" +#include "stringhtmlwriter.h" #include "objecttreesource.h" #include @@ -78,8 +78,7 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const msg->parse(); // render the mail - const QString fname("/tmp/test.html"); - FileHtmlWriter htmlWriter(fname); + StringHtmlWriter htmlWriter; QImage paintDevice; MessageViewer::CSSHelper cssHelper(&paintDevice); MessageViewer::NodeHelper nodeHelper; @@ -92,16 +91,9 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const otp.parseObjectTree(msg.data()); htmlWriter.queue(QStringLiteral("")); - htmlWriter.flush(); htmlWriter.end(); - QFile file(fname); - if (file.open(QFile::ReadOnly)) { - const auto content = file.readAll(); - return content; - } else { - qWarning() << "Failed to open the file"; - } + return htmlWriter.html(); } else { qWarning() << "Failed to open the file"; } diff --git a/framework/mail/stringhtmlwriter.cpp b/framework/mail/stringhtmlwriter.cpp new file mode 100644 index 00000000..2c84dc6f --- /dev/null +++ b/framework/mail/stringhtmlwriter.cpp @@ -0,0 +1,134 @@ +/* -*- c++ -*- + filehtmlwriter.cpp + + This file is part of KMail, the KDE mail client. + Copyright (c) 2003 Marc Mutz + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "stringhtmlwriter.h" + +#include +#include + +StringHtmlWriter::StringHtmlWriter() + : MessageViewer::HtmlWriter() + , mState(Ended) +{ +} + +StringHtmlWriter::~StringHtmlWriter() +{ +} + +void StringHtmlWriter::begin(const QString &css) +{ + if (mState != Ended) { + qWarning() << "begin() called on non-ended session!"; + reset(); + } + + mState = Begun; + mExtraHead.clear(); + mHtml.clear(); + + if (!css.isEmpty()) { + write(QLatin1String("\n")); + } +} + +void StringHtmlWriter::end() +{ + if (mState != Begun) { + qWarning() << "Called on non-begun or queued session!"; + } + + if (!mExtraHead.isEmpty()) { + insertExtraHead(); + mExtraHead.clear(); + } + mState = Ended; +} + +void StringHtmlWriter::reset() +{ + if (mState != Ended) { + mHtml.clear(); + mExtraHead.clear(); + mState = Begun; // don't run into end()'s warning + end(); + mState = Ended; + } +} + +void StringHtmlWriter::write(const QString &str) +{ + if (mState != Begun) { + qWarning() << "Called in Ended or Queued state!"; + } + mHtml.append(str); +} + +void StringHtmlWriter::queue(const QString &str) +{ + write(str); +} + +void StringHtmlWriter::flush() +{ + mState = Begun; // don't run into end()'s warning + end(); +} + +void StringHtmlWriter::embedPart(const QByteArray &contentId, const QString &url) +{ + write("\n"); +} +void StringHtmlWriter::extraHead(const QString &extraHead) +{ + if (mState != Ended) { + qWarning() << "Called on non-started session!"; + } + mExtraHead.append(extraHead); +} + + +void StringHtmlWriter::insertExtraHead() +{ + const QString headTag(QStringLiteral("")); + const int index = mHtml.indexOf(headTag); + if (index != -1) { + mHtml.insert(index + headTag.length(), mExtraHead); + } +} + +QString StringHtmlWriter::html() const +{ + if (mState != Ended) { + qWarning() << "Called on non-ended session!"; + } + return mHtml; +} diff --git a/framework/mail/stringhtmlwriter.h b/framework/mail/stringhtmlwriter.h new file mode 100644 index 00000000..0805d027 --- /dev/null +++ b/framework/mail/stringhtmlwriter.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- + + Copyright (c) 2016 Sandro Knauß + + Kube is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + Kube 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KUBE_FRAMEWORK_MAIL_STRINGHTMLWRITER_H__ +#define __KUBE_FRAMEWORK_MAIL_STRINGHTMLWRITER_H__ + +#include + +#include +#include + +class QString; + +class StringHtmlWriter : public MessageViewer::HtmlWriter +{ +public: + explicit StringHtmlWriter(); + virtual ~StringHtmlWriter(); + + void begin(const QString &cssDefs) Q_DECL_OVERRIDE; + void end() Q_DECL_OVERRIDE; + void reset() Q_DECL_OVERRIDE; + void write(const QString &str) Q_DECL_OVERRIDE; + void queue(const QString &str) Q_DECL_OVERRIDE; + void flush() Q_DECL_OVERRIDE; + void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE; + void extraHead(const QString &str) Q_DECL_OVERRIDE; + + QString html() const; +private: + void insertExtraHead(); + + QString mHtml; + QString mExtraHead; + enum State { + Begun, + Queued, + Ended + } mState; +}; + +#endif // __MESSAGEVIEWER_FILEHTMLWRITER_H__ -- cgit v1.2.3 From 9a3059769a0bf9dbf81e523c9245d2aa98420bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Fri, 15 Jan 2016 13:03:29 +0100 Subject: Adopt changes from libOtp * CSSHalper -> CSSHerlperBase * new pure virtual methods from ObjectTreeSourceIf --- framework/mail/maillistmodel.cpp | 4 ++-- framework/mail/objecttreesource.cpp | 21 ++++++++++++++++++--- framework/mail/objecttreesource.h | 8 +++++--- 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'framework') diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp index d3b60187..f7a92097 100644 --- a/framework/mail/maillistmodel.cpp +++ b/framework/mail/maillistmodel.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include MailListModel::MailListModel(QObject *parent) : QIdentityProxyModel() @@ -80,7 +80,7 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const // render the mail StringHtmlWriter htmlWriter; QImage paintDevice; - MessageViewer::CSSHelper cssHelper(&paintDevice); + MessageViewer::CSSHelperBase cssHelper(&paintDevice); MessageViewer::NodeHelper nodeHelper; ObjectTreeSource source(&htmlWriter, &cssHelper); MessageViewer::ObjectTreeParser otp(&source, &nodeHelper); diff --git a/framework/mail/objecttreesource.cpp b/framework/mail/objecttreesource.cpp index cde4775a..1aca5d54 100644 --- a/framework/mail/objecttreesource.cpp +++ b/framework/mail/objecttreesource.cpp @@ -34,14 +34,14 @@ public: } MessageViewer::HtmlWriter *mWriter; - MessageViewer::CSSHelper *mCSSHelper; + MessageViewer::CSSHelperBase *mCSSHelper; bool mAllowDecryption; bool mHtmlLoadExternal; bool mHtmlMail; }; ObjectTreeSource::ObjectTreeSource(MessageViewer::HtmlWriter *writer, - MessageViewer::CSSHelper *cssHelper) + MessageViewer::CSSHelperBase *cssHelper) : MessageViewer::ObjectTreeSourceIf() , d(new ObjectSourcePrivate) { @@ -63,7 +63,7 @@ MessageViewer::HtmlWriter *ObjectTreeSource::htmlWriter() { return d->mWriter; } -MessageViewer::CSSHelper *ObjectTreeSource::cssHelper() +MessageViewer::CSSHelperBase *ObjectTreeSource::cssHelper() { return d->mCSSHelper; } @@ -126,4 +126,19 @@ QObject *ObjectTreeSource::sourceObject() void ObjectTreeSource::setHtmlMode(MessageViewer::Util::HtmlMode mode) { Q_UNUSED(mode); +} + +bool ObjectTreeSource::autoImportKeys() +{ + return false; +} + +bool ObjectTreeSource::showEmoticons() +{ + return false; +} + +bool ObjectTreeSource::showExpandQuotesMark() +{ + return false; } \ No newline at end of file diff --git a/framework/mail/objecttreesource.h b/framework/mail/objecttreesource.h index c61ba715..4823999f 100644 --- a/framework/mail/objecttreesource.h +++ b/framework/mail/objecttreesource.h @@ -29,7 +29,7 @@ class ObjectTreeSource : public MessageViewer::ObjectTreeSourceIf { public: ObjectTreeSource(MessageViewer::HtmlWriter *writer, - MessageViewer::CSSHelper *cssHelper); + MessageViewer::CSSHelperBase *cssHelper); virtual ~ObjectTreeSource(); void setHtmlLoadExternal(bool loadExternal); void setHtmlMail(bool htmlMail); @@ -44,9 +44,11 @@ public: QString createMessageHeader(KMime::Message *message) Q_DECL_OVERRIDE; const MessageViewer::AttachmentStrategy *attachmentStrategy() Q_DECL_OVERRIDE; MessageViewer::HtmlWriter *htmlWriter() Q_DECL_OVERRIDE; - MessageViewer::CSSHelper *cssHelper() Q_DECL_OVERRIDE; + MessageViewer::CSSHelperBase *cssHelper() Q_DECL_OVERRIDE; QObject *sourceObject() Q_DECL_OVERRIDE; - + bool autoImportKeys() Q_DECL_OVERRIDE; + bool showEmoticons() Q_DECL_OVERRIDE; + bool showExpandQuotesMark() Q_DECL_OVERRIDE; private: ObjectSourcePrivate *const d; }; -- cgit v1.2.3