Commit 55f92cb9 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Isa

ux: change application start

- make the wizard a widget in the mainwindow navstack
- remove findRingAccount, any account present should not invoke the
  wizard

Change-Id: I5341d9060e17b74ac253619d70aad6d2d9a93874
Reviewed-by: Isa's avatarIsa Nanic <isa.nanic@savoirfairelinux.com>
parent 0a4e7aa3
......@@ -81,7 +81,8 @@ SOURCES += main.cpp\
accountitemdelegate.cpp \
accountlistmodel.cpp \
messagemodel.cpp \
invitebuttonswidget.cpp
invitebuttonswidget.cpp \
wizardwidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -126,7 +127,8 @@ HEADERS += mainwindow.h \
accountitemdelegate.h \
accountlistmodel.h \
messagemodel.h \
invitebuttonswidget.h
invitebuttonswidget.h \
wizardwidget.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......@@ -153,7 +155,8 @@ FORMS += mainwindow.ui \
deleteaccountdialog.ui \
bannedcontactswidget.ui \
photoboothwidget.ui \
invitebuttonswidget.ui
invitebuttonswidget.ui \
wizardwidget.ui
win32: LIBS += -lole32 -luuid -lshlwapi -lgdi32
LIBS += -lqrencode
......
......@@ -51,7 +51,7 @@ int AccountListModel::columnCount(const QModelIndex &parent) const
QVariant AccountListModel::data(const QModelIndex &index, int role) const
{
auto accountList = LRCInstance::accountModel().getAccountList();
if (!index.isValid() || accountList.size() == 0) {
if (!index.isValid() || accountList.size() <= index.row()) {
return QVariant();
}
......
......@@ -108,8 +108,6 @@ CallWidget::CallWidget(QWidget* parent) :
ui->spinnerLabel->setMovie(miniSpinner_);
ui->spinnerLabel->hide();
// set to welcome view
ui->stackedWidget->setCurrentWidget(ui->welcomePage);
setupOutOfCallIM();
// connections
......@@ -155,6 +153,9 @@ CallWidget::CallWidget(QWidget* parent) :
connect(&LRCInstance::behaviorController(), &BehaviorController::showChatView,
this, &CallWidget::slotShowChatView);
// set first view to welcome view
ui->stackedWidget->setCurrentWidget(ui->welcomePage);
}
CallWidget::~CallWidget()
......@@ -320,36 +321,6 @@ CallWidget::setupQRCode(QString ringID)
Qt::KeepAspectRatio)));
}
bool
CallWidget::findRingAccount()
{
bool ringAccountFound = false;
auto accountList = LRCInstance::accountModel().getAccountList();
for (int i = 0; i < accountList.size(); ++i) {
auto accountId = accountList.at(i);
auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
if (accountInfo.profileInfo.type == lrc::api::profile::Type::RING) {
ringAccountFound = true;
if (accountInfo.status == lrc::api::account::Status::ERROR_NEED_MIGRATION) {
WizardDialog dlg(WizardDialog::MIGRATION);
dlg.exec();
}
}
}
if (!ringAccountFound) {
WizardDialog wizardDialog;
wizardDialog.exec();
if (wizardDialog.result() != QDialog::Accepted) {
return false;
}
}
ui->currentAccountWidget->update();
return true;
}
void
CallWidget::on_smartList_clicked(const QModelIndex& index)
{
......
......@@ -64,7 +64,6 @@ class CallWidget : public NavWidget
public:
explicit CallWidget(QWidget* parent = 0);
~CallWidget();
bool findRingAccount();
public slots:
void on_ringContactLineEdit_returnPressed();
......
......@@ -89,6 +89,9 @@ ConfigurationWidget::ConfigurationWidget(QWidget *parent) :
auto idx = ui->accountView->currentIndex();
DeleteAccountDialog dialog(idx);
dialog.exec();
if (!LRCInstance::accountModel().getAccountList().size()) {
emit NavigationRequested(ScreenEnum::WizardScreen);
}
});
isLoading_ = true;
......
......@@ -180,10 +180,6 @@ main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/images/FontAwesome.otf");
if (not MainWindow::instance().init()) {
return 1;
}
MainWindow::instance().createThumbBar();
if (not uri.isEmpty()) {
......
......@@ -37,6 +37,7 @@
#include "callmodel.h"
#include "callwidget.h"
#include "utils.h"
#include "wizarddialog.h"
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent),
......@@ -44,6 +45,11 @@ MainWindow::MainWindow(QWidget* parent) :
{
ui->setupUi(this);
connect(ui->wizardwidget, &WizardWidget::NavigationRequested,
[this](ScreenEnum scr) {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(scr));
});
connect(ui->callwidget, &CallWidget::NavigationRequested,
[this](ScreenEnum scr) {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(scr));
......@@ -117,6 +123,22 @@ MainWindow::MainWindow(QWidget* parent) :
Q_UNUSED(online)
AccountModel::instance().slotConnectivityChanged();
});
auto accountList = LRCInstance::accountModel().getAccountList();
if (accountList.size()) {
for (const auto& accountId : accountList) {
auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
if (accountInfo.profileInfo.type == lrc::api::profile::Type::RING) {
if (accountInfo.status == lrc::api::account::Status::ERROR_NEED_MIGRATION) {
WizardDialog dlg(WizardDialog::MIGRATION);
dlg.exec();
}
}
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(ScreenEnum::CallScreen));
} else {
Utils::setStackWidget(ui->navStack, ui->navStack->widget(ScreenEnum::WizardScreen));
}
}
MainWindow::~MainWindow()
......@@ -124,12 +146,6 @@ MainWindow::~MainWindow()
delete ui;
}
bool
MainWindow::init()
{
return ui->callwidget->findRingAccount();
}
void
MainWindow::onRingEvent(const QString& uri)
{
......@@ -218,6 +234,7 @@ MainWindow::switchNormalMaximize()
void
MainWindow::closeEvent(QCloseEvent* event)
{
Video::PreviewManager::instance().stopPreview();
QSettings settings;
if (settings.value(SettingsKey::closeOrMinimized).toBool()) {
this->hide();
......
......@@ -463,6 +463,7 @@
</property>
<item>
<widget class="QStackedWidget" name="navStack">
<widget class="WizardWidget" name="wizardwidget"/>
<widget class="CallWidget" name="callwidget"/>
<widget class="ConfigurationWidget" name="configurationwidget"/>
</widget>
......@@ -484,6 +485,12 @@
<header>configurationwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>WizardWidget</class>
<extends>QWidget</extends>
<header>wizardwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......
......@@ -22,6 +22,7 @@
enum ScreenEnum {
//DO not add main widget screen before callScreen
WizardScreen,
CallScreen,
ConfScreen,
END
......
......@@ -169,8 +169,13 @@
<ClCompile Include="videowidget.cpp" />
<ClCompile Include="windowscontactbackend.cpp" />
<ClCompile Include="wizarddialog.cpp" />
<ClCompile Include="wizardwidget.cpp" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="wizardwidget.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\lrc\src;$(ProjectDir)..\client-windows\winsparkle\include;$(ProjectDir)..\client-windows\qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='Release|x64'">_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;NIGHTLY_VERSION=20180706;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
</QtMoc>
<QtMoc Include="aboutdialog.h">
</QtMoc>
<QtMoc Include="accountdetails.h">
......@@ -386,6 +391,7 @@
</QtUic>
<QtUic Include="invitebuttonswidget.ui" />
<QtUic Include="mainwindow.ui">
<SubType>Designer</SubType>
</QtUic>
<QtUic Include="photoboothdialog.ui">
</QtUic>
......@@ -405,6 +411,9 @@
</QtUic>
<QtUic Include="wizarddialog.ui">
</QtUic>
<QtUic Include="wizardwidget.ui">
<SubType>Designer</SubType>
</QtUic>
</ItemGroup>
<ItemGroup>
<None Include="images\FontAwesome.otf" />
......
......@@ -183,6 +183,9 @@
<ClCompile Include="invitebuttonswidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wizardwidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="aboutdialog.h">
......@@ -314,6 +317,9 @@
<QtMoc Include="invitebuttonswidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="wizardwidget.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......@@ -611,6 +617,9 @@
<QtUic Include="invitebuttonswidget.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="wizardwidget.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<None Include="images\FontAwesome.otf">
......
......@@ -41,7 +41,7 @@ private:
void hideButtonsWidgets();
QModelIndex hoveredRow_;
signals:
signals:
void btnAcceptInviteClicked(const QModelIndex& index) const;
void btnBlockInviteClicked(const QModelIndex& index) const;
void btnIgnoreInviteClicked(const QModelIndex& index) const;
......
......@@ -375,21 +375,23 @@ WizardDialog::createRingAccount(const QString &displayName,
);
});
connect(&LRCInstance::accountModel(),
&lrc::api::NewAccountModel::accountAdded,
[this](const std::string& accountId) {
//set default ringtone
auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
accept();
});
connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountAdded,
this, &WizardDialog::slotAccountAdded);
ui->navBarWidget->hide();
Utils::setStackWidget(ui->stackedWidget, ui->spinnerPage);
repaint();
}
void
WizardDialog::slotAccountAdded(const std::string& accountId)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
accept();
}
void
WizardDialog::on_dhtImportBtn_clicked()
{
......
......@@ -26,7 +26,6 @@
#include "account.h"
#include "person.h"
// new lrc
#include "lrcinstance.h"
namespace Ui {
......@@ -70,6 +69,7 @@ private slots:
void on_archivePathSelector_clicked();
void on_dhtImportBtn_clicked();
void on_fileImportBtn_clicked();
void slotAccountAdded(const std::string & accountId);
private:
Ui::WizardDialog* ui;
......
/**************************************************************************
* Copyright (C) 2015-2018 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "wizardwidget.h"
#include "ui_wizardwidget.h"
#include <QMovie>
#include <QMessageBox>
#include <QFileDialog>
#include "accountmodel.h"
#include "account.h"
#include "profilemodel.h"
#include "profile.h"
#include "namedirectory.h"
#include "utils.h"
const QString DEFAULT_RING_ACCT_ALIAS = QObject::tr("Ring account", "Default alias for new Ring account");
WizardWidget::WizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrated, QWidget* parent) :
NavWidget(parent),
ui(new Ui::WizardWidget),
account_(toBeMigrated),
wizardMode_(wizardMode),
nameLookupTimer_(this)
{
ui->setupUi(this);
Qt::WindowFlags flags = windowFlags();
flags = flags & (~Qt::WindowContextHelpButtonHint);
setWindowFlags(flags);
QPixmap logo(":/images/logo-ring-standard-coul.png");
ui->welcomeLogo->setPixmap(logo.scaledToHeight(65, Qt::SmoothTransformation));
ui->welcomeLogo->setAlignment(Qt::AlignHCenter);
ui->fullNameEdit->setText(Utils::GetCurrentUserName());
movie_ = new QMovie(":/images/loading.gif");
ui->spinnerLabel->setMovie(movie_);
movie_->start();
if (wizardMode_ == MIGRATION) {
Utils::setStackWidget(ui->stackedWidget, ui->profilePage);
ui->usernameEdit->setEnabled(false);
ui->usernameEdit->setText(QString::fromStdString(toBeMigrated->profileInfo.alias));
ui->previousButton->hide();
ui->photoBooth->hide();
ui->pinEdit->hide();
ui->infoLabel->setText(tr("Your account needs to be migrated. Enter your password."));
} else {
ui->navBarWidget->hide();
}
ui->searchingStateLabel->clear();
connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(handle_registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
nameLookupTimer_.setSingleShot(true);
connect(&nameLookupTimer_, &QTimer::timeout, this, &WizardWidget::timeoutNameLookupTimer);
connect(ui->photoBooth, &PhotoboothWidget::photoTaken, this, &WizardWidget::on_photoTaken);
ui->avatarLabel->hide();
}
WizardWidget::~WizardWidget()
{
disconnect(&NameDirectory::instance(), SIGNAL(registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(handle_registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
delete ui;
}
void
WizardWidget::processWizardInformations()
{
if (wizardMode_ == MIGRATION)
ui->progressLabel->setText(tr("Migrating your Ring account..."));
else if (wizardMode_ == IMPORT)
ui->progressLabel->setText(tr("Importing account archive..."));
else
ui->progressLabel->setText(tr("Generating your Ring account..."));
if (wizardMode_ != IMPORT) {
if (ui->pinEdit->isVisible() && ui->pinEdit->text().isEmpty()) {
ui->pinEdit->setStyleSheet("border-color: rgb(204, 0, 0);");
return;
}
if (ui->passwordEdit->text() != ui->confirmPasswordEdit->text()) {
ui->passwordEdit->setStyleSheet("border-color: rgb(204, 0, 0);");
ui->confirmPasswordEdit->setStyleSheet("border-color: rgb(204, 0, 0);");
return;
} else {
ui->passwordEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
ui->confirmPasswordEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
ui->pinEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
}
QString accountAlias = (ui->fullNameEdit->text().isEmpty() ||
ui->fullNameEdit->text().isNull()) ? DEFAULT_RING_ACCT_ALIAS : ui->fullNameEdit->text();
QString archivePin = (ui->pinEdit->text().isEmpty() || ui->pinEdit->text().isNull()) ? QString() : ui->pinEdit->text();
createRingAccount(accountAlias, ui->passwordEdit->text(), archivePin);
ui->passwordEdit->clear();
ui->confirmPasswordEdit->clear();
ui->pinEdit->clear();
}
Utils::CreateStartupLink();
}
void
WizardWidget::on_photoTaken(QString fileName)
{
auto image = QImage(fileName);
auto avatar = image.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar);
ui->avatarLabel->setPixmap(QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarLabel->width())));
ui->photoBooth->stopBooth();
ui->avatarLabel->show();
}
void
WizardWidget::on_existingPushButton_clicked()
{
ui->navBarWidget->show();
ui->nextButton->hide();
Utils::setStackWidget(ui->stackedWidget, ui->linkMethodPage);
}
void
WizardWidget::on_newAccountButton_clicked()
{
wizardMode_ = NEW_ACCOUNT;
changePage(false);
}
void
WizardWidget::changePage(bool existingAccount)
{
if (existingAccount) { // If user want to add a device
ui->accountLabel->setText(tr("Add a device"));
Utils::setStackWidget(ui->stackedWidget, ui->explanationPage);
ui->photoBooth->hide();
} else { // If user want to create a new account
ui->accountLabel->setText(tr("Create your account"));
Utils::setStackWidget(ui->stackedWidget, ui->profilePage);
ui->photoBooth->startBooth();
ui->photoBooth->show();
}
ui->navBarWidget->show();
ui->avatarLabel->setHidden(true);
ui->infoLabel->setHidden(existingAccount);
ui->usernameEdit->setHidden(existingAccount);
ui->signUpCheckbox->setHidden(existingAccount);
ui->signUpCheckbox->setChecked(!existingAccount);
ui->confirmPasswordEdit->setHidden(existingAccount);
ui->searchingStateLabel->setHidden(existingAccount);
ui->pinEdit->setVisible(existingAccount);
}
void
WizardWidget::on_nextButton_clicked()
{
const QWidget* curWidget = ui->stackedWidget->currentWidget();
if (curWidget == ui->profilePage) {
ui->photoBooth->stopBooth();
}
if (curWidget == ui->profilePage || curWidget == ui->explanationPage) {
Utils::setStackWidget(ui->stackedWidget, ui->accountPage);
} else if (curWidget == ui->accountPage) {
processWizardInformations();
} else if (curWidget == ui->fileImportPage) {
validateFileImport();
}
}
void
WizardWidget::on_previousButton_clicked()
{
const QWidget* curWidget = ui->stackedWidget->currentWidget();
if (curWidget == ui->profilePage) {
ui->navBarWidget->hide();
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
} else if (curWidget == ui->explanationPage || curWidget == ui->fileImportPage) {
ui->navBarWidget->show();
ui->nextButton->hide();
Utils::setStackWidget(ui->stackedWidget, ui->linkMethodPage);
} else if (curWidget == ui->accountPage) {
if (ui->pinEdit->isVisible()) {
// If we are adding a device
Utils::setStackWidget(ui->stackedWidget, ui->explanationPage);
} else {
ui->photoBooth->startBooth();
ui->photoBooth->show();
Utils::setStackWidget(ui->stackedWidget, ui->profilePage);
}
ui->passwordEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
ui->confirmPasswordEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
ui->pinEdit->setStyleSheet("border-color: rgb(0, 192, 212);");
} else if (curWidget == ui->linkMethodPage) {
ui->navBarWidget->hide();
ui->nextButton->show();
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
} else if (curWidget == ui->spinnerPage) {
ui->nextButton->show();
ui->navBarWidget->hide();
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
}
}
void
WizardWidget::on_passwordEdit_textChanged(const QString& arg1)
{
Q_UNUSED(arg1)
if (ui->pinEdit->isVisible()) {
ui->confirmPasswordEdit->setText(ui->passwordEdit->text());
}
}
void
WizardWidget::on_usernameEdit_textChanged(const QString &arg1)
{
Q_UNUSED(arg1)
if(ui->signUpCheckbox->isChecked() && !arg1.isEmpty()) {
ui->searchingStateLabel->setText(tr("Searching..."));
nameLookupTimer_.start(1500);
} else {
ui->searchingStateLabel->clear();
nameLookupTimer_.stop();
}
}
void
WizardWidget::timeoutNameLookupTimer()
{
if(ui->signUpCheckbox->isChecked() && !ui->usernameEdit->text().isEmpty()) {
NameDirectory::instance().lookupName(nullptr, QString(), ui->usernameEdit->text());
} else {
ui->searchingStateLabel->clear();
}
}
void
WizardWidget::handle_registeredNameFound (Account* account, NameDirectory::LookupStatus status, const QString& address, const QString& name)
{
Q_UNUSED(account)
Q_UNUSED(address)
Q_UNUSED(name)
#pragma push_macro("ERROR")
#undef ERROR