libquentier 0.5.0
The library for rich desktop clients of Evernote service
Loading...
Searching...
No Matches
ENMLConverter.h
1/*
2 * Copyright 2016-2020 Dmitry Ivanov
3 *
4 * This file is part of libquentier
5 *
6 * libquentier is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, version 3 of the License.
9 *
10 * libquentier is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LIB_QUENTIER_ENML_ENML_CONVERTER_H
20#define LIB_QUENTIER_ENML_ENML_CONVERTER_H
21
22#include <quentier/types/ErrorString.h>
23#include <quentier/types/Note.h>
24#include <quentier/utility/Linkage.h>
25#include <quentier/utility/Printable.h>
26
27#include <QHash>
28#include <QSet>
29#include <QString>
30#include <QTextDocument>
31
32namespace quentier {
33
34QT_FORWARD_DECLARE_CLASS(DecryptedTextManager)
35QT_FORWARD_DECLARE_CLASS(ENMLConverterPrivate)
36QT_FORWARD_DECLARE_CLASS(Resource)
37
38
43class QUENTIER_EXPORT ENMLConverter
44{
45public:
47
48 virtual ~ENMLConverter();
49
60 class QUENTIER_EXPORT SkipHtmlElementRule : public Printable
61 {
62 public:
63 enum class ComparisonRule
64 {
65 Equals = 0,
66 StartsWith,
67 EndsWith,
68 Contains
69 };
70
71 friend QUENTIER_EXPORT QTextStream & operator<<(
72 QTextStream & strm, const ComparisonRule rule);
73
74 virtual QTextStream & print(QTextStream & strm) const override;
75
76 QString m_elementNameToSkip;
77 ComparisonRule m_elementNameComparisonRule = ComparisonRule::Equals;
78 Qt::CaseSensitivity m_elementNameCaseSensitivity = Qt::CaseSensitive;
79
80 QString m_attributeNameToSkip;
81 ComparisonRule m_attributeNameComparisonRule = ComparisonRule::Equals;
82 Qt::CaseSensitivity m_attributeNameCaseSensitivity = Qt::CaseSensitive;
83
84 QString m_attributeValueToSkip;
85 ComparisonRule m_attributeValueComparisonRule = ComparisonRule::Equals;
86 Qt::CaseSensitivity m_attributeValueCaseSensitivity = Qt::CaseSensitive;
87
88 bool m_includeElementContents = false;
89 };
90
91 bool htmlToNoteContent(
92 const QString & html, QString & noteContent,
93 DecryptedTextManager & decryptedTextManager,
94 ErrorString & errorDescription,
95 const QVector<SkipHtmlElementRule> & skipRules = {}) const;
96
111 const QString & inputHtml, QString & cleanedUpHtml,
112 ErrorString & errorDescription) const;
113
128 const QString & html, QTextDocument & doc,
129 ErrorString & errorDescription,
130 const QVector<SkipHtmlElementRule> & skipRules = {}) const;
131
133 {
134 quint64 m_numEnToDoNodes = 0;
135 quint64 m_numHyperlinkNodes = 0;
136 quint64 m_numEnCryptNodes = 0;
137 quint64 m_numEnDecryptedNodes = 0;
138 };
139
140 bool noteContentToHtml(
141 const QString & noteContent, QString & html,
142 ErrorString & errorDescription,
143 DecryptedTextManager & decryptedTextManager,
144 NoteContentToHtmlExtraData & extraData) const;
145
146 bool validateEnml(
147 const QString & enml, ErrorString & errorDescription) const;
148
149 bool validateAndFixupEnml(
150 QString & enml, ErrorString & errorDescription) const;
151
152 static bool noteContentToPlainText(
153 const QString & noteContent, QString & plainText,
154 ErrorString & errorMessage);
155
156 static bool noteContentToListOfWords(
157 const QString & noteContent, QStringList & listOfWords,
158 ErrorString & errorMessage, QString * plainText = nullptr);
159
160 static QStringList plainTextToListOfWords(const QString & plainText);
161
162 static QString toDoCheckboxHtml(const bool checked, const quint64 idNumber);
163
164 static QString encryptedTextHtml(
165 const QString & encryptedText, const QString & hint,
166 const QString & cipher, const size_t keyLength,
167 const quint64 enCryptIndex);
168
169 static QString decryptedTextHtml(
170 const QString & decryptedText, const QString & encryptedText,
171 const QString & hint, const QString & cipher, const size_t keyLength,
172 const quint64 enDecryptedIndex);
173
174 static QString resourceHtml(
175 const Resource & resource, ErrorString & errorDescription);
176
177 static void escapeString(QString & string, const bool simplify = true);
178
183 enum class EnexExportTags
184 {
185 Yes = 0,
186 No
187 };
188
218 const QVector<Note> & notes,
219 const QHash<QString, QString> & tagNamesByTagLocalUids,
220 const EnexExportTags exportTagsOption, QString & enex,
221 ErrorString & errorDescription, const QString & version = {}) const;
222
242 const QString & enex, QVector<Note> & notes,
243 QHash<QString, QStringList> & tagNamesByNoteLocalUid,
244 ErrorString & errorDescription) const;
245
246private:
247 Q_DISABLE_COPY(ENMLConverter)
248
249private:
250 ENMLConverterPrivate * const d_ptr;
251 Q_DECLARE_PRIVATE(ENMLConverter)
252};
253
254} // namespace quentier
255
256#endif // LIB_QUENTIER_ENML_ENML_CONVERTER_H
Definition DecryptedTextManager.h:31
The SkipHtmlElementRule class describes the set of rules for HTML -> ENML conversion about the HTML e...
Definition ENMLConverter.h:61
The ENMLConverter class encapsulates a set of methods and helper data structures for performing the c...
Definition ENMLConverter.h:44
bool exportNotesToEnex(const QVector< Note > &notes, const QHash< QString, QString > &tagNamesByTagLocalUids, const EnexExportTags exportTagsOption, QString &enex, ErrorString &errorDescription, const QString &version={}) const
exportNotesToEnex exports either a single note or a set of notes into ENEX format
EnexExportTags
The EnexExportTags enum allows to specify whether export of note(s) to ENEX should include the names ...
Definition ENMLConverter.h:184
bool importEnex(const QString &enex, QVector< Note > &notes, QHash< QString, QStringList > &tagNamesByNoteLocalUid, ErrorString &errorDescription) const
importEnex reads the content of input ENEX file and converts it into a set of notes and tag names.
bool cleanupExternalHtml(const QString &inputHtml, QString &cleanedUpHtml, ErrorString &errorDescription) const
cleanupExternalHtml method cleans up a piece of HTML coming from some external source: the cleanup in...
bool htmlToQTextDocument(const QString &html, QTextDocument &doc, ErrorString &errorDescription, const QVector< SkipHtmlElementRule > &skipRules={}) const
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition ErrorString.h:44
The Printable class is the interface for Quentier's internal classes which should be able to write th...
Definition Printable.h:38
Definition Resource.h:30