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

kabc

  • kabc
  • plugins
  • evolution
resourceevo.cpp
1 #include <tqdir.h>
2 
3 #include <kglobal.h>
4 #include <klocale.h>
5 #include <kdebug.h>
6 
7 #include <stdio.h>
8 
9 #include <kabc/vcardparser/vcardtool.h>
10 
11 #include "dbwrapper.h"
12 #include "resourceevo.h"
13 
14 using namespace Evolution;
15 using namespace KABC;
16 
17 class EvolutionFactory : public KRES::PluginFactoryBase
18 {
19  public:
20  KRES::Resource *resource( const KConfig *config )
21  {
22  return new ResourceEvolution( config );
23  }
24 
25  KRES::ConfigWidget *configWidget( TQWidget * )
26  {
27  return 0;
28  }
29 };
30 
31 extern "C"
32 {
33  KDE_EXPORT void *init_kabc_evo()
34  {
35  return ( new EvolutionFactory() );
36  }
37 }
38 
39 ResourceEvolution::ResourceEvolution( const KConfig* conf )
40  : Resource( conf ), mWrap(0l)
41 {
42  m_isOpen = false;
43 }
44 ResourceEvolution::~ResourceEvolution() {
45  delete mWrap;
46 }
47 bool 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 }
64 void ResourceEvolution::doClose() {
65  delete mWrap;
66  mWrap = 0l;
67  m_isOpen = false;
68 }
69 Ticket* ResourceEvolution::requestSaveTicket() {
70  if ( !addressBook() ) return 0;
71  return createTicket( this );
72 }
73 /*
74  * skip the first key
75  */
76 
77 bool 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  qWarning( "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 }
101 bool 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 }
128 void ResourceEvolution::removeAddressee( const Addressee& rem) {
129  if (!m_isOpen) return;
130 
131  mWrap->remove( rem.uid() );
132 }
KABC::Addressee::setResource
void setResource(Resource *resource)
Set resource where the addressee is from.
Definition: addressee.src.cpp:1013
KABC::Addressee::setChanged
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.src.cpp:1024
klocale.h
KABC::Ticket
Helper class for handling coordinated save of address books.
Definition: resource.h:37
KABC::Addressee
address book entry
Definition: addressee.src.h:74
KConfig
KABC::AddressBook::Iterator
Address Book Iterator.
Definition: addressbook.h:57
KABC::Addressee::uid
TQString uid() const
Return unique identifier.
Definition: addressee.src.cpp:174

kabc

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

kabc

Skip menu "kabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kabc by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |