summaryrefslogtreecommitdiffstats
path: root/tdeabc/plugins/evolution
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-02-15 21:57:54 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-02-15 21:57:54 -0600
commited99a30644c19b0a3cf0d2147243532df4daa16b (patch)
tree7f3f2850e59824fdf100a642367a82b1e7f0204f /tdeabc/plugins/evolution
parente5f2d46e9caf6942f365f1b454087dda71a340f7 (diff)
downloadtdelibs-ed99a30644c19b0a3cf0d2147243532df4daa16b.tar.gz
tdelibs-ed99a30644c19b0a3cf0d2147243532df4daa16b.zip
Rename additional header files to avoid conflicts with KDE4
Diffstat (limited to 'tdeabc/plugins/evolution')
-rw-r--r--tdeabc/plugins/evolution/Makefile.am19
-rw-r--r--tdeabc/plugins/evolution/README15
-rw-r--r--tdeabc/plugins/evolution/dbwrapper.cpp187
-rw-r--r--tdeabc/plugins/evolution/dbwrapper.h60
-rw-r--r--tdeabc/plugins/evolution/evolution.desktop26
-rw-r--r--tdeabc/plugins/evolution/resourceevo.cpp132
-rw-r--r--tdeabc/plugins/evolution/resourceevo.h23
7 files changed, 462 insertions, 0 deletions
diff --git a/tdeabc/plugins/evolution/Makefile.am b/tdeabc/plugins/evolution/Makefile.am
new file mode 100644
index 000000000..2c22cf376
--- /dev/null
+++ b/tdeabc/plugins/evolution/Makefile.am
@@ -0,0 +1,19 @@
+INCLUDES = -I$(top_builddir)/kabc -I$(top_srcdir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourceevo.h dbwrapper.h
+
+kde_module_LTLIBRARIES = kabc_evo.la
+
+kabc_evo_la_SOURCES = dbwrapper.cpp resourceevo.cpp
+
+kabc_evo_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kabc_evo_la_LIBADD = ../../../tdeabc/libkabc.la ../../../tdeui/libtdeui.la -ldb ../../../tdeabc/vcardparser/libvcards.la
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_evolution.pot
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = evolution.desktop
diff --git a/tdeabc/plugins/evolution/README b/tdeabc/plugins/evolution/README
new file mode 100644
index 000000000..7dfefce00
--- /dev/null
+++ b/tdeabc/plugins/evolution/README
@@ -0,0 +1,15 @@
+A Resource using DB3 to access the evolution
+addressbook make sure the wombat is not running
+In future versions I may use bonobo to access it...
+
+
+DESIGN:
+The Format vs Resource idea is somehow not applyable to the
+Evolution PAS
+
+Format would be vCard and Resource would be DB3..
+BUT
+Format get's a QFile* pointer which is just not usable
+with a DB3
+INSTEAD we will use the vCardImpl directly to convert
+a string to Addressee \ No newline at end of file
diff --git a/tdeabc/plugins/evolution/dbwrapper.cpp b/tdeabc/plugins/evolution/dbwrapper.cpp
new file mode 100644
index 000000000..fbdff165a
--- /dev/null
+++ b/tdeabc/plugins/evolution/dbwrapper.cpp
@@ -0,0 +1,187 @@
+#include <db.h>
+
+#include <tqfile.h>
+
+#include "dbwrapper.h"
+
+
+using namespace Evolution;
+
+struct DBIterator::Data {
+ DBWrapper *wrapper;
+ TQString key;
+ TQString data;
+ DBC* cursor;
+ bool atEnd;
+};
+
+DBIterator::DBIterator( DBWrapper* wra) {
+ data = new Data;
+ data->wrapper = wra;
+ data->atEnd = false;
+ data->cursor = 0l;
+}
+DBIterator::DBIterator( const DBIterator& copy ) {
+ data = new Data;
+ data->wrapper = copy.data->wrapper;
+ data->key = copy.data->key;
+ data->data = copy.data->data;
+ data->atEnd = copy.data->atEnd;
+ if (copy.data->cursor )
+ copy.data->cursor->c_dup(copy.data->cursor, &data->cursor, 0 );
+ else
+ data->cursor = 0l;
+}
+DBIterator::~DBIterator() {
+ if (data->cursor)
+ data->cursor->c_close(data->cursor);
+ delete data;
+}
+DBIterator& DBIterator::operator=( const DBIterator& rhs ) {
+ if ( *this == rhs )
+ return *this;
+ if (data->cursor)
+ data->cursor->c_close(data->cursor);
+ delete data;
+ data = new Data;
+ data->wrapper = rhs.data->wrapper;
+ data->key = rhs.data->key;
+ data->data = rhs.data->data;
+ data->atEnd = rhs.data->atEnd;
+ if ( rhs.data->cursor )
+ rhs.data->cursor->c_dup(rhs.data->cursor, &data->cursor, 0 );
+ else
+ data->cursor = 0l;
+
+ return *this;
+}
+TQString DBIterator::key()const{
+ return data->key;
+}
+TQString DBIterator::value()const {
+ return data->data;
+}
+TQString DBIterator::operator*() {
+ return data->data;
+}
+DBIterator& DBIterator::operator++() {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ if ( data->cursor )
+ if ( data->cursor->c_get(data->cursor, &key, &val,DB_NEXT ) != 0 )
+ data->atEnd = true;
+ data->key = TQString::fromUtf8( (char*)key.data, key.size );
+ data->data = TQString::fromUtf8( (char*)val.data, val.size );
+ return *this;
+}
+DBIterator& DBIterator::operator--() {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ if ( data->cursor )
+ if ( data->cursor->c_get(data->cursor, &key, &val,DB_PREV ) != 0 )
+ data->atEnd = true;
+ data->key = TQString::fromUtf8( (char*)key.data, key.size );
+ data->data = TQString::fromUtf8( (char*)val.data, val.size );
+ return *this;
+}
+bool DBIterator::operator==( const DBIterator& rhs ) {
+ if ( data->atEnd && data->atEnd == rhs.data->atEnd ) return true;
+
+ return false;
+}
+bool DBIterator::operator!=( const DBIterator& rhs ) {
+ return !this->operator==(rhs );
+}
+struct DBWrapper::Data {
+ DB* db;
+ bool only;
+};
+DBWrapper::DBWrapper() {
+ data = new Data;
+ (void)db_create(&data->db, NULL, 0 );
+ data->only = false;
+}
+DBWrapper::~DBWrapper() {
+ data->db->close(data->db, 0 );
+ delete data;
+}
+bool DBWrapper::open( const TQString& file, bool on) {
+ data->only = on;
+ return !data->db->open(data->db, TQFile::encodeName( file ), NULL, DB_HASH, 0, 0666 );
+}
+bool DBWrapper::save() {
+ return true;
+}
+DBIterator DBWrapper::begin() {
+ DBIterator it(this);
+ DBC* cursor;
+ DBT key, val;
+ int ret;
+ ret = data->db->cursor(data->db, NULL, &cursor, 0 );
+ if (ret ) {
+ it.data->atEnd = true;
+ return it;
+ }
+
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ ret = cursor->c_get(cursor, &key, &val, DB_FIRST );
+ if (ret ) {
+ it.data->atEnd = true;
+ return it;
+ }
+
+ it.data->cursor = cursor;
+ it.data->key = TQString::fromUtf8((char*)key.data, key.size );
+ it.data->data = TQString::fromUtf8((char*)val.data, val.size );
+
+ return it;
+}
+DBIterator DBWrapper::end() {
+ DBIterator it(this);
+ it.data->atEnd = true;
+
+ return it;
+}
+bool DBWrapper::find( const TQString& _key, TQString& _val ) {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+
+ TQCString db_key = _key.local8Bit();
+ key.data = db_key.data();
+ key.size = db_key.size();
+
+ int ret = data->db->get(data->db, NULL, &key, &val, 0 );
+ if (!ret) {
+ _val = TQString::fromUtf8( (char*)val.data, val.size );
+ tqWarning("key: %s val: %sXXX", (char*)key.data, (char*)val.data );
+ return true;
+ }
+ return false;
+}
+bool DBWrapper::add( const TQString& _key, const TQString& _val ) {
+ TQCString db_key = _key.local8Bit();
+ TQCString db_val = _val.local8Bit();
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+
+ key.data = db_key.data();
+ key.size = db_key.size();
+ val.data = db_val.data();
+ val.size = db_val.size();
+
+ return !data->db->put(data->db, NULL, &key, &val, 0 );
+}
+bool DBWrapper::remove( const TQString& _key ) {
+ TQCString db_key = _key.local8Bit();
+ DBT key;
+ memset(&key, 0, sizeof(key) );
+ key.data = db_key.data();
+ key.size = db_key.size();
+
+ return !data->db->del(data->db, NULL, &key, 0 );
+}
diff --git a/tdeabc/plugins/evolution/dbwrapper.h b/tdeabc/plugins/evolution/dbwrapper.h
new file mode 100644
index 000000000..e5e0a2c33
--- /dev/null
+++ b/tdeabc/plugins/evolution/dbwrapper.h
@@ -0,0 +1,60 @@
+#ifndef KABC_EVOLUTION_DB_WRAPPER
+#define KABC_EVOLUTION_DB_WRAPPER
+
+#include <db.h>
+
+#include <tqstring.h>
+#include <tqpair.h>
+
+namespace Evolution {
+
+ class DBWrapper;
+ class DBIterator {
+ friend class DBWrapper;
+ public:
+ DBIterator( DBWrapper* = 0l );
+ ~DBIterator();
+
+ DBIterator( const DBIterator& );
+ DBIterator &operator=( const DBIterator& );
+
+ TQString key()const;
+ TQString value()const;
+
+ TQString operator*();
+
+ DBIterator &operator++();
+ DBIterator &operator--();
+
+ bool operator==( const DBIterator& );
+ bool operator!=( const DBIterator& );
+ private:
+ struct Data;
+ Data* data;
+ };
+ class DBWrapper {
+ public:
+ DBWrapper();
+ ~DBWrapper();
+
+ TQString lastError()const;
+
+ bool open( const TQString& file, bool readOnly = false);
+ bool save();
+ DBIterator begin();
+ DBIterator end();
+
+ bool find( const TQString& key, TQString& value );
+ bool add( const TQString& key, const TQString& val );
+ bool remove( const TQString& key );
+ private:
+ // DBT element( const TQString& );
+ struct Data;
+ Data* data;
+
+ };
+
+}
+
+
+#endif
diff --git a/tdeabc/plugins/evolution/evolution.desktop b/tdeabc/plugins/evolution/evolution.desktop
new file mode 100644
index 000000000..98030e906
--- /dev/null
+++ b/tdeabc/plugins/evolution/evolution.desktop
@@ -0,0 +1,26 @@
+[Desktop Entry]
+Name=Evolution
+Name[be]=Эвалюцыя
+Name[bn]=ইভোলিউশন
+Name[eo]=Evoluo
+Name[fa]=اوولوشن
+Name[hi]=एवॉल्यूशन
+Name[ko]=에볼루션
+Name[mn]=Хөгжил
+Name[ne]=इभोल्युसन
+Name[pa]=ਏਵੂਲੇਸ਼ਨ
+Name[sr]=Еволуција
+Name[sr@Latn]=Evolucija
+Name[ta]=படிப்படியான வளர்ச்சி
+Name[te]=ఎవల్యుషన్
+Name[th]=เอฟโวลูชัน
+Name[tt]=Üseş
+Name[ven]=Tsikoni
+Name[wa]=Evolucion
+Name[xh]=Utshintsho lwendawo ngokwenqanawa
+Name[zu]=Evolushini
+X-TDE-Library=kabc_evo
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=evolution
diff --git a/tdeabc/plugins/evolution/resourceevo.cpp b/tdeabc/plugins/evolution/resourceevo.cpp
new file mode 100644
index 000000000..e6545f738
--- /dev/null
+++ b/tdeabc/plugins/evolution/resourceevo.cpp
@@ -0,0 +1,132 @@
+#include <tqdir.h>
+
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kdebug.h>
+
+#include <stdio.h>
+
+#include <tdeabc/vcardparser/vcardtool.h>
+
+#include "dbwrapper.h"
+#include "resourceevo.h"
+
+using namespace Evolution;
+using namespace KABC;
+
+class EvolutionFactory : public KRES::PluginFactoryBase
+{
+ public:
+ KRES::Resource *resource( const TDEConfig *config )
+ {
+ return new ResourceEvolution( config );
+ }
+
+ KRES::ConfigWidget *configWidget( TQWidget * )
+ {
+ return 0;
+ }
+};
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_evo()
+ {
+ return ( new EvolutionFactory() );
+ }
+}
+
+ResourceEvolution::ResourceEvolution( const TDEConfig* conf )
+ : Resource( conf ), mWrap(0l)
+{
+ m_isOpen = false;
+}
+ResourceEvolution::~ResourceEvolution() {
+ delete mWrap;
+}
+bool ResourceEvolution::doOpen() {
+ mWrap = new DBWrapper;
+ if (!mWrap->open( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db" ) ) {
+ return false;
+ }
+
+ TQString val;
+ if (!mWrap->find( "PAS-DB-VERSION", val ) )
+ return false;
+
+ if (!val.startsWith("0.2") )
+ return false;
+
+ m_isOpen = true;
+
+ return true;
+}
+void ResourceEvolution::doClose() {
+ delete mWrap;
+ mWrap = 0l;
+ m_isOpen = false;
+}
+Ticket* ResourceEvolution::requestSaveTicket() {
+ if ( !addressBook() ) return 0;
+ return createTicket( this );
+}
+/*
+ * skip the first key
+ */
+
+bool ResourceEvolution::load() {
+ /* doOpen never get's called :( */
+ if (!doOpen()) return false;
+ if (!mWrap ) return false; // open first!
+
+ DBIterator it = mWrap->begin();
+ // skip the "PAS-DB-VERSION"
+
+ for ( ; it != mWrap->end(); ++it ) {
+ if ( it.key().startsWith("PAS-DB-VERSION") )
+ continue;
+
+ tqWarning( "val:%s", it.value().latin1() );
+ VCardTool tool;
+ TQString str = it.value().stripWhiteSpace();
+ Addressee::List list = tool.parseVCards( str );
+ if (!list.first().isEmpty() ) {
+ Addressee adr = list.first();
+ adr.setResource(this);
+ addressBook()->insertAddressee( adr );
+ }
+ }
+ return true;
+}
+bool ResourceEvolution::save( Ticket* ticket ) {
+ delete ticket;
+ if (!m_isOpen ) return false;
+
+ // just delete the summary so evolution will regenerate it
+ // on next start up
+ (void)TQFile::remove( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db.summary" );
+
+
+ AddressBook::Iterator it;
+ Addressee::List list;
+ for ( it = addressBook()->begin(); it !=addressBook()->end(); ++it ) {
+ if ( (*it).resource() != this || !(*it).changed() )
+ continue;
+
+ // remove, convert add set unchanged false
+ list.clear();
+ mWrap->remove( (*it).uid() );
+ VCardTool tool;
+ list.append( (*it) );
+ mWrap->add( (*it).uid(), tool.createVCards( list, VCard::v2_1) );
+
+ (*it).setChanged( false );
+ }
+
+ return true;
+}
+void ResourceEvolution::removeAddressee( const Addressee& rem) {
+ if (!m_isOpen) return;
+
+ mWrap->remove( rem.uid() );
+}
diff --git a/tdeabc/plugins/evolution/resourceevo.h b/tdeabc/plugins/evolution/resourceevo.h
new file mode 100644
index 000000000..29e163e1c
--- /dev/null
+++ b/tdeabc/plugins/evolution/resourceevo.h
@@ -0,0 +1,23 @@
+#include "resource.h"
+
+namespace Evolution {
+ class DBWrapper;
+}
+
+namespace KABC {
+ class ResourceEvolution : public Resource {
+ public:
+ ResourceEvolution( const TDEConfig* config );
+ ~ResourceEvolution();
+
+ bool doOpen();
+ void doClose();
+ Ticket* requestSaveTicket();
+ bool load();
+ bool save( Ticket* ticket );
+ void removeAddressee( const Addressee& );
+ private:
+ Evolution::DBWrapper *mWrap;
+ bool m_isOpen : 1;
+ };
+}