Commit 3199a1f0 authored by Andreas Traczyk's avatar Andreas Traczyk

wizard: support archive import and linking

Change-Id: I8cd96ba6cd96a5334a1e10c6f2ecdbcd17901e5a
parent 14c3e865
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>
\ No newline at end of file
......@@ -131,6 +131,7 @@ MainWindow::MainWindow(QWidget* parent) :
auto flags_ = windowFlags();
auto accountList = LRCInstance::accountModel().getAccountList();
lastAccountCount_ = accountList.size();
ScreenEnum startScreen;
if (accountList.size()) {
readSettingsFromRegistry();
......@@ -169,8 +170,13 @@ MainWindow::slotCurrentChanged(int index)
{
auto accountList = LRCInstance::accountModel().getAccountList();
auto firstUse =
(accountList.size() == 1 && lastScr_ == ScreenEnum::WizardScreen) ||
(accountList.size() == 1 && lastScr_ == ScreenEnum::WizardScreen &&
lastAccountCount_ < accountList.size()) ||
!accountList.size();
if (lastScr_ == ScreenEnum::WizardScreen &&
lastAccountCount_ < accountList.size()) {
lastAccountCount_ = accountList.size();
}
for (int i = 0; i < ui->navStack->count(); ++i) {
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(i))) {
navWidget->navigated(index == i);
......
......@@ -77,6 +77,7 @@ private:
void setWindowSize(ScreenEnum scr, bool firstUse = false);
ScreenEnum lastScr_;
int lastAccountCount_;
Qt::WindowFlags flags_;
void readSettingsFromRegistry();
......
......@@ -34,11 +34,10 @@
const QString DEFAULT_RING_ACCT_ALIAS = QObject::tr("Jami account", "Default alias for new Jami account");
NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrated, QWidget* parent) :
NewWizardWidget::NewWizardWidget(QWidget* parent) :
NavWidget(parent),
ui(new Ui::NewWizardWidget),
account_(toBeMigrated),
wizardMode_(wizardMode),
wizardMode_(WizardMode::WIZARD),
lookupTimer_(this)
{
ui->setupUi(this);
......@@ -67,20 +66,28 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate
statusInvalidPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-error_outline-24px.svg", RingTheme::urgentOrange_);
statusErrorPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-close-24px.svg", RingTheme::red_);
if (wizardMode_ == MIGRATION) {
changePage(ui->createRingAccountPage);
ui->usernameEdit->setEnabled(false);
ui->usernameEdit->setText(QString::fromStdString(toBeMigrated->profileInfo.alias));
ui->previousButton->hide();
ui->infoWidget->show();
ui->infoLabel->setText(tr("Your account needs to be migrated. Enter your password."));
} else {
ui->infoWidget->hide();
setNavBarVisibility(false);
}
ui->infoWidget->hide();
setNavBarVisibility(false, true);
lookupTimer_.setSingleShot(true);
connect(ui->fileImportBtn, &QPushButton::clicked,
[this] {
QString filePath;
filePath = QFileDialog::getOpenFileName(this,
tr("Open File"),
QString(),
tr("Jami archive files (*.gz); All files (*)"));
fileToImport_ = QDir::toNativeSeparators(filePath);
if (!fileToImport_.isEmpty()) {
QFileInfo fi(filePath);
ui->fileImportBtn->setText(fi.fileName());
} else {
ui->fileImportBtn->setText(tr("(None)"));
}
validateWizardProgression();
});
connect(&lookupTimer_, &QTimer::timeout,
this, &NewWizardWidget::timeoutNameLookupTimer);
......@@ -94,6 +101,11 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate
validateWizardProgression();
});
connect(ui->pinEdit, &QLineEdit::textChanged,
[this] {
validateWizardProgression();
});
ui->containerWidget->setVisible(false);
}
......@@ -102,6 +114,18 @@ NewWizardWidget::~NewWizardWidget()
delete ui;
}
void
NewWizardWidget::setToMigrate(AccountInfo* toBeMigrated)
{
wizardMode_ = MIGRATION;
changePage(ui->createRingAccountPage);
ui->usernameEdit->setEnabled(false);
ui->usernameEdit->setText(QString::fromStdString(toBeMigrated->profileInfo.alias));
ui->previousButton->hide();
ui->infoWidget->show();
ui->infoLabel->setText(tr("Your account needs to be migrated. Enter your password."));
}
void
NewWizardWidget::updateNameRegistrationUi(NameRegistrationUIState state)
{
......@@ -151,7 +175,7 @@ NewWizardWidget::processWizardInformations()
QString archivePin = (ui->pinEdit->text().isEmpty() || ui->pinEdit->text().isNull()) ? QString() : ui->pinEdit->text();
changePage(ui->spinnerPage);
createRingAccount(accountAlias, ui->passwordEdit->text(), archivePin);
createRingAccount(accountAlias, ui->passwordEdit->text(), archivePin, fileToImport_);
ui->passwordEdit->clear();
ui->confirmPasswordEdit->clear();
......@@ -170,7 +194,6 @@ NewWizardWidget::on_existingPushButton_clicked()
void
NewWizardWidget::on_newAccountButton_clicked()
{
wizardMode_ = NEW_ACCOUNT;
changePage(ui->createRingAccountPage);
}
......@@ -199,9 +222,16 @@ void NewWizardWidget::changePage(QWidget* toPage)
validateWizardProgression();
ui->setAvatarWidget->startBooth();
} else if (toPage == ui->linkRingAccountPage) {
fileToImport_ = QString("");
ui->fileImportBtn->setText(tr("(None)"));
ui->pinEdit->clear();
ui->importPasswordEdit->clear();
ui->pinEdit->setEnabled(true);
ui->fileImportBtn->setEnabled(true);
setNavBarVisibility(true);
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
validateWizardProgression();
} else if (toPage == ui->spinnerPage) {
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
......@@ -214,13 +244,15 @@ NewWizardWidget::updateCustomUI()
QPoint editUsernamePos = ui->usernameEdit->mapTo(this, ui->usernameEdit->rect().topRight());
lookupStatusLabel_->setGeometry(editUsernamePos.x() + 6, editUsernamePos.y() - 1, 30, 30);
QPoint editconfpassPos = ui->confirmPasswordEdit->mapTo(this, ui->confirmPasswordEdit->rect().topRight());
passwordStatusLabel_->setGeometry(editconfpassPos.x() + 6, editconfpassPos.y() - 1, 30, 30);
passwordStatusLabel_->setGeometry(editconfpassPos.x() + 6, editconfpassPos.y() - 1, 24, 24);
}
void
NewWizardWidget::setNavBarVisibility(bool nav, bool back)
{
ui->navBarWidget->setVisible(nav);
ui->navBarWidget->setVisible(nav || back);
ui->nextButton->setVisible(nav);
ui->previousButton->setVisible(nav);
ui->backButton->setVisible(back && LRCInstance::accountModel().getAccountList().size());
}
......@@ -232,10 +264,9 @@ NewWizardWidget::on_nextButton_clicked()
ui->setAvatarWidget->stopBooth();
disconnect(registeredNameFoundConnection_);
}
if (curWidget == ui->createRingAccountPage) {
if (curWidget == ui->createRingAccountPage ||
curWidget == ui->linkRingAccountPage) {
processWizardInformations();
// or
//validateFileImport();
}
}
......@@ -249,7 +280,6 @@ NewWizardWidget::on_previousButton_clicked()
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
}
if (curWidget == ui->createRingAccountPage ||
curWidget == ui->linkRingAccountPage) {
changePage(ui->welcomePage);
......@@ -342,16 +372,19 @@ NewWizardWidget::on_signUpCheckbox_toggled(bool checked)
validateWizardProgression();
}
void
NewWizardWidget::validateFileImport()
{
validateWizardProgression();
}
void
NewWizardWidget::validateWizardProgression()
{
qDebug() << "validating wizard progression...";
if (ui->stackedWidget->currentWidget() == ui->linkRingAccountPage) {
bool validPin = !ui->pinEdit->text().isEmpty();
ui->fileImportBtn->setEnabled(!validPin);
ui->fileImportLabel->setEnabled(!validPin);
bool validImport = !fileToImport_.isEmpty();
ui->pinEdit->setEnabled(!validImport);
ui->pinEditLabel->setEnabled(!validImport);
ui->nextButton->setEnabled(validPin || validImport);
return;
}
bool usernameOk =
!ui->signUpCheckbox->isChecked() ||
(ui->signUpCheckbox->isChecked() &&
......@@ -394,8 +427,11 @@ NewWizardWidget::createRingAccount(const QString &displayName,
auto confProps = LRCInstance::accountModel().getAccountConfig(accountId);
confProps.Ringtone.ringtonePath = Utils::GetRingtonePath().toStdString();
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
LRCInstance::editableAccountModel()->registerName(LRCInstance::getCurrAccId(),
"", registeredName_.toStdString());
LRCInstance::editableAccountModel()->registerName(
LRCInstance::getCurrAccId(),
"",
registeredName_.toStdString()
);
connect(LRCInstance::editableAccountModel(),
&lrc::api::NewAccountModel::nameRegistrationEnded,
[this] {
......
......@@ -38,17 +38,17 @@ public:
using AccountInfo = Info;
enum WizardMode { WIZARD, NEW_ACCOUNT, IMPORT, MIGRATION };
enum WizardMode { WIZARD, IMPORT, MIGRATION };
private:
enum NameRegistrationUIState { BLANK, INVALID, TAKEN, FREE, SEARCHING };
public:
explicit NewWizardWidget(WizardMode wizardMode = WIZARD,
AccountInfo* toBeMigrated = nullptr,
QWidget* parent = 0);
explicit NewWizardWidget(QWidget* parent = 0);
~NewWizardWidget();
void setToMigrate(AccountInfo* toBeMigrated);
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
......@@ -88,12 +88,12 @@ private:
QString registeredName_;
bool registrationStateOk_;
QMetaObject::Connection registeredNameFoundConnection_;
QString fileToImport_;
QLabel* passwordStatusLabel_;
void updateNameRegistrationUi(NameRegistrationUIState state);
void changePage(QWidget* toPage);
void setNavBarVisibility(bool visible, bool back=false);
void validateFileImport();
void validateWizardProgression();
void createRingAccount(const QString &displayName = QString(),
const QString &password = QString(),
......
......@@ -108,7 +108,7 @@
<string notr="true"/>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="welcomePage">
<layout class="QVBoxLayout" name="verticalLayout_3">
......@@ -295,6 +295,9 @@
</widget>
<widget class="QWidget" name="linkRingAccountPage">
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -303,16 +306,34 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<pointsize>18</pointsize>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
......@@ -322,10 +343,78 @@
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_15">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="horizontalWidget" native="true">
<layout class="QGridLayout" name="gridLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="linkInfoLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>195</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">padding:8px;background-color:#efefef;border:1px solid #e0e0e0; border-radius:16px;</string>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot;&gt;To link this device to another account, you first &lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:14px; font-weight:600; color:#555555;&quot;&gt;need to obtain a PIN&lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot;&gt; code. To generate the PIN code:&lt;/span&gt;&lt;/p&gt;
&lt;ol style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14px;&quot;&gt;Go to the &lt;/span&gt;&lt;span style=&quot; font-size:14px; font-weight:600;&quot;&gt;Account management setting&lt;/span&gt;&lt;span style=&quot; font-size:14px;&quot;&gt; of a previous device&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14px;&quot;&gt;Choose the &lt;/span&gt;&lt;span style=&quot; font-size:14px; font-weight:600;&quot;&gt;Jami account&lt;/span&gt;&lt;span style=&quot; font-size:14px;&quot;&gt; you want to use&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14px;&quot;&gt;Go to the &lt;/span&gt;&lt;span style=&quot; font-size:14px; font-weight:600;&quot;&gt;Devices&lt;/span&gt;&lt;span style=&quot; font-size:14px;&quot;&gt; tab&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot; style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14px;&quot;&gt;Select &lt;/span&gt;&lt;span style=&quot; font-size:14px; font-weight:600;&quot;&gt;Add a device&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:14px; color:#555555;&quot;&gt;You will get the necessary PIN to complete this form. The PIN is only valid for &lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:14px; font-weight:600; color:#555555;&quot;&gt;10 minutes&lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:10px; color:#555555;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_14">
<property name="orientation">
......@@ -356,7 +445,7 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="pinEditLabel">
<property name="minimumSize">
<size>
<width>0</width>
......@@ -365,7 +454,7 @@
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
......@@ -419,7 +508,7 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="fileImportLabel">
<property name="minimumSize">
<size>
<width>0</width>
......@@ -428,7 +517,7 @@
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
......@@ -453,6 +542,11 @@
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="toolTip">
<string>Link from exported account archive file</string>
</property>
......@@ -476,7 +570,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
<height>2</height>
</size>
</property>
</spacer>
......@@ -521,7 +615,7 @@
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
......@@ -542,7 +636,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>30</height>
</size>
</property>
</spacer>
......@@ -1033,7 +1127,10 @@
</size>
</property>
<property name="toolTip">
<string>Register your username on the Ring. This will reserve the username so that only you can use it. Your friends will be able to call you with your usename instead of using your RingID.</string>
<string>Register your username.
This will reserve the username so that only you can use it.
Your friends will be able to call you with your usename
instead of using your ID.</string>
</property>
<property name="accessibleName">
<string>Public username checkbox</string>
......@@ -1420,6 +1517,11 @@
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="toolTip">
<string>Previous page button</string>
</property>
......@@ -1455,6 +1557,11 @@
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="toolTip">
<string>Cancel account create/link</string>
</property>
......@@ -1496,6 +1603,11 @@
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="toolTip">
<string>Next page Button</string>
</property>
......
<RCC>
<qresource prefix="/">
<file>images/icons/outline-info-24px.svg</file>
<file>images/icons/baseline-camera_alt-24px.svg</file>
<file>images/icons/baseline-refresh-24px.svg</file>
<file>images/jami_rolling_spinner.gif</file>
......
......@@ -40,7 +40,9 @@ SmartListModel::SmartListModel(const lrc::api::account::Info &acc, QObject *pare
int SmartListModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return acc_.conversationModel->allFilteredConversations().size();
try {
return acc_.conversationModel->allFilteredConversations().size();
} catch (...) {}
}
return 0; // A valid QModelIndex returns 0 as no entry has sub-elements
}
......
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