summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/addbookmarks/addbookmarksprefssettings.cpp
blob: 31f12978de02128aadebe607ec202757d522c4af (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
//
// C++ Implementation: %{MODULE}
//
// Description:
//
//
// Author: Roie Kerstein <sf_kersteinroie@bezeqint.net>, (C) 2004
//
// License: GPL v2
//
//
#include <kdebug.h>
#include <kconfig.h>
#include <kglobal.h>

#include "addbookmarksprefssettings.h"

BookmarksPrefsSettings::BookmarksPrefsSettings(TQObject *parent, const char *name)
 : TQObject(parent, name)
{
	load();
}


BookmarksPrefsSettings::~BookmarksPrefsSettings()
{
}

void BookmarksPrefsSettings::load()
{
	TDEConfig * configfile = TDEGlobal::config();
	m_isfolderforeachcontact = Always;
	m_contactslist.clear();
	m_addbookmarksfromunknowns = false;
	if( configfile->getConfigState() == TDEConfigBase::NoAccess ){
		kdDebug( 14501 ) << "load: failed to open config file for reading" << endl;
		return;
	}
	if( !configfile->hasGroup("Bookmarks Plugin") ){
		kdDebug( 14501 ) << "load: no config found in file" << endl;
		return;
	}
	configfile->setGroup("Bookmarks Plugin");
	m_isfolderforeachcontact = (UseSubfolders)configfile->readNumEntry( "UseSubfolderForEachContact", 0 );
	m_contactslist = configfile->readListEntry( "ContactsList" );
	m_addbookmarksfromunknowns = configfile->readBoolEntry( "AddBookmarksFromUnknownContacts" );
}

void BookmarksPrefsSettings::save()
{
	TDEConfig * configfile = TDEGlobal::config();

	if( configfile->getConfigState() != TDEConfigBase::ReadWrite ){
		kdDebug( 14501 ) << "save: failed to open config file for writing" << endl;
		return;
	}
	configfile->setGroup( "Bookmarks Plugin" );
	configfile->writeEntry( "UseSubfolderForEachContact", (int)m_isfolderforeachcontact );
	configfile->writeEntry( "ContactsList", m_contactslist );
	configfile->writeEntry( "AddBookmarksFromUnknownContacts", m_addbookmarksfromunknowns );
	configfile->sync();
}

bool BookmarksPrefsSettings::useSubfolderForContact( TQString nickname )
{
	if ( !nickname.isEmpty() )
	{
		switch( m_isfolderforeachcontact ){
		case Never:
			return false;
		case Always:
			return true;
		case SelectedContacts:
			return ( m_contactslist.find( nickname ) != m_contactslist.end() );
		case UnselectedContacts:
			return ( m_contactslist.find( nickname ) == m_contactslist.end() );
		}
	}
	return false;
}

void BookmarksPrefsSettings::setAddBookmarksFromUnknownContacts( bool addUntrusted )
{
    m_addbookmarksfromunknowns = addUntrusted;
}

#include "addbookmarksprefssettings.moc"