From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/libkopete/kopeteblacklister.cpp | 109 +++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 kopete/libkopete/kopeteblacklister.cpp (limited to 'kopete/libkopete/kopeteblacklister.cpp') diff --git a/kopete/libkopete/kopeteblacklister.cpp b/kopete/libkopete/kopeteblacklister.cpp new file mode 100644 index 00000000..8ec5c54b --- /dev/null +++ b/kopete/libkopete/kopeteblacklister.cpp @@ -0,0 +1,109 @@ +/* + kopeteblacklister.cpp - Kopete BlackLister + + Copyright (c) 2004 by Roie Kerstein + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopeteblacklister.h" + +#include "kopetecontact.h" + +#include +#include + +#include + +namespace Kopete +{ + +class BlackLister::Private +{ +public: + QStringList blacklist; + QString owner; + QString protocol; +}; + + +BlackLister::BlackLister(const QString &protocolId, const QString &accountId, QObject *parent, const char *name) + : QObject(parent, name), d( new Private ) +{ + KConfig *config = KGlobal::config(); + + d->owner = accountId; + d->protocol = protocolId; + config->setGroup("BlackLister"); + d->blacklist = config->readListEntry( d->protocol + QString::fromLatin1("_") + d->owner ); +} + +BlackLister::~BlackLister() +{ + delete d; +} + + +bool BlackLister::isBlocked(const QString &contactId) +{ + return (d->blacklist.find( contactId ) != d->blacklist.end() ); +} + +bool BlackLister::isBlocked(Contact *contact) +{ + return isBlocked(contact->contactId()); +} + +void BlackLister::addContact(const QString &contactId) +{ + if( !isBlocked(contactId) ) + { + d->blacklist += contactId; + saveToDisk(); + emit contactAdded( contactId ); + } +} + +void BlackLister::addContact(Contact *contact) +{ + QString temp = contact->contactId(); + + addContact( temp ); +} + +void BlackLister::removeContact(Contact *contact) +{ + QString temp = contact->contactId(); + + removeContact( temp ); +} + +void BlackLister::saveToDisk() +{ + KConfig *config = KGlobal::config(); + + config->setGroup("BlackLister"); + config->writeEntry( d->protocol + QString::fromLatin1("_") + d->owner, d->blacklist ); + config->sync(); +} + +void BlackLister::removeContact(const QString &contactId) +{ + if( isBlocked(contactId) ) + { + d->blacklist.remove( contactId ); + saveToDisk(); + emit contactRemoved( contactId ); + } +} + +} + +#include "kopeteblacklister.moc" -- cgit v1.2.1