kopete/libkopete
kopeteblacklister.cpp
Go to the documentation of this file.00001 /* 00002 kopeteblacklister.cpp - Kopete BlackLister 00003 00004 Copyright (c) 2004 by Roie Kerstein <sf_kersteinroie@bezeqint.net> 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 00016 #include "kopeteblacklister.h" 00017 00018 #include "kopetecontact.h" 00019 00020 #include <ksharedconfig.h> 00021 #include <kconfiggroup.h> 00022 #include <kglobal.h> 00023 00024 #include <qstringlist.h> 00025 00026 namespace Kopete 00027 { 00028 00029 class BlackLister::Private 00030 { 00031 public: 00032 QStringList blacklist; 00033 QString owner; 00034 QString protocol; 00035 }; 00036 00037 00038 BlackLister::BlackLister(const QString &protocolId, const QString &accountId, QObject *parent) 00039 : QObject(parent), d( new Private ) 00040 { 00041 KConfigGroup config = KGlobal::config()->group("BlackLister"); 00042 00043 d->owner = accountId; 00044 d->protocol = protocolId; 00045 d->blacklist = config.readEntry( d->protocol + QString::fromLatin1("_") + d->owner, QStringList() ); 00046 } 00047 00048 BlackLister::~BlackLister() 00049 { 00050 delete d; 00051 } 00052 00053 00054 bool BlackLister::isBlocked(const QString &contactId) 00055 { 00056 return (d->blacklist.indexOf( contactId ) != -1 ); 00057 } 00058 00059 bool BlackLister::isBlocked(Contact *contact) 00060 { 00061 return isBlocked(contact->contactId()); 00062 } 00063 00064 void BlackLister::addContact(const QString &contactId) 00065 { 00066 if( !isBlocked(contactId) ) 00067 { 00068 d->blacklist += contactId; 00069 saveToDisk(); 00070 emit contactAdded( contactId ); 00071 } 00072 } 00073 00074 void BlackLister::addContact(Contact *contact) 00075 { 00076 QString temp = contact->contactId(); 00077 00078 addContact( temp ); 00079 } 00080 00081 void BlackLister::removeContact(Contact *contact) 00082 { 00083 QString temp = contact->contactId(); 00084 00085 removeContact( temp ); 00086 } 00087 00088 void BlackLister::saveToDisk() 00089 { 00090 KConfigGroup config = KGlobal::config()->group("BlackLister"); 00091 config.writeEntry( d->protocol + QString::fromLatin1("_") + d->owner, d->blacklist ); 00092 config.sync(); 00093 } 00094 00095 void BlackLister::removeContact(const QString &contactId) 00096 { 00097 if( isBlocked(contactId) ) 00098 { 00099 d->blacklist.removeAll( contactId ); 00100 saveToDisk(); 00101 emit contactRemoved( contactId ); 00102 } 00103 } 00104 00105 } 00106 00107 #include "kopeteblacklister.moc"
KDE 4.2 API Reference