Event backend porting
[quassel.git] / src / client / coreaccountmodel.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 COREACCOUNTMODEL_H_
22 #define COREACCOUNTMODEL_H_
23
24 #include <QAbstractListModel>
25 #include <QUuid>
26
27 #include "coreaccount.h"
28
29 class CoreAccountModel : public QAbstractListModel {
30   Q_OBJECT
31
32 public:
33   enum {
34     AccountIdRole = Qt::UserRole,
35     UuidRole
36   };
37
38   CoreAccountModel(QObject *parent = 0);
39   CoreAccountModel(const CoreAccountModel *other, QObject *parent = 0);
40
41   inline int rowCount(const QModelIndex &parent = QModelIndex()) const;
42   virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
43
44   CoreAccount account(const QModelIndex &) const;
45   CoreAccount account(AccountId) const;
46   QList<CoreAccount> accounts() const;
47   QList<AccountId> accountIds() const;
48   QModelIndex accountIndex(AccountId id) const;
49
50   inline AccountId internalAccount() const;
51
52   AccountId createOrUpdateAccount(const CoreAccount &newAccountData = CoreAccount());
53   CoreAccount takeAccount(AccountId);
54   void removeAccount(AccountId);
55
56   void update(const CoreAccountModel *other);
57
58   bool operator==(const CoreAccountModel &other) const;
59
60 public slots:
61   void save();
62   void load();
63   void clear();
64
65 protected:
66   void insertAccount(const CoreAccount &);
67   int findAccountIdx(AccountId) const;
68
69 private:
70   int listIndex(AccountId);
71
72   QList<CoreAccount> _accounts;
73   QSet<AccountId> _removedAccounts;
74   AccountId _internalAccount;
75 };
76
77 // Inlines
78 int CoreAccountModel::rowCount(const QModelIndex &) const {
79   return _accounts.count();
80 }
81
82 AccountId CoreAccountModel::internalAccount() const {
83   return _internalAccount;
84 }
85
86 #endif