| 1 | /* |
| 2 | * Copyright (C) 2020 Damir Porobic <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "UploaderSettings.h" |
| 21 | |
| 22 | UploaderSettings::UploaderSettings(const QSharedPointer<IConfig> &config) : |
| 23 | mConfig(config), |
| 24 | mConfirmBeforeUploadCheckbox(new QCheckBox(this)), |
| 25 | mUploaderTypeComboBox(new QComboBox(this)), |
| 26 | mUploaderTypeLabel(new QLabel(this)), |
| 27 | mLayout(new QGridLayout(this)) |
| 28 | { |
| 29 | initGui(); |
| 30 | loadConfig(); |
| 31 | } |
| 32 | |
| 33 | UploaderSettings::~UploaderSettings() |
| 34 | { |
| 35 | delete mConfirmBeforeUploadCheckbox; |
| 36 | delete mUploaderTypeComboBox; |
| 37 | delete mUploaderTypeLabel; |
| 38 | } |
| 39 | |
| 40 | void UploaderSettings::saveSettings() |
| 41 | { |
| 42 | mConfig->setConfirmBeforeUpload(mConfirmBeforeUploadCheckbox->isChecked()); |
| 43 | mConfig->setUploaderType(static_cast<UploaderType>(mUploaderTypeComboBox->currentData().toInt())); |
| 44 | } |
| 45 | |
| 46 | void UploaderSettings::initGui() |
| 47 | { |
| 48 | mConfirmBeforeUploadCheckbox->setText(tr("Ask for confirmation before uploading")); |
| 49 | |
| 50 | mUploaderTypeLabel->setText(tr("Uploader Type:")); |
| 51 | |
| 52 | mUploaderTypeComboBox->addItem(tr("Imgur"), static_cast<int>(UploaderType::Imgur)); |
| 53 | mUploaderTypeComboBox->addItem(tr("FTP"), static_cast<int>(UploaderType::Ftp)); |
| 54 | mUploaderTypeComboBox->addItem(tr("Script"), static_cast<int>(UploaderType::Script)); |
| 55 | |
| 56 | mLayout->setAlignment(Qt::AlignTop); |
| 57 | mLayout->addWidget(mConfirmBeforeUploadCheckbox, 0, 0, 1, 3); |
| 58 | mLayout->setRowMinimumHeight(1, 15); |
| 59 | mLayout->addWidget(mUploaderTypeLabel, 2, 0, 1, 1); |
| 60 | mLayout->addWidget(mUploaderTypeComboBox, 2, 1, 1, 1); |
| 61 | |
| 62 | setTitle(tr("Uploader")); |
| 63 | setLayout(mLayout); |
| 64 | } |
| 65 | |
| 66 | void UploaderSettings::loadConfig() |
| 67 | { |
| 68 | mConfirmBeforeUploadCheckbox->setChecked(mConfig->confirmBeforeUpload()); |
| 69 | mUploaderTypeComboBox->setCurrentIndex(mUploaderTypeComboBox->findData(static_cast<int>(mConfig->uploaderType()))); |
| 70 | } |