summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp101
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kaddressbook/kabcore.cpp95
-rw-r--r--kaddressbook/kabcore.h5
4 files changed, 186 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 47d298a..70eda1b 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -234,7 +234,27 @@ AddressBook::AddressBook( const QString &config, const QString &family )
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() );
}
@@ -244,8 +264,57 @@ void AddressBook::init(const QString &config, const QString &family )
}
//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()
@@ -284,12 +353,40 @@ bool AddressBook::save( Ticket *ticket )
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()
{
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f89d7da..e43de31 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -141,6 +141,7 @@ class AddressBook : public QObject
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
+ bool saveAB( );
/**
Returns a iterator for first entry of address book.
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 49c3b19..e912941 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -148,6 +148,7 @@ $Id$
#endif
// sync includes
#include <libkdepim/ksyncprofile.h>
+#include <libkdepim/ksyncprefsdialog.h>
bool pasteWithNewUid = true;
@@ -179,6 +180,8 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
SLOT( addressBookChanged() ) );
+#if 0
+ // LP moved to addressbook init method
mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
"X-Department", "KADDRESSBOOK" );
mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
@@ -204,7 +207,7 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
"X-Children", "KADDRESSBOOK" );
mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
"X-FreeBusyUrl", "KADDRESSBOOK" );
-
+#endif
initGUI();
mIncSearchWidget->setFocus();
@@ -2195,8 +2198,8 @@ void KABCore::slotSyncMenu( int action )
} else if ( action >= 1003 ) {
if ( temp->getIsLocalFileSync() ) {
- if ( syncWithFile( temp->getRemoteFileName( ), false ) )
- KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
+ if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
+ KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
} else {
if ( temp->getIsPhoneSync() ) {
KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
@@ -2317,7 +2320,7 @@ int KABCore::ringSync()
mCurrentSyncProfile = i;
temp->setName(syncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
- if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) {
+ if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
++syncedProfiles;
// KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
@@ -2333,8 +2336,8 @@ int KABCore::ringSync()
syncSharp();
} else {
if ( temp->getIsLocalFileSync() ) {
- if ( syncWithFile( temp->getRemoteFileName( ), true ) )
- KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
+ if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
+ KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
} else {
if ( temp->getIsPhoneSync() ) {
KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
@@ -2373,7 +2376,7 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask)
0, 0 ) != 0 )
return;
}
- QString command = prof->getPreSyncCommand();
+ QString command = prof->getPreSyncCommandAB();
int fi;
if ( (fi = command.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
@@ -2405,13 +2408,13 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask)
}
setCaption ( i18n( "Copying succeed." ) );
//qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
- if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
+ if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
// Event* e = mView->getLastSyncEvent();
// e->setReadOnly( false );
// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
// e->setReadOnly( true );
if ( KABPrefs::instance()->mWriteBackFile ) {
- command = prof->getPostSyncCommand();
+ command = prof->getPostSyncCommandAB();
int fi;
if ( (fi = command.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
@@ -2510,17 +2513,83 @@ QString KABCore::getPassword( )
return retfile;
}
+bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
+{
+}
bool KABCore::syncAB(QString filename, int mode)
{
+
+
+ mGlobalSyncMode = SYNC_MODE_NORMAL;
+ AddressBook abLocal(filename,"syncContact");
+ bool syncOK = false;
+ if ( abLocal.load() ) {
+ qDebug("AB loaded %s mode %d",filename.latin1(), mode );
+ AddressBook::Iterator it;
+ QStringList vcards;
+ for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
+ qDebug("Name %s ", (*it).familyName().latin1());
+ }
+ syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
+ if ( syncOK ) {
+ if ( KABPrefs::instance()->mWriteBackFile )
+ {
+ abLocal.saveAB();
+ }
+ }
+ setModified();
+
+ }
+ if ( syncOK )
+ ;//updateView();
+ return syncOK;
+#if 0
+ mGlobalSyncMode = SYNC_MODE_NORMAL;
+ CalendarLocal* calendar = new CalendarLocal();
+ calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
+ FileStorage* storage = new FileStorage( calendar );
+ bool syncOK = false;
+ storage->setFileName( filename );
+ // qDebug("loading ... ");
+ if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
+ getEventViewerDialog()->setSyncMode( true );
+ syncOK = synchronizeCalendar( mCalendar, calendar, mode );
+ getEventViewerDialog()->setSyncMode( false );
+ if ( syncOK ) {
+ if ( KOPrefs::instance()->mWriteBackFile )
+ {
+ storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
+ storage->save();
+ }
+ }
+ setModified();
+ }
+ delete storage;
+ delete calendar;
+ if ( syncOK )
+ updateView();
+ return syncOK;
+#endif
}
void KABCore::confSync()
-{
- //mView->confSync();
- qDebug("pending KABCore::confSync() ");
+{
+ static KSyncPrefsDialog* sp = 0;
+ if ( ! sp ) {
+ sp = new KSyncPrefsDialog( this, "syncprefs", true );
+ }
+ sp->usrReadConfig();
+#ifndef DESKTOP_VERSION
+ sp->showMaximized();
+#else
+ sp->show();
+#endif
+ sp->exec();
+ KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
+ KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
fillSyncMenu();
}
void KABCore::syncSharp()
@@ -2529,7 +2598,7 @@ void KABCore::syncSharp()
save();
qDebug("pending syncSharp() ");
//mView->syncSharp();
- mModified = true ;
+ setModified();
}
void KABCore::syncPhone()
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 10ce8f4..4487a8a 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -456,7 +456,6 @@ class KABCore : public QWidget
// sync stuff!
QPopupMenu *syncMenu;
void fillSyncMenu();
- void confSync();
QString mCurrentSyncDevice;
QString mCurrentSyncName;
void quickSyncLocalFile();
@@ -471,6 +470,10 @@ class KABCore : public QWidget
bool syncAB(QString filename, int mode);
int ringSync();
QString getPassword( );
+ int mGlobalSyncMode;
+ bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode);
+ public slots:
+ void confSync();
// *********************
};