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(),
......
This diff is collapsed.
<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