-rw-r--r-- | kaddressbook/kabcore.cpp | 134 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 42 |
2 files changed, 162 insertions, 14 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 2a54900..d891b07 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -86,4 +86,5 @@ #include <qtopia/qcopenvelope_qws.h> #endif +#include <qpe/ir.h> #endif // KAB_EMBEDDED @@ -450,4 +451,10 @@ void KABCore::setContactSelected( const QString &uid ) mActionMail->setEnabled( selected ); mActionMailVCard->setEnabled( selected ); + if (mActionBeam) + mActionBeam->setEnabled( selected ); + + if (mActionBeam) + mActionBeamVCard->setEnabled( selected ); + mActionWhoAmI->setEnabled( selected ); mActionCategories->setEnabled( selected ); @@ -486,4 +493,6 @@ void KABCore::sendMail( const QString& email ) } + + void KABCore::mailVCard() { @@ -565,4 +574,110 @@ 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 ) { @@ -1364,4 +1479,5 @@ void KABCore::initActions() } + mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); @@ -1374,4 +1490,12 @@ void KABCore::initActions() 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() ), @@ -1474,4 +1598,12 @@ void KABCore::initActions() "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(), @@ -1562,4 +1694,5 @@ void KABCore::addActionsManually() fileMenu->insertSeparator(); mActionMailVCard->plug( fileMenu ); + if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); fileMenu->insertSeparator(); mActionQuit->plug( fileMenu ); @@ -1602,4 +1735,5 @@ 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 @@ -65,4 +65,5 @@ class ViewContainer; class ViewManager; class AddresseeEditorDialog; +class Ir; class KABCore : public QWidget @@ -72,6 +73,6 @@ class KABCore : public QWidget public: KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 ); - - + + ~KABCore(); @@ -140,5 +141,5 @@ class KABCore : public QWidget void createAboutData(); #endif //KAB_EMBEDDED - + void statusMessage(QString, int time = 0 ); /** @@ -164,4 +165,14 @@ 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. */ @@ -287,7 +298,7 @@ class KABCore : public QWidget */ void editContact( const QString &uid /*US = QString::null*/ ); -//US added a second method without defaultparameter +//US added a second method without defaultparameter void editContact2(); - + /** Launches the configuration dialog. @@ -336,10 +347,10 @@ class KABCore : public QWidget void initGUI(); void initActions(); - + AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, const char *name = 0 ); KXMLGUIClient *mGUIClient; - + KABC::AddressBook *mAddressBook; @@ -367,4 +378,5 @@ class KABCore : public QWidget //US file menu KAction *mActionMail; + KAction *mActionBeam; KAction* mActionPrint; KAction* mActionNewContact; @@ -372,6 +384,8 @@ class KABCore : public QWidget KAction *mActionEditAddressee; KAction *mActionMailVCard; + KAction *mActionBeamVCard; + KAction *mActionQuit; - + //US edit menu KAction *mActionCopy; @@ -382,5 +396,5 @@ class KABCore : public QWidget KAction *mActionRedo; KAction *mActionDelete; - + //US settings menu KAction *mActionConfigResources; @@ -394,12 +408,12 @@ class KABCore : public QWidget KAction *mActionCategories; KAction *mActionAboutKAddressbook; - + KAction *mActionDeleteView; - + QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; - + //US QAction *mActionSave; QPopupMenu *ImportMenu; @@ -408,5 +422,5 @@ class KABCore : public QWidget KAction *mActionRemoveVoice; KAction * mActionImportOL; - + #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; @@ -419,5 +433,5 @@ class KABCore : public QWidget KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED - + }; |