-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 @@ -64,48 +64,49 @@ #else // KAB_EMBEDDED #include <kapplication.h> #include "KDGanttMinimizeSplitter.h" #include "kaddressbookmain.h" #include "kactioncollection.h" #include <qapp.h> #include <qmenubar.h> //#include <qtoolbar.h> #include <qmessagebox.h> #include <kdebug.h> #include <kiconloader.h> // needed for SmallIcon #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> #include <qmap.h> #include <qdir.h> #include <qfile.h> #include <qvbox.h> #include <qlayout.h> #include <qclipboard.h> #include <qtextstream.h> #include <libkdepim/categoryselectdialog.h> #include <kabc/vcardconverter.h> @@ -428,84 +429,92 @@ void KABCore::setContactSelected( const QString &uid ) { px.convertFromImage(pic.data()); } emit contactSelected( px ); } } mExtensionManager->setSelectionChanged(); // update the actions 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, "" ); /*US original qtopia implementation PimContact c = abList->currentEntry(); QString name = c.fileAs(); QString email = c.defaultEmail(); #ifndef QT_NO_COP QCopEnvelope e(Service::channel("Email"), "writeMail(QString,QString)"); e << name << email; #else */ #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()); /*US // Create a temp dir, so that we can put the files in it with proper names KTempFile tempDir; if ( tempDir.status() != 0 ) { kdWarning() << strerror( tempDir.status() ) << endl; return; } QString dirName = tempDir.name(); tempDir.unlink(); */ @@ -543,48 +552,154 @@ void KABCore::mailVCard( const QStringList& uids ) } /*US kapp->invokeMailer( QString::null, QString::null, QString::null, QString::null, // subject QString::null, // body QString::null, urls ); // attachments */ #ifndef QT_NO_COP QCString channel = KABPrefs::instance()->mEmailChannel.latin1(); qDebug("Using QCopEnvelope e(\"" + channel + "\", \"writeMail(QMap(QString,QString))\")"); 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 ); } void KABCore::deleteContacts() { QStringList uidList = mViewManager->selectedUids(); deleteContacts( uidList ); } void KABCore::deleteContacts( const QStringList &uids ) { if ( uids.count() > 0 ) { PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); @@ -1342,58 +1457,67 @@ void KABCore::initGUI() } void KABCore::initActions() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifndef KAB_EMBEDDED connect( QApplication::clipboard(), SIGNAL( dataChanged() ), SLOT( clipboardDataChanged() ) ); #endif //KAB_EMBEDDED // file menu 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 if ( mIsPart ) { mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, SLOT( copyContacts() ), actionCollection(), "kaddressbook_copy" ); mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, SLOT( cutContacts() ), actionCollection(), "kaddressbook_cut" ); mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, SLOT( pasteContacts() ), actionCollection(), "kaddressbook_paste" ); mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, SLOT( selectAllContacts() ), actionCollection(), @@ -1452,48 +1576,56 @@ void KABCore::initActions() actionCollection(), "options_show_jump_bar" ); connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0, actionCollection(), "options_show_details" ); connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); // misc // only enable LDAP lookup if we can handle the protocol #ifndef KAB_EMBEDDED if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 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 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, this, SLOT( createAboutData() ), actionCollection(), "kaddressbook_about_data" ); #endif //KAB_EMBEDDED clipboardDataChanged(); connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); } //US we need this function, to plug all actions into the correct menues. // KDE uses a XML format to plug the actions, but we work her without this overhead. @@ -1540,88 +1672,90 @@ void KABCore::addActionsManually() popupBarTB->insertItem( "&Help", helpMenu ); if (QApplication::desktop()->width() > 320 ) { // mViewManager->getFilterAction()->plug ( tb); } #endif // mActionQuit->plug ( mMainWindow->toolBar()); //US Now connect the actions with the menue entries. mActionPrint->plug( fileMenu ); mActionMail->plug( fileMenu ); 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 ); mActionDelete->plug( editMenu ); editMenu->insertSeparator(); mActionSelectAll->plug( editMenu ); mActionRemoveVoice->plug( changeMenu ); // settings menu //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionConfigKAddressbook->plug( settingsMenu ); if ( mIsPart ) { mActionConfigShortcuts->plug( settingsMenu ); mActionConfigureToolbars->plug( settingsMenu ); } 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 ); mActionDelete->plug( tb ); mActionRedo->plug( tb ); } } //mActionQuit->plug ( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget, 6); //US link the searchwidget first to this. // The real linkage to the toolbar happens later. //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); //US tb->insertItem( mIncSearchWidget ); /*US diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 6446974..be39148 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -43,57 +43,58 @@ class KConfig; class KAddressBookService; class LDAPSearchDialog; #else //KAB_EMBEDDED class KAddressBookMain; //US class QAction; #endif //KAB_EMBEDDED class KCMultiDialog; class KXMLGUIClient; class ExtensionManager; class XXPortManager; 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. */ void restoreSettings(); /** Saves the global settings. */ void saveSettings(); /** Returns a pointer to the StdAddressBook of the application. */ KABC::AddressBook *addressBook() const; @@ -118,72 +119,82 @@ class KABCore : public QWidget Returns the uid list of the currently selected contacts. */ QStringList selectedUIDs() const; /** Displays the ResourceSelectDialog and returns the selected resource or a null pointer if no resource was selected by the user. */ KABC::Resource *requestResource( QWidget *parent ); #ifndef KAB_EMBEDDED 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. */ void deleteContacts(); /** Deletes given contacts from the address book. @param uids The uids of the contacts, which shall be deleted. */ void deleteContacts( const QStringList &uids ); /** Copys the selected contacts into clipboard for later pasting. */ @@ -265,160 +276,163 @@ class KABCore : public QWidget /** END DCOP METHODS */ /** Saves the contents of the AddressBook back to disk. */ void save(); /** Undos the last command using the undo stack. */ 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 dialog and do the printing. */ void print(); /** Registers a new GUI client, so plugins can register its actions. */ void addGUIClient( KXMLGUIClient *client ); signals: void contactSelected( const QString &name ); void contactSelected( const QPixmap &pixmap ); public slots: void setDetailsVisible( bool visible ); void setDetailsToState(); private slots: void setJumpButtonBarVisible( bool visible ); void importFromOL(); void extensionModified( const KABC::Addressee::List &list ); void clipboardDataChanged(); void updateActionMenu(); void configureKeyBindings(); 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; KCMultiDialog *mConfigureDialog; #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 |