kopete/protocols/messenger/libpapillon
fetchcontactlistjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "fetchcontactlistjob.h"
00016
00017
00018 #include <QtCore/QPointer>
00019 #include <QtCore/QTimer>
00020 #include <QtCore/QLatin1String>
00021 #include <QtDebug>
00022
00023
00024 #include "Papillon/Contact"
00025 #include "Papillon/ContactList"
00026 #include "Papillon/Client"
00027 #include "Papillon/UserContact"
00028 #include "Papillon/Http/Connection"
00029 #include "Papillon/Enums"
00030
00031
00032 #include "sharingservicebinding.h"
00033
00034 using namespace Papillon::Internal;
00035
00036 namespace Papillon
00037 {
00038
00039 class FetchContactListJob::Private
00040 {
00041 public:
00042 Private()
00043 : connection(0)
00044 {}
00045
00046 QPointer<ContactList> contactList;
00047 HttpConnection *connection;
00048 };
00049
00050 FetchContactListJob::FetchContactListJob(ContactList *contactList)
00051 : QObject(contactList), d(new Private)
00052 {
00053 d->contactList = contactList;
00054
00055 d->connection = new HttpConnection( this );
00056
00057 QString cookie = QString("MSPAuth=%1").arg( d->contactList->client()->userContact()->loginCookie() );
00058 d->connection->setCookie(cookie);
00059 }
00060
00061 FetchContactListJob::~FetchContactListJob()
00062 {
00063 delete d;
00064 }
00065
00066 void FetchContactListJob::execute()
00067 {
00068 Papillon::Internal::SharingServiceBinding *binding = new Papillon::Internal::SharingServiceBinding(d->connection, this);
00069 connect(binding, SIGNAL(findMembershipResult(Papillon::Internal::FindMembershipResult *)), this, SLOT(bindingFindMembershipResult(Papillon::Internal::FindMembershipResult *)));
00070
00071 QTimer::singleShot(0, binding, SLOT(findMembership()));
00072 }
00073
00074 void FetchContactListJob::bindingFindMembershipResult(Papillon::Internal::FindMembershipResult *result)
00075 {
00076 if( result )
00077 {
00078 QList<Service*> services = result->services();
00079 foreach(Service *service, services)
00080 {
00081 foreach(Membership *membership, service->memberships())
00082 {
00083 ContactListEnums::ListFlags currentFlag;
00084
00085 QString role = membership->memberRole();
00086 if( role == QLatin1String("Allow") )
00087 currentFlag = ContactListEnums::AllowList;
00088 else if( role == QLatin1String("Block") )
00089 currentFlag = ContactListEnums::BlockList;
00090 else if( role == QLatin1String("Reverse") )
00091 currentFlag = ContactListEnums::ReverseList;
00092 else if( role == QLatin1String("Pending") )
00093 currentFlag = ContactListEnums::PendingList;
00094
00095 foreach(Member *member, membership->members())
00096 {
00097 QString contactId = member->passportName();
00098 Contact *contact = d->contactList->createContact(contactId);
00099 contact->setPassportId(contactId);
00100 contact->addToList(currentFlag);
00101 }
00102 }
00103 }
00104
00105 delete result;
00106 }
00107
00108 emit finished(this);
00109 deleteLater();
00110 }
00111
00112 }
00113
00114 #include "fetchcontactlistjob.moc"