You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
api sync
This commit is contained in:
@ -4,11 +4,20 @@
|
||||
#include "database.h"
|
||||
#include "models/foldermodel.h"
|
||||
#include "services/folderservice.h"
|
||||
#include "settings.h"
|
||||
|
||||
using namespace jop;
|
||||
|
||||
Application::Application(int &argc, char **argv) : QGuiApplication(argc, argv) {
|
||||
db_ = Database("D:/Web/www/joplin/QtClient/data/notes.sqlite");
|
||||
Application::Application(int &argc, char **argv) : QGuiApplication(argc, argv), db_("D:/Web/www/joplin/QtClient/data/notes.sqlite"), api_("http://joplin.local"), synchronizer_(api_, db_) {
|
||||
// This is linked to where the QSettings will be saved. In other words,
|
||||
// if these values are changed, the settings will be reset and saved
|
||||
// somewhere else.
|
||||
QCoreApplication::setOrganizationName("Cozic");
|
||||
QCoreApplication::setOrganizationDomain("cozic.net");
|
||||
QCoreApplication::setApplicationName("Joplin");
|
||||
|
||||
Settings settings;
|
||||
|
||||
folderService_ = FolderService(db_);
|
||||
folderModel_.setService(folderService_);
|
||||
|
||||
@ -29,6 +38,31 @@ Application::Application(int &argc, char **argv) : QGuiApplication(argc, argv) {
|
||||
connect(rootObject, SIGNAL(currentNoteChanged()), this, SLOT(view_currentNoteChanged()));
|
||||
|
||||
view_.show();
|
||||
|
||||
connect(&api_, SIGNAL(requestDone(const QJsonObject&, const QString&)), this, SLOT(api_requestDone(const QJsonObject&, const QString&)));
|
||||
|
||||
QString sessionId = settings.value("sessionId").toString();
|
||||
if (sessionId == "") {
|
||||
QUrlQuery postData;
|
||||
postData.addQueryItem("email", "laurent@cozic.net");
|
||||
postData.addQueryItem("password", "12345678");
|
||||
postData.addQueryItem("client_id", "B6E12222B6E12222");
|
||||
api_.post("sessions", QUrlQuery(), postData, "getSession");
|
||||
} else {
|
||||
afterSessionInitialization();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::api_requestDone(const QJsonObject& response, const QString& tag) {
|
||||
// TODO: handle errors
|
||||
|
||||
if (tag == "getSession") {
|
||||
QString sessionId = response.value("id").toString();
|
||||
Settings settings;
|
||||
settings.setValue("sessionId", sessionId);
|
||||
afterSessionInitialization();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QString Application::selectedFolderId() const {
|
||||
@ -47,6 +81,17 @@ QString Application::selectedNoteId() const {
|
||||
return noteModel_.data(modelIndex, NoteModel::IdRole).toString();
|
||||
}
|
||||
|
||||
void Application::afterSessionInitialization() {
|
||||
// TODO: rather than saving the session id, save the username/password and
|
||||
// request a new session everytime on startup.
|
||||
|
||||
Settings settings;
|
||||
QString sessionId = settings.value("sessionId").toString();
|
||||
qDebug() << "Session:" << sessionId;
|
||||
api_.setSessionId(sessionId);
|
||||
synchronizer_.start();
|
||||
}
|
||||
|
||||
void Application::view_currentFolderChanged() {
|
||||
QString folderId = selectedFolderId();
|
||||
noteCollection_ = NoteCollection(db_, folderId, "title ASC");
|
||||
|
Reference in New Issue
Block a user