Take the ENML note and transform it into HTML that WebKit will not complain about */
| 115 | /* Take the ENML note and transform it into HTML that WebKit will |
| 116 | not complain about */ |
| 117 | QByteArray NoteFormatter::rebuildNoteHTML() { |
| 118 | QLOG_TRACE() << "Rebuilding HTML"; |
| 119 | |
| 120 | formatError = false; |
| 121 | readOnly = false; |
| 122 | |
| 123 | ResourceTable resTable(global.db); |
| 124 | if (!note.guid.isSet()) { |
| 125 | formatError=true; |
| 126 | readOnly=true; |
| 127 | QLOG_TRACE() << "NOTE GUID IS NOT SET!!!"; |
| 128 | } else { |
| 129 | QLOG_TRACE() << "getting resource from hash"; |
| 130 | resTable.getResourceMap(hashMap, resourceMap, note.guid); |
| 131 | } |
| 132 | |
| 133 | QWebPage page; |
| 134 | QEventLoop loop; |
| 135 | QLOG_TRACE() << "Before preHTMLFormat"; |
| 136 | QString html = "<body></body>"; |
| 137 | if (note.content.isSet()) |
| 138 | html = preHtmlFormat(note.content); |
| 139 | html.replace("<en-note", "<body"); |
| 140 | html.replace("</en-note>", "</body>"); |
| 141 | QByteArray htmlPage; |
| 142 | htmlPage.append(html); |
| 143 | QLOG_TRACE() << "About to set content"; |
| 144 | page.mainFrame()->setContent(htmlPage); |
| 145 | QObject::connect(&page, SIGNAL(loadFinished(bool)), &loop, SLOT(quit())); |
| 146 | |
| 147 | QLOG_TRACE() << "Starting to modify tags"; |
| 148 | modifyTags(page); |
| 149 | QLOG_TRACE() << "Done modifying tags"; |
| 150 | note.content = page.mainFrame()->toHtml(); |
| 151 | content.clear(); |
| 152 | content.append(note.content); |
| 153 | |
| 154 | qint32 index = content.indexOf("<body"); |
| 155 | content.remove(0,index); |
| 156 | content.prepend("<style>img { height:auto; width:auto; max-height:auto; max-width:100%; }</style>"); |
| 157 | content.prepend("<head><meta http-equiv=\"content-type\" content=\"text-html; charset=utf-8\"></head>"); |
| 158 | content.prepend("<html>"); |
| 159 | content.append("</html>"); |
| 160 | |
| 161 | if (!formatError && !readOnly) { |
| 162 | NotebookTable ntable(global.db); |
| 163 | if (note.notebookGuid.isSet()) { |
| 164 | qint32 notebookLid = ntable.getLid(note.notebookGuid); |
| 165 | if (ntable.isReadOnly(notebookLid)) { |
| 166 | QLOG_DEBUG() << "Notebook is read-only. Marking note read-only."; |
| 167 | readOnly = true; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | if (note.active.isSet() && !note.active) { |
| 172 | QLOG_DEBUG() << "Note is inactive. Setting to read-only."; |
| 173 | readOnly = true; |
| 174 | } |
no test coverage detected