File indexing completed on 2025-01-05 04:00:14

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2020-27-07
0007  * Description : system settings widget
0008  *
0009  * SPDX-FileCopyrightText: 2020-2023 by Maik Qualmann <metzpinguin at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "systemsettingswidget.h"
0016 
0017 // Qt includes
0018 
0019 #include <QApplication>
0020 #include <QPushButton>
0021 #include <QGridLayout>
0022 #include <QCheckBox>
0023 #include <QLabel>
0024 #include <QStyle>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 // Local includes
0031 
0032 #include "digikam_debug.h"
0033 #include "systemsettings.h"
0034 #include "filesdownloader.h"
0035 #include "ui_proxysettingswidget.h"
0036 
0037 namespace Digikam
0038 {
0039 
0040 class Q_DECL_HIDDEN SystemSettingsWidget::Private
0041 {
0042 
0043 public:
0044 
0045     Private() = default;
0046 
0047 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0048 
0049     QCheckBox*              useHighDpiScalingCheck = nullptr;
0050     QCheckBox*              useHighDpiPixmapsCheck = nullptr;
0051 
0052 #endif
0053 
0054     QCheckBox*              softwareOpenGLCheck    = nullptr;
0055     QCheckBox*              disableOpenCLCheck     = nullptr;
0056     QCheckBox*              enableLoggingCheck     = nullptr;
0057 
0058     QPushButton*            filesDownloadButton    = nullptr;
0059 
0060     FilesDownloader*        filesDownloader        = nullptr;
0061 
0062     Ui::ProxySettingsWidget uiProxySettings;
0063 };
0064 
0065 SystemSettingsWidget::SystemSettingsWidget(QWidget* const parent)
0066     : QWidget(parent),
0067       d      (new Private)
0068 {
0069     const int spacing         = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0070                                      QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0071 
0072     QGridLayout* const layout = new QGridLayout(this);
0073 
0074     d->filesDownloader        = new FilesDownloader(this);
0075 
0076 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0077 
0078     d->useHighDpiScalingCheck = new QCheckBox(i18n("Use high DPI scaling from the screen factor"), this);
0079     d->useHighDpiPixmapsCheck = new QCheckBox(i18n("Use pixmaps with high DPI resolution"), this);
0080 
0081 #endif
0082 
0083     d->softwareOpenGLCheck    = new QCheckBox(i18n("Force use of software OpenGL rendering"), this);
0084     d->disableOpenCLCheck     = new QCheckBox(i18n("Disable hardware acceleration OpenCL"), this);
0085     d->enableLoggingCheck     = new QCheckBox(i18n("Enable internal debug logging"), this);
0086 
0087     d->filesDownloadButton    = new QPushButton(i18n("Download required binary data..."), this);
0088 
0089     // Proxy Settings
0090 
0091     QWidget* const proxySettings = new QWidget(this);
0092     d->uiProxySettings.setupUi(proxySettings);
0093     proxySettings->setContentsMargins(QMargins());
0094 
0095     // ---
0096 
0097     if (qApp->applicationName() == QLatin1String("showfoto"))
0098     {
0099         d->disableOpenCLCheck->hide();
0100     }
0101 
0102     QLabel* const systemNote  = new QLabel(i18n("<b>Note: All changes to these settings only take effect "
0103                                                 "after the restart. Some settings are hardware dependent "
0104                                                 "and may have no effect.</b>"), this);
0105     systemNote->setWordWrap(true);
0106     systemNote->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0107 
0108     int row = 0;
0109 
0110 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0111 
0112     layout->addWidget(d->useHighDpiScalingCheck, row++, 0, 1, 1);
0113     layout->addWidget(d->useHighDpiPixmapsCheck, row++, 0, 1, 1);
0114 
0115 #endif
0116 
0117     layout->addWidget(d->softwareOpenGLCheck,    row++, 0, 1, 1);
0118     layout->addWidget(d->disableOpenCLCheck,     row++, 0, 1, 1);
0119     layout->addWidget(d->enableLoggingCheck,     row++, 0, 1, 1);
0120     layout->addWidget(d->filesDownloadButton,    row++, 0, 1, 1);
0121     layout->addWidget(proxySettings,             row++, 0, 1, 1);
0122     layout->addWidget(systemNote,                row++, 0, 1, 2);
0123     layout->setContentsMargins(spacing, spacing, spacing, spacing);
0124     layout->setRowStretch(row, 10);
0125 
0126     connect(d->filesDownloadButton, &QPushButton::pressed,
0127             this, &SystemSettingsWidget::slotBinaryDownload);
0128 }
0129 
0130 SystemSettingsWidget::~SystemSettingsWidget()
0131 {
0132     delete d;
0133 }
0134 
0135 void SystemSettingsWidget::readSettings()
0136 {
0137     SystemSettings system(qApp->applicationName());
0138 
0139 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0140 
0141     d->useHighDpiScalingCheck->setChecked(system.useHighDpiScaling);
0142     d->useHighDpiPixmapsCheck->setChecked(system.useHighDpiPixmaps);
0143 
0144 #endif
0145 
0146     d->softwareOpenGLCheck->setChecked(system.softwareOpenGL);
0147     d->enableLoggingCheck->setChecked(system.enableLogging);
0148     d->disableOpenCLCheck->setChecked(system.disableOpenCL);
0149 
0150     // Proxy Settings
0151 
0152     d->uiProxySettings.kcfg_proxyUrl->setText(system.proxyUrl);
0153     d->uiProxySettings.kcfg_proxyPort->setValue(system.proxyPort);
0154     d->uiProxySettings.kcfg_proxyUser->setText(system.proxyUser);
0155     d->uiProxySettings.kcfg_proxyPass->setText(system.proxyPass);
0156     d->uiProxySettings.kcfg_proxyType->setCurrentIndex(system.proxyType);
0157     d->uiProxySettings.kcfg_proxyAuth->setChecked(system.proxyAuth);
0158 }
0159 
0160 void SystemSettingsWidget::saveSettings()
0161 {
0162     SystemSettings system(qApp->applicationName());
0163 
0164 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0165 
0166     system.useHighDpiScaling = d->useHighDpiScalingCheck->isChecked();
0167     system.useHighDpiPixmaps = d->useHighDpiPixmapsCheck->isChecked();
0168 
0169 #endif
0170 
0171     system.softwareOpenGL    = d->softwareOpenGLCheck->isChecked();
0172     system.enableLogging     = d->enableLoggingCheck->isChecked();
0173     system.disableOpenCL     = d->disableOpenCLCheck->isChecked();
0174 
0175     system.proxyUrl          = d->uiProxySettings.kcfg_proxyUrl->text();
0176     system.proxyPort         = d->uiProxySettings.kcfg_proxyPort->value();
0177     system.proxyType         = d->uiProxySettings.kcfg_proxyType->currentIndex();
0178 
0179     if (d->uiProxySettings.kcfg_proxyAuth->isChecked())
0180     {
0181         system.proxyAuth = true;
0182         system.proxyUser = d->uiProxySettings.kcfg_proxyUser->text();
0183         system.proxyPass = d->uiProxySettings.kcfg_proxyPass->text();
0184     }
0185     else
0186     {
0187         system.proxyAuth = false;
0188     }
0189 
0190     system.saveSettings();
0191 }
0192 
0193 void SystemSettingsWidget::slotBinaryDownload()
0194 {
0195     d->filesDownloader->startDownload();
0196 }
0197 
0198 } // namespace Digikam
0199 
0200 #include "moc_systemsettingswidget.cpp"