mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Get sync to update view
This commit is contained in:
parent
b1415056cb
commit
fb63787d10
@ -54,14 +54,13 @@ Application::Application(int &argc, char **argv) :
|
||||
|
||||
view_.show();
|
||||
|
||||
synchronizerTimer_.setInterval(1000 * 60);
|
||||
synchronizerTimer_.setInterval(1000 * 10);
|
||||
synchronizerTimer_.start();
|
||||
|
||||
connect(&synchronizerTimer_, SIGNAL(timeout()), this, SLOT(synchronizerTimer_timeout()));
|
||||
|
||||
connect(&api_, SIGNAL(requestDone(const QJsonObject&, const QString&)), this, SLOT(api_requestDone(const QJsonObject&, const QString&)));
|
||||
|
||||
|
||||
// Don't store password, store session ID
|
||||
QString clientId = "B6E12222B6E12222";
|
||||
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) {
|
||||
qDebug() << "Folder created" << folderId;
|
||||
synchronizerTimer_.start(1000 * 3);
|
||||
//synchronizerTimer_.start(1000 * 3);
|
||||
}
|
||||
|
||||
void Application::dispatcher_folderUpdated(const QString &folderId) {
|
||||
qDebug() << "Folder udpated" << folderId;
|
||||
synchronizerTimer_.start(1000 * 3);
|
||||
//synchronizerTimer_.start(1000 * 3);
|
||||
}
|
||||
|
||||
void Application::dispatcher_folderDeleted(const QString &folderId) {
|
||||
qDebug() << "Folder deleted" << folderId;
|
||||
synchronizerTimer_.start(1000 * 3);
|
||||
//synchronizerTimer_.start(1000 * 3);
|
||||
}
|
||||
|
||||
void Application::synchronizerTimer_timeout() {
|
||||
synchronizerTimer_.start(1000 * 60);
|
||||
//synchronizerTimer_.start(1000 * 10);
|
||||
synchronizer_.start();
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
#include "foldermodel.h"
|
||||
#include "uuid.h"
|
||||
#include "dispatcher.h"
|
||||
|
||||
using namespace jop;
|
||||
|
||||
FolderModel::FolderModel(Database &database) : QAbstractListModel(), db_(database), orderBy_("title") {
|
||||
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);
|
||||
@ -128,22 +133,22 @@ void FolderModel::addData(const QString &title) {
|
||||
folder.setValue("title", title);
|
||||
if (!folder.save()) return;
|
||||
|
||||
cache_.clear();
|
||||
//cache_.clear();
|
||||
|
||||
lastInsertId_ = folder.id().toString();
|
||||
|
||||
QVector<int> roles;
|
||||
roles << Qt::DisplayRole;
|
||||
// QVector<int> roles;
|
||||
// roles << Qt::DisplayRole;
|
||||
|
||||
int from = 0;
|
||||
int to = rowCount() - 1;
|
||||
// int from = 0;
|
||||
// int to = rowCount() - 1;
|
||||
|
||||
// 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();
|
||||
// // 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);
|
||||
// emit dataChanged(this->index(from), this->index(to), roles);
|
||||
}
|
||||
|
||||
void FolderModel::deleteData(const int index) {
|
||||
@ -159,3 +164,35 @@ void FolderModel::deleteData(const int index) {
|
||||
roles << Qt::DisplayRole;
|
||||
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);
|
||||
}
|
||||
|
@ -54,6 +54,10 @@ public slots:
|
||||
int idToIndex(const QString& id) const;
|
||||
QString lastInsertId() const;
|
||||
|
||||
void dispatcher_folderCreated(const QString& folderId);
|
||||
void dispatcher_folderUpdated(const QString& folderId);
|
||||
void dispatcher_folderDeleted(const QString& folderId);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -131,28 +131,34 @@ void Synchronizer::api_requestDone(const QJsonObject& response, const QString& t
|
||||
}
|
||||
} else if (category == "download") {
|
||||
if (action == "getSynchronizer") {
|
||||
downloadsRemaining_ = 0;
|
||||
QJsonArray items = response["items"].toArray();
|
||||
foreach (QJsonValue item, items) {
|
||||
QJsonObject obj = item.toObject();
|
||||
QString itemId = obj["item_id"].toString();
|
||||
QString itemType = obj["item_type"].toString();
|
||||
QString operationType = obj["type"].toString();
|
||||
QString revId = QString::number(obj["id"].toInt());
|
||||
QString revId = obj["id"].toString();
|
||||
|
||||
QString path = itemType + "s";
|
||||
|
||||
if (operationType == "create") {
|
||||
api_.get(path + "/" + itemId, QUrlQuery(), QUrlQuery(), "download:getFolder:" + itemId + ":" + revId);
|
||||
api_.get(path + "/" + itemId, QUrlQuery(), QUrlQuery(), "download:createFolder:" + itemId + ":" + revId);
|
||||
}
|
||||
|
||||
downloadsRemaining_++;
|
||||
}
|
||||
|
||||
if (!downloadsRemaining_) {
|
||||
qDebug() << "All download operations complete";
|
||||
state_ = Idle;
|
||||
}
|
||||
} else {
|
||||
downloadsRemaining_--;
|
||||
|
||||
Settings settings;
|
||||
|
||||
if (action == "getFolder") {
|
||||
if (action == "createFolder") {
|
||||
Folder folder;
|
||||
folder.loadJsonObject(response);
|
||||
folder.save(false);
|
||||
|
Loading…
Reference in New Issue
Block a user