Can get current user ID

This commit is contained in:
Pierre HUBERT
2018-11-29 17:35:27 +01:00
parent 2396047204
commit d405b0e8e1
8 changed files with 193 additions and 24 deletions

View 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();
}

View 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