-rw-r--r-- | kabc/plugins/qtopia/qtopiaE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 7 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.h | 1 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 78 |
4 files changed, 60 insertions, 28 deletions
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro index 148da2a..c0aa960 100644 --- a/kabc/plugins/qtopia/qtopiaE.pro +++ b/kabc/plugins/qtopia/qtopiaE.pro @@ -1,27 +1,27 @@ TEMPLATE = lib CONFIG += qt warn_on TARGET = microkabc_qtopia -INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include +INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include OBJECTS_DIR = obj/$(PLATFORM) MOC_DIR = moc/$(PLATFORM) DESTDIR = $(QPEDIR)/lib LIBS += -lmicrokde LIBS += -lmicrokabc LIBS += -L$(QPEDIR)/lib LIBS += -lqpepim LIBS += -lqpe INTERFACES = \ HEADERS = \ resourceqtopia.h \ resourceqtopiaconfig.h \ qtopiaconverter.h SOURCES = \ resourceqtopia.cpp \ resourceqtopiaconfig.cpp \ qtopiaconverter.cpp diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 7d00a3f..de45e63 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -11,92 +11,96 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ //US #include "kglobal.h" #include "qtopiaconverter.h" #include <qpe/categories.h> +#include <libkdepim/ksyncprofile.h> //US #include <qpe/categoryselect.h> using namespace KABC; QtopiaConverter::QtopiaConverter() : catDB(0) { } QtopiaConverter::~QtopiaConverter() { deinit(); } bool QtopiaConverter::init() { catDB = new Categories(); if (!catDB) return false; catDB->load( categoryFileName() ); return true; } void QtopiaConverter::deinit() { if (catDB) { delete catDB; catDB = 0; } } bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) { // name addr.setFormattedName(contact.fileAs()); addr.setFamilyName( contact.lastName() ); addr.setGivenName( contact.firstName() ); addr.setAdditionalName( contact.middleName() ); addr.setPrefix( contact.nameTitle() ); addr.setSuffix( contact.suffix() ); + + addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); QString exuid = contact.uid().toString(); + addr.setOriginalExternalUID( exuid ); int ente = exuid.find( "-0000"); if ( exuid.left(1) == "{" ) exuid = exuid.mid(1); if ( ente > -1 ) exuid = exuid.left( ente-1 ); addr.setExternalUID( exuid ); //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); // email QStringList emails = contact.emailList(); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); } if (!contact.defaultEmail().isEmpty()) addr.insertEmail(contact.defaultEmail(), true); // home if ((!contact.homeStreet().isEmpty()) || (!contact.homeCity().isEmpty()) || (!contact.homeState().isEmpty()) || (!contact.homeZip().isEmpty()) || (!contact.homeCountry().isEmpty())) { @@ -230,48 +234,51 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a addr.setNote( contact.notes() ); //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; QArray<int> catArray = contact.categories(); QString cat; for ( unsigned int i=0; i < catArray.size(); i++ ) { cat = catDB->label("contact", catArray[i]); if ( cat.isEmpty() ) addr.insertCategory(QString::number(catArray[i])); else addr.insertCategory( cat ); } return true; } bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) { + + + // name contact.setLastName(addr.familyName()); contact.setFirstName(addr.givenName()); contact.setMiddleName(addr.additionalName()); contact.setNameTitle(addr.prefix()); contact.setSuffix(addr.suffix()); contact.setFileAs(); // email QStringList emails = addr.emails(); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { contact.insertEmail(*it); } contact.setDefaultEmail( addr.preferredEmail() ); // home const Address homeaddress = addr.address(Address::Home); if (!homeaddress.isEmpty()) { contact.setHomeStreet(homeaddress.street()); contact.setHomeCity(homeaddress.locality()); contact.setHomeState(homeaddress.region()); contact.setHomeZip(homeaddress.postalCode()); diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h index 8f4c698..012a6e2 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.h +++ b/kabc/plugins/qtopia/qtopiaconverter.h @@ -10,48 +10,49 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_QTOPIACONVERTER_H #define KABC_QTOPIACONVERTER_H #include <qstring.h> #include "addressee.h" #include <qpe/pim/contact.h> +#include <qpe/quuid.h> class Categories; namespace KABC { class QtopiaConverter { public: /** * Constructor. */ QtopiaConverter(); /** * Destructor. */ virtual ~QtopiaConverter(); bool init(); void deinit(); /** * Converts a vcard string to an addressee. diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 48a9f22..935a1cf 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -31,48 +31,50 @@ $Id$ #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include <qpe/pim/addressbookaccess.h> #include "resourceqtopiaconfig.h" #include "stdaddressbook.h" #include "qtopiaconverter.h" #include "syncprefwidget.h" #include "resourceqtopia.h" +#include <libkdepim/ksyncprofile.h> +#include <qpe/quuid.h> using namespace KABC; extern "C" { void *init_microkabc_qtopia() { return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); } } ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) : Resource( config, syncable ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; init( fileName ); } ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) : Resource( 0, syncable ) { init( fileName ); } @@ -168,80 +170,102 @@ bool ResourceQtopia::load() AddressBookIterator it(*mAccess); const PimContact* contact; bool res; for (contact=it.toFirst(); it.current(); ++it) { contact = it.current(); KABC::Addressee addressee; res = mConverter->qtopiaToAddressee( (*contact), addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } bool ResourceQtopia::save( Ticket *ticket ) { - qDebug("ResourceQtopia::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - - KABC::AddressBook::Iterator it; - bool res; - - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { - PimContact c; - KABC::Addressee addressee = (*it); - - res = mConverter->addresseeToQtopia( *it, c ); - if (res == true) - { - mAccess->addContact(c); -// if (res == false) -// qDebug("Unable to append Contact %s", c.fullName().latin1()); + qDebug("ResourceQtopia::save: %s", fileName().latin1()); + + mDirWatch.stopScan(); + + KABC::AddressBook::Iterator it; + bool res; + + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + //KABC::Addressee addressee = (*it); + if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + QUuid uid( (*it).originalExternalUID() ); + bool ok; + PimContact c = mAccess->contactForId( uid, &ok ); + res = mConverter->addresseeToQtopia( *it, c ); + if (res == true) { + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { + mAccess->addContact(c); + KABC::Addressee addressee; + mConverter->qtopiaToAddressee( c, addressee ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + addressBook()->insertAddressee( addressee ); + + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + if ( ok ) + mAccess->removeContact(c); + else + qDebug("Error revoe contact from qtopia "); + } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + if ( ok ) { + mAccess->updateContact(c); + KABC::Addressee addressee; + mConverter->qtopiaToAddressee( c, addressee ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + addressBook()->insertAddressee( addressee ); + } + else + qDebug("Error update contact from qtopia "); + + } + + } else { + qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); + } + } } - else - { - qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); - } - } -// mAccess->addressBookUpdated(); + // mAccess->addressBookUpdated(); - mDirWatch.startScan(); + mDirWatch.startScan(); - delete ticket; - unlock( fileName() ); + delete ticket; + unlock( fileName() ); - return true; + return true; } bool ResourceQtopia::lock( const QString &lockfileName ) { qDebug("ResourceQtopia::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceQtopia::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); |