Merge lp:~mzanetti/reminders-app/fix-stale-qt-tags into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 409
Merged at revision: 411
Proposed branch: lp:~mzanetti/reminders-app/fix-stale-qt-tags
Merge into: lp:reminders-app
Diff against target: 77 lines (+28/-8)
1 file modified
src/libqtevernote/utils/enmldocument.cpp (+28/-8)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/fix-stale-qt-tags
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+255894@code.launchpad.net

Commit message

fix data loss because of stale "-qt" tags in the markup

Description of the change

I caught a data loss bug that happened with a note of mine. Afaiu, this can happen if you create a note with reminders and just add some empty lines (paragraphs). The QTextEdit will set a style attribute to it like:

<p style="-qt-paragraph-type: empty;"> </p>

If this is sent to Evernote and the user edits this paragraph on the website, it will add content to the paragraph but still keep that attribute, not knowing about it but still trying to play nice on other clients and keep their special attributes.

When this comes back to reminders, QTextEdit will get confused about the paragraph being marked as an empty one but still having text, effectively, not displaying half of the content in this paragraph. Saving such a note will permanently drop parts of the paragraph and sync the result back to Evernote.

As a fix, I now completely clean up all the "-qt-*" tags generated by the QTextArea when converting the content back to ENML. That might make rendering next time a wee little slower, as the QTextEdit seems to regenerate those tags, but gives me a much better feeling than having stale attributes floating around - and fixes the content loss with my test note here.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

I have got warnings compiling:

/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp: In member function ‘QString EnmlDocument::convert(const QString&, EnmlDocument::Type) const’:
/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp:137:54: warning: unknown escape sequence: '\-'
                                 style.remove(QRegExp("-qt-[a-z\-\: ]*;"));
                                                      ^
/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp:137:54: warning: unknown escape sequence: '\:'
/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp: In member function ‘void EnmlDocument::setRichText(const QString&)’:
/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp:370:54: warning: unknown escape sequence: '\-'
                                 style.remove(QRegExp("-qt-[a-z\-\: ]*;"));
                                                      ^
/home/rpadovani/Documents/ubuntu/touch/core-apps/reminders-app/fix-stale-qt-tags/src/libqtevernote/utils/enmldocument.cpp:370:54: warning: unknown escape sequence: '\:'

review: Needs Fixing
409. By Michael Zanetti

fix warnings

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libqtevernote/utils/enmldocument.cpp'
2--- src/libqtevernote/utils/enmldocument.cpp 2015-03-08 21:00:25 +0000
3+++ src/libqtevernote/utils/enmldocument.cpp 2015-04-13 20:45:34 +0000
4@@ -128,15 +128,23 @@
5 break;
6 }
7 if (type == TypeRichText) {
8+ QString style = attribute.value().toString();
9+
10+ // Let's remove any "-qt" attributes that might have ended up in the ENML (earlier versions
11+ // of reminders, or other QTextEdit based clients). They are most likely outdated as
12+ // Evernote just ignores but still keeps them and might cause issues if the content inside
13+ // the <p> changed. TextArea will regenerate them anyways if it thinks they are useful.
14+ style.remove(QRegExp("-qt-[a-z-: ]*;"));
15+
16+ // Now convert some of the ENML style tags to "-qt" tags in order to get the most out
17+ // of QTextEdit.
18 if (attribute.value().contains("padding-left")) {
19- QString style = attribute.value().toString();
20 int padding = style.split("padding-left:").at(1).split("px").first().toInt();
21 int indent = padding / 30 * 4;
22 style.replace(QRegExp("padding-left:[ 0-9]*px;"), "-qt-block-indent:" + QString::number(indent) + ";");
23- writer.writeAttribute("style", style);
24- } else {
25- writer.writeAttribute(attribute);
26 }
27+
28+ writer.writeAttribute("style", style);
29 } else {
30 writer.writeAttribute(attribute);
31 }
32@@ -276,6 +284,8 @@
33
34 writer.writeEndElement();
35 writer.writeEndDocument();
36+ qCDebug(dcEnml) << QString("************** Converting ENML to %1 **************").arg(type == TypeHtml ? "HTML" : "RichText");
37+ qCDebug(dcEnml) << QString("Original EML document:") << m_enml;
38 qCDebug(dcEnml) << QString("Converted to %1:").arg(type == TypeHtml ? "HTML" : "RichText") << html;
39 return html;
40 }
41@@ -346,15 +356,20 @@
42 if (reader.name() == "p") {
43 foreach (const QXmlStreamAttribute &attribute, reader.attributes()) {
44 if (attribute.name() == "style") {
45+ QString style = attribute.value().toString();
46+
47+ // First convert some of the "-qt" tags added by the QTextArea to ENML style tags
48 if (attribute.value().contains("-qt-block-indent")) {
49- QString style = attribute.value().toString();
50 int indent = style.split("-qt-block-indent:").at(1).split(";").first().toInt();
51 int padding = indent / 4 * 30;
52 style.replace(QRegExp("-qt-block-indent:[0-9]*;"), "padding-left:" + QString::number(padding) + "px;");
53- writer.writeAttribute("style", style);
54- } else {
55- writer.writeAttribute(attribute);
56 }
57+
58+ // Now let's remove any left "-qt" attributes as they won't do any good to ENML
59+ // TextArea will regenerate them anyways when it loads a document without them.
60+ style.remove(QRegExp("-qt-[a-z-: ]*;"));
61+
62+ writer.writeAttribute("style", style);
63 } else {
64 writer.writeAttribute(attribute);
65 }
66@@ -414,6 +429,11 @@
67 }
68
69 writer.writeEndDocument();
70+
71+ qCDebug(dcEnml) << QString("************** Converting RichText to ENML **************");
72+ qCDebug(dcEnml) << QString("Original RichText:") << richText;
73+ qCDebug(dcEnml) << QString("Converted to ENML:") << m_enml;
74+
75 }
76
77 void EnmlDocument::markTodo(const QString &todoId, bool checked)

Subscribers

People subscribed via source and target branches