kopete/libkopete
chatsessionmemberslistmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "kopetecontact.h"
00019 #include "kopeteonlinestatus.h"
00020 #include "chatsessionmemberslistmodel.h"
00021
00022 namespace Kopete
00023 {
00024
00025 ChatSessionMembersListModel::ChatSessionMembersListModel(QObject * parent)
00026 : QAbstractListModel(parent), m_session(0L)
00027 {
00028
00029 }
00030
00031 void ChatSessionMembersListModel::setChatSession(ChatSession *session)
00032 {
00033 if ( m_session )
00034 disconnect( m_session, 0, this, 0 );
00035
00036 m_session = session;
00037
00038 connect( session, SIGNAL(closing(Kopete::ChatSession*)),
00039 this, SLOT(slotSessionClosed()) );
00040 connect( session, SIGNAL(contactAdded(const Kopete::Contact*, bool)),
00041 this, SLOT(slotContactAdded(const Kopete::Contact*)) );
00042 connect( session, SIGNAL(contactRemoved(const Kopete::Contact*, const QString&, Qt::TextFormat, bool)),
00043 this, SLOT(slotContactRemoved(const Kopete::Contact*)) );
00044 connect( session, SIGNAL(onlineStatusChanged(Kopete::Contact*, const Kopete::OnlineStatus&, const Kopete::OnlineStatus&)),
00045 this, SLOT(slotContactStatusChanged(Kopete::Contact*, const Kopete::OnlineStatus&)) );
00046 connect( session, SIGNAL(displayNameChanged()),
00047 this, SLOT(slotSessionChanged()) );
00048 connect( session, SIGNAL(photoChanged()),
00049 this, SLOT(slotSessionChanged()) );
00050 reset();
00051 }
00052
00053 Kopete::Contact * ChatSessionMembersListModel::contactAt( const QModelIndex &index ) const
00054 {
00055 if ( m_session )
00056 {
00057 if (!index.isValid())
00058 return 0L;
00059
00060 if (index.row() >= m_session->members().size() + 1)
00061 return 0L;
00062
00063 if ( index.row() == 0 )
00064 return const_cast<Kopete::Contact *>(m_session->myself());
00065 else
00066 return m_session->members().at(index.row() - 1);
00067 }
00068
00069 return 0L;
00070 }
00071
00072 int ChatSessionMembersListModel::rowCount(const QModelIndex &parent) const
00073 {
00074 Q_UNUSED(parent)
00075 if ( m_session )
00076 return m_session->members().count() + 1;
00077
00078 return 0;
00079 }
00080
00081 QVariant ChatSessionMembersListModel::data(const QModelIndex &index, int role) const
00082 {
00083 Contact *c = contactAt(index);
00084 if (!c)
00085 return QVariant();
00086
00087 if (role == Qt::DisplayRole)
00088 {
00089 QString nick = c->property(Kopete::Global::Properties::self()->nickName().key()).value().toString();
00090 if ( nick.isEmpty() )
00091 nick = c->contactId();
00092
00093 return nick;
00094 }
00095 else if (role == Qt::DecorationRole)
00096 {
00097 return c->onlineStatus().iconFor(c);
00098 }
00099 else if (role == Qt::ToolTipRole)
00100 {
00101 return c->toolTip();
00102 }
00103 else
00104 return QVariant();
00105 }
00106
00107 QVariant ChatSessionMembersListModel::headerData(int section, Qt::Orientation orientation, int role) const
00108 {
00109 if (role != Qt::DisplayRole)
00110 return QVariant();
00111
00112 if (orientation == Qt::Horizontal)
00113 return QString("Column %1").arg(section);
00114 else
00115 return QString("Row %1").arg(section);
00116 }
00117
00118 void ChatSessionMembersListModel::slotContactAdded( const Kopete::Contact *contact )
00119 {
00120 Q_UNUSED(contact)
00121
00122
00123 reset();
00124 }
00125
00126 void ChatSessionMembersListModel::slotContactRemoved( const Kopete::Contact *contact )
00127 {
00128 Q_UNUSED(contact)
00129
00130
00131 reset();
00132 }
00133
00134 void ChatSessionMembersListModel::slotContactStatusChanged( Kopete::Contact *contact, const Kopete::OnlineStatus &status )
00135 {
00136 Q_UNUSED(contact)
00137 Q_UNUSED(status)
00138
00139
00140 reset();
00141 }
00142
00143 void ChatSessionMembersListModel::slotSessionChanged()
00144 {
00145 reset();
00146 }
00147
00148 void ChatSessionMembersListModel::slotSessionClosed()
00149 {
00150 if ( m_session )
00151 {
00152 disconnect( m_session, 0, this, 0 );
00153 m_session = 0;
00154 reset();
00155 }
00156 }
00157
00158 }
00159