summaryrefslogtreecommitdiff
path: root/TelepathyQt4Yell/Models/accounts-model.h
blob: 1020ee512305769f8ec19bd5f7cb689bfecf3d96 (plain)
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
135
136
137
138
139
140
/*
 * This file is part of TelepathyQt4Yell Models
 *
 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_
#define _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_

#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER
#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER
#endif

#include <TelepathyQt4Yell/Models/AccountsModelItem>

#include <TelepathyQt4/Account>
#include <TelepathyQt4/AccountManager>
#include <TelepathyQt4/TextChannel>
#include <TelepathyQt4/Types>

#include <QAbstractListModel>

namespace Tpy
{

class TELEPATHY_QT4_YELL_MODELS_EXPORT AccountsModel : public QAbstractItemModel
{
    Q_OBJECT
    Q_DISABLE_COPY(AccountsModel)
    Q_PROPERTY(int accountCount READ accountCount NOTIFY accountCountChanged)
    Q_ENUMS(Role)

public:
    enum Role {
        // general roles
        ItemRole = Qt::UserRole,
        AvatarRole,
        IdRole,

        // account roles
        ValidRole,
        EnabledRole,
        ConnectionManagerNameRole,
        ProtocolNameRole,
        DisplayNameRole,
        IconRole,
        NicknameRole,
        ConnectsAutomaticallyRole,
        ChangingPresenceRole,
        AutomaticPresenceRole,
        AutomaticPresenceTypeRole,
        AutomaticPresenceStatusMessageRole,
        CurrentPresenceRole,
        CurrentPresenceTypeRole,
        CurrentPresenceStatusMessageRole,
        RequestedPresenceRole,
        RequestedPresenceTypeRole,
        RequestedPresenceStatusMessageRole,
        ConnectionStatusRole,
        ConnectionStatusReasonRole,
        ContactListStateRole,

        // contact roles
        AliasRole,
        PresenceStatusRole,
        PresenceTypeRole,
        PresenceMessageRole,
        SubscriptionStateRole,
        PublishStateRole,
        BlockedRole,
        GroupsRole,
        TextChatCapabilityRole,
        StreamedMediaCallCapabilityRole,
        StreamedMediaAudioCallCapabilityRole,
        StreamedMediaVideoCallCapabilityRole,
        StreamedMediaVideoCallWithAudioCapabilityRole,
        StreamedMediaUpgradeCallCapabilityRole,
        MediaCallCapabilityRole,
        AudioCallCapabilityRole,
        VideoCallCapabilityRole,
        VideoCallWithAudioCapabilityRole,
        UpgradeCallCapabilityRole,
        FileTransferCapabilityRole,

        CustomRole // a placemark for custom roles in inherited models
    };

    explicit AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent = 0);
    virtual ~AccountsModel();

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    Tp::AccountPtr accountForIndex(const QModelIndex &index) const;
    Tp::AccountPtr accountForContactIndex(const QModelIndex &index) const;
    Tp::ContactPtr contactForIndex(const QModelIndex &index) const;

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
    virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
    virtual QModelIndex index(TreeNode *node) const;
    virtual QModelIndex parent(const QModelIndex &index) const;

    int accountCount() const;
    Q_INVOKABLE QObject *accountItemForId(const QString &id) const;
    Q_INVOKABLE QObject *contactItemForId(const QString &accountId, const QString &contactId) const;

Q_SIGNALS:
    void accountCountChanged();
    void accountConnectionStatusChanged(const QString &accountId, int status);

protected Q_SLOTS:
    void onNewAccount(const Tp::AccountPtr &account);
    void onItemChanged(TreeNode *node);
    void onItemsAdded(TreeNode *parent, const QList<TreeNode *> &nodes);
    void onItemsRemoved(TreeNode *parent, int first, int last);

private:
    struct Private;
    friend struct Private;
    Private *mPriv;
};

}

#endif // _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_