Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 by Savoir-Faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -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 | |
| 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 Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 26 | #include "video/previewmanager.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 27 | |
| 28 | #include "accountmodel.h" |
| 29 | #include "protocolmodel.h" |
| 30 | #include "accountdetails.h" |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 31 | #include "callmodel.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 32 | |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 33 | #include "utils.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 34 | |
| 35 | ConfigurationWidget::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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 46 | isLoading_ = true; |
| 47 | ui->deviceBox->setModel(deviceModel_); |
Edric Milaret | 94b4aab | 2015-05-08 12:10:44 -0400 | [diff] [blame] | 48 | connect(deviceModel_, SIGNAL(currentIndexChanged(int)), |
| 49 | this, SLOT(deviceIndexChanged(int))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 50 | |
| 51 | connect(ui->accountView->selectionModel(), |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 52 | SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
| 53 | this, SLOT(accountSelected(QItemSelection))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 54 | |
| 55 | ui->accountView->setCurrentIndex(accountModel_->index(0)); |
| 56 | ui->accountDetailLayout->addWidget(accountDetails_); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 57 | ui->accountTypeBox->setModel(accountModel_->protocolModel()); |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 58 | ui->startupBox->setChecked(Utils::CheckStartupLink()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void ConfigurationWidget::atExit() { |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 62 | if (CallModel::instance()->getActiveCalls().size() == 0 ) { |
| 63 | ui->videoView->hide(); |
| 64 | Video::PreviewManager::instance()->stopPreview(); |
| 65 | } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 66 | accountModel_->save(); |
| 67 | accountDetails_->save(); |
| 68 | } |
| 69 | |
| 70 | ConfigurationWidget::~ConfigurationWidget() |
| 71 | { |
| 72 | delete ui; |
| 73 | } |
| 74 | |
| 75 | void |
Edric Milaret | 94b4aab | 2015-05-08 12:10:44 -0400 | [diff] [blame] | 76 | ConfigurationWidget::deviceIndexChanged(int index) { |
| 77 | ui->deviceBox->setCurrentIndex(index); |
| 78 | } |
| 79 | |
| 80 | void |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 81 | ConfigurationWidget::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 | |
| 104 | void |
| 105 | ConfigurationWidget::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 Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 124 | activeResolution()->activeRate()->relativeIndex()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 125 | isLoading_ = false; |
| 126 | } |
| 127 | |
| 128 | void |
| 129 | ConfigurationWidget::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 | |
| 137 | void |
| 138 | ConfigurationWidget::accountSelected(QItemSelection itemSel) { |
| 139 | Q_UNUSED(itemSel) |
| 140 | accountDetails_->setAccount(accountModel_->getAccountByModelIndex( |
| 141 | ui->accountView->currentIndex())); |
| 142 | } |
| 143 | |
| 144 | void |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 145 | ConfigurationWidget::on_deleteAccountButton_clicked() |
| 146 | { |
| 147 | auto account = accountModel_->getAccountByModelIndex( |
| 148 | ui->accountView->currentIndex()); |
| 149 | if (account != accountModel_->ip2ip()) |
| 150 | accountModel_->remove(account); |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | ConfigurationWidget::on_addAccountButton_clicked() |
| 155 | { |
Edric Milaret | 031c305 | 2015-04-29 18:14:18 -0400 | [diff] [blame] | 156 | auto account = accountModel_->add("New Account", |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 157 | ui->accountTypeBox->model()->index( |
| 158 | ui->accountTypeBox->currentIndex(), 0)); |
Edric Milaret | 031c305 | 2015-04-29 18:14:18 -0400 | [diff] [blame] | 159 | account->setRingtonePath(Utils::GetRingtonePath()); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 160 | accountModel_->save(); |
| 161 | } |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 162 | |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 163 | void |
| 164 | ConfigurationWidget::on_startupBox_toggled(bool checked) |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 165 | { |
| 166 | if (checked) |
| 167 | Utils::CreateStartupLink(); |
| 168 | else |
| 169 | Utils::DeleteStartupLink(); |
| 170 | } |
Edric Milaret | 3aeae3a | 2015-06-01 17:31:54 -0400 | [diff] [blame] | 171 | |
| 172 | void |
| 173 | ConfigurationWidget::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 | } |