diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-08 13:47:35 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-08 13:47:35 +0200 |
commit | eb6c831fdcaff4201127585b8c7090d9f60b9ffc (patch) | |
tree | 6ea7c0fa48a056b5e0fa411175efb6e7a915f56a /examples/maildirresource/maildirresource.cpp | |
parent | ed0e4f50cb0131dda1558269cd9801934172e626 (diff) | |
download | sink-eb6c831fdcaff4201127585b8c7090d9f60b9ffc.tar.gz sink-eb6c831fdcaff4201127585b8c7090d9f60b9ffc.zip |
Extracted createFolder function
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 44 |
1 files changed, 19 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 | ||