mirror of
https://gitlab.com/comunic/comunicmessages
synced 2025-06-20 00:45:17 +00:00
Can get current user ID
This commit is contained in:
64
controllers/initcontroller.cpp
Normal file
64
controllers/initcontroller.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QProgressDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "../helpers/accounthelper.h"
|
||||
#include "widgets/loginwidget.h"
|
||||
#include "widgets/mainwindow.h"
|
||||
#include "initcontroller.h"
|
||||
#include "config.h"
|
||||
|
||||
InitController::InitController() : QObject()
|
||||
{
|
||||
mAccountHelper = new AccountHelper;
|
||||
connect(mAccountHelper, &AccountHelper::refreshCurrentUserIDResult, this, &InitController::getUserIDCallback);
|
||||
}
|
||||
|
||||
InitController::~InitController()
|
||||
{
|
||||
mAccountHelper->deleteLater();
|
||||
|
||||
if(mProgressdialog != nullptr)
|
||||
mProgressdialog->deleteLater();
|
||||
}
|
||||
|
||||
void InitController::init()
|
||||
{
|
||||
//Define some basic values
|
||||
QCoreApplication::setOrganizationName(ORGANIZATION_NAME);
|
||||
QCoreApplication::setOrganizationDomain(ORGANIZATION_DOMAIN);
|
||||
QCoreApplication::setApplicationName(APPLICATION_NAME);
|
||||
|
||||
//Determine whether user is signed in or not
|
||||
if(!mAccountHelper->signedIn()) {
|
||||
LoginWidget *widget = new LoginWidget();
|
||||
widget->show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Display startup splash screen
|
||||
mProgressdialog = new QProgressDialog(QObject::tr("Starting up..."), QString(), 0, 3);
|
||||
mProgressdialog->show();
|
||||
|
||||
//First, we need to refresh current user ID
|
||||
mProgressdialog->setLabelText(tr("Get current user ID..."));
|
||||
mProgressdialog->setValue(1);
|
||||
mAccountHelper->refreshCurrentUserID();
|
||||
|
||||
}
|
||||
|
||||
void InitController::getUserIDCallback(bool success)
|
||||
{
|
||||
if(!success){
|
||||
QMessageBox::warning(mProgressdialog, tr("Error"), tr("Could not get current user ID! Please check your internet connection..."));
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
mProgressdialog->setLabelText(tr("Open main window..."));
|
||||
mProgressdialog->setValue(2);
|
||||
(new MainWindow())->show();
|
||||
|
||||
mProgressdialog->hide();
|
||||
deleteLater();
|
||||
}
|
41
controllers/initcontroller.h
Normal file
41
controllers/initcontroller.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Initialization controller
|
||||
*
|
||||
* Used to initialize the application
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef INITCONTROLLER_H
|
||||
#define INITCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QProgressDialog;
|
||||
class AccountHelper;
|
||||
|
||||
class InitController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InitController();
|
||||
~InitController();
|
||||
|
||||
/**
|
||||
* Initialize the application. This operation can be
|
||||
* run several times
|
||||
*/
|
||||
void init();
|
||||
|
||||
|
||||
private slots:
|
||||
|
||||
void getUserIDCallback(bool success);
|
||||
|
||||
private:
|
||||
AccountHelper *mAccountHelper = nullptr;
|
||||
QProgressDialog *mProgressdialog = nullptr;
|
||||
};
|
||||
|
||||
#endif // INITCONTROLLER_H
|
Reference in New Issue
Block a user