Commit 643bf44f authored by Andreas Traczyk's avatar Andreas Traczyk

settings: fixes crash when loading settings widget with no accounts

Change-Id: If11cb212d6a209b33d927f5911e3776818dcb0fe
parent f37ed860
/***************************************************************************
* Copyright (C) 2019-2019 by Savoir-faire Linux *
* Copyright (C) 2019-2019 by Savoir-faire Linux *
* Author: Isa Nanic <isa.nanic@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
......
......@@ -265,6 +265,10 @@ CallWidget::updateCustomUI()
}
void
CallWidget::slotAccountOnBoarded()
{}
int
CallWidget::getLeftPanelWidth()
{
......
......@@ -67,6 +67,8 @@ public:
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
public slots:
void on_ringContactLineEdit_returnPressed();
......
......@@ -132,6 +132,7 @@ MainWindow::MainWindow(QWidget* parent) :
if (accountList.size()) {
readSettingsFromRegistry();
startScreen = ScreenEnum::CallScreen;
emit LRCInstance::instance().accountOnBoarded();
} else {
startScreen = ScreenEnum::WizardScreen;
}
......
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Copyright (C) 2015-2019 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -18,10 +18,15 @@
#include "navwidget.h"
#include "lrcinstance.h"
#include "utils.h"
NavWidget::NavWidget(QWidget* parent) :
QWidget(parent)
{}
QWidget(parent)
{
Utils::oneShotConnect(&LRCInstance::instance(), &LRCInstance::accountOnBoarded,
this, &NavWidget::slotAccountOnBoarded);
}
NavWidget::~NavWidget()
{}
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Copyright (C) 2015-2019 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@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 *
......@@ -21,7 +22,6 @@
#include <QWidget>
enum ScreenEnum {
//DO not add main widget screen before callScreen
WizardScreen,
CallScreen,
SetttingsScreen,
......@@ -41,7 +41,8 @@ public:
signals:
void NavigationRequested(ScreenEnum screen);
void BackRequested();
};
protected slots:
virtual void slotAccountOnBoarded() = 0;
};
......@@ -158,6 +158,10 @@ NewWizardWidget::navigated(bool to)
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
}
void
NewWizardWidget::slotAccountOnBoarded()
{}
void
NewWizardWidget::on_existingPushButton_clicked()
{
......@@ -448,8 +452,6 @@ NewWizardWidget::createAccount()
[this, isRing](const std::string& accountId) {
//set default ringtone
auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
if (confProps.username.empty())
return;
confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
if (!isRing) {
// set SIP details
......@@ -459,27 +461,29 @@ NewWizardWidget::createAccount()
confProps.proxyServer = inputPara_["proxy"].toStdString();
}
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
// RING SPECIFIC
if (isRing) {
connect(LRCInstance::editableAccountModel(),
&lrc::api::NewAccountModel::nameRegistrationEnded,
[this] {
lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
if (!confProps.username.empty()) {
connect(LRCInstance::editableAccountModel(),
&lrc::api::NewAccountModel::nameRegistrationEnded,
[this] {
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(),
"",
registeredName_.toStdString()
);
} else {
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
});
LRCInstance::editableAccountModel()->registerName(
LRCInstance::getCurrAccId(),
"",
registeredName_.toStdString()
);
}
// END RING SPECIFIC
if (ui->setSIPAvatarWidget->hasAvatar() && wizardMode_ == WizardMode::CREATESIP) {
LRCInstance::setCurrAccAvatar(ui->setSIPAvatarWidget->getAvatarPixmap());
} else if (ui->setAvatarWidget->hasAvatar() && wizardMode_ == WizardMode::CREATE) {
}
LRCInstance::setCurrAccAvatar(ui->setAvatarWidget->getAvatarPixmap());
} else {
LRCInstance::setCurrAccAvatar(ui->setSIPAvatarWidget->getAvatarPixmap());
}
});
Utils::oneShotConnect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::accountRemoved,
......@@ -515,6 +519,7 @@ NewWizardWidget::createAccount()
);
QThread::sleep(2);
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
}
});
changePage(ui->spinnerPage);
......
......@@ -53,6 +53,8 @@ public:
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
//UI Slots
private slots:
......
......@@ -452,9 +452,10 @@
<Define Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;NIGHTLY_VERSION=20180706;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
</QtMoc>
<QtMoc Include="settingswidget.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>
<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;NIGHTLY_VERSION=20180706;ENABLE_AUTOUPDATE;QT_NO_DEBUG;NDEBUG</Define>
<SubType>Designer</SubType>
<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>
</QtMoc>
<ClInclude Include="utils.h" />
<QtMoc Include="videooverlay.h">
......
......@@ -296,9 +296,6 @@
<QtMoc Include="animationhelpers.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="settingswidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="passworddialog.h">
<Filter>Header Files</Filter>
</QtMoc>
......@@ -332,6 +329,9 @@
<QtMoc Include="advancedsipsettingwidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="settingswidget.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......
/***************************************************************************
* Copyright (C) 2019-2019 by Savoir-faire Linux *
* Author: Isa Nanic <isa.nanic@savoirfairelinux.com> *
* 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: Mingrui Zhang <mingrui.zhang@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 <https://www.gnu.org/licenses/>. *
**************************************************************************/
* Copyright (C) 2019 by Savoir-faire Linux *
* Author: Isa Nanic <isa.nanic@savoirfairelinux.com> *
* 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: Mingrui Zhang <mingrui.zhang@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 <https://www.gnu.org/licenses/>. *
**************************************************************************/
#include "settingswidget.h"
#include "ui_settingswidget.h"
......@@ -82,8 +83,6 @@ SettingsWidget::SettingsWidget(QWidget* parent)
//display name SIP
ui->displaySIPNameLineEdit->setAlignment(Qt::AlignHCenter);
setSelected(Button::accountSettingsButton);
//SIP User Name
ui->usernameSIP->setStyleSheet("border : 0px;");
......@@ -131,20 +130,16 @@ SettingsWidget::SettingsWidget(QWidget* parent)
auto accountList = LRCInstance::accountModel().getAccountList();
if (!accountList.size()) {
Utils::oneShotConnect(&LRCInstance::instance(),
&LRCInstance::accountOnBoarded,
[this]() {
setConnections();
});
} else {
setConnections();
}
ui->containerWidget->setVisible(false);
}
void
SettingsWidget::slotAccountOnBoarded()
{
setSelected(Button::accountSettingsButton);
setConnections();
}
void
SettingsWidget::navigated(bool to)
{
......
......@@ -56,6 +56,8 @@ public:
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
public slots:
void updateSettings(int size);
......
......@@ -101,6 +101,27 @@ namespace Utils
});
}
template <typename Func1, typename Func2>
void
oneShotConnect( const typename QtPrivate::FunctionPointer<Func1>::Object* sender, Func1 signal,
const typename QtPrivate::FunctionPointer<Func2>::Object* receiver, Func2 slot)
{
QMetaObject::Connection* const connection = new QMetaObject::Connection;
*connection = QObject::connect(sender, signal, receiver, slot);
QMetaObject::Connection* const disconnectConnection = new QMetaObject::Connection;
*disconnectConnection = QObject::connect(sender, signal,
[connection, disconnectConnection] {
if (connection) {
QObject::disconnect(*connection);
delete connection;
}
if (disconnectConnection) {
QObject::disconnect(*disconnectConnection);
delete disconnectConnection;
}
});
}
template<typename E>
constexpr inline typename std::enable_if< std::is_enum<E>::value,
typename std::underlying_type<E>::type
......
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