diff --git a/resources/scripts/astyle/.astylerc b/resources/scripts/astyle/.astylerc index 2e6be6992..3bfdf0990 100755 --- a/resources/scripts/astyle/.astylerc +++ b/resources/scripts/astyle/.astylerc @@ -21,7 +21,7 @@ --close-templates --max-code-length=140 --lineend=linux ---delete-empty-lines +#--delete-empty-lines --mode=c -t -p -M60Ucv \ No newline at end of file diff --git a/src/services/abstract/cacheforserviceroot.cpp b/src/services/abstract/cacheforserviceroot.cpp index 69e4be18f..57d29b802 100755 --- a/src/services/abstract/cacheforserviceroot.cpp +++ b/src/services/abstract/cacheforserviceroot.cpp @@ -33,36 +33,69 @@ CacheForServiceRoot::~CacheForServiceRoot() { void CacheForServiceRoot::addMessageStatesToCache(const QList& ids_of_messages, RootItem::Importance importance) { m_cacheSaveMutex->lock(); + QList& list_act = m_cachedStatesImportant[importance]; QList& list_other = m_cachedStatesImportant[importance == RootItem::Important ? RootItem::NotImportant : RootItem::Important]; + // Store changes, they will be sent to server later. list_act.append(ids_of_messages); QSet set_act = list_act.toSet(); QSet set_other = list_other.toSet(); + // Now, we want to remove all IDS from list_other, which are contained in list. set_other -= set_act; list_act.clear(); list_act.append(set_act.toList()); list_other.clear(); list_other.append(set_other.toList()); + m_cacheSaveMutex->unlock(); } void CacheForServiceRoot::addMessageStatesToCache(const QStringList& ids_of_messages, RootItem::ReadStatus read) { m_cacheSaveMutex->lock(); + QStringList& list_act = m_cachedStatesRead[read]; QStringList& list_other = m_cachedStatesRead[read == RootItem::Read ? RootItem::Unread : RootItem::Read]; + // Store changes, they will be sent to server later. list_act.append(ids_of_messages); QSet set_act = list_act.toSet(); QSet set_other = list_other.toSet(); + // Now, we want to remove all IDS from list_other, which are contained in list. set_other -= set_act; list_act.clear(); list_act.append(set_act.toList()); list_other.clear(); list_other.append(set_other.toList()); - m_cacheSaveMutex->unlock(); + + m_cacheSaveMutex->unlock(); +} + +void CacheForServiceRoot::saveCacheToFile(int accId) { + m_cacheSaveMutex->lock(); + + // Save to file. + + + + clearCache(); + m_cacheSaveMutex->unlock(); +} + +void CacheForServiceRoot::clearCache() { + m_cachedStatesRead.clear(); + m_cachedStatesImportant.clear(); +} + +void CacheForServiceRoot::loadCacheFromFile(int accId) { + m_cacheSaveMutex->lock(); + clearCache(); + + // Load from file. + + m_cacheSaveMutex->unlock(); } QPair, QMap>> CacheForServiceRoot::takeMessageCache() { @@ -71,16 +104,19 @@ QPair, QMapunlock(); + return QPair, QMap>>(); } // Make copy of changes. QMap cached_data_read = m_cachedStatesRead; cached_data_read.detach(); + QMap> cached_data_imp = m_cachedStatesImportant; cached_data_imp.detach(); - m_cachedStatesRead.clear(); - m_cachedStatesImportant.clear(); + + clearCache(); m_cacheSaveMutex->unlock(); + return QPair, QMap>>(cached_data_read, cached_data_imp); } diff --git a/src/services/abstract/cacheforserviceroot.h b/src/services/abstract/cacheforserviceroot.h index 4c867f098..74034abc2 100755 --- a/src/services/abstract/cacheforserviceroot.h +++ b/src/services/abstract/cacheforserviceroot.h @@ -35,6 +35,11 @@ class CacheForServiceRoot { void addMessageStatesToCache(const QList& ids_of_messages, RootItem::Importance importance); void addMessageStatesToCache(const QStringList& ids_of_messages, RootItem::ReadStatus read); + // Persistently saves/loads cached changes to/from file. + // NOTE: The whole cache is cleared after save is done and before load is done. + void saveCacheToFile(int accId); + void loadCacheFromFile(int accId); + protected: QPair, QMap>> takeMessageCache();