From 3199a1f04e70d38bcaff9df52ade9b5bafbfad8c Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Wed, 26 Dec 2018 18:20:09 -0500 Subject: [PATCH] wizard: support archive import and linking Change-Id: I8cd96ba6cd96a5334a1e10c6f2ecdbcd17901e5a --- images/icons/outline-info-24px.svg | 1 + mainwindow.cpp | 8 +- mainwindow.h | 1 + newwizardwidget.cpp | 98 ++++++++++++++------- newwizardwidget.h | 12 +-- newwizardwidget.ui | 136 ++++++++++++++++++++++++++--- ressources.qrc | 1 + smartlistmodel.cpp | 4 +- 8 files changed, 210 insertions(+), 51 deletions(-) create mode 100644 images/icons/outline-info-24px.svg diff --git a/images/icons/outline-info-24px.svg b/images/icons/outline-info-24px.svg new file mode 100644 index 0000000..ab9cff7 --- /dev/null +++ b/images/icons/outline-info-24px.svg @@ -0,0 +1 @@ +<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 diff --git a/mainwindow.cpp b/mainwindow.cpp index b3c69ef..efb48b5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); diff --git a/mainwindow.h b/mainwindow.h index 36ba031..02e6138 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -77,6 +77,7 @@ private: void setWindowSize(ScreenEnum scr, bool firstUse = false); ScreenEnum lastScr_; + int lastAccountCount_; Qt::WindowFlags flags_; void readSettingsFromRegistry(); diff --git a/newwizardwidget.cpp b/newwizardwidget.cpp index 3f47312..82f907b 100644 --- a/newwizardwidget.cpp +++ b/newwizardwidget.cpp @@ -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] { diff --git a/newwizardwidget.h b/newwizardwidget.h index 8239a45..8c4d2e7 100644 --- a/newwizardwidget.h +++ b/newwizardwidget.h @@ -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(), diff --git a/newwizardwidget.ui b/newwizardwidget.ui index 1a98d8d..146a6e1 100644 --- a/newwizardwidget.ui +++ b/newwizardwidget.ui @@ -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><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:14px; color:#555555;">To link this device to another account, you first </span><span style=" font-family:'Ubuntu'; font-size:14px; font-weight:600; color:#555555;">need to obtain a PIN</span><span style=" font-family:'Ubuntu'; font-size:14px; color:#555555;"> code. To generate the PIN code:</span></p> +<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-family:'Ubuntu'; font-size:14px; color:#555555;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14px;">Go to the </span><span style=" font-size:14px; font-weight:600;">Account management setting</span><span style=" font-size:14px;"> of a previous device</span></li> +<li style=" font-family:'Ubuntu'; font-size:14px; color:#555555;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14px;">Choose the </span><span style=" font-size:14px; font-weight:600;">Jami account</span><span style=" font-size:14px;"> you want to use</span></li> +<li style=" font-family:'Ubuntu'; font-size:14px; color:#555555;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14px;">Go to the </span><span style=" font-size:14px; font-weight:600;">Devices</span><span style=" font-size:14px;"> tab</span></li> +<li style=" font-family:'Ubuntu'; font-size:14px; color:#555555;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14px;">Select </span><span style=" font-size:14px; font-weight:600;">Add a device</span></li></ol> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:14px; color:#555555;">You will get the necessary PIN to complete this form. The PIN is only valid for </span><span style=" font-family:'Ubuntu'; font-size:14px; font-weight:600; color:#555555;">10 minutes</span><span style=" font-family:'Ubuntu'; font-size:10px; color:#555555;">.</span></p></body></html></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> diff --git a/ressources.qrc b/ressources.qrc index 717bcb8..187a3e3 100644 --- a/ressources.qrc +++ b/ressources.qrc @@ -1,5 +1,6 @@ <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> diff --git a/smartlistmodel.cpp b/smartlistmodel.cpp index be10454..03551f9 100644 --- a/smartlistmodel.cpp +++ b/smartlistmodel.cpp @@ -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 } -- GitLab