2 ChatSessionMembersListModel
4 Copyright (c) 2007 by Duncan Mac-Vicar Prett <duncan@kde.org>
6 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
15 *************************************************************************
18 #include "kopetecontact.h"
19 #include "kopeteonlinestatus.h"
20 #include "chatsessionmemberslistmodel.h"
25 ChatSessionMembersListModel::ChatSessionMembersListModel(QObject
* parent
)
26 : QAbstractListModel(parent
), m_session(0L)
31 void ChatSessionMembersListModel::setChatSession(ChatSession
*session
)
34 disconnect( m_session
, 0, this, 0 );
38 connect( session
, SIGNAL(closing(Kopete::ChatSession
*)),
39 this, SLOT(slotSessionClosed()) );
40 connect( session
, SIGNAL(contactAdded(const Kopete::Contact
*, bool)),
41 this, SLOT(slotContactAdded(const Kopete::Contact
*)) );
42 connect( session
, SIGNAL(contactRemoved(const Kopete::Contact
*, const QString
&, Qt::TextFormat
, bool)),
43 this, SLOT(slotContactRemoved(const Kopete::Contact
*)) );
44 connect( session
, SIGNAL(onlineStatusChanged(Kopete::Contact
*, const Kopete::OnlineStatus
&, const Kopete::OnlineStatus
&)),
45 this, SLOT(slotContactStatusChanged(Kopete::Contact
*, const Kopete::OnlineStatus
&)) );
46 connect( session
, SIGNAL(displayNameChanged()),
47 this, SLOT(slotSessionChanged()) );
48 connect( session
, SIGNAL(photoChanged()),
49 this, SLOT(slotSessionChanged()) );
53 Kopete::Contact
* ChatSessionMembersListModel::contactAt( const QModelIndex
&index
) const
60 if (index
.row() >= m_session
->members().size() + 1)
63 if ( index
.row() == 0 )
64 return const_cast<Kopete::Contact
*>(m_session
->myself());
66 return m_session
->members().at(index
.row() - 1);
72 int ChatSessionMembersListModel::rowCount(const QModelIndex
&parent
) const
76 return m_session
->members().count() + 1;
81 QVariant
ChatSessionMembersListModel::data(const QModelIndex
&index
, int role
) const
83 Contact
*c
= contactAt(index
);
87 if (role
== Qt::DisplayRole
)
89 QString nick
= c
->property(Kopete::Global::Properties::self()->nickName().key()).value().toString();
91 nick
= c
->contactId();
95 else if (role
== Qt::DecorationRole
)
97 return m_session
->contactOnlineStatus(c
).iconFor(c
);
99 else if (role
== Qt::ToolTipRole
)
107 QVariant
ChatSessionMembersListModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
109 if (role
!= Qt::DisplayRole
)
112 if (orientation
== Qt::Horizontal
)
113 return QString("Column %1").arg(section
);
115 return QString("Row %1").arg(section
);
118 void ChatSessionMembersListModel::slotContactAdded( const Kopete::Contact
*contact
)
121 // NOTE in the future the adding of a contact
122 // could be done just for the contact
126 void ChatSessionMembersListModel::slotContactRemoved( const Kopete::Contact
*contact
)
129 // NOTE in the future the removal of a contact
130 // could be done just for the contact
134 void ChatSessionMembersListModel::slotContactStatusChanged( Kopete::Contact
*contact
, const Kopete::OnlineStatus
&status
)
138 // NOTE in the future the change of a contact
139 // could be done just for the contact
143 void ChatSessionMembersListModel::slotSessionChanged()
148 void ChatSessionMembersListModel::slotSessionClosed()
152 disconnect( m_session
, 0, this, 0 );