make webinterface translatable. there are around 20 short strings, all with context...
[kdenetwork.git] / kopete / libkopete / chatsessionmemberslistmodel.cpp
blobed6ede958151eaced468a395294cde0d6d340393
1 /*
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 *************************************************************************
9 * *
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. *
14 * *
15 *************************************************************************
18 #include "kopetecontact.h"
19 #include "kopeteonlinestatus.h"
20 #include "chatsessionmemberslistmodel.h"
22 namespace Kopete
25 ChatSessionMembersListModel::ChatSessionMembersListModel(QObject * parent)
26 : QAbstractListModel(parent), m_session(0L)
31 void ChatSessionMembersListModel::setChatSession(ChatSession *session)
33 if ( m_session )
34 disconnect( m_session, 0, this, 0 );
36 m_session = session;
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()) );
50 reset();
53 Kopete::Contact * ChatSessionMembersListModel::contactAt( const QModelIndex &index ) const
55 if ( m_session )
57 if (!index.isValid())
58 return 0L;
60 if (index.row() >= m_session->members().size() + 1)
61 return 0L;
63 if ( index.row() == 0 )
64 return const_cast<Kopete::Contact *>(m_session->myself());
65 else
66 return m_session->members().at(index.row() - 1);
69 return 0L;
72 int ChatSessionMembersListModel::rowCount(const QModelIndex &parent) const
74 Q_UNUSED(parent)
75 if ( m_session )
76 return m_session->members().count() + 1;
78 return 0;
81 QVariant ChatSessionMembersListModel::data(const QModelIndex &index, int role) const
83 Contact *c = contactAt(index);
84 if (!c)
85 return QVariant();
87 if (role == Qt::DisplayRole)
89 QString nick = c->property(Kopete::Global::Properties::self()->nickName().key()).value().toString();
90 if ( nick.isEmpty() )
91 nick = c->contactId();
93 return nick;
95 else if (role == Qt::DecorationRole)
97 return c->onlineStatus().iconFor(c);
99 else if (role == Qt::ToolTipRole)
101 return c->toolTip();
103 else
104 return QVariant();
107 QVariant ChatSessionMembersListModel::headerData(int section, Qt::Orientation orientation, int role) const
109 if (role != Qt::DisplayRole)
110 return QVariant();
112 if (orientation == Qt::Horizontal)
113 return QString("Column %1").arg(section);
114 else
115 return QString("Row %1").arg(section);
118 void ChatSessionMembersListModel::slotContactAdded( const Kopete::Contact *contact )
120 Q_UNUSED(contact)
121 // NOTE in the future the adding of a contact
122 // could be done just for the contact
123 reset();
126 void ChatSessionMembersListModel::slotContactRemoved( const Kopete::Contact *contact )
128 Q_UNUSED(contact)
129 // NOTE in the future the removal of a contact
130 // could be done just for the contact
131 reset();
134 void ChatSessionMembersListModel::slotContactStatusChanged( Kopete::Contact *contact, const Kopete::OnlineStatus &status )
136 Q_UNUSED(contact)
137 Q_UNUSED(status)
138 // NOTE in the future the change of a contact
139 // could be done just for the contact
140 reset();
143 void ChatSessionMembersListModel::slotSessionChanged()
145 reset();
148 void ChatSessionMembersListModel::slotSessionClosed()
150 if ( m_session )
152 disconnect( m_session, 0, this, 0 );
153 m_session = 0;
154 reset();