6948e85a823f8811c858b82faf9bb2a4f0ce4e7a
[quassel.git] / src / qtui / settingspages / coreaccountsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2009 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef COREACCOUNTSETTINGSPAGE_H_
22 #define COREACCOUNTSETTINGSPAGE_H_
23
24 #include "settingspage.h"
25
26 #include "coreaccount.h"
27
28 #include "ui_coreaccounteditdlg.h"
29 #include "ui_coreaccountsettingspage.h"
30
31 class CoreAccountModel;
32
33 class CoreAccountSettingsPage : public SettingsPage {
34   Q_OBJECT
35
36   public:
37     CoreAccountSettingsPage(QWidget *parent = 0);
38
39     inline bool hasDefaults() const { return false; }
40     inline bool isStandAlone() const { return _standalone; }
41
42     AccountId selectedAccount() const;
43
44   public slots:
45     void save();
46     void load();
47
48     void setSelectedAccount(AccountId accId);
49     void setStandAlone(bool);
50
51 signals:
52     void connectToCore(AccountId accId);
53
54   private slots:
55     void on_addAccountButton_clicked();
56     void on_editAccountButton_clicked();
57     void on_deleteAccountButton_clicked();
58     void on_accountView_doubleClicked(const QModelIndex &index);
59
60     void setWidgetStates();
61
62     void rowsAboutToBeRemoved(const QModelIndex &index, int start, int end);
63     void rowsInserted(const QModelIndex &index, int start, int end);
64
65   private:
66     Ui::CoreAccountSettingsPage ui;
67
68     CoreAccountModel *_model;
69     inline CoreAccountModel *model() const { return _model; }
70
71     AccountId _lastAccountId, _lastAutoConnectId;
72     bool _standalone;
73
74     virtual QVariant loadAutoWidgetValue(const QString &widgetName);
75     virtual void saveAutoWidgetValue(const QString &widgetName, const QVariant &value);
76
77     void editAccount(const QModelIndex &);
78
79     void widgetHasChanged();
80     bool testHasChanged();
81
82     inline QString settingsKey() const { return QString("CoreAccounts"); }
83 };
84
85 // ========================================
86 //  CoreAccountEditDlg
87 // ========================================
88 class CoreAccountEditDlg : public QDialog {
89   Q_OBJECT
90
91 public:
92   CoreAccountEditDlg(const CoreAccount &account, QWidget *parent = 0);
93
94   CoreAccount account();
95
96 private slots:
97   void on_hostName_textChanged(const QString &);
98   void on_accountName_textChanged(const QString &);
99   void on_user_textChanged(const QString &);
100
101   void setWidgetStates();
102
103 private:
104   Ui::CoreAccountEditDlg ui;
105   CoreAccount _account;
106 };
107
108 #endif