blob: be953c97c3a7d81daae7092dc99a0ffa07053384 [file] [log] [blame]
Edric Milaret67007d12015-05-07 09:40:09 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret67007d12015-05-07 09:40:09 -04003 * 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 Milaret559bda52015-04-29 17:02:31 -040019#include "wizarddialog.h"
20#include "ui_wizarddialog.h"
21
Edric Milaret74e4b8b2015-05-15 10:25:00 -040022#include <QMovie>
23
Edric Milaret559bda52015-04-29 17:02:31 -040024#include "accountmodel.h"
Edric Milaret74e4b8b2015-05-15 10:25:00 -040025#include "account.h"
Edric Milaret25236d92016-03-28 09:40:58 -040026#include "profilemodel.h"
27#include "profile.h"
Edric Milaret559bda52015-04-29 17:02:31 -040028
29#include "utils.h"
Edric Milaret25236d92016-03-28 09:40:58 -040030#include "photoboothdialog.h"
Edric Milaret559bda52015-04-29 17:02:31 -040031
Edric Milaret25236d92016-03-28 09:40:58 -040032WizardDialog::WizardDialog(QWidget* parent) :
Edric Milaret559bda52015-04-29 17:02:31 -040033 QDialog(parent),
34 ui(new Ui::WizardDialog)
35{
36 ui->setupUi(this);
37
Edric Milaret4097d2f2016-02-09 14:41:50 -050038 Qt::WindowFlags flags = windowFlags();
39 flags = flags & (~Qt::WindowContextHelpButtonHint);
Edric Milaret74e4b8b2015-05-15 10:25:00 -040040
Edric Milaret4097d2f2016-02-09 14:41:50 -050041 setWindowFlags(flags);
Edric Milareted0b2802015-10-01 15:10:02 -040042
43 QPixmap logo(":/images/logo-ring-standard-coul.png");
Edric Milaret4097d2f2016-02-09 14:41:50 -050044 ui->ringLogo->setPixmap(logo.scaledToHeight(65, Qt::SmoothTransformation));
Edric Milareted0b2802015-10-01 15:10:02 -040045 ui->ringLogo->setAlignment(Qt::AlignHCenter);
Edric Milaret36587362016-02-04 12:30:52 -050046
47 ui->usernameEdit->setText(Utils::GetCurrentUserName());
Edric Milaret559bda52015-04-29 17:02:31 -040048}
49
50WizardDialog::~WizardDialog()
51{
52 delete ui;
53}
54
55void
Edric Milaret67007d12015-05-07 09:40:09 -040056WizardDialog::accept()
57{
Edric Milaret53ac6e52015-09-14 13:37:06 -040058 ui->label->setText(tr("Please wait while we create your account."));
Nicolas Jager1ddb38d2016-01-20 11:11:49 -050059 ui->wizardButton->setEnabled(false);
Edric Milaret67007d12015-05-07 09:40:09 -040060 ui->usernameEdit->setEnabled(false);
61
Edric Milaret25236d92016-03-28 09:40:58 -040062 auto profile = ProfileModel::instance().selectedProfile();
63
Edric Milaret74e4b8b2015-05-15 10:25:00 -040064 repaint();
Edric Milaret67007d12015-05-07 09:40:09 -040065
Edric Milaret74e4b8b2015-05-15 10:25:00 -040066 Utils::CreateStartupLink();
Edric Milaret67007d12015-05-07 09:40:09 -040067
Edric Milareta3e47282015-10-23 15:20:30 -040068 auto account = AccountModel::instance().add(ui->usernameEdit->text(), Account::Protocol::RING);
Edric Milaret25236d92016-03-28 09:40:58 -040069 if (not ui->usernameEdit->text().isEmpty()) {
Edric Milaret4097d2f2016-02-09 14:41:50 -050070 account->setDisplayName(ui->usernameEdit->text());
Edric Milaret25236d92016-03-28 09:40:58 -040071 profile->person()->setFormattedName(ui->usernameEdit->text());
72 }
73 else {
74 profile->person()->setFormattedName(tr("Unknown"));
75 }
Edric Milaret031c3052015-04-29 18:14:18 -040076 account->setRingtonePath(Utils::GetRingtonePath());
Edric Milaret74e4b8b2015-05-15 10:25:00 -040077 account->setUpnpEnabled(true);
78
79 connect(account, SIGNAL(changed(Account*)), this, SLOT(endSetup(Account*)));
80
81 account->performAction(Account::EditAction::SAVE);
Edric Milaret25236d92016-03-28 09:40:58 -040082
83 profile->setAccounts({account});
84 profile->save();
Edric Milaret74e4b8b2015-05-15 10:25:00 -040085}
86
87void
88WizardDialog::endSetup(Account* a)
89{
90 Q_UNUSED(a)
91 QDialog::accept();
Edric Milaret559bda52015-04-29 17:02:31 -040092}
93
94void
Edric Milaret25236d92016-03-28 09:40:58 -040095WizardDialog::closeEvent(QCloseEvent* event)
Edric Milareted0b2802015-10-01 15:10:02 -040096{
97 Q_UNUSED(event)
98
99 exit(0);
Edric Milaret559bda52015-04-29 17:02:31 -0400100}
Edric Milaret25236d92016-03-28 09:40:58 -0400101
102void
103WizardDialog::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}