File indexing completed on 2024-05-12 15:41:57
0001 0002 // Own 0003 #include "netpref.h" 0004 0005 // Qt 0006 #include <QCheckBox> 0007 #include <QFormLayout> 0008 #include <QGroupBox> 0009 0010 // KDE 0011 #include <KConfig> 0012 #include <KConfigGroup> 0013 #include <KLocalizedString> 0014 #include <KPluginFactory> 0015 #include <KPluralHandlingSpinBox> 0016 #include <ioworker_defaults.h> 0017 0018 // Local 0019 #include "../ksaveioconfig.h" 0020 0021 static constexpr int s_maxTimeoutValue = 3600; 0022 0023 K_PLUGIN_CLASS_WITH_JSON(KIOPreferences, "netpref.json") 0024 0025 KIOPreferences::KIOPreferences(QWidget *parent, const QVariantList &) 0026 : KCModule(parent) 0027 { 0028 QVBoxLayout *mainLayout = new QVBoxLayout(this); 0029 mainLayout->setContentsMargins(0, 0, 0, 0); 0030 gb_Timeout = new QGroupBox(i18n("Timeout Values"), this); 0031 gb_Timeout->setWhatsThis( 0032 i18np("Here you can set timeout values. " 0033 "You might want to tweak them if your " 0034 "connection is very slow. The maximum " 0035 "allowed value is 1 second.", 0036 "Here you can set timeout values. " 0037 "You might want to tweak them if your " 0038 "connection is very slow. The maximum " 0039 "allowed value is %1 seconds.", 0040 s_maxTimeoutValue)); 0041 mainLayout->addWidget(gb_Timeout); 0042 0043 QFormLayout *timeoutLayout = new QFormLayout(gb_Timeout); 0044 sb_socketRead = new KPluralHandlingSpinBox(this); 0045 sb_socketRead->setSuffix(ki18np(" second", " seconds")); 0046 connect(sb_socketRead, qOverload<int>(&QSpinBox::valueChanged), this, &KIOPreferences::configChanged); 0047 timeoutLayout->addRow(i18n("Soc&ket read:"), sb_socketRead); 0048 0049 sb_proxyConnect = new KPluralHandlingSpinBox(this); 0050 sb_proxyConnect->setValue(0); 0051 sb_proxyConnect->setSuffix(ki18np(" second", " seconds")); 0052 connect(sb_proxyConnect, qOverload<int>(&QSpinBox::valueChanged), this, &KIOPreferences::configChanged); 0053 timeoutLayout->addRow(i18n("Pro&xy connect:"), sb_proxyConnect); 0054 0055 sb_serverConnect = new KPluralHandlingSpinBox(this); 0056 sb_serverConnect->setValue(0); 0057 sb_serverConnect->setSuffix(ki18np(" second", " seconds")); 0058 connect(sb_serverConnect, qOverload<int>(&QSpinBox::valueChanged), this, &KIOPreferences::configChanged); 0059 timeoutLayout->addRow(i18n("Server co&nnect:"), sb_serverConnect); 0060 0061 sb_serverResponse = new KPluralHandlingSpinBox(this); 0062 sb_serverResponse->setValue(0); 0063 sb_serverResponse->setSuffix(ki18np(" second", " seconds")); 0064 connect(sb_serverResponse, qOverload<int>(&QSpinBox::valueChanged), this, &KIOPreferences::configChanged); 0065 timeoutLayout->addRow(i18n("&Server response:"), sb_serverResponse); 0066 0067 QGroupBox *gb_Global = new QGroupBox(i18n("Global Options"), this); 0068 mainLayout->addWidget(gb_Global); 0069 QVBoxLayout *globalLayout = new QVBoxLayout(gb_Global); 0070 0071 cb_globalMarkPartial = new QCheckBox(i18n("Mark &partially uploaded files"), this); 0072 cb_globalMarkPartial->setWhatsThis( 0073 i18n("<p>Marks partially uploaded files " 0074 "through SMB, SFTP and other protocols." 0075 "</p><p>When this option is " 0076 "enabled, partially uploaded files " 0077 "will have a \".part\" extension. " 0078 "This extension will be removed " 0079 "once the transfer is complete.</p>")); 0080 connect(cb_globalMarkPartial, &QAbstractButton::toggled, this, &KIOPreferences::configChanged); 0081 globalLayout->addWidget(cb_globalMarkPartial); 0082 0083 auto partialWidget = new QWidget(this); 0084 connect(cb_globalMarkPartial, &QAbstractButton::toggled, partialWidget, &QWidget::setEnabled); 0085 globalLayout->addWidget(partialWidget); 0086 auto partialLayout = new QFormLayout(partialWidget); 0087 partialLayout->setContentsMargins(20, 0, 0, 0); // indent below mark partial 0088 0089 sb_globalMinimumKeepSize = new KPluralHandlingSpinBox(this); 0090 sb_globalMinimumKeepSize->setSuffix(ki18np(" byte", " bytes")); 0091 connect(sb_globalMinimumKeepSize, qOverload<int>(&QSpinBox::valueChanged), this, &KIOPreferences::configChanged); 0092 partialLayout->addRow(i18nc("@label:spinbox", "If cancelled, automatically delete partially uploaded files smaller than:"), sb_globalMinimumKeepSize); 0093 0094 gb_Ftp = new QGroupBox(i18n("FTP Options"), this); 0095 mainLayout->addWidget(gb_Ftp); 0096 QVBoxLayout *ftpLayout = new QVBoxLayout(gb_Ftp); 0097 0098 cb_ftpEnablePasv = new QCheckBox(i18n("Enable passive &mode (PASV)"), this); 0099 cb_ftpEnablePasv->setWhatsThis( 0100 i18n("Enables FTP's \"passive\" mode. " 0101 "This is required to allow FTP to " 0102 "work from behind firewalls.")); 0103 connect(cb_ftpEnablePasv, &QAbstractButton::toggled, this, &KIOPreferences::configChanged); 0104 ftpLayout->addWidget(cb_ftpEnablePasv); 0105 0106 cb_ftpMarkPartial = new QCheckBox(i18n("Mark &partially uploaded files"), this); 0107 cb_ftpMarkPartial->setWhatsThis( 0108 i18n("<p>Marks partially uploaded FTP " 0109 "files.</p><p>When this option is " 0110 "enabled, partially uploaded files " 0111 "will have a \".part\" extension. " 0112 "This extension will be removed " 0113 "once the transfer is complete.</p>")); 0114 connect(cb_ftpMarkPartial, &QAbstractButton::toggled, this, &KIOPreferences::configChanged); 0115 ftpLayout->addWidget(cb_ftpMarkPartial); 0116 0117 mainLayout->addStretch(1); 0118 } 0119 0120 KIOPreferences::~KIOPreferences() 0121 { 0122 } 0123 0124 void KIOPreferences::load() 0125 { 0126 KProtocolManager proto; 0127 0128 sb_socketRead->setRange(MIN_TIMEOUT_VALUE, s_maxTimeoutValue); 0129 sb_serverResponse->setRange(MIN_TIMEOUT_VALUE, s_maxTimeoutValue); 0130 sb_serverConnect->setRange(MIN_TIMEOUT_VALUE, s_maxTimeoutValue); 0131 sb_proxyConnect->setRange(MIN_TIMEOUT_VALUE, s_maxTimeoutValue); 0132 0133 sb_socketRead->setValue(proto.readTimeout()); 0134 sb_serverResponse->setValue(proto.responseTimeout()); 0135 sb_serverConnect->setValue(proto.connectTimeout()); 0136 sb_proxyConnect->setValue(proto.proxyConnectTimeout()); 0137 0138 cb_globalMarkPartial->setChecked(proto.markPartial()); 0139 sb_globalMinimumKeepSize->setRange(0, 1024 * 1024 * 1024 /* 1 GiB */); 0140 sb_globalMinimumKeepSize->setValue(proto.minimumKeepSize()); 0141 0142 KConfig config(QStringLiteral("kio_ftprc"), KConfig::NoGlobals); 0143 cb_ftpEnablePasv->setChecked(!config.group("").readEntry("DisablePassiveMode", false)); 0144 cb_ftpMarkPartial->setChecked(config.group("").readEntry("MarkPartial", true)); 0145 Q_EMIT changed(false); 0146 } 0147 0148 void KIOPreferences::save() 0149 { 0150 KSaveIOConfig::setReadTimeout(sb_socketRead->value()); 0151 KSaveIOConfig::setResponseTimeout(sb_serverResponse->value()); 0152 KSaveIOConfig::setConnectTimeout(sb_serverConnect->value()); 0153 KSaveIOConfig::setProxyConnectTimeout(sb_proxyConnect->value()); 0154 0155 KSaveIOConfig::setMarkPartial(cb_globalMarkPartial->isChecked()); 0156 KSaveIOConfig::setMinimumKeepSize(sb_globalMinimumKeepSize->value()); 0157 0158 KConfig config(QStringLiteral("kio_ftprc"), KConfig::NoGlobals); 0159 config.group("").writeEntry("DisablePassiveMode", !cb_ftpEnablePasv->isChecked()); 0160 config.group("").writeEntry("MarkPartial", cb_ftpMarkPartial->isChecked()); 0161 config.sync(); 0162 0163 KSaveIOConfig::updateRunningWorkers(this); 0164 0165 Q_EMIT changed(false); 0166 } 0167 0168 void KIOPreferences::defaults() 0169 { 0170 sb_socketRead->setValue(DEFAULT_READ_TIMEOUT); 0171 sb_serverResponse->setValue(DEFAULT_RESPONSE_TIMEOUT); 0172 sb_serverConnect->setValue(DEFAULT_CONNECT_TIMEOUT); 0173 sb_proxyConnect->setValue(DEFAULT_PROXY_CONNECT_TIMEOUT); 0174 0175 cb_globalMarkPartial->setChecked(true); 0176 0177 cb_ftpEnablePasv->setChecked(true); 0178 cb_ftpMarkPartial->setChecked(true); 0179 0180 Q_EMIT changed(true); 0181 } 0182 0183 QString KIOPreferences::quickHelp() const 0184 { 0185 return i18n( 0186 "<h1>Network Preferences</h1>Here you can define" 0187 " the behavior of KDE programs when using Internet" 0188 " and network connections. If you experience timeouts" 0189 " or use a modem to connect to the Internet, you might" 0190 " want to adjust these settings."); 0191 } 0192 0193 #include "moc_netpref.cpp" 0194 #include "netpref.moc"