summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-09-18 08:25:05 (UTC)
committer zautrix <zautrix>2004-09-18 08:25:05 (UTC)
commit983b010853dfadfec3638e2afd90e522985f67fb (patch) (side-by-side diff)
treeb691b7664b9f6f23d0d92a0e05bf3e8cbcf2df67 /kabc
parentdf03bd8c7ff6a738dd386001679542ae4b493a07 (diff)
downloadkdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2
more AB syncing
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp101
-rw-r--r--kabc/addressbook.h1
2 files changed, 100 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 47d298a..70eda1b 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -109,312 +109,409 @@ Addressee *AddressBook::Iterator::operator->()
return &(*(d->mIt));
}
AddressBook::Iterator &AddressBook::Iterator::operator++()
{
(d->mIt)++;
return *this;
}
AddressBook::Iterator &AddressBook::Iterator::operator++(int)
{
(d->mIt)++;
return *this;
}
AddressBook::Iterator &AddressBook::Iterator::operator--()
{
(d->mIt)--;
return *this;
}
AddressBook::Iterator &AddressBook::Iterator::operator--(int)
{
(d->mIt)--;
return *this;
}
bool AddressBook::Iterator::operator==( const Iterator &it )
{
return ( d->mIt == it.d->mIt );
}
bool AddressBook::Iterator::operator!=( const Iterator &it )
{
return ( d->mIt != it.d->mIt );
}
AddressBook::ConstIterator::ConstIterator()
{
d = new ConstIteratorData;
}
AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
{
d = new ConstIteratorData;
d->mIt = i.d->mIt;
}
AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
{
if( this == &i ) return *this; // guard for self assignment
delete d; // delete the old data because the Iterator was really constructed before
d = new ConstIteratorData;
d->mIt = i.d->mIt;
return *this;
}
AddressBook::ConstIterator::~ConstIterator()
{
delete d;
}
const Addressee &AddressBook::ConstIterator::operator*() const
{
return *(d->mIt);
}
const Addressee* AddressBook::ConstIterator::operator->() const
{
return &(*(d->mIt));
}
AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
{
(d->mIt)++;
return *this;
}
AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
{
(d->mIt)++;
return *this;
}
AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
{
(d->mIt)--;
return *this;
}
AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
{
(d->mIt)--;
return *this;
}
bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
{
return ( d->mIt == it.d->mIt );
}
bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
{
return ( d->mIt != it.d->mIt );
}
AddressBook::AddressBook()
{
init(0, "contact");
}
AddressBook::AddressBook( const QString &config )
{
init(config, "contact");
}
AddressBook::AddressBook( const QString &config, const QString &family )
{
init(config, family);
}
// the default family is "contact"
void AddressBook::init(const QString &config, const QString &family )
{
d = new AddressBookData;
+ QString fami = family;
+ qDebug("new ab ");
if (config != 0) {
+ qDebug("config != 0 ");
+ if ( family == "syncContact" ) {
+ qDebug("creating sync config ");
+ fami = "contact";
+ KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
+ con->setGroup( "General" );
+ con->writeEntry( "ResourceKeys", QString("sync") );
+ con->writeEntry( "Standard", QString("sync") );
+ con->setGroup( "Resource_sync" );
+ con->writeEntry( "FileFormat", QString("vcard") );
+ con->writeEntry( "FileName", config );
+ con->writeEntry( "ResourceIdentifier", QString("sync") );
+ con->writeEntry( "ResourceName", QString("sync_res") );
+ con->writeEntry( "ResourceType", QString("file") );
+ //con->sync();
+ d->mConfig = con;
+ }
+ else
d->mConfig = new KConfig( locateLocal("config", config) );
// qDebug("AddressBook::init 1 config=%s",config.latin1() );
}
else {
d->mConfig = 0;
// qDebug("AddressBook::init 1 config=0");
}
//US d->mErrorHandler = 0;
- d->mManager = new KRES::Manager<Resource>( family, false );
+ d->mManager = new KRES::Manager<Resource>( fami, false );
d->mManager->readConfig( d->mConfig );
+ if ( family == "syncContact" ) {
+ KRES::Manager<Resource> *manager = d->mManager;
+ KRES::Manager<Resource>::ActiveIterator it;
+ for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
+ (*it)->setAddressBook( this );
+ if ( !(*it)->open() )
+ error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
+ }
+ Resource *res = standardResource();
+ if ( !res ) {
+ qDebug("ERROR: no standard resource");
+ res = manager->createResource( "file" );
+ if ( res )
+ {
+ addResource( res );
+ }
+ else
+ qDebug(" No resource available!!!");
+ }
+ setStandardResource( res );
+ manager->writeConfig();
+ }
+ addCustomField( i18n( "Department" ), KABC::Field::Organization,
+ "X-Department", "KADDRESSBOOK" );
+ addCustomField( i18n( "Profession" ), KABC::Field::Organization,
+ "X-Profession", "KADDRESSBOOK" );
+ addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
+ "X-AssistantsName", "KADDRESSBOOK" );
+ addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
+ "X-ManagersName", "KADDRESSBOOK" );
+ addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
+ "X-SpousesName", "KADDRESSBOOK" );
+ addCustomField( i18n( "Office" ), KABC::Field::Personal,
+ "X-Office", "KADDRESSBOOK" );
+ addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
+ "X-IMAddress", "KADDRESSBOOK" );
+ addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
+ "X-Anniversary", "KADDRESSBOOK" );
+
+ //US added this field to become compatible with Opie/qtopia addressbook
+ // values can be "female" or "male" or "". An empty field represents undefined.
+ addCustomField( i18n( "Gender" ), KABC::Field::Personal,
+ "X-Gender", "KADDRESSBOOK" );
+ addCustomField( i18n( "Children" ), KABC::Field::Personal,
+ "X-Children", "KADDRESSBOOK" );
+ addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
+ "X-FreeBusyUrl", "KADDRESSBOOK" );
+ addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
+ "X-ExternalID", "KADDRESSBOOK" );
}
AddressBook::~AddressBook()
{
delete d->mConfig; d->mConfig = 0;
delete d->mManager; d->mManager = 0;
//US delete d->mErrorHandler; d->mErrorHandler = 0;
delete d; d = 0;
}
bool AddressBook::load()
{
clear();
KRES::Manager<Resource>::ActiveIterator it;
bool ok = true;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
if ( !(*it)->load() ) {
error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
ok = false;
}
// mark all addressees as unchanged
Addressee::List::Iterator addrIt;
for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
(*addrIt).setChanged( false );
return ok;
}
bool AddressBook::save( Ticket *ticket )
{
kdDebug(5700) << "AddressBook::save()"<< endl;
if ( ticket->resource() ) {
deleteRemovedAddressees();
-
return ticket->resource()->save( ticket );
}
return false;
}
+bool AddressBook::saveAB()
+{
+ bool ok = true;
+
+ deleteRemovedAddressees();
+
+ 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;
}
AddressBook::Iterator AddressBook::end()
{
Iterator it = Iterator();
it.d->mIt = d->mAddressees.end();
return it;
}
AddressBook::ConstIterator AddressBook::end() const
{
ConstIterator it = ConstIterator();
it.d->mIt = d->mAddressees.end();
return it;
}
void AddressBook::clear()
{
d->mAddressees.clear();
}
Ticket *AddressBook::requestSaveTicket( Resource *resource )
{
kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
if ( !resource )
{
qDebug("AddressBook::requestSaveTicket no resource" );
resource = standardResource();
}
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
if ( (*it) == resource ) {
if ( (*it)->readOnly() || !(*it)->isOpen() )
return 0;
else
return (*it)->requestSaveTicket();
}
}
return 0;
}
void AddressBook::insertAddressee( const Addressee &a )
{
Addressee::List::Iterator it;
for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
bool changed = false;
Addressee addr = a;
if ( addr != (*it) )
changed = true;
(*it) = a;
if ( (*it).resource() == 0 )
(*it).setResource( standardResource() );
if ( changed ) {
(*it).setRevision( QDateTime::currentDateTime() );
(*it).setChanged( true );
}
return;
}
}
d->mAddressees.append( a );
Addressee& addr = d->mAddressees.last();
if ( addr.resource() == 0 )
addr.setResource( standardResource() );
addr.setChanged( true );
}
void AddressBook::removeAddressee( const Addressee &a )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
removeAddressee( it );
return;
}
}
}
void AddressBook::removeAddressee( const Iterator &it )
{
d->mRemovedAddressees.append( (*it) );
d->mAddressees.remove( it.d->mIt );
}
AddressBook::Iterator AddressBook::find( const Addressee &a )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
return it;
}
}
return end();
}
Addressee AddressBook::findByUid( const QString &uid )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).uid() ) {
return *it;
}
}
return Addressee();
}
Addressee::List AddressBook::allAddressees()
{
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f89d7da..e43de31 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -16,256 +16,257 @@
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_ADDRESSBOOK_H
#define KABC_ADDRESSBOOK_H
#include <qobject.h>
#include <kresources/manager.h>
#include <qptrlist.h>
#include "addressee.h"
#include "field.h"
namespace KABC {
class ErrorHandler;
class Resource;
class Ticket;
/**
@short Address Book
This class provides access to a collection of address book entries.
*/
class AddressBook : public QObject
{
Q_OBJECT
friend QDataStream &operator<<( QDataStream &, const AddressBook & );
friend QDataStream &operator>>( QDataStream &, AddressBook & );
friend class StdAddressBook;
public:
/**
@short Address Book Iterator
This class provides an iterator for address book entries.
*/
class Iterator
{
public:
Iterator();
Iterator( const Iterator & );
~Iterator();
Iterator &operator=( const Iterator & );
const Addressee &operator*() const;
Addressee &operator*();
Addressee* operator->();
Iterator &operator++();
Iterator &operator++(int);
Iterator &operator--();
Iterator &operator--(int);
bool operator==( const Iterator &it );
bool operator!=( const Iterator &it );
struct IteratorData;
IteratorData *d;
};
/**
@short Address Book Const Iterator
This class provides a const iterator for address book entries.
*/
class ConstIterator
{
public:
ConstIterator();
ConstIterator( const ConstIterator & );
~ConstIterator();
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( );
/**
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 & );
/**
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 & );
/**
Find the specified entry in address book. Returns end(), if the entry
couldn't be found.
*/
Iterator find( const Addressee & );
/**
Find the entry specified by an unique id. Returns an empty Addressee
object, if the address book does not contain an entry with this id.
*/
Addressee findByUid( const QString & );
/**
Returns a list of all addressees in the address book. This list can
be sorted with @ref KABC::AddresseeList for example.
*/
Addressee::List allAddressees();
/**
Find all entries with the specified name in the address book. Returns
an empty list, if no entries could be found.
*/
Addressee::List findByName( const QString & );
/**
Find all entries with the specified email address in the address book.
Returns an empty list, if no entries could be found.
*/
Addressee::List findByEmail( const QString & );
/**
Find all entries wich have the specified category in the address book.
Returns an empty list, if no entries could be found.
*/
Addressee::List findByCategory( const QString & );
/**
Return a string identifying this addressbook.
*/
virtual QString identifier();
/**
Used for debug output.
*/
void dump() const;
void emitAddressBookLocked() { emit addressBookLocked( this ); }
void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
void emitAddressBookChanged() { emit addressBookChanged( this ); }
/**
Return list of all Fields known to the address book which are associated
with the given field category.
*/
Field::List fields( int category = Field::All );
/**
Add custom field to address book.
@param label User visible label of the field.
@param category Ored list of field categories.
@param key Identifier used as key for reading and writing the field.
@param app String used as application key for reading and writing
the field.
*/
bool addCustomField( const QString &label, int category = Field::All,
const QString &key = QString::null,
const QString &app = QString::null );
/**
Add address book resource.
*/
bool addResource( Resource * );
/**
Remove address book resource.
*/
bool removeResource( Resource * );
/**
Return pointer list of all resources.
*/