-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 | |||
@@ -182,14 +182,14 @@ class KAex2phonePrefs : public QDialog | |||
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 ); |
@@ -691,80 +691,25 @@ void KABCore::export2phone() | |||
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!")); |
@@ -2840,12 +2785,13 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) | |||
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 | } |
@@ -2872,23 +2818,25 @@ bool KABCore::syncPhone() | |||
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 ) |