-rw-r--r-- | kaddressbook/kabcore.cpp | 86 |
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 | |||
@@ -176,26 +176,26 @@ class KAex2phonePrefs : public QDialog | |||
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 | ||
@@ -685,92 +685,37 @@ void KABCore::export2phone() | |||
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 | } |
@@ -2834,24 +2779,25 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) | |||
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 | } |
2857 | void KABCore::message( QString m ) | 2803 | void KABCore::message( QString m ) |
@@ -2866,35 +2812,37 @@ bool KABCore::syncPhone() | |||
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 | } |
2898 | void KABCore::getFile( bool success ) | 2846 | void KABCore::getFile( bool success ) |
2899 | { | 2847 | { |
2900 | if ( ! success ) { | 2848 | if ( ! success ) { |