common: Make SyncableObject non-copyable
[quassel.git] / src / qtui / settingspages / dccsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "dccconfig.h"
24 #include "settingspage.h"
25
26 #include "ui_dccsettingspage.h"
27
28 /**
29  * A settingspage for configuring DCC.
30  */
31 class DccSettingsPage : public SettingsPage
32 {
33     Q_OBJECT
34
35 public:
36     /**
37      * Constructor.
38      *
39      * @param[in] parent QObject parent
40      */
41     DccSettingsPage(QWidget* parent = nullptr);
42
43     /// See base class docs
44     bool hasDefaults() const override;
45
46 public slots:
47     // See base class docs
48     void save() final override;
49     void load() final override;
50     void defaults() final override;
51
52 private:
53     /**
54      * Whether the client's DccConfig is valid
55      *
56      * @returns true if the client is connected and its DccConfig instance synchronized
57      */
58     bool isClientConfigValid() const;
59
60     /**
61      * Set the client config
62      *
63      * @param[in] config The client's config. Must be be valid or a nullptr.
64      */
65     void setClientConfig(DccConfig* config);
66
67     // See base class docs
68     QVariant loadAutoWidgetValue(const QString& widgetName) override;
69     void saveAutoWidgetValue(const QString& widgetName, const QVariant& value) override;
70
71 private slots:
72     /**
73      * Updates the enabled state according to the current config.
74      */
75     void updateWidgetStates();
76
77     /**
78      * Checks if the current unsaved config differs from the client's and sets state accordingly.
79      */
80     void widgetHasChanged();
81
82     /**
83      * Called if the client's config was changed (e.g. if the connection state changed).
84      */
85     void onClientConfigChanged();
86
87 private:
88     Ui::DccSettingsPage ui;             ///< The UI object
89     DccConfig* _clientConfig{nullptr};  ///< Pointer to the client's config (nullptr if not synchronized/available)
90     DccConfig _localConfig;             ///< Local config reflecting the widget states
91 };