summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index c5406bf..939296f 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -606,213 +606,228 @@ void KABCore::mailVCard( const QStringList& uids )
606 606
607 if ( a.isEmpty() ) 607 if ( a.isEmpty() )
608 continue; 608 continue;
609 609
610 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 610 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
611 611
612 QString fileName = dirName + "/" + name; 612 QString fileName = dirName + "/" + name;
613 613
614 QFile outFile(fileName); 614 QFile outFile(fileName);
615 615
616 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 616 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
617 KABC::VCardConverter converter; 617 KABC::VCardConverter converter;
618 QString vcard; 618 QString vcard;
619 619
620 converter.addresseeToVCard( a, vcard ); 620 converter.addresseeToVCard( a, vcard );
621 621
622 QTextStream t( &outFile ); // use a text stream 622 QTextStream t( &outFile ); // use a text stream
623 t.setEncoding( QTextStream::UnicodeUTF8 ); 623 t.setEncoding( QTextStream::UnicodeUTF8 );
624 t << vcard; 624 t << vcard;
625 625
626 outFile.close(); 626 outFile.close();
627 627
628 urls.append( fileName ); 628 urls.append( fileName );
629 } 629 }
630 } 630 }
631 631
632 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 632 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
633 633
634 634
635/*US 635/*US
636 kapp->invokeMailer( QString::null, QString::null, QString::null, 636 kapp->invokeMailer( QString::null, QString::null, QString::null,
637 QString::null, // subject 637 QString::null, // subject
638 QString::null, // body 638 QString::null, // body
639 QString::null, 639 QString::null,
640 urls ); // attachments 640 urls ); // attachments
641*/ 641*/
642 642
643} 643}
644 644
645/** 645/**
646 Beams the "WhoAmI contact. 646 Beams the "WhoAmI contact.
647*/ 647*/
648void KABCore::beamMySelf() 648void KABCore::beamMySelf()
649{ 649{
650 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 650 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
651 if (!a.isEmpty()) 651 if (!a.isEmpty())
652 { 652 {
653 QStringList uids; 653 QStringList uids;
654 uids << a.uid(); 654 uids << a.uid();
655 655
656 beamVCard(uids); 656 beamVCard(uids);
657 } else { 657 } else {
658 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 658 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
659 659
660 660
661 } 661 }
662} 662}
663 663
664void KABCore::export2phone() 664void KABCore::export2phone()
665{ 665{
666 666
667 KAex2phonePrefs ex2phone; 667 KAex2phonePrefs ex2phone;
668 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 668 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
669 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 669 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
670 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 670 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
671 671
672 if ( !ex2phone.exec() ) { 672 if ( !ex2phone.exec() ) {
673 return; 673 return;
674 } 674 }
675 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 675 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
676 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 676 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
677 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 677 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
678 678
679 679
680 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 680 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
681 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 681 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
682 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 682 KPimGlobalPrefs::instance()->mEx2PhoneModel );
683 683
684 QStringList uids = mViewManager->selectedUids(); 684 QStringList uids = mViewManager->selectedUids();
685 if ( uids.isEmpty() ) 685 if ( uids.isEmpty() )
686 return; 686 return;
687 687
688#ifdef _WIN32_ 688#ifdef _WIN32_
689 QString fileName = locateLocal("tmp", "tempfile.vcf"); 689 QString fileName = locateLocal("tmp", "tempfile.vcf");
690#else 690#else
691 QString fileName = "/tmp/kdepimtemp.vcf"; 691 QString fileName = "/tmp/kdepimtemp.vcf";
692#endif 692#endif
693 693
694 KABC::VCardConverter converter; 694 KABC::VCardConverter converter;
695 QString description; 695 QString description;
696 QString datastream; 696 QString datastream;
697 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 697 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
698 KABC::Addressee a = mAddressBook->findByUid( *it ); 698 KABC::Addressee a = mAddressBook->findByUid( *it );
699 699
700 if ( a.isEmpty() ) 700 if ( a.isEmpty() )
701 continue; 701 continue;
702 a.simplifyEmails();
703 a.simplifyPhoneNumbers();
704 a.simplifyPhoneNumberTypes();
702 705
703 if (description.isEmpty()) 706 if (description.isEmpty())
704 description = a.formattedName(); 707 description = a.formattedName();
705
706 QString vcard; 708 QString vcard;
709 QString vcardnew;
707 converter.addresseeToVCard( a, vcard ); 710 converter.addresseeToVCard( a, vcard );
708 int start = 0; 711 int start = 0;
709 int next; 712 int next;
710 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 713 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
711 int semi = vcard.find(";", next); 714 int semi = vcard.find(";", next);
712 int dopp = vcard.find(":", next); 715 int dopp = vcard.find(":", next);
713 int sep; 716 int sep;
714 if ( semi < dopp && semi >= 0 ) 717 if ( semi < dopp && semi >= 0 )
715 sep = semi ; 718 sep = semi ;
716 else 719 else
717 sep = dopp; 720 sep = dopp;
718 datastream +=vcard.mid( start, next - start); 721 vcardnew +=vcard.mid( start, next - start);
719 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 722 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
720 start = sep; 723 start = sep;
721 } 724 }
722 datastream += vcard.mid( start,vcard.length() ); 725 vcardnew += vcard.mid( start,vcard.length() );
726 vcard = "";
727 start = 0;
728 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
729 int sep = vcardnew.find(":", next);
730 vcard +=vcardnew.mid( start, next - start+3);
731 start = sep;
732 }
733 vcard += vcardnew.mid( start,vcardnew.length() );
734 vcard.replace ( QRegExp(";;;") , "" );
735 vcard.replace ( QRegExp(";;") , "" );
736 datastream += vcard;
737
723 } 738 }
724 QFile outFile(fileName); 739 QFile outFile(fileName);
725 if ( outFile.open(IO_WriteOnly) ) { 740 if ( outFile.open(IO_WriteOnly) ) {
726 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 741 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
727 QTextStream t( &outFile ); // use a text stream 742 QTextStream t( &outFile ); // use a text stream
728 t.setEncoding( QTextStream::UnicodeUTF8 ); 743 t.setEncoding( QTextStream::UnicodeUTF8 );
729 t <<datastream; 744 t <<datastream;
730 outFile.close(); 745 outFile.close();
731 if ( PhoneAccess::writeToPhone( fileName ) ) 746 if ( PhoneAccess::writeToPhone( fileName ) )
732 qDebug("Export okay "); 747 qDebug("Export okay ");
733 else 748 else
734 qDebug("Error export contacts "); 749 qDebug("Error export contacts ");
735 750
736 } else { 751 } else {
737 qDebug("Error open temp file "); 752 qDebug("Error open temp file ");
738 return; 753 return;
739 } 754 }
740 755
741 756
742#if 0 757#if 0
743 758
744 setCaption( i18n("Writing to phone...")); 759 setCaption( i18n("Writing to phone..."));
745 if ( PhoneFormat::writeToPhone( cal ) ) 760 if ( PhoneFormat::writeToPhone( cal ) )
746 setCaption( i18n("Export to phone successful!")); 761 setCaption( i18n("Export to phone successful!"));
747 else 762 else
748 setCaption( i18n("Error exporting to phone!")); 763 setCaption( i18n("Error exporting to phone!"));
749#endif 764#endif
750 765
751 766
752} 767}
753void KABCore::beamVCard() 768void KABCore::beamVCard()
754{ 769{
755 QStringList uids = mViewManager->selectedUids(); 770 QStringList uids = mViewManager->selectedUids();
756 if ( !uids.isEmpty() ) 771 if ( !uids.isEmpty() )
757 beamVCard( uids ); 772 beamVCard( uids );
758} 773}
759 774
760 775
761void KABCore::beamVCard(const QStringList& uids) 776void KABCore::beamVCard(const QStringList& uids)
762{ 777{
763/*US 778/*US
764 QString beamFilename; 779 QString beamFilename;
765 Opie::OPimContact c; 780 Opie::OPimContact c;
766 if ( actionPersonal->isOn() ) { 781 if ( actionPersonal->isOn() ) {
767 beamFilename = addressbookPersonalVCardName(); 782 beamFilename = addressbookPersonalVCardName();
768 if ( !QFile::exists( beamFilename ) ) 783 if ( !QFile::exists( beamFilename ) )
769 return; // can't beam a non-existent file 784 return; // can't beam a non-existent file
770 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 785 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
771 beamFilename ); 786 beamFilename );
772 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 787 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
773 Opie::OPimContactAccess::List allList = access->allRecords(); 788 Opie::OPimContactAccess::List allList = access->allRecords();
774 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 789 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
775 c = *it; 790 c = *it;
776 791
777 delete access; 792 delete access;
778 } else { 793 } else {
779 unlink( beamfile ); // delete if exists 794 unlink( beamfile ); // delete if exists
780 mkdir("/tmp/obex/", 0755); 795 mkdir("/tmp/obex/", 0755);
781 c = m_abView -> currentEntry(); 796 c = m_abView -> currentEntry();
782 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 797 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
783 beamfile ); 798 beamfile );
784 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 799 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
785 access->add( c ); 800 access->add( c );
786 access->save(); 801 access->save();
787 delete access; 802 delete access;
788 803
789 beamFilename = beamfile; 804 beamFilename = beamfile;
790 } 805 }
791 806
792 owarn << "Beaming: " << beamFilename << oendl; 807 owarn << "Beaming: " << beamFilename << oendl;
793*/ 808*/
794 809
795#if 0 810#if 0
796 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 811 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
797 812
798 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 813 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
799 814
800 QString name = "contact.vcf"; 815 QString name = "contact.vcf";
801 816
802 QString fileName = dirName + "/" + name; 817 QString fileName = dirName + "/" + name;
803#endif 818#endif
804 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 819 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
805 // 820 //
806 QString fileName = "/tmp/kapibeamfile.vcf"; 821 QString fileName = "/tmp/kapibeamfile.vcf";
807 822
808 823
809 //QDir().mkdir( dirName, true ); 824 //QDir().mkdir( dirName, true );
810 825
811 826
812 KABC::VCardConverter converter; 827 KABC::VCardConverter converter;
813 QString description; 828 QString description;
814 QString datastream; 829 QString datastream;
815 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 830 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
816 KABC::Addressee a = mAddressBook->findByUid( *it ); 831 KABC::Addressee a = mAddressBook->findByUid( *it );
817 832
818 if ( a.isEmpty() ) 833 if ( a.isEmpty() )