summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp134
-rw-r--r--kaddressbook/kabcore.h14
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 @@
#endif
+#include <qpe/ir.h>
@@ -451,2 +452,8 @@ void KABCore::setContactSelected( const QString &uid )
mActionMailVCard->setEnabled( selected );
+ if (mActionBeam)
+ mActionBeam->setEnabled( selected );
+
+ if (mActionBeam)
+ mActionBeamVCard->setEnabled( selected );
+
mActionWhoAmI->setEnabled( selected );
@@ -487,2 +494,4 @@ void KABCore::sendMail( const QString& email )
+
+
void KABCore::mailVCard()
@@ -566,2 +575,108 @@ void KABCore::mailVCard( const QStringList& uids )
+/**
+ Beams the "WhoAmI contact.
+*/
+void KABCore::beamMySelf()
+{
+ KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
+ if (!a.isEmpty())
+ {
+ QStringList uids;
+ uids << a.uid();
+
+ beamVCard(uids);
+ }
+}
+
+void KABCore::beamVCard()
+{
+ QStringList uids = mViewManager->selectedUids();
+ if ( !uids.isEmpty() )
+ beamVCard( uids );
+}
+
+
+void KABCore::beamVCard(const QStringList& uids)
+{
+/*US
+ QString beamFilename;
+ Opie::OPimContact c;
+ if ( actionPersonal->isOn() ) {
+ beamFilename = addressbookPersonalVCardName();
+ if ( !QFile::exists( beamFilename ) )
+ return; // can't beam a non-existent file
+ Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
+ beamFilename );
+ Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
+ Opie::OPimContactAccess::List allList = access->allRecords();
+ Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
+ c = *it;
+
+ delete access;
+ } else {
+ unlink( beamfile ); // delete if exists
+ mkdir("/tmp/obex/", 0755);
+ c = m_abView -> currentEntry();
+ Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
+ beamfile );
+ Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
+ access->add( c );
+ access->save();
+ delete access;
+
+ beamFilename = beamfile;
+ }
+
+ owarn << "Beaming: " << beamFilename << oendl;
+*/
+ QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
+
+ QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
+
+ QString name = "contact.vcf";
+
+ QString fileName = dirName + "/" + name;
+
+
+ QDir().mkdir( dirName, true );
+
+ QFile outFile(fileName);
+ KABC::VCardConverter converter;
+ QString description;
+
+ if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
+
+ QTextStream t( &outFile ); // use a text stream
+ t.setEncoding( QTextStream::UnicodeUTF8 );
+
+ for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee a = mAddressBook->findByUid( *it );
+
+ if ( a.isEmpty() )
+ continue;
+
+ if (description.isEmpty())
+ description = a.formattedName();
+
+ QString vcard;
+ converter.addresseeToVCard( a, vcard );
+ t << vcard;
+
+ }
+ }
+
+ outFile.close();
+
+ Ir *ir = new Ir( this );
+ connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
+ ir->send( fileName, description, "text/x-vCard" );
+
+}
+
+void KABCore::beamDone( Ir *ir )
+{
+ delete ir;
+}
+
+
void KABCore::browse( const QString& url )
@@ -1365,2 +1480,3 @@ void KABCore::initActions()
+
mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
@@ -1375,2 +1491,10 @@ void KABCore::initActions()
+ mActionBeamVCard = 0;
+ if ( Ir::supported() ) {
+ mActionBeamVCard = new KAction( i18n( "Beam v&Card" ), "beam", 0, this,
+ SLOT( beamVCard() ), actionCollection(),
+ "kaddressbook_beam_vcard" );
+ }
+
+
mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
@@ -1475,2 +1599,10 @@ void KABCore::initActions()
+ mActionBeam = 0;
+ if ( Ir::supported() ) {
+ mActionBeam = new KAction( i18n( "&Beam Who Am I" ), "beam", 0, this,
+ SLOT( beamMySelf() ), actionCollection(),
+ "kaddressbook_beam_myself" );
+ }
+
+
mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
@@ -1563,2 +1695,3 @@ void KABCore::addActionsManually()
mActionMailVCard->plug( fileMenu );
+ if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
fileMenu->insertSeparator();
@@ -1603,2 +1736,3 @@ void KABCore::addActionsManually()
mActionWhoAmI->plug( settingsMenu );
+ if ( Ir::supported() ) mActionBeam->plug( settingsMenu );
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;
class AddresseeEditorDialog;
+class Ir;
@@ -165,2 +166,12 @@ class KABCore : public QWidget
/**
+ Beams the "WhoAmI contact.
+ */
+ void beamMySelf();
+
+ void beamVCard();
+ void beamVCard(const QStringList& uids);
+ void beamDone( Ir *ir );
+
+
+ /**
Starts the preferred web browser with the given URL as argument.
@@ -368,2 +379,3 @@ class KABCore : public QWidget
KAction *mActionMail;
+ KAction *mActionBeam;
KAction* mActionPrint;
@@ -373,2 +385,4 @@ class KABCore : public QWidget
KAction *mActionMailVCard;
+ KAction *mActionBeamVCard;
+
KAction *mActionQuit;