-rw-r--r-- | kaddressbook/kabcore.cpp | 134 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 14 |
2 files changed, 148 insertions, 0 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 2a54900..d891b07 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -87,2 +87,3 @@ | |||
87 | #endif | 87 | #endif |
88 | #include <qpe/ir.h> | ||
88 | 89 | ||
@@ -451,2 +452,8 @@ void KABCore::setContactSelected( const QString &uid ) | |||
451 | mActionMailVCard->setEnabled( selected ); | 452 | mActionMailVCard->setEnabled( selected ); |
453 | if (mActionBeam) | ||
454 | mActionBeam->setEnabled( selected ); | ||
455 | |||
456 | if (mActionBeam) | ||
457 | mActionBeamVCard->setEnabled( selected ); | ||
458 | |||
452 | mActionWhoAmI->setEnabled( selected ); | 459 | mActionWhoAmI->setEnabled( selected ); |
@@ -487,2 +494,4 @@ void KABCore::sendMail( const QString& email ) | |||
487 | 494 | ||
495 | |||
496 | |||
488 | void KABCore::mailVCard() | 497 | void KABCore::mailVCard() |
@@ -566,2 +575,108 @@ void KABCore::mailVCard( const QStringList& uids ) | |||
566 | 575 | ||
576 | /** | ||
577 | Beams the "WhoAmI contact. | ||
578 | */ | ||
579 | void KABCore::beamMySelf() | ||
580 | { | ||
581 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | ||
582 | if (!a.isEmpty()) | ||
583 | { | ||
584 | QStringList uids; | ||
585 | uids << a.uid(); | ||
586 | |||
587 | beamVCard(uids); | ||
588 | } | ||
589 | } | ||
590 | |||
591 | void KABCore::beamVCard() | ||
592 | { | ||
593 | QStringList uids = mViewManager->selectedUids(); | ||
594 | if ( !uids.isEmpty() ) | ||
595 | beamVCard( uids ); | ||
596 | } | ||
597 | |||
598 | |||
599 | void KABCore::beamVCard(const QStringList& uids) | ||
600 | { | ||
601 | /*US | ||
602 | QString beamFilename; | ||
603 | Opie::OPimContact c; | ||
604 | if ( actionPersonal->isOn() ) { | ||
605 | beamFilename = addressbookPersonalVCardName(); | ||
606 | if ( !QFile::exists( beamFilename ) ) | ||
607 | return; // can't beam a non-existent file | ||
608 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
609 | beamFilename ); | ||
610 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
611 | Opie::OPimContactAccess::List allList = access->allRecords(); | ||
612 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | ||
613 | c = *it; | ||
614 | |||
615 | delete access; | ||
616 | } else { | ||
617 | unlink( beamfile ); // delete if exists | ||
618 | mkdir("/tmp/obex/", 0755); | ||
619 | c = m_abView -> currentEntry(); | ||
620 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | ||
621 | beamfile ); | ||
622 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
623 | access->add( c ); | ||
624 | access->save(); | ||
625 | delete access; | ||
626 | |||
627 | beamFilename = beamfile; | ||
628 | } | ||
629 | |||
630 | owarn << "Beaming: " << beamFilename << oendl; | ||
631 | */ | ||
632 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | ||
633 | |||
634 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); | ||
635 | |||
636 | QString name = "contact.vcf"; | ||
637 | |||
638 | QString fileName = dirName + "/" + name; | ||
639 | |||
640 | |||
641 | QDir().mkdir( dirName, true ); | ||
642 | |||
643 | QFile outFile(fileName); | ||
644 | KABC::VCardConverter converter; | ||
645 | QString description; | ||
646 | |||
647 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | ||
648 | |||
649 | QTextStream t( &outFile ); // use a text stream | ||
650 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
651 | |||
652 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | ||
653 | KABC::Addressee a = mAddressBook->findByUid( *it ); | ||
654 | |||
655 | if ( a.isEmpty() ) | ||
656 | continue; | ||
657 | |||
658 | if (description.isEmpty()) | ||
659 | description = a.formattedName(); | ||
660 | |||
661 | QString vcard; | ||
662 | converter.addresseeToVCard( a, vcard ); | ||
663 | t << vcard; | ||
664 | |||
665 | } | ||
666 | } | ||
667 | |||
668 | outFile.close(); | ||
669 | |||
670 | Ir *ir = new Ir( this ); | ||
671 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | ||
672 | ir->send( fileName, description, "text/x-vCard" ); | ||
673 | |||
674 | } | ||
675 | |||
676 | void KABCore::beamDone( Ir *ir ) | ||
677 | { | ||
678 | delete ir; | ||
679 | } | ||
680 | |||
681 | |||
567 | void KABCore::browse( const QString& url ) | 682 | void KABCore::browse( const QString& url ) |
@@ -1365,2 +1480,3 @@ void KABCore::initActions() | |||
1365 | 1480 | ||
1481 | |||
1366 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1482 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
@@ -1375,2 +1491,10 @@ void KABCore::initActions() | |||
1375 | 1491 | ||
1492 | mActionBeamVCard = 0; | ||
1493 | if ( Ir::supported() ) { | ||
1494 | mActionBeamVCard = new KAction( i18n( "Beam v&Card" ), "beam", 0, this, | ||
1495 | SLOT( beamVCard() ), actionCollection(), | ||
1496 | "kaddressbook_beam_vcard" ); | ||
1497 | } | ||
1498 | |||
1499 | |||
1376 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1500 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
@@ -1475,2 +1599,10 @@ void KABCore::initActions() | |||
1475 | 1599 | ||
1600 | mActionBeam = 0; | ||
1601 | if ( Ir::supported() ) { | ||
1602 | mActionBeam = new KAction( i18n( "&Beam Who Am I" ), "beam", 0, this, | ||
1603 | SLOT( beamMySelf() ), actionCollection(), | ||
1604 | "kaddressbook_beam_myself" ); | ||
1605 | } | ||
1606 | |||
1607 | |||
1476 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1608 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
@@ -1563,2 +1695,3 @@ void KABCore::addActionsManually() | |||
1563 | mActionMailVCard->plug( fileMenu ); | 1695 | mActionMailVCard->plug( fileMenu ); |
1696 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); | ||
1564 | fileMenu->insertSeparator(); | 1697 | fileMenu->insertSeparator(); |
@@ -1603,2 +1736,3 @@ void KABCore::addActionsManually() | |||
1603 | mActionWhoAmI->plug( settingsMenu ); | 1736 | mActionWhoAmI->plug( settingsMenu ); |
1737 | if ( Ir::supported() ) mActionBeam->plug( settingsMenu ); | ||
1604 | mActionCategories->plug( settingsMenu ); | 1738 | mActionCategories->plug( settingsMenu ); |
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 6446974..be39148 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -66,2 +66,3 @@ class ViewManager; | |||
66 | class AddresseeEditorDialog; | 66 | class AddresseeEditorDialog; |
67 | class Ir; | ||
67 | 68 | ||
@@ -165,2 +166,12 @@ class KABCore : public QWidget | |||
165 | /** | 166 | /** |
167 | Beams the "WhoAmI contact. | ||
168 | */ | ||
169 | void beamMySelf(); | ||
170 | |||
171 | void beamVCard(); | ||
172 | void beamVCard(const QStringList& uids); | ||
173 | void beamDone( Ir *ir ); | ||
174 | |||
175 | |||
176 | /** | ||
166 | Starts the preferred web browser with the given URL as argument. | 177 | Starts the preferred web browser with the given URL as argument. |
@@ -368,2 +379,3 @@ class KABCore : public QWidget | |||
368 | KAction *mActionMail; | 379 | KAction *mActionMail; |
380 | KAction *mActionBeam; | ||
369 | KAction* mActionPrint; | 381 | KAction* mActionPrint; |
@@ -373,2 +385,4 @@ class KABCore : public QWidget | |||
373 | KAction *mActionMailVCard; | 385 | KAction *mActionMailVCard; |
386 | KAction *mActionBeamVCard; | ||
387 | |||
374 | KAction *mActionQuit; | 388 | KAction *mActionQuit; |