Commit cb7efa63 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk

accountmigration: add account migration support

Change-Id: Ibacd1eb552a26b8ef158cf28a29daf0e0b9b74b6
parent 44f7d1c2
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2015-2019 by Savoir-faire Linux *
* 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 <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "accountmigrationdialog.h"
#include "ui_accountmigration.h"
#include <QTimer>
#include <QtConcurrent/QtConcurrent>
AccountMigrationDialog::AccountMigrationDialog(QWidget *parent, const std::string& accountId) :
QDialog(parent),
ui(new Ui::AccountMigrationDialog),
accountId_(accountId)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
auto& avatarInfo = LRCInstance::accountModel().getAccountInfo(accountId_);
auto managerUsername = QString::fromStdString(avatarInfo.confProperties.managerUsername);
auto managerUri = QString::fromStdString(avatarInfo.confProperties.managerUri);
auto username = QString::fromStdString(avatarInfo.confProperties.username);
auto alias = QString::fromStdString(LRCInstance::accountModel().getAccountInfo(accountId_).profileInfo.alias);
// manager uri
if (!managerUri.isEmpty()) {
ui->managerUriInputLabel->setText(managerUri);
} else {
ui->managerUriLabel->hide();
ui->managerUriInputLabel->hide();
ui->gridLayout->removeWidget(ui->managerUriLabel);
ui->gridLayout->removeWidget(ui->managerUriInputLabel);
ui->gridLayout->removeItem(ui->managerUriHorizontalSpacer);
}
// username
if (!username.isEmpty()) {
ui->usernameInputLabel->setText(username);
} else {
if (avatarInfo.confProperties.managerUsername.empty()) {
ui->usernameLabel->hide();
ui->usernameInputLabel->hide();
ui->gridLayout->removeWidget(ui->usernameInputLabel);
ui->gridLayout->removeWidget(ui->usernameLabel);
ui->gridLayout->removeItem(ui->usernameHorizontalSpacer);
} else {
ui->usernameInputLabel->setText(managerUsername);
}
}
// alias
if (!alias.isEmpty()) {
ui->aliasInputLabel->setText(alias);
} else {
ui->aliasLabel->hide();
ui->aliasInputLabel->hide();
ui->gridLayout->removeWidget(ui->aliasLabel);
ui->gridLayout->removeWidget(ui->aliasInputLabel);
ui->gridLayout->removeItem(ui->aliasHorizontalSpacer);
}
ui->avatarLabel->setPixmap(QPixmap::fromImage(Utils::accountPhoto(avatarInfo, ui->avatarLabel->size())));
connect(ui->passwordInputLineEdit, &QLineEdit::editingFinished, this, &AccountMigrationDialog::slotPasswordEditingFinished);
connect(ui->deleteAccountPushButton, &QAbstractButton::clicked, this, &AccountMigrationDialog::slotDeleteButtonClicked);
connect(ui->migrationPushButton, &QAbstractButton::clicked, this, &AccountMigrationDialog::slotMigrationButtonClicked);
connect(ui->passwordInputLineEdit, &QLineEdit::textChanged,
[this](const QString& text) {
if (text.isEmpty()) {
ui->migrationPushButton->setDisabled(true);
} else {
ui->migrationPushButton->setDisabled(false);
}
password_ = text.toStdString();
});
ui->migrationPushButton->setDisabled(true);
migrationSpinnerMovie_ = new QMovie(":/images/jami_eclipse_spinner.gif");
ui->spinnerLabel->setMovie(migrationSpinnerMovie_);
Utils::setStackWidget(ui->stackedWidget, ui->accountMigrationPage);
}
AccountMigrationDialog::~AccountMigrationDialog()
{
delete ui;
}
void
AccountMigrationDialog::slotPasswordEditingFinished()
{
password_ = ui->passwordInputLineEdit->text().toStdString();
}
void
AccountMigrationDialog::slotDeleteButtonClicked()
{
LRCInstance::accountModel().removeAccount(accountId_);
done(DialogCode::Accepted);
}
void
AccountMigrationDialog::slotMigrationButtonClicked()
{
Utils::setStackWidget(ui->stackedWidget, ui->migrationWaitingPage);
migrationSpinnerMovie_->start();
connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::migrationEnded,
[this](const std::string& accountId, bool ok) {
if (accountId_ != accountId) {
return;
}
if (!ok) {
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("Migration Failed"));
QTimer::singleShot(1000, this,
[this] {
Utils::setStackWidget(ui->stackedWidget, ui->accountMigrationPage);
ui->passwordInputLineEdit->clear();
ui->spinnerLabel->setMovie(migrationSpinnerMovie_);
ui->progressLabel->setStyleSheet("color:black;");
ui->progressLabel->setText(tr("Migrating your Jami account..."));
});
} else {
done(DialogCode::Accepted);
}
});
QtConcurrent::run(
[this] {
auto config = LRCInstance::accountModel().getAccountConfig(accountId_);
config.archivePassword = password_;
LRCInstance::accountModel().setAccountConfig(accountId_, config);
});
}
void
AccountMigrationDialog::closeEvent(QCloseEvent *event)
{
done(DialogCode::Rejected);
QDialog::closeEvent(event);
}
/***************************************************************************
* Copyright (C) 2015-2019 by Savoir-faire Linux *
* 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 <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
#include <QDialog>
#include <QMovie>
#include "utils.h"
#include "lrcinstance.h"
namespace Ui {
class AccountMigrationDialog;
}
class AccountMigrationDialog : public QDialog
{
Q_OBJECT;
public:
explicit AccountMigrationDialog(QWidget *parent = 0, const std::string& accountId = {});
~AccountMigrationDialog();
private:
Ui::AccountMigrationDialog *ui;
std::string accountId_;
std::string password_;
QMovie* migrationSpinnerMovie_;
private slots:
void slotPasswordEditingFinished();
void slotDeleteButtonClicked();
void slotMigrationButtonClicked();
protected:
void closeEvent(QCloseEvent *event);
};
......@@ -73,7 +73,8 @@ HEADERS += ./aboutdialog.h \
./updatedownloaddialog.h \
./sipinputpanel.h \
./callaudioonlyavataroverlay.h \
./overlaybutton.h
./overlaybutton.h \
./accountmigrationdialog.h
SOURCES += ./aboutdialog.cpp \
./banneditemwidget.cpp \
./conversationsfilterwidget.cpp \
......@@ -128,7 +129,8 @@ SOURCES += ./aboutdialog.cpp \
./videooverlay.cpp \
./sipinputpanel.cpp \
./callaudioonlyavataroverlay.cpp \
./overlaybutton.cpp
./overlaybutton.cpp \
./accountmigrationdialog.cpp
FORMS += ./aboutdialog.ui \
./advancedsipsettingwidget.ui \
./callwidget.ui \
......@@ -153,5 +155,6 @@ FORMS += ./aboutdialog.ui \
./updateconfirmdialog.ui \
./videoview.ui \
./sipkeypad.ui \
./callaudioonlyavataroverlay.ui
./callaudioonlyavataroverlay.ui \
./accountmigration.ui
RESOURCES += ressources.qrc
......@@ -19,6 +19,7 @@
#include "mainwindow.h"
#include "accountmigrationdialog.h"
#include "globalinstances.h"
#include "downloadmanager.h"
#include "lrcinstance.h"
......@@ -93,6 +94,13 @@ fileDebug(QFile& debugFile)
});
}
void
exitApp(RunGuard& guard)
{
GlobalSystemTray::instance().hide();
guard.release();
}
int
main(int argc, char* argv[])
{
......@@ -238,6 +246,28 @@ main(int argc, char* argv[])
}
}
auto accountList = LRCInstance::accountModel().getAccountList();
for (const std::string& i : accountList) {
auto accountStatus = LRCInstance::accountModel().getAccountInfo(i).status;
if (accountStatus == lrc::api::account::Status::ERROR_NEED_MIGRATION) {
std::unique_ptr<AccountMigrationDialog> dialog = std::make_unique<AccountMigrationDialog>(nullptr, i);
int status = dialog->exec();
//migration failed
if (!status) {
#ifdef Q_OS_WIN
FreeConsole();
#endif
exitApp(guard);
return status;
}
}
}
splash->finish(&MainWindow::instance());
splash->deleteLater();
QFontDatabase::addApplicationFont(":/images/FontAwesome.otf");
MainWindow::instance().createThumbBar();
......@@ -249,19 +279,10 @@ main(int argc, char* argv[])
MainWindow::instance().hide();
}
QObject::connect(&a, &QApplication::aboutToQuit,
[&guard] {
GlobalSystemTray::instance().hide();
guard.release();
});
splash->finish(&MainWindow::instance());
splash->deleteLater();
QObject::connect(&a, &QApplication::aboutToQuit, [&guard] { exitApp(guard); });
auto ret = a.exec();
LRCInstance::reset();
#ifdef Q_OS_WIN
FreeConsole();
#endif
......
......@@ -230,6 +230,7 @@ del /s /q $(OutDir)\Jami.exp</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="accountmigrationdialog.cpp" />
<ClCompile Include="advancedsettingswidget.cpp" />
<ClCompile Include="advancedsipsettingwidget.cpp" />
<ClCompile Include="avatargraphicsview.cpp" />
......@@ -463,6 +464,10 @@ del /s /q $(OutDir)\Jami.exp</Command>
<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)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>
<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>
<QtMoc Include="accountmigrationdialog.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)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>
<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="pixbufmanipulator.h" />
<QtMoc Include="ringbutton.h">
</QtMoc>
......@@ -634,6 +639,7 @@ del /s /q $(OutDir)\Jami.exp</Command>
<ItemGroup>
<QtUic Include="aboutdialog.ui">
</QtUic>
<QtUic Include="accountmigration.ui" />
<QtUic Include="advancedsettingswidget.ui">
<SubType>Designer</SubType>
</QtUic>
......
......@@ -228,6 +228,9 @@
<ClCompile Include="overlaybutton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="accountmigrationdialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="aboutdialog.h">
......@@ -398,6 +401,9 @@
<QtMoc Include="overlaybutton.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="accountmigrationdialog.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......@@ -689,6 +695,9 @@
<QtUic Include="sipkeypad.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="accountmigration.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<None Include="images\FontAwesome.otf">
......
......@@ -347,7 +347,6 @@ void SettingsWidget::leaveSettingsSlot()
photoBooth->stopBooth();
});
}
emit NavigationRequested(ScreenEnum::CallScreen);
}
......
......@@ -273,7 +273,7 @@ QScrollBar::handle:vertical{
QWidget#messagingPage, QWidget#contactRequestPage,
QDialog#DeleteAccountDialog, QDialog#updateDownloadDialog,
QDialog#UpdateConfirmDialog {
QDialog#UpdateConfirmDialog, QDialog#AccountMigrationDialog {
background: rgb(255, 255, 255);
}
......@@ -287,8 +287,24 @@ QDialog#DeleteAccountDialog {
background: rgb(255, 255, 255);
}
QPushButton#deleteAccountPushButton {
background-color: red;
border: 0px;
border-radius: 15px;
height: 30px;
color: white;
}
QPushButton#deleteAccountPushButton:hover {
background-color: rgb(230, 0, 0);
}
QPushButton#deleteAccountPushButton:disabled {
background-color: rgba(255, 0, 0, 0.8);
}
QPushButton#nextButton, QPushButton#playButton, QPushButton#clearHistoryButton, QPushButton#doTransferButton,
QPushButton#photoButton,
QPushButton#photoButton, QPushButton#migrationPushButton,
QPushButton#fromDeviceButton, QPushButton#newAccountButton, QPushButton#previousButton, QPushButton#exportButton, QPushButton#newSIPAccountButton, QPushButton#fromBackupButton, QPushButton#connectAccountManagerButton,
QPushButton#cancelAddButton, QPushButton#exportOnRingButton, QPushButton#addDeviceButton, QPushButton#exportEndedOkButton,
QPushButton#errorPushButton, QPushButton#registerButton, QPushButton#acceptCRButton, QPushButton#discardCRButton, QPushButton#deleteCancelBtn,
......@@ -310,7 +326,7 @@ QPushButton#registerButton:disabled, QPushButton#acceptCRButton:disabled, QPushB
QPushButton#deleteCancelBtn:disabled, QPushButton#dhtImportBtn:disabled, QPushButton#fileImportBtn:disabled,
QPushButton#changePassBtn:disabled, QPushButton#confirmChangeBtn:disabled, QPushButton#backButton:disabled,
QPushButton#fromDeviceButton:disabled, QPushButton#connectAccountManagerButton:disabled, QPushButton#exportBtn:disabled,
QPushButton#skipBtn:disabled {
QPushButton#skipBtn:disabled, QPushButton#migrationPushButton:disabled {
background: rgba(242, 242, 242, 0.8);
color: grey;
}
......@@ -328,7 +344,7 @@ QPushButton#existingPushButton:hover, QPushButton#newAccountButton:hover, QPushB
QPushButton#exportButton:hover, QPushButton#cancelAddButton:hover, QPushButton#exportOnRingButton:hover,
QPushButton#addDeviceButton:hover, QPushButton#exportEndedOkButton:hover, QPushButton#errorPushButton:hover,
QPushButton#registerButton:hover, QPushButton#acceptCRButton:hover, QPushButton#discardCRButton:hover,
QPushButton#deleteCancelBtn:hover, QPushButton#dhtImportBtn:hover, QPushButton#fileImportBtn:hover,
QPushButton#deleteCancelBtn:hover, QPushButton#dhtImportBtn:hover, QPushButton#fileImportBtn:hover, QPushButton#migrationPushButton:hover,
QPushButton#changePassBtn:hover, QPushButton#confirmChangeBtn:hover, QPushButton#backButton:hover, QPushButton#skipBtn:hover,
QPushButton#fromDeviceButton:hover, QPushButton#connectAccountManagerButton:hover, QPushButton#exportBtn:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #2b4b7e, stop: 1.0 #001d4d);
......@@ -341,7 +357,7 @@ QPushButton#deleteButton:hover, QPushButton#deleteBanBtn:hover, QPushButton#canc
}
QPushButton#nextButton:pressed, QPushButton#playButton:pressed, QPushButton#clearHistoryButton:pressed,
QPushButton#doTransferButton:pressed, QPushButton#photoButton:pressed, QPushButton#skipBtn:pressed,
QPushButton#doTransferButton:pressed, QPushButton#photoButton:pressed, QPushButton#skipBtn:pressed, QPushButton#migrationPushButton:pressed,
QPushButton#existingPushButton:pressed, QPushButton#newAccountButton:pressed, QPushButton#previousButton:pressed, QPushButton#newSIPAccountButton:pressed,
QPushButton#exportButton:pressed, QPushButton#cancelAddButton:pressed, QPushButton#exportOnRingButton:pressed,
QPushButton#addDeviceButton:pressed, QPushButton#exportEndedOkButton:pressed, QPushButton#errorPushButton:pressed,
......
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