File indexing completed on 2024-04-21 04:57:00

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004 - 2007 KGet Developers <kget@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 */
0009 
0010 #include "preferencesdialog.h"
0011 #include "core/kget.h"
0012 #include "core/transferhistorystore.h"
0013 #include "settings.h"
0014 
0015 #include "dlgwebinterface.h"
0016 #include "ui_dlgappearance.h"
0017 #include "ui_dlgnetwork.h"
0018 
0019 #include "integrationpreferences.h"
0020 #include "pluginselector.h"
0021 #include "transfersgroupwidget.h"
0022 #include "verificationpreferences.h"
0023 
0024 #include <KComboBox>
0025 #include <KConfigSkeleton>
0026 #include <KLocalizedString>
0027 
0028 #include <QIntValidator>
0029 
0030 #include <limits>
0031 
0032 PreferencesDialog::PreferencesDialog(QWidget *parent, KConfigSkeleton *skeleton)
0033     : KConfigDialog(parent, "preferences", skeleton)
0034 {
0035     auto *appearance = new QWidget(this);
0036     auto *groups = new TransfersGroupWidget(this);
0037     auto *webinterface = new DlgWebinterface(this);
0038     connect(webinterface, &DlgWebinterface::changed, this, &PreferencesDialog::enableApplyButton);
0039     connect(webinterface, &DlgWebinterface::saved, this, &PreferencesDialog::settingsChangedSlot);
0040     auto *network = new QWidget(this);
0041     auto *advanced = new QWidget(this);
0042     auto *integration = new IntegrationPreferences(this);
0043     connect(integration, &IntegrationPreferences::changed, this, &PreferencesDialog::enableApplyButton);
0044     auto *verification = new VerificationPreferences(this);
0045     connect(verification, &VerificationPreferences::changed, this, &PreferencesDialog::enableApplyButton);
0046     auto *pluginSelector = new PluginSelector(this);
0047     connect(pluginSelector, &PluginSelector::changed, this, &PreferencesDialog::enableApplyButton);
0048 
0049     Ui::DlgAppearance dlgApp;
0050     Ui::DlgNetwork dlgNet;
0051 
0052     dlgApp.setupUi(appearance);
0053     dlgNet.setupUi(network);
0054     dlgAdv.setupUi(advanced);
0055 
0056     // history backend entries
0057     dlgAdv.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
0058 #ifdef HAVE_SQLITE
0059     dlgAdv.kcfg_HistoryBackend->addItem(i18n("Sqlite"), QVariant(TransferHistoryStore::SQLite));
0060 #endif
0061 
0062     dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
0063     dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
0064     dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
0065 
0066     // enable or disable the AfterFinishAction depends on the AfterFinishActionEnabled checkbox state
0067     dlgAdv.kcfg_AfterFinishAction->setEnabled(dlgAdv.kcfg_AfterFinishActionEnabled->checkState() == Qt::Checked);
0068     connect(dlgAdv.kcfg_AfterFinishActionEnabled, &QCheckBox::stateChanged, this, &PreferencesDialog::slotToggleAfterFinishAction);
0069 
0070     dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Day(s)"), QVariant(TransferHistoryStore::Day));
0071     dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Hour(s)"), QVariant(TransferHistoryStore::Hour));
0072     dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Minute(s)"), QVariant(TransferHistoryStore::Minute));
0073     dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Second(s)"), QVariant(TransferHistoryStore::Second));
0074 
0075     // enable or disable the SetExpiryTimeType and SetExpiryTimeValue on the EnableAutomaticDeletion checkbox state
0076     dlgAdv.kcfg_ExpiryTimeType->setEnabled(dlgAdv.kcfg_AutomaticDeletionEnabled->checkState() == Qt::Checked);
0077     dlgAdv.kcfg_ExpiryTimeValue->setEnabled(dlgAdv.kcfg_AutomaticDeletionEnabled->checkState() == Qt::Checked);
0078     connect(dlgAdv.kcfg_AutomaticDeletionEnabled, &QCheckBox::stateChanged, this, &PreferencesDialog::slotToggleAutomaticDeletion);
0079     connect(this, &PreferencesDialog::settingsChanged, this, &PreferencesDialog::slotCheckExpiryValue);
0080 
0081     // TODO: remove the following lines as soon as these features are ready
0082     dlgNet.lb_per_transfer->setVisible(false);
0083     dlgNet.kcfg_TransferSpeedLimit->setVisible(false);
0084 
0085     addPage(appearance, i18n("Appearance"), "preferences-desktop-theme", i18n("Change appearance settings"));
0086     addPage(groups, i18n("Groups"), "bookmarks", i18n("Manage the groups"));
0087     addPage(network, i18n("Network"), "network-workgroup", i18n("Network and Downloads"));
0088     addPage(webinterface, i18n("Web Interface"), "network-workgroup", i18n("Control KGet over a Network or the Internet"));
0089     addPage(verification, i18n("Verification"), "document-encrypt", i18n("Verification"));
0090     addPage(integration,
0091             i18nc("integration of KGet with other applications", "Integration"),
0092             "konqueror",
0093             i18nc("integration of KGet with other applications", "Integration"));
0094     addPage(advanced, i18nc("Advanced Options", "Advanced"), "preferences-other", i18n("Advanced Options"));
0095     addPage(pluginSelector, i18n("Plugins"), "preferences-plugin", i18n("Transfer Plugins"));
0096 
0097     connect(this, &PreferencesDialog::accepted, this, &PreferencesDialog::disableApplyButton);
0098     connect(this, &PreferencesDialog::rejected, this, &PreferencesDialog::disableApplyButton);
0099 }
0100 
0101 void PreferencesDialog::disableApplyButton()
0102 {
0103     button(QDialogButtonBox::Apply)->setEnabled(false);
0104 }
0105 
0106 void PreferencesDialog::enableApplyButton()
0107 {
0108     button(QDialogButtonBox::Apply)->setEnabled(true);
0109 }
0110 
0111 void PreferencesDialog::slotToggleAfterFinishAction(int state)
0112 {
0113     dlgAdv.kcfg_AfterFinishAction->setEnabled(state == Qt::Checked);
0114 }
0115 
0116 void PreferencesDialog::slotToggleAutomaticDeletion(int state)
0117 {
0118     dlgAdv.kcfg_ExpiryTimeType->setEnabled(state == Qt::Checked);
0119     dlgAdv.kcfg_ExpiryTimeValue->setEnabled(state == Qt::Checked);
0120     if (state)
0121         dlgAdv.kcfg_ExpiryTimeValue->setValidator(new QIntValidator(1, 999));
0122     else
0123         delete dlgAdv.kcfg_ExpiryTimeValue->validator();
0124 }
0125 
0126 void PreferencesDialog::slotCheckExpiryValue()
0127 {
0128     if (dlgAdv.kcfg_ExpiryTimeValue->text().isEmpty())
0129         dlgAdv.kcfg_ExpiryTimeValue->setText(QString('1'));
0130 }
0131 
0132 void PreferencesDialog::updateWidgetsDefault()
0133 {
0134     Q_EMIT resetDefaults();
0135     KConfigDialog::updateWidgetsDefault();
0136 }
0137 
0138 #include "moc_preferencesdialog.cpp"