summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
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/addressbook.cpp
parentdf03bd8c7ff6a738dd386001679542ae4b493a07 (diff)
downloadkdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2
more AB syncing
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp101
1 files changed, 99 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
@@ -173,184 +173,281 @@ 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;