Commit 6ace34fc authored by Andreas Traczyk's avatar Andreas Traczyk

add new wizard

Change-Id: I138136ff268d717967d62e2e612798c39f3e098d
parent 5bafcb9d
......@@ -25,6 +25,7 @@
#include "utils.h"
#include "accountlistmodel.h"
#include "ringthemeutils.h"
#include "lrcinstance.h"
#undef REGISTERED
......@@ -62,6 +63,20 @@ AccountItemDelegate::paint(QPainter* painter,
QRect &rect = opt.rect;
QFont font(painter->font());
font.setPointSize(fontSize_);
QPen pen(painter->pen());
// is it the add account row?
if (index.row() == LRCInstance::accountModel().getAccountList().size()) {
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
painter->setFont(font);
QFontMetrics fontMetrics(font);
painter->drawText(rect, Qt::AlignVCenter | Qt::AlignHCenter, tr("Add Account") + "+");
return;
}
// Avatar drawing
opt.decorationSize = QSize(avatarSize_, avatarSize_);
opt.decorationPosition = QStyleOptionViewItem::Left;
......@@ -72,8 +87,6 @@ AccountItemDelegate::paint(QPainter* painter,
QPixmap::fromImage(index.data(AccountListModel::Role::Picture).value<QImage>())
.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
QFont font(painter->font());
// Presence indicator
QPainterPath outerCircle, innerCircle;
QPointF center(rectAvatar.right() - avatarSize_ / 6, (rectAvatar.bottom() - avatarSize_ / 6) + 1);
......@@ -87,9 +100,6 @@ AccountItemDelegate::paint(QPainter* painter,
painter->fillPath(innerCircle, RingTheme::presenceGreen_);
}
font.setPointSize(fontSize_);
QPen pen(painter->pen());
painter->setPen(pen);
QRect rectTexts(dx_ + rect.left() + dx_ + avatarSize_,
......
......@@ -37,7 +37,7 @@ AccountListModel::AccountListModel(QObject *parent)
int AccountListModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return LRCInstance::accountModel().getAccountList().size(); // count
return LRCInstance::accountModel().getAccountList().size() + 1; // count
}
return 0; // A valid QModelIndex returns 0 as no entry has sub-elements
}
......
......@@ -128,6 +128,11 @@ CallWidget::CallWidget(QWidget* parent) :
connect(ui->currentAccountComboBox, &CurrentAccountComboBox::settingsButtonClicked,
this, &CallWidget::settingsButtonClicked);
connect(ui->currentAccountComboBox, &CurrentAccountComboBox::newAccountClicked,
[this]() {
emit NavigationRequested(ScreenEnum::WizardScreen);
});
connect(ui->videoWidget, &VideoView::setChatVisibility,
[this](bool visible) {
if (visible) {
......@@ -223,12 +228,17 @@ CallWidget::navigated(bool to)
if (to) {
updateSmartList();
connectConversationModel();
ui->currentAccountComboBox->accountListUpdate();
} else {
QObject::disconnect(smartlistSelectionConnection_);
smartListModel_.reset(nullptr);
}
}
void CallWidget::updateCustomUI()
{
}
int
CallWidget::getLeftPanelWidth()
{
......@@ -592,8 +602,12 @@ void CallWidget::slotCustomContextMenuRequested(const QPoint& pos)
void CallWidget::slotAccountChanged(int index)
{
auto accountList = LRCInstance::accountModel().getAccountList();
setSelectedAccount(accountList.at(index));
try {
auto accountList = LRCInstance::accountModel().getAccountList();
setSelectedAccount(accountList.at(index));
} catch (...) {
qWarning() << "exception changing account";
}
}
void CallWidget::slotShowCallView(const std::string& accountId,
......@@ -914,12 +928,6 @@ CallWidget::on_sendContactRequestButton_clicked()
LRCInstance::getCurrentConversationModel()->makePermanent(selectedConvUid());
}
void
CallWidget::on_pendingCRBackButton_clicked()
{
ui->stackedWidget->setCurrentWidget(ui->welcomePage);
}
void
CallWidget::on_btnAudioCall_clicked()
{
......
......@@ -68,6 +68,7 @@ public:
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
void on_ringContactLineEdit_returnPressed();
......@@ -98,7 +99,6 @@ private slots:
void on_smartList_clicked(const QModelIndex &index);
void on_qrButton_toggled(bool checked);
void on_shareButton_clicked();
void on_pendingCRBackButton_clicked();
void on_btnAudioCall_clicked();
void on_btnVideoCall_clicked();
......
......@@ -39,7 +39,7 @@ CurrentAccountComboBox::CurrentAccountComboBox(QWidget* parent)
gearLabel_.setMouseTracking(true);
accountListUpdate();
accountItemDelegate_ = new AccountItemDelegate();
accountItemDelegate_ = new AccountItemDelegate(this);
this->setItemDelegate(accountItemDelegate_);
// combobox index changed and so must the avatar
......@@ -131,6 +131,10 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
painter.setPen(Qt::lightGray);
painter.drawText(comboBoxRect, (Qt::AlignBottom | Qt::AlignLeft), secondaryAccountID);
}
if (QWidget* popupWidget = this->findChild<QFrame*>()) {
popupWidget->setStyleSheet("QFrame{border: 0px;border-bottom: 1px solid #f0f0f0;}");
}
}
void CurrentAccountComboBox::resizeEvent(QResizeEvent* event)
......@@ -160,8 +164,13 @@ CurrentAccountComboBox::importLabelPhoto(int index)
void
CurrentAccountComboBox::setCurrentIndex(int index)
{
importLabelPhoto(index);
QComboBox::setCurrentIndex(index);
auto accountListSize = LRCInstance::accountModel().getAccountList().size();
if (index == accountListSize) {
emit newAccountClicked();
} else if (index < accountListSize) {
importLabelPhoto(index);
QComboBox::setCurrentIndex(index);
}
}
void
......@@ -176,9 +185,7 @@ void
CurrentAccountComboBox::mousePressEvent(QMouseEvent* mouseEvent)
{
if (!gearLabel_.frameGeometry().contains(mouseEvent->localPos().toPoint())) {
if (count() > 1) {
QComboBox::mousePressEvent(mouseEvent);
}
QComboBox::mousePressEvent(mouseEvent);
} else {
emit settingsButtonClicked();
}
......
......@@ -40,6 +40,7 @@ public:
signals:
void settingsButtonClicked();
void newAccountClicked();
protected:
void paintEvent(QPaintEvent* e);
......@@ -47,12 +48,12 @@ protected:
void mousePressEvent(QMouseEvent* mouseEvent);
void mouseMoveEvent(QMouseEvent* event);
void leaveEvent(QEvent * event);
void showPopup();
void hidePopup();
private:
void importLabelPhoto(int index);
void setupSettingsButton();
void showPopup();
void hidePopup();
AccountItemDelegate* accountItemDelegate_;
std::unique_ptr<AccountListModel> accountListModel_;
......
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3.2"/><path d="M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"/></svg>
\ No newline at end of file
<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 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ No newline at end of file
......@@ -104,6 +104,7 @@ int
main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication a(argc, argv);
......
......@@ -65,6 +65,7 @@ MainWindow::MainWindow(QWidget* parent) :
QIcon icon(":images/jami.png");
this->setWindowIcon(icon);
setWindowTitle(" ");
GlobalSystemTray& sysIcon = GlobalSystemTray::instance();
sysIcon.setIcon(icon);
......@@ -147,6 +148,15 @@ MainWindow::MainWindow(QWidget* parent) :
}
lastScr_ = startScreen;
connect(windowHandle(), &QWindow::activeChanged,
[this]() {
auto screenNumber = qApp->desktop()->screenNumber();
QScreen* screen = qApp->screens().at(screenNumber);
windowHandle()->setScreen(nullptr);
windowHandle()->setScreen(screen);
});
}
MainWindow::~MainWindow()
......@@ -297,7 +307,6 @@ void
MainWindow::setWindowSize(ScreenEnum scr, bool firstUse)
{
auto screenNumber = qApp->desktop()->screenNumber();
QScreen* screen = qApp->screens().at(screenNumber);
auto accountList = LRCInstance::accountModel().getAccountList();
if (scr == ScreenEnum::WizardScreen && !accountList.size()) {
hide();
......@@ -315,7 +324,6 @@ MainWindow::setWindowSize(ScreenEnum scr, bool firstUse)
qApp->desktop()->screenGeometry(screenNumber)
)
);
windowHandle()->setScreen(screen);
if (scr == ScreenEnum::WizardScreen) {
setWindowFlags(Qt::Dialog);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
......@@ -336,8 +344,21 @@ MainWindow::show()
disconnect(screenChangedConnection_);
screenChangedConnection_ = connect(windowHandle(), &QWindow::screenChanged,
[this](QScreen* screen) {
Q_UNUSED(screen);
adjustSize();
updateGeometry();
update();
// a little delay won't hurt ;)
QTimer::singleShot(100, this,
[this] {
qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI();
});
});
}
void
MainWindow::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI();
}
......@@ -59,6 +59,7 @@ public:
protected:
bool nativeEvent(const QByteArray& eventType, void* message, long* result);
void closeEvent(QCloseEvent* event);
void resizeEvent(QResizeEvent *event);
public slots:
void onRingEvent(const QString& uri);
......
......@@ -463,7 +463,7 @@
</property>
<item>
<widget class="QStackedWidget" name="navStack">
<widget class="WizardWidget" name="wizardwidget"/>
<widget class="NewWizardWidget" name="wizardwidget"/>
<widget class="CallWidget" name="callwidget"/>
<widget class="SettingsWidget" name="settingswidget">
<property name="sizePolicy">
......@@ -487,15 +487,15 @@
<container>1</container>
</customwidget>
<customwidget>
<class>WizardWidget</class>
<class>SettingsWidget</class>
<extends>QWidget</extends>
<header>wizardwidget.h</header>
<container>1</container>
<header>settingswidget.h</header>
</customwidget>
<customwidget>
<class>SettingsWidget</class>
<class>NewWizardWidget</class>
<extends>QWidget</extends>
<header>settingswidget.h</header>
<header>newwizardwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
......
......@@ -37,6 +37,7 @@ public:
~NavWidget();
virtual void navigated(bool to) = 0;
virtual void updateCustomUI() = 0;
signals:
void NavigationRequested(ScreenEnum screen);
......
/**************************************************************************
* Copyright (C) 2015-2018 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* Author: Anthony Lonard <anthony.leonard@savoirfairelinux.com> *
* Author: Olivier Soldano <olivier.soldano@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 <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "newwizardwidget.h"
#include "ui_newwizardwidget.h"
#include <QMovie>
#include <QMessageBox>
#include <QFileDialog>
#include <QBitmap>
#include "accountmodel.h"
#include "account.h"
#include "profilemodel.h"
#include "profile.h"
#include "namedirectory.h"
#include "utils.h"
#include "ringthemeutils.h"
const QString DEFAULT_RING_ACCT_ALIAS = QObject::tr("Jami account", "Default alias for new Jami account");
NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrated, QWidget* parent) :
NavWidget(parent),
ui(new Ui::NewWizardWidget),
account_(toBeMigrated),
wizardMode_(wizardMode),
lookupTimer_(this)
{
ui->setupUi(this);
QPixmap logo(":/images/logo-jami-standard-coul.png");
ui->welcomeLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation));
ui->welcomeLogo->setAlignment(Qt::AlignHCenter);
ui->fullNameEdit->setText(Utils::GetCurrentUserName());
creationSpinnerMovie_ = new QMovie(":/images/jami_eclipse_spinner.gif");
ui->spinnerLabel->setMovie(creationSpinnerMovie_);
creationSpinnerMovie_->start();
lookupSpinnerMovie_ = new QMovie(":/images/jami_rolling_spinner.gif");
lookupSpinnerMovie_->setScaledSize(QSize(30, 30));
lookupStatusLabel_ = new QLabel(this);
lookupStatusLabel_->setMovie(lookupSpinnerMovie_);
lookupStatusLabel_->hide();
registrationStateOk_ = false;
passwordStatusLabel_ = new QLabel(this);
statusSuccessPixmap_ = Utils::generateTintedPixmap(":/images/icons/baseline-done-24px.svg", RingTheme::presenceGreen_);
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);
}
lookupTimer_.setSingleShot(true);
connect(&lookupTimer_, &QTimer::timeout,
this, &NewWizardWidget::timeoutNameLookupTimer);
connect(ui->backButton, &QPushButton::clicked,
[this] {
emit NavigationRequested(ScreenEnum::CallScreen);
});
connect(ui->confirmPasswordEdit, &QLineEdit::textChanged,
[this] {
validateWizardProgression();
});
connect(ui->setAvatarWidget, &PhotoboothWidget::photoTaken,
this, &NewWizardWidget::on_photoTaken);
connect(ui->setAvatarWidget, &PhotoboothWidget::photoReady,
[this] {
ui->setAvatarWidget->startBooth();
});
ui->containerWidget->setVisible(false);
}
NewWizardWidget::~NewWizardWidget()
{
delete ui;
}
void
NewWizardWidget::updateNameRegistrationUi(NameRegistrationUIState state)
{
switch (state) {
case NameRegistrationUIState::BLANK:
lookupStatusLabel_->hide();
break;
case NameRegistrationUIState::INVALID:
lookupStatusLabel_->setPixmap(statusInvalidPixmap_);
break;
case NameRegistrationUIState::TAKEN:
lookupStatusLabel_->setPixmap(statusErrorPixmap_);
break;
case NameRegistrationUIState::FREE:
lookupStatusLabel_->setPixmap(statusSuccessPixmap_);
break;
case NameRegistrationUIState::SEARCHING:
lookupStatusLabel_->setMovie(lookupSpinnerMovie_);
lookupSpinnerMovie_->stop();
lookupSpinnerMovie_->start();
lookupStatusLabel_->show();
break;
}
}
void
NewWizardWidget::navigated(bool to)
{
ui->containerWidget->setVisible(to);
changePage(ui->welcomePage);
Utils::setStackWidget(ui->stackedWidget, ui->welcomePage);
}
void
NewWizardWidget::processWizardInformations()
{
if (wizardMode_ == MIGRATION)
ui->progressLabel->setText(tr("Migrating your Jami account..."));
else if (wizardMode_ == IMPORT)
ui->progressLabel->setText(tr("Importing account archive..."));
else
ui->progressLabel->setText(tr("Generating your Jami account..."));
if (wizardMode_ != IMPORT) {
QString accountAlias = (ui->fullNameEdit->text().isEmpty() ||
ui->fullNameEdit->text().isNull()) ? DEFAULT_RING_ACCT_ALIAS : ui->fullNameEdit->text();
QString archivePin = (ui->pinEdit->text().isEmpty() || ui->pinEdit->text().isNull()) ? QString() : ui->pinEdit->text();
changePage(ui->spinnerPage);
createRingAccount(accountAlias, ui->passwordEdit->text(), archivePin);
ui->passwordEdit->clear();
ui->confirmPasswordEdit->clear();
ui->pinEdit->clear();
}
Utils::CreateStartupLink();
}
void
NewWizardWidget::on_photoTaken(QString fileName)
{
ui->setAvatarWidget->stopBooth();
}
void
NewWizardWidget::on_existingPushButton_clicked()
{
changePage(ui->linkRingAccountPage);
}
void
NewWizardWidget::on_newAccountButton_clicked()
{
wizardMode_ = NEW_ACCOUNT;
changePage(ui->createRingAccountPage);
}
void NewWizardWidget::changePage(QWidget* toPage)
{
if (toPage == ui->spinnerPage) {
setNavBarVisibility(false);
}
Utils::setStackWidget(ui->stackedWidget, toPage);
if (toPage == ui->welcomePage) {
setNavBarVisibility(false, true);
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
} else if (toPage == ui->createRingAccountPage) {
ui->usernameEdit->clear();
ui->passwordEdit->clear();
ui->confirmPasswordEdit->clear();
ui->signUpCheckbox->setChecked(true);
ui->usernameEdit->setEnabled(true);
setNavBarVisibility(true);
updateCustomUI();
registeredNameFoundConnection_ = connect(
&LRCInstance::accountModel(), &lrc::api::NewAccountModel::registeredNameFound,
this, &NewWizardWidget::slotRegisteredNameFound);
validateWizardProgression();
ui->setAvatarWidget->startBooth();
} else if (toPage == ui->linkRingAccountPage) {
setNavBarVisibility(true);
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
} else if (toPage == ui->spinnerPage) {
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
}
}
void
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);
}
void
NewWizardWidget::setNavBarVisibility(bool nav, bool back)
{
ui->navBarWidget->setVisible(nav);
ui->backButton->setVisible(back && LRCInstance::accountModel().getAccountList().size());
}
void
NewWizardWidget::on_nextButton_clicked()
{
const QWidget* curWidget = ui->stackedWidget->currentWidget();
if (curWidget != ui->createRingAccountPage) {
ui->setAvatarWidget->stopBooth();
disconnect(registeredNameFoundConnection_);
}
if (curWidget == ui->createRingAccountPage) {
processWizardInformations();
// or
//validateFileImport();
}
}
void
NewWizardWidget::on_previousButton_clicked()
{
const QWidget* curWidget = ui->stackedWidget->currentWidget();
if (curWidget != ui->createRingAccountPage) {
ui->setAvatarWidget->stopBooth();
disconnect(registeredNameFoundConnection_);
lookupStatusLabel_->hide();
passwordStatusLabel_->hide();
}
if (curWidget