summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-10-09 21:35:22 (UTC)
committer zautrix <zautrix>2004-10-09 21:35:22 (UTC)
commit213a9d993e5a4751b64e18320cfbebb000681d13 (patch) (side-by-side diff)
tree995b465797464e689b73d3271ff4a3f8f0d3749b /kabc
parentd68435216e1ebc5a7fed391157197994e13992b3 (diff)
downloadkdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.zip
kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.gz
kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.bz2
ab phone sync implemented
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp44
-rw-r--r--kabc/addressbook.h3
2 files changed, 47 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16927e2..d037d2f 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -2,96 +2,97 @@
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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$
*/
/*US
#include <qfile.h>
#include <qregexp.h>
#include <qtimer.h>
#include <kapplication.h>
#include <kinstance.h>
#include <kstandarddirs.h>
#include "errorhandler.h"
*/
#include <qptrlist.h>
#include <qtextstream.h>
#include <qfile.h>
#include <qregexp.h>
#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <libkcal/syncdefines.h>
+#include <libkdepim/phoneaccess.h>
#include "addressbook.h"
#include "resource.h"
#include "vcardconverter.h"
#include "vcardparser/vcardtool.h"
//US #include "addressbook.moc"
using namespace KABC;
struct AddressBook::AddressBookData
{
Addressee::List mAddressees;
Addressee::List mRemovedAddressees;
Field::List mAllFields;
KConfig *mConfig;
KRES::Manager<Resource> *mManager;
//US ErrorHandler *mErrorHandler;
};
struct AddressBook::Iterator::IteratorData
{
Addressee::List::Iterator mIt;
};
struct AddressBook::ConstIterator::ConstIteratorData
{
Addressee::List::ConstIterator mIt;
};
AddressBook::Iterator::Iterator()
{
d = new IteratorData;
}
AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
{
d = new IteratorData;
d->mIt = i.d->mIt;
}
AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
{
if( this == &i ) return *this; // guard against self assignment
delete d; // delete the old data the Iterator was completely constructed before
d = new IteratorData;
d->mIt = i.d->mIt;
return *this;
}
@@ -414,96 +415,139 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool rem
QByteArray rawData = file.readAll();
file.close();
QString data;
if ( replaceLabel ) {
data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
data.replace ( QRegExp("LABEL") , "ADR" );
data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
} else
data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
KABC::VCardTool tool;
list = tool.parseVCards( data );
KABC::Addressee::List::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
(*it).setResource( 0 );
if ( replaceLabel )
(*it).removeVoice();
if ( removeOld )
(*it).setTagged( true );
insertAddressee( (*it), false, true );
}
if ( removeOld )
removeUntagged();
}
void AddressBook::setUntagged()
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).setTagged( false );
}
}
void AddressBook::removeUntagged()
{
Iterator ait;
bool todelete = false;
Iterator todel;
for ( ait = begin(); ait != end(); ++ait ) {
if ( todelete )
removeAddressee( todel );
if (!(*ait).tagged()) {
todelete = true;
todel = ait;
} else
todelete = false;
}
if ( todelete )
removeAddressee( todel );
deleteRemovedAddressees();
}
+void AddressBook::smplifyAddressees()
+{
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ (*ait).simplifyEmails();
+ (*ait).simplifyPhoneNumbers();
+ (*ait).simplifyPhoneNumberTypes();
+ (*ait).simplifyAddresses();
+ }
+}
+void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
+{
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ QString id = (*ait).IDStr();
+ (*ait).setIDStr( ":");
+ (*ait).setExternalUID( id );
+ (*ait).setOriginalExternalUID( id );
+ if ( isPreSync )
+ (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
+ else
+ (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ }
+}
+bool AddressBook::saveABphone( QString fileName )
+{
+ smplifyAddressees();
+ qDebug("saveABphone:: saving AB... ");
+ if ( ! saveAB() )
+ return false;
+ qDebug("saveABphone:: writing to phone... ");
+ if ( !PhoneAccess::writeToPhone( fileName) ) {
+ return false;
+ }
+ qDebug("saveABphone:: re-reading from phone... ");
+ if ( !PhoneAccess::readFromPhone( fileName) ) {
+ return false;
+ }
+ qDebug("reloading phone book... ");
+ if ( !load() )
+ return false;
+ return true;
+}
bool AddressBook::saveAB()
{
bool ok = true;
deleteRemovedAddressees();
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( !(*ait).IDStr().isEmpty() ) {
(*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
}
}
KRES::Manager<Resource>::ActiveIterator it;
KRES::Manager<Resource> *manager = d->mManager;
for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
if ( !(*it)->readOnly() && (*it)->isOpen() ) {
Ticket *ticket = requestSaveTicket( *it );
// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
if ( !ticket ) {
error( i18n( "Unable to save to resource '%1'. It is locked." )
.arg( (*it)->resourceName() ) );
return false;
}
//if ( !save( ticket ) )
if ( ticket->resource() ) {
if ( ! ticket->resource()->save( ticket ) )
ok = false;
} else
ok = false;
}
}
return ok;
}
AddressBook::Iterator AddressBook::begin()
{
Iterator it = Iterator();
it.d->mIt = d->mAddressees.begin();
return it;
}
AddressBook::ConstIterator AddressBook::begin() const
{
ConstIterator it = ConstIterator();
it.d->mIt = d->mAddressees.begin();
return it;
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 532e05d..cc755d1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -97,96 +97,99 @@ class AddressBook : public QObject
ConstIterator &operator=( const ConstIterator & );
const Addressee &operator*() const;
const Addressee* operator->() const;
ConstIterator &operator++();
ConstIterator &operator++(int);
ConstIterator &operator--();
ConstIterator &operator--(int);
bool operator==( const ConstIterator &it );
bool operator!=( const ConstIterator &it );
struct ConstIteratorData;
ConstIteratorData *d;
};
/**
Constructs a address book object.
@param format File format class.
*/
AddressBook();
AddressBook( const QString &config );
AddressBook( const QString &config, const QString &family );
virtual ~AddressBook();
/**
Requests a ticket for saving the addressbook. Calling this function locks
the addressbook for all other processes. If the address book is already
locked the function returns 0. You need the returned @ref Ticket object
for calling the @ref save() function.
@see save()
*/
Ticket *requestSaveTicket( Resource *resource=0 );
/**
Load address book from file.
*/
bool load();
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
bool saveAB( );
+ bool saveABphone( QString fileName );
+ void smplifyAddressees();
+ void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
void export2File( QString fileName );
void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
void setUntagged();
void removeUntagged();
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator begin() const;
/**
Returns a iterator for first entry of address book.
*/
Iterator end();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator end() const;
/**
Removes all entries from address book.
*/
void clear();
/**
Insert an Addressee object into address book. If an object with the same
unique id already exists in the address book it it replaced by the new
one. If not the new object is appended to the address book.
*/
void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
/**
Removes entry from the address book.
*/
void removeAddressee( const Addressee & );
/**
This is like @ref removeAddressee() just above, with the difference that
the first element is a iterator, returned by @ref begin().
*/
void removeAddressee( const Iterator & );
/**