cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / settingspages / coreaccountsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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 #ifndef COREACCOUNTSETTINGSPAGE_H_
22 #define COREACCOUNTSETTINGSPAGE_H_
23
24 #include <QNetworkProxy>
25 #include <QSortFilterProxyModel>
26
27 #include "coreaccount.h"
28 #include "settingspage.h"
29
30 #include "ui_coreaccounteditdlg.h"
31 #include "ui_coreaccountsettingspage.h"
32
33 class CoreAccountModel;
34 class FilteredCoreAccountModel;
35
36 class CoreAccountSettingsPage : public SettingsPage
37 {
38     Q_OBJECT
39
40 public:
41     CoreAccountSettingsPage(QWidget* parent = nullptr);
42
43     inline bool hasDefaults() const override { return false; }
44     inline bool isStandAlone() const { return _standalone; }
45
46     AccountId selectedAccount() const;
47
48 public slots:
49     void save() override;
50     void load() override;
51
52     void setSelectedAccount(AccountId accId);
53     void setStandAlone(bool);
54
55 signals:
56     void connectToCore(AccountId accId);
57
58 private slots:
59     void on_addAccountButton_clicked();
60     void on_editAccountButton_clicked();
61     void on_deleteAccountButton_clicked();
62     void on_accountView_doubleClicked(const QModelIndex& index);
63
64     void setWidgetStates();
65     void widgetHasChanged();
66
67     void rowsAboutToBeRemoved(const QModelIndex& index, int start, int end);
68     void rowsInserted(const QModelIndex& index, int start, int end);
69
70 private:
71     Ui::CoreAccountSettingsPage ui;
72
73     CoreAccountModel* _model;
74     inline CoreAccountModel* model() const { return _model; }
75     FilteredCoreAccountModel* _filteredModel;
76     inline FilteredCoreAccountModel* filteredModel() const { return _filteredModel; }
77
78     AccountId _lastAccountId, _lastAutoConnectId;
79     bool _standalone{false};
80
81     void editAccount(const QModelIndex&);
82
83     bool testHasChanged();
84
85     inline QString settingsKey() const override { return QString("CoreAccounts"); }
86 };
87
88 // ========================================
89 //  CoreAccountEditDlg
90 // ========================================
91 class CoreAccountEditDlg : public QDialog
92 {
93     Q_OBJECT
94
95 public:
96     CoreAccountEditDlg(const CoreAccount& account, QWidget* parent = nullptr);
97
98     CoreAccount account();
99
100 private slots:
101     void on_hostName_textChanged(const QString&);
102     void on_accountName_textChanged(const QString&);
103     void on_user_textChanged(const QString&);
104     void on_radioButtonManualProxy_toggled(bool checked);
105
106     void setWidgetStates();
107
108 private:
109     Ui::CoreAccountEditDlg ui;
110     CoreAccount _account;
111     enum ProxyType
112     {
113         NoProxy,
114         SystemProxy,
115         ManualProxy
116     };
117 };
118
119 // ========================================
120 //  FilteredCoreAccountModel
121 // ========================================
122
123 //! This filters out the internal account from the non-monolithic client's UI
124 class FilteredCoreAccountModel : public QSortFilterProxyModel
125 {
126     Q_OBJECT
127
128 public:
129     FilteredCoreAccountModel(CoreAccountModel* model, QObject* parent = nullptr);
130
131 protected:
132     bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
133
134 private:
135     AccountId _internalAccount;
136 };
137
138 #endif