summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp86
1 files changed, 17 insertions, 69 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -140,98 +140,98 @@ $Id$
140#include "undocmds.h" 140#include "undocmds.h"
141#include "addresseeeditordialog.h" 141#include "addresseeeditordialog.h"
142#include "viewmanager.h" 142#include "viewmanager.h"
143#include "details/detailsviewcontainer.h" 143#include "details/detailsviewcontainer.h"
144#include "kabprefs.h" 144#include "kabprefs.h"
145#include "xxportmanager.h" 145#include "xxportmanager.h"
146#include "incsearchwidget.h" 146#include "incsearchwidget.h"
147#include "jumpbuttonbar.h" 147#include "jumpbuttonbar.h"
148#include "extensionmanager.h" 148#include "extensionmanager.h"
149#include "addresseeconfig.h" 149#include "addresseeconfig.h"
150#include <kcmultidialog.h> 150#include <kcmultidialog.h>
151 151
152#ifdef _WIN32_ 152#ifdef _WIN32_
153 153
154#include "kaimportoldialog.h" 154#include "kaimportoldialog.h"
155#else 155#else
156#include <unistd.h> 156#include <unistd.h>
157#endif 157#endif
158// sync includes 158// sync includes
159#include <libkdepim/ksyncprofile.h> 159#include <libkdepim/ksyncprofile.h>
160#include <libkdepim/ksyncprefsdialog.h> 160#include <libkdepim/ksyncprefsdialog.h>
161 161
162class KAex2phonePrefs : public QDialog 162class KAex2phonePrefs : public QDialog
163{ 163{
164 public: 164 public:
165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
166 QDialog( parent, name, true ) 166 QDialog( parent, name, true )
167 { 167 {
168 setCaption( i18n("Export to phone options") ); 168 setCaption( i18n("Export to phone options") );
169 QVBoxLayout* lay = new QVBoxLayout( this ); 169 QVBoxLayout* lay = new QVBoxLayout( this );
170 lay->setSpacing( 3 ); 170 lay->setSpacing( 3 );
171 lay->setMargin( 3 ); 171 lay->setMargin( 3 );
172 QLabel *lab; 172 QLabel *lab;
173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
174 lab->setAlignment (AlignHCenter ); 174 lab->setAlignment (AlignHCenter );
175 QHBox* temphb; 175 QHBox* temphb;
176 temphb = new QHBox( this ); 176 temphb = new QHBox( this );
177 new QLabel( i18n("I/O device: "), temphb ); 177 new QLabel( i18n("I/O device: "), temphb );
178 mPhoneDevice = new QLineEdit( temphb); 178 mPhoneDevice = new QLineEdit( temphb);
179 lay->addWidget( temphb ); 179 lay->addWidget( temphb );
180 temphb = new QHBox( this ); 180 temphb = new QHBox( this );
181 new QLabel( i18n("Connection: "), temphb ); 181 new QLabel( i18n("Connection: "), temphb );
182 mPhoneConnection = new QLineEdit( temphb); 182 mPhoneConnection = new QLineEdit( temphb);
183 lay->addWidget( temphb ); 183 lay->addWidget( temphb );
184 temphb = new QHBox( this ); 184 temphb = new QHBox( this );
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
193 lay->addWidget( ok ); 193 lay->addWidget( ok );
194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
195 lay->addWidget( cancel ); 195 lay->addWidget( cancel );
196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
198 resize( 220, 240 ); 198 resize( 220, 240 );
199 199
200 } 200 }
201 201
202public: 202public:
203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
204 QCheckBox* mWriteToSim; 204 QCheckBox* mWriteToSim;
205}; 205};
206 206
207bool pasteWithNewUid = true; 207bool pasteWithNewUid = true;
208 208
209#ifdef KAB_EMBEDDED 209#ifdef KAB_EMBEDDED
210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
214#else //KAB_EMBEDDED 214#else //KAB_EMBEDDED
215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
218 mReadWrite( readWrite ), mModified( false ) 218 mReadWrite( readWrite ), mModified( false )
219#endif //KAB_EMBEDDED 219#endif //KAB_EMBEDDED
220{ 220{
221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
222 // syncManager->setBlockSave(false); 222 // syncManager->setBlockSave(false);
223 mExtensionBarSplitter = 0; 223 mExtensionBarSplitter = 0;
224 mIsPart = !parent->inherits( "KAddressBookMain" ); 224 mIsPart = !parent->inherits( "KAddressBookMain" );
225 225
226 mAddressBook = KABC::StdAddressBook::self(); 226 mAddressBook = KABC::StdAddressBook::self();
227 KABC::StdAddressBook::setAutomaticSave( false ); 227 KABC::StdAddressBook::setAutomaticSave( false );
228 228
229#ifndef KAB_EMBEDDED 229#ifndef KAB_EMBEDDED
230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
231#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
232 232
233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
234 SLOT( addressBookChanged() ) ); 234 SLOT( addressBookChanged() ) );
235 235
236#if 0 236#if 0
237 // LP moved to addressbook init method 237 // LP moved to addressbook init method
@@ -649,164 +649,109 @@ void KABCore::mailVCard( const QStringList& uids )
649*/ 649*/
650 650
651} 651}
652 652
653/** 653/**
654 Beams the "WhoAmI contact. 654 Beams the "WhoAmI contact.
655*/ 655*/
656void KABCore::beamMySelf() 656void KABCore::beamMySelf()
657{ 657{
658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
659 if (!a.isEmpty()) 659 if (!a.isEmpty())
660 { 660 {
661 QStringList uids; 661 QStringList uids;
662 uids << a.uid(); 662 uids << a.uid();
663 663
664 beamVCard(uids); 664 beamVCard(uids);
665 } else { 665 } else {
666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
667 667
668 668
669 } 669 }
670} 670}
671 671
672void KABCore::export2phone() 672void KABCore::export2phone()
673{ 673{
674 674
675 KAex2phonePrefs ex2phone; 675 KAex2phonePrefs ex2phone;
676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
679 679
680 if ( !ex2phone.exec() ) { 680 if ( !ex2phone.exec() ) {
681 return; 681 return;
682 } 682 }
683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
686 686
687 687
688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
689 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 689 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
690 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 690 KPimGlobalPrefs::instance()->mEx2PhoneModel );
691 691
692 QStringList uids = mViewManager->selectedUids(); 692 QStringList uids = mViewManager->selectedUids();
693 if ( uids.isEmpty() ) 693 if ( uids.isEmpty() )
694 return; 694 return;
695 695
696#ifdef _WIN32_ 696#ifdef _WIN32_
697 QString fileName = locateLocal("tmp", "tempfile.vcf"); 697 QString fileName = locateLocal("tmp", "phonefile.vcf");
698#else 698#else
699 QString fileName = "/tmp/kdepimtemp.vcf"; 699 QString fileName = "/tmp/phonefile.vcf";
700#endif 700#endif
701 701
702 KABC::VCardConverter converter; 702 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
703 QString description;
704 QString datastream;
705 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
706 KABC::Addressee a = mAddressBook->findByUid( *it );
707
708 if ( a.isEmpty() )
709 continue;
710 a.simplifyEmails();
711 a.simplifyPhoneNumbers();
712 a.simplifyPhoneNumberTypes();
713 a.simplifyAddresses();
714
715 if (description.isEmpty())
716 description = a.formattedName();
717 QString vcard;
718 QString vcardnew;
719 converter.addresseeToVCard( a, vcard );
720 int start = 0;
721 int next;
722 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
723 int semi = vcard.find(";", next);
724 int dopp = vcard.find(":", next);
725 int sep;
726 if ( semi < dopp && semi >= 0 )
727 sep = semi ;
728 else
729 sep = dopp;
730 vcardnew +=vcard.mid( start, next - start);
731 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
732 start = sep;
733 }
734 vcardnew += vcard.mid( start,vcard.length() );
735 vcard = "";
736 start = 0;
737 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
738 int sep = vcardnew.find(":", next);
739 vcard +=vcardnew.mid( start, next - start+3);
740 start = sep;
741 }
742 vcard += vcardnew.mid( start,vcardnew.length() );
743 vcard.replace ( QRegExp(";;;") , "" );
744 vcard.replace ( QRegExp(";;") , "" );
745 datastream += vcard;
746
747 }
748 QFile outFile(fileName);
749 if ( outFile.open(IO_WriteOnly) ) {
750 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
751 QTextStream t( &outFile ); // use a text stream
752 t.setEncoding( QTextStream::UnicodeUTF8 );
753 t <<datastream;
754 outFile.close();
755 if ( PhoneAccess::writeToPhone( fileName ) )
756 qDebug("Export okay ");
757 else
758 qDebug("Error export contacts ");
759
760 } else {
761 qDebug("Error open temp file ");
762 return; 703 return;
763 } 704
764 705 if ( PhoneAccess::writeToPhone( fileName ) )
706 qDebug("Export okay ");
707 else
708 qDebug("Error export contacts ");
709
765 710
766#if 0 711#if 0
767 712
768 setCaption( i18n("Writing to phone...")); 713 setCaption( i18n("Writing to phone..."));
769 if ( PhoneFormat::writeToPhone( cal ) ) 714 if ( PhoneFormat::writeToPhone( cal ) )
770 setCaption( i18n("Export to phone successful!")); 715 setCaption( i18n("Export to phone successful!"));
771 else 716 else
772 setCaption( i18n("Error exporting to phone!")); 717 setCaption( i18n("Error exporting to phone!"));
773#endif 718#endif
774 719
775 720
776} 721}
777void KABCore::beamVCard() 722void KABCore::beamVCard()
778{ 723{
779 QStringList uids = mViewManager->selectedUids(); 724 QStringList uids = mViewManager->selectedUids();
780 if ( !uids.isEmpty() ) 725 if ( !uids.isEmpty() )
781 beamVCard( uids ); 726 beamVCard( uids );
782} 727}
783 728
784 729
785void KABCore::beamVCard(const QStringList& uids) 730void KABCore::beamVCard(const QStringList& uids)
786{ 731{
787/*US 732/*US
788 QString beamFilename; 733 QString beamFilename;
789 Opie::OPimContact c; 734 Opie::OPimContact c;
790 if ( actionPersonal->isOn() ) { 735 if ( actionPersonal->isOn() ) {
791 beamFilename = addressbookPersonalVCardName(); 736 beamFilename = addressbookPersonalVCardName();
792 if ( !QFile::exists( beamFilename ) ) 737 if ( !QFile::exists( beamFilename ) )
793 return; // can't beam a non-existent file 738 return; // can't beam a non-existent file
794 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 739 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
795 beamFilename ); 740 beamFilename );
796 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 741 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
797 Opie::OPimContactAccess::List allList = access->allRecords(); 742 Opie::OPimContactAccess::List allList = access->allRecords();
798 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 743 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
799 c = *it; 744 c = *it;
800 745
801 delete access; 746 delete access;
802 } else { 747 } else {
803 unlink( beamfile ); // delete if exists 748 unlink( beamfile ); // delete if exists
804 mkdir("/tmp/obex/", 0755); 749 mkdir("/tmp/obex/", 0755);
805 c = m_abView -> currentEntry(); 750 c = m_abView -> currentEntry();
806 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 751 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
807 beamfile ); 752 beamfile );
808 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 753 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
809 access->add( c ); 754 access->add( c );
810 access->save(); 755 access->save();
811 delete access; 756 delete access;
812 757
@@ -2798,127 +2743,130 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2798 } 2743 }
2799 } 2744 }
2800 //AddressBook::Iterator it; 2745 //AddressBook::Iterator it;
2801 //QStringList vcards; 2746 //QStringList vcards;
2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2747 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2803 // qDebug("Name %s ", (*it).familyName().latin1()); 2748 // qDebug("Name %s ", (*it).familyName().latin1());
2804 //} 2749 //}
2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2750 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2806 if ( syncOK ) { 2751 if ( syncOK ) {
2807 if ( syncManager->mWriteBackFile ) 2752 if ( syncManager->mWriteBackFile )
2808 { 2753 {
2809 if ( external ) 2754 if ( external )
2810 abLocal.removeSyncAddressees( !isXML); 2755 abLocal.removeSyncAddressees( !isXML);
2811 qDebug("Saving remote AB "); 2756 qDebug("Saving remote AB ");
2812 if ( ! abLocal.saveAB()) 2757 if ( ! abLocal.saveAB())
2813 qDebug("Error writing back AB to file "); 2758 qDebug("Error writing back AB to file ");
2814 if ( isXML ) { 2759 if ( isXML ) {
2815 // afterwrite processing 2760 // afterwrite processing
2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2761 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2817 } 2762 }
2818 } 2763 }
2819 } 2764 }
2820 setModified(); 2765 setModified();
2821 2766
2822 } 2767 }
2823 if ( syncOK ) 2768 if ( syncOK )
2824 mViewManager->refreshView(); 2769 mViewManager->refreshView();
2825 return syncOK; 2770 return syncOK;
2826 2771
2827} 2772}
2828 2773
2829 2774
2830//this is a overwritten callbackmethods from the syncinterface 2775//this is a overwritten callbackmethods from the syncinterface
2831bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2776bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2832{ 2777{
2833 if ( resource == "phone" ) 2778 if ( resource == "phone" )
2834 return syncPhone(); 2779 return syncPhone();
2835 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2780 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2836 2781
2837 AddressBook abLocal( resource,"syncContact"); 2782 AddressBook abLocal( resource,"syncContact");
2838 bool syncOK = false; 2783 bool syncOK = false;
2839 if ( abLocal.load() ) { 2784 if ( abLocal.load() ) {
2840 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2785 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2841 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2842 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2787 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2843 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2788 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2844 if ( syncOK ) { 2789 if ( syncOK ) {
2845 if ( syncManager->mWriteBackFile ) { 2790 if ( syncManager->mWriteBackFile ) {
2791 abLocal.removeSyncAddressees( false );
2846 abLocal.saveAB(); 2792 abLocal.saveAB();
2847 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2793 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2848 } 2794 }
2849 } 2795 }
2850 setModified(); 2796 setModified();
2851 } 2797 }
2852 if ( syncOK ) 2798 if ( syncOK )
2853 mViewManager->refreshView(); 2799 mViewManager->refreshView();
2854 return syncOK; 2800 return syncOK;
2855 2801
2856} 2802}
2857void KABCore::message( QString m ) 2803void KABCore::message( QString m )
2858{ 2804{
2859 2805
2860 topLevelWidget()->setCaption( m ); 2806 topLevelWidget()->setCaption( m );
2861 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2807 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2862} 2808}
2863bool KABCore::syncPhone() 2809bool KABCore::syncPhone()
2864{ 2810{
2865 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2811 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2866 QString fileName; 2812 QString fileName;
2867#ifdef _WIN32_ 2813#ifdef _WIN32_
2868 fileName = locateLocal("tmp", "phonefile.vcf"); 2814 fileName = locateLocal("tmp", "phonefile.vcf");
2869#else 2815#else
2870 fileName = "/tmp/phonefile.vcf"; 2816 fileName = "/tmp/phonefile.vcf";
2871#endif 2817#endif
2872 if ( !PhoneAccess::readFromPhone( fileName) ) { 2818 if ( !PhoneAccess::readFromPhone( fileName) ) {
2873 message(i18n("Phone access failed!")); 2819 message(i18n("Phone access failed!"));
2874 return false; 2820 return false;
2875 } 2821 }
2876 AddressBook abLocal( fileName,"syncContact"); 2822 AddressBook abLocal( fileName,"syncContact");
2877 bool syncOK = false; 2823 bool syncOK = false;
2878 if ( abLocal.load() ) { 2824 {
2825 abLocal.importFromFile( fileName );
2879 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2826 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2880 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2827 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2881 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2828 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2882 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2829 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2883 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2830 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2884 if ( syncOK ) { 2831 if ( syncOK ) {
2885 if ( syncManager->mWriteBackFile ) { 2832 if ( syncManager->mWriteBackFile ) {
2833 abLocal.removeSyncAddressees( true );
2886 abLocal.saveABphone( fileName ); 2834 abLocal.saveABphone( fileName );
2887 abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2835 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2836 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2889 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2837 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2890 } 2838 }
2891 } 2839 }
2892 setModified(); 2840 setModified();
2893 } 2841 }
2894 if ( syncOK ) 2842 if ( syncOK )
2895 mViewManager->refreshView(); 2843 mViewManager->refreshView();
2896 return syncOK; 2844 return syncOK;
2897} 2845}
2898void KABCore::getFile( bool success ) 2846void KABCore::getFile( bool success )
2899{ 2847{
2900 if ( ! success ) { 2848 if ( ! success ) {
2901 message( i18n("Error receiving file. Nothing changed!") ); 2849 message( i18n("Error receiving file. Nothing changed!") );
2902 return; 2850 return;
2903 } 2851 }
2904 mAddressBook->importFromFile( sentSyncFile() , false, true ); 2852 mAddressBook->importFromFile( sentSyncFile() , false, true );
2905 message( i18n("Pi-Sync successful!") ); 2853 message( i18n("Pi-Sync successful!") );
2906 mViewManager->refreshView(); 2854 mViewManager->refreshView();
2907} 2855}
2908void KABCore::syncFileRequest() 2856void KABCore::syncFileRequest()
2909{ 2857{
2910 mAddressBook->export2File( sentSyncFile() ); 2858 mAddressBook->export2File( sentSyncFile() );
2911} 2859}
2912QString KABCore::sentSyncFile() 2860QString KABCore::sentSyncFile()
2913{ 2861{
2914#ifdef _WIN32_ 2862#ifdef _WIN32_
2915 return locateLocal( "tmp", "copysyncab.vcf" ); 2863 return locateLocal( "tmp", "copysyncab.vcf" );
2916#else 2864#else
2917 return QString( "/tmp/copysyncab.vcf" ); 2865 return QString( "/tmp/copysyncab.vcf" );
2918#endif 2866#endif
2919} 2867}
2920 2868
2921void KABCore::setCaptionBack() 2869void KABCore::setCaptionBack()
2922{ 2870{
2923 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2871 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2924} 2872}