From cd848e07de3cfd164c074cb60a94dc3c6d7abcf1 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Sun, 22 Feb 2009 23:50:27 +0000 Subject: [PATCH] Basic reading and writing of quick notes to and from zionworx playlists --- kworship/filters/zionworx/KwPascalStream.cpp | 13 +++++++++++ kworship/filters/zionworx/KwPascalStream.h | 11 ++++++---- kworship/filters/zionworx/KwZionworxFilter.cpp | 30 ++++++++++++++++++++++++-- kworship/playlist/KwPlaylistPaged.cpp | 13 +++++++++++ kworship/playlist/KwPlaylistPaged.h | 7 +++++- 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/kworship/filters/zionworx/KwPascalStream.cpp b/kworship/filters/zionworx/KwPascalStream.cpp index 65403e5..368f52a 100644 --- a/kworship/filters/zionworx/KwPascalStream.cpp +++ b/kworship/filters/zionworx/KwPascalStream.cpp @@ -102,6 +102,14 @@ QByteArray KwPascalStream::readLString() return m_d->read(len); } +/// Read wide string. +QString KwPascalStream::readWString() +{ + uint32_t len = read32(); + QByteArray data = m_d->read(len>>1); + return QString::fromUtf8(data, data.size()); +} + /// Read UTF8 string. QString KwPascalStream::readUtf8String() { @@ -298,7 +306,12 @@ KwPascalStream& KwPascalStream::operator >> (QVariant& var) case vaSingle: case vaCurrency: case vaDate: + /// @todo Implement missing readers + var = 0; + break; case vaWString: + var = readWString(); + break; case vaInt64: /// @todo Implement missing readers var = 0; diff --git a/kworship/filters/zionworx/KwPascalStream.h b/kworship/filters/zionworx/KwPascalStream.h index e3da25f..be0f2b6 100644 --- a/kworship/filters/zionworx/KwPascalStream.h +++ b/kworship/filters/zionworx/KwPascalStream.h @@ -73,6 +73,9 @@ class KwPascalStream /// Read long string. QByteArray readLString(); + /// Read wide string. + QString readWString(); + /// Read UTF8 string. QString readUtf8String(); @@ -149,22 +152,22 @@ class KwPascalStream vaInt8, vaInt16, vaInt32, - vaExtended, + vaExtended, // 5 vaString, vaIdent, vaFalse, vaTrue, - vaBinary, + vaBinary, // 10 vaSet, vaLString, vaNil, vaCollection, - vaSingle, + vaSingle, // 15 vaCurrency, vaDate, vaWString, vaInt64, - vaUTF8String + vaUTF8String // 20 }; /* diff --git a/kworship/filters/zionworx/KwZionworxFilter.cpp b/kworship/filters/zionworx/KwZionworxFilter.cpp index 2d7b81c..6aa9439 100644 --- a/kworship/filters/zionworx/KwZionworxFilter.cpp +++ b/kworship/filters/zionworx/KwZionworxFilter.cpp @@ -159,8 +159,12 @@ KwDocument* KwZionworxFilter::load(const KUrl& url, const QString& mimeType) } else if (itemType == "siQuickNote") { + QStringList quickNote = readStringList(item.firstChildElement("QuickNote")); + // Rejoin list and split on blank lines + /// @todo Handle more than 2 newlines without losing data + quickNote = quickNote.join("\n").split("\n\n"); KwPlaylistText* note = new KwPlaylistText(item.firstChildElement("Title").text(), - readStringList(item.firstChildElement("QuickNote"))); + quickNote); newItem = note; } else if (itemType == "siBible") @@ -632,7 +636,7 @@ class KwZionworxFilter::ExportToDom /// @todo Store and reload right to leftness of songs. QDomElement item = createPlaylistItem(document, node, "siSong", song->name(), - true); + false); QDomElement title1El = document.createElement("Title1"); if (!song->name().isEmpty()) @@ -672,6 +676,28 @@ class KwZionworxFilter::ExportToDom { QDomElement node = createPlaylistNode(document, element); QDomElement style = createOverlayStyle(document, node, self); + /// @todo Get bi di from text item + QDomElement item = createPlaylistItem(document, node, + "siQuickNote", self->getLabel(), + false); + + QDomElement quickNoteEl = document.createElement("QuickNote"); + quickNoteEl.appendChild(document.createTextNode("(TTntStringList)")); + { + QDomElement definedPropsEl = document.createElement("DefinedProperties"); + QByteArray propsData; + KwPascalStream data(&propsData, QIODevice::WriteOnly); + + QStringList quickNote = self->blocks(); + // resplit on newlines + quickNote = quickNote.join("\n\n").split('\n'); + data.writeProperty("Strings", quickNote); + + propsData = propsData.toBase64(); + definedPropsEl.appendChild(document.createTextNode(propsData)); + quickNoteEl.appendChild(definedPropsEl); + } + item.appendChild(quickNoteEl); return 0; } static int bible(const KwBiblePlaylistItem* self, QDomDocument& document, QDomElement& element) diff --git a/kworship/playlist/KwPlaylistPaged.cpp b/kworship/playlist/KwPlaylistPaged.cpp index 4035b5d..111c554 100644 --- a/kworship/playlist/KwPlaylistPaged.cpp +++ b/kworship/playlist/KwPlaylistPaged.cpp @@ -103,6 +103,19 @@ QString KwPlaylistPaged::getPageText(unsigned int pageIndex) const return m_pageContents[pageIndex]; } +/// Get the list of blocks. +QStringList KwPlaylistPaged::blocks() const +{ + QStringList result; + for (int block = 0; block < m_blockStarts.size(); ++block) + { + unsigned int first = m_blockStarts[block]; + unsigned int count = (block == m_blockStarts.size()-1 ? -1 : m_blockStarts[block+1]-first); + result += QStringList(m_pageContents.mid(first, count)).join("\n"); + } + return result; +} + KwPlaylistNode* KwPlaylistPaged::getNode(KwPlaylistNode* parent) { return new KwPlaylistPagedNode(parent, this); diff --git a/kworship/playlist/KwPlaylistPaged.h b/kworship/playlist/KwPlaylistPaged.h index b5a001c..0007295 100644 --- a/kworship/playlist/KwPlaylistPaged.h +++ b/kworship/playlist/KwPlaylistPaged.h @@ -28,11 +28,13 @@ #include "KwPlaylistItem.h" +#include + #include #include /// A paged plain text playlist item. -class KwPlaylistPaged : public KwPlaylistItem +class KDE_EXPORT KwPlaylistPaged : public KwPlaylistItem { public: @@ -68,6 +70,9 @@ class KwPlaylistPaged : public KwPlaylistItem /// Get the content of a page. QString getPageText(unsigned int pageIndex) const; + /// Get the list of blocks. + QStringList blocks() const; + virtual KwPlaylistNode* getNode(KwPlaylistNode* parent); protected: -- 2.11.4.GIT