• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kopete/libkopete

chatsessionmemberslistmodel.cpp

Go to the documentation of this file.
00001 /*
00002     ChatSessionMembersListModel
00003 
00004     Copyright (c) 2007 by Duncan Mac-Vicar Prett <duncan@kde.org>
00005    
00006     Kopete    (c) 2002-2007 by the Kopete developers  <kopete-devel@kde.org>
00007 
00008     *************************************************************************
00009     *                                                                       *
00010     * This library is free software; you can redistribute it and/or         *
00011     * modify it under the terms of the GNU Lesser General Public            *
00012     * License as published by the Free Software Foundation; either          *
00013     * version 2 of the License, or (at your option) any later version.      *
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     // NOTE in the future the adding of a contact
00122   // could be done just for the contact
00123     reset();
00124 }
00125 
00126 void ChatSessionMembersListModel::slotContactRemoved( const Kopete::Contact *contact )
00127 {
00128     Q_UNUSED(contact)
00129     // NOTE in the future the removal of a contact
00130   // could be done just for the contact
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     // NOTE in the future the change of a contact
00139   // could be done just for the contact
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 

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal