blob: 112c9a8bcd7c8047cb7ee29a5b1ba49579644084 [file] [log] [blame]
Edric Milaret67007d12015-05-07 09:40:09 -04001/***************************************************************************
2 * Copyright (C) 2015 by Savoir-Faire Linux *
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 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 Milaret559bda52015-04-29 17:02:31 -040026
27#include "utils.h"
28
29WizardDialog::WizardDialog(QWidget *parent) :
30 QDialog(parent),
31 ui(new Ui::WizardDialog)
32{
33 ui->setupUi(this);
34
35 this->setWindowFlags(Qt::CustomizeWindowHint);
36 this->setWindowFlags(Qt::FramelessWindowHint);
37 this->setFixedSize(this->width(),this->height());
38 ui->buttonBox->setEnabled(false);
Edric Milaret74e4b8b2015-05-15 10:25:00 -040039
40 ui->spinnerLabel->hide();
41 QMovie* movie = new QMovie(":images/spinner.gif");
42 if (movie->isValid())
43 {
44 ui->spinnerLabel->setMovie(movie);
45 movie->start();
46 }
Edric Milaret559bda52015-04-29 17:02:31 -040047}
48
49WizardDialog::~WizardDialog()
50{
Edric Milaret01f23842015-06-22 14:46:01 -040051 if (ui->spinnerLabel->movie()) {
52 delete ui->spinnerLabel->movie();
53 }
Edric Milaret559bda52015-04-29 17:02:31 -040054 delete ui;
55}
56
57void
Edric Milaret67007d12015-05-07 09:40:09 -040058WizardDialog::accept()
59{
Edric Milaret74e4b8b2015-05-15 10:25:00 -040060 //ui->spinnerLabel->show();
61 ui->label->setText("Please wait while we create your account.");
Edric Milaret67007d12015-05-07 09:40:09 -040062 ui->buttonBox->setEnabled(false);
63 ui->usernameEdit->setEnabled(false);
64
Edric Milaret74e4b8b2015-05-15 10:25:00 -040065 repaint();
Edric Milaret67007d12015-05-07 09:40:09 -040066
Edric Milaret74e4b8b2015-05-15 10:25:00 -040067 Utils::CreateStartupLink();
Edric Milaret67007d12015-05-07 09:40:09 -040068
Edric Milaret031c3052015-04-29 18:14:18 -040069 auto account = AccountModel::instance()->add(ui->usernameEdit->text(), Account::Protocol::RING);
Edric Milaret67007d12015-05-07 09:40:09 -040070 AccountModel::instance()->ip2ip()->setRingtonePath(Utils::GetRingtonePath());
Edric Milaret031c3052015-04-29 18:14:18 -040071 account->setRingtonePath(Utils::GetRingtonePath());
Edric Milaret74e4b8b2015-05-15 10:25:00 -040072 account->setUpnpEnabled(true);
73
74 connect(account, SIGNAL(changed(Account*)), this, SLOT(endSetup(Account*)));
75
76 account->performAction(Account::EditAction::SAVE);
77}
78
79void
80WizardDialog::endSetup(Account* a)
81{
82 Q_UNUSED(a)
83 QDialog::accept();
Edric Milaret559bda52015-04-29 17:02:31 -040084}
85
86void
87WizardDialog::on_usernameEdit_textChanged(const QString &arg1)
88{
Edric Milaret74e4b8b2015-05-15 10:25:00 -040089 ui->buttonBox->setEnabled(!arg1.isEmpty());
Edric Milaret559bda52015-04-29 17:02:31 -040090}