author | ulf69 <ulf69> | 2004-08-06 01:40:28 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-06 01:40:28 (UTC) |
commit | b82b4b1efe9edddfb7b7d5eaa9fe8da4a9698138 (patch) (side-by-side diff) | |
tree | 6e407c4b61128e5d16f657f6ae788ebcaadb7862 | |
parent | 422cea307a0a85064db6b5b64a847375da9311e1 (diff) | |
download | kdepimpi-b82b4b1efe9edddfb7b7d5eaa9fe8da4a9698138.zip kdepimpi-b82b4b1efe9edddfb7b7d5eaa9fe8da4a9698138.tar.gz kdepimpi-b82b4b1efe9edddfb7b7d5eaa9fe8da4a9698138.tar.bz2 |
enabled beaming and sending of emails
-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 @@ -82,12 +82,13 @@ #ifdef Q_WS_QWS #include <qtopia/services.h> #include <qtopia/qcopenvelope_qws.h> #endif +#include <qpe/ir.h> #endif // KAB_EMBEDDED #include <kcmkabconfig.h> #include <kresources/selectdialog.h> @@ -446,12 +447,18 @@ void KABCore::setContactSelected( const QString &uid ) mActionCopy->setEnabled( selected ); mActionDelete->setEnabled( selected ); mActionEditAddressee->setEnabled( selected ); mActionMail->setEnabled( selected ); mActionMailVCard->setEnabled( selected ); + if (mActionBeam) + mActionBeam->setEnabled( selected ); + + if (mActionBeam) + mActionBeamVCard->setEnabled( selected ); + mActionWhoAmI->setEnabled( selected ); mActionCategories->setEnabled( selected ); } void KABCore::sendMail() { @@ -482,12 +489,14 @@ void KABCore::sendMail( const QString& email ) e << "" << email; #else KMessageBox::sorry( this, i18n( "This version does not support sending emails." ) ); #endif } + + void KABCore::mailVCard() { QStringList uids = mViewManager->selectedUids(); if ( !uids.isEmpty() ) mailVCard( uids ); } @@ -561,12 +570,118 @@ void KABCore::mailVCard( const QStringList& uids ) KMessageBox::sorry( this, i18n( "This version does not support sending emails." ) ); #endif } +/** + 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 ) { #ifndef KAB_EMBEDDED kapp->invokeBrowser( url ); #else //KAB_EMBEDDED qDebug("KABCore::browse must be fixed"); @@ -1360,22 +1475,31 @@ void KABCore::initActions() } else { mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); } + mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, this, SLOT( mailVCard() ), actionCollection(), "file_mail_vcard"); + 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, this, SLOT( editContact2() ), actionCollection(), "file_properties" ); #ifdef KAB_EMBEDDED // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); @@ -1470,12 +1594,20 @@ void KABCore::initActions() mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, SLOT( setWhoAmI() ), actionCollection(), "set_personal" ); + 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, SLOT( setCategories() ), actionCollection(), "edit_set_categories" ); mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, SLOT( removeVoice() ), actionCollection(), @@ -1558,12 +1690,13 @@ void KABCore::addActionsManually() fileMenu->insertSeparator(); mActionSave->plug( fileMenu ); fileMenu->insertItem( "&Import", ImportMenu ); fileMenu->insertItem( "&Emport", ExportMenu ); fileMenu->insertSeparator(); mActionMailVCard->plug( fileMenu ); + if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); fileMenu->insertSeparator(); mActionQuit->plug( fileMenu ); #ifdef _WIN32_ mActionImportOL->plug( ImportMenu ); #endif // edit menu @@ -1598,12 +1731,13 @@ void KABCore::addActionsManually() mActionJumpBar->plug( settingsMenu ); mActionDetails->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionWhoAmI->plug( settingsMenu ); + if ( Ir::supported() ) mActionBeam->plug( settingsMenu ); mActionCategories->plug( settingsMenu ); mActionAboutKAddressbook->plug( helpMenu ); if (QApplication::desktop()->width() > 320 ) { diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 6446974..be39148 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -61,12 +61,13 @@ class KToggleAction; class QAction; class QMenuBar; class QSplitter; class ViewContainer; class ViewManager; class AddresseeEditorDialog; +class Ir; class KABCore : public QWidget { Q_OBJECT public: @@ -160,12 +161,22 @@ class KABCore : public QWidget void mailVCard(); void mailVCard(const QStringList& uids); /** + 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. */ void browse( const QString& url ); /** Select all contacts in the view. @@ -363,17 +374,20 @@ class KABCore : public QWidget bool mReadWrite; bool mModified; bool mIsPart; //US file menu KAction *mActionMail; + KAction *mActionBeam; KAction* mActionPrint; KAction* mActionNewContact; KAction *mActionSave; KAction *mActionEditAddressee; KAction *mActionMailVCard; + KAction *mActionBeamVCard; + KAction *mActionQuit; //US edit menu KAction *mActionCopy; KAction *mActionCut; KAction *mActionPaste; |