Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 1 | /*************************************************************************** |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2019-2019 by Savoir-faire Linux * |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 3 | * Author: Isa Nanic <isa.nanic@savoirfairelinux.com> * |
| 4 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 5 | * Author: Anthony L�onard <anthony.leonard@savoirfairelinux.com> * |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 6 | * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> * |
| 7 | * * |
| 8 | * This program is free software; you can redistribute it and/or modify * |
| 9 | * it under the terms of the GNU General Public License as published by * |
| 10 | * the Free Software Foundation; either version 3 of the License, or * |
| 11 | * (at your option) any later version. * |
| 12 | * * |
| 13 | * This program is distributed in the hope that it will be useful, * |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 | * GNU General Public License for more details. * |
| 17 | * * |
| 18 | * You should have received a copy of the GNU General Public License * |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. * |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 20 | **************************************************************************/ |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 21 | |
| 22 | #include "settingswidget.h" |
| 23 | #include "ui_settingswidget.h" |
| 24 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 25 | #include <QPixmap> |
| 26 | #include <QTimer> |
| 27 | #include <QModelIndex> |
| 28 | #include <QFileDialog> |
| 29 | #include <QInputDialog> |
| 30 | #include <QStandardPaths> |
| 31 | #include <QMessageBox> |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 32 | #include <QSettings> |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 33 | |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 34 | #include "utils.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 35 | #include "settingsitemwidget.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 36 | #include "passworddialog.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 37 | #include "regnamedialog.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 38 | #include "setavatardialog.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 39 | #include "deleteaccountdialog.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 40 | |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 41 | #include "api/newdevicemodel.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 42 | #include "media/recordingmodel.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 43 | #include "audio/settings.h" |
| 44 | #include "audio/outputdevicemodel.h" |
| 45 | #include "audio/inputdevicemodel.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 46 | #include "video/devicemodel.h" |
| 47 | #include "video/channel.h" |
| 48 | #include "video/resolution.h" |
| 49 | #include "video/rate.h" |
| 50 | #include "video/previewmanager.h" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 51 | #include "callmodel.h" |
| 52 | |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 53 | #ifdef Q_OS_WIN |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 54 | #include "winsparkle.h" |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 55 | #endif |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 56 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 57 | SettingsWidget::SettingsWidget(QWidget* parent) |
| 58 | : NavWidget(parent), |
| 59 | ui(new Ui::SettingsWidget), |
Andreas Traczyk | b81281e | 2018-12-13 13:13:28 -0500 | [diff] [blame] | 60 | scrollArea_(new QScrollArea(this)), |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 61 | deviceModel_(&Video::DeviceModel::instance()), |
| 62 | gif(new QMovie(":/images/ajax-loader.gif")) |
| 63 | { |
| 64 | ui->setupUi(this); |
| 65 | |
| 66 | ui->accountSettingsButton->setAutoFillBackground(true); |
| 67 | ui->generalSettingsButton->setAutoFillBackground(true); |
| 68 | ui->avSettingsButton->setAutoFillBackground(true); |
| 69 | |
| 70 | ui->accountSettingsButton->setChecked(true); |
| 71 | |
| 72 | ui->exitSettingsButton->setIconSize(QSize(24, 24)); |
| 73 | ui->exitSettingsButton->setIcon(QPixmap(":/images/icons/round-close-24px.svg")); |
| 74 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 75 | // display name (aka alias) |
| 76 | ui->displayNameLineEdit->setAlignment(Qt::AlignHCenter); |
| 77 | ui->displayNameLineEdit->setPlaceholderText(tr("Enter the displayed name")); |
| 78 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 79 | setSelected(Button::accountSettingsButton); |
| 80 | |
| 81 | ui->currentRegisteredID->setReadOnly(true); |
| 82 | ui->currentRegisteredID->setStyleSheet("border : 0px;"); |
| 83 | |
| 84 | ui->currentRingID->setReadOnly(true); |
| 85 | |
| 86 | avatarSize_ = ui->currentAccountAvatar->width(); |
| 87 | |
| 88 | ui->currentAccountAvatar->setIconSize(QSize(avatarSize_, avatarSize_)); |
| 89 | |
| 90 | // create ellipse-selectable avatar image |
| 91 | QRegion avatarClickableRegion(-1, -1, |
| 92 | ui->currentAccountAvatar->width() + 2, ui->currentAccountAvatar->height() + 2, QRegion::Ellipse); |
| 93 | ui->currentAccountAvatar->setMask(avatarClickableRegion); |
| 94 | |
| 95 | QString styleS( |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 96 | "QPushButton {" |
| 97 | " background-color: white;" |
| 98 | " border-right: 1px solid #f0f0f0;" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 99 | "}" |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 100 | " QPushButton:hover {" |
| 101 | " background-color: rgb(245, 245, 245);" |
| 102 | " border-right: 1px solid #f0f0f0;" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 103 | " }" |
| 104 | |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 105 | "QPushButton:checked {" |
| 106 | " background-color: rgb(237, 237, 237);" |
| 107 | " border-right: 1px solid #f0f0f0;" |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 108 | "}" |
| 109 | ); |
| 110 | |
| 111 | ui->accountSettingsButton->setStyleSheet(styleS); |
| 112 | ui->generalSettingsButton->setStyleSheet(styleS); |
| 113 | ui->avSettingsButton->setStyleSheet(styleS); |
| 114 | |
| 115 | ui->advancedAccountSettingsPButton->setIcon(QPixmap(":/images/icons/round-arrow_drop_down-24px.svg")); |
| 116 | ui->linkDevPushButton->setIcon(QPixmap(":/images/icons/round-add-24px.svg")); |
| 117 | ui->blockedContactsBtn->setIcon(QPixmap(":/images/icons/round-arrow_drop_up-24px.svg")); |
| 118 | |
| 119 | ui->advancedSettingsOffsetLabel->show(); |
| 120 | |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 121 | auto accountList = LRCInstance::accountModel().getAccountList(); |
| 122 | if (!accountList.size()) { |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 123 | Utils::oneShotConnect(&LRCInstance::accountModel(), |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 124 | &lrc::api::NewAccountModel::accountAdded, |
Andreas Traczyk | f946549 | 2019-01-09 13:53:37 -0500 | [diff] [blame] | 125 | [this](const std::string& accountId) { |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 126 | Q_UNUSED(accountId); |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 127 | setConnections(); |
Andreas Traczyk | fc33a49 | 2018-12-14 13:53:13 -0500 | [diff] [blame] | 128 | }); |
| 129 | } else { |
| 130 | setConnections(); |
| 131 | } |
| 132 | |
| 133 | ui->containerWidget->setVisible(false); |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | SettingsWidget::navigated(bool to) |
| 138 | { |
| 139 | ui->containerWidget->setVisible(to); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Andreas Traczyk | 6ace34f | 2018-12-14 14:31:23 -0500 | [diff] [blame] | 142 | void SettingsWidget::updateCustomUI() |
| 143 | { |
| 144 | } |
| 145 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 146 | void |
| 147 | SettingsWidget::leaveSettingsSlot() |
| 148 | { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 149 | if (advancedSettingsDropped_) { |
| 150 | toggleAdvancedSettings(); |
| 151 | } |
| 152 | |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 153 | Video::PreviewManager::instance().stopPreview(); |
| 154 | saveSizeIndex(); |
| 155 | |
| 156 | emit NavigationRequested(ScreenEnum::CallScreen); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | SettingsWidget::~SettingsWidget() |
| 160 | { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 161 | delete ui; |
| 162 | } |
| 163 | |
| 164 | // called at every callwidget -> settingsWidget navigation |
| 165 | void |
| 166 | SettingsWidget::updateSettings(int size) |
| 167 | { |
| 168 | setSelected(Button::accountSettingsButton); |
| 169 | resize(size); |
| 170 | updateAccountInfoDisplayed(); |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | SettingsWidget::resize(int size) |
| 175 | { |
| 176 | ui->rightSettingsWidget->setGeometry(size, 0, this->width() - size, this->height()); |
| 177 | ui->accountSettingsButton->setFixedWidth(size); |
| 178 | } |
| 179 | |
| 180 | void |
| 181 | SettingsWidget::setSelected(Button sel) |
| 182 | { |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 183 | saveSizeIndex(); |
| 184 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 185 | switch (sel) |
| 186 | { |
| 187 | case Button::accountSettingsButton: |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 188 | Video::PreviewManager::instance().stopPreview(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 189 | |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 190 | if (advancedSettingsDropped_) { toggleAdvancedSettings(); } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 191 | ui->stackedWidget->setCurrentWidget(ui->currentAccountSettingsScrollWidget); |
| 192 | if (pastButton_ == Button::generalSettingsButton) { |
| 193 | ui->accountSettingsButton->setChecked(true); |
| 194 | ui->generalSettingsButton->setChecked(false); |
| 195 | break; |
| 196 | } |
| 197 | else { |
| 198 | ui->accountSettingsButton->setChecked(true); |
| 199 | ui->avSettingsButton->setChecked(false); |
| 200 | break; |
| 201 | } |
| 202 | case Button::generalSettingsButton: |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 203 | Video::PreviewManager::instance().stopPreview(); |
| 204 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 205 | ui->stackedWidget->setCurrentWidget(ui->generalSettings); |
| 206 | populateGeneralSettings(); |
| 207 | if (pastButton_ == Button::avSettingsButton) { |
| 208 | ui->generalSettingsButton->setChecked(true); |
| 209 | ui->avSettingsButton->setChecked(false); |
| 210 | break; |
| 211 | } |
| 212 | else { |
| 213 | ui->generalSettingsButton->setChecked(true); |
| 214 | ui->accountSettingsButton->setChecked(false); |
| 215 | break; |
| 216 | } |
| 217 | case Button::avSettingsButton: |
| 218 | ui->stackedWidget->setCurrentWidget(ui->avSettings); |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 219 | populateAVSettings(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 220 | if (pastButton_ == Button::accountSettingsButton) { |
| 221 | ui->avSettingsButton->setChecked(true); |
| 222 | ui->accountSettingsButton->setChecked(false); |
| 223 | break; |
| 224 | } |
| 225 | else { |
| 226 | ui->avSettingsButton->setChecked(true); |
| 227 | ui->generalSettingsButton->setChecked(false); |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | pastButton_ = sel; |
| 232 | } |
| 233 | |
| 234 | // called to update current settings information when navigating to settingsWidget |
| 235 | void |
| 236 | SettingsWidget::updateAccountInfoDisplayed() |
| 237 | { |
| 238 | ui->currentRegisteredID->setText(QString::fromStdString(LRCInstance::getCurrentAccountInfo().registeredName)); |
| 239 | ui->currentRingID->setText(QString::fromStdString(LRCInstance::getCurrentAccountInfo().profileInfo.uri)); |
| 240 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 241 | // if no registered name is found for account |
| 242 | if (LRCInstance::getCurrentAccountInfo().registeredName.empty()) { |
| 243 | ui->currentRegisteredID->setReadOnly(false); |
| 244 | } |
| 245 | else { |
| 246 | ui->currentRegisteredID->setReadOnly(true); |
| 247 | setRegNameUi(RegName::BLANK); |
| 248 | } |
| 249 | |
| 250 | ui->currentAccountAvatar->setIcon(LRCInstance::getCurrAccPixmap(). |
| 251 | scaledToHeight(avatarSize_, Qt::SmoothTransformation)); |
| 252 | |
| 253 | ui->accountEnableCheckBox->setChecked(LRCInstance::getCurrentAccountInfo().enabled); |
| 254 | |
| 255 | ui->displayNameLineEdit->setText(QString::fromStdString(LRCInstance::getCurrentAccountInfo().profileInfo.alias)); |
| 256 | |
| 257 | updateAndShowDevicesSlot(); |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 258 | bannedContactsShown_ = false; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 259 | if (!LRCInstance::getCurrentAccountInfo().contactModel->getBannedContacts().size()){ |
| 260 | ui->blockedContactsBtn->hide(); |
| 261 | } else { |
| 262 | ui->blockedContactsBtn->show(); |
| 263 | } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void |
| 267 | SettingsWidget::passwordClicked() |
| 268 | { |
| 269 | PasswordDialog passwdDialog(this); |
| 270 | passwdDialog.exec(); |
| 271 | } |
| 272 | |
| 273 | void |
| 274 | SettingsWidget::toggleAdvancedSettings() |
| 275 | { |
| 276 | if (advancedSettingsDropped_) { |
| 277 | ui->advancedAccountSettingsPButton->setIcon(QPixmap(":/images/icons/round-arrow_drop_down-24px.svg")); |
| 278 | ui->currentAccountSettingsScrollLayout->removeWidget(advancedSettingsWidget_); |
| 279 | ui->scrollBarLabel->show(); |
| 280 | ui->advancedSettingsOffsetLabel->hide(); |
| 281 | delete advancedSettingsWidget_; |
| 282 | } |
| 283 | else { // will show advanced settings next |
| 284 | ui->advancedAccountSettingsPButton->setIcon(QPixmap(":/images/icons/round-arrow_drop_up-24px.svg")); |
Andreas Traczyk | b81281e | 2018-12-13 13:13:28 -0500 | [diff] [blame] | 285 | advancedSettingsWidget_ = new AdvancedSettingsWidget(this); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 286 | advancedSettingsWidget_->setMaximumWidth(ui->scrollAreaWidgetContents->width() - 10); |
| 287 | ui->currentAccountSettingsScrollLayout->addWidget(advancedSettingsWidget_); |
| 288 | ui->advancedSettingsOffsetLabel->show(); |
| 289 | ui->scrollBarLabel->hide(); |
| 290 | } |
| 291 | advancedSettingsDropped_ = !advancedSettingsDropped_; |
| 292 | } |
| 293 | |
| 294 | void |
| 295 | SettingsWidget::toggleBannedContacts() |
| 296 | { |
| 297 | if (bannedContactsShown_) { // will show linked devices next |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 298 | bannedContactsShown_ = false; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 299 | updateAndShowDevicesSlot(); |
| 300 | } |
| 301 | else { // will show banned contacts next |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 302 | bannedContactsShown_ = true; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 303 | updateAndShowBannedContactsSlot(); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | SettingsWidget::resizeEvent(QResizeEvent* event) |
| 309 | { |
| 310 | QWidget::resizeEvent(event); |
| 311 | scrollArea_->resize(ui->currentAccountSettingsScrollWidget->width(), this->height()); |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | SettingsWidget::avatarClicked() |
| 316 | { |
| 317 | SetAvatarDialog avatarDialog(this); |
| 318 | |
| 319 | // return new avatar pixmap from setAvatarDialog |
Andreas Traczyk | 2771e2e | 2019-01-08 17:44:33 -0500 | [diff] [blame] | 320 | connect(&avatarDialog, &SetAvatarDialog::pixmapSignal, |
| 321 | [this](const std::string& pixString) { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 322 | if (!pixString.empty()) { |
| 323 | LRCInstance::setCurrAccAvatar(pixString); |
| 324 | updateAccountInfoDisplayed(); |
| 325 | } |
| 326 | } |
| 327 | ); |
| 328 | avatarDialog.exec(); |
| 329 | } |
| 330 | |
| 331 | void |
| 332 | SettingsWidget::verifyRegisteredNameSlot() |
| 333 | { |
| 334 | if (!LRCInstance::getCurrentAccountInfo().registeredName.empty()) { |
| 335 | setRegNameUi(RegName::BLANK); |
| 336 | } |
| 337 | else { |
| 338 | registeredName_ = ui->currentRegisteredID->text().simplified(); |
| 339 | |
| 340 | if (!registeredName_.isEmpty()) { |
| 341 | if (validateRegNameForm(registeredName_)) { // name has valid form |
| 342 | setRegNameUi(RegName::SEARCHING); |
| 343 | QTimer::singleShot(300, this, SLOT(beforeNameLookup())); |
| 344 | } else { // name does not have valid form |
| 345 | setRegNameUi(RegName::INVALIDFORM); |
| 346 | } |
| 347 | } else { |
| 348 | setRegNameUi(RegName::BLANK); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // returns true if name is valid registered name |
| 354 | bool |
| 355 | SettingsWidget::validateRegNameForm(const QString& regName) |
| 356 | { |
| 357 | QRegularExpression regExp(" "); |
| 358 | if (regName.size() > 2 && !regName.contains(regExp)) { |
| 359 | return true; |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 360 | } else { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | void |
| 366 | SettingsWidget::receiveRegNameSlot(const std::string& accountID, |
| 367 | lrc::api::account::LookupStatus status, const std::string& address, const std::string& name) |
| 368 | { |
| 369 | Q_UNUSED(accountID); Q_UNUSED(address); |
| 370 | afterNameLookup(status, name); |
| 371 | } |
| 372 | |
| 373 | void |
| 374 | SettingsWidget::beforeNameLookup() |
| 375 | { |
| 376 | NameDirectory::instance().lookupName(nullptr, QString(), registeredName_); |
| 377 | } |
| 378 | |
| 379 | void |
| 380 | SettingsWidget::afterNameLookup(lrc::api::account::LookupStatus status, const std::string& regName) |
| 381 | { |
| 382 | if (registeredName_.toStdString() == regName && regName.length() > 2) { |
| 383 | if (status == lrc::api::account::LookupStatus::NOT_FOUND) { |
| 384 | setRegNameUi(RegName::FREE); |
| 385 | } |
| 386 | else { |
| 387 | setRegNameUi(RegName::TAKEN); |
| 388 | } |
| 389 | } |
| 390 | else { |
| 391 | setRegNameUi(RegName::BLANK); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | void SettingsWidget::setRegNameUi(RegName stat) |
| 396 | { |
| 397 | disconnect(gif, SIGNAL(frameChanged(int)), this, SLOT(setButtonIconSlot(int))); |
| 398 | disconnect(ui->regNameButton, &QPushButton::clicked, this, &SettingsWidget::regNameRegisteredSlot); |
| 399 | |
| 400 | switch (stat) { |
| 401 | case RegName::BLANK: |
| 402 | ui->currentRegisteredID->setStyleSheet("padding-left: 5px; border: 0px; border-radius: 3px; border: 1px solid rgb(245, 245, 245);"); |
| 403 | regNameBtn_ = false; |
| 404 | ui->currentRegisteredID->setToolTip(tr("")); |
| 405 | ui->regNameButton->setIcon(QPixmap()); |
| 406 | ui->regNameButton->setEnabled(false); |
| 407 | break; |
| 408 | |
| 409 | case RegName::INVALIDFORM: |
| 410 | ui->currentRegisteredID->setStyleSheet("padding-left: 5px; border: 1px solid red; border-radius: 3px;"); |
| 411 | regNameBtn_ = false; |
| 412 | ui->currentRegisteredID->setToolTip(tr("A registered name should not have any spaces and must be at least three letters long")); |
| 413 | ui->regNameButton->setIcon(QPixmap(":/images/icons/round-error-24px.svg")); |
| 414 | ui->regNameButton->setToolTip(tr("A registered name should not have any spaces and must be at least three letters long")); |
| 415 | ui->regNameButton->setEnabled(true); |
| 416 | break; |
| 417 | |
| 418 | case RegName::TAKEN: |
| 419 | ui->currentRegisteredID->setStyleSheet("padding-left: 5px; border: 1px solid orange; border-radius: 3px;"); |
| 420 | regNameBtn_ = false; |
| 421 | ui->currentRegisteredID->setToolTip(tr("This name is already taken")); |
| 422 | ui->regNameButton->setIcon(QPixmap(":/images/icons/round-error-24px.svg")); |
| 423 | ui->regNameButton->setToolTip(tr("This registered name is already taken")); |
| 424 | ui->regNameButton->setEnabled(true); |
| 425 | break; |
| 426 | |
| 427 | case RegName::FREE: |
| 428 | ui->currentRegisteredID->setStyleSheet("padding-left: 5px; border: 1px solid green; border-radius: 3px;"); |
| 429 | regNameBtn_ = true; |
| 430 | ui->currentRegisteredID->setToolTip(tr("This name is available")); |
| 431 | ui->regNameButton->setIcon(QPixmap(":/images/icons/round-check_circle-24px.svg")); |
| 432 | ui->regNameButton->setToolTip(tr("Register this name")); |
| 433 | ui->regNameButton->setEnabled(true); |
| 434 | |
| 435 | connect(ui->regNameButton, &QPushButton::clicked, this, &SettingsWidget::regNameRegisteredSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 436 | break; |
| 437 | |
| 438 | case RegName::SEARCHING: |
| 439 | ui->currentRegisteredID->setStyleSheet("padding-left: 5px; border: 1px solid rgb(2, 187, 213); border-radius: 3px;"); |
| 440 | regNameBtn_ = false; |
| 441 | ui->currentRegisteredID->setToolTip(tr("")); |
| 442 | |
| 443 | connect(gif, SIGNAL(frameChanged(int)), this, SLOT(setButtonIconSlot(int))); |
| 444 | gif->start(); |
| 445 | ui->regNameButton->setEnabled(false); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | } |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 449 | |
| 450 | void |
| 451 | SettingsWidget::setButtonIconSlot(int frame) |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 452 | { |
| 453 | Q_UNUSED(frame); |
| 454 | ui->regNameButton->setIcon(QIcon(gif->currentPixmap())); |
| 455 | } |
| 456 | |
| 457 | void |
| 458 | SettingsWidget::regNameRegisteredSlot() |
| 459 | { |
| 460 | if (!regNameBtn_) { return; } |
| 461 | |
| 462 | RegNameDialog regNameDialog(registeredName_, this); |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 463 | if (regNameDialog.exec() == QDialog::Accepted) { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 464 | ui->currentRegisteredID->setReadOnly(true); |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 465 | ui->currentRegisteredID->setText(registeredName_); |
| 466 | |
| 467 | lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 468 | LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties); |
| 469 | } else { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 470 | ui->currentRegisteredID->setText(""); |
| 471 | registeredName_ = ""; |
| 472 | } |
| 473 | setRegNameUi(RegName::BLANK); |
| 474 | } |
| 475 | |
| 476 | void |
| 477 | SettingsWidget::setAccEnableSlot(int state) |
| 478 | { |
| 479 | LRCInstance::editableAccountModel()->enableAccount(LRCInstance::getCurrAccId(), (bool)state); |
| 480 | |
| 481 | auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId()); |
| 482 | LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps); |
| 483 | } |
| 484 | |
| 485 | void |
| 486 | SettingsWidget::delAccountSlot() |
| 487 | { |
| 488 | DeleteAccountDialog delDialog(this); |
Andreas Traczyk | 39fa4d0 | 2019-01-03 17:32:07 -0500 | [diff] [blame] | 489 | auto ret = delDialog.exec(); |
| 490 | if (ret == QDialog::Accepted) { |
| 491 | LRCInstance::setSelectedAccountId(""); |
| 492 | if (!LRCInstance::accountModel().getAccountList().size()) { |
| 493 | emit NavigationRequested(ScreenEnum::WizardScreen); |
| 494 | } else { |
| 495 | LRCInstance::setSelectedConvId(""); |
| 496 | emit NavigationRequested(ScreenEnum::CallScreen); |
| 497 | } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | void |
| 502 | SettingsWidget::removeDeviceSlot(int index) |
| 503 | { |
| 504 | if (!index) { return; } |
| 505 | |
| 506 | auto deviceList = LRCInstance::getCurrentAccountInfo().deviceModel->getAllDevices(); |
| 507 | auto it = deviceList.begin(); |
| 508 | |
| 509 | std::advance(it, index); |
| 510 | QString psswd; |
| 511 | |
| 512 | bool ok = false; |
| 513 | if (LRCInstance::getCurrAccConfig().archiveHasPassword) { |
| 514 | psswd = QInputDialog::getText(this, tr("Remove Device"), |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 515 | tr("Enter this account's password to confirm the removal of this device"), QLineEdit::Password, |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 516 | QDir::home().dirName(), &ok); |
| 517 | } |
| 518 | else { |
| 519 | psswd = ""; |
| 520 | QMessageBox devDel; |
| 521 | devDel.setText(tr("Please confirm that you wish to remove this device")); |
| 522 | devDel.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
| 523 | devDel.setDefaultButton(QMessageBox::Cancel); |
| 524 | if (devDel.exec() == QMessageBox::Ok) { goto delete_; } |
| 525 | } |
| 526 | |
| 527 | if (ok) { |
| 528 | delete_: |
| 529 | LRCInstance::getCurrentAccountInfo().deviceModel->revokeDevice(it->id, psswd.toStdString()); |
| 530 | updateAndShowDevicesSlot(); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | void |
| 535 | SettingsWidget::unban(int index) |
| 536 | { |
| 537 | auto bannedContactList = LRCInstance::getCurrentAccountInfo().contactModel->getBannedContacts(); |
| 538 | auto it = bannedContactList.begin(); |
| 539 | std::advance(it, index); |
| 540 | |
| 541 | auto contactInfo = LRCInstance::getCurrentAccountInfo().contactModel->getContact(*it); |
| 542 | |
| 543 | LRCInstance::getCurrentAccountInfo().contactModel->addContact(contactInfo); |
| 544 | updateAndShowBannedContactsSlot(); |
| 545 | } |
| 546 | |
| 547 | void |
| 548 | SettingsWidget::exportAccountSlot() |
| 549 | { |
| 550 | QFileDialog dialog(this); |
| 551 | QString dir = QFileDialog::getExistingDirectory(this, tr("Export Account Here"), |
| 552 | QDir::homePath() + "/Desktop", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); |
| 553 | |
| 554 | if (!dir.isEmpty()) { |
| 555 | LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), (dir + "/export.gz").toStdString()); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | void |
| 560 | SettingsWidget::updateAndShowDevicesSlot() |
| 561 | { |
| 562 | ui->settingsListWidget->clear(); |
| 563 | |
| 564 | ui->label->setText(tr("Linked Devices")); |
| 565 | ui->blockedContactsBtn->setText(tr("Blocked Contacts")); |
| 566 | ui->linkDevPushButton->show(); |
| 567 | |
| 568 | auto deviceList = LRCInstance::getCurrentAccountInfo().deviceModel->getAllDevices(); |
| 569 | |
| 570 | int i = 0; |
| 571 | |
| 572 | for (auto it = deviceList.begin(); it != deviceList.end(); ++it, ++i) { |
| 573 | SettingsItemWidget* item = new SettingsItemWidget(itemHeight_, i, false, ui->settingsListWidget); |
| 574 | item->setSizeHint(QSize(ui->settingsListWidget->width(), itemHeight_)); |
| 575 | ui->settingsListWidget->addItem(item); |
| 576 | |
| 577 | if (i) { |
| 578 | connect(item->button_, &QPushButton::clicked, [this, i]() { |
| 579 | removeDeviceSlot(i); |
| 580 | } |
| 581 | ); |
| 582 | } |
| 583 | } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void |
| 587 | SettingsWidget::updateAndShowBannedContactsSlot() |
| 588 | { |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 589 | if (bannedContactsShown_) { |
| 590 | ui->settingsListWidget->clear(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 591 | |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 592 | ui->label->setText(tr("Blocked Contacts")); |
| 593 | ui->blockedContactsBtn->setText(tr("Linked Devices")); |
| 594 | ui->linkDevPushButton->hide(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 595 | |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 596 | auto bannedContactList = LRCInstance::getCurrentAccountInfo().contactModel->getBannedContacts(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 597 | |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 598 | int i = 0; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 599 | |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 600 | for (auto it = bannedContactList.begin(); it != bannedContactList.end(); ++it, ++i) { |
| 601 | SettingsItemWidget* item = new SettingsItemWidget(itemHeight_, i, true, ui->settingsListWidget); |
| 602 | item->setSizeHint(QSize(ui->settingsListWidget->width(), itemHeight_)); |
| 603 | ui->settingsListWidget->addItem(item); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 604 | |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 605 | connect(item->button_, &QPushButton::clicked, [this, i]() { |
| 606 | unban(i); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 607 | } |
Isa Nanic | 3a9c6e2 | 2018-12-11 17:07:20 -0500 | [diff] [blame] | 608 | ); |
| 609 | } |
| 610 | if (!bannedContactList.size()) { updateAndShowDevicesSlot(); ui->blockedContactsBtn->hide(); } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 611 | } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | void |
| 615 | SettingsWidget::showLinkDevSlot() |
| 616 | { |
| 617 | if (!advancedSettingsWidget_) { delete advancedSettingsWidget_; } |
| 618 | |
| 619 | linkDevWidget = new LinkDevWidget(ui->scrollAreaWidgetContents); |
| 620 | linkDevWidget->setMinimumWidth(600); |
| 621 | |
| 622 | ui->accountHorLayout->insertWidget(1, linkDevWidget); |
| 623 | |
| 624 | linkDevWidget->show(); |
| 625 | ui->centralWidget->hide(); |
| 626 | |
| 627 | connect(linkDevWidget->cancelBtn(), &QPushButton::clicked, this, &SettingsWidget::showCurrentAccountSlot); |
| 628 | connect(linkDevWidget->endCancelBtn(), &QPushButton::clicked, this, &SettingsWidget::showCurrentAccountSlot); |
| 629 | } |
| 630 | |
| 631 | void |
| 632 | SettingsWidget::showCurrentAccountSlot() |
| 633 | { |
| 634 | disconnect(linkDevWidget); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 635 | delete linkDevWidget; |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 636 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 637 | ui->centralWidget->show(); |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 638 | updateAndShowDevicesSlot(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void |
| 642 | SettingsWidget::setConnections() |
| 643 | { |
| 644 | // exitSettingsButton |
| 645 | connect(ui->exitSettingsButton, &QPushButton::clicked, this, &SettingsWidget::leaveSettingsSlot); |
| 646 | |
| 647 | connect(ui->accountSettingsButton, &QPushButton::clicked, [this]() { |
| 648 | setSelected(Button::accountSettingsButton); } |
| 649 | ); |
| 650 | |
| 651 | connect(ui->generalSettingsButton, &QPushButton::clicked, [this]() { |
| 652 | setSelected(Button::generalSettingsButton); } |
| 653 | ); |
| 654 | |
| 655 | connect(ui->avSettingsButton, &QPushButton::clicked, [this]() { |
| 656 | setSelected(Button::avSettingsButton); } |
| 657 | ); |
| 658 | |
| 659 | connect(ui->passwdPushButton, &QPushButton::clicked, [this]() { |
| 660 | passwordClicked(); } |
| 661 | ); |
| 662 | |
| 663 | connect(ui->currentAccountAvatar, &QPushButton::clicked, [this]() { |
| 664 | avatarClicked(); } |
| 665 | ); |
| 666 | |
| 667 | connect(ui->advancedAccountSettingsPButton, &QPushButton::clicked, this, &SettingsWidget::toggleAdvancedSettings); |
| 668 | |
| 669 | connect(ui->currentRegisteredID, &QLineEdit::textChanged, this, &SettingsWidget::verifyRegisteredNameSlot); |
| 670 | |
| 671 | connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::registeredNameFound, |
| 672 | this, &SettingsWidget::receiveRegNameSlot); |
| 673 | |
| 674 | //connect "export account" button |
| 675 | connect(ui->btnExportAccount, &QPushButton::clicked, this, &SettingsWidget::exportAccountSlot); |
| 676 | |
| 677 | // connect "delete account" button |
| 678 | connect(ui->btnDeletAccount, &QPushButton::clicked, this, &SettingsWidget::delAccountSlot); |
| 679 | |
| 680 | // connect "banned contacts" button |
| 681 | connect(ui->blockedContactsBtn, &QPushButton::clicked, this, &SettingsWidget::toggleBannedContacts); |
| 682 | |
| 683 | // connect "link device" button |
| 684 | connect(ui->linkDevPushButton, &QPushButton::clicked, this, &SettingsWidget::showLinkDevSlot); |
| 685 | |
| 686 | // update banned accounts automatically |
| 687 | connect(LRCInstance::getCurrentAccountInfo().contactModel.get(), &lrc::api::ContactModel::modelUpdated, |
| 688 | this, &SettingsWidget::updateAndShowBannedContactsSlot); |
| 689 | |
| 690 | // update linked devices automatically |
| 691 | QObject::connect(LRCInstance::getCurrentAccountInfo().deviceModel.get(), &lrc::api::NewDeviceModel::deviceUpdated, |
| 692 | this, &SettingsWidget::updateAndShowDevicesSlot); |
| 693 | |
| 694 | // account settings setters { |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 695 | connect(ui->accountEnableCheckBox, &QCheckBox::clicked, this, &SettingsWidget::setAccEnableSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 696 | |
| 697 | connect(ui->displayNameLineEdit, &QLineEdit::textChanged, [this](const QString& displayName) { |
| 698 | LRCInstance::setCurrAccDisplayName(displayName.toStdString()); |
| 699 | } |
| 700 | ); |
| 701 | |
| 702 | // general settings |
| 703 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 704 | connect(ui->notificationCheckBox, &QAbstractButton::clicked, this, &SettingsWidget::setNotificationsSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 705 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 706 | connect(ui->closeOrMinCheckBox, &QAbstractButton::clicked, this, &SettingsWidget::setClosedOrMinSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 707 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 708 | connect(ui->downloadButton, &QAbstractButton::clicked, this, &SettingsWidget::openDownloadFolderSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 709 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 710 | connect(ui->alwaysRecordingCheckBox, &QAbstractButton::clicked, this, &SettingsWidget::setAlwaysRecordingSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 711 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 712 | connect(ui->checkUpdateButton, &QAbstractButton::clicked, this, &SettingsWidget::checkForUpdateSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 713 | |
| 714 | connect(ui->intervalUpdateCheckSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsWidget::setUpdateIntervalSlot); |
| 715 | |
Isa Nanic | 100368f | 2018-12-11 16:43:01 -0500 | [diff] [blame] | 716 | connect(ui->autoUpdateCheckBox, &QAbstractButton::clicked, this, &SettingsWidget::setUpdateAutomaticSlot); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 717 | |
| 718 | // audio / visual settings |
| 719 | |
| 720 | connect(ui->recordPathButton, &QPushButton::clicked, this, &SettingsWidget::openRecordFolderSlot); |
| 721 | } |
| 722 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 723 | // ************************* General Settings ************************* |
| 724 | |
| 725 | void SettingsWidget::populateGeneralSettings() |
| 726 | { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 727 | QSettings settings; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 728 | |
| 729 | // settings |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 730 | ui->downloadButton->setText(QString::fromStdString(LRCInstance::dataTransferModel().downloadDirectory)); |
| 731 | ui->closeOrMinCheckBox->setChecked(settings.value(SettingsKey::closeOrMinimized).toBool()); |
| 732 | ui->notificationCheckBox->setChecked(settings.value(SettingsKey::enableNotifications).toBool()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 733 | |
| 734 | //recordings |
| 735 | ui->alwaysRecordingCheckBox->setChecked(media::RecordingModel::instance().isAlwaysRecording()); |
| 736 | |
| 737 | if (media::RecordingModel::instance().recordPath().isEmpty()) { |
| 738 | QString recordPath = QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); |
| 739 | media::RecordingModel::instance().setRecordPath(recordPath); |
| 740 | } |
| 741 | ui->recordPathButton->setText(media::RecordingModel::instance().recordPath()); |
| 742 | |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 743 | #ifdef Q_OS_WIN |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 744 | ui->autoUpdateCheckBox->setChecked(win_sparkle_get_automatic_check_for_updates()); |
| 745 | ui->intervalUpdateCheckSpinBox->setValue(win_sparkle_get_update_check_interval() / 86400); |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 746 | #endif |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void |
| 750 | SettingsWidget::setNotificationsSlot(int state) |
| 751 | { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 752 | QSettings settings; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 753 | if (state == Qt::CheckState::Unchecked) { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 754 | settings.setValue(SettingsKey::enableNotifications, false); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 755 | } else { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 756 | settings.setValue(SettingsKey::enableNotifications, true); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | void |
| 761 | SettingsWidget::setClosedOrMinSlot(int state) |
| 762 | { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 763 | QSettings settings; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 764 | if (state == Qt::CheckState::Unchecked) { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 765 | settings.setValue(SettingsKey::closeOrMinimized, false); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 766 | } |
| 767 | else { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 768 | settings.setValue(SettingsKey::closeOrMinimized, true); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
| 772 | void |
| 773 | SettingsWidget::checkForUpdateSlot() |
| 774 | { |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 775 | #ifdef Q_OS_WIN |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 776 | win_sparkle_check_update_with_ui(); |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 777 | #endif |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | void |
| 781 | SettingsWidget::setUpdateIntervalSlot(int value) |
| 782 | { |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 783 | #ifdef Q_OS_WIN |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 784 | win_sparkle_set_update_check_interval(value * 86400); |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 785 | #endif |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | void |
| 789 | SettingsWidget::setUpdateAutomaticSlot(int state) |
| 790 | { |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 791 | #ifdef Q_OS_WIN |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 792 | if (state == Qt::CheckState::Unchecked) { |
| 793 | win_sparkle_set_automatic_check_for_updates(false); |
| 794 | ui->intervalUpdateCheckSpinBox->setEnabled(false); |
| 795 | } else { |
| 796 | win_sparkle_set_automatic_check_for_updates(true); |
| 797 | ui->intervalUpdateCheckSpinBox->setEnabled(true); |
| 798 | } |
Sébastien Blin | d2e8d0e | 2019-01-10 14:18:36 -0500 | [diff] [blame] | 799 | #endif |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void |
| 803 | SettingsWidget::openDownloadFolderSlot() |
| 804 | { |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 805 | QSettings settings; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 806 | QString dir = QFileDialog::getExistingDirectory(this, tr("Select A Folder For Your Downloads"), |
| 807 | QStandardPaths::writableLocation(QStandardPaths::DownloadLocation), QFileDialog::ShowDirsOnly |
| 808 | | QFileDialog::DontResolveSymlinks); |
| 809 | |
| 810 | if (!dir.isEmpty()) { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 811 | ui->downloadButton->setText(dir); |
Isa Nanic | 5bafcb9 | 2018-12-19 12:54:51 -0500 | [diff] [blame] | 812 | settings.setValue(SettingsKey::downloadPath, dir); |
Isa Nanic | 7a3dfa4 | 2018-12-12 12:34:42 -0500 | [diff] [blame] | 813 | LRCInstance::editableDataTransferModel()->downloadDirectory = dir.toStdString() + "/"; |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | SettingsWidget::setAlwaysRecordingSlot(int state) |
| 819 | { |
| 820 | if (state == Qt::CheckState::Unchecked) { |
| 821 | media::RecordingModel::instance().setAlwaysRecording(false); |
| 822 | } else { |
| 823 | media::RecordingModel::instance().setAlwaysRecording(true); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | void |
| 828 | SettingsWidget::openRecordFolderSlot() |
| 829 | { |
| 830 | QString dir = QFileDialog::getExistingDirectory(this, tr("Select A Folder For Your Recordings"), |
| 831 | media::RecordingModel::instance().recordPath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); |
| 832 | |
| 833 | if (!dir.isEmpty()) { |
| 834 | media::RecordingModel::instance().setRecordPath(dir); |
| 835 | ui->recordPathButton->setText(media::RecordingModel::instance().recordPath()); |
| 836 | } |
| 837 | } |
| 838 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 839 | // ************************* Audio/Visual Settings ************************* |
| 840 | |
| 841 | void |
| 842 | SettingsWidget::populateAVSettings() |
| 843 | { |
| 844 | ui->deviceBox->setModel(deviceModel_); |
| 845 | connect(deviceModel_, SIGNAL(currentIndexChanged(int)), |
| 846 | this, SLOT(deviceIndexChanged(int))); |
| 847 | |
Isa Nanic | 9316d47 | 2018-12-18 16:27:13 -0500 | [diff] [blame] | 848 | // Audio settings |
| 849 | auto inputModel = Audio::Settings::instance().inputDeviceModel(); |
| 850 | auto outputModel = Audio::Settings::instance().outputDeviceModel(); |
| 851 | |
| 852 | ui->inputComboBox->setModel(inputModel); |
| 853 | ui->outputComboBox->setModel(outputModel); |
| 854 | |
| 855 | auto inputIndex = inputModel->selectionModel()->currentIndex(); |
| 856 | auto outputIndex = outputModel->selectionModel()->currentIndex(); |
| 857 | |
| 858 | ui->inputComboBox->setCurrentIndex(inputIndex.row()); |
| 859 | ui->outputComboBox->setCurrentIndex(outputIndex.row()); |
| 860 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 861 | if (ui->deviceBox->count() > 0) { |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 862 | deviceBoxCurrentIndexChangedSlot(0); |
| 863 | } |
| 864 | |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 865 | if (currentResIndex >= 0) { |
| 866 | ui->sizeBox->setCurrentIndex(currentResIndex); |
| 867 | } |
| 868 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 869 | connect(ui->outputComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), |
| 870 | this, &SettingsWidget::outputDevIndexChangedSlot); |
| 871 | connect(ui->inputComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), |
| 872 | this, &SettingsWidget::inputdevIndexChangedSlot); |
| 873 | |
| 874 | connect(ui->deviceBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
| 875 | &SettingsWidget::deviceBoxCurrentIndexChangedSlot); |
| 876 | connect(ui->sizeBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
| 877 | &SettingsWidget::sizeBoxCurrentIndexChangedSlot); |
Isa Nanic | 9316d47 | 2018-12-18 16:27:13 -0500 | [diff] [blame] | 878 | |
| 879 | showPreview(); |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 880 | } |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 881 | |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 882 | void |
| 883 | SettingsWidget::saveSizeIndex() |
| 884 | { |
| 885 | currentResIndex = ui->sizeBox->currentIndex(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | void |
| 889 | SettingsWidget::showPreview() |
| 890 | { |
| 891 | if (!CallModel::instance().getActiveCalls().size()) { |
| 892 | ui->previewUnavailableLabel->hide(); |
| 893 | ui->videoWidget->show(); |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 894 | startVideo(); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 895 | ui->videoWidget->setIsFullPreview(true); |
| 896 | } else { |
| 897 | ui->previewUnavailableLabel->show(); |
| 898 | ui->videoWidget->hide(); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | void |
| 903 | SettingsWidget::deviceBoxCurrentIndexChangedSlot(int index) |
| 904 | { |
| 905 | if (index < 0) { |
| 906 | return; |
| 907 | } |
| 908 | |
Isa Nanic | 9316d47 | 2018-12-18 16:27:13 -0500 | [diff] [blame] | 909 | deviceModel_->setActive(index); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 910 | |
| 911 | auto device = deviceModel_->activeDevice(); |
| 912 | |
| 913 | ui->sizeBox->clear(); |
| 914 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 915 | if (device->channelList().size() > 0) { |
| 916 | for (auto resolution : device->channelList()[0]->validResolutions()) { |
| 917 | ui->sizeBox->addItem(resolution->name()); |
| 918 | } |
| 919 | } |
| 920 | ui->sizeBox->setCurrentIndex( |
| 921 | device->channelList()[0]->activeResolution()->relativeIndex()); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | void |
| 925 | SettingsWidget::sizeBoxCurrentIndexChangedSlot(int index) |
| 926 | { |
Isa Nanic | 9316d47 | 2018-12-18 16:27:13 -0500 | [diff] [blame] | 927 | if (index < 0) { |
| 928 | return; |
| 929 | } |
| 930 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 931 | auto device = deviceModel_->activeDevice(); |
| 932 | |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 933 | device->channelList()[0]->setActiveResolution(device->channelList()[0]->validResolutions()[index]); |
Isa Nanic | 9316d47 | 2018-12-18 16:27:13 -0500 | [diff] [blame] | 934 | |
| 935 | QTimer::singleShot(200, this, [this]() { |
| 936 | deviceModel_->setActive(ui->deviceBox->currentIndex()); |
| 937 | }); |
Isa Nanic | 6e4a39a | 2018-12-04 14:26:02 -0500 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | void |
| 941 | SettingsWidget::deviceIndexChanged(int index) |
| 942 | { |
| 943 | ui->deviceBox->setCurrentIndex(index); |
| 944 | |
| 945 | ui->videoLayout->update(); |
| 946 | } |
| 947 | |
| 948 | void |
| 949 | SettingsWidget::outputDevIndexChangedSlot(int index) |
| 950 | { |
| 951 | auto outputModel = Audio::Settings::instance().outputDeviceModel(); |
| 952 | outputModel->selectionModel()->setCurrentIndex(outputModel->index(index), QItemSelectionModel::ClearAndSelect); |
| 953 | } |
| 954 | |
| 955 | void |
| 956 | SettingsWidget::inputdevIndexChangedSlot(int index) |
| 957 | { |
| 958 | auto inputModel = Audio::Settings::instance().inputDeviceModel(); |
| 959 | inputModel->selectionModel()->setCurrentIndex(inputModel->index(index), QItemSelectionModel::ClearAndSelect); |
Isa Nanic | 054ef9a | 2018-12-11 11:56:28 -0500 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void |
| 963 | SettingsWidget::startVideo() |
| 964 | { |
| 965 | Video::PreviewManager::instance().stopPreview(); |
| 966 | Video::PreviewManager::instance().startPreview(); |
| 967 | } |
| 968 | |
| 969 | void |
| 970 | SettingsWidget::stopVideo() |
| 971 | { |
| 972 | Video::PreviewManager::instance().stopPreview(); |
Isa Nanic | 26c8661 | 2018-12-14 12:21:56 -0500 | [diff] [blame] | 973 | } |