9 #include <kabc/vcardparser/vcardtool.h> 11 #include "dbwrapper.h" 12 #include "resourceevo.h" 17 class EvolutionFactory :
public KRES::PluginFactoryBase
20 KRES::Resource *resource(
const KConfig *config )
22 return new ResourceEvolution( config );
25 KRES::ConfigWidget *configWidget( TQWidget * )
33 KDE_EXPORT
void *init_kabc_evo()
35 return (
new EvolutionFactory() );
39 ResourceEvolution::ResourceEvolution(
const KConfig* conf )
40 : Resource( conf ), mWrap(0l)
44 ResourceEvolution::~ResourceEvolution() {
47 bool ResourceEvolution::doOpen() {
48 mWrap =
new DBWrapper;
49 if (!mWrap->open( TQDir::homeDirPath() +
"/evolution/local/Contacts/addressbook.db" ) ) {
54 if (!mWrap->find(
"PAS-DB-VERSION", val ) )
57 if (!val.startsWith(
"0.2") )
64 void ResourceEvolution::doClose() {
69 Ticket* ResourceEvolution::requestSaveTicket() {
70 if ( !addressBook() )
return 0;
71 return createTicket(
this );
77 bool ResourceEvolution::load() {
79 if (!doOpen())
return false;
80 if (!mWrap )
return false;
82 DBIterator it = mWrap->begin();
85 for ( ; it != mWrap->end(); ++it ) {
86 if ( it.key().startsWith(
"PAS-DB-VERSION") )
89 qWarning(
"val:%s", it.value().latin1() );
91 TQString str = it.value().stripWhiteSpace();
92 Addressee::List list = tool.parseVCards( str );
93 if (!list.first().isEmpty() ) {
96 addressBook()->insertAddressee( adr );
101 bool ResourceEvolution::save(
Ticket* ticket ) {
103 if (!m_isOpen )
return false;
107 (void)TQFile::remove( TQDir::homeDirPath() +
"/evolution/local/Contacts/addressbook.db.summary" );
111 Addressee::List list;
112 for ( it = addressBook()->begin(); it !=addressBook()->end(); ++it ) {
113 if ( (*it).resource() !=
this || !(*it).changed() )
118 mWrap->remove( (*it).uid() );
120 list.append( (*it) );
121 mWrap->add( (*it).uid(), tool.createVCards( list, VCard::v2_1) );
128 void ResourceEvolution::removeAddressee(
const Addressee& rem) {
129 if (!m_isOpen)
return;
131 mWrap->remove( rem.
uid() );
void setResource(Resource *resource)
Set resource where the addressee is from.
void setChanged(bool value)
Mark addressee as changed.
Helper class for handling coordinated save of address books.
static data, shared by ALL addressee objects
TQString uid() const
Return unique identifier.