[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Btelepathy-chat-handler=5D_lib=3A_Code_tidy_up?=
From: David Edmundson <kde () davidedmundson ! co ! uk>
Date: 2011-03-24 21:25:37
Message-ID: 20110324212537.07847A60C4 () git ! kde ! org
[Download RAW message or body]
Git commit 62e35bafac288869da27980477b83f956164e391 by David Edmundson.
Committed on 24/03/2011 at 03:46.
Pushed by davidedmundson into branch 'master'.
Code tidy up
M +48 -37 lib/channel-contact-list.cpp
M +8 -5 lib/channel-contact-list.h
http://commits.kde.org/telepathy-chat-handler/62e35bafac288869da27980477b83f956164e391
diff --git a/lib/channel-contact-list.cpp b/lib/channel-contact-list.cpp
index 980f4eb..d970725 100644
--- a/lib/channel-contact-list.cpp
+++ b/lib/channel-contact-list.cpp
@@ -25,9 +25,10 @@
ChannelContactList::ChannelContactList(const Tp::TextChannelPtr & channel, QObject \
*parent) : QAbstractListModel(parent)
{
-
+ //add existing contacts
addContacts(channel->groupContacts());
+ //monitor for future changes
connect(channel.data(),
SIGNAL(groupMembersChanged(Tp::Contacts,Tp::Contacts,Tp::Contacts,
\
Tp::Contacts,Tp::Channel::GroupMemberChangeDetails)), @@ -35,40 +36,6 @@ \
ChannelContactList::ChannelContactList(const Tp::TextChannelPtr & \
channel, QObje
\
Tp::Contacts,Tp::Channel::GroupMemberChangeDetails))); }
-void ChannelContactList::onGroupMembersChanged(const Tp::Contacts & \
groupMembersAdded,
- const Tp::Contacts & \
groupLocalPendingMembersAdded,
- const Tp::Contacts & \
groupRemotePendingMembersAdded,
- const Tp::Contacts & \
groupMembersRemoved,
- const \
Tp::Channel::GroupMemberChangeDetails & details)
-{
- kDebug();
-
- Q_UNUSED(groupLocalPendingMembersAdded);
- Q_UNUSED(groupRemotePendingMembersAdded);
- Q_UNUSED(details);
-
- addContacts(groupMembersAdded);
- removeContacts(groupMembersRemoved);
-}
-
-void ChannelContactList::onContactPresenceChanged(const Tp::Presence &presence)
-{
- Tp::ContactPtr contact(qobject_cast<Tp::Contact*>(sender()));
-
- QModelIndex index = createIndex(m_contacts.lastIndexOf(contact), 0);
- emit dataChanged(index, index);
-
- emit contactPresenceChanged(contact, presence);}
-
-void ChannelContactList::onContactAliasChanged(const QString &alias)
-{
- Tp::ContactPtr contact(qobject_cast<Tp::Contact*>(sender()));
-
- QModelIndex index = createIndex(m_contacts.lastIndexOf(contact), 0);
- emit dataChanged(index, index);
-
- emit contactAliasChanged(contact, alias);
-}
int ChannelContactList::rowCount(const QModelIndex &parent) const
{
@@ -89,27 +56,65 @@ QVariant ChannelContactList::data(const QModelIndex &index, int \
role) const switch (role) {
case Qt::DisplayRole:
return QVariant(m_contacts[row]->alias());
+
case Qt::DecorationRole:
switch(m_contacts[row]->presence().type()) {
case Tp::ConnectionPresenceTypeAvailable:
return QVariant(KIcon("im-user"));
case Tp::ConnectionPresenceTypeAway:
+ //fall through
case Tp::ConnectionPresenceTypeExtendedAway:
return QVariant(KIcon("im-user-away"));
case Tp::ConnectionPresenceTypeBusy:
return QVariant(KIcon("im-user-busy"));
case Tp::ConnectionPresenceTypeOffline:
+ //fall through
case Tp::ConnectionPresenceTypeHidden:
return QVariant(KIcon("im-user-offline"));
default:
return QVariant(KIcon("im-user"));
}
- //icon for presence stuff here? im-user-away etc.
+
default:
return QVariant();
}
}
+void ChannelContactList::onGroupMembersChanged(const Tp::Contacts & \
groupMembersAdded, + const Tp::Contacts & \
groupLocalPendingMembersAdded, + const \
Tp::Contacts & groupRemotePendingMembersAdded, + \
const Tp::Contacts & groupMembersRemoved, + \
const Tp::Channel::GroupMemberChangeDetails & details) +{
+ kDebug();
+
+ Q_UNUSED(groupLocalPendingMembersAdded);
+ Q_UNUSED(groupRemotePendingMembersAdded);
+ Q_UNUSED(details);
+
+ addContacts(groupMembersAdded);
+ removeContacts(groupMembersRemoved);
+}
+
+void ChannelContactList::onContactPresenceChanged(const Tp::Presence &presence)
+{
+ Tp::ContactPtr contact(qobject_cast<Tp::Contact*>(sender()));
+
+ QModelIndex index = createIndex(m_contacts.lastIndexOf(contact), 0);
+ emit dataChanged(index, index);
+
+ emit contactPresenceChanged(contact, presence);}
+
+void ChannelContactList::onContactAliasChanged(const QString &alias)
+{
+ Tp::ContactPtr contact(qobject_cast<Tp::Contact*>(sender()));
+
+ QModelIndex index = createIndex(m_contacts.lastIndexOf(contact), 0);
+ emit dataChanged(index, index);
+
+ emit contactAliasChanged(contact, alias);
+}
+
void ChannelContactList::addContacts(const Tp::Contacts &contacts)
{
QList<Tp::ContactPtr> newContacts = contacts.toList();
@@ -127,7 +132,13 @@ void ChannelContactList::addContacts(const Tp::Contacts \
&contacts) void ChannelContactList::removeContacts(const Tp::Contacts &contacts)
{
foreach(Tp::ContactPtr contact, contacts) {
- //does it make sense to disconnect the signals here too? as technically the \
contact itself hasn't actually been deleted yet... +
+ //I think this is needed as technically the contact itself hasn't actually \
been deleted even if we remove our pointers to it + //and could be used \
referenced elsewhere in the chat application in a different tab. + //if we \
don't disconnect could we still get notifications here about their status/presence \
changes even if a contact has left the room + disconnect(contact.data(), \
SIGNAL(aliasChanged(QString)), SLOT(onContactAliasChanged(QString))); + \
disconnect(contact.data(), SIGNAL(presenceChanged(Tp::Presence)), \
SLOT(onContactPresenceChanged(Tp::Presence))); +
beginRemoveRows(QModelIndex(), m_contacts.indexOf(contact), \
m_contacts.indexOf(contact)); m_contacts.removeAll(contact);
endRemoveRows();
diff --git a/lib/channel-contact-list.h b/lib/channel-contact-list.h
index fe1db06..97d19c9 100644
--- a/lib/channel-contact-list.h
+++ b/lib/channel-contact-list.h
@@ -29,17 +29,20 @@
#include <TelepathyQt4/Presence>
/** A model of all users in the channel.
- Also acts as a proxy for emiting presence and alias changes of any contacts in the \
channel for displaying as notifications*/ + Also acts as a proxy for emiting \
presence and alias changes of any contacts in the channel + so that the main class \
doesn't need to monitor this and keep connection/disconnecting to alias \
change/presence + change for notification messages
+ */
class ChannelContactList : public QAbstractListModel
{
Q_OBJECT
public:
- explicit ChannelContactList(const Tp::TextChannelPtr & channel, QObject *parent \
= 0); + explicit ChannelContactList(const Tp::TextChannelPtr &channel, QObject \
*parent = 0);
signals:
- void contactPresenceChanged(const Tp::ContactPtr & contact, const Tp::Presence & \
presence);
- void contactAliasChanged(const Tp::ContactPtr & contact, const QString & alias);
+ void contactPresenceChanged(const Tp::ContactPtr &contact, const Tp::Presence \
&presence); + void contactAliasChanged(const Tp::ContactPtr &contact, const \
QString &alias);
protected:
int rowCount(const QModelIndex &parent) const;
@@ -51,7 +54,7 @@ private slots:
const Tp::Contacts &groupRemotePendingMembersAdded,
const Tp::Contacts &groupMembersRemoved,
const Tp::Channel::GroupMemberChangeDetails &details);
- void onContactPresenceChanged(const Tp::Presence& presence);
+ void onContactPresenceChanged(const Tp::Presence &presence);
void onContactAliasChanged(const QString &alias);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic