-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 @@ -76,24 +76,25 @@ #include <kresources/kcmkresources.h> #include <ktoolbar.h> #include <kcmkabconfig.h> //#include <qlabel.h> #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> #include <kmessagebox.h> #include <picture.h> #include <resource.h> //US#include <qsplitter.h> @@ -440,24 +441,30 @@ void KABCore::setContactSelected( const QString &uid ) bool selected = !uid.isEmpty(); if ( mReadWrite ) { mActionCut->setEnabled( selected ); mActionPaste->setEnabled( selected ); } 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() { sendMail( mViewManager->selectedEmails().join( ", " ) ); } void KABCore::sendMail( const QString& email ) { //US original kde implementation : kapp->invokeMailer( email, "" ); @@ -476,24 +483,26 @@ void KABCore::sendMail( const QString& email ) #ifndef QT_NO_COP QCString channel = KABPrefs::instance()->mEmailChannel.latin1(); qDebug("Using QCopEnvelope e(\"" + channel + "\", \"writeMail(QMap(QString,QString))\")"); QCopEnvelope e(channel, "writeMail(QString,QString)"); //US we need no names in the To field. The emailadresses are enough 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 ); } void KABCore::mailVCard( const QStringList& uids ) { QStringList urls; QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); @@ -555,24 +564,130 @@ void KABCore::mailVCard( const QStringList& uids ) QMap<QString, QString> parameterMap; parameterMap.insert("ATTACHMENT<n>", urls.join(", ")); QCopEnvelope e(channel, "writeMail(QMap(QString,QString))"); e << parameterMap; #else 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"); #endif //KAB_EMBEDDED } void KABCore::selectAllContacts() { mViewManager->setSelected( QString::null, true ); @@ -1354,34 +1469,43 @@ void KABCore::initActions() if ( mIsPart ) { mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, SLOT( sendMail() ), actionCollection(), "kaddressbook_mail" ); mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, SLOT( print() ), actionCollection(), "kaddressbook_print" ); } 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() ); mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, mMainWindow, SLOT( exit() ), actionCollection(), "quit" ); #endif //KAB_EMBEDDED // edit menu @@ -1464,24 +1588,32 @@ void KABCore::initActions() this, SLOT( openLDAPDialog() ), actionCollection(), "ldap_lookup" ); } #else //KAB_EMBEDDED //qDebug("KABCore::initActions() LDAP has to be implemented"); #endif //KAB_EMBEDDED 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(), "remove_voice" ); mActionImportOL = new KAction( i18n( "Import from OL..." ), 0, this, SLOT( importFromOL() ), actionCollection(), "import_OL" ); #ifdef KAB_EMBEDDED @@ -1552,24 +1684,25 @@ void KABCore::addActionsManually() fileMenu->insertSeparator(); mActionNewContact->plug( fileMenu ); mActionNewContact->plug( tb ); mActionEditAddressee->plug( fileMenu ); 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 mActionUndo->plug( editMenu ); mActionRedo->plug( editMenu ); editMenu->insertSeparator(); mActionCut->plug( editMenu ); mActionCopy->plug( editMenu ); mActionPaste->plug( editMenu ); @@ -1592,24 +1725,25 @@ void KABCore::addActionsManually() } else { mActionKeyBindings->plug( settingsMenu ); } settingsMenu->insertSeparator(); 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 ) { mActionEditAddressee->plug( tb ); mActionSave->plug( tb ); mViewManager->getFilterAction()->plug ( tb); if (QApplication::desktop()->width() > 480 ) { mActionUndo->plug( tb ); diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 6446974..be39148 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -55,33 +55,34 @@ class JumpButtonBar; class IncSearchWidget; class KDGanttMinimizeSplitter; class KAction; class KActionCollection; class KToggleAction; class QAction; class QMenuBar; class QSplitter; class ViewContainer; class ViewManager; class AddresseeEditorDialog; +class Ir; class KABCore : public QWidget { Q_OBJECT public: KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 ); - - + + ~KABCore(); #ifdef KAB_EMBEDDED //US added functionality QPopupMenu* getViewMenu() {return viewMenu;} QPopupMenu* getFilterMenu() {return filterMenu;} QPopupMenu* getSettingsMenu() {return settingsMenu;} void addActionsManually(); #endif //KAB_EMBEDDED /** Restores the global settings. @@ -130,48 +131,58 @@ class KABCore : public QWidget static KAboutData *createAboutData(); #endif //KAB_EMBEDDED #ifdef KAB_EMBEDDED inline QPopupMenu* getImportMenu() { return ImportMenu;} inline QPopupMenu* getExportMenu() { return ExportMenu;} #endif //KAB_EMBEDDED public slots: #ifdef KAB_EMBEDDED void createAboutData(); #endif //KAB_EMBEDDED - + void statusMessage(QString, int time = 0 ); /** Is called whenever a contact is selected in the view. */ void setContactSelected( const QString &uid ); /** Opens the preferred mail composer with all selected contacts as arguments. */ void sendMail(); /** Opens the preferred mail composer with the given contacts as arguments. */ void sendMail( const QString& email ); 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. */ void selectAllContacts(); /** Deletes all selected contacts from the address book. */ @@ -277,27 +288,27 @@ class KABCore : public QWidget void undo(); /** Redos the last command that was undone, using the redo stack. */ void redo(); /** Shows the edit dialog for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ 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. */ void openConfigDialog(); /** Launches the ldap search dialog. */ void openLDAPDialog(); /** Creates a KAddressBookPrinter, which will display the print @@ -326,30 +337,30 @@ class KABCore : public QWidget void removeVoice(); #ifdef KAB_EMBEDDED void configureResources(); #endif //KAB_EMBEDDED void slotEditorDestroyed( const QString &uid ); void configurationChanged(); void addressBookChanged(); private: void initGUI(); void initActions(); - + AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, const char *name = 0 ); KXMLGUIClient *mGUIClient; - + KABC::AddressBook *mAddressBook; ViewManager *mViewManager; // QSplitter *mDetailsSplitter; KDGanttMinimizeSplitter *mExtensionBarSplitter; ViewContainer *mDetails; KDGanttMinimizeSplitter* mMiniSplitter; XXPortManager *mXXPortManager; JumpButtonBar *mJumpButtonBar; IncSearchWidget *mIncSearchWidget; ExtensionManager *mExtensionManager; @@ -357,68 +368,71 @@ class KABCore : public QWidget #ifndef KAB_EMBEDDED LDAPSearchDialog *mLdapSearchDialog; #endif //KAB_EMBEDDED // QDict<AddresseeEditorDialog> mEditorDict; AddresseeEditorDialog *mEditorDialog; 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; KAction *mActionSelectAll; KAction *mActionUndo; KAction *mActionRedo; KAction *mActionDelete; - + //US settings menu KAction *mActionConfigResources; KAction *mActionConfigKAddressbook; KAction *mActionConfigShortcuts; KAction *mActionConfigureToolbars; KAction *mActionKeyBindings; KToggleAction *mActionJumpBar; KToggleAction *mActionDetails; KAction *mActionWhoAmI; KAction *mActionCategories; KAction *mActionAboutKAddressbook; - + KAction *mActionDeleteView; - + QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; - + //US QAction *mActionSave; QPopupMenu *ImportMenu; QPopupMenu *ExportMenu; //LR additional methods KAction *mActionRemoveVoice; KAction * mActionImportOL; - + #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; #endif //KAB_EMBEDDED class KABCorePrivate; KABCorePrivate *d; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED - + }; #endif |