Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@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 | |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 19 | #include "wizarddialog.h" |
| 20 | #include "ui_wizarddialog.h" |
| 21 | |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 22 | #include <QMovie> |
| 23 | |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 24 | #include "accountmodel.h" |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 25 | #include "account.h" |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 26 | #include "profilemodel.h" |
| 27 | #include "profile.h" |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 28 | |
| 29 | #include "utils.h" |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 30 | #include "photoboothdialog.h" |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 31 | |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 32 | WizardDialog::WizardDialog(QWidget* parent) : |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 33 | QDialog(parent), |
| 34 | ui(new Ui::WizardDialog) |
| 35 | { |
| 36 | ui->setupUi(this); |
| 37 | |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 38 | Qt::WindowFlags flags = windowFlags(); |
| 39 | flags = flags & (~Qt::WindowContextHelpButtonHint); |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 40 | |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 41 | setWindowFlags(flags); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 42 | |
| 43 | QPixmap logo(":/images/logo-ring-standard-coul.png"); |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 44 | ui->ringLogo->setPixmap(logo.scaledToHeight(65, Qt::SmoothTransformation)); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 45 | ui->ringLogo->setAlignment(Qt::AlignHCenter); |
Edric Milaret | 3658736 | 2016-02-04 12:30:52 -0500 | [diff] [blame] | 46 | |
| 47 | ui->usernameEdit->setText(Utils::GetCurrentUserName()); |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | WizardDialog::~WizardDialog() |
| 51 | { |
| 52 | delete ui; |
| 53 | } |
| 54 | |
| 55 | void |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 56 | WizardDialog::accept() |
| 57 | { |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 58 | ui->label->setText(tr("Please wait while we create your account.")); |
Nicolas Jager | 1ddb38d | 2016-01-20 11:11:49 -0500 | [diff] [blame] | 59 | ui->wizardButton->setEnabled(false); |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 60 | ui->usernameEdit->setEnabled(false); |
| 61 | |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 62 | auto profile = ProfileModel::instance().selectedProfile(); |
| 63 | |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 64 | repaint(); |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 65 | |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 66 | Utils::CreateStartupLink(); |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 67 | |
Edric Milaret | a3e4728 | 2015-10-23 15:20:30 -0400 | [diff] [blame] | 68 | auto account = AccountModel::instance().add(ui->usernameEdit->text(), Account::Protocol::RING); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 69 | if (not ui->usernameEdit->text().isEmpty()) { |
Edric Milaret | 4097d2f | 2016-02-09 14:41:50 -0500 | [diff] [blame] | 70 | account->setDisplayName(ui->usernameEdit->text()); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 71 | profile->person()->setFormattedName(ui->usernameEdit->text()); |
| 72 | } |
| 73 | else { |
| 74 | profile->person()->setFormattedName(tr("Unknown")); |
| 75 | } |
Edric Milaret | 031c305 | 2015-04-29 18:14:18 -0400 | [diff] [blame] | 76 | account->setRingtonePath(Utils::GetRingtonePath()); |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 77 | account->setUpnpEnabled(true); |
| 78 | |
| 79 | connect(account, SIGNAL(changed(Account*)), this, SLOT(endSetup(Account*))); |
| 80 | |
| 81 | account->performAction(Account::EditAction::SAVE); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 82 | |
| 83 | profile->setAccounts({account}); |
| 84 | profile->save(); |
Edric Milaret | 74e4b8b | 2015-05-15 10:25:00 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | WizardDialog::endSetup(Account* a) |
| 89 | { |
| 90 | Q_UNUSED(a) |
| 91 | QDialog::accept(); |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 95 | WizardDialog::closeEvent(QCloseEvent* event) |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 96 | { |
| 97 | Q_UNUSED(event) |
| 98 | |
| 99 | exit(0); |
Edric Milaret | 559bda5 | 2015-04-29 17:02:31 -0400 | [diff] [blame] | 100 | } |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 101 | |
| 102 | void |
| 103 | WizardDialog::on_avatarButton_clicked() |
| 104 | { |
| 105 | PhotoBoothDialog dlg; |
| 106 | dlg.exec(); |
| 107 | if (dlg.result() == QDialog::Accepted) { |
| 108 | auto image = QImage(dlg.fileName_); |
| 109 | auto avatar = image.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); |
| 110 | ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar); |
| 111 | ui->avatarButton->setIcon(QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarButton->width()))); |
| 112 | } |
| 113 | } |