summaryrefslogtreecommitdiffabout
path: root/libkdepim/externalapphandler.cpp
Unidiff
Diffstat (limited to 'libkdepim/externalapphandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
index 0e9c5e5..2ce6926 100644
--- a/libkdepim/externalapphandler.cpp
+++ b/libkdepim/externalapphandler.cpp
@@ -1,128 +1,129 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30#include <stdlib.h> 30#include <stdlib.h>
31 31
32#include <qfile.h> 32#include <qfile.h>
33#include <qtimer.h>
33#include <qmap.h> 34#include <qmap.h>
34#include <qregexp.h> 35#include <qregexp.h>
35 36
36#ifndef DESKTOP_VERSION 37#ifndef DESKTOP_VERSION
37#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
38#include <qtopia/qcopenvelope_qws.h> 39#include <qtopia/qcopenvelope_qws.h>
39#else 40#else
40#include <qapplication.h> 41#include <qapplication.h>
41#endif 42#endif
42 43
43#include <kstaticdeleter.h> 44#include <kstaticdeleter.h>
44#include <kmessagebox.h> 45#include <kmessagebox.h>
45 46
46 47
47#include "externalapphandler.h" 48#include "externalapphandler.h"
48 49
49#include "kpimglobalprefs.h" 50#include "kpimglobalprefs.h"
50 51
51//uncomment line to get debug output 52//uncomment line to get debug output
52//#define DEBUG_EXT_APP_HANDLER 53//#define DEBUG_EXT_APP_HANDLER
53 54
54/********************************************************************************* 55/*********************************************************************************
55 * 56 *
56 ********************************************************************************/ 57 ********************************************************************************/
57 58
58 59
59QCopTransferItem::QCopTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) 60QCopTransferItem::QCopTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage)
60 : _usedSourceParameters(usedSourceParameters), _sourceMessage(sourceMessage), _targetChannel(targetChannel), _targetMessage(targetMessage) 61 : _usedSourceParameters(usedSourceParameters), _sourceMessage(sourceMessage), _targetChannel(targetChannel), _targetMessage(targetMessage)
61{ 62{
62 //sourceMessage passes later three parameters: sourceChannel, uid, param1 63 //sourceMessage passes later three parameters: sourceChannel, uid, param1
63 if (_usedSourceParameters == 0) 64 if (_usedSourceParameters == 0)
64 _sourceMessageParameters = "QString,QString)"; 65 _sourceMessageParameters = "QString,QString)";
65 else if (_usedSourceParameters == 1) 66 else if (_usedSourceParameters == 1)
66 _sourceMessageParameters = "(QString,QString,QString)"; 67 _sourceMessageParameters = "(QString,QString,QString)";
67 else if (_usedSourceParameters == 2) 68 else if (_usedSourceParameters == 2)
68 _sourceMessageParameters = "(QString,QString,QString,QString)"; 69 _sourceMessageParameters = "(QString,QString,QString,QString)";
69 else if (_usedSourceParameters == 3) 70 else if (_usedSourceParameters == 3)
70 _sourceMessageParameters = "(QString,QString,QString,QString,QString)"; 71 _sourceMessageParameters = "(QString,QString,QString,QString,QString)";
71} 72}
72 73
73/*********************************************************************************/ 74/*********************************************************************************/
74 75
75QCopTransferItem::QCopTransferItem() 76QCopTransferItem::QCopTransferItem()
76{ 77{
77} 78}
78 79
79/*********************************************************************************/ 80/*********************************************************************************/
80bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& param1, const QString& param2, const QString& param3) 81bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& param1, const QString& param2, const QString& param3)
81{ 82{
82 83
83#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
84 //sourceMessage passes two parameters: sourceChannel, uid 85 //sourceMessage passes two parameters: sourceChannel, uid
85 QString sourceMessage = _sourceMessage + _sourceMessageParameters; 86 QString sourceMessage = _sourceMessage + _sourceMessageParameters;
86#ifdef DEBUG_EXT_APP_HANDLER 87#ifdef DEBUG_EXT_APP_HANDLER
87 qDebug("1Using QCopEnvelope e(\"%s\",\"%s\")", _targetChannel.latin1(), sourceMessage.latin1()); 88 qDebug("1Using QCopEnvelope e(\"%s\",\"%s\")", _targetChannel.latin1(), sourceMessage.latin1());
88 qDebug("passing sourcechannel(%s), uid(%s), param1(%s), param2(%s), param3(%s) as parameter to QCopEnvelope", _sourceChannel.latin1(), uid.latin1(), param1.latin1(), param2.latin1(), param3.latin1()); 89 qDebug("passing sourcechannel(%s), uid(%s), param1(%s), param2(%s), param3(%s) as parameter to QCopEnvelope", _sourceChannel.latin1(), uid.latin1(), param1.latin1(), param2.latin1(), param3.latin1());
89#endif 90#endif
90 91
91 QCopEnvelope e(_targetChannel.latin1(), sourceMessage.latin1()); 92 QCopEnvelope e(_targetChannel.latin1(), sourceMessage.latin1());
92 93
93 e << _sourceChannel << uid; 94 e << _sourceChannel << uid;
94 95
95 if (_usedSourceParameters == 1) 96 if (_usedSourceParameters == 1)
96 e << param1; 97 e << param1;
97 else if (_usedSourceParameters == 2) 98 else if (_usedSourceParameters == 2)
98 e << param1 << param2; 99 e << param1 << param2;
99 else if (_usedSourceParameters == 3) 100 else if (_usedSourceParameters == 3)
100 e << param1 << param2 << param3; 101 e << param1 << param2 << param3;
101 102
102 qApp->processEvents(); 103 qApp->processEvents();
103 104
104 return true; 105 return true;
105 106
106#else 107#else
107 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); 108 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) );
108 return false; 109 return false;
109#endif 110#endif
110 111
111} 112}
112 113
113 114
114/*********************************************************************************/ 115/*********************************************************************************/
115void QCopTransferItem::setSourceChannel(const QString& sourceChannel) 116void QCopTransferItem::setSourceChannel(const QString& sourceChannel)
116{ 117{
117 118
118 if ( !sourceChannel.isEmpty()) 119 if ( !sourceChannel.isEmpty())
119 _sourceChannel = sourceChannel; 120 _sourceChannel = sourceChannel;
120} 121}
121 122
122 123
123/*********************************************************************************/ 124/*********************************************************************************/
124bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) 125bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data )
125{ 126{
126 127
127 // copied from old mail2 128 // copied from old mail2
128/* 129/*
@@ -1036,176 +1037,181 @@ bool ExternalAppHandler::callBySIP( const QString& sipnumber )
1036 1037
1037 1038
1038 //first check if one of the sip apps need the emails right in the message. 1039 //first check if one of the sip apps need the emails right in the message.
1039 message = translateMessage(message, sipnumber, ""); 1040 message = translateMessage(message, sipnumber, "");
1040 1041
1041 1042
1042#ifdef DEBUG_EXT_APP_HANDLER 1043#ifdef DEBUG_EXT_APP_HANDLER
1043 qDebug("10Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 1044 qDebug("10Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
1044 qDebug("passing sipnumber(%s) as parameter in the form %s to QCopEnvelope", sipnumber.latin1(), parameters.latin1()); 1045 qDebug("passing sipnumber(%s) as parameter in the form %s to QCopEnvelope", sipnumber.latin1(), parameters.latin1());
1045#endif 1046#endif
1046 1047
1047 QCopEnvelope e(channel.latin1(), message.latin1()); 1048 QCopEnvelope e(channel.latin1(), message.latin1());
1048 //US we need no names in the To field. The emailadresses are enough 1049 //US we need no names in the To field. The emailadresses are enough
1049 1050
1050 passParameters(&e, parameters, sipnumber, ""); 1051 passParameters(&e, parameters, sipnumber, "");
1051 1052
1052 1053
1053#else 1054#else
1054 KMessageBox::sorry( 0, i18n( "This version does not support sip." ) ); 1055 KMessageBox::sorry( 0, i18n( "This version does not support sip." ) );
1055#endif 1056#endif
1056 1057
1057 1058
1058 return true; 1059 return true;
1059} 1060}
1060 1061
1061 1062
1062/************************************************************************** 1063/**************************************************************************
1063 * 1064 *
1064 **************************************************************************/ 1065 **************************************************************************/
1065 1066
1066 1067
1067QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1, const QString& param2 ) const 1068QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1, const QString& param2 ) const
1068{ 1069{
1069 message = message.replace( QRegExp("%1"), param1 ); 1070 message = message.replace( QRegExp("%1"), param1 );
1070 return message.replace( QRegExp("%2"), param2 ); 1071 return message.replace( QRegExp("%2"), param2 );
1071} 1072}
1072 1073
1073/************************************************************************** 1074/**************************************************************************
1074 * 1075 *
1075 **************************************************************************/ 1076 **************************************************************************/
1076 1077
1077void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& parameters, const QString& param1 , const QString& param2) const 1078void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& parameters, const QString& param1 , const QString& param2) const
1078{ 1079{
1079#ifndef DESKTOP_VERSION 1080#ifndef DESKTOP_VERSION
1080 QMap<QString, QString> valmap; 1081 QMap<QString, QString> valmap;
1081 bool useValMap = false; 1082 bool useValMap = false;
1082 1083
1083 // first extract all parts of the parameters. 1084 // first extract all parts of the parameters.
1084 QStringList paramlist = QStringList::split(";", parameters); 1085 QStringList paramlist = QStringList::split(";", parameters);
1085 1086
1086 //Now check how many parts we have. 1087 //Now check how many parts we have.
1087 //=0 :no params to pass 1088 //=0 :no params to pass
1088 //>0 :parameters to pass 1089 //>0 :parameters to pass
1089 for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it ) 1090 for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it )
1090 { 1091 {
1091 QString param = (*it); 1092 QString param = (*it);
1092 QStringList keyvallist = QStringList::split("=", param); 1093 QStringList keyvallist = QStringList::split("=", param);
1093 1094
1094 //if we have keyvalue pairs, we assume that we pass a map to the envelope 1095 //if we have keyvalue pairs, we assume that we pass a map to the envelope
1095 QStringList::Iterator it2 = keyvallist.begin(); 1096 QStringList::Iterator it2 = keyvallist.begin();
1096 QString key = (*it2); 1097 QString key = (*it2);
1097 key = key.replace( QRegExp("%1"), param1 ); 1098 key = key.replace( QRegExp("%1"), param1 );
1098 key = key.replace( QRegExp("%2"), param2 ); 1099 key = key.replace( QRegExp("%2"), param2 );
1099 ++it2; 1100 ++it2;
1100 1101
1101 if(it2 != keyvallist.end()) 1102 if(it2 != keyvallist.end())
1102 { 1103 {
1103 QString value = (*it2); 1104 QString value = (*it2);
1104 value = value.replace( QRegExp("%1"), param1 ); 1105 value = value.replace( QRegExp("%1"), param1 );
1105 value = value.replace( QRegExp("%2"), param2 ); 1106 value = value.replace( QRegExp("%2"), param2 );
1106 1107
1107 valmap.insert(key, value); 1108 valmap.insert(key, value);
1108 useValMap = true; 1109 useValMap = true;
1109 } 1110 }
1110 else 1111 else
1111 { 1112 {
1112 // qDebug("pass parameter << %s", key.latin1()); 1113 // qDebug("pass parameter << %s", key.latin1());
1113 (*e) << key; 1114 (*e) << key;
1114 } 1115 }
1115 } 1116 }
1116 1117
1117 if (useValMap == true) 1118 if (useValMap == true)
1118 (*e) << valmap; 1119 (*e) << valmap;
1119 1120
1120#endif 1121#endif
1121 1122
1122} 1123}
1123 1124
1124 1125
1125 1126
1126/************************************************************************** 1127/**************************************************************************
1127 * 1128 *
1128 **************************************************************************/ 1129 **************************************************************************/
1129 1130
1130void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data ) 1131void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data )
1131{ 1132{
1132 1133 qDebug("ExternalAppHandler::appMessage %s %x", cmsg.data(), this);
1133 if ( cmsg == "nextView()" ) { 1134 if ( cmsg == "nextView()" ) {
1134 qDebug("nextView()"); 1135 qDebug("nextView()");
1135 emit nextView(); 1136 QTimer::singleShot( 0, this, SIGNAL ( nextView() ));
1136 return; 1137 return;
1137 } 1138 }
1138 if ( cmsg == "callContactdialog()" ) { 1139 if ( cmsg == "callContactdialog()" ) {
1139 qDebug("callContactdialog()"); 1140 qDebug("callContactdialog()");
1140 emit callContactdialog(); 1141 QTimer::singleShot( 0, this, SIGNAL ( callContactdialog() ));
1142 return;
1143 }
1144 if ( cmsg == "doRingSync" ) {
1145 qDebug("doRingSync");
1146 QTimer::singleShot( 0, this, SIGNAL ( doRingSync() ));
1141 return; 1147 return;
1142 } 1148 }
1143 1149
1144 bool res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); 1150 bool res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data );
1145 if (!res) 1151 if (!res)
1146 res = mBirthdayListFromKAPITransfer->appMessage( cmsg, data ); 1152 res = mBirthdayListFromKAPITransfer->appMessage( cmsg, data );
1147 1153
1148 if (!res) 1154 if (!res)
1149 res = mDisplayDetails->appMessage( cmsg, data ); 1155 res = mDisplayDetails->appMessage( cmsg, data );
1150 1156
1151// if (!res) 1157// if (!res)
1152// res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); 1158// res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data );
1153} 1159}
1154 1160
1155 1161
1156 1162
1157bool ExternalAppHandler::requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid) 1163bool ExternalAppHandler::requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid)
1158{ 1164{
1159 mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); 1165 mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel);
1160 // maybe we are sending to KA/Pi fom a different worldd... 1166 // maybe we are sending to KA/Pi fom a different worldd...
1161 // it may be that the QAplication::desktop()->width() values in KA/Pi are not the same as in our application 1167 // it may be that the QAplication::desktop()->width() values in KA/Pi are not the same as in our application
1162 // for that reason we send the current QApplication::desktop()->width() to KA/Pi 1168 // for that reason we send the current QApplication::desktop()->width() to KA/Pi
1163 //qDebug("UID %s ", sessionuid.latin1()); 1169 //qDebug("UID %s ", sessionuid.latin1());
1164 //return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(QString::number ( QApplication::desktop()->width() )); 1170 //return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(QString::number ( QApplication::desktop()->width() ));
1165 return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(sessionuid); 1171 return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(sessionuid);
1166} 1172}
1167 1173
1168bool ExternalAppHandler::returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3) 1174bool ExternalAppHandler::returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3)
1169{ 1175{
1170 QStringList list4, list5, list6; 1176 QStringList list4, list5, list6;
1171 1177
1172 mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); 1178 mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel);
1173 return mNameEmailUidListFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6); 1179 return mNameEmailUidListFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6);
1174} 1180}
1175 1181
1176bool ExternalAppHandler::requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QString& email) 1182bool ExternalAppHandler::requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QString& email)
1177{ 1183{
1178 mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); 1184 mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel);
1179 return mFindByEmailFromKAPITransfer->sendMessageToTarget(sessionuid, email); 1185 return mFindByEmailFromKAPITransfer->sendMessageToTarget(sessionuid, email);
1180} 1186}
1181 1187
1182bool ExternalAppHandler::returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3) 1188bool ExternalAppHandler::returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3)
1183{ 1189{
1184 QStringList list4, list5, list6; 1190 QStringList list4, list5, list6;
1185 1191
1186 mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); 1192 mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel);
1187 return mFindByEmailFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6); 1193 return mFindByEmailFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6);
1188} 1194}
1189 1195
1190bool ExternalAppHandler::requestDetailsFromKAPI(const QString& name, const QString& email, const QString& uid) 1196bool ExternalAppHandler::requestDetailsFromKAPI(const QString& name, const QString& email, const QString& uid)
1191{ 1197{
1192 mDisplayDetails->setSourceChannel(""); 1198 mDisplayDetails->setSourceChannel("");
1193 return mDisplayDetails->sendMessageToTarget("", name, email, uid); 1199 return mDisplayDetails->sendMessageToTarget("", name, email, uid);
1194} 1200}
1195 1201
1196bool ExternalAppHandler::requestBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid) 1202bool ExternalAppHandler::requestBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid)
1197{ 1203{
1198 mBirthdayListFromKAPITransfer->setSourceChannel(sourceChannel); 1204 mBirthdayListFromKAPITransfer->setSourceChannel(sourceChannel);
1199 return mBirthdayListFromKAPITransfer->sendMessageToTarget(sessionuid); 1205 return mBirthdayListFromKAPITransfer->sendMessageToTarget(sessionuid);
1200} 1206}
1201 1207
1202bool ExternalAppHandler::returnBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6) 1208bool ExternalAppHandler::returnBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6)
1203{ 1209{
1204 mBirthdayListFromKAPITransfer->setSourceChannel(sourceChannel); 1210 mBirthdayListFromKAPITransfer->setSourceChannel(sourceChannel);
1205 return mBirthdayListFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6); 1211 return mBirthdayListFromKAPITransfer->sendMessageToSource(sessionuid, list1, list2, list3, list4, list5, list6);
1206} 1212}
1207 1213
1208 1214
1209 1215
1210 1216
1211 1217