2022-03-31 21:32:22 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-01-19 20:46:42 +00:00
|
|
|
#include "pagegeneral.h"
|
|
|
|
#include "ui_pagegeneral.h"
|
|
|
|
|
|
|
|
PageGeneral::PageGeneral(QWidget* parent):
|
|
|
|
QWidget(parent),
|
2022-02-19 18:31:49 +00:00
|
|
|
m_ui(new Ui::PageGeneral()),
|
|
|
|
dialog(nullptr)
|
2022-01-19 20:46:42 +00:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
2022-02-17 17:26:15 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
m_ui->downloadsPathInput->setText(settings.value("downloadsPath").toString());
|
2022-08-15 16:40:07 +00:00
|
|
|
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
bool tray = settings.value("tray", false).toBool();
|
|
|
|
m_ui->trayInput->setChecked(tray);
|
|
|
|
if (tray) {
|
|
|
|
m_ui->hideTrayInput->setChecked(settings.value("hideTray", false).toBool());
|
|
|
|
} else {
|
|
|
|
m_ui->hideTrayInput->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(m_ui->trayInput, &QCheckBox::stateChanged, this, &PageGeneral::onTrayChecked);
|
|
|
|
connect(m_ui->hideTrayInput, &QCheckBox::stateChanged, this, &PageGeneral::onHideTrayChecked);
|
|
|
|
} else {
|
|
|
|
m_ui->trayInput->setEnabled(false);
|
|
|
|
m_ui->hideTrayInput->setEnabled(false);
|
|
|
|
m_ui->trayInput->setToolTip(tr("Tray is not available for your system")); //TODO translate
|
|
|
|
}
|
|
|
|
|
2022-02-19 18:31:49 +00:00
|
|
|
connect(m_ui->downloadsPathButton, &QPushButton::clicked, this, &PageGeneral::onBrowseButtonClicked);
|
2022-01-19 20:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PageGeneral::~PageGeneral()
|
|
|
|
{
|
2022-02-19 18:31:49 +00:00
|
|
|
if (dialog != nullptr) {
|
|
|
|
dialog->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageGeneral::onBrowseButtonClicked()
|
|
|
|
{
|
|
|
|
if (dialog == nullptr) {
|
|
|
|
QSettings settings;
|
|
|
|
dialog = new QFileDialog(this, tr("Select where downloads folder is going to be"), settings.value("downloadsPath").toString());
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->setAcceptMode(QFileDialog::AcceptSave); //I find it the most convinient way
|
|
|
|
dialog->setFileMode(QFileDialog::AnyFile); //Otherwise the directory is supposed to be
|
|
|
|
dialog->setOption(QFileDialog::ShowDirsOnly, true); //selected and not to be navigated
|
|
|
|
dialog->setOption(QFileDialog::DontConfirmOverwrite, true);
|
|
|
|
dialog->setModal(true);
|
|
|
|
connect(dialog, &QFileDialog::accepted, this, &PageGeneral::onDialogAccepted);
|
|
|
|
connect(dialog, &QFileDialog::destroyed, this, &PageGeneral::onDialogDestroyed);
|
|
|
|
dialog->show();
|
|
|
|
} else {
|
|
|
|
dialog->show();
|
|
|
|
dialog->raise();
|
|
|
|
dialog->activateWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageGeneral::onDialogAccepted()
|
|
|
|
{
|
|
|
|
QStringList files = dialog->selectedFiles();
|
|
|
|
QString path;
|
|
|
|
if (files.size() > 0) {
|
|
|
|
path = files[0];
|
|
|
|
} else {
|
|
|
|
path = dialog->directory().canonicalPath();
|
|
|
|
}
|
|
|
|
m_ui->downloadsPathInput->setText(path);
|
|
|
|
emit variableModified("downloadsPath", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageGeneral::onDialogDestroyed()
|
|
|
|
{
|
|
|
|
dialog = nullptr;
|
2022-01-19 20:46:42 +00:00
|
|
|
}
|
2022-08-15 16:40:07 +00:00
|
|
|
|
|
|
|
void PageGeneral::onTrayChecked(int state)
|
|
|
|
{
|
|
|
|
bool enabled = state == Qt::Checked;
|
|
|
|
emit variableModified("tray", enabled);
|
|
|
|
m_ui->hideTrayInput->setEnabled(enabled);
|
|
|
|
if (!enabled) {
|
2022-08-17 16:25:35 +00:00
|
|
|
m_ui->hideTrayInput->setChecked(false);
|
2022-08-15 16:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageGeneral::onHideTrayChecked(int state)
|
|
|
|
{
|
|
|
|
bool enabled = state == Qt::Checked;
|
|
|
|
emit variableModified("hideTray", enabled);
|
|
|
|
}
|