1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Get sync to update view

This commit is contained in:
Laurent Cozic 2017-01-07 10:40:13 +01:00
parent b1415056cb
commit fb63787d10
4 changed files with 65 additions and 19 deletions

View File

@ -54,14 +54,13 @@ Application::Application(int &argc, char **argv) :
view_.show(); view_.show();
synchronizerTimer_.setInterval(1000 * 60); synchronizerTimer_.setInterval(1000 * 10);
synchronizerTimer_.start(); synchronizerTimer_.start();
connect(&synchronizerTimer_, SIGNAL(timeout()), this, SLOT(synchronizerTimer_timeout())); connect(&synchronizerTimer_, SIGNAL(timeout()), this, SLOT(synchronizerTimer_timeout()));
connect(&api_, SIGNAL(requestDone(const QJsonObject&, const QString&)), this, SLOT(api_requestDone(const QJsonObject&, const QString&))); connect(&api_, SIGNAL(requestDone(const QJsonObject&, const QString&)), this, SLOT(api_requestDone(const QJsonObject&, const QString&)));
// Don't store password, store session ID // Don't store password, store session ID
QString clientId = "B6E12222B6E12222"; QString clientId = "B6E12222B6E12222";
if (!settings.contains("user.email")) { if (!settings.contains("user.email")) {
@ -91,21 +90,21 @@ void Application::api_requestDone(const QJsonObject& response, const QString& ta
void Application::dispatcher_folderCreated(const QString &folderId) { void Application::dispatcher_folderCreated(const QString &folderId) {
qDebug() << "Folder created" << folderId; qDebug() << "Folder created" << folderId;
synchronizerTimer_.start(1000 * 3); //synchronizerTimer_.start(1000 * 3);
} }
void Application::dispatcher_folderUpdated(const QString &folderId) { void Application::dispatcher_folderUpdated(const QString &folderId) {
qDebug() << "Folder udpated" << folderId; qDebug() << "Folder udpated" << folderId;
synchronizerTimer_.start(1000 * 3); //synchronizerTimer_.start(1000 * 3);
} }
void Application::dispatcher_folderDeleted(const QString &folderId) { void Application::dispatcher_folderDeleted(const QString &folderId) {
qDebug() << "Folder deleted" << folderId; qDebug() << "Folder deleted" << folderId;
synchronizerTimer_.start(1000 * 3); //synchronizerTimer_.start(1000 * 3);
} }
void Application::synchronizerTimer_timeout() { void Application::synchronizerTimer_timeout() {
synchronizerTimer_.start(1000 * 60); //synchronizerTimer_.start(1000 * 10);
synchronizer_.start(); synchronizer_.start();
} }

View File

@ -1,10 +1,15 @@
#include "foldermodel.h" #include "foldermodel.h"
#include "uuid.h" #include "uuid.h"
#include "dispatcher.h"
using namespace jop; using namespace jop;
FolderModel::FolderModel(Database &database) : QAbstractListModel(), db_(database), orderBy_("title") { FolderModel::FolderModel(Database &database) : QAbstractListModel(), db_(database), orderBy_("title") {
virtualItemShown_ = false; virtualItemShown_ = false;
connect(&dispatcher(), SIGNAL(folderCreated(QString)), this, SLOT(dispatcher_folderCreated(QString)));
connect(&dispatcher(), SIGNAL(folderUpdated(QString)), this, SLOT(dispatcher_folderUpdated(QString)));
connect(&dispatcher(), SIGNAL(folderDeleted(QString)), this, SLOT(dispatcher_folderDeleted(QString)));
} }
int FolderModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); int FolderModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent);
@ -128,22 +133,22 @@ void FolderModel::addData(const QString &title) {
folder.setValue("title", title); folder.setValue("title", title);
if (!folder.save()) return; if (!folder.save()) return;
cache_.clear(); //cache_.clear();
lastInsertId_ = folder.id().toString(); lastInsertId_ = folder.id().toString();
QVector<int> roles; // QVector<int> roles;
roles << Qt::DisplayRole; // roles << Qt::DisplayRole;
int from = 0; // int from = 0;
int to = rowCount() - 1; // int to = rowCount() - 1;
// Necessary to make sure a new item is added to the view, even // // Necessary to make sure a new item is added to the view, even
// though it might not be positioned there due to sorting // // though it might not be positioned there due to sorting
beginInsertRows(QModelIndex(), to, to); // beginInsertRows(QModelIndex(), to, to);
endInsertRows(); // endInsertRows();
emit dataChanged(this->index(from), this->index(to), roles); // emit dataChanged(this->index(from), this->index(to), roles);
} }
void FolderModel::deleteData(const int index) { void FolderModel::deleteData(const int index) {
@ -159,3 +164,35 @@ void FolderModel::deleteData(const int index) {
roles << Qt::DisplayRole; roles << Qt::DisplayRole;
emit dataChanged(this->index(0), this->index(rowCount() - 1), roles); emit dataChanged(this->index(0), this->index(rowCount() - 1), roles);
} }
void FolderModel::dispatcher_folderCreated(const QString &folderId) {
qDebug() << "FolderModel Folder created" << folderId;
cache_.clear();
// int index = idToIndex(folderId);
// Folder folder = atIndex(index);
int from = 0;
int to = rowCount() - 1;
QVector<int> roles;
roles << Qt::DisplayRole;
// Necessary to make sure a new item is added to the view, even
// though it might not be positioned there due to sorting
beginInsertRows(QModelIndex(), to, to);
endInsertRows();
emit dataChanged(this->index(from), this->index(to), roles);
}
void FolderModel::dispatcher_folderUpdated(const QString &folderId) {
qDebug() << "FolderModel Folder udpated" << folderId;
//synchronizerTimer_.start(1000 * 3);
}
void FolderModel::dispatcher_folderDeleted(const QString &folderId) {
qDebug() << "FolderModel Folder deleted" << folderId;
//synchronizerTimer_.start(1000 * 3);
}

View File

@ -54,6 +54,10 @@ public slots:
int idToIndex(const QString& id) const; int idToIndex(const QString& id) const;
QString lastInsertId() const; QString lastInsertId() const;
void dispatcher_folderCreated(const QString& folderId);
void dispatcher_folderUpdated(const QString& folderId);
void dispatcher_folderDeleted(const QString& folderId);
}; };
} }

