From 339a30fd1917011d8ad8a3900509f3a8880d569d Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Thu, 20 Aug 2020 14:54:31 +0200 Subject: [feat] reset error --- gui/backend.go | 9 +++++++-- gui/handlers.cpp | 21 +++++++++++++-------- gui/handlers.h | 4 ++++ gui/main.cpp | 4 +--- gui/qml/LoginOKDialog.qml | 3 +-- 5 files changed, 26 insertions(+), 15 deletions(-) (limited to 'gui') diff --git a/gui/backend.go b/gui/backend.go index a5cb3ab..c953d18 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -23,8 +23,8 @@ func GetAppName() *C.char { } //export Login -func Login(username, password *C.char) { - backend.Login(C.GoString(username), C.GoString(password)) +func Login(username, password string) { + backend.Login(username, password) } //export SwitchOn @@ -76,6 +76,11 @@ func RefreshContext() *C.char { return (*C.char)(backend.RefreshContext()) } +//export ResetError +func ResetError(errname string) { + backend.ResetError(errname) +} + //export InstallHelpers func InstallHelpers() { backend.InstallHelpers() diff --git a/gui/handlers.cpp b/gui/handlers.cpp index 3959964..f34133e 100644 --- a/gui/handlers.cpp +++ b/gui/handlers.cpp @@ -6,6 +6,13 @@ #include "handlers.h" #include "lib/libgoshim.h" +GoString toGoStr(QString s) +{ + char *c = s.toLocal8Bit().data(); + return (GoString){c, (long int)strlen(c)}; +} + + Backend::Backend(QObject *parent) : QObject(parent) { } @@ -37,14 +44,12 @@ void Backend::donateAccepted() void Backend::login(QString username, QString password) { - // TODO: there has to be a cleaner way to do the conversion - char * u = new char [username.length()+1]; - char * p = new char [password.length()+1]; - strcpy(u, username.toStdString().c_str()); - strcpy(p, password.toStdString().c_str()); - Login(u, p); - delete [] u; - delete [] p; + Login(toGoStr(username), toGoStr(password)); +} + +void Backend::resetError(QString errlabel) +{ + ResetError(toGoStr(errlabel)); } void Backend::quit() diff --git a/gui/handlers.h b/gui/handlers.h index 656a451..9299827 100644 --- a/gui/handlers.h +++ b/gui/handlers.h @@ -4,6 +4,9 @@ #include #include #include "qjsonmodel.h" +#include "lib/libgoshim.h" + +GoString toGoStr(QString s); class QJsonWatch : public QObject { @@ -36,6 +39,7 @@ public slots: void switchOff(); void donateAccepted(); void login(QString username, QString password); + void resetError(QString errlabel); void quit(); }; diff --git a/gui/main.cpp b/gui/main.cpp index 2a300e2..e3b8530 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -144,9 +144,7 @@ int main(int argc, char **argv) { /* if requested, enable web api for controlling the VPN */ if (webAPI) { - char* wp = webPort.toLocal8Bit().data(); - GoString p = {wp, (long int)strlen(wp)}; - EnableWebAPI(p); + EnableWebAPI(toGoStr(webPort)); }; /* kick off your shoes, put your feet up */ diff --git a/gui/qml/LoginOKDialog.qml b/gui/qml/LoginOKDialog.qml index 52b3770..be023dd 100644 --- a/gui/qml/LoginOKDialog.qml +++ b/gui/qml/LoginOKDialog.qml @@ -12,9 +12,8 @@ Dialog { } } - // TODO implement cleanNotifications on backend function _loginOk() { - loginDone = true; + backend.resetError("bad_auth") } visible: false -- cgit v1.2.3