some UI changes for usability
[makneto-zunavac1.git] / src / backend / accounts-model.h
blob0eda36f8ec4c040d78e1fe8a93eb3744ab431f22
1 /*
2 * Accounts and contacts model
3 * This file is based on TelepathyQt4Yell Models
5 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
6 * Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef TELEPATHY_ACCOUNTS_MODEL_H
24 #define TELEPATHY_ACCOUNTS_MODEL_H
26 #include <QAbstractListModel>
28 #include <TelepathyQt4/Account>
29 #include <TelepathyQt4/AccountManager>
30 #include <TelepathyQt4/TextChannel>
31 #include <TelepathyQt4/Types>
33 #include "accounts-model-item.h"
34 #include "makneto-backend.h"
37 namespace MaknetoBackend {
39 class MAKNETO_EXPORT AccountsModel : public QAbstractItemModel {
41 Q_OBJECT
42 Q_DISABLE_COPY(AccountsModel)
43 Q_PROPERTY(int accountCount READ accountCount NOTIFY accountCountChanged)
44 Q_ENUMS(Role)
46 public:
47 enum Role {
48 // general roles
49 ItemRole = Qt::UserRole,
50 AvatarRole,
51 IdRole,
53 // account roles
54 ValidRole,
55 EnabledRole,
56 ConnectionManagerNameRole,
57 ProtocolNameRole,
58 DisplayNameRole,
59 IconRole,
60 NicknameRole,
61 ConnectsAutomaticallyRole,
62 ChangingPresenceRole,
63 AutomaticPresenceRole,
64 AutomaticPresenceTypeRole,
65 AutomaticPresenceStatusMessageRole,
66 CurrentPresenceRole,
67 CurrentPresenceTypeRole,
68 CurrentPresenceStatusMessageRole,
69 RequestedPresenceRole,
70 RequestedPresenceTypeRole,
71 RequestedPresenceStatusMessageRole,
72 ConnectionStatusRole,
73 ConnectionStatusReasonRole,
75 // contact roles
76 ManagerIdRole,
77 AliasRole,
78 PresenceStatusRole,
79 PresenceTypeRole,
80 PresenceMessageRole,
81 SubscriptionStateRole,
82 PublishStateRole,
83 BlockedRole,
84 GroupsRole,
85 TextChatCapabilityRole,
86 MediaCallCapabilityRole,
87 AudioCallCapabilityRole,
88 VideoCallCapabilityRole,
89 UpgradeCallCapabilityRole,
90 FileTransferCapabilityRole,
92 CustomRole // a placemark for custom roles in inherited models
95 explicit AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent = 0);
96 virtual ~AccountsModel();
98 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
99 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
100 virtual QVariant data(const QModelIndex &index, int role) const;
101 Q_INVOKABLE QVariant data(int row, int role); // ivokable, for QML
102 Tp::AccountPtr accountForIndex(const QModelIndex &index) const;
103 Tp::ContactPtr contactForIndex(const QModelIndex &index) const;
105 Tp::AccountPtr accountForContactIndex(const QModelIndex &index) const;
107 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
108 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
109 virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
110 virtual QModelIndex index(TreeNode *node) const;
111 virtual QModelIndex parent(const QModelIndex &index) const;
113 int accountCount() const;
114 Q_INVOKABLE QObject *accountItemForId(const QString &id) const;
115 Q_INVOKABLE QObject *contactItemForId(const QString &accountId, const QString &contactId) const;
116 Q_INVOKABLE QModelIndex contactIndexForId(const QString &accountId, const QString &contactId) const;
118 Q_SIGNALS:
119 void accountCountChanged();
120 void accountConnectionStatusChanged(const Tp::AccountPtr &account, Tp::ConnectionStatus status);
122 public
123 Q_SLOTS:
124 void onNewAccount(const Tp::AccountPtr &account);
125 void onItemChanged(TreeNode *node);
126 void onItemsAdded(TreeNode *parent, const QList<TreeNode *> &nodes);
127 void onItemsRemoved(TreeNode *parent, int first, int last);
129 private:
130 struct Private;
131 friend struct Private;
132 Private *mPriv;
137 #endif // TELEPATHY_ACCOUNTS_MODEL_H