mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(nexus): make loginscreen independent of nexus
This commit is contained in:
parent
09ad16bc44
commit
11f263ffc3
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>LoginScreen</class>
|
<class>LoginScreen</class>
|
||||||
<widget class="QWidget" name="LoginScreen">
|
<widget class="QDialog" name="LoginScreen">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -323,18 +323,25 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Profile* profile = nullptr;
|
||||||
|
|
||||||
// Autologin
|
// Autologin
|
||||||
if (autoLogin) {
|
if (autoLogin && Profile::exists(profileName) &&
|
||||||
if (Profile::exists(profileName)) {
|
!Profile::isEncrypted(profileName)) {
|
||||||
if (!Profile::isEncrypted(profileName)) {
|
profile = Profile::loadProfile(profileName);
|
||||||
Profile* profile = Profile::loadProfile(profileName);
|
} else {
|
||||||
if (profile)
|
LoginScreen loginScreen{};
|
||||||
Nexus::getInstance().setProfile(profile);
|
loginScreen.exec();
|
||||||
}
|
profile = loginScreen.getProfile();
|
||||||
Settings::getInstance().setCurrentProfile(profileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nexus::getInstance().setProfile(profile);
|
||||||
|
Settings::getInstance().setCurrentProfile(profileName);
|
||||||
|
|
||||||
Nexus& nexus = Nexus::getInstance();
|
Nexus& nexus = Nexus::getInstance();
|
||||||
nexus.start();
|
nexus.start();
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,7 @@ Nexus::Nexus(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, profile{nullptr}
|
, profile{nullptr}
|
||||||
, widget{nullptr}
|
, widget{nullptr}
|
||||||
, loginScreen{nullptr}
|
|
||||||
, running{true}
|
, running{true}
|
||||||
, quitOnLastWindowClosed{true}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +68,6 @@ Nexus::~Nexus()
|
||||||
{
|
{
|
||||||
delete widget;
|
delete widget;
|
||||||
widget = nullptr;
|
widget = nullptr;
|
||||||
delete loginScreen;
|
|
||||||
loginScreen = nullptr;
|
|
||||||
delete profile;
|
delete profile;
|
||||||
profile = nullptr;
|
profile = nullptr;
|
||||||
Settings::getInstance().saveGlobal();
|
Settings::getInstance().saveGlobal();
|
||||||
|
@ -109,17 +105,8 @@ void Nexus::start()
|
||||||
qRegisterMetaType<ToxId>("ToxId");
|
qRegisterMetaType<ToxId>("ToxId");
|
||||||
qRegisterMetaType<GroupInvite>("GroupInvite");
|
qRegisterMetaType<GroupInvite>("GroupInvite");
|
||||||
|
|
||||||
loginScreen = new LoginScreen();
|
|
||||||
|
|
||||||
// We need this LastWindowClosed dance because the LoginScreen may be shown
|
|
||||||
// and closed in a processEvents() loop before the start of the real
|
|
||||||
// exec() event loop, meaning we wouldn't receive the onLastWindowClosed,
|
|
||||||
// and so we wouldn't have a chance to tell the processEvents() loop to quit.
|
|
||||||
qApp->setQuitOnLastWindowClosed(false);
|
|
||||||
connect(qApp, &QApplication::lastWindowClosed, this, &Nexus::onLastWindowClosed);
|
|
||||||
connect(loginScreen, &LoginScreen::closed, this, &Nexus::onLastWindowClosed);
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
// TODO: still needed?
|
||||||
globalMenuBar = new QMenuBar(0);
|
globalMenuBar = new QMenuBar(0);
|
||||||
dockMenu = new QMenu(globalMenuBar);
|
dockMenu = new QMenu(globalMenuBar);
|
||||||
|
|
||||||
|
@ -150,15 +137,9 @@ void Nexus::start()
|
||||||
windowMapper = new QSignalMapper(this);
|
windowMapper = new QSignalMapper(this);
|
||||||
connect(windowMapper, SIGNAL(mapped(QObject*)), this, SLOT(onOpenWindow(QObject*)));
|
connect(windowMapper, SIGNAL(mapped(QObject*)), this, SLOT(onOpenWindow(QObject*)));
|
||||||
|
|
||||||
connect(loginScreen, &LoginScreen::windowStateChanged, this, &Nexus::onWindowStateChanged);
|
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
#endif
|
#endif
|
||||||
|
showMainGUI();
|
||||||
if (profile)
|
|
||||||
showMainGUI();
|
|
||||||
else
|
|
||||||
showLogin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,20 +153,24 @@ void Nexus::showLogin()
|
||||||
delete profile;
|
delete profile;
|
||||||
profile = nullptr;
|
profile = nullptr;
|
||||||
|
|
||||||
loginScreen->reset();
|
LoginScreen loginScreen;
|
||||||
loginScreen->move(QApplication::desktop()->screen()->rect().center()
|
loginScreen.exec();
|
||||||
- loginScreen->rect().center());
|
|
||||||
loginScreen->show();
|
profile = loginScreen.getProfile();
|
||||||
quitOnLastWindowClosed = true;
|
|
||||||
|
if (profile) {
|
||||||
|
Nexus::getInstance().setProfile(profile);
|
||||||
|
Settings::getInstance().setCurrentProfile(profile->getName());
|
||||||
|
showMainGUI();
|
||||||
|
} else {
|
||||||
|
quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nexus::showMainGUI()
|
void Nexus::showMainGUI()
|
||||||
{
|
{
|
||||||
assert(profile);
|
assert(profile);
|
||||||
|
|
||||||
quitOnLastWindowClosed = false;
|
|
||||||
loginScreen->close();
|
|
||||||
|
|
||||||
// Create GUI
|
// Create GUI
|
||||||
widget = Widget::getInstance();
|
widget = Widget::getInstance();
|
||||||
|
|
||||||
|
@ -338,12 +323,6 @@ bool Nexus::tryRemoveFile(const QString& filepath)
|
||||||
return writable;
|
return writable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nexus::onLastWindowClosed()
|
|
||||||
{
|
|
||||||
if (quitOnLastWindowClosed)
|
|
||||||
quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
void Nexus::retranslateUi()
|
void Nexus::retranslateUi()
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
class Widget;
|
class Widget;
|
||||||
class Profile;
|
class Profile;
|
||||||
class LoginScreen;
|
|
||||||
class Core;
|
class Core;
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -85,9 +84,6 @@ private:
|
||||||
QActionGroup* windowActions = nullptr;
|
QActionGroup* windowActions = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onLastWindowClosed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Nexus(QObject* parent = 0);
|
explicit Nexus(QObject* parent = 0);
|
||||||
~Nexus();
|
~Nexus();
|
||||||
|
@ -95,9 +91,7 @@ private:
|
||||||
private:
|
private:
|
||||||
Profile* profile;
|
Profile* profile;
|
||||||
Widget* widget;
|
Widget* widget;
|
||||||
LoginScreen* loginScreen;
|
|
||||||
bool running;
|
bool running;
|
||||||
bool quitOnLastWindowClosed;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NEXUS_H
|
#endif // NEXUS_H
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include "loginscreen.h"
|
#include "loginscreen.h"
|
||||||
#include "ui_loginscreen.h"
|
#include "ui_loginscreen.h"
|
||||||
#include "src/nexus.h"
|
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/persistence/profilelocker.h"
|
#include "src/persistence/profilelocker.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
@ -29,11 +28,12 @@
|
||||||
#include "src/widget/tool/profileimporter.h"
|
#include "src/widget/tool/profileimporter.h"
|
||||||
#include "src/widget/translator.h"
|
#include "src/widget/translator.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
LoginScreen::LoginScreen(QWidget* parent)
|
LoginScreen::LoginScreen(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::LoginScreen)
|
, ui(new Ui::LoginScreen)
|
||||||
, quitShortcut{QKeySequence(Qt::CTRL + Qt::Key_Q), this}
|
, quitShortcut{QKeySequence(Qt::CTRL + Qt::Key_Q), this}
|
||||||
{
|
{
|
||||||
|
@ -105,6 +105,11 @@ void LoginScreen::reset()
|
||||||
ui->autoLoginCB->blockSignals(false);
|
ui->autoLoginCB->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Profile *LoginScreen::getProfile() const
|
||||||
|
{
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
bool LoginScreen::event(QEvent* event)
|
bool LoginScreen::event(QEvent* event)
|
||||||
{
|
{
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
|
@ -118,7 +123,6 @@ bool LoginScreen::event(QEvent* event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,19 +171,16 @@ void LoginScreen::onCreateNewProfile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile* profile = Profile::createProfile(name, pass);
|
profile = Profile::createProfile(name, pass);
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
// Unknown error
|
// Unknown error
|
||||||
QMessageBox::critical(this, tr("Couldn't create a new profile"),
|
QMessageBox::critical(this, tr("Couldn't create a new profile"),
|
||||||
tr("Unknown error: Couldn't create a new profile.\nIf you "
|
tr("Unknown error: Couldn't create a new profile.\nIf you "
|
||||||
"encountered this error, please report it."));
|
"encountered this error, please report it."));
|
||||||
|
done(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
done(0);
|
||||||
Nexus& nexus = Nexus::getInstance();
|
|
||||||
|
|
||||||
nexus.setProfile(profile);
|
|
||||||
nexus.showMainGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginScreen::onLoginUsernameSelected(const QString& name)
|
void LoginScreen::onLoginUsernameSelected(const QString& name)
|
||||||
|
@ -223,7 +224,7 @@ void LoginScreen::onLogin()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile* profile = Profile::loadProfile(name, pass);
|
profile = Profile::loadProfile(name, pass);
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
if (!ProfileLocker::isLockable(name)) {
|
if (!ProfileLocker::isLockable(name)) {
|
||||||
QMessageBox::critical(this, tr("Couldn't load this profile"),
|
QMessageBox::critical(this, tr("Couldn't load this profile"),
|
||||||
|
@ -236,11 +237,7 @@ void LoginScreen::onLogin()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done(0);
|
||||||
Nexus& nexus = Nexus::getInstance();
|
|
||||||
|
|
||||||
nexus.setProfile(profile);
|
|
||||||
nexus.showMainGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginScreen::onPasswordEdited()
|
void LoginScreen::onPasswordEdited()
|
||||||
|
|
|
@ -23,20 +23,23 @@
|
||||||
|
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QWidget>
|
#include <QDialog>
|
||||||
|
|
||||||
|
class Profile;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class LoginScreen;
|
class LoginScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoginScreen : public QWidget
|
class LoginScreen : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LoginScreen(QWidget* parent = 0);
|
explicit LoginScreen(QWidget* parent = nullptr);
|
||||||
~LoginScreen();
|
~LoginScreen();
|
||||||
void reset();
|
void reset();
|
||||||
|
Profile* getProfile() const;
|
||||||
|
|
||||||
bool event(QEvent* event) final override;
|
bool event(QEvent* event) final override;
|
||||||
|
|
||||||
|
@ -68,6 +71,7 @@ private:
|
||||||
private:
|
private:
|
||||||
Ui::LoginScreen* ui;
|
Ui::LoginScreen* ui;
|
||||||
QShortcut quitShortcut;
|
QShortcut quitShortcut;
|
||||||
|
Profile* profile{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOGINSCREEN_H
|
#endif // LOGINSCREEN_H
|
||||||
|
|
|
@ -963,7 +963,7 @@ void Widget::onStopNotification()
|
||||||
|
|
||||||
void Widget::onRejectCall(uint32_t friendId)
|
void Widget::onRejectCall(uint32_t friendId)
|
||||||
{
|
{
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* const av = Core::getInstance()->getAv();
|
||||||
av->cancelCall(friendId);
|
av->cancelCall(friendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user