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

tdeabc

resourceevo.cpp

00001 #include <tqdir.h>
00002 
00003 #include <tdeglobal.h>
00004 #include <tdelocale.h>
00005 #include <kdebug.h>
00006 
00007 #include <stdio.h>
00008 
00009 #include <tdeabc/vcardparser/vcardtool.h>
00010 
00011 #include "dbwrapper.h"
00012 #include "resourceevo.h"
00013 
00014 using namespace Evolution;
00015 using namespace TDEABC;
00016 
00017 class EvolutionFactory : public KRES::PluginFactoryBase
00018 {
00019   public:
00020     KRES::Resource *resource( const TDEConfig *config )
00021     {
00022       return new ResourceEvolution( config );
00023     }
00024 
00025     KRES::ConfigWidget *configWidget( TQWidget * )
00026     {
00027       return 0;
00028     }
00029 };
00030 
00031 extern "C"
00032 {
00033   KDE_EXPORT void *init_tdeabc_evo()
00034   {
00035     return ( new EvolutionFactory() );
00036   }
00037 }
00038 
00039 ResourceEvolution::ResourceEvolution( const TDEConfig* conf )
00040     : Resource( conf ), mWrap(0l)
00041 {
00042     m_isOpen = false;
00043 }
00044 ResourceEvolution::~ResourceEvolution() {
00045     delete mWrap;
00046 }
00047 bool ResourceEvolution::doOpen() {
00048     mWrap = new DBWrapper;
00049     if (!mWrap->open( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db" ) ) {
00050         return false;
00051     }
00052 
00053     TQString val;
00054     if (!mWrap->find( "PAS-DB-VERSION", val ) )
00055         return false;
00056 
00057     if (!val.startsWith("0.2") )
00058         return false;
00059 
00060     m_isOpen = true;
00061 
00062     return true;
00063 }
00064 void ResourceEvolution::doClose() {
00065     delete mWrap;
00066     mWrap = 0l;
00067     m_isOpen = false;
00068 }
00069 Ticket* ResourceEvolution::requestSaveTicket() {
00070     if ( !addressBook() ) return 0;
00071     return createTicket( this );
00072 }
00073 /*
00074  * skip the first key
00075  */
00076 
00077 bool ResourceEvolution::load() {
00078     /* doOpen never get's called :( */
00079     if (!doOpen()) return false;
00080     if (!mWrap ) return false; // open first!
00081 
00082     DBIterator it = mWrap->begin();
00083     // skip the "PAS-DB-VERSION"
00084 
00085     for ( ; it != mWrap->end(); ++it ) {
00086         if ( it.key().startsWith("PAS-DB-VERSION") )
00087             continue;
00088 
00089         tqWarning( "val:%s", it.value().latin1() );
00090         VCardTool tool;
00091         TQString str = it.value().stripWhiteSpace();
00092         Addressee::List list = tool.parseVCards( str );
00093         if (!list.first().isEmpty() ) {
00094             Addressee adr = list.first();
00095             adr.setResource(this);
00096             addressBook()->insertAddressee( adr );
00097         }
00098     }
00099     return true;
00100 }
00101 bool ResourceEvolution::save( Ticket* ticket ) {
00102     delete ticket;
00103     if (!m_isOpen ) return false;
00104 
00105     // just delete the summary so evolution will regenerate it 
00106     // on next start up
00107     (void)TQFile::remove( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db.summary" );
00108 
00109 
00110     AddressBook::Iterator it;
00111     Addressee::List list;
00112     for ( it = addressBook()->begin(); it !=addressBook()->end(); ++it ) {
00113         if ( (*it).resource() != this || !(*it).changed() )
00114             continue;
00115 
00116     // remove, convert add set unchanged false
00117         list.clear();
00118         mWrap->remove( (*it).uid() );
00119         VCardTool tool;
00120         list.append( (*it) );
00121         mWrap->add( (*it).uid(), tool.createVCards( list,  VCard::v2_1) );
00122 
00123     (*it).setChanged( false );
00124     }
00125 
00126     return true;
00127 }
00128 void ResourceEvolution::removeAddressee( const Addressee& rem) {
00129     if (!m_isOpen) return;
00130 
00131     mWrap->remove( rem.uid() );
00132 }

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.7.1
This website is maintained by Timothy Pearson.