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
=== modified file 'src/libqtevernote/utils/enmldocument.cpp'
--- src/libqtevernote/utils/enmldocument.cpp 2015-03-08 21:00:25 +0000
+++ src/libqtevernote/utils/enmldocument.cpp 2015-04-13 20:45:34 +0000
@@ -128,15 +128,23 @@
128 break;128 break;
129 }129 }
130 if (type == TypeRichText) {130 if (type == TypeRichText) {
131 QString style = attribute.value().toString();
132
133 // Let's remove any "-qt" attributes that might have ended up in the ENML (earlier versions
134 // of reminders, or other QTextEdit based clients). They are most likely outdated as
135 // Evernote just ignores but still keeps them and might cause issues if the content inside
136 // the <p> changed. TextArea will regenerate them anyways if it thinks they are useful.
137 style.remove(QRegExp("-qt-[a-z-: ]*;"));
138
139 // Now convert some of the ENML style tags to "-qt" tags in order to get the most out
140 // of QTextEdit.
131 if (attribute.value().contains("padding-left")) {141 if (attribute.value().contains("padding-left")) {
132 QString style = attribute.value().toString();
133 int padding = style.split("padding-left:").at(1).split("px").first().toInt();142 int padding = style.split("padding-left:").at(1).split("px").first().toInt();
134 int indent = padding / 30 * 4;143 int indent = padding / 30 * 4;
135 style.replace(QRegExp("padding-left:[ 0-9]*px;"), "-qt-block-indent:" + QString::number(indent) + ";");144 style.replace(QRegExp("padding-left:[ 0-9]*px;"), "-qt-block-indent:" + QString::number(indent) + ";");
136 writer.writeAttribute("style", style);
137 } else {
138 writer.writeAttribute(attribute);
139 }145 }
146
147 writer.writeAttribute("style", style);
140 } else {148 } else {
141 writer.writeAttribute(attribute);149 writer.writeAttribute(attribute);
142 }150 }
@@ -276,6 +284,8 @@
276284
277 writer.writeEndElement();285 writer.writeEndElement();
278 writer.writeEndDocument();286 writer.writeEndDocument();
287 qCDebug(dcEnml) << QString("************** Converting ENML to %1 **************").arg(type == TypeHtml ? "HTML" : "RichText");
288 qCDebug(dcEnml) << QString("Original EML document:") << m_enml;
279 qCDebug(dcEnml) << QString("Converted to %1:").arg(type == TypeHtml ? "HTML" : "RichText") << html;289 qCDebug(dcEnml) << QString("Converted to %1:").arg(type == TypeHtml ? "HTML" : "RichText") << html;
280 return html;290 return html;
281}291}
@@ -346,15 +356,20 @@
346 if (reader.name() == "p") {356 if (reader.name() == "p") {
347 foreach (const QXmlStreamAttribute &attribute, reader.attributes()) {357 foreach (const QXmlStreamAttribute &attribute, reader.attributes()) {
348 if (attribute.name() == "style") {358 if (attribute.name() == "style") {
359 QString style = attribute.value().toString();
360
361 // First convert some of the "-qt" tags added by the QTextArea to ENML style tags
349 if (attribute.value().contains("-qt-block-indent")) {362 if (attribute.value().contains("-qt-block-indent")) {
350 QString style = attribute.value().toString();
351 int indent = style.split("-qt-block-indent:").at(1).split(";").first().toInt();363 int indent = style.split("-qt-block-indent:").at(1).split(";").first().toInt();
352 int padding = indent / 4 * 30;364 int padding = indent / 4 * 30;
353 style.replace(QRegExp("-qt-block-indent:[0-9]*;"), "padding-left:" + QString::number(padding) + "px;");365 style.replace(QRegExp("-qt-block-indent:[0-9]*;"), "padding-left:" + QString::number(padding) + "px;");
354 writer.writeAttribute("style", style);
355 } else {
356 writer.writeAttribute(attribute);
357 }366 }
367
368 // Now let's remove any left "-qt" attributes as they won't do any good to ENML
369 // TextArea will regenerate them anyways when it loads a document without them.
370 style.remove(QRegExp("-qt-[a-z-: ]*;"));
371
372 writer.writeAttribute("style", style);
358 } else {373 } else {
359 writer.writeAttribute(attribute);374 writer.writeAttribute(attribute);
360 }375 }
@@ -414,6 +429,11 @@
414 }429 }
415430
416 writer.writeEndDocument();431 writer.writeEndDocument();
432
433 qCDebug(dcEnml) << QString("************** Converting RichText to ENML **************");
434 qCDebug(dcEnml) << QString("Original RichText:") << richText;
435 qCDebug(dcEnml) << QString("Converted to ENML:") << m_enml;
436
417}437}
418438
419void EnmlDocument::markTodo(const QString &todoId, bool checked)439void EnmlDocument::markTodo(const QString &todoId, bool checked)

Subscribers

People subscribed via source and target branches