Commit 94f87a2c authored by Andreas Traczyk's avatar Andreas Traczyk

wizard: respond to signals indicating invalid account link/create

- In the case of an invalid account import, lrc adds an account
  and removes it only after an erroneous state change. So we
  ignore accountAdded signals pertaining to accounts with empty
  usernames, and return the user to the wizard's welcome page upon
  receiving either the accountRemoved or invalidAccountDetected
  signals.
- This patch makes LRCInstance inherit from QObject so it can emit
  the accountOnBoarded signal when account creation has succeeded.

Change-Id: I43e4ba168fac96d4bd86171639ae8d4776d5cada
parent 6b03c270
......@@ -22,6 +22,7 @@
#undef ERROR
#endif
#include <QObject>
#include <QSettings>
#include <QRegularExpression>
#include <QPixmap>
......@@ -44,8 +45,15 @@
#include <settingskey.h>
class LRCInstance {
class LRCInstance : public QObject
{
Q_OBJECT
public:
static LRCInstance& instance() {
static LRCInstance instance_;
return instance_;
};
static void init() {
instance();
};
......@@ -156,16 +164,14 @@ public:
return instance().getCurrentAccountInfo().confProperties;
}
signals:
/// emit once at least one valid account is loaded
void accountOnBoarded();
private:
std::unique_ptr<lrc::api::Lrc> lrc_;
AccountListModel accountListModel_;
static LRCInstance& instance() {
static LRCInstance instance_;
return instance_;
};
LRCInstance() {
lrc_ = std::make_unique<lrc::api::Lrc>();
};
......
......@@ -204,6 +204,7 @@ void NewWizardWidget::changePage(QWidget* toPage)
}
Utils::setStackWidget(ui->stackedWidget, toPage);
if (toPage == ui->welcomePage) {
fileToImport_ = QString("");
setNavBarVisibility(false, true);
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
......@@ -410,6 +411,8 @@ NewWizardWidget::createRingAccount(const QString &displayName,
[this](const std::string& accountId) {
//set default ringtone
auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
if (confProps.username.empty())
return;
confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
connect(LRCInstance::editableAccountModel(),
......@@ -418,6 +421,7 @@ NewWizardWidget::createRingAccount(const QString &displayName,
lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
});
LRCInstance::editableAccountModel()->registerName(
LRCInstance::getCurrAccId(),
......@@ -428,6 +432,18 @@ NewWizardWidget::createRingAccount(const QString &displayName,
LRCInstance::setCurrAccAvatar(ui->setAvatarWidget->getAvatarPixmap());
}
});
Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountRemoved,
[this](const std::string& accountId) {
Q_UNUSED(accountId);
qWarning() << Q_FUNC_INFO << ": " << "accountRemoved";
reportFailure();
});
Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::invalidAccountDetected,
[this](const std::string& accountId) {
Q_UNUSED(accountId);
qWarning() << Q_FUNC_INFO << ": " << "invalidAccountDetected";
reportFailure();
});
QtConcurrent::run(
[=] {
LRCInstance::accountModel().createNewAccount(
......@@ -440,4 +456,21 @@ NewWizardWidget::createRingAccount(const QString &displayName,
});
changePage(ui->spinnerPage);
repaint();
}
void
NewWizardWidget::reportFailure()
{
auto spinnerGeometry = ui->spinnerLabel->frameGeometry();
auto pixmap = Utils::generateTintedPixmap(":/images/icons/baseline-error_outline-24px.svg", RingTheme::urgentOrange_)
.scaled(spinnerGeometry.width(), spinnerGeometry.height());
ui->spinnerLabel->setPixmap(pixmap);
ui->progressLabel->setStyleSheet("color:red;");
ui->progressLabel->setText(tr("Error creating account"));
QTimer::singleShot(1000, this,
[this] {
changePage(ui->welcomePage);
ui->progressLabel->setStyleSheet("");
ui->spinnerLabel->setMovie(creationSpinnerMovie_);
});
}
\ No newline at end of file
......@@ -99,5 +99,6 @@ private:
const QString &password = QString(),
const QString &pin = QString(),
const QString &archivePath = QString());
void reportFailure();
void processWizardInformations();
};
......@@ -369,7 +369,12 @@
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)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\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">COMPILE_ONLY;_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
</QtMoc>
<ClInclude Include="lrcinstance.h" />
<QtMoc Include="lrcinstance.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)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\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='Release|x64'">_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)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\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">COMPILE_ONLY;_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
</QtMoc>
<QtMoc Include="messagewebview.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\QtWebEngineWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|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\QtWebEngineWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
......
......@@ -329,6 +329,9 @@
<QtMoc Include="bezierconnectorwidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="lrcinstance.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......@@ -750,9 +753,6 @@
<ResourceCompile Include="ico.rc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="lrcinstance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="settingsitemwidget.h">
<Filter>Header Files</Filter>
</ClInclude>
......
......@@ -95,10 +95,9 @@ SettingsWidget::SettingsWidget(QWidget* parent)
auto accountList = LRCInstance::accountModel().getAccountList();
if (!accountList.size()) {
Utils::oneShotConnect(&LRCInstance::accountModel(),
&lrc::api::NewAccountModel::accountAdded,
[this](const std::string& accountId) {
Q_UNUSED(accountId);
Utils::oneShotConnect(&LRCInstance::instance(),
&LRCInstance::accountOnBoarded,
[this]() {
setConnections();
});
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment