kopete/protocols/messenger/libpapillon
notifypresencetask.cpp
Go to the documentation of this file.00001 /* 00002 notifypresencetask.cpp - Notify about presence changes of contacts 00003 00004 Copyright (c) 2006 by Michaƫl Larouche <larouche@kde.org> 00005 00006 ************************************************************************* 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2 of the License, or (at your option) any later version. * 00012 * * 00013 ************************************************************************* 00014 */ 00015 #include "Papillon/Tasks/NotifyPresenceTask" 00016 00017 // Qt includes 00018 #include <QtCore/QStringList> 00019 #include <QtCore/QLatin1String> 00020 #include <QtDebug> 00021 00022 // Papillon includes 00023 #include "Papillon/NetworkMessage" 00024 #include "Papillon/Global" 00025 00026 namespace Papillon 00027 { 00028 00029 class NotifyPresenceTask::Private 00030 { 00031 public: 00032 Private() 00033 {} 00034 }; 00035 00036 NotifyPresenceTask::NotifyPresenceTask(Papillon::Task *parent) 00037 : Papillon::Task(parent), d(new Private) 00038 {} 00039 00040 NotifyPresenceTask::~NotifyPresenceTask() 00041 { 00042 delete d; 00043 } 00044 00045 00046 bool NotifyPresenceTask::take(NetworkMessage *networkMessage) 00047 { 00048 if( forMe(networkMessage) ) 00049 { 00050 QString contactId; 00051 Papillon::Presence::Status newPresence = Presence::Offline; 00052 00053 // ILN is initial presence and NLN normal presence change. 00054 if( networkMessage->command() == QLatin1String("NLN") || networkMessage->command() == QLatin1String("ILN") ) 00055 { 00056 newPresence = Papillon::Global::stringToPresence( networkMessage->arguments()[0] ); 00057 contactId = networkMessage->arguments()[1]; 00058 // TODO: Handle nickname, features, MsnObject 00059 } 00060 // Contact went offline 00061 else if( networkMessage->command() == QLatin1String("FLN") ) 00062 { 00063 newPresence = Presence::Offline; 00064 contactId = networkMessage->arguments()[0]; 00065 } 00066 00067 emit contactPresenceChanged(contactId, newPresence); 00068 00069 return true; 00070 } 00071 00072 return false; 00073 } 00074 00075 bool NotifyPresenceTask::forMe(NetworkMessage *networkMessage) const 00076 { 00077 if( networkMessage->command() == QLatin1String("ILN") || 00078 networkMessage->command() == QLatin1String("NLN") || 00079 networkMessage->command() == QLatin1String("FLN") ) 00080 { 00081 return true; 00082 } 00083 00084 return false; 00085 } 00086 00087 } 00088 00089 #include "notifypresencetask.moc"
KDE 4.2 API Reference