summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopeteblacklister.cpp
blob: 29dbf72795cc720b71eb76fed0da8b73614c418b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    kopeteblacklister.cpp - Kopete BlackLister

    Copyright (c) 2004      by Roie Kerstein         <sf_kersteinroie@bezeqint.net>

    *************************************************************************
    *                                                                       *
    * 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 <kconfig.h>
#include <kglobal.h>

#include <tqstringlist.h>

namespace Kopete
{

class BlackLister::Private
{
public:
	TQStringList blacklist;
	TQString owner;
	TQString protocol;
};


BlackLister::BlackLister(const TQString &protocolId, const TQString &accountId, TQObject *parent, const char *name)
 : TQObject(parent, name), d( new Private )
{
	KConfig *config = KGlobal::config();
	
	d->owner = accountId;
	d->protocol = protocolId;
	config->setGroup("BlackLister");
	d->blacklist = config->readListEntry( d->protocol + TQString::fromLatin1("_") + d->owner );
}

BlackLister::~BlackLister()
{
	delete d;
}


bool BlackLister::isBlocked(const TQString &contactId)
{
	return (d->blacklist.find( contactId ) != d->blacklist.end() );
}

bool BlackLister::isBlocked(Contact *contact)
{
	return isBlocked(contact->contactId());
}

void BlackLister::addContact(const TQString &contactId)
{
	if( !isBlocked(contactId) )
	{
		d->blacklist += contactId;
		saveToDisk();
		emit contactAdded( contactId );
	}
}

void BlackLister::addContact(Contact *contact)
{
	TQString temp = contact->contactId();
	
	addContact( temp );
}

void BlackLister::removeContact(Contact *contact)
{
	TQString temp = contact->contactId();
	
	removeContact( temp );
}

void BlackLister::saveToDisk()
{
	KConfig *config = KGlobal::config();
	
	config->setGroup("BlackLister");
	config->writeEntry( d->protocol + TQString::fromLatin1("_") + d->owner, d->blacklist );
	config->sync();
}

void BlackLister::removeContact(const TQString &contactId)
{
	if( isBlocked(contactId) )
	{
		d->blacklist.remove( contactId );
		saveToDisk();
		emit contactRemoved( contactId );
	}
}

}

#include "kopeteblacklister.moc"