View File

@ -131,28 +131,34 @@ void Synchronizer::api_requestDone(const QJsonObject& response, const QString& t
} }
} else if (category == "download") { } else if (category == "download") {
if (action == "getSynchronizer") { if (action == "getSynchronizer") {
downloadsRemaining_ = 0;
QJsonArray items = response["items"].toArray(); QJsonArray items = response["items"].toArray();
foreach (QJsonValue item, items) { foreach (QJsonValue item, items) {
QJsonObject obj = item.toObject(); QJsonObject obj = item.toObject();
QString itemId = obj["item_id"].toString(); QString itemId = obj["item_id"].toString();
QString itemType = obj["item_type"].toString(); QString itemType = obj["item_type"].toString();
QString operationType = obj["type"].toString(); QString operationType = obj["type"].toString();
QString revId = QString::number(obj["id"].toInt()); QString revId = obj["id"].toString();
QString path = itemType + "s"; QString path = itemType + "s";
if (operationType == "create") { if (operationType == "create") {
api_.get(path + "/" + itemId, QUrlQuery(), QUrlQuery(), "download:getFolder:" + itemId + ":" + revId); api_.get(path + "/" + itemId, QUrlQuery(), QUrlQuery(), "download:createFolder:" + itemId + ":" + revId);
} }
downloadsRemaining_++; downloadsRemaining_++;
} }
if (!downloadsRemaining_) {
qDebug() << "All download operations complete";
state_ = Idle;
}
} else { } else {
downloadsRemaining_--; downloadsRemaining_--;
Settings settings; Settings settings;
if (action == "getFolder") { if (action == "createFolder") {
Folder folder; Folder folder;
folder.loadJsonObject(response); folder.loadJsonObject(response);
folder.save(false); folder.save(false);