~ubuntu-branches/ubuntu/trusty/quassel/trusty-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
 *   Copyright (C) 2005-2014 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.         *
 ***************************************************************************/

#ifndef COREACCOUNTSETTINGSPAGE_H_
#define COREACCOUNTSETTINGSPAGE_H_

#include <QSortFilterProxyModel>

#include "settingspage.h"

#include "coreaccount.h"

#include "ui_coreaccounteditdlg.h"
#include "ui_coreaccountsettingspage.h"

class CoreAccountModel;
class FilteredCoreAccountModel;

class CoreAccountSettingsPage : public SettingsPage
{
    Q_OBJECT

public:
    CoreAccountSettingsPage(QWidget *parent = 0);

    inline bool hasDefaults() const { return false; }
    inline bool isStandAlone() const { return _standalone; }

    AccountId selectedAccount() const;

public slots:
    void save();
    void load();

    void setSelectedAccount(AccountId accId);
    void setStandAlone(bool);

signals:
    void connectToCore(AccountId accId);

private slots:
    void on_addAccountButton_clicked();
    void on_editAccountButton_clicked();
    void on_deleteAccountButton_clicked();
    void on_accountView_doubleClicked(const QModelIndex &index);

    void setWidgetStates();
    void widgetHasChanged();

    void rowsAboutToBeRemoved(const QModelIndex &index, int start, int end);
    void rowsInserted(const QModelIndex &index, int start, int end);

private:
    Ui::CoreAccountSettingsPage ui;

    CoreAccountModel *_model;
    inline CoreAccountModel *model() const { return _model; }
    FilteredCoreAccountModel *_filteredModel;
    inline FilteredCoreAccountModel *filteredModel() const { return _filteredModel; }

    AccountId _lastAccountId, _lastAutoConnectId;
    bool _standalone;

    void editAccount(const QModelIndex &);

    bool testHasChanged();

    inline QString settingsKey() const { return QString("CoreAccounts"); }
};


// ========================================
//  CoreAccountEditDlg
// ========================================
class CoreAccountEditDlg : public QDialog
{
    Q_OBJECT

public:
    CoreAccountEditDlg(const CoreAccount &account, QWidget *parent = 0);

    CoreAccount account();

private slots:
    void on_hostName_textChanged(const QString &);
    void on_accountName_textChanged(const QString &);
    void on_user_textChanged(const QString &);

    void setWidgetStates();

private:
    Ui::CoreAccountEditDlg ui;
    CoreAccount _account;
};


// ========================================
//  FilteredCoreAccountModel
// ========================================

//! This filters out the internal account from the non-monolithic client's UI
class FilteredCoreAccountModel : public QSortFilterProxyModel
{
    Q_OBJECT

public:
    FilteredCoreAccountModel(CoreAccountModel *model, QObject *parent = 0);

protected:
    virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;

private:
    AccountId _internalAccount;
};


#endif