| 1 | /* |
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
| 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 3 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, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #include "environmentfolderswidget.h" |
| 18 | #include "ui_environmentfolderswidget.h" |
| 19 | #include "../settings.h" |
| 20 | #include "../mainwindow.h" |
| 21 | #include "../iconsmanager.h" |
| 22 | |
| 23 | #include <QDesktopServices> |
| 24 | #include <QDir> |
| 25 | #include <QMessageBox> |
| 26 | #include <QUrl> |
| 27 | |
| 28 | EnvironmentFoldersWidget::EnvironmentFoldersWidget(const QString& name, const QString& group, QWidget *parent) : |
| 29 | SettingsWidget(name,group,parent), |
| 30 | ui(new Ui::EnvironmentFoldersWidget) |
| 31 | { |
| 32 | ui->setupUi(this); |
| 33 | } |
| 34 | |
| 35 | EnvironmentFoldersWidget::~EnvironmentFoldersWidget() |
| 36 | { |
| 37 | delete ui; |
| 38 | } |
| 39 | |
| 40 | void EnvironmentFoldersWidget::doLoad() |
| 41 | { |
| 42 | ui->txtConfigFolder->setText(pSettings->dirs().config()); |
| 43 | ui->txtIconSetFolder->setEnabled(pSettings->environment().useCustomIconSet()); |
| 44 | ui->btnOpenIconSetFolderInFileBrowser->setEnabled(pSettings->environment().useCustomIconSet()); |
| 45 | if (pSettings->environment().useCustomIconSet()) { |
| 46 | ui->txtIconSetFolder->setText(pSettings->dirs().config(Settings::Dirs::DataType::IconSet)); |
| 47 | } |
| 48 | ui->txtThemeFolder->setEnabled(pSettings->environment().useCustomTheme()); |
| 49 | ui->btnOpenThemeFolderInFileBrowser->setEnabled(pSettings->environment().useCustomTheme()); |
| 50 | if (pSettings->environment().useCustomTheme()) { |
| 51 | ui->txtThemeFolder->setText(pSettings->dirs().config(Settings::Dirs::DataType::Theme)); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void EnvironmentFoldersWidget::doSave() |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | void EnvironmentFoldersWidget::on_btnOpenConfigFolderInBrowser_clicked() |
| 60 | { |
| 61 | QDesktopServices::openUrl( |
| 62 | QUrl("file:///" + |
| 63 | includeTrailingPathDelimiter(pSettings->dirs().config()),QUrl::TolerantMode)); |
| 64 | |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void EnvironmentFoldersWidget::on_btnResetDefault_clicked() |
| 69 | { |
| 70 | if (QMessageBox::question(this,tr("Confirm" ), |
| 71 | tr("Do you really want to delete all custom settings?" ), |
| 72 | QMessageBox::Yes|QMessageBox::No, |
| 73 | QMessageBox::No)!=QMessageBox::Yes) |
| 74 | return; |
| 75 | QDir dir(pSettings->dirs().config()); |
| 76 | if (!dir.removeRecursively()) { |
| 77 | QMessageBox::critical(this,tr("Error" ), |
| 78 | tr("Failed to delete custom settings." )); |
| 79 | return; |
| 80 | } |
| 81 | emit shouldQuitApp(); |
| 82 | } |
| 83 | |
| 84 | void EnvironmentFoldersWidget::updateIcons(const QSize &/*size*/) |
| 85 | { |
| 86 | pIconsManager->setIcon(ui->btnOpenConfigFolderInBrowser,IconsManager::ACTION_FILE_OPEN_FOLDER); |
| 87 | pIconsManager->setIcon(ui->btnOpenThemeFolderInFileBrowser,IconsManager::ACTION_FILE_OPEN_FOLDER); |
| 88 | pIconsManager->setIcon(ui->btnOpenIconSetFolderInFileBrowser,IconsManager::ACTION_FILE_OPEN_FOLDER); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | void EnvironmentFoldersWidget::on_btnOpenIconSetFolderInFileBrowser_clicked() |
| 93 | { |
| 94 | QDesktopServices::openUrl( |
| 95 | QUrl("file:///" + |
| 96 | includeTrailingPathDelimiter(pSettings->dirs().config(Settings::Dirs::DataType::IconSet)),QUrl::TolerantMode)); |
| 97 | |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void EnvironmentFoldersWidget::on_btnOpenThemeFolderInFileBrowser_clicked() |
| 102 | { |
| 103 | QDesktopServices::openUrl( |
| 104 | QUrl("file:///" + |
| 105 | includeTrailingPathDelimiter(pSettings->dirs().config(Settings::Dirs::DataType::Theme)),QUrl::TolerantMode)); |
| 106 | |
| 107 | } |
| 108 | |
| 109 | |