blob: 75d74bf7d9bdc78ce26b35aa0e1f767daac2a7ad [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Edric Milaret4bba46d2015-04-29 16:33:38 -04002 * Copyright (C) 2015 by Savoir-Faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -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
19#include "configurationwidget.h"
20#include "ui_configurationwidget.h"
21
22#include "video/devicemodel.h"
23#include "video/channel.h"
24#include "video/resolution.h"
25#include "video/rate.h"
Edric Milaret4bba46d2015-04-29 16:33:38 -040026#include "video/previewmanager.h"
Edric Milaret627500d2015-03-27 16:41:40 -040027
28#include "accountmodel.h"
29#include "protocolmodel.h"
30#include "accountdetails.h"
Edric Milaret3aeae3a2015-06-01 17:31:54 -040031#include "callmodel.h"
Edric Milaret627500d2015-03-27 16:41:40 -040032
Edric Milaret4bba46d2015-04-29 16:33:38 -040033#include "utils.h"
Edric Milaret627500d2015-03-27 16:41:40 -040034
35ConfigurationWidget::ConfigurationWidget(QWidget *parent) :
36 NavWidget(Nav, parent),
37 ui(new Ui::ConfigurationWidget),
38 accountModel_(AccountModel::instance()),
39 deviceModel_(Video::DeviceModel::instance()),
40 accountDetails_(new AccountDetails())
41{
42 ui->setupUi(this);
43
44 ui->accountView->setModel(accountModel_);
45
Edric Milaret627500d2015-03-27 16:41:40 -040046 isLoading_ = true;
47 ui->deviceBox->setModel(deviceModel_);
Edric Milaret94b4aab2015-05-08 12:10:44 -040048 connect(deviceModel_, SIGNAL(currentIndexChanged(int)),
49 this, SLOT(deviceIndexChanged(int)));
Edric Milaret627500d2015-03-27 16:41:40 -040050
51 connect(ui->accountView->selectionModel(),
Edric Milaret3aeae3a2015-06-01 17:31:54 -040052 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
53 this, SLOT(accountSelected(QItemSelection)));
Edric Milaret627500d2015-03-27 16:41:40 -040054
55 ui->accountView->setCurrentIndex(accountModel_->index(0));
56 ui->accountDetailLayout->addWidget(accountDetails_);
Edric Milaret627500d2015-03-27 16:41:40 -040057 ui->accountTypeBox->setModel(accountModel_->protocolModel());
Edric Milaret4bba46d2015-04-29 16:33:38 -040058 ui->startupBox->setChecked(Utils::CheckStartupLink());
Edric Milaret627500d2015-03-27 16:41:40 -040059}
60
61void ConfigurationWidget::atExit() {
Edric Milaret3aeae3a2015-06-01 17:31:54 -040062 if (CallModel::instance()->getActiveCalls().size() == 0 ) {
63 ui->videoView->hide();
64 Video::PreviewManager::instance()->stopPreview();
65 }
Edric Milaret627500d2015-03-27 16:41:40 -040066 accountModel_->save();
67 accountDetails_->save();
68}
69
70ConfigurationWidget::~ConfigurationWidget()
71{
72 delete ui;
73}
74
75void
Edric Milaret94b4aab2015-05-08 12:10:44 -040076ConfigurationWidget::deviceIndexChanged(int index) {
77 ui->deviceBox->setCurrentIndex(index);
78}
79
80void
Edric Milaret627500d2015-03-27 16:41:40 -040081ConfigurationWidget::on_deviceBox_currentIndexChanged(int index)
82{
83 if (index < 0)
84 return;
85
86 if (!isLoading_)
87 deviceModel_->setActive(index);
88
89 auto device = deviceModel_->activeDevice();
90
91 ui->sizeBox->clear();
92
93 isLoading_ = true;
94 if (device->channelList().size() > 0) {
95 for (auto resolution : device->channelList()[0]->validResolutions()) {
96 ui->sizeBox->addItem(resolution->name());
97 }
98 }
99 ui->sizeBox->setCurrentIndex(
100 device->channelList()[0]->activeResolution()->relativeIndex());
101 isLoading_ = false;
102}
103
104void
105ConfigurationWidget::on_sizeBox_currentIndexChanged(int index)
106{
107 auto device = deviceModel_->activeDevice();
108
109 ui->rateBox->clear();
110
111 if (index < 0)
112 return;
113 if (!isLoading_)
114 device->channelList()[0]->setActiveResolution(
115 device->channelList()[0]->validResolutions()[index]);
116
117 isLoading_ = true;
118 for (auto rate
119 : device->channelList()[0]->validResolutions()[index]->validRates()) {
120 ui->rateBox->addItem(rate->name());
121 }
122 ui->rateBox->setCurrentIndex(
123 device->channelList()[0]->
Edric Milaret3aeae3a2015-06-01 17:31:54 -0400124 activeResolution()->activeRate()->relativeIndex());
Edric Milaret627500d2015-03-27 16:41:40 -0400125 isLoading_ = false;
126}
127
128void
129ConfigurationWidget::on_rateBox_currentIndexChanged(int index)
130{
131 if (index < 0 || isLoading_)
132 return;
133 auto device = deviceModel_->activeDevice();
134 device->channelList()[0]->activeResolution()->setActiveRate(index);
135}
136
137void
138ConfigurationWidget::accountSelected(QItemSelection itemSel) {
139 Q_UNUSED(itemSel)
140 accountDetails_->setAccount(accountModel_->getAccountByModelIndex(
141 ui->accountView->currentIndex()));
142}
143
144void
Edric Milaret627500d2015-03-27 16:41:40 -0400145ConfigurationWidget::on_deleteAccountButton_clicked()
146{
147 auto account = accountModel_->getAccountByModelIndex(
148 ui->accountView->currentIndex());
149 if (account != accountModel_->ip2ip())
150 accountModel_->remove(account);
151}
152
153void
154ConfigurationWidget::on_addAccountButton_clicked()
155{
Edric Milaret031c3052015-04-29 18:14:18 -0400156 auto account = accountModel_->add("New Account",
Edric Milaret3aeae3a2015-06-01 17:31:54 -0400157 ui->accountTypeBox->model()->index(
158 ui->accountTypeBox->currentIndex(), 0));
Edric Milaret031c3052015-04-29 18:14:18 -0400159 account->setRingtonePath(Utils::GetRingtonePath());
Edric Milaret627500d2015-03-27 16:41:40 -0400160 accountModel_->save();
161}
Edric Milaret4bba46d2015-04-29 16:33:38 -0400162
Edric Milaret3aeae3a2015-06-01 17:31:54 -0400163void
164ConfigurationWidget::on_startupBox_toggled(bool checked)
Edric Milaret4bba46d2015-04-29 16:33:38 -0400165{
166 if (checked)
167 Utils::CreateStartupLink();
168 else
169 Utils::DeleteStartupLink();
170}
Edric Milaret3aeae3a2015-06-01 17:31:54 -0400171
172void
173ConfigurationWidget::showEvent(QShowEvent* event)
174{
175 QWidget::showEvent(event);
176 if (CallModel::instance()->getActiveCalls().size() == 0 ) {
177 ui->videoView->show();
178 Video::PreviewManager::instance()->startPreview();
179 }
180}