##// END OF EJS Templates
Addd save methods. Fix bug with work repository suffix handling
perrinel -
r1279:4e7a8f2af91d
parent child
Show More
@@ -22,8 +22,8 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22 22
23 23 namespace {
24 24
25 static QString REPOSITORY_WORK_SUFFIX = QString{"work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"};
25 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 27 }
28 28
29 29 class CatalogueController::CatalogueControllerPrivate {
@@ -40,6 +40,10 public:
40 40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 41 QString toWorkRepository(QString repository);
42 42 QString toSyncRepository(QString repository);
43 void savAllDB();
44
45 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
46 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
43 47 };
44 48
45 49 CatalogueController::CatalogueController(QObject *parent)
@@ -132,7 +136,7 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> ca
132 136
133 137 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
134 138 {
135 event->setRepository(impl->toSyncRepository(event->getRepository()));
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
136 140
137 141 impl->m_CatalogueDao.updateEvent(*event);
138 142 }
@@ -171,7 +175,7 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
171 175
172 176 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
173 177 {
174 impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true);
178 impl->saveEvent(event, true);
175 179 }
176 180
177 181 std::list<std::shared_ptr<DBCatalogue> >
@@ -189,7 +193,7 CatalogueController::retrieveCatalogues(const QString &repository) const
189 193
190 194 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
191 195 {
192 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
196 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
193 197
194 198 impl->m_CatalogueDao.updateCatalogue(*catalogue);
195 199 }
@@ -205,8 +209,7 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
205 209
206 210 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
207 211 {
208 impl->m_CatalogueDao.moveCatalogue(*catalogue,
209 impl->toSyncRepository(catalogue->getRepository()), true);
212 impl->saveCatalogue(catalogue, true);
210 213 }
211 214
212 215 void CatalogueController::saveAll()
@@ -215,15 +218,17 void CatalogueController::saveAll()
215 218 // Save Event
216 219 auto events = this->retrieveEvents(repository);
217 220 for (auto event : events) {
218 this->saveEvent(event);
221 impl->saveEvent(event, false);
219 222 }
220 223
221 224 // Save Catalogue
222 225 auto catalogues = this->retrieveCatalogues(repository);
223 226 for (auto catalogue : catalogues) {
224 this->saveCatalogue(catalogue);
227 impl->saveCatalogue(catalogue, false);
225 228 }
226 229 }
230
231 impl->savAllDB();
227 232 }
228 233
229 234 void CatalogueController::initialize()
@@ -290,7 +295,7 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QStrin
290 295 {
291 296 auto syncRepository = toSyncRepository(repository);
292 297
293 return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
298 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
294 299 }
295 300
296 301 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
@@ -304,3 +309,30 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QStrin
304 309 }
305 310 return syncRepository;
306 311 }
312
313 void CatalogueController::CatalogueControllerPrivate::savAllDB()
314 {
315 for (auto repository : m_RepositoryList) {
316 auto defaultRepositoryLocation
317 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
318 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
319 }
320 }
321
322 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
323 bool persist)
324 {
325 m_CatalogueDao.moveEvent(*event, toSyncRepository(event->getRepository()), true);
326 if (persist) {
327 savAllDB();
328 }
329 }
330
331 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
332 std::shared_ptr<DBCatalogue> catalogue, bool persist)
333 {
334 m_CatalogueDao.moveCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
335 if (persist) {
336 savAllDB();
337 }
338 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now