• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
  • plugins
  • evolution
resourceevo.cpp
1#include <tqdir.h>
2
3#include <tdeglobal.h>
4#include <tdelocale.h>
5#include <kdebug.h>
6
7#include <stdio.h>
8
9#include <tdeabc/vcardparser/vcardtool.h>
10
11#include "dbwrapper.h"
12#include "resourceevo.h"
13
14using namespace Evolution;
15using namespace TDEABC;
16
17class EvolutionFactory : public KRES::PluginFactoryBase
18{
19 public:
20 KRES::Resource *resource( const TDEConfig *config )
21 {
22 return new ResourceEvolution( config );
23 }
24
25 KRES::ConfigWidget *configWidget( TQWidget * )
26 {
27 return 0;
28 }
29};
30
31extern "C"
32{
33 TDE_EXPORT void *init_tdeabc_evo()
34 {
35 return ( new EvolutionFactory() );
36 }
37}
38
39ResourceEvolution::ResourceEvolution( const TDEConfig* conf )
40 : Resource( conf ), mWrap(0l)
41{
42 m_isOpen = false;
43}
44ResourceEvolution::~ResourceEvolution() {
45 delete mWrap;
46}
47bool ResourceEvolution::doOpen() {
48 mWrap = new DBWrapper;
49 if (!mWrap->open( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db" ) ) {
50 return false;
51 }
52
53 TQString val;
54 if (!mWrap->find( "PAS-DB-VERSION", val ) )
55 return false;
56
57 if (!val.startsWith("0.2") )
58 return false;
59
60 m_isOpen = true;
61
62 return true;
63}
64void ResourceEvolution::doClose() {
65 delete mWrap;
66 mWrap = 0l;
67 m_isOpen = false;
68}
69Ticket* ResourceEvolution::requestSaveTicket() {
70 if ( !addressBook() ) return 0;
71 return createTicket( this );
72}
73/*
74 * skip the first key
75 */
76
77bool ResourceEvolution::load() {
78 /* doOpen never get's called :( */
79 if (!doOpen()) return false;
80 if (!mWrap ) return false; // open first!
81
82 DBIterator it = mWrap->begin();
83 // skip the "PAS-DB-VERSION"
84
85 for ( ; it != mWrap->end(); ++it ) {
86 if ( it.key().startsWith("PAS-DB-VERSION") )
87 continue;
88
89 tqWarning( "val:%s", it.value().latin1() );
90 VCardTool tool;
91 TQString str = it.value().stripWhiteSpace();
92 Addressee::List list = tool.parseVCards( str );
93 if (!list.first().isEmpty() ) {
94 Addressee adr = list.first();
95 adr.setResource(this);
96 addressBook()->insertAddressee( adr );
97 }
98 }
99 return true;
100}
101bool ResourceEvolution::save( Ticket* ticket ) {
102 delete ticket;
103 if (!m_isOpen ) return false;
104
105 // just delete the summary so evolution will regenerate it
106 // on next start up
107 (void)TQFile::remove( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db.summary" );
108
109
110 AddressBook::Iterator it;
111 Addressee::List list;
112 for ( it = addressBook()->begin(); it !=addressBook()->end(); ++it ) {
113 if ( (*it).resource() != this || !(*it).changed() )
114 continue;
115
116 // remove, convert add set unchanged false
117 list.clear();
118 mWrap->remove( (*it).uid() );
119 VCardTool tool;
120 list.append( (*it) );
121 mWrap->add( (*it).uid(), tool.createVCards( list, VCard::v2_1) );
122
123 (*it).setChanged( false );
124 }
125
126 return true;
127}
128void ResourceEvolution::removeAddressee( const Addressee& rem) {
129 if (!m_isOpen) return;
130
131 mWrap->remove( rem.uid() );
132}
TDEABC::AddressBook::Iterator
Address Book Iterator.
Definition: addressbook.h:58
TDEABC::Addressee
address book entry
Definition: addressee.src.h:75
TDEABC::Addressee::setChanged
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.src.cpp:1024
TDEABC::Addressee::setResource
void setResource(Resource *resource)
Set resource where the addressee is from.
Definition: addressee.src.cpp:1013
TDEABC::Addressee::uid
TQString uid() const
Return unique identifier.
Definition: addressee.src.cpp:174
TDEABC::Ticket
Helper class for handling coordinated save of address books.
Definition: resource.h:38
TDEConfig
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
tdelocale.h

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.4
This website is maintained by Timothy Pearson.