blob: 784e8ea449e10dee9ba19a3ad8144d977c640477 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
2 * Copyright (C) 2011-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
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"
26
27#include "accountmodel.h"
28#include "protocolmodel.h"
29#include "accountdetails.h"
30
31#include <video/previewmanager.h>
32
33ConfigurationWidget::ConfigurationWidget(QWidget *parent) :
34 NavWidget(Nav, parent),
35 ui(new Ui::ConfigurationWidget),
36 accountModel_(AccountModel::instance()),
37 deviceModel_(Video::DeviceModel::instance()),
38 accountDetails_(new AccountDetails())
39{
40 ui->setupUi(this);
41
42 ui->accountView->setModel(accountModel_);
43
44 //FIXME : Seems to set the active device instead of taking the default one
45 isLoading_ = true;
46 ui->deviceBox->setModel(deviceModel_);
47 ui->deviceBox->setCurrentIndex(deviceModel_->activeIndex());
48
49 connect(ui->accountView->selectionModel(),
50 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
51 this, SLOT(accountSelected(QItemSelection)));
52
53 ui->accountView->setCurrentIndex(accountModel_->index(0));
54 ui->accountDetailLayout->addWidget(accountDetails_);
55 ui->testVideoButton->setCheckable(true);
56 ui->accountTypeBox->setModel(accountModel_->protocolModel());
57}
58
59void ConfigurationWidget::atExit() {
60 accountModel_->save();
61 accountDetails_->save();
62}
63
64ConfigurationWidget::~ConfigurationWidget()
65{
66 delete ui;
67}
68
69void
70ConfigurationWidget::on_deviceBox_currentIndexChanged(int index)
71{
72 if (index < 0)
73 return;
74
75 if (!isLoading_)
76 deviceModel_->setActive(index);
77
78 auto device = deviceModel_->activeDevice();
79
80 ui->sizeBox->clear();
81
82 isLoading_ = true;
83 if (device->channelList().size() > 0) {
84 for (auto resolution : device->channelList()[0]->validResolutions()) {
85 ui->sizeBox->addItem(resolution->name());
86 }
87 }
88 ui->sizeBox->setCurrentIndex(
89 device->channelList()[0]->activeResolution()->relativeIndex());
90 isLoading_ = false;
91}
92
93void
94ConfigurationWidget::on_sizeBox_currentIndexChanged(int index)
95{
96 auto device = deviceModel_->activeDevice();
97
98 ui->rateBox->clear();
99
100 if (index < 0)
101 return;
102 if (!isLoading_)
103 device->channelList()[0]->setActiveResolution(
104 device->channelList()[0]->validResolutions()[index]);
105
106 isLoading_ = true;
107 for (auto rate
108 : device->channelList()[0]->validResolutions()[index]->validRates()) {
109 ui->rateBox->addItem(rate->name());
110 }
111 ui->rateBox->setCurrentIndex(
112 device->channelList()[0]->
113 activeResolution()->activeRate()->relativeIndex());
114 isLoading_ = false;
115}
116
117void
118ConfigurationWidget::on_rateBox_currentIndexChanged(int index)
119{
120 if (index < 0 || isLoading_)
121 return;
122 auto device = deviceModel_->activeDevice();
123 device->channelList()[0]->activeResolution()->setActiveRate(index);
124}
125
126void
127ConfigurationWidget::accountSelected(QItemSelection itemSel) {
128 Q_UNUSED(itemSel)
129 accountDetails_->setAccount(accountModel_->getAccountByModelIndex(
130 ui->accountView->currentIndex()));
131}
132
133void
134ConfigurationWidget::on_testVideoButton_toggled(bool checked)
135{
Edric Milaret72c406d2015-04-28 13:23:54 -0400136 checked ? ui->videoView->show() : ui->videoView->hide();
Edric Milaret627500d2015-03-27 16:41:40 -0400137 checked ? Video::PreviewManager::instance()->startPreview()
138 : Video::PreviewManager::instance()->stopPreview();
139}
140
141void
142ConfigurationWidget::on_deleteAccountButton_clicked()
143{
144 auto account = accountModel_->getAccountByModelIndex(
145 ui->accountView->currentIndex());
146 if (account != accountModel_->ip2ip())
147 accountModel_->remove(account);
148}
149
150void
151ConfigurationWidget::on_addAccountButton_clicked()
152{
153 accountModel_->add("New Account",
154 ui->accountTypeBox->model()->index(
155 ui->accountTypeBox->currentIndex(), 0));
156 accountModel_->save();
157}