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
@@ -164,50 +164,50 @@ class KAex2phonePrefs : public QDialog
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)
@@ -673,116 +673,61 @@ void 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;
@@ -2822,91 +2767,94 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
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()