95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
//
|
|
// Created by selim on 03.01.2022.
|
|
//
|
|
|
|
#include "LoginWindow.h"
|
|
#include "MainWindow.h"
|
|
#include "../services/Api.h"
|
|
#include "../coro/GLibMainContextExecutor.h"
|
|
|
|
#include "../gtkpp/HeaderBar.h"
|
|
|
|
#include <iostream>
|
|
#include <folly/experimental/coro/Task.h>
|
|
#include <folly/executors/IOThreadPoolExecutor.h>
|
|
|
|
LoginWindow::LoginWindow() {
|
|
|
|
setDefaultSize(640, 480);
|
|
|
|
_loginEntry.setPlaceholder("Email");
|
|
_loginEntry.setPurpose(GTK_INPUT_PURPOSE_EMAIL);
|
|
_loginEntry.onChanged([this] { validateFields(); });
|
|
|
|
_passwordEntry.setPlaceholder("Password");
|
|
_passwordEntry.setPurpose(GTK_INPUT_PURPOSE_PASSWORD);
|
|
_passwordEntry.setVisibility(false);
|
|
_passwordEntry.onChanged([this] { validateFields(); });
|
|
|
|
_loginButton.setTitle("Log in");
|
|
_loginButton.setVerticalMargins(8);
|
|
_loginButton.setEnabled(false);
|
|
_loginButton.onClick([this] { loginClicked(); });
|
|
|
|
gtkpp::Box contentBox(GTK_ORIENTATION_VERTICAL, 8);
|
|
contentBox.append(_loginEntry);
|
|
contentBox.append(_passwordEntry);
|
|
contentBox.append(_loginButton);
|
|
contentBox.append(_spinner);
|
|
contentBox.setMargins(48);
|
|
contentBox.setVAlign(GTK_ALIGN_CENTER);
|
|
contentBox.setVExpand(true);
|
|
|
|
gtkpp::Box rootBox(GTK_ORIENTATION_VERTICAL, 0);
|
|
rootBox.append(gtkpp::HeaderBar("Login"));
|
|
rootBox.append(contentBox);
|
|
|
|
adw_window_set_content(ADW_WINDOW(_window), rootBox.gobj());
|
|
}
|
|
|
|
void LoginWindow::loginClicked() {
|
|
// auto email = _emailField.get_text();
|
|
// auto password = _passwordField.get_text();
|
|
//
|
|
// enableControls(false);
|
|
// _spinner.start();
|
|
//
|
|
// try {
|
|
// User user = co_await Api::login(email, password).scheduleOn(GLibMainContextExecutor::instance());
|
|
// auto app = this->get_application();
|
|
// auto mainWindow = new MainWindow();
|
|
// mainWindow->show();
|
|
// hide();
|
|
// app->add_window(*mainWindow);
|
|
// app->remove_window(*this);
|
|
// } catch (std::exception& ex) {
|
|
// enableControls(true);
|
|
// _spinner.stop();
|
|
// showError(ex.what());
|
|
// }
|
|
}
|
|
|
|
void LoginWindow::validateFields() {
|
|
// bool buttonEnabled = _emailField.get_text_length() > 0 && _passwordField.get_text_length() > 0;
|
|
// _loginButton.set_sensitive(buttonEnabled);
|
|
}
|
|
|
|
void LoginWindow::showError(const std::string& message) {
|
|
// _dialog = std::make_unique<Gtk::MessageDialog>("Error",
|
|
// false,
|
|
// Gtk::MessageType::ERROR,
|
|
// Gtk::ButtonsType::OK,
|
|
// true);
|
|
// _dialog->set_secondary_text(message);
|
|
// _dialog->set_transient_for(*this);
|
|
// _dialog->set_hide_on_close(true);
|
|
// _dialog->signal_response().connect(sigc::hide(sigc::mem_fun(*_dialog, &Gtk::Widget::hide)));
|
|
// _dialog->show();
|
|
}
|
|
|
|
void LoginWindow::enableControls(bool enable) {
|
|
// _loginButton.set_sensitive(enable);
|
|
// _emailField.set_sensitive(enable);
|
|
// _passwordField.set_sensitive(enable);
|
|
}
|