From ab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb Mon Sep 17 00:00:00 2001 From: ulf69 Date: Tue, 17 Aug 2004 00:09:26 +0000 Subject: QCop implementation for KOrganizer to access Ka/pi directly --- diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 6807bed..e7c815e 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -67,6 +67,8 @@ #include "KDGanttMinimizeSplitter.h" #include "kaddressbookmain.h" #include "kactioncollection.h" +#include "addresseedialog.h" + #include #include //#include @@ -211,6 +213,10 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const connect( mDetails, SIGNAL( sendEmail( const QString& ) ), SLOT( sendMail( const QString& ) ) ); + + connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&, const QString&))); + + #ifndef KAB_EMBEDDED connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), mXXPortManager, SLOT( importVCard( const KURL& ) ) ); @@ -218,6 +224,7 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const connect( mDetails, SIGNAL( browse( const QString& ) ), SLOT( browse( const QString& ) ) ); + mAddressBookService = new KAddressBookService( this ); #endif //KAB_EMBEDDED @@ -1965,6 +1972,32 @@ void KABCore::configureResources() #endif //KAB_EMBEDDED +/* this method will be called through the QCop interface from Ko/Pi to select addresses + * for the attendees list of an event. + */ +void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid, const QString& param1) +{ + //param1 is usually empty for this kind of request + + QStringList nameList; + QStringList emailList; + QStringList uidList; + + KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); + uint i=0; + for (i=0; i < list.count(); i++) + { + nameList.append(list[i].realName()); + emailList.append(list[i].preferredEmail()); + uidList.append(list[i].uid()); + } + + bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); + +} + + + #ifndef KAB_EMBEDDED #include "kabcore.moc" diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index d4d28f1..fe778af 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -328,6 +328,9 @@ class KABCore : public QWidget */ void addGUIClient( KXMLGUIClient *client ); + void requestForNameEmailUidList(const QString& sourceChannel, const QString& uid, const QString& param1); + + signals: void contactSelected( const QString &name ); void contactSelected( const QPixmap &pixmap ); diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp index 7f368eb..850e5b2 100644 --- a/kaddressbook/mainembedded.cpp +++ b/kaddressbook/mainembedded.cpp @@ -3,9 +3,9 @@ #include #else #include -#include -#include -#include +#include +#include +#include #endif #include @@ -13,6 +13,7 @@ #include #include #include "kaddressbookmain.h" +#include "externalapphandler.h" int main( int argc, char **argv ) { @@ -20,17 +21,17 @@ int main( int argc, char **argv ) QPEApplication a( argc, argv ); a.setKeepRunning (); #else - QApplication a( argc, argv ); + QApplication a( argc, argv ); QApplication::setStyle( new QPlatinumStyle ()); #endif - + bool exitHelp = false; if ( argc > 1 ) { QString command = argv[1]; if ( command == "-help" ){ printf("KA/E command line commands:\n"); printf(" no command: Start KA/E in usual way\n"); - printf(" -help: This output\n"); + printf(" -help: This output\n"); printf(" KA/E is exiting now. Bye!\n"); exitHelp = true; } @@ -49,11 +50,11 @@ int main( int argc, char **argv ) KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName)); QApplication::addLibraryPath ( qApp->applicationDirPath () ); -#endif +#endif KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook"))); KAddressBookMain m ; //US MainWindow m; -//US QObject::connect( &a, SIGNAL (appMessage ( const QCString &, const QByteArray & )),&m, SLOT(recieve( const QCString&, const QByteArray& ))); + QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); #ifndef DESKTOP_VERSION a.showMainWidget( &m ); @@ -63,7 +64,7 @@ int main( int argc, char **argv ) m.show(); #endif a.exec(); - + } qDebug("KA: Bye! "); } diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp index 35638b1..64caa7d 100644 --- a/libkdepim/externalapphandler.cpp +++ b/libkdepim/externalapphandler.cpp @@ -45,19 +45,255 @@ $Id$ #include "kpimglobalprefs.h" +/********************************************************************************* + * + ********************************************************************************/ + + +QCopTransferItem::QCopTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) + : _sourceMessage(sourceMessage), _targetChannel(targetChannel), _targetMessage(targetMessage) +{ + //sourceMessage passes later three parameters: sourceChannel, uid, param1 + _sourceMessageParameters = "(QString,QString,QString)"; +} + +/*********************************************************************************/ + +QCopTransferItem::QCopTransferItem() +{ +} + +/*********************************************************************************/ +bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& param1) +{ + +#ifndef DESKTOP_VERSION + //sourceMessage passes two parameters: sourceChannel, uid + QString sourceMessage = _sourceMessage + _sourceMessageParameters; + + qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _targetChannel.latin1(), sourceMessage.latin1()); + qDebug("passing sourcechannel(%s), uid(%s), param1(%s) as parameter to QCopEnvelope", _sourceChannel.latin1(), uid.latin1(), param1.latin1()); + + QCopEnvelope e(_targetChannel.latin1(), sourceMessage.latin1()); + + e << _sourceChannel << uid << param1; + + return true; + +#else + KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); + return false; +#endif + +} + + +/*********************************************************************************/ +void QCopTransferItem::setSourceChannel(const QString& sourceChannel) +{ + + if (_sourceChannel.isEmpty()) + _sourceChannel = sourceChannel; +} + + +/*********************************************************************************/ +bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) +{ +/*US + // copied from old mail2 + static int ii = 0; + + // block second call + if ( ii < 2 ) { + ++ii; + if ( ii > 1 ) { + qDebug("qcop call blocked "); + return true; + } + } +*/ + qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() ); + + //we are in the target and get a request from the source + if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data()) + { + QDataStream stream( data, IO_ReadOnly ); + + + QString sourceChannel; + QString uid; + QString param1; + stream >> sourceChannel >> uid >> param1; + emit receivedMessageFromSource(sourceChannel, uid, param1); + return true; + } + + return false; +} + + +/********************************************************************************* + * + ********************************************************************************/ + + +QCopMapTransferItem::QCopMapTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) + : QCopTransferItem(sourceMessage, targetChannel,targetMessage) +{ + //targetMessage returns later two parameters: uid, and map + _targetMessageParameters = "(QString,QMAP)"; +} + +/*********************************************************************************/ +bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap& nameEmailMap) +{ +#ifndef DESKTOP_VERSION + //targetMessage passes two parameters: uid, map + QString targetMessage = _targetMessage + _targetMessageParameters; + + qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); + qDebug("passing uid(%s) and map as parameter to QCopEnvelope", uid.latin1()); + QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); + //US we need no names in the To field. The emailadresses are enough + + e << uid << nameEmailMap; + + return true; + +#else + KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); + return false; +#endif + +} + + +/*********************************************************************************/ +bool QCopMapTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) +{ + bool res = QCopTransferItem::appMessage( cmsg, data ); + + if (res == false) + { + QDataStream stream( data, IO_ReadOnly ); + + qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() ); + + //we are in the source and get an answer from the target + if ((_targetMessage + _targetMessageParameters) == cmsg.data()) + { + QMap adrMap; + QString uid; + + stream >> uid >> adrMap; + + emit receivedMessageFromTarget(uid, adrMap); + + + return true; + } + } + + return false; +} + + +/********************************************************************************* + * + ********************************************************************************/ + + +QCopListTransferItem::QCopListTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) + : QCopTransferItem(sourceMessage, targetChannel,targetMessage) +{ + //targetMessage returns later two parameters: uid, and map + _targetMessageParameters = "(QString,QStringList,QStringList,QStringList)"; +} + +/*********************************************************************************/ +bool QCopListTransferItem::sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) +{ +#ifndef DESKTOP_VERSION + //targetMessage passes two parameters: uid, map + QString targetMessage = _targetMessage + _targetMessageParameters; + + qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); + qDebug("passing uid(%s) and list1, list2, list3 as parameter to QCopEnvelope", uid.latin1()); + + QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); + //US we need no names in the To field. The emailadresses are enough + + e << uid << list1 << list2 << list3; + + return true; + +#else + KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); + return false; +#endif + +} + + +/*********************************************************************************/ +bool QCopListTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) +{ + bool res = QCopTransferItem::appMessage( cmsg, data ); + + if (res == false) + { + QDataStream stream( data, IO_ReadOnly ); + + qDebug("QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); + + //we are in the source and get an answer from the target + if ((_targetMessage + _targetMessageParameters) == cmsg.data()) + { + QStringList list1; + QStringList list2; + QStringList list3; + QString uid; + + stream >> uid >> list1 >> list2 >> list3; + + emit receivedMessageFromTarget(uid, list1, list2, list3); + + + return true; + } + } + + return false; +} + + + +/********************************************************************************* + * + ********************************************************************************/ ExternalAppHandler *ExternalAppHandler::sInstance = 0; static KStaticDeleter staticDeleter; - ExternalAppHandler::ExternalAppHandler() { mDefaultItems.setAutoDelete(true); + + mNameEmailUidListFromKAPITransfer = new QCopListTransferItem("requestNameEmailUIDListFromKAPI", "QPE/Application/kapi", "receiveNameEmailUIDList"); + connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForNameEmailUidList(const QString&, const QString&, const QString&))); + connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); + +//US mFindByEmailFromKAPITransfer = new QCopListTransferItem("requestFindByEmailFromKAPI", "QPE/Application/kapi", "receiveFindByEmailNameEmailUIDList"); +//US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForFindByEmail(const QString&, const QString&, const QString&))); +//US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedFindByEmailEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); + + } ExternalAppHandler::~ExternalAppHandler() @@ -391,7 +627,8 @@ bool ExternalAppHandler::mailToOneContact( const QString& adressline ) QString emailadress = line.mid(first+1, last-first-1); //Subject can not be handled right now. - mailToOneContact( name, emailadress ); + return mailToOneContact( name, emailadress ); + } @@ -679,3 +916,44 @@ void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& paramete +/************************************************************************** + * + **************************************************************************/ + +void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data ) +{ + bool res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); + +// if (!res) +// res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); +} + + + +bool ExternalAppHandler::requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid) +{ + mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); + return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(uid, QString::null); +} + +bool ExternalAppHandler::returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) +{ + mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); + return mNameEmailUidListFromKAPITransfer->sendMessageToSource(uid, list1, list2, list3); +} + +bool ExternalAppHandler::requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QString& email) +{ + mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); + return mFindByEmailFromKAPITransfer->sendMessageToTarget(uid, email); +} + +bool ExternalAppHandler::returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) +{ + mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); + return mFindByEmailFromKAPITransfer->sendMessageToSource(uid, list1, list2, list3); +} + + + + diff --git a/libkdepim/externalapphandler.h b/libkdepim/externalapphandler.h index 3cf9e06..7c8de4e 100644 --- a/libkdepim/externalapphandler.h +++ b/libkdepim/externalapphandler.h @@ -31,12 +31,88 @@ $Id$ #ifndef EXTERNALAPPHANDLER_H #define EXTERNALAPPHANDLER_H +#include #include +#include class QCopEnvelope; class ExternalAppHandler; +class QCopTransferItem : public QObject +{ + Q_OBJECT + public: + QCopTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); + QCopTransferItem(); + + bool sendMessageToTarget(const QString& uid, const QString& param1); + + void setSourceChannel(const QString& sourceChannel); + + virtual bool appMessage( const QCString& msg, const QByteArray& data ); + + + signals: + void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1); + + + public: + QString _sourceChannel; + QString _sourceMessage; + QString _sourceMessageParameters; + QString _targetChannel; + QString _targetMessage; + QString _targetMessageParameters; + +}; + +/********************************************************************************* + * + ********************************************************************************/ + +class QCopMapTransferItem : public QCopTransferItem +{ + Q_OBJECT + public: + QCopMapTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); + + bool sendMessageToSource(const QString& uid, const QMap& nameEmailMap); + + + virtual bool appMessage( const QCString& msg, const QByteArray& data ); + + + signals: + void receivedMessageFromTarget(const QString& uid, const QMap& nameEmailMap); + +}; + +/********************************************************************************* + * + ********************************************************************************/ + +class QCopListTransferItem : public QCopTransferItem +{ + Q_OBJECT + public: + QCopListTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); + + bool sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3); + + + virtual bool appMessage( const QCString& msg, const QByteArray& data ); + + + signals: + void receivedMessageFromTarget(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3); + +}; + +/********************************************************************************* + * + ********************************************************************************/ + class DefaultAppItem { @@ -60,8 +136,13 @@ class DefaultAppItem }; -class ExternalAppHandler +/********************************************************************************* + * + ********************************************************************************/ + +class ExternalAppHandler : public QObject { + Q_OBJECT public: virtual ~ExternalAppHandler(); @@ -112,6 +193,14 @@ class ExternalAppHandler bool isPagerAppAvailable(); + //Call this method on the source when you want to select names from the addressbook by using QCop + bool requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid); + //Call this method on the target when you want to return the name/email map to the source (client). + bool returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& name, const QStringList& email, const QStringList& uid); + + bool requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QString& email); + bool returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& name, const QStringList& email, const QStringList& uid); + //loadConfig clears the cache and checks again if the applications are available or not void loadConfig(); @@ -119,6 +208,21 @@ class ExternalAppHandler QList getAvailableDefaultItems(Types); DefaultAppItem* getDefaultItem(Types, int); + public slots: + void appMessage( const QCString& msg, const QByteArray& data ); + + + signals: + // Emmitted when the target app receives a request from the source app + void requestForNameEmailUidList(const QString& sourceChannel, const QString& uid, const QString& param1); + + // Emitted when the source app recieves a list of name/email pairs (=addresses) from another target app. Usually Ka/Pi + // The first parameter is a uniqueid. It can be used to identify the event + void receivedNameEmailUidListEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); + + void requestFindByEmail(const QString& sourceChannel, const QString& uid, const QString& email); + void receivedFindBbyEmailEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); + private: ExternalAppHandler(); @@ -130,6 +234,9 @@ class ExternalAppHandler Availability mSMSAppAvailable; Availability mPagerAppAvailable; + QCopListTransferItem* mNameEmailUidListFromKAPITransfer; + QCopListTransferItem* mFindByEmailFromKAPITransfer; + void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2); @@ -139,7 +246,7 @@ class ExternalAppHandler static ExternalAppHandler *sInstance; - }; + #endif -- cgit v0.9.0.2