From ef3e54f6daebeeaa8d6e105a98711cb1760a637d Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 8 Oct 2016 17:06:13 +0200 Subject: [PATCH] dcc: Add settings page for DCC configuration --- src/qtui/mainwin.cpp | 2 + src/qtui/settingspages/dccsettingspage.cpp | 192 +++++++++++ src/qtui/settingspages/dccsettingspage.h | 90 +++++ src/qtui/settingspages/dccsettingspage.ui | 369 +++++++++++++++++++++ src/qtui/settingspages/settingspages.cmake | 1 + 5 files changed, 654 insertions(+) create mode 100644 src/qtui/settingspages/dccsettingspage.cpp create mode 100644 src/qtui/settingspages/dccsettingspage.h create mode 100644 src/qtui/settingspages/dccsettingspage.ui diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 3fc4cb96..cdaf51db 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -146,6 +146,7 @@ #include "settingspages/connectionsettingspage.h" #include "settingspages/coreaccountsettingspage.h" #include "settingspages/coreconnectionsettingspage.h" +#include "settingspages/dccsettingspage.h" #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" #include "settingspages/ignorelistsettingspage.h" @@ -1450,6 +1451,7 @@ void MainWin::showSettingsDlg() dlg->registerSettingsPage(new NetworksSettingsPage(dlg)); dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg)); + dlg->registerSettingsPage(new DccSettingsPage(dlg)); // Category: Remote Cores if (Quassel::runMode() != Quassel::Monolithic) { diff --git a/src/qtui/settingspages/dccsettingspage.cpp b/src/qtui/settingspages/dccsettingspage.cpp new file mode 100644 index 00000000..62fce35f --- /dev/null +++ b/src/qtui/settingspages/dccsettingspage.cpp @@ -0,0 +1,192 @@ +/*************************************************************************** + * Copyright (C) 2005-2016 by the Quassel Project * + * devel@quassel-irc.org * + * * + * 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 2 of the License, or * + * (at your option) version 3. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "dccsettingspage.h" + +#include "client.h" +#include "clienttransfermanager.h" + +DccSettingsPage::DccSettingsPage(QWidget *parent) + : SettingsPage(tr("IRC"), tr("DCC"), parent) +{ + ui.setupUi(this); + initAutoWidgets(); + connect(ui.ipDetectionMode, SIGNAL(currentIndexChanged(int)), SLOT(updateWidgetStates())); + connect(ui.portSelectionMode, SIGNAL(currentIndexChanged(int)), SLOT(updateWidgetStates())); + updateWidgetStates(); + + connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), SLOT(onClientConfigChanged())); + setClientConfig(Client::dccConfig()); +} + + +bool DccSettingsPage::isClientConfigValid() const +{ + return _clientConfig != nullptr; +} + + +void DccSettingsPage::setClientConfig(DccConfig *config) +{ + if (_clientConfig) { + disconnect(_clientConfig, 0, this, 0); + } + if (config && !isClientConfigValid()) { + qWarning() << "Client DCC config is not valid/synchronized!"; + _clientConfig = nullptr; + ui.dccEnabled->setEnabled(false); + return; + } + _clientConfig = config; + if (_clientConfig) { + connect(_clientConfig, SIGNAL(updated()), SLOT(load())); + load(); + ui.dccEnabled->setEnabled(true); + } + else { + ui.dccEnabled->setEnabled(false); + } +} + + +void DccSettingsPage::onClientConfigChanged() +{ + if (Client::isConnected() && Client::dccConfig() && !Client::dccConfig()->isInitialized()) { + connect(Client::dccConfig(), SIGNAL(initDone()), SLOT(onClientConfigChanged())); + } + else { + setClientConfig(Client::isConnected() ? Client::dccConfig() : nullptr); + } +} + + +bool DccSettingsPage::hasDefaults() const +{ + return true; +} + + +void DccSettingsPage::defaults() +{ + _localConfig = DccConfig(); + SettingsPage::load(); + widgetHasChanged(); +} + + +void DccSettingsPage::load() +{ + _localConfig = isClientConfigValid() ? *_clientConfig : DccConfig{}; + SettingsPage::load(); + widgetHasChanged(); +} + + +void DccSettingsPage::save() +{ + SettingsPage::save(); + if (isClientConfigValid()) { + Client::dccConfig()->requestUpdate(_localConfig.toVariantMap()); + } + setChangedState(false); +} + + +QVariant DccSettingsPage::loadAutoWidgetValue(const QString& widgetName) +{ + if (widgetName == "dccEnabled") + return _localConfig.isDccEnabled(); + if (widgetName == "ipDetectionMode") + // NOTE: Use mapping if item order differs from enum order + return static_cast(_localConfig.ipDetectionMode()); + if (widgetName == "portSelectionMode") + // NOTE: Use mapping if item order differs from enum order + return static_cast(_localConfig.portSelectionMode()); + if (widgetName == "minPort") + return _localConfig.minPort(); + if (widgetName == "maxPort") + return _localConfig.maxPort(); + if (widgetName == "chunkSize") + return _localConfig.chunkSize(); + if (widgetName == "sendTimeout") + return _localConfig.sendTimeout(); + if (widgetName == "usePassiveDcc") + return _localConfig.usePassiveDcc(); + if (widgetName == "useFastSend") + return _localConfig.useFastSend(); + if (widgetName == "outgoingIp") + return _localConfig.outgoingIp().toString(); + + qWarning() << "Unknown auto widget" << widgetName; + return {}; +} + + +void DccSettingsPage::saveAutoWidgetValue(const QString& widgetName, const QVariant& value) +{ + if (widgetName == "dccEnabled") + _localConfig.setDccEnabled(value.toBool()); + else if (widgetName == "ipDetectionMode") + // NOTE: Use mapping if item order differs from enum order + _localConfig.setIpDetectionMode(static_cast(value.toInt())); + else if (widgetName == "portSelectionMode") + // NOTE: Use mapping if item order differs from enum order + _localConfig.setPortSelectionMode(static_cast(value.toInt())); + else if (widgetName == "minPort") + _localConfig.setMinPort(value.toInt()); + else if (widgetName == "maxPort") + _localConfig.setMaxPort(value.toInt()); + else if (widgetName == "chunkSize") + _localConfig.setChunkSize(value.toInt()); + else if (widgetName == "sendTimeout") + _localConfig.setSendTimeout(value.toInt()); + else if (widgetName == "usePassiveDcc") + _localConfig.setUsePassiveDcc(value.toBool()); + else if (widgetName == "useFastSend") + _localConfig.setUseFastSend(value.toBool()); + else if (widgetName == "outgoingIp") { + QHostAddress address {QHostAddress::LocalHost}; + if (!address.setAddress(value.toString())) { + qWarning() << "Invalid IP address!"; + address = QHostAddress{QHostAddress::LocalHost}; + } + _localConfig.setOutgoingIp(std::move(address)); + } + else { + qWarning() << "Unknown auto widget" << widgetName; + } +} + + +void DccSettingsPage::widgetHasChanged() +{ + bool same = isClientConfigValid() && (_localConfig == *_clientConfig); + setChangedState(!same); +} + + +void DccSettingsPage::updateWidgetStates() +{ + ui.outgoingIp->setEnabled(ui.ipDetectionMode->currentIndex() != 0); + bool enablePorts = ui.portSelectionMode->currentIndex() != 0; + ui.minPort->setEnabled(enablePorts); + ui.maxPort->setEnabled(enablePorts); + ui.portsToLabel->setEnabled(enablePorts); +} diff --git a/src/qtui/settingspages/dccsettingspage.h b/src/qtui/settingspages/dccsettingspage.h new file mode 100644 index 00000000..b5fabbc8 --- /dev/null +++ b/src/qtui/settingspages/dccsettingspage.h @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2005-2016 by the Quassel Project * + * devel@quassel-irc.org * + * * + * 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 2 of the License, or * + * (at your option) version 3. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#pragma once + +#include "dccconfig.h" +#include "settingspage.h" +#include "ui_dccsettingspage.h" + +/** + * A settingspage for configuring DCC. + */ +class DccSettingsPage : public SettingsPage +{ + Q_OBJECT + +public: + /** + * Constructor. + * + * @param[in] parent QObject parent + */ + DccSettingsPage(QWidget *parent = nullptr); + + /// See base class docs + bool hasDefaults() const override; + +public slots: + // See base class docs + void save() override; + void load() override; + void defaults() override; + +private: + /** + * Whether the client's DccConfig is valid + * + * @returns true if the client is connected and its DccConfig instance synchronized + */ + bool isClientConfigValid() const; + + /** + * Set the client config + * + * @param[in] config The client's config. Must be be valid or a nullptr. + */ + void setClientConfig(DccConfig *config); + + // See base class docs + QVariant loadAutoWidgetValue(const QString &widgetName) override; + void saveAutoWidgetValue(const QString &widgetName, const QVariant &value) override; + +private slots: + /** + * Updates the enabled state according to the current config. + */ + void updateWidgetStates(); + + /** + * Checks if the current unsaved config differs from the client's and sets state accordingly. + */ + void widgetHasChanged(); + + /** + * Called if the client's config was changed (e.g. if the connection state changed). + */ + void onClientConfigChanged(); + +private: + Ui::DccSettingsPage ui; ///< The UI object + DccConfig *_clientConfig {nullptr}; ///< Pointer to the client's config (nullptr if not synchronized/available) + DccConfig _localConfig; ///< Local config reflecting the widget states +}; diff --git a/src/qtui/settingspages/dccsettingspage.ui b/src/qtui/settingspages/dccsettingspage.ui new file mode 100644 index 00000000..acd5a9dd --- /dev/null +++ b/src/qtui/settingspages/dccsettingspage.ui @@ -0,0 +1,369 @@ + + + DccSettingsPage + + + + 0 + 0 + 736 + 559 + + + + Form + + + + + + Enable DCC + + + true + + + + + + false + + + + + + + + Ports: + + + + + + + + + + 0 + + + + Automatic + + + + + Manual + + + + + + + + + + 1024 + + + 65535 + + + + + + 1024 + + + + + + + to + + + + + + + 1024 + + + 65535 + + + 65535 + + + + + + 32767 + + + + + + + + + Outgoing IP: + + + + + + + + + + localhost + + + + + + + + + + 0 + + + + Automatic + + + + + Manual + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + DCC send timeout: + + + + + + + seconds + + + 10 + + + 3600 + + + 10 + + + 180 + + + + + + 180 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Chunk size: + + + + + + + KiB + + + + + + 1 + + + 1024 + + + 16 + + + 16 + + + + + + 16 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Use passive/reverse DCC + + + + + + false + + + + + + + Use fast sending (might not work with all peers) + + + + + + false + + + + + + + + + + false + + + File transfers + + + + + + + + Default download folder: + + + + + + + + + + ... + + + + + + + + + Create folder per sender + + + + + + + Prefix filenames with sender + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ipDetectionMode + outgoingIp + portSelectionMode + minPort + maxPort + sendTimeout + chunkSize + usePassiveDcc + useFastSend + downloadPath + browseButton + createSenderDirectory + prefixFilenames + dccEnabled + + + + diff --git a/src/qtui/settingspages/settingspages.cmake b/src/qtui/settingspages/settingspages.cmake index c2705cbc..e0612410 100644 --- a/src/qtui/settingspages/settingspages.cmake +++ b/src/qtui/settingspages/settingspages.cmake @@ -12,6 +12,7 @@ set(SETTINGSPAGES connection coreconnection coreaccount + dcc highlight identities ignorelist -- 2.20.1