1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Don't use dispatcher in QML to avoid threading issue in Android platform

This commit is contained in:
Laurent Cozic 2017-01-11 21:09:50 +01:00
parent 603d5e1370
commit d3e8ce55f9
7 changed files with 76 additions and 8 deletions

View File

@ -15,12 +15,12 @@ LoginPageForm {
Connections {
target: root
onLoginButtonClicked: {
dispatcher.emitLoginClicked(root.apiBaseUrl, root.email, root.password);
appRoot.emitLoginClicked(root.apiBaseUrl, root.email, root.password);
}
}
Connections {
target: dispatcher
target: appRoot
onLoginStarted: {
root.enabled = false;
}
@ -32,4 +32,14 @@ LoginPageForm {
}
}
// Connections {
// target: dispatcher
// onLoginFailed: {
// root.enabled = true;
// }
// onLoginSuccess: {
// root.enabled = true;
// }
// }
}

View File

@ -103,7 +103,7 @@ Item {
text: "Logout"
anchors.right: syncButton.left
anchors.top: parent.top
onClicked: dispatcher.logoutClicked()
onClicked: appRoot.logoutClicked() //dispatcher.logoutClicked()
}
}

View File

@ -13,6 +13,11 @@ Item {
signal addFolderButtonClicked()
signal syncButtonClicked()
signal loginButtonClicked()
signal loginClicked(string apiBaseUrl, string email, string password)
signal loginStarted()
signal loginFailed()
signal loginSuccess()
signal logoutClicked()
property alias currentFolderIndex: mainPage.currentFolderIndex
property alias currentNoteIndex: mainPage.currentNoteIndex
@ -52,6 +57,28 @@ Item {
page.onShown();
}
function emitLoginStarted() {
print("CALLING emitLoginStarted");
root.loginStarted();
}
function emitLoginFailed() {
print("CALLING emitLoginFailed");
root.loginFailed();
}
function emitLoginSuccess() {
root.loginSuccess();
}
function emitLoginClicked(apiBaseUrl, email, password) {
root.loginClicked(apiBaseUrl, email, password);
}
function emitLogoutClicked() {
root.logoutClicked();
}
MainPage {
id: mainPage
anchors.fill: parent

View File

@ -62,12 +62,14 @@ Application::Application(int &argc, char **argv) :
connect(rootObject, SIGNAL(currentNoteChanged()), this, SLOT(view_currentNoteChanged()));
connect(rootObject, SIGNAL(addFolderButtonClicked()), this, SLOT(view_addFolderButtonClicked()));
connect(rootObject, SIGNAL(syncButtonClicked()), this, SLOT(view_syncButtonClicked()));
connect(rootObject, SIGNAL(loginClicked(QString,QString,QString)), this, SLOT(dispatcher_loginClicked(QString,QString,QString)));
connect(rootObject, SIGNAL(logoutClicked()), this, SLOT(dispatcher_logoutClicked()));
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)));
connect(&dispatcher(), SIGNAL(loginClicked(QString,QString,QString)), this, SLOT(dispatcher_loginClicked(QString,QString,QString)));
connect(&dispatcher(), SIGNAL(logoutClicked()), this, SLOT(dispatcher_logoutClicked()));
//connect(&dispatcher(), SIGNAL(loginClicked(QString,QString,QString)), this, SLOT(dispatcher_loginClicked(QString,QString,QString)));
//connect(&dispatcher(), SIGNAL(logoutClicked()), this, SLOT(dispatcher_logoutClicked()));
view_.show();
@ -119,7 +121,9 @@ void Application::api_requestDone(const QJsonObject& response, const QString& ta
if (tag == "getSession") {
if (response.contains("error")) {
qWarning() << "Could not get session:" << response.value("error").toString();
dispatcher().emitLoginFailed();
//dispatcher().emitLoginFailed();
view_.emitSignal("loginFailed");
//qDebug() << "FAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILEDFAILED";
view_.showPage("login");
} else {
QString sessionId = response.value("id").toString();
@ -127,7 +131,8 @@ void Application::api_requestDone(const QJsonObject& response, const QString& ta
Settings settings;
settings.setValue("session.id", sessionId);
afterSessionInitialization();
dispatcher().emitLoginSuccess();
//dispatcher().emitLoginSuccess();
view_.emitSignal("loginSuccess");
view_.showPage("main");
}
return;
@ -151,7 +156,10 @@ void Application::dispatcher_folderDeleted(const QString &folderId) {
void Application::dispatcher_loginClicked(const QString &apiBaseUrl, const QString &email, const QString &password) {
qDebug() << apiBaseUrl << email << password;
dispatcher().emitLoginStarted();
view_.emitSignal("loginStarted");
//dispatcher().emitLoginStarted();
QString newBaseUrl = filters::apiBaseUrl(apiBaseUrl);

View File

@ -9,3 +9,23 @@ void Window::showPage(const QString &pageName) {
QVariant returnedValue;
QMetaObject::invokeMethod((QObject*)rootObject(), "showPage", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, pageNameV));
}
void Window::emitSignal(const QString &name, const QVariantList &args) {
QVariant returnedValue;
QString nameCopy(name);
nameCopy = nameCopy.left(1).toUpper() + nameCopy.right(nameCopy.length() - 1);
nameCopy = "emit" + nameCopy;
qDebug() << "Going to call" << nameCopy;
QObject* o = (QObject*)rootObject();
if (args.size() == 0) {
QMetaObject::invokeMethod(o, nameCopy.toStdString().c_str(), Q_RETURN_ARG(QVariant, returnedValue));
} else if (args.size() == 1) {
QMetaObject::invokeMethod(o, nameCopy.toStdString().c_str(), Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, args[0]));
} else if (args.size() == 2) {
QMetaObject::invokeMethod(o, nameCopy.toStdString().c_str(), Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, args[0]), Q_ARG(QVariant, args[1]));
} else if (args.size() == 3) {
QMetaObject::invokeMethod(o, nameCopy.toStdString().c_str(), Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, args[0]), Q_ARG(QVariant, args[1]), Q_ARG(QVariant, args[2]));
} else {
qCritical() << "Window::emitSignal: add support for more args!" << args.size();
}
}

View File

@ -13,6 +13,7 @@ public:
Window();
void showPage(const QString& pageName);
void emitSignal(const QString& name, const QVariantList& args = QVariantList());
};

View File

@ -156,6 +156,8 @@ switch ($action) {
case 'changes':
// Hack so that all the changes are returned, as if the client requesting them
// was completely new.
$session = execRequest('POST', 'sessions', null, array(
'email' => 'laurent@cozic.net',
'password' => '12345678',