1
0
forked from BRT/arc
arc/views/widget/loader/RegistrationWindow.cpp
trnsmkot 8bc198a787 Add SettingsDAO implementation, schema migration, and related updates
Implemented `SettingsDAO` with `get`, `set`, `remove`, and related methods for key-value storage. Added database schema migration for a new `settings` table. Updated `EventDAO` with error handling improvements and `AbstractDAO` with helper utilities. Enhanced Ozon scripts with ad banner detection and handling.
2026-03-09 15:53:35 +07:00

79 lines
2.8 KiB
C++

#include "RegistrationWindow.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QThread>
#include <QSettings>
#include "LoaderDialog.h"
#include "dao/SettingsDAO.h"
#include "net/NetworkService.h"
RegistrationWindow::RegistrationWindow(QWidget *parent): QWidget(parent) {
setWindowTitle("Вход");
resize(300, 130);
auto *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel("Введите API ключ:"));
QLineEdit *apiKeyEdit = new QLineEdit();
apiKeyEdit->setPlaceholderText("API ключ");
layout->addWidget(apiKeyEdit);
QHBoxLayout *buttonLayout = new QHBoxLayout();
QPushButton *loginButton = new QPushButton("Войти");
QPushButton *closeButton = new QPushButton("Закрыть");
buttonLayout->addWidget(loginButton);
buttonLayout->addWidget(closeButton);
layout->addLayout(buttonLayout);
connect(closeButton, &QPushButton::clicked, qApp, &QApplication::quit);
connect(loginButton, &QPushButton::clicked, this, [=]() {
const QString apiKey = apiKeyEdit->text().trimmed();
if (apiKey.isEmpty()) {
QMessageBox::warning(this, "Ошибка", "Введите API ключ");
return;
}
SettingsDAO::set("api_key", apiKey);
auto *loader = new LoaderDialog(this);
loader->show();
auto *thread = new QThread;
auto *networkService = new NetworkService;
networkService->moveToThread(thread);
connect(thread, &QThread::started, networkService, &NetworkService::loginAndSetup);
connect(networkService, &NetworkService::finished, thread, &QThread::quit);
connect(networkService, &NetworkService::finished, networkService, &QObject::deleteLater);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
connect(networkService, &NetworkService::finishedWithResult, this, [=](int result) {
QMetaObject::invokeMethod(this, [=]() {
loader->close();
loader->deleteLater();
if (result == 1) {
emit onRegisteredSuccess();
} else if (result == 0) {
SettingsDAO::remove("api_key");
QMessageBox::critical(this, "Ошибка входа", "Неверный API ключ. Проверьте и попробуйте снова.");
} else {
QMessageBox::critical(this, "Ошибка подключения",
"Нет подключения к интернету или сервер не отвечает.\n\nПожалуйста, попробуйте позже.");
}
}, Qt::QueuedConnection);
});
thread->start();
});
}