Very initial implementation of #71.
This commit is contained in:
parent
935ef8c769
commit
09630f1e81
4 changed files with 64 additions and 12 deletions
|
|
@ -219,8 +219,8 @@ void FeedReader::checkServicesForAsyncOperations() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedReader::checkServicesForAsyncOperations(bool wait_for_future) {
|
void FeedReader::checkServicesForAsyncOperations(bool wait_for_future) {
|
||||||
if (m_cacheSaveFutureWatcher->future().isStarted() || m_cacheSaveFutureWatcher->future().isRunning()) {
|
if (m_cacheSaveFutureWatcher->future().isRunning()) {
|
||||||
qDebug("Previous future is still running or was already started.");
|
qDebug("Previous future is still running.");
|
||||||
|
|
||||||
|
|
||||||
// If we want to wait for future synchronously, we want to make sure that
|
// If we want to wait for future synchronously, we want to make sure that
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,6 @@ class ServiceRoot : public RootItem {
|
||||||
virtual void start(bool freshly_activated) = 0;
|
virtual void start(bool freshly_activated) = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
|
||||||
// Is called in short intervals in worker thread.
|
|
||||||
// Service can save its cached data (if any) here.
|
|
||||||
virtual void saveAllCachedData();
|
virtual void saveAllCachedData();
|
||||||
|
|
||||||
// Account ID corresponds with DB attribute Accounts (id).
|
// Account ID corresponds with DB attribute Accounts (id).
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@
|
||||||
|
|
||||||
|
|
||||||
OwnCloudServiceRoot::OwnCloudServiceRoot(RootItem *parent)
|
OwnCloudServiceRoot::OwnCloudServiceRoot(RootItem *parent)
|
||||||
: ServiceRoot(parent), m_recycleBin(new OwnCloudRecycleBin(this)),
|
: ServiceRoot(parent), m_cacheSaveMutex(new Mutex(QMutex::NonRecursive, this)), m_cachedStatesRead(QMap<RootItem::ReadStatus, QStringList>()),
|
||||||
|
m_cachedStatesImportant(QMap<RootItem::Importance, QStringList>()), m_recycleBin(new OwnCloudRecycleBin(this)),
|
||||||
m_actionSyncIn(nullptr), m_serviceMenu(QList<QAction*>()), m_network(new OwnCloudNetworkFactory()) {
|
m_actionSyncIn(nullptr), m_serviceMenu(QList<QAction*>()), m_network(new OwnCloudNetworkFactory()) {
|
||||||
setIcon(OwnCloudServiceEntryPoint().icon());
|
setIcon(OwnCloudServiceEntryPoint().icon());
|
||||||
}
|
}
|
||||||
|
|
@ -112,12 +113,61 @@ OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
||||||
return m_network;
|
return m_network;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OwnCloudServiceRoot::saveAllCachedData() {
|
||||||
|
if (m_cachedStatesRead.isEmpty() && m_cachedStatesImportant.isEmpty()) {
|
||||||
|
// No cached changes.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_cacheSaveMutex->lock();
|
||||||
|
|
||||||
|
// Make copy of changes.
|
||||||
|
QMap<RootItem::ReadStatus, QStringList> cached_data_read = m_cachedStatesRead;
|
||||||
|
cached_data_read.detach();
|
||||||
|
|
||||||
|
QMap<RootItem::Importance, QStringList> cached_data_imp = m_cachedStatesImportant;
|
||||||
|
cached_data_imp.detach();
|
||||||
|
|
||||||
|
m_cachedStatesRead.clear();
|
||||||
|
m_cachedStatesImportant.clear();
|
||||||
|
|
||||||
|
m_cacheSaveMutex->unlock();
|
||||||
|
|
||||||
|
// Save the actual data.
|
||||||
|
for (int i = 0; i < cached_data_read.size(); i++) {
|
||||||
|
auto key = cached_data_read.keys().at(i);
|
||||||
|
QStringList ids = cached_data_read[key];
|
||||||
|
|
||||||
|
if (!ids.isEmpty()) {
|
||||||
|
network()->markMessagesRead(key, ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool OwnCloudServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages,
|
bool OwnCloudServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages,
|
||||||
RootItem::ReadStatus read) {
|
RootItem::ReadStatus read) {
|
||||||
Q_UNUSED(selected_item)
|
Q_UNUSED(selected_item)
|
||||||
|
|
||||||
QNetworkReply::NetworkError reply = network()->markMessagesRead(read, customIDsOfMessages(messages));
|
m_cacheSaveMutex->lock();
|
||||||
return reply == QNetworkReply::NoError;
|
|
||||||
|
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(customIDsOfMessages(messages));
|
||||||
|
|
||||||
|
QSet<QString> set_act = list_act.toSet();
|
||||||
|
QSet<QString> 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();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OwnCloudServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
|
bool OwnCloudServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
|
||||||
|
|
@ -185,8 +235,8 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
|
||||||
|
|
||||||
if (saved) {
|
if (saved) {
|
||||||
if (DatabaseQueries::createOwnCloudAccount(database, id_to_assign, m_network->authUsername(),
|
if (DatabaseQueries::createOwnCloudAccount(database, id_to_assign, m_network->authUsername(),
|
||||||
m_network->authPassword(), m_network->url(),
|
m_network->authPassword(), m_network->url(),
|
||||||
m_network->forceServerSideUpdate())) {
|
m_network->forceServerSideUpdate())) {
|
||||||
setId(id_to_assign);
|
setId(id_to_assign);
|
||||||
setAccountId(id_to_assign);
|
setAccountId(id_to_assign);
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
@ -195,9 +245,6 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OwnCloudServiceRoot::saveAllCachedData() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void OwnCloudServiceRoot::addNewFeed(const QString &url) {
|
void OwnCloudServiceRoot::addNewFeed(const QString &url) {
|
||||||
if (!qApp->feedUpdateLock()->tryLock()) {
|
if (!qApp->feedUpdateLock()->tryLock()) {
|
||||||
// Lock was not obtained because
|
// Lock was not obtained because
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,12 @@
|
||||||
|
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
|
||||||
class OwnCloudNetworkFactory;
|
class OwnCloudNetworkFactory;
|
||||||
class OwnCloudRecycleBin;
|
class OwnCloudRecycleBin;
|
||||||
|
class Mutex;
|
||||||
|
|
||||||
class OwnCloudServiceRoot : public ServiceRoot {
|
class OwnCloudServiceRoot : public ServiceRoot {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -58,6 +61,10 @@ class OwnCloudServiceRoot : public ServiceRoot {
|
||||||
void addNewCategory();
|
void addNewCategory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mutex *m_cacheSaveMutex;
|
||||||
|
QMap<RootItem::ReadStatus, QStringList> m_cachedStatesRead;
|
||||||
|
QMap<RootItem::Importance, QStringList> m_cachedStatesImportant;
|
||||||
|
|
||||||
QMap<int,QVariant> storeCustomFeedsData();
|
QMap<int,QVariant> storeCustomFeedsData();
|
||||||
void restoreCustomFeedsData(const QMap<int,QVariant> &data, const QHash<int,Feed*> &feeds);
|
void restoreCustomFeedsData(const QMap<int,QVariant> &data, const QHash<int,Feed*> &feeds);
|
||||||
RootItem *obtainNewTreeForSyncIn() const;
|
RootItem *obtainNewTreeForSyncIn() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue