kopete/protocols/messenger/libpapillon
contactlist.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Papillon/ContactList"
00016
00017
00018 #include <QtCore/QPointer>
00019
00020
00021 #include "Papillon/Client"
00022 #include "Papillon/Contact"
00023
00024
00025 #include "fetchcontactlistjob.h"
00026
00027 namespace Papillon
00028 {
00029
00030 class ContactList::Private
00031 {
00032 public:
00033 Private()
00034 {}
00035
00036 ~Private()
00037 {
00038 }
00039
00040 QPointer<Client> client;
00041
00042 QList<Contact*> contacts;
00043 };
00044
00045 ContactList::ContactList(Client *client)
00046 : QObject(client), d(new Private)
00047 {
00048 d->client = client;
00049 }
00050
00051
00052 ContactList::~ContactList()
00053 {
00054 delete d;
00055 }
00056
00057 Client *ContactList::client()
00058 {
00059 return d->client;
00060 }
00061
00062 QList<Papillon::Contact*> ContactList::contacts() const
00063 {
00064 QList<Contact*> result;
00065
00066 foreach(Contact *contact, d->contacts)
00067 {
00068 if( contact->lists() & ContactListEnums::ForwardList )
00069 {
00070 result << contact;
00071 }
00072 }
00073 return result;
00074 }
00075
00076 QList<Papillon::Contact*> ContactList::allowList() const
00077 {
00078 QList<Contact*> result;
00079
00080 foreach(Contact *contact, d->contacts)
00081 {
00082 if( contact->lists() & ContactListEnums::AllowList )
00083 {
00084 result << contact;
00085 }
00086 }
00087
00088 return result;
00089 }
00090
00091 QList<Papillon::Contact*> ContactList::blockList() const
00092 {
00093 QList<Contact*> result;
00094
00095 foreach(Contact *contact, d->contacts)
00096 {
00097 if( contact->lists() & ContactListEnums::BlockList )
00098 {
00099 result << contact;
00100 }
00101 }
00102
00103 return result;
00104 }
00105
00106 QList<Papillon::Contact*> ContactList::reverseList() const
00107 {
00108 QList<Contact*> result;
00109
00110 foreach(Contact *contact, d->contacts)
00111 {
00112 if( contact->lists() & ContactListEnums::ReverseList )
00113 {
00114 result << contact;
00115 }
00116 }
00117
00118 return result;
00119 }
00120
00121 QList<Papillon::Contact*> ContactList::pendingList() const
00122 {
00123 QList<Contact*> result;
00124
00125 foreach(Contact *contact, d->contacts)
00126 {
00127 if( contact->lists() & ContactListEnums::PendingList )
00128 {
00129 result << contact;
00130 }
00131 }
00132
00133 return result;
00134 }
00135
00136 Contact* ContactList::contact(const QString &contactId)
00137 {
00138 Contact *foundContact = 0, *contact = 0;
00139
00140 foreach(contact, d->contacts)
00141 {
00142 if( contact->contactId() == contactId || contact->passportId() == contactId )
00143 {
00144 foundContact = contact;
00145 break;
00146 }
00147 }
00148
00149 return foundContact;
00150 }
00151
00152 void ContactList::load()
00153 {
00154 FetchContactListJob *fetchJob = new FetchContactListJob(this);
00155
00156 connect(fetchJob, SIGNAL(finished(Papillon::FetchContactListJob*)), this, SIGNAL(contactListLoaded()));
00157 fetchJob->execute();
00158 }
00159
00160 Contact* ContactList::createContact(const QString &contactId)
00161 {
00162 if( !contact(contactId) )
00163 {
00164 Contact *newContact = new Contact(this);
00165 newContact->setContactId(contactId);
00166
00167 d->contacts << newContact;
00168 }
00169
00170 return contact(contactId);
00171 }
00172
00173 }
00174
00175 #include "contactlist.moc"