author | ulf69 <ulf69> | 2004-08-17 00:09:26 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-17 00:09:26 (UTC) |
commit | ab3b10a5018152dedbdb64d0d5a4bd8ec752ccdb (patch) (unidiff) | |
tree | a9f62469297dda2981807b5235e7812cac72f44c /libkdepim/externalapphandler.cpp | |
parent | 0e46d151bca931ff5c69a637d91cfcc381094e0b (diff) | |
download | kdepimpi-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) (ignore whitespace changes)
-rw-r--r-- | libkdepim/externalapphandler.cpp | 282 |
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 | |||
@@ -44,21 +44,257 @@ $Id$ | |||
44 | #include "externalapphandler.h" | 44 | #include "externalapphandler.h" |
45 | 45 | ||
46 | #include "kpimglobalprefs.h" | 46 | #include "kpimglobalprefs.h" |
47 | 47 | ||
48 | /********************************************************************************* | ||
49 | * | ||
50 | ********************************************************************************/ | ||
51 | |||
52 | |||
53 | QCopTransferItem::QCopTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | ||
54 | : _sourceMessage(sourceMessage), _targetChannel(targetChannel), _targetMessage(targetMessage) | ||
55 | { | ||
56 | //sourceMessage passes later three parameters: sourceChannel, uid, param1 | ||
57 | _sourceMessageParameters = "(QString,QString,QString)"; | ||
58 | } | ||
59 | |||
60 | /*********************************************************************************/ | ||
61 | |||
62 | QCopTransferItem::QCopTransferItem() | ||
63 | { | ||
64 | } | ||
65 | |||
66 | /*********************************************************************************/ | ||
67 | bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& param1) | ||
68 | { | ||
69 | |||
70 | #ifndef DESKTOP_VERSION | ||
71 | //sourceMessage passes two parameters: sourceChannel, uid | ||
72 | QString sourceMessage = _sourceMessage + _sourceMessageParameters; | ||
73 | |||
74 | qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _targetChannel.latin1(), sourceMessage.latin1()); | ||
75 | qDebug("passing sourcechannel(%s), uid(%s), param1(%s) as parameter to QCopEnvelope", _sourceChannel.latin1(), uid.latin1(), param1.latin1()); | ||
76 | |||
77 | QCopEnvelope e(_targetChannel.latin1(), sourceMessage.latin1()); | ||
78 | |||
79 | e << _sourceChannel << uid << param1; | ||
80 | |||
81 | return true; | ||
82 | |||
83 | #else | ||
84 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); | ||
85 | return false; | ||
86 | #endif | ||
87 | |||
88 | } | ||
89 | |||
90 | |||
91 | /*********************************************************************************/ | ||
92 | void QCopTransferItem::setSourceChannel(const QString& sourceChannel) | ||
93 | { | ||
94 | |||
95 | if (_sourceChannel.isEmpty()) | ||
96 | _sourceChannel = sourceChannel; | ||
97 | } | ||
98 | |||
99 | |||
100 | /*********************************************************************************/ | ||
101 | bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | ||
102 | { | ||
103 | /*US | ||
104 | // copied from old mail2 | ||
105 | static int ii = 0; | ||
106 | |||
107 | // block second call | ||
108 | if ( ii < 2 ) { | ||
109 | ++ii; | ||
110 | if ( ii > 1 ) { | ||
111 | qDebug("qcop call blocked "); | ||
112 | return true; | ||
113 | } | ||
114 | } | ||
115 | */ | ||
116 | qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() ); | ||
117 | |||
118 | //we are in the target and get a request from the source | ||
119 | if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data()) | ||
120 | { | ||
121 | QDataStream stream( data, IO_ReadOnly ); | ||
122 | |||
123 | |||
124 | QString sourceChannel; | ||
125 | QString uid; | ||
126 | QString param1; | ||
48 | 127 | ||
128 | stream >> sourceChannel >> uid >> param1; | ||
49 | 129 | ||
130 | emit receivedMessageFromSource(sourceChannel, uid, param1); | ||
50 | 131 | ||
132 | return true; | ||
133 | } | ||
134 | |||
135 | return false; | ||
136 | } | ||
137 | |||
138 | |||
139 | /********************************************************************************* | ||
140 | * | ||
141 | ********************************************************************************/ | ||
142 | |||
143 | |||
144 | QCopMapTransferItem::QCopMapTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | ||
145 | : QCopTransferItem(sourceMessage, targetChannel,targetMessage) | ||
146 | { | ||
147 | //targetMessage returns later two parameters: uid, and map<qstring,qstring> | ||
148 | _targetMessageParameters = "(QString,QMAP<QString,QString>)"; | ||
149 | } | ||
150 | |||
151 | /*********************************************************************************/ | ||
152 | bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap<QString,QString>& nameEmailMap) | ||
153 | { | ||
154 | #ifndef DESKTOP_VERSION | ||
155 | //targetMessage passes two parameters: uid, map | ||
156 | QString targetMessage = _targetMessage + _targetMessageParameters; | ||
157 | |||
158 | qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); | ||
159 | qDebug("passing uid(%s) and map as parameter to QCopEnvelope", uid.latin1()); | ||
51 | 160 | ||
161 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); | ||
162 | //US we need no names in the To field. The emailadresses are enough | ||
163 | |||
164 | e << uid << nameEmailMap; | ||
165 | |||
166 | return true; | ||
167 | |||
168 | #else | ||
169 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); | ||
170 | return false; | ||
171 | #endif | ||
172 | |||
173 | } | ||
174 | |||
175 | |||
176 | /*********************************************************************************/ | ||
177 | bool QCopMapTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | ||
178 | { | ||
179 | bool res = QCopTransferItem::appMessage( cmsg, data ); | ||
180 | |||
181 | if (res == false) | ||
182 | { | ||
183 | QDataStream stream( data, IO_ReadOnly ); | ||
184 | |||
185 | qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() ); | ||
186 | |||
187 | //we are in the source and get an answer from the target | ||
188 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) | ||
189 | { | ||
190 | QMap<QString,QString> adrMap; | ||
191 | QString uid; | ||
192 | |||
193 | stream >> uid >> adrMap; | ||
194 | |||
195 | emit receivedMessageFromTarget(uid, adrMap); | ||
196 | |||
197 | |||
198 | return true; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return false; | ||
203 | } | ||
204 | |||
205 | |||
206 | /********************************************************************************* | ||
207 | * | ||
208 | ********************************************************************************/ | ||
209 | |||
210 | |||
211 | QCopListTransferItem::QCopListTransferItem(const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | ||
212 | : QCopTransferItem(sourceMessage, targetChannel,targetMessage) | ||
213 | { | ||
214 | //targetMessage returns later two parameters: uid, and map<qstring,qstring> | ||
215 | _targetMessageParameters = "(QString,QStringList,QStringList,QStringList)"; | ||
216 | } | ||
217 | |||
218 | /*********************************************************************************/ | ||
219 | bool QCopListTransferItem::sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) | ||
220 | { | ||
221 | #ifndef DESKTOP_VERSION | ||
222 | //targetMessage passes two parameters: uid, map | ||
223 | QString targetMessage = _targetMessage + _targetMessageParameters; | ||
224 | |||
225 | qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); | ||
226 | qDebug("passing uid(%s) and list1, list2, list3 as parameter to QCopEnvelope", uid.latin1()); | ||
227 | |||
228 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); | ||
229 | //US we need no names in the To field. The emailadresses are enough | ||
230 | |||
231 | e << uid << list1 << list2 << list3; | ||
232 | |||
233 | return true; | ||
234 | |||
235 | #else | ||
236 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); | ||
237 | return false; | ||
238 | #endif | ||
239 | |||
240 | } | ||
241 | |||
242 | |||
243 | /*********************************************************************************/ | ||
244 | bool QCopListTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | ||
245 | { | ||
246 | bool res = QCopTransferItem::appMessage( cmsg, data ); | ||
247 | |||
248 | if (res == false) | ||
249 | { | ||
250 | QDataStream stream( data, IO_ReadOnly ); | ||
251 | |||
252 | qDebug("QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); | ||
253 | |||
254 | //we are in the source and get an answer from the target | ||
255 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) | ||
256 | { | ||
257 | QStringList list1; | ||
258 | QStringList list2; | ||
259 | QStringList list3; | ||
260 | QString uid; | ||
261 | |||
262 | stream >> uid >> list1 >> list2 >> list3; | ||
263 | |||
264 | emit receivedMessageFromTarget(uid, list1, list2, list3); | ||
265 | |||
266 | |||
267 | return true; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | return false; | ||
272 | } | ||
273 | |||
274 | |||
275 | |||
276 | /********************************************************************************* | ||
277 | * | ||
278 | ********************************************************************************/ | ||
52 | 279 | ||
53 | 280 | ||
54 | ExternalAppHandler *ExternalAppHandler::sInstance = 0; | 281 | ExternalAppHandler *ExternalAppHandler::sInstance = 0; |
55 | static KStaticDeleter<ExternalAppHandler> staticDeleter; | 282 | static KStaticDeleter<ExternalAppHandler> staticDeleter; |
56 | 283 | ||
57 | |||
58 | ExternalAppHandler::ExternalAppHandler() | 284 | ExternalAppHandler::ExternalAppHandler() |
59 | { | 285 | { |
60 | mDefaultItems.setAutoDelete(true); | 286 | mDefaultItems.setAutoDelete(true); |
287 | |||
288 | mNameEmailUidListFromKAPITransfer = new QCopListTransferItem("requestNameEmailUIDListFromKAPI", "QPE/Application/kapi", "receiveNameEmailUIDList"); | ||
289 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForNameEmailUidList(const QString&, const QString&, const QString&))); | ||
290 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); | ||
291 | |||
292 | //US mFindByEmailFromKAPITransfer = new QCopListTransferItem("requestFindByEmailFromKAPI", "QPE/Application/kapi", "receiveFindByEmailNameEmailUIDList"); | ||
293 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForFindByEmail(const QString&, const QString&, const QString&))); | ||
294 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedFindByEmailEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); | ||
295 | |||
296 | |||
61 | } | 297 | } |
62 | 298 | ||
63 | ExternalAppHandler::~ExternalAppHandler() | 299 | ExternalAppHandler::~ExternalAppHandler() |
64 | { | 300 | { |
@@ -390,9 +626,10 @@ bool ExternalAppHandler::mailToOneContact( const QString& adressline ) | |||
390 | QString name = line.left(first); | 626 | QString name = line.left(first); |
391 | QString emailadress = line.mid(first+1, last-first-1); | 627 | QString emailadress = line.mid(first+1, last-first-1); |
392 | 628 | ||
393 | //Subject can not be handled right now. | 629 | //Subject can not be handled right now. |
394 | mailToOneContact( name, emailadress ); | 630 | return mailToOneContact( name, emailadress ); |
631 | |||
395 | } | 632 | } |
396 | 633 | ||
397 | 634 | ||
398 | /************************************************************************** | 635 | /************************************************************************** |
@@ -678,4 +915,45 @@ void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& paramete | |||
678 | } | 915 | } |
679 | 916 | ||
680 | 917 | ||
681 | 918 | ||
919 | /************************************************************************** | ||
920 | * | ||
921 | **************************************************************************/ | ||
922 | |||
923 | void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data ) | ||
924 | { | ||
925 | bool res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); | ||
926 | |||
927 | // if (!res) | ||
928 | // res = mNameEmailUidListFromKAPITransfer->appMessage( cmsg, data ); | ||
929 | } | ||
930 | |||
931 | |||
932 | |||
933 | bool ExternalAppHandler::requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid) | ||
934 | { | ||
935 | mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); | ||
936 | return mNameEmailUidListFromKAPITransfer->sendMessageToTarget(uid, QString::null); | ||
937 | } | ||
938 | |||
939 | bool ExternalAppHandler::returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) | ||
940 | { | ||
941 | mNameEmailUidListFromKAPITransfer->setSourceChannel(sourceChannel); | ||
942 | return mNameEmailUidListFromKAPITransfer->sendMessageToSource(uid, list1, list2, list3); | ||
943 | } | ||
944 | |||
945 | bool ExternalAppHandler::requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QString& email) | ||
946 | { | ||
947 | mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); | ||
948 | return mFindByEmailFromKAPITransfer->sendMessageToTarget(uid, email); | ||
949 | } | ||
950 | |||
951 | bool ExternalAppHandler::returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3) | ||
952 | { | ||
953 | mFindByEmailFromKAPITransfer->setSourceChannel(sourceChannel); | ||
954 | return mFindByEmailFromKAPITransfer->sendMessageToSource(uid, list1, list2, list3); | ||
955 | } | ||
956 | |||
957 | |||
958 | |||
959 | |||