blob: 47630c8e9a652ec04f919a7fcbd641089482dc90 [file] [log] [blame]
Andreas Traczyk6ace34f2018-12-14 14:31:23 -05001/**************************************************************************
Sébastien Blin68abac92019-01-02 17:41:31 -05002* Copyright (C) 2018-2019 by Savoir-faire Linux *
Andreas Traczyk6ace34f2018-12-14 14:31:23 -05003* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
4* *
5* This program is free software; you can redistribute it and/or modify *
6* it under the terms of the GNU General Public License as published by *
7* the Free Software Foundation; either version 3 of the License, or *
8* (at your option) any later version. *
9* *
10* This program is distributed in the hope that it will be useful, *
11* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13* GNU General Public License for more details. *
14* *
15* You should have received a copy of the GNU General Public License *
16* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17**************************************************************************/
18
19#pragma once
20
21#include <QLabel>
22#include <QtConcurrent/QtConcurrent>
23
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050024#include "lrcinstance.h"
25#include "navwidget.h"
26
27namespace Ui {
28class NewWizardWidget;
29}
30
31using namespace lrc::api::account;
32
33class NewWizardWidget : public NavWidget
34{
35 Q_OBJECT
36
37public:
38
39 using AccountInfo = Info;
40
Andreas Traczyk3199a1f2018-12-26 18:20:09 -050041 enum WizardMode { WIZARD, IMPORT, MIGRATION };
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050042
43private:
44 enum NameRegistrationUIState { BLANK, INVALID, TAKEN, FREE, SEARCHING };
45
46public:
Andreas Traczyk3199a1f2018-12-26 18:20:09 -050047 explicit NewWizardWidget(QWidget* parent = 0);
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050048 ~NewWizardWidget();
49
Andreas Traczyk3199a1f2018-12-26 18:20:09 -050050 void setToMigrate(AccountInfo* toBeMigrated);
51
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050052 // NavWidget
53 virtual void navigated(bool to);
54 virtual void updateCustomUI();
55
56 //UI Slots
57private slots:
58 void on_existingPushButton_clicked();
59 void on_newAccountButton_clicked();
60 void on_nextButton_clicked();
61 void on_previousButton_clicked();
62 void on_passwordEdit_textChanged(const QString& arg1);
63
64private slots:
65 void on_usernameEdit_textChanged(const QString& arg1);
66 void slotRegisteredNameFound(const std::string& accountId,
67 LookupStatus status,
68 const std::string& address,
69 const std::string& name);
70 void handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name);
71 void timeoutNameLookupTimer();
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050072 void on_signUpCheckbox_toggled(bool checked);
73
74private:
75 Ui::NewWizardWidget* ui;
76
77 WizardMode wizardMode_;
78 QPixmap statusSuccessPixmap_;
79 QPixmap statusInvalidPixmap_;
80 QPixmap statusErrorPixmap_;
81
82 AccountInfo* account_;
83 QMovie* creationSpinnerMovie_;
84
85 QMovie* lookupSpinnerMovie_;
86 QTimer lookupTimer_;
87 QLabel* lookupStatusLabel_;
88 QString registeredName_;
89 bool registrationStateOk_;
90 QMetaObject::Connection registeredNameFoundConnection_;
Andreas Traczyk3199a1f2018-12-26 18:20:09 -050091 QString fileToImport_;
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050092 QLabel* passwordStatusLabel_;
Andreas Traczyk3199a1f2018-12-26 18:20:09 -050093
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050094 void updateNameRegistrationUi(NameRegistrationUIState state);
95 void changePage(QWidget* toPage);
96 void setNavBarVisibility(bool visible, bool back=false);
Andreas Traczyk6ace34f2018-12-14 14:31:23 -050097 void validateWizardProgression();
98 void createRingAccount(const QString &displayName = QString(),
99 const QString &password = QString(),
100 const QString &pin = QString(),
101 const QString &archivePath = QString());
102 void processWizardInformations();
103};