summaryrefslogtreecommitdiffabout
path: root/libkdepim/externalapphandler.cpp
authorulf69 <ulf69>2004-08-17 00:09:26 (UTC)
committer ulf69 <ulf69>2004-08-17 00:09:26 (UTC)
commitab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb (patch) (side-by-side diff)
treea9f62469297dda2981807b5235e7812cac72f44c /libkdepim/externalapphandler.cpp
parent0e46d151bca931ff5c69a637d91cfcc381094e0b (diff)
downloadkdepimpi-ab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb.zip
kdepimpi-ab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb.tar.gz
kdepimpi-ab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb.tar.bz2
QCop implementation for KOrganizer to access Ka/pi directly
Diffstat (limited to 'libkdepim/externalapphandler.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp282
1 files changed, 280 insertions, 2 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
index 35638b1..64caa7d 100644
--- a/libkdepim/externalapphandler.cpp
+++ b/libkdepim/externalapphandler.cpp
@@ -1,108 +1,344 @@
/*
This file is part of libkdepim.
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <stdlib.h>
#include <qfile.h>
#include <qmap.h>
#include <qregexp.h>
#ifndef DESKTOP_VERSION
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <kstaticdeleter.h>
#include <kmessagebox.h>
#include "externalapphandler.h"
#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<qstring,qstring>
+ _targetMessageParameters = "(QString,QMAP<QString,QString>)";
+}
+
+/*********************************************************************************/
+bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap<QString,QString>& 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<QString,QString> 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<qstring,qstring>
+ _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<ExternalAppHandler> 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()
{
}
void ExternalAppHandler::loadConfig()
{
mDefaultItems.clear();
mEmailAppAvailable = UNDEFINED;
mPhoneAppAvailable = UNDEFINED;
mFaxAppAvailable = UNDEFINED;
mSMSAppAvailable = UNDEFINED;
mPagerAppAvailable = UNDEFINED;
QString opiepath = QString::fromLatin1( getenv("OPIEDIR") );
QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") );
if (opiepath.isEmpty())
opiepath = qtopiapath;
//mailclients
QString mailmsg1 = "writeMail(QString,QString)";
QString mailmsg2 = "writeMail(QMap(QString,QString))";
QString undefined = "";
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined);
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined);
if (( QFile::exists( qtopiapath + "/bin/ompi" )) ||
( QFile::exists( opiepath + "/bin/ompi" )))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2");
if ( QFile::exists( qtopiapath + "/bin/qtmail" ))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2");
if ( QFile::exists( opiepath + "/bin/opiemail" ))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2");
//phoneclients
addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined);
@@ -346,97 +582,98 @@ bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& e
{
qDebug("could not find configured email application.");
return false;
}
channel = dai->_channel;
message = dai->_message;
parameters = dai->_parameters;
}
//first check if one of the mailers need the emails right in the message.
message = translateMessage(message, name, emailadress);
qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
qDebug("passing name(%s), emailadresses(%s) as parameters in the form %s to QCopEnvelope", name.latin1(), emailadress.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameters(&e, parameters, name, emailadress);
#else
KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) );
#endif
return true;
}
/**************************************************************************
*
**************************************************************************/
//calls the emailapplication and creates a mail with parameter as recipients
// parameters format is
// NAME <EMAIL>:SUBJECT
bool ExternalAppHandler::mailToOneContact( const QString& adressline )
{
QString line = adressline;
int first = line.find( "<");
int last = line.find( ">");
QString name = line.left(first);
QString emailadress = line.mid(first+1, last-first-1);
//Subject can not be handled right now.
- mailToOneContact( name, emailadress );
+ return mailToOneContact( name, emailadress );
+
}
/**************************************************************************
*
**************************************************************************/
//calls the phoneapplication with the number
bool ExternalAppHandler::callByPhone( const QString& phonenumber )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mPhoneClient;
if (client == KPimGlobalPrefs::OTHER_PHC)
{
channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel;
message = KPimGlobalPrefs::instance()->mPhoneOtherMessage;
parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters;
}
else
{
DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client);
if (!dai)
{
qDebug("could not find configured phone application.");
return false;
}
channel = dai->_channel;
message = dai->_message;
parameters = dai->_parameters;
}
//first check if one of the mailers need the emails right in the message.
message = translateMessage(message, phonenumber, "");
qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
qDebug("passing phonenumber(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameters(&e, parameters, phonenumber, "");
@@ -634,48 +871,89 @@ void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& paramete
{
#ifndef DESKTOP_VERSION
QMap<QString, QString> valmap;
bool useValMap = false;
// first extract all parts of the parameters.
QStringList paramlist = QStringList::split(";", parameters);
//Now check how many parts we have.
//=0 :no params to pass
//>0 :parameters to pass
for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it )
{
QString param = (*it);
QStringList keyvallist = QStringList::split("=", param);
//if we have keyvalue pairs, we assume that we pass a map to the envelope
QStringList::Iterator it2 = keyvallist.begin();
QString key = (*it2);
key = key.replace( QRegExp("%1"), param1 );
key = key.replace( QRegExp("%2"), param2 );
++it2;
if(it2 != keyvallist.end())
{
QString value = (*it2);
value = value.replace( QRegExp("%1"), param1 );
value = value.replace( QRegExp("%2"), param2 );
valmap.insert(key, value);
useValMap = true;
}
else
{
// qDebug("pass parameter << %s", key.latin1());
(*e) << key;
}
}
if (useValMap == true)
(*e) << valmap;
#endif
}
+/**************************************************************************
+ *
+ **************************************************************************/
+
+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);
+}
+
+
+
+