File indexing completed on 2023-09-24 08:52:51
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 #ifdef HAVE_KWORKSPACE 0063 dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown)); 0064 dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate)); 0065 dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend)); 0066 #endif 0067 0068 // enable or disable the AfterFinishAction depends on the AfterFinishActionEnabled checkbox state 0069 dlgAdv.kcfg_AfterFinishAction->setEnabled(dlgAdv.kcfg_AfterFinishActionEnabled->checkState() == Qt::Checked); 0070 connect(dlgAdv.kcfg_AfterFinishActionEnabled, &QCheckBox::stateChanged, this, &PreferencesDialog::slotToggleAfterFinishAction); 0071 0072 dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Day(s)"), QVariant(TransferHistoryStore::Day)); 0073 dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Hour(s)"), QVariant(TransferHistoryStore::Hour)); 0074 dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Minute(s)"), QVariant(TransferHistoryStore::Minute)); 0075 dlgAdv.kcfg_ExpiryTimeType->addItem(i18n("Second(s)"), QVariant(TransferHistoryStore::Second)); 0076 0077 // enable or disable the SetExpiryTimeType and SetExpiryTimeValue on the EnableAutomaticDeletion checkbox state 0078 dlgAdv.kcfg_ExpiryTimeType->setEnabled(dlgAdv.kcfg_AutomaticDeletionEnabled->checkState() == Qt::Checked); 0079 dlgAdv.kcfg_ExpiryTimeValue->setEnabled(dlgAdv.kcfg_AutomaticDeletionEnabled->checkState() == Qt::Checked); 0080 connect(dlgAdv.kcfg_AutomaticDeletionEnabled, &QCheckBox::stateChanged, this, &PreferencesDialog::slotToggleAutomaticDeletion); 0081 connect(this, &PreferencesDialog::settingsChanged, this, &PreferencesDialog::slotCheckExpiryValue); 0082 0083 // TODO: remove the following lines as soon as these features are ready 0084 dlgNet.lb_per_transfer->setVisible(false); 0085 dlgNet.kcfg_TransferSpeedLimit->setVisible(false); 0086 0087 addPage(appearance, i18n("Appearance"), "preferences-desktop-theme", i18n("Change appearance settings")); 0088 addPage(groups, i18n("Groups"), "bookmarks", i18n("Manage the groups")); 0089 addPage(network, i18n("Network"), "network-workgroup", i18n("Network and Downloads")); 0090 addPage(webinterface, i18n("Web Interface"), "network-workgroup", i18n("Control KGet over a Network or the Internet")); 0091 addPage(verification, i18n("Verification"), "document-encrypt", i18n("Verification")); 0092 addPage(integration, 0093 i18nc("integration of KGet with other applications", "Integration"), 0094 "konqueror", 0095 i18nc("integration of KGet with other applications", "Integration")); 0096 addPage(advanced, i18nc("Advanced Options", "Advanced"), "preferences-other", i18n("Advanced Options")); 0097 addPage(pluginSelector, i18n("Plugins"), "preferences-plugin", i18n("Transfer Plugins")); 0098 0099 connect(this, &PreferencesDialog::accepted, this, &PreferencesDialog::disableApplyButton); 0100 connect(this, &PreferencesDialog::rejected, this, &PreferencesDialog::disableApplyButton); 0101 } 0102 0103 void PreferencesDialog::disableApplyButton() 0104 { 0105 button(QDialogButtonBox::Apply)->setEnabled(false); 0106 } 0107 0108 void PreferencesDialog::enableApplyButton() 0109 { 0110 button(QDialogButtonBox::Apply)->setEnabled(true); 0111 } 0112 0113 void PreferencesDialog::slotToggleAfterFinishAction(int state) 0114 { 0115 dlgAdv.kcfg_AfterFinishAction->setEnabled(state == Qt::Checked); 0116 } 0117 0118 void PreferencesDialog::slotToggleAutomaticDeletion(int state) 0119 { 0120 dlgAdv.kcfg_ExpiryTimeType->setEnabled(state == Qt::Checked); 0121 dlgAdv.kcfg_ExpiryTimeValue->setEnabled(state == Qt::Checked); 0122 if (state) 0123 dlgAdv.kcfg_ExpiryTimeValue->setValidator(new QIntValidator(1, 999)); 0124 else 0125 delete dlgAdv.kcfg_ExpiryTimeValue->validator(); 0126 } 0127 0128 void PreferencesDialog::slotCheckExpiryValue() 0129 { 0130 if (dlgAdv.kcfg_ExpiryTimeValue->text().isEmpty()) 0131 dlgAdv.kcfg_ExpiryTimeValue->setText(QString('1')); 0132 } 0133 0134 void PreferencesDialog::updateWidgetsDefault() 0135 { 0136 Q_EMIT resetDefaults(); 0137 KConfigDialog::updateWidgetsDefault(); 0138 } 0139 0140 #include "moc_preferencesdialog.cpp"