-rw-r--r-- | kaddressbook/kabcore.cpp | 57 |
1 files changed, 9 insertions, 48 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 2e408b7..11eeabc 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -663,169 +663,130 @@ void KABCore::beamMySelf() | |||
663 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | 663 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); |
664 | if (!a.isEmpty()) | 664 | if (!a.isEmpty()) |
665 | { | 665 | { |
666 | QStringList uids; | 666 | QStringList uids; |
667 | uids << a.uid(); | 667 | uids << a.uid(); |
668 | 668 | ||
669 | beamVCard(uids); | 669 | beamVCard(uids); |
670 | } else { | 670 | } else { |
671 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 671 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
672 | 672 | ||
673 | 673 | ||
674 | } | 674 | } |
675 | } | 675 | } |
676 | 676 | ||
677 | void KABCore::export2phone() | 677 | void KABCore::export2phone() |
678 | { | 678 | { |
679 | 679 | ||
680 | KAex2phonePrefs ex2phone; | 680 | KAex2phonePrefs ex2phone; |
681 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); | 681 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); |
682 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); | 682 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); |
683 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 683 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
684 | 684 | ||
685 | if ( !ex2phone.exec() ) { | 685 | if ( !ex2phone.exec() ) { |
686 | return; | 686 | return; |
687 | } | 687 | } |
688 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); | 688 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); |
689 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); | 689 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); |
690 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); | 690 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); |
691 | 691 | ||
692 | 692 | ||
693 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, | 693 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, |
694 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, | 694 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, |
695 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 695 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
696 | 696 | ||
697 | QStringList uids = mViewManager->selectedUids(); | 697 | QStringList uids = mViewManager->selectedUids(); |
698 | if ( uids.isEmpty() ) | 698 | if ( uids.isEmpty() ) |
699 | return; | 699 | return; |
700 | 700 | ||
701 | QString fileName = getPhoneFile(); | 701 | QString fileName = getPhoneFile(); |
702 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) | 702 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) |
703 | return; | 703 | return; |
704 | 704 | ||
705 | message(i18n("Exporting to phone...")); | 705 | message(i18n("Exporting to phone...")); |
706 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); | 706 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); |
707 | 707 | ||
708 | } | 708 | } |
709 | QString KABCore::getPhoneFile() | 709 | QString KABCore::getPhoneFile() |
710 | { | 710 | { |
711 | #ifdef _WIN32_ | 711 | #ifdef DESKTOP_VERSION |
712 | return locateLocal("tmp", "phonefile.vcf"); | 712 | return locateLocal("tmp", "phonefile.vcf"); |
713 | #else | 713 | #else |
714 | return "/tmp/phonefile.vcf"; | 714 | return "/tmp/phonefile.vcf"; |
715 | #endif | 715 | #endif |
716 | 716 | ||
717 | } | 717 | } |
718 | void KABCore::writeToPhone( ) | 718 | void KABCore::writeToPhone( ) |
719 | { | 719 | { |
720 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) | 720 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) |
721 | message(i18n("Export to phone finished!")); | 721 | message(i18n("Export to phone finished!")); |
722 | else | 722 | else |
723 | qDebug(i18n("Error exporting to phone")); | 723 | qDebug(i18n("Error exporting to phone")); |
724 | } | 724 | } |
725 | void KABCore::beamVCard() | 725 | void KABCore::beamVCard() |
726 | { | 726 | { |
727 | QStringList uids = mViewManager->selectedUids(); | 727 | QStringList uids = mViewManager->selectedUids(); |
728 | if ( !uids.isEmpty() ) | 728 | if ( !uids.isEmpty() ) |
729 | beamVCard( uids ); | 729 | beamVCard( uids ); |
730 | } | 730 | } |
731 | 731 | ||
732 | 732 | ||
733 | void KABCore::beamVCard(const QStringList& uids) | 733 | void KABCore::beamVCard(const QStringList& uids) |
734 | { | 734 | { |
735 | /*US | ||
736 | QString beamFilename; | ||
737 | Opie::OPimContact c; | ||
738 | if ( actionPersonal->isOn() ) { | ||
739 | beamFilename = addressbookPersonalVCardName(); | ||
740 | if ( !QFile::exists( beamFilename ) ) | ||
741 | return; // can't beam a non-existent file | ||
742 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
743 | beamFilename ); | ||
744 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
745 | Opie::OPimContactAccess::List allList = access->allRecords(); | ||
746 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | ||
747 | c = *it; | ||
748 | |||
749 | delete access; | ||
750 | } else { | ||
751 | unlink( beamfile ); // delete if exists | ||
752 | mkdir("/tmp/obex/", 0755); | ||
753 | c = m_abView -> currentEntry(); | ||
754 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
755 | beamfile ); | ||
756 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
757 | access->add( c ); | ||
758 | access->save(); | ||
759 | delete access; | ||
760 | |||
761 | beamFilename = beamfile; | ||
762 | } | ||
763 | |||
764 | owarn << "Beaming: " << beamFilename << oendl; | ||
765 | */ | ||
766 | |||
767 | #if 0 | ||
768 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | ||
769 | |||
770 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); | ||
771 | |||
772 | QString name = "contact.vcf"; | ||
773 | 735 | ||
774 | QString fileName = dirName + "/" + name; | 736 | // LR: we should use the /tmp dir on the Zaurus, |
775 | #endif | 737 | // because: /tmp = RAM, (HOME)/kdepim = flash memory |
776 | // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory | 738 | |
777 | // | 739 | #ifdef DESKTOP_VERSION |
740 | QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); | ||
741 | #else | ||
778 | QString fileName = "/tmp/kapibeamfile.vcf"; | 742 | QString fileName = "/tmp/kapibeamfile.vcf"; |
743 | #endif | ||
779 | 744 | ||
780 | |||
781 | //QDir().mkdir( dirName, true ); | ||
782 | |||
783 | |||
784 | KABC::VCardConverter converter; | 745 | KABC::VCardConverter converter; |
785 | QString description; | 746 | QString description; |
786 | QString datastream; | 747 | QString datastream; |
787 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 748 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
788 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 749 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
789 | 750 | ||
790 | if ( a.isEmpty() ) | 751 | if ( a.isEmpty() ) |
791 | continue; | 752 | continue; |
792 | 753 | ||
793 | if (description.isEmpty()) | 754 | if (description.isEmpty()) |
794 | description = a.formattedName(); | 755 | description = a.formattedName(); |
795 | 756 | ||
796 | QString vcard; | 757 | QString vcard; |
797 | converter.addresseeToVCard( a, vcard ); | 758 | converter.addresseeToVCard( a, vcard ); |
798 | int start = 0; | 759 | int start = 0; |
799 | int next; | 760 | int next; |
800 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 761 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
801 | int semi = vcard.find(";", next); | 762 | int semi = vcard.find(";", next); |
802 | int dopp = vcard.find(":", next); | 763 | int dopp = vcard.find(":", next); |
803 | int sep; | 764 | int sep; |
804 | if ( semi < dopp && semi >= 0 ) | 765 | if ( semi < dopp && semi >= 0 ) |
805 | sep = semi ; | 766 | sep = semi ; |
806 | else | 767 | else |
807 | sep = dopp; | 768 | sep = dopp; |
808 | datastream +=vcard.mid( start, next - start); | 769 | datastream +=vcard.mid( start, next - start); |
809 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | 770 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); |
810 | start = sep; | 771 | start = sep; |
811 | } | 772 | } |
812 | datastream += vcard.mid( start,vcard.length() ); | 773 | datastream += vcard.mid( start,vcard.length() ); |
813 | } | 774 | } |
814 | #ifndef DESKTOP_VERSION | 775 | #ifndef DESKTOP_VERSION |
815 | QFile outFile(fileName); | 776 | QFile outFile(fileName); |
816 | if ( outFile.open(IO_WriteOnly) ) { | 777 | if ( outFile.open(IO_WriteOnly) ) { |
817 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 778 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
818 | QTextStream t( &outFile ); // use a text stream | 779 | QTextStream t( &outFile ); // use a text stream |
819 | //t.setEncoding( QTextStream::UnicodeUTF8 ); | 780 | //t.setEncoding( QTextStream::UnicodeUTF8 ); |
820 | t.setEncoding( QTextStream::Latin1 ); | 781 | t.setEncoding( QTextStream::Latin1 ); |
821 | t <<datastream.latin1(); | 782 | t <<datastream.latin1(); |
822 | outFile.close(); | 783 | outFile.close(); |
823 | Ir *ir = new Ir( this ); | 784 | Ir *ir = new Ir( this ); |
824 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 785 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
825 | ir->send( fileName, description, "text/x-vCard" ); | 786 | ir->send( fileName, description, "text/x-vCard" ); |
826 | } else { | 787 | } else { |
827 | qDebug("Error open temp beam file "); | 788 | qDebug("Error open temp beam file "); |
828 | return; | 789 | return; |
829 | } | 790 | } |
830 | #endif | 791 | #endif |
831 | 792 | ||
@@ -2817,60 +2778,60 @@ void KABCore::message( QString m ) | |||
2817 | bool KABCore::syncPhone() | 2778 | bool KABCore::syncPhone() |
2818 | { | 2779 | { |
2819 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2780 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2820 | QString fileName = getPhoneFile(); | 2781 | QString fileName = getPhoneFile(); |
2821 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2782 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2822 | message(i18n("Phone access failed!")); | 2783 | message(i18n("Phone access failed!")); |
2823 | return false; | 2784 | return false; |
2824 | } | 2785 | } |
2825 | AddressBook abLocal( fileName,"syncContact"); | 2786 | AddressBook abLocal( fileName,"syncContact"); |
2826 | bool syncOK = false; | 2787 | bool syncOK = false; |
2827 | { | 2788 | { |
2828 | abLocal.importFromFile( fileName ); | 2789 | abLocal.importFromFile( fileName ); |
2829 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2790 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2830 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2791 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2831 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2792 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2832 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2793 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2833 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2794 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2834 | if ( syncOK ) { | 2795 | if ( syncOK ) { |
2835 | if ( syncManager->mWriteBackFile ) { | 2796 | if ( syncManager->mWriteBackFile ) { |
2836 | abLocal.removeSyncAddressees( true ); | 2797 | abLocal.removeSyncAddressees( true ); |
2837 | abLocal.saveABphone( fileName ); | 2798 | abLocal.saveABphone( fileName ); |
2838 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2799 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2839 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2800 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2840 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2801 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2841 | } | 2802 | } |
2842 | } | 2803 | } |
2843 | setModified(); | 2804 | setModified(); |
2844 | } | 2805 | } |
2845 | if ( syncOK ) | 2806 | if ( syncOK ) |
2846 | mViewManager->refreshView(); | 2807 | mViewManager->refreshView(); |
2847 | return syncOK; | 2808 | return syncOK; |
2848 | } | 2809 | } |
2849 | void KABCore::getFile( bool success ) | 2810 | void KABCore::getFile( bool success ) |
2850 | { | 2811 | { |
2851 | if ( ! success ) { | 2812 | if ( ! success ) { |
2852 | message( i18n("Error receiving file. Nothing changed!") ); | 2813 | message( i18n("Error receiving file. Nothing changed!") ); |
2853 | return; | 2814 | return; |
2854 | } | 2815 | } |
2855 | mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2816 | mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2856 | message( i18n("Pi-Sync successful!") ); | 2817 | message( i18n("Pi-Sync successful!") ); |
2857 | mViewManager->refreshView(); | 2818 | mViewManager->refreshView(); |
2858 | } | 2819 | } |
2859 | void KABCore::syncFileRequest() | 2820 | void KABCore::syncFileRequest() |
2860 | { | 2821 | { |
2861 | mAddressBook->export2File( sentSyncFile() ); | 2822 | mAddressBook->export2File( sentSyncFile() ); |
2862 | } | 2823 | } |
2863 | QString KABCore::sentSyncFile() | 2824 | QString KABCore::sentSyncFile() |
2864 | { | 2825 | { |
2865 | #ifdef _WIN32_ | 2826 | #ifdef DESKTOP_VERSION |
2866 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2827 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2867 | #else | 2828 | #else |
2868 | return QString( "/tmp/copysyncab.vcf" ); | 2829 | return QString( "/tmp/copysyncab.vcf" ); |
2869 | #endif | 2830 | #endif |
2870 | } | 2831 | } |
2871 | 2832 | ||
2872 | void KABCore::setCaptionBack() | 2833 | void KABCore::setCaptionBack() |
2873 | { | 2834 | { |
2874 | mMessageTimer->stop(); | 2835 | mMessageTimer->stop(); |
2875 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2836 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2876 | } | 2837 | } |