diff options
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 44 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.h | 1 |
2 files changed, 20 insertions, 25 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 4505373..f4833a8 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -98,20 +98,8 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh | |||
98 | auto transaction = mainStore->createTransaction(Sink::Storage::ReadOnly); | 98 | auto transaction = mainStore->createTransaction(Sink::Storage::ReadOnly); |
99 | auto synchronizationTransaction = syncStore->createTransaction(Sink::Storage::ReadWrite); | 99 | auto synchronizationTransaction = syncStore->createTransaction(Sink::Storage::ReadWrite); |
100 | 100 | ||
101 | auto folderPath = mDraftsFolder; | 101 | auto remoteId = createFolder(mDraftsFolder, "folder", transaction, synchronizationTransaction); |
102 | auto remoteId = folderPath.toUtf8(); | 102 | auto draftsFolderLocalId = resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId, synchronizationTransaction); |
103 | auto bufferType = ENTITY_TYPE_FOLDER; | ||
104 | KPIM::Maildir md(folderPath, folderPath == mMaildirPath); | ||
105 | Sink::ApplicationDomain::Folder folder; | ||
106 | folder.setProperty("name", md.name()); | ||
107 | folder.setProperty("icon", "folder"); | ||
108 | |||
109 | if (!md.isRoot()) { | ||
110 | folder.setProperty("parent", resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8(), synchronizationTransaction)); | ||
111 | } | ||
112 | createOrModify(transaction, synchronizationTransaction, *mFolderAdaptorFactory, bufferType, remoteId, folder); | ||
113 | |||
114 | auto draftsFolderLocalId = resolveRemoteId(ENTITY_TYPE_FOLDER, mDraftsFolder.toUtf8(), synchronizationTransaction); | ||
115 | synchronizationTransaction.commit(); | 103 | synchronizationTransaction.commit(); |
116 | 104 | ||
117 | folderUpdater->mDraftsFolder = draftsFolderLocalId; | 105 | folderUpdater->mDraftsFolder = draftsFolderLocalId; |
@@ -132,6 +120,22 @@ static QStringList listRecursive( const QString &root, const KPIM::Maildir &dir | |||
132 | return list; | 120 | return list; |
133 | } | 121 | } |
134 | 122 | ||
123 | QByteArray MaildirResource::createFolder(const QString &folderPath, const QByteArray &icon, Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction) | ||
124 | { | ||
125 | auto remoteId = folderPath.toUtf8(); | ||
126 | auto bufferType = ENTITY_TYPE_FOLDER; | ||
127 | KPIM::Maildir md(folderPath, folderPath == mMaildirPath); | ||
128 | Sink::ApplicationDomain::Folder folder; | ||
129 | folder.setProperty("name", md.name()); | ||
130 | folder.setProperty("icon", "folder"); | ||
131 | |||
132 | if (!md.isRoot()) { | ||
133 | folder.setProperty("parent", resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8(), synchronizationTransaction)); | ||
134 | } | ||
135 | createOrModify(transaction, synchronizationTransaction, *mFolderAdaptorFactory, bufferType, remoteId, folder); | ||
136 | return remoteId; | ||
137 | } | ||
138 | |||
135 | QStringList MaildirResource::listAvailableFolders() | 139 | QStringList MaildirResource::listAvailableFolders() |
136 | { | 140 | { |
137 | KPIM::Maildir dir(mMaildirPath, true); | 141 | KPIM::Maildir dir(mMaildirPath, true); |
@@ -168,17 +172,7 @@ void MaildirResource::synchronizeFolders(Sink::Storage::Transaction &transaction | |||
168 | ); | 172 | ); |
169 | 173 | ||
170 | for (const auto folderPath : folderList) { | 174 | for (const auto folderPath : folderList) { |
171 | const auto remoteId = folderPath.toUtf8(); | 175 | createFolder(folderPath, "folder", transaction, synchronizationTransaction); |
172 | Trace() << "Processing folder " << remoteId; | ||
173 | KPIM::Maildir md(folderPath, folderPath == mMaildirPath); | ||
174 | |||
175 | Sink::ApplicationDomain::Folder folder; | ||
176 | folder.setProperty("name", md.name()); | ||
177 | folder.setProperty("icon", "folder"); | ||
178 | if (!md.isRoot()) { | ||
179 | folder.setProperty("parent", resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8(), synchronizationTransaction)); | ||
180 | } | ||
181 | createOrModify(transaction, synchronizationTransaction, *mFolderAdaptorFactory, bufferType, remoteId, folder); | ||
182 | } | 176 | } |
183 | } | 177 | } |
184 | 178 | ||
diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index 2afd0ed..33ba3ae 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h | |||
@@ -54,6 +54,7 @@ private: | |||
54 | 54 | ||
55 | void synchronizeFolders(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction); | 55 | void synchronizeFolders(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction); |
56 | void synchronizeMails(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QString &folder); | 56 | void synchronizeMails(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QString &folder); |
57 | QByteArray createFolder(const QString &folderPath, const QByteArray &icon, Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction); | ||
57 | QStringList listAvailableFolders(); | 58 | QStringList listAvailableFolders(); |
58 | QString mMaildirPath; | 59 | QString mMaildirPath; |
59 | QString mDraftsFolder; | 60 | QString mDraftsFolder; |