summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-09-08 09:57:16 (UTC)
committer zautrix <zautrix>2004-09-08 09:57:16 (UTC)
commit848c77f86b7105095b27a6034a0fefac8a7a0891 (patch) (unidiff)
tree2816ee9a05000ccabc43d3c9be4558053bfc8c0b /kaddressbook
parent6650dd66dd13498a6d28844770d9d8c291335ad4 (diff)
downloadkdepimpi-848c77f86b7105095b27a6034a0fefac8a7a0891.zip
kdepimpi-848c77f86b7105095b27a6034a0fefac8a7a0891.tar.gz
kdepimpi-848c77f86b7105095b27a6034a0fefac8a7a0891.tar.bz2
Beam vcard fix
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 6538295..d1d385c 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -549,226 +549,238 @@ void KABCore::mailVCard( const QStringList& uids )
549 outFile.close(); 549 outFile.close();
550 550
551 urls.append( fileName ); 551 urls.append( fileName );
552 } 552 }
553 } 553 }
554 554
555 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 555 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
556 556
557 557
558/*US 558/*US
559 kapp->invokeMailer( QString::null, QString::null, QString::null, 559 kapp->invokeMailer( QString::null, QString::null, QString::null,
560 QString::null, // subject 560 QString::null, // subject
561 QString::null, // body 561 QString::null, // body
562 QString::null, 562 QString::null,
563 urls ); // attachments 563 urls ); // attachments
564*/ 564*/
565 565
566} 566}
567 567
568/** 568/**
569 Beams the "WhoAmI contact. 569 Beams the "WhoAmI contact.
570*/ 570*/
571void KABCore::beamMySelf() 571void KABCore::beamMySelf()
572{ 572{
573 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 573 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
574 if (!a.isEmpty()) 574 if (!a.isEmpty())
575 { 575 {
576 QStringList uids; 576 QStringList uids;
577 uids << a.uid(); 577 uids << a.uid();
578 578
579 beamVCard(uids); 579 beamVCard(uids);
580 } else { 580 } else {
581 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 581 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
582 582
583 583
584 } 584 }
585} 585}
586 586
587void KABCore::beamVCard() 587void KABCore::beamVCard()
588{ 588{
589 QStringList uids = mViewManager->selectedUids(); 589 QStringList uids = mViewManager->selectedUids();
590 if ( !uids.isEmpty() ) 590 if ( !uids.isEmpty() )
591 beamVCard( uids ); 591 beamVCard( uids );
592} 592}
593 593
594 594
595void KABCore::beamVCard(const QStringList& uids) 595void KABCore::beamVCard(const QStringList& uids)
596{ 596{
597/*US 597/*US
598 QString beamFilename; 598 QString beamFilename;
599 Opie::OPimContact c; 599 Opie::OPimContact c;
600 if ( actionPersonal->isOn() ) { 600 if ( actionPersonal->isOn() ) {
601 beamFilename = addressbookPersonalVCardName(); 601 beamFilename = addressbookPersonalVCardName();
602 if ( !QFile::exists( beamFilename ) ) 602 if ( !QFile::exists( beamFilename ) )
603 return; // can't beam a non-existent file 603 return; // can't beam a non-existent file
604 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 604 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
605 beamFilename ); 605 beamFilename );
606 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 606 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
607 Opie::OPimContactAccess::List allList = access->allRecords(); 607 Opie::OPimContactAccess::List allList = access->allRecords();
608 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 608 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
609 c = *it; 609 c = *it;
610 610
611 delete access; 611 delete access;
612 } else { 612 } else {
613 unlink( beamfile ); // delete if exists 613 unlink( beamfile ); // delete if exists
614 mkdir("/tmp/obex/", 0755); 614 mkdir("/tmp/obex/", 0755);
615 c = m_abView -> currentEntry(); 615 c = m_abView -> currentEntry();
616 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 616 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
617 beamfile ); 617 beamfile );
618 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 618 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
619 access->add( c ); 619 access->add( c );
620 access->save(); 620 access->save();
621 delete access; 621 delete access;
622 622
623 beamFilename = beamfile; 623 beamFilename = beamfile;
624 } 624 }
625 625
626 owarn << "Beaming: " << beamFilename << oendl; 626 owarn << "Beaming: " << beamFilename << oendl;
627*/ 627*/
628 628
629#if 0 629#if 0
630 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 630 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
631 631
632 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 632 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
633 633
634 QString name = "contact.vcf"; 634 QString name = "contact.vcf";
635 635
636 QString fileName = dirName + "/" + name; 636 QString fileName = dirName + "/" + name;
637#endif 637#endif
638 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 638 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
639 // 639 //
640 QString fileName = "/tmp/kapibeamfile.vcf"; 640 QString fileName = "/tmp/kapibeamfile.vcf";
641 641
642 642
643 //QDir().mkdir( dirName, true ); 643 //QDir().mkdir( dirName, true );
644 644
645 QFile outFile(fileName); 645
646 KABC::VCardConverter converter; 646 KABC::VCardConverter converter;
647 QString description; 647 QString description;
648 648 QString datastream;
649 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 649 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
650
651 QTextStream t( &outFile ); // use a text stream
652 t.setEncoding( QTextStream::UnicodeUTF8 );
653
654 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
655 KABC::Addressee a = mAddressBook->findByUid( *it ); 650 KABC::Addressee a = mAddressBook->findByUid( *it );
656 651
657 if ( a.isEmpty() ) 652 if ( a.isEmpty() )
658 continue; 653 continue;
659 654
660 if (description.isEmpty()) 655 if (description.isEmpty())
661 description = a.formattedName(); 656 description = a.formattedName();
662 657
663 QString vcard; 658 QString vcard;
664 converter.addresseeToVCard( a, vcard ); 659 converter.addresseeToVCard( a, vcard );
665 t << vcard; 660 int start = 0;
666 661 int next;
667 } 662 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
663 int semi = vcard.find(";", next);
664 int dopp = vcard.find(":", next);
665 int sep;
666 if ( semi < dopp && semi >= 0 )
667 sep = semi ;
668 else
669 sep = dopp;
670 datastream +=vcard.mid( start, next - start);
671 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
672 start = sep;
673 }
674 datastream += vcard.mid( start,vcard.length() );
675 }
676#ifndef DESKTOP_VERSION
677 QFile outFile(fileName);
678 if ( outFile.open(IO_WriteOnly) ) {
679 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
680 QTextStream t( &outFile ); // use a text stream
681 t.setEncoding( QTextStream::UnicodeUTF8 );
682 t <<datastream;
683 outFile.close();
684 Ir *ir = new Ir( this );
685 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
686 ir->send( fileName, description, "text/x-vCard" );
668 } else { 687 } else {
669 qDebug("Error open temp beam file "); 688 qDebug("Error open temp beam file ");
670 return; 689 return;
671 } 690 }
672
673 outFile.close();
674
675#ifndef DESKTOP_VERSION
676 Ir *ir = new Ir( this );
677 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
678 ir->send( fileName, description, "text/x-vCard" );
679#endif 691#endif
680 692
681} 693}
682 694
683void KABCore::beamDone( Ir *ir ) 695void KABCore::beamDone( Ir *ir )
684{ 696{
685#ifndef DESKTOP_VERSION 697#ifndef DESKTOP_VERSION
686 delete ir; 698 delete ir;
687#endif 699#endif
688} 700}
689 701
690 702
691void KABCore::browse( const QString& url ) 703void KABCore::browse( const QString& url )
692{ 704{
693#ifndef KAB_EMBEDDED 705#ifndef KAB_EMBEDDED
694 kapp->invokeBrowser( url ); 706 kapp->invokeBrowser( url );
695#else //KAB_EMBEDDED 707#else //KAB_EMBEDDED
696 qDebug("KABCore::browse must be fixed"); 708 qDebug("KABCore::browse must be fixed");
697#endif //KAB_EMBEDDED 709#endif //KAB_EMBEDDED
698} 710}
699 711
700void KABCore::selectAllContacts() 712void KABCore::selectAllContacts()
701{ 713{
702 mViewManager->setSelected( QString::null, true ); 714 mViewManager->setSelected( QString::null, true );
703} 715}
704 716
705void KABCore::deleteContacts() 717void KABCore::deleteContacts()
706{ 718{
707 QStringList uidList = mViewManager->selectedUids(); 719 QStringList uidList = mViewManager->selectedUids();
708 deleteContacts( uidList ); 720 deleteContacts( uidList );
709} 721}
710 722
711void KABCore::deleteContacts( const QStringList &uids ) 723void KABCore::deleteContacts( const QStringList &uids )
712{ 724{
713 if ( uids.count() > 0 ) { 725 if ( uids.count() > 0 ) {
714 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 726 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
715 UndoStack::instance()->push( command ); 727 UndoStack::instance()->push( command );
716 RedoStack::instance()->clear(); 728 RedoStack::instance()->clear();
717 729
718 // now if we deleted anything, refresh 730 // now if we deleted anything, refresh
719 setContactSelected( QString::null ); 731 setContactSelected( QString::null );
720 setModified( true ); 732 setModified( true );
721 } 733 }
722} 734}
723 735
724void KABCore::copyContacts() 736void KABCore::copyContacts()
725{ 737{
726 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 738 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
727 739
728 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 740 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
729 741
730 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 742 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
731 743
732 QClipboard *cb = QApplication::clipboard(); 744 QClipboard *cb = QApplication::clipboard();
733 cb->setText( clipText ); 745 cb->setText( clipText );
734} 746}
735 747
736void KABCore::cutContacts() 748void KABCore::cutContacts()
737{ 749{
738 QStringList uidList = mViewManager->selectedUids(); 750 QStringList uidList = mViewManager->selectedUids();
739 751
740//US if ( uidList.size() > 0 ) { 752//US if ( uidList.size() > 0 ) {
741 if ( uidList.count() > 0 ) { 753 if ( uidList.count() > 0 ) {
742 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 754 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
743 UndoStack::instance()->push( command ); 755 UndoStack::instance()->push( command );
744 RedoStack::instance()->clear(); 756 RedoStack::instance()->clear();
745 757
746 setModified( true ); 758 setModified( true );
747 } 759 }
748} 760}
749 761
750void KABCore::pasteContacts() 762void KABCore::pasteContacts()
751{ 763{
752 QClipboard *cb = QApplication::clipboard(); 764 QClipboard *cb = QApplication::clipboard();
753 765
754 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 766 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
755 767
756 pasteContacts( list ); 768 pasteContacts( list );
757} 769}
758 770
759void KABCore::pasteContacts( KABC::Addressee::List &list ) 771void KABCore::pasteContacts( KABC::Addressee::List &list )
760{ 772{
761 KABC::Resource *resource = requestResource( this ); 773 KABC::Resource *resource = requestResource( this );
762 KABC::Addressee::List::Iterator it; 774 KABC::Addressee::List::Iterator it;
763 for ( it = list.begin(); it != list.end(); ++it ) 775 for ( it = list.begin(); it != list.end(); ++it )
764 (*it).setResource( resource ); 776 (*it).setResource( resource );
765 777
766 PwPasteCommand *command = new PwPasteCommand( this, list ); 778 PwPasteCommand *command = new PwPasteCommand( this, list );
767 UndoStack::instance()->push( command ); 779 UndoStack::instance()->push( command );
768 RedoStack::instance()->clear(); 780 RedoStack::instance()->clear();
769 781
770 setModified( true ); 782 setModified( true );
771} 783}
772 784
773void KABCore::setWhoAmI() 785void KABCore::setWhoAmI()
774{ 786{