author | zautrix <zautrix> | 2005-06-29 16:14:46 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-29 16:14:46 (UTC) |
commit | 77aa480c9891a90c9b492618ebfd2b20f2d0727a (patch) (unidiff) | |
tree | 4f2c278d016fe21f280f8ee6abbca34685aada96 /libkdepim | |
parent | e0fa858c284dddf0d47146e666c4ece7158487be (diff) | |
download | kdepimpi-77aa480c9891a90c9b492618ebfd2b20f2d0727a.zip kdepimpi-77aa480c9891a90c9b492618ebfd2b20f2d0727a.tar.gz kdepimpi-77aa480c9891a90c9b492618ebfd2b20f2d0727a.tar.bz2 |
many sync fixes
-rw-r--r-- | libkdepim/externalapphandler.cpp | 12 | ||||
-rw-r--r-- | libkdepim/externalapphandler.h | 1 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 18 |
3 files changed, 20 insertions, 11 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp index 0e9c5e5..2ce6926 100644 --- a/libkdepim/externalapphandler.cpp +++ b/libkdepim/externalapphandler.cpp | |||
@@ -1,1211 +1,1217 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 | ||
59 | QCopTransferItem::QCopTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | 60 | QCopTransferItem::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 | ||
75 | QCopTransferItem::QCopTransferItem() | 76 | QCopTransferItem::QCopTransferItem() |
76 | { | 77 | { |
77 | } | 78 | } |
78 | 79 | ||
79 | /*********************************************************************************/ | 80 | /*********************************************************************************/ |
80 | bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& param1, const QString& param2, const QString& param3) | 81 | bool 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 | /*********************************************************************************/ |
115 | void QCopTransferItem::setSourceChannel(const QString& sourceChannel) | 116 | void 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 | /*********************************************************************************/ |
124 | bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | 125 | bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) |
125 | { | 126 | { |
126 | 127 | ||
127 | // copied from old mail2 | 128 | // copied from old mail2 |
128 | /* | 129 | /* |
129 | static int ii = 0; | 130 | static int ii = 0; |
130 | 131 | ||
131 | // block second call | 132 | // block second call |
132 | if ( ii < 2 ) { | 133 | if ( ii < 2 ) { |
133 | ++ii; | 134 | ++ii; |
134 | if ( ii > 1 ) { | 135 | if ( ii > 1 ) { |
135 | qDebug("qcop call blocked "); | 136 | qDebug("qcop call blocked "); |
136 | return true; | 137 | return true; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | */ | 140 | */ |
140 | 141 | ||
141 | // qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() ); | 142 | // qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() ); |
142 | 143 | ||
143 | //we are in the target and get a request from the source | 144 | //we are in the target and get a request from the source |
144 | if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data()) | 145 | if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data()) |
145 | { | 146 | { |
146 | 147 | ||
147 | QDataStream stream( data, IO_ReadOnly ); | 148 | QDataStream stream( data, IO_ReadOnly ); |
148 | 149 | ||
149 | 150 | ||
150 | QString sourceChannel; | 151 | QString sourceChannel; |
151 | QString uid; | 152 | QString uid; |
152 | QString param1; | 153 | QString param1; |
153 | QString param2; | 154 | QString param2; |
154 | QString param3; | 155 | QString param3; |
155 | 156 | ||
156 | stream >> sourceChannel >> uid; | 157 | stream >> sourceChannel >> uid; |
157 | 158 | ||
158 | if (_usedSourceParameters == 0) | 159 | if (_usedSourceParameters == 0) |
159 | { | 160 | { |
160 | emit receivedMessageFromSource(sourceChannel, uid); | 161 | emit receivedMessageFromSource(sourceChannel, uid); |
161 | } | 162 | } |
162 | else if (_usedSourceParameters == 1) | 163 | else if (_usedSourceParameters == 1) |
163 | { | 164 | { |
164 | stream >> param1; | 165 | stream >> param1; |
165 | emit receivedMessageFromSource(sourceChannel, uid, param1); | 166 | emit receivedMessageFromSource(sourceChannel, uid, param1); |
166 | } | 167 | } |
167 | else if (_usedSourceParameters == 2) | 168 | else if (_usedSourceParameters == 2) |
168 | { | 169 | { |
169 | stream >> param1 >> param2; | 170 | stream >> param1 >> param2; |
170 | emit receivedMessageFromSource(sourceChannel, uid, param1, param2); | 171 | emit receivedMessageFromSource(sourceChannel, uid, param1, param2); |
171 | } | 172 | } |
172 | else if (_usedSourceParameters == 3) | 173 | else if (_usedSourceParameters == 3) |
173 | { | 174 | { |
174 | stream >> param1 >> param2 >> param3; | 175 | stream >> param1 >> param2 >> param3; |
175 | emit receivedMessageFromSource(sourceChannel, uid, param1, param2, param3); | 176 | emit receivedMessageFromSource(sourceChannel, uid, param1, param2, param3); |
176 | } | 177 | } |
177 | 178 | ||
178 | return true; | 179 | return true; |
179 | } | 180 | } |
180 | 181 | ||
181 | return false; | 182 | return false; |
182 | } | 183 | } |
183 | 184 | ||
184 | 185 | ||
185 | /********************************************************************************* | 186 | /********************************************************************************* |
186 | * | 187 | * |
187 | ********************************************************************************/ | 188 | ********************************************************************************/ |
188 | 189 | ||
189 | 190 | ||
190 | QCopMapTransferItem::QCopMapTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | 191 | QCopMapTransferItem::QCopMapTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) |
191 | : QCopTransferItem(usedSourceParameters, sourceMessage, targetChannel,targetMessage) | 192 | : QCopTransferItem(usedSourceParameters, sourceMessage, targetChannel,targetMessage) |
192 | { | 193 | { |
193 | //targetMessage returns later two parameters: uid, and map<qstring,qstring> | 194 | //targetMessage returns later two parameters: uid, and map<qstring,qstring> |
194 | _targetMessageParameters = "(QString,QMAP<QString,QString>)"; | 195 | _targetMessageParameters = "(QString,QMAP<QString,QString>)"; |
195 | } | 196 | } |
196 | 197 | ||
197 | /*********************************************************************************/ | 198 | /*********************************************************************************/ |
198 | bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap<QString,QString>& nameEmailMap) | 199 | bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap<QString,QString>& nameEmailMap) |
199 | { | 200 | { |
200 | #ifndef DESKTOP_VERSION | 201 | #ifndef DESKTOP_VERSION |
201 | //targetMessage passes two parameters: uid, map | 202 | //targetMessage passes two parameters: uid, map |
202 | QString targetMessage = _targetMessage + _targetMessageParameters; | 203 | QString targetMessage = _targetMessage + _targetMessageParameters; |
203 | 204 | ||
204 | #ifdef DEBUG_EXT_APP_HANDLER | 205 | #ifdef DEBUG_EXT_APP_HANDLER |
205 | qDebug("2Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); | 206 | qDebug("2Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); |
206 | qDebug("passing uid(%s) and map as parameter to QCopEnvelope", uid.latin1()); | 207 | qDebug("passing uid(%s) and map as parameter to QCopEnvelope", uid.latin1()); |
207 | #endif | 208 | #endif |
208 | 209 | ||
209 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); | 210 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); |
210 | //US we need no names in the To field. The emailadresses are enough | 211 | //US we need no names in the To field. The emailadresses are enough |
211 | 212 | ||
212 | e << uid << nameEmailMap; | 213 | e << uid << nameEmailMap; |
213 | 214 | ||
214 | qApp->processEvents(); | 215 | qApp->processEvents(); |
215 | 216 | ||
216 | return true; | 217 | return true; |
217 | 218 | ||
218 | #else | 219 | #else |
219 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); | 220 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); |
220 | return false; | 221 | return false; |
221 | #endif | 222 | #endif |
222 | 223 | ||
223 | } | 224 | } |
224 | 225 | ||
225 | 226 | ||
226 | /*********************************************************************************/ | 227 | /*********************************************************************************/ |
227 | bool QCopMapTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | 228 | bool QCopMapTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) |
228 | { | 229 | { |
229 | bool res = QCopTransferItem::appMessage( cmsg, data ); | 230 | bool res = QCopTransferItem::appMessage( cmsg, data ); |
230 | 231 | ||
231 | if (res == false) | 232 | if (res == false) |
232 | { | 233 | { |
233 | QDataStream stream( data, IO_ReadOnly ); | 234 | QDataStream stream( data, IO_ReadOnly ); |
234 | 235 | ||
235 | // qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() ); | 236 | // qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() ); |
236 | 237 | ||
237 | //we are in the source and get an answer from the target | 238 | //we are in the source and get an answer from the target |
238 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) | 239 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) |
239 | { | 240 | { |
240 | QMap<QString,QString> adrMap; | 241 | QMap<QString,QString> adrMap; |
241 | QString uid; | 242 | QString uid; |
242 | 243 | ||
243 | stream >> uid >> adrMap; | 244 | stream >> uid >> adrMap; |
244 | 245 | ||
245 | emit receivedMessageFromTarget(uid, adrMap); | 246 | emit receivedMessageFromTarget(uid, adrMap); |
246 | 247 | ||
247 | 248 | ||
248 | return true; | 249 | return true; |
249 | } | 250 | } |
250 | } | 251 | } |
251 | 252 | ||
252 | return false; | 253 | return false; |
253 | } | 254 | } |
254 | 255 | ||
255 | 256 | ||
256 | /********************************************************************************* | 257 | /********************************************************************************* |
257 | * | 258 | * |
258 | ********************************************************************************/ | 259 | ********************************************************************************/ |
259 | 260 | ||
260 | QCopListTransferItem::~QCopListTransferItem() | 261 | QCopListTransferItem::~QCopListTransferItem() |
261 | { | 262 | { |
262 | 263 | ||
263 | } | 264 | } |
264 | 265 | ||
265 | QCopListTransferItem::QCopListTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) | 266 | QCopListTransferItem::QCopListTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage) |
266 | : QCopTransferItem(usedSourceParameters, sourceMessage, targetChannel,targetMessage) | 267 | : QCopTransferItem(usedSourceParameters, sourceMessage, targetChannel,targetMessage) |
267 | { | 268 | { |
268 | //targetMessage returns later two parameters: uid, and three lists | 269 | //targetMessage returns later two parameters: uid, and three lists |
269 | _targetMessageParameters = "(QString,QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)"; | 270 | _targetMessageParameters = "(QString,QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)"; |
270 | } | 271 | } |
271 | 272 | ||
272 | /*********************************************************************************/ | 273 | /*********************************************************************************/ |
273 | bool QCopListTransferItem::sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6) | 274 | bool QCopListTransferItem::sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6) |
274 | { | 275 | { |
275 | #ifndef DESKTOP_VERSION | 276 | #ifndef DESKTOP_VERSION |
276 | //targetMessage passes two parameters: uid, map | 277 | //targetMessage passes two parameters: uid, map |
277 | QString targetMessage = _targetMessage + _targetMessageParameters; | 278 | QString targetMessage = _targetMessage + _targetMessageParameters; |
278 | 279 | ||
279 | #ifdef DEBUG_EXT_APP_HANDLER | 280 | #ifdef DEBUG_EXT_APP_HANDLER |
280 | qDebug("3Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); | 281 | qDebug("3Using QCopEnvelope e(\"%s\",\"%s\")", _sourceChannel.latin1(), targetMessage.latin1()); |
281 | qDebug("passing uid(%s) and list1, list2, list3, list4, list5, list6 as parameter to QCopEnvelope", uid.latin1()); | 282 | qDebug("passing uid(%s) and list1, list2, list3, list4, list5, list6 as parameter to QCopEnvelope", uid.latin1()); |
282 | 283 | ||
283 | 284 | ||
284 | for ( int i = 0; i < list3.count(); i++) | 285 | for ( int i = 0; i < list3.count(); i++) |
285 | qDebug("listentry list3: %s",list3[i].latin1()); | 286 | qDebug("listentry list3: %s",list3[i].latin1()); |
286 | #endif | 287 | #endif |
287 | 288 | ||
288 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); | 289 | QCopEnvelope e(_sourceChannel.latin1(), targetMessage.latin1()); |
289 | //US we need no names in the To field. The emailadresses are enough | 290 | //US we need no names in the To field. The emailadresses are enough |
290 | 291 | ||
291 | e << uid << list1 << list2 << list3 << list4 << list5 << list6; | 292 | e << uid << list1 << list2 << list3 << list4 << list5 << list6; |
292 | 293 | ||
293 | qApp->processEvents(); | 294 | qApp->processEvents(); |
294 | 295 | ||
295 | return true; | 296 | return true; |
296 | 297 | ||
297 | #else | 298 | #else |
298 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); | 299 | KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); |
299 | return false; | 300 | return false; |
300 | #endif | 301 | #endif |
301 | 302 | ||
302 | } | 303 | } |
303 | 304 | ||
304 | 305 | ||
305 | /*********************************************************************************/ | 306 | /*********************************************************************************/ |
306 | bool QCopListTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) | 307 | bool QCopListTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) |
307 | { | 308 | { |
308 | bool res = QCopTransferItem::appMessage( cmsg, data ); | 309 | bool res = QCopTransferItem::appMessage( cmsg, data ); |
309 | #ifdef DEBUG_EXT_APP_HANDLER | 310 | #ifdef DEBUG_EXT_APP_HANDLER |
310 | qDebug("1QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); | 311 | qDebug("1QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); |
311 | #endif | 312 | #endif |
312 | 313 | ||
313 | if (res == false) | 314 | if (res == false) |
314 | { | 315 | { |
315 | QDataStream stream( data, IO_ReadOnly ); | 316 | QDataStream stream( data, IO_ReadOnly ); |
316 | 317 | ||
317 | #ifdef DEBUG_EXT_APP_HANDLER | 318 | #ifdef DEBUG_EXT_APP_HANDLER |
318 | qDebug("2QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); | 319 | qDebug("2QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); |
319 | #endif | 320 | #endif |
320 | 321 | ||
321 | //we are in the source and get an answer from the target | 322 | //we are in the source and get an answer from the target |
322 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) | 323 | if ((_targetMessage + _targetMessageParameters) == cmsg.data()) |
323 | { | 324 | { |
324 | QStringList list1; | 325 | QStringList list1; |
325 | QStringList list2; | 326 | QStringList list2; |
326 | QStringList list3; | 327 | QStringList list3; |
327 | QStringList list4; | 328 | QStringList list4; |
328 | QStringList list5; | 329 | QStringList list5; |
329 | QStringList list6; | 330 | QStringList list6; |
330 | QString uid; | 331 | QString uid; |
331 | 332 | ||
332 | #ifdef DEBUG_EXT_APP_HANDLER | 333 | #ifdef DEBUG_EXT_APP_HANDLER |
333 | qDebug("3QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); | 334 | qDebug("3QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); |
334 | #endif | 335 | #endif |
335 | 336 | ||
336 | stream >> uid >> list1 >> list2 >> list3 >> list4 >> list5 >> list6; | 337 | stream >> uid >> list1 >> list2 >> list3 >> list4 >> list5 >> list6; |
337 | emit receivedMessageFromTarget(uid, list1, list2, list3, list4, list5, list6); | 338 | emit receivedMessageFromTarget(uid, list1, list2, list3, list4, list5, list6); |
338 | 339 | ||
339 | 340 | ||
340 | return true; | 341 | return true; |
341 | } | 342 | } |
342 | } | 343 | } |
343 | 344 | ||
344 | return false; | 345 | return false; |
345 | } | 346 | } |
346 | 347 | ||
347 | 348 | ||
348 | 349 | ||
349 | /********************************************************************************* | 350 | /********************************************************************************* |
350 | * | 351 | * |
351 | ********************************************************************************/ | 352 | ********************************************************************************/ |
352 | 353 | ||
353 | 354 | ||
354 | ExternalAppHandler *ExternalAppHandler::sInstance = 0; | 355 | ExternalAppHandler *ExternalAppHandler::sInstance = 0; |
355 | static KStaticDeleter<ExternalAppHandler> staticDeleter; | 356 | static KStaticDeleter<ExternalAppHandler> staticDeleter; |
356 | 357 | ||
357 | ExternalAppHandler::ExternalAppHandler() | 358 | ExternalAppHandler::ExternalAppHandler() |
358 | { | 359 | { |
359 | mDefaultItems.setAutoDelete(true); | 360 | mDefaultItems.setAutoDelete(true); |
360 | 361 | ||
361 | mNameEmailUidListFromKAPITransfer = new QCopListTransferItem(0, "requestNameEmailUIDListFromKAPI", "QPE/Application/kapi", "receiveNameEmailUIDList"); | 362 | mNameEmailUidListFromKAPITransfer = new QCopListTransferItem(0, "requestNameEmailUIDListFromKAPI", "QPE/Application/kapi", "receiveNameEmailUIDList"); |
362 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&)), this, SIGNAL (requestForNameEmailUidList(const QString&, const QString&))); | 363 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&)), this, SIGNAL (requestForNameEmailUidList(const QString&, const QString&))); |
363 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), this, SLOT (receivedNameEmailUidList_Slot(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); | 364 | connect(mNameEmailUidListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), this, SLOT (receivedNameEmailUidList_Slot(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); |
364 | 365 | ||
365 | //US mFindByEmailFromKAPITransfer = new QCopListTransferItem(1, "requestFindByEmailFromKAPI", "QPE/Application/kapi", "receiveFindByEmailNameEmailUIDList"); | 366 | //US mFindByEmailFromKAPITransfer = new QCopListTransferItem(1, "requestFindByEmailFromKAPI", "QPE/Application/kapi", "receiveFindByEmailNameEmailUIDList"); |
366 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForFindByEmail(const QString&, const QString&, const QString&))); | 367 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&)), this, SIGNAL (requestForFindByEmail(const QString&, const QString&, const QString&))); |
367 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedFindByEmailEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); | 368 | //US connect(mFindByEmailFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedFindByEmailEvent(const QString&, const QStringList&, const QStringList&, const QStringList&))); |
368 | 369 | ||
369 | mDisplayDetails = new QCopListTransferItem(3, "requestDisplayDetailsFromKAPI", "QPE/Application/kapi", ""); | 370 | mDisplayDetails = new QCopListTransferItem(3, "requestDisplayDetailsFromKAPI", "QPE/Application/kapi", ""); |
370 | connect(mDisplayDetails, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&, const QString&, const QString&)), this, SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); | 371 | connect(mDisplayDetails, SIGNAL (receivedMessageFromSource(const QString&, const QString&, const QString&, const QString&, const QString&)), this, SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); |
371 | 372 | ||
372 | 373 | ||
373 | 374 | ||
374 | mBirthdayListFromKAPITransfer = new QCopListTransferItem(0, "requestBirthdayListFromKAPI", "QPE/Application/kapi", "receiveBirthdayList"); | 375 | mBirthdayListFromKAPITransfer = new QCopListTransferItem(0, "requestBirthdayListFromKAPI", "QPE/Application/kapi", "receiveBirthdayList"); |
375 | connect(mBirthdayListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&)), this, SIGNAL (requestForBirthdayList(const QString&, const QString&))); | 376 | connect(mBirthdayListFromKAPITransfer, SIGNAL (receivedMessageFromSource(const QString&, const QString&)), this, SIGNAL (requestForBirthdayList(const QString&, const QString&))); |
376 | connect(mBirthdayListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); | 377 | connect(mBirthdayListFromKAPITransfer, SIGNAL (receivedMessageFromTarget(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), this, SIGNAL (receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); |
377 | 378 | ||
378 | 379 | ||
379 | } | 380 | } |
380 | 381 | ||
381 | ExternalAppHandler::~ExternalAppHandler() | 382 | ExternalAppHandler::~ExternalAppHandler() |
382 | { | 383 | { |
383 | delete mNameEmailUidListFromKAPITransfer; | 384 | delete mNameEmailUidListFromKAPITransfer; |
384 | //delete mFindByEmailFromKAPITransfer; | 385 | //delete mFindByEmailFromKAPITransfer; |
385 | delete mDisplayDetails; | 386 | delete mDisplayDetails; |
386 | delete mBirthdayListFromKAPITransfer; | 387 | delete mBirthdayListFromKAPITransfer; |
387 | } | 388 | } |
388 | 389 | ||
389 | void ExternalAppHandler::receivedNameEmailUidList_Slot(const QString& uid, | 390 | void ExternalAppHandler::receivedNameEmailUidList_Slot(const QString& uid, |
390 | const QStringList& nameList, | 391 | const QStringList& nameList, |
391 | const QStringList& emailList, | 392 | const QStringList& emailList, |
392 | const QStringList& uidList, | 393 | const QStringList& uidList, |
393 | const QStringList&, | 394 | const QStringList&, |
394 | const QStringList&, | 395 | const QStringList&, |
395 | const QStringList& ) | 396 | const QStringList& ) |
396 | { | 397 | { |
397 | // this method is a conevnient way to reduce the number of parameters I have to pass | 398 | // this method is a conevnient way to reduce the number of parameters I have to pass |
398 | emit receivedNameEmailUidListEvent(uid, nameList, emailList, uidList); | 399 | emit receivedNameEmailUidListEvent(uid, nameList, emailList, uidList); |
399 | } | 400 | } |
400 | 401 | ||
401 | 402 | ||
402 | void ExternalAppHandler::loadConfig() | 403 | void ExternalAppHandler::loadConfig() |
403 | { | 404 | { |
404 | 405 | ||
405 | mDefaultItems.clear(); | 406 | mDefaultItems.clear(); |
406 | mEmailAppAvailable = UNDEFINED; | 407 | mEmailAppAvailable = UNDEFINED; |
407 | mPhoneAppAvailable = UNDEFINED; | 408 | mPhoneAppAvailable = UNDEFINED; |
408 | mFaxAppAvailable = UNDEFINED; | 409 | mFaxAppAvailable = UNDEFINED; |
409 | mSMSAppAvailable = UNDEFINED; | 410 | mSMSAppAvailable = UNDEFINED; |
410 | mPagerAppAvailable = UNDEFINED; | 411 | mPagerAppAvailable = UNDEFINED; |
411 | mSIPAppAvailable = UNDEFINED; | 412 | mSIPAppAvailable = UNDEFINED; |
412 | 413 | ||
413 | QString opiepath = QString::fromLatin1( getenv("OPIEDIR") ); | 414 | QString opiepath = QString::fromLatin1( getenv("OPIEDIR") ); |
414 | QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") ); | 415 | QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") ); |
415 | QString qtpath = QString::fromLatin1( getenv("QTDIR") ); | 416 | QString qtpath = QString::fromLatin1( getenv("QTDIR") ); |
416 | 417 | ||
417 | //if qtopiapath is not set, fallback to qt | 418 | //if qtopiapath is not set, fallback to qt |
418 | if (qtopiapath.isEmpty()) | 419 | if (qtopiapath.isEmpty()) |
419 | qtopiapath = qtpath; | 420 | qtopiapath = qtpath; |
420 | 421 | ||
421 | //if opiepath is not set, fallback to qtopia | 422 | //if opiepath is not set, fallback to qtopia |
422 | if (opiepath.isEmpty()) | 423 | if (opiepath.isEmpty()) |
423 | opiepath = qtopiapath; | 424 | opiepath = qtopiapath; |
424 | 425 | ||
425 | 426 | ||
426 | 427 | ||
427 | //mailclients | 428 | //mailclients |
428 | QString mailmsg1 = "writeMail(QString,QString)"; | 429 | QString mailmsg1 = "writeMail(QString,QString)"; |
429 | QString mailmsg2 = "writeMail(QMap(QString,QString))"; | 430 | QString mailmsg2 = "writeMail(QMap(QString,QString))"; |
430 | 431 | ||
431 | QString undefined = ""; | 432 | QString undefined = ""; |
432 | 433 | ||
433 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined); | 434 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined); |
434 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined); | 435 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined); |
435 | 436 | ||
436 | if (( QFile::exists( qtopiapath + "/bin/ompi" )) || | 437 | if (( QFile::exists( qtopiapath + "/bin/ompi" )) || |
437 | ( QFile::exists( opiepath + "/bin/ompi" )) || | 438 | ( QFile::exists( opiepath + "/bin/ompi" )) || |
438 | ( QFile::exists( qtpath + "/bin/ompi" ))) | 439 | ( QFile::exists( qtpath + "/bin/ompi" ))) |
439 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); | 440 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); |
440 | 441 | ||
441 | if (( QFile::exists( qtopiapath + "/bin/qtmail" )) || | 442 | if (( QFile::exists( qtopiapath + "/bin/qtmail" )) || |
442 | ( QFile::exists( qtpath + "/bin/qtmail" ))) | 443 | ( QFile::exists( qtpath + "/bin/qtmail" ))) |
443 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); | 444 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); |
444 | 445 | ||
445 | if ( QFile::exists( opiepath + "/bin/opiemail" )) | 446 | if ( QFile::exists( opiepath + "/bin/opiemail" )) |
446 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); | 447 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); |
447 | 448 | ||
448 | if ( QFile::exists( opiepath + "/bin/mailit" )) | 449 | if ( QFile::exists( opiepath + "/bin/mailit" )) |
449 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_MAILIT_EMC, "Opie mailit email client", "QPE/Application/mailit", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); | 450 | addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_MAILIT_EMC, "Opie mailit email client", "QPE/Application/mailit", mailmsg1, "%1;%2", mailmsg2, "TO=%1;ATTACHMENT=%2"); |
450 | 451 | ||
451 | 452 | ||
452 | 453 | ||
453 | //phoneclients | 454 | //phoneclients |
454 | 455 | ||
455 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined); | 456 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined); |
456 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::OTHER_PHC, "Other phone client", undefined, undefined, undefined, undefined, undefined); | 457 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::OTHER_PHC, "Other phone client", undefined, undefined, undefined, undefined, undefined); |
457 | if (( QFile::exists( qtopiapath + "/bin/kppi" )) || | 458 | if (( QFile::exists( qtopiapath + "/bin/kppi" )) || |
458 | ( QFile::exists( opiepath + "/bin/kppi" ))) | 459 | ( QFile::exists( opiepath + "/bin/kppi" ))) |
459 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::KPPI_PHC, "KP/Pi phone client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined); | 460 | addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::KPPI_PHC, "KP/Pi phone client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined); |
460 | 461 | ||
461 | //faxclients | 462 | //faxclients |
462 | addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::NONE_FAC, "No fax client installed", undefined, undefined, undefined, undefined, undefined); | 463 | addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::NONE_FAC, "No fax client installed", undefined, undefined, undefined, undefined, undefined); |
463 | addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::OTHER_FAC, "Other fax client", undefined, undefined, undefined, undefined, undefined); | 464 | addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::OTHER_FAC, "Other fax client", undefined, undefined, undefined, undefined, undefined); |
464 | 465 | ||
465 | //smsclients | 466 | //smsclients |
466 | addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::NONE_SMC, "No sms client installed", undefined, undefined, undefined, undefined, undefined); | 467 | addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::NONE_SMC, "No sms client installed", undefined, undefined, undefined, undefined, undefined); |
467 | addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::OTHER_SMC, "Other sms client", undefined, undefined, undefined, undefined, undefined); | 468 | addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::OTHER_SMC, "Other sms client", undefined, undefined, undefined, undefined, undefined); |
468 | 469 | ||
469 | //pagerclients | 470 | //pagerclients |
470 | addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::NONE_PAC, "No pager client installed", undefined, undefined, undefined, undefined, undefined); | 471 | addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::NONE_PAC, "No pager client installed", undefined, undefined, undefined, undefined, undefined); |
471 | addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::OTHER_PAC, "Other pager client", undefined, undefined, undefined, undefined, undefined); | 472 | addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::OTHER_PAC, "Other pager client", undefined, undefined, undefined, undefined, undefined); |
472 | 473 | ||
473 | //sipclients | 474 | //sipclients |
474 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::NONE_SIC, "No SIP client installed", undefined, undefined, undefined, undefined, undefined); | 475 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::NONE_SIC, "No SIP client installed", undefined, undefined, undefined, undefined, undefined); |
475 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::OTHER_SIC, "Other SIP client", undefined, undefined, undefined, undefined, undefined); | 476 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::OTHER_SIC, "Other SIP client", undefined, undefined, undefined, undefined, undefined); |
476 | if (( QFile::exists( qtopiapath + "/bin/kppi" )) || | 477 | if (( QFile::exists( qtopiapath + "/bin/kppi" )) || |
477 | ( QFile::exists( opiepath + "/bin/kppi" ))) | 478 | ( QFile::exists( opiepath + "/bin/kppi" ))) |
478 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::KPPI_SIC, "KP/Pi SIP client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined); | 479 | addDefaultAppItem(ExternalAppHandler::SIP, KPimGlobalPrefs::KPPI_SIC, "KP/Pi SIP client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined); |
479 | 480 | ||
480 | } | 481 | } |
481 | 482 | ||
482 | ExternalAppHandler *ExternalAppHandler::instance() | 483 | ExternalAppHandler *ExternalAppHandler::instance() |
483 | { | 484 | { |
484 | if ( !sInstance ) { | 485 | if ( !sInstance ) { |
485 | sInstance = staticDeleter.setObject( new ExternalAppHandler() ); | 486 | sInstance = staticDeleter.setObject( new ExternalAppHandler() ); |
486 | sInstance->loadConfig(); | 487 | sInstance->loadConfig(); |
487 | } | 488 | } |
488 | 489 | ||
489 | return sInstance; | 490 | return sInstance; |
490 | } | 491 | } |
491 | 492 | ||
492 | void ExternalAppHandler::addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameter, const QString& message2, const QString& parameter2) | 493 | void ExternalAppHandler::addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameter, const QString& message2, const QString& parameter2) |
493 | { | 494 | { |
494 | DefaultAppItem* dai = new DefaultAppItem(type, id, label, channel, message, parameter, message2, parameter2); | 495 | DefaultAppItem* dai = new DefaultAppItem(type, id, label, channel, message, parameter, message2, parameter2); |
495 | // qDebug("%d %d %s %s ", type, id, label.latin1(), channel.latin1() ); | 496 | // qDebug("%d %d %s %s ", type, id, label.latin1(), channel.latin1() ); |
496 | mDefaultItems.append(dai); | 497 | mDefaultItems.append(dai); |
497 | } | 498 | } |
498 | 499 | ||
499 | 500 | ||
500 | QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type) | 501 | QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type) |
501 | { | 502 | { |
502 | QList<DefaultAppItem> list; | 503 | QList<DefaultAppItem> list; |
503 | 504 | ||
504 | DefaultAppItem* dai; | 505 | DefaultAppItem* dai; |
505 | 506 | ||
506 | for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) | 507 | for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) |
507 | { | 508 | { |
508 | if (dai->_type == type) | 509 | if (dai->_type == type) |
509 | list.append(dai); | 510 | list.append(dai); |
510 | } | 511 | } |
511 | 512 | ||
512 | return list; | 513 | return list; |
513 | } | 514 | } |
514 | 515 | ||
515 | DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid) | 516 | DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid) |
516 | { | 517 | { |
517 | DefaultAppItem* dai; | 518 | DefaultAppItem* dai; |
518 | 519 | ||
519 | for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) | 520 | for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) |
520 | { | 521 | { |
521 | if (dai->_type == type && dai->_id == clientid) | 522 | if (dai->_type == type && dai->_id == clientid) |
522 | return dai; | 523 | return dai; |
523 | } | 524 | } |
524 | 525 | ||
525 | return 0; | 526 | return 0; |
526 | } | 527 | } |
527 | 528 | ||
528 | bool ExternalAppHandler::isEmailAppAvailable() | 529 | bool ExternalAppHandler::isEmailAppAvailable() |
529 | { | 530 | { |
530 | #ifndef DESKTOP_VERSION | 531 | #ifndef DESKTOP_VERSION |
531 | if (mEmailAppAvailable == UNDEFINED) | 532 | if (mEmailAppAvailable == UNDEFINED) |
532 | { | 533 | { |
533 | int client = KPimGlobalPrefs::instance()->mEmailClient; | 534 | int client = KPimGlobalPrefs::instance()->mEmailClient; |
534 | if (client == KPimGlobalPrefs::NONE_EMC) | 535 | if (client == KPimGlobalPrefs::NONE_EMC) |
535 | mEmailAppAvailable = UNAVAILABLE; | 536 | mEmailAppAvailable = UNAVAILABLE; |
536 | else | 537 | else |
537 | mEmailAppAvailable = AVAILABLE; | 538 | mEmailAppAvailable = AVAILABLE; |
538 | } | 539 | } |
539 | return (mEmailAppAvailable == AVAILABLE); | 540 | return (mEmailAppAvailable == AVAILABLE); |
540 | 541 | ||
541 | #else //DESKTOP_VERSION | 542 | #else //DESKTOP_VERSION |
542 | return false; | 543 | return false; |
543 | #endif //DESKTOP_VERSION | 544 | #endif //DESKTOP_VERSION |
544 | } | 545 | } |
545 | 546 | ||
546 | bool ExternalAppHandler::isSMSAppAvailable() | 547 | bool ExternalAppHandler::isSMSAppAvailable() |
547 | { | 548 | { |
548 | #ifndef DESKTOP_VERSION | 549 | #ifndef DESKTOP_VERSION |
549 | if (mSMSAppAvailable == UNDEFINED) | 550 | if (mSMSAppAvailable == UNDEFINED) |
550 | { | 551 | { |
551 | int client = KPimGlobalPrefs::instance()->mSMSClient; | 552 | int client = KPimGlobalPrefs::instance()->mSMSClient; |
552 | if (client == KPimGlobalPrefs::NONE_SMC) | 553 | if (client == KPimGlobalPrefs::NONE_SMC) |
553 | mSMSAppAvailable = UNAVAILABLE; | 554 | mSMSAppAvailable = UNAVAILABLE; |
554 | else | 555 | else |
555 | mSMSAppAvailable = AVAILABLE; | 556 | mSMSAppAvailable = AVAILABLE; |
556 | } | 557 | } |
557 | 558 | ||
558 | return (mSMSAppAvailable == AVAILABLE); | 559 | return (mSMSAppAvailable == AVAILABLE); |
559 | #else //DESKTOP_VERSION | 560 | #else //DESKTOP_VERSION |
560 | return false; | 561 | return false; |
561 | #endif //DESKTOP_VERSION | 562 | #endif //DESKTOP_VERSION |
562 | } | 563 | } |
563 | 564 | ||
564 | bool ExternalAppHandler::isPhoneAppAvailable() | 565 | bool ExternalAppHandler::isPhoneAppAvailable() |
565 | { | 566 | { |
566 | #ifndef DESKTOP_VERSION | 567 | #ifndef DESKTOP_VERSION |
567 | if (mPhoneAppAvailable == UNDEFINED) | 568 | if (mPhoneAppAvailable == UNDEFINED) |
568 | { | 569 | { |
569 | int client = KPimGlobalPrefs::instance()->mPhoneClient; | 570 | int client = KPimGlobalPrefs::instance()->mPhoneClient; |
570 | if (client == KPimGlobalPrefs::NONE_PHC) | 571 | if (client == KPimGlobalPrefs::NONE_PHC) |
571 | mPhoneAppAvailable = UNAVAILABLE; | 572 | mPhoneAppAvailable = UNAVAILABLE; |
572 | else | 573 | else |
573 | mPhoneAppAvailable = AVAILABLE; | 574 | mPhoneAppAvailable = AVAILABLE; |
574 | } | 575 | } |
575 | 576 | ||
576 | return (mPhoneAppAvailable == AVAILABLE); | 577 | return (mPhoneAppAvailable == AVAILABLE); |
577 | #else //DESKTOP_VERSION | 578 | #else //DESKTOP_VERSION |
578 | return false; | 579 | return false; |
579 | #endif //DESKTOP_VERSION | 580 | #endif //DESKTOP_VERSION |
580 | } | 581 | } |
581 | 582 | ||
582 | bool ExternalAppHandler::isFaxAppAvailable() | 583 | bool ExternalAppHandler::isFaxAppAvailable() |
583 | { | 584 | { |
584 | #ifndef DESKTOP_VERSION | 585 | #ifndef DESKTOP_VERSION |
585 | if (mFaxAppAvailable == UNDEFINED) | 586 | if (mFaxAppAvailable == UNDEFINED) |
586 | { | 587 | { |
587 | int client = KPimGlobalPrefs::instance()->mFaxClient; | 588 | int client = KPimGlobalPrefs::instance()->mFaxClient; |
588 | if (client == KPimGlobalPrefs::NONE_FAC) | 589 | if (client == KPimGlobalPrefs::NONE_FAC) |
589 | mFaxAppAvailable = UNAVAILABLE; | 590 | mFaxAppAvailable = UNAVAILABLE; |
590 | else | 591 | else |
591 | mFaxAppAvailable = AVAILABLE; | 592 | mFaxAppAvailable = AVAILABLE; |
592 | } | 593 | } |
593 | 594 | ||
594 | return (mFaxAppAvailable == AVAILABLE); | 595 | return (mFaxAppAvailable == AVAILABLE); |
595 | #else //DESKTOP_VERSION | 596 | #else //DESKTOP_VERSION |
596 | return false; | 597 | return false; |
597 | #endif //DESKTOP_VERSION | 598 | #endif //DESKTOP_VERSION |
598 | } | 599 | } |
599 | 600 | ||
600 | bool ExternalAppHandler::isPagerAppAvailable() | 601 | bool ExternalAppHandler::isPagerAppAvailable() |
601 | { | 602 | { |
602 | #ifndef DESKTOP_VERSION | 603 | #ifndef DESKTOP_VERSION |
603 | if (mPagerAppAvailable == UNDEFINED) | 604 | if (mPagerAppAvailable == UNDEFINED) |
604 | { | 605 | { |
605 | int client = KPimGlobalPrefs::instance()->mPagerClient; | 606 | int client = KPimGlobalPrefs::instance()->mPagerClient; |
606 | if (client == KPimGlobalPrefs::NONE_PAC) | 607 | if (client == KPimGlobalPrefs::NONE_PAC) |
607 | mPagerAppAvailable = UNAVAILABLE; | 608 | mPagerAppAvailable = UNAVAILABLE; |
608 | else | 609 | else |
609 | mPagerAppAvailable = AVAILABLE; | 610 | mPagerAppAvailable = AVAILABLE; |
610 | } | 611 | } |
611 | 612 | ||
612 | return (mPagerAppAvailable == AVAILABLE); | 613 | return (mPagerAppAvailable == AVAILABLE); |
613 | #else //DESKTOP_VERSION | 614 | #else //DESKTOP_VERSION |
614 | return false; | 615 | return false; |
615 | #endif //DESKTOP_VERSION | 616 | #endif //DESKTOP_VERSION |
616 | } | 617 | } |
617 | 618 | ||
618 | 619 | ||
619 | bool ExternalAppHandler::isSIPAppAvailable() | 620 | bool ExternalAppHandler::isSIPAppAvailable() |
620 | { | 621 | { |
621 | #ifndef DESKTOP_VERSION | 622 | #ifndef DESKTOP_VERSION |
622 | if (mSIPAppAvailable == UNDEFINED) | 623 | if (mSIPAppAvailable == UNDEFINED) |
623 | { | 624 | { |
624 | int client = KPimGlobalPrefs::instance()->mSipClient; | 625 | int client = KPimGlobalPrefs::instance()->mSipClient; |
625 | if (client == KPimGlobalPrefs::NONE_SIC) | 626 | if (client == KPimGlobalPrefs::NONE_SIC) |
626 | mSIPAppAvailable = UNAVAILABLE; | 627 | mSIPAppAvailable = UNAVAILABLE; |
627 | else | 628 | else |
628 | mSIPAppAvailable = AVAILABLE; | 629 | mSIPAppAvailable = AVAILABLE; |
629 | } | 630 | } |
630 | 631 | ||
631 | return (mSIPAppAvailable == AVAILABLE); | 632 | return (mSIPAppAvailable == AVAILABLE); |
632 | #else //DESKTOP_VERSION | 633 | #else //DESKTOP_VERSION |
633 | return false; | 634 | return false; |
634 | #endif //DESKTOP_VERSION | 635 | #endif //DESKTOP_VERSION |
635 | } | 636 | } |
636 | 637 | ||
637 | /************************************************************************** | 638 | /************************************************************************** |
638 | * | 639 | * |
639 | **************************************************************************/ | 640 | **************************************************************************/ |
640 | 641 | ||
641 | 642 | ||
642 | //calls the emailapplication with a number of attachments that need to be send (Seperated by Comma) | 643 | //calls the emailapplication with a number of attachments that need to be send (Seperated by Comma) |
643 | bool ExternalAppHandler::mailToMultipleContacts( const QString& emails, const QString& urls ) | 644 | bool ExternalAppHandler::mailToMultipleContacts( const QString& emails, const QString& urls ) |
644 | { | 645 | { |
645 | 646 | ||
646 | #ifndef DESKTOP_VERSION | 647 | #ifndef DESKTOP_VERSION |
647 | QString channel; | 648 | QString channel; |
648 | QString message2; | 649 | QString message2; |
649 | QString parameters2; | 650 | QString parameters2; |
650 | 651 | ||
651 | 652 | ||
652 | int client = KPimGlobalPrefs::instance()->mEmailClient; | 653 | int client = KPimGlobalPrefs::instance()->mEmailClient; |
653 | if (client == KPimGlobalPrefs::OTHER_EMC) | 654 | if (client == KPimGlobalPrefs::OTHER_EMC) |
654 | { | 655 | { |
655 | channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; | 656 | channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; |
656 | message2 = KPimGlobalPrefs::instance()->mEmailOtherMessage; | 657 | message2 = KPimGlobalPrefs::instance()->mEmailOtherMessage; |
657 | parameters2 = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; | 658 | parameters2 = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; |
658 | } | 659 | } |
659 | else | 660 | else |
660 | { | 661 | { |
661 | DefaultAppItem* dai = getDefaultItem(EMAIL, client); | 662 | DefaultAppItem* dai = getDefaultItem(EMAIL, client); |
662 | if (!dai) | 663 | if (!dai) |
663 | { | 664 | { |
664 | qDebug("could not find configured email application."); | 665 | qDebug("could not find configured email application."); |
665 | return false; | 666 | return false; |
666 | } | 667 | } |
667 | channel = dai->_channel; | 668 | channel = dai->_channel; |
668 | message2 = dai->_message2; | 669 | message2 = dai->_message2; |
669 | parameters2 = dai->_parameters2; | 670 | parameters2 = dai->_parameters2; |
670 | } | 671 | } |
671 | 672 | ||
672 | //first check if one of the mailers need the emails right in the message. | 673 | //first check if one of the mailers need the emails right in the message. |
673 | message2 = translateMessage(message2, emails, urls); | 674 | message2 = translateMessage(message2, emails, urls); |
674 | 675 | ||
675 | 676 | ||
676 | #ifdef DEBUG_EXT_APP_HANDLER | 677 | #ifdef DEBUG_EXT_APP_HANDLER |
677 | qDebug("4Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1()); | 678 | qDebug("4Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1()); |
678 | qDebug("passing emailadresses(%s), attachmenturls(%s) as parameters in the form %s to QCopEnvelope", emails.latin1() , urls.latin1(), parameters2.latin1()); | 679 | qDebug("passing emailadresses(%s), attachmenturls(%s) as parameters in the form %s to QCopEnvelope", emails.latin1() , urls.latin1(), parameters2.latin1()); |
679 | #endif | 680 | #endif |
680 | 681 | ||
681 | 682 | ||
682 | QCopEnvelope e(channel.latin1(), message2.latin1()); | 683 | QCopEnvelope e(channel.latin1(), message2.latin1()); |
683 | //US we need no names in the To field. The emailadresses are enough | 684 | //US we need no names in the To field. The emailadresses are enough |
684 | 685 | ||
685 | passParameters(&e, parameters2, emails, urls); | 686 | passParameters(&e, parameters2, emails, urls); |
686 | 687 | ||
687 | 688 | ||
688 | 689 | ||
689 | #else | 690 | #else |
690 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); | 691 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); |
691 | #endif | 692 | #endif |
692 | 693 | ||
693 | return true; | 694 | return true; |
694 | } | 695 | } |
695 | 696 | ||
696 | /************************************************************************** | 697 | /************************************************************************** |
697 | * | 698 | * |
698 | **************************************************************************/ | 699 | **************************************************************************/ |
699 | 700 | ||
700 | 701 | ||
701 | //calls the emailapplication and creates a mail with parameter emails as recipients | 702 | //calls the emailapplication and creates a mail with parameter emails as recipients |
702 | bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& emailadress ) | 703 | bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& emailadress ) |
703 | { | 704 | { |
704 | #ifndef DESKTOP_VERSION | 705 | #ifndef DESKTOP_VERSION |
705 | QString channel; | 706 | QString channel; |
706 | QString message; | 707 | QString message; |
707 | QString parameters; | 708 | QString parameters; |
708 | 709 | ||
709 | 710 | ||
710 | int client = KPimGlobalPrefs::instance()->mEmailClient; | 711 | int client = KPimGlobalPrefs::instance()->mEmailClient; |
711 | if (client == KPimGlobalPrefs::OTHER_EMC) | 712 | if (client == KPimGlobalPrefs::OTHER_EMC) |
712 | { | 713 | { |
713 | channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; | 714 | channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; |
714 | message = KPimGlobalPrefs::instance()->mEmailOtherMessage; | 715 | message = KPimGlobalPrefs::instance()->mEmailOtherMessage; |
715 | parameters = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; | 716 | parameters = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; |
716 | } | 717 | } |
717 | else | 718 | else |
718 | { | 719 | { |
719 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(EMAIL, client); | 720 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(EMAIL, client); |
720 | if (!dai) | 721 | if (!dai) |
721 | { | 722 | { |
722 | qDebug("could not find configured email application."); | 723 | qDebug("could not find configured email application."); |
723 | return false; | 724 | return false; |
724 | } | 725 | } |
725 | channel = dai->_channel; | 726 | channel = dai->_channel; |
726 | message = dai->_message; | 727 | message = dai->_message; |
727 | parameters = dai->_parameters; | 728 | parameters = dai->_parameters; |
728 | } | 729 | } |
729 | 730 | ||
730 | 731 | ||
731 | //first check if one of the mailers need the emails right in the message. | 732 | //first check if one of the mailers need the emails right in the message. |
732 | message = translateMessage(message, name, emailadress); | 733 | message = translateMessage(message, name, emailadress); |
733 | 734 | ||
734 | 735 | ||
735 | #ifdef DEBUG_EXT_APP_HANDLER | 736 | #ifdef DEBUG_EXT_APP_HANDLER |
736 | qDebug("5Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); | 737 | qDebug("5Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); |
737 | qDebug("passing name(%s), emailadresses(%s) as parameters in the form %s to QCopEnvelope", name.latin1(), emailadress.latin1(), parameters.latin1()); | 738 | qDebug("passing name(%s), emailadresses(%s) as parameters in the form %s to QCopEnvelope", name.latin1(), emailadress.latin1(), parameters.latin1()); |
738 | #endif | 739 | #endif |
739 | 740 | ||
740 | QCopEnvelope e(channel.latin1(), message.latin1()); | 741 | QCopEnvelope e(channel.latin1(), message.latin1()); |
741 | //US we need no names in the To field. The emailadresses are enough | 742 | //US we need no names in the To field. The emailadresses are enough |
742 | 743 | ||
743 | passParameters(&e, parameters, name, emailadress); | 744 | passParameters(&e, parameters, name, emailadress); |
744 | 745 | ||
745 | 746 | ||
746 | #else | 747 | #else |
747 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); | 748 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); |
748 | #endif | 749 | #endif |
749 | 750 | ||
750 | 751 | ||
751 | return true; | 752 | return true; |
752 | } | 753 | } |
753 | 754 | ||
754 | /************************************************************************** | 755 | /************************************************************************** |
755 | * | 756 | * |
756 | **************************************************************************/ | 757 | **************************************************************************/ |
757 | 758 | ||
758 | //calls the emailapplication and creates a mail with parameter as recipients | 759 | //calls the emailapplication and creates a mail with parameter as recipients |
759 | // parameters format is | 760 | // parameters format is |
760 | // NAME <EMAIL>:SUBJECT | 761 | // NAME <EMAIL>:SUBJECT |
761 | bool ExternalAppHandler::mailToOneContact( const QString& adressline ) | 762 | bool ExternalAppHandler::mailToOneContact( const QString& adressline ) |
762 | { | 763 | { |
763 | QString line = adressline; | 764 | QString line = adressline; |
764 | 765 | ||
765 | int first = line.find( "<"); | 766 | int first = line.find( "<"); |
766 | int last = line.find( ">"); | 767 | int last = line.find( ">"); |
767 | QString name = line.left(first); | 768 | QString name = line.left(first); |
768 | QString emailadress = line.mid(first+1, last-first-1); | 769 | QString emailadress = line.mid(first+1, last-first-1); |
769 | 770 | ||
770 | //Subject can not be handled right now. | 771 | //Subject can not be handled right now. |
771 | return mailToOneContact( name, emailadress ); | 772 | return mailToOneContact( name, emailadress ); |
772 | 773 | ||
773 | } | 774 | } |
774 | 775 | ||
775 | 776 | ||
776 | /************************************************************************** | 777 | /************************************************************************** |
777 | * | 778 | * |
778 | **************************************************************************/ | 779 | **************************************************************************/ |
779 | 780 | ||
780 | //calls the phoneapplication with the number | 781 | //calls the phoneapplication with the number |
781 | bool ExternalAppHandler::callByPhone( const QString& phonenumber ) | 782 | bool ExternalAppHandler::callByPhone( const QString& phonenumber ) |
782 | { | 783 | { |
783 | #ifndef DESKTOP_VERSION | 784 | #ifndef DESKTOP_VERSION |
784 | QString channel; | 785 | QString channel; |
785 | QString message; | 786 | QString message; |
786 | QString parameters; | 787 | QString parameters; |
787 | 788 | ||
788 | 789 | ||
789 | int client = KPimGlobalPrefs::instance()->mPhoneClient; | 790 | int client = KPimGlobalPrefs::instance()->mPhoneClient; |
790 | if (client == KPimGlobalPrefs::OTHER_PHC) | 791 | if (client == KPimGlobalPrefs::OTHER_PHC) |
791 | { | 792 | { |
792 | channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel; | 793 | channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel; |
793 | message = KPimGlobalPrefs::instance()->mPhoneOtherMessage; | 794 | message = KPimGlobalPrefs::instance()->mPhoneOtherMessage; |
794 | parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters; | 795 | parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters; |
795 | } | 796 | } |
796 | else | 797 | else |
797 | { | 798 | { |
798 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client); | 799 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client); |
799 | if (!dai) | 800 | if (!dai) |
800 | { | 801 | { |
801 | qDebug("could not find configured phone application."); | 802 | qDebug("could not find configured phone application."); |
802 | return false; | 803 | return false; |
803 | } | 804 | } |
804 | channel = dai->_channel; | 805 | channel = dai->_channel; |
805 | message = dai->_message; | 806 | message = dai->_message; |
806 | parameters = dai->_parameters; | 807 | parameters = dai->_parameters; |
807 | } | 808 | } |
808 | 809 | ||
809 | 810 | ||
810 | //first check if one of the mailers need the emails right in the message. | 811 | //first check if one of the mailers need the emails right in the message. |
811 | message = translateMessage(message, phonenumber, ""); | 812 | message = translateMessage(message, phonenumber, ""); |
812 | 813 | ||
813 | 814 | ||
814 | #ifdef DEBUG_EXT_APP_HANDLER | 815 | #ifdef DEBUG_EXT_APP_HANDLER |
815 | qDebug("6Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); | 816 | qDebug("6Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); |
816 | qDebug("passing phonenumber(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); | 817 | qDebug("passing phonenumber(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); |
817 | #endif | 818 | #endif |
818 | 819 | ||
819 | QCopEnvelope e(channel.latin1(), message.latin1()); | 820 | QCopEnvelope e(channel.latin1(), message.latin1()); |
820 | //US we need no names in the To field. The emailadresses are enough | 821 | //US we need no names in the To field. The emailadresses are enough |
821 | 822 | ||
822 | passParameters(&e, parameters, phonenumber, ""); | 823 | passParameters(&e, parameters, phonenumber, ""); |
823 | 824 | ||
824 | 825 | ||
825 | #else | 826 | #else |
826 | KMessageBox::sorry( 0, i18n( "This version does not support phonecalls." ) ); | 827 | KMessageBox::sorry( 0, i18n( "This version does not support phonecalls." ) ); |
827 | #endif | 828 | #endif |
828 | 829 | ||
829 | 830 | ||
830 | return true; | 831 | return true; |
831 | } | 832 | } |
832 | 833 | ||
833 | /************************************************************************** | 834 | /************************************************************************** |
834 | * | 835 | * |
835 | **************************************************************************/ | 836 | **************************************************************************/ |
836 | 837 | ||
837 | //calls the smsapplication with the number | 838 | //calls the smsapplication with the number |
838 | bool ExternalAppHandler::callBySMS( const QString& phonenumber ) | 839 | bool ExternalAppHandler::callBySMS( const QString& phonenumber ) |
839 | { | 840 | { |
840 | #ifndef DESKTOP_VERSION | 841 | #ifndef DESKTOP_VERSION |
841 | QString channel; | 842 | QString channel; |
842 | QString message; | 843 | QString message; |
843 | QString parameters; | 844 | QString parameters; |
844 | 845 | ||
845 | 846 | ||
846 | int client = KPimGlobalPrefs::instance()->mSMSClient; | 847 | int client = KPimGlobalPrefs::instance()->mSMSClient; |
847 | if (client == KPimGlobalPrefs::OTHER_SMC) | 848 | if (client == KPimGlobalPrefs::OTHER_SMC) |
848 | { | 849 | { |
849 | channel = KPimGlobalPrefs::instance()->mSMSOtherChannel; | 850 | channel = KPimGlobalPrefs::instance()->mSMSOtherChannel; |
850 | message = KPimGlobalPrefs::instance()->mSMSOtherMessage; | 851 | message = KPimGlobalPrefs::instance()->mSMSOtherMessage; |
851 | parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters; | 852 | parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters; |
852 | } | 853 | } |
853 | else | 854 | else |
854 | { | 855 | { |
855 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SMS, client); | 856 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SMS, client); |
856 | if (!dai) | 857 | if (!dai) |
857 | { | 858 | { |
858 | qDebug("could not find configured sms application."); | 859 | qDebug("could not find configured sms application."); |
859 | return false; | 860 | return false; |
860 | } | 861 | } |
861 | channel = dai->_channel; | 862 | channel = dai->_channel; |
862 | message = dai->_message; | 863 | message = dai->_message; |
863 | parameters = dai->_parameters; | 864 | parameters = dai->_parameters; |
864 | } | 865 | } |
865 | 866 | ||
866 | 867 | ||
867 | //first check if one of the mailers need the emails right in the message. | 868 | //first check if one of the mailers need the emails right in the message. |
868 | message = translateMessage(message, phonenumber, ""); | 869 | message = translateMessage(message, phonenumber, ""); |
869 | 870 | ||
870 | 871 | ||
871 | #ifdef DEBUG_EXT_APP_HANDLER | 872 | #ifdef DEBUG_EXT_APP_HANDLER |
872 | qDebug("7Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); | 873 | qDebug("7Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); |
873 | qDebug("passing phonenumber(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); | 874 | qDebug("passing phonenumber(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); |
874 | #endif | 875 | #endif |
875 | 876 | ||
876 | QCopEnvelope e(channel.latin1(), message.latin1()); | 877 | QCopEnvelope e(channel.latin1(), message.latin1()); |
877 | //US we need no names in the To field. The emailadresses are enough | 878 | //US we need no names in the To field. The emailadresses are enough |
878 | 879 | ||
879 | passParameters(&e, parameters, phonenumber, ""); | 880 | passParameters(&e, parameters, phonenumber, ""); |
880 | 881 | ||
881 | 882 | ||
882 | #else | 883 | #else |
883 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of sms." ) ); | 884 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of sms." ) ); |
884 | #endif | 885 | #endif |
885 | 886 | ||
886 | 887 | ||
887 | return true; | 888 | return true; |
888 | } | 889 | } |
889 | 890 | ||
890 | /************************************************************************** | 891 | /************************************************************************** |
891 | * | 892 | * |
892 | **************************************************************************/ | 893 | **************************************************************************/ |
893 | 894 | ||
894 | //calls the pagerapplication with the number | 895 | //calls the pagerapplication with the number |
895 | bool ExternalAppHandler::callByPager( const QString& pagernumber ) | 896 | bool ExternalAppHandler::callByPager( const QString& pagernumber ) |
896 | { | 897 | { |
897 | #ifndef DESKTOP_VERSION | 898 | #ifndef DESKTOP_VERSION |
898 | QString channel; | 899 | QString channel; |
899 | QString message; | 900 | QString message; |
900 | QString parameters; | 901 | QString parameters; |
901 | 902 | ||
902 | 903 | ||
903 | int client = KPimGlobalPrefs::instance()->mPagerClient; | 904 | int client = KPimGlobalPrefs::instance()->mPagerClient; |
904 | if (client == KPimGlobalPrefs::OTHER_PAC) | 905 | if (client == KPimGlobalPrefs::OTHER_PAC) |
905 | { | 906 | { |
906 | channel = KPimGlobalPrefs::instance()->mPagerOtherChannel; | 907 | channel = KPimGlobalPrefs::instance()->mPagerOtherChannel; |
907 | message = KPimGlobalPrefs::instance()->mPagerOtherMessage; | 908 | message = KPimGlobalPrefs::instance()->mPagerOtherMessage; |
908 | parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters; | 909 | parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters; |
909 | } | 910 | } |
910 | else | 911 | else |
911 | { | 912 | { |
912 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PAGER, client); | 913 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PAGER, client); |
913 | if (!dai) | 914 | if (!dai) |
914 | { | 915 | { |
915 | qDebug("could not find configured pager application."); | 916 | qDebug("could not find configured pager application."); |
916 | return false; | 917 | return false; |
917 | } | 918 | } |
918 | channel = dai->_channel; | 919 | channel = dai->_channel; |
919 | message = dai->_message; | 920 | message = dai->_message; |
920 | parameters = dai->_parameters; | 921 | parameters = dai->_parameters; |
921 | } | 922 | } |
922 | 923 | ||
923 | 924 | ||
924 | //first check if one of the mailers need the emails right in the message. | 925 | //first check if one of the mailers need the emails right in the message. |
925 | message = translateMessage(message, pagernumber, ""); | 926 | message = translateMessage(message, pagernumber, ""); |
926 | 927 | ||
927 | 928 | ||
928 | #ifdef DEBUG_EXT_APP_HANDLER | 929 | #ifdef DEBUG_EXT_APP_HANDLER |
929 | qDebug("8Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); | 930 | qDebug("8Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); |
930 | qDebug("passing pagernumber(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1()); | 931 | qDebug("passing pagernumber(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1()); |
931 | #endif | 932 | #endif |
932 | 933 | ||
933 | QCopEnvelope e(channel.latin1(), message.latin1()); | 934 | QCopEnvelope e(channel.latin1(), message.latin1()); |
934 | //US we need no names in the To field. The emailadresses are enough | 935 | //US we need no names in the To field. The emailadresses are enough |
935 | 936 | ||
936 | passParameters(&e, parameters, pagernumber, ""); | 937 | passParameters(&e, parameters, pagernumber, ""); |
937 | 938 | ||
938 | 939 | ||
939 | #else | 940 | #else |
940 | KMessageBox::sorry( 0, i18n( "This version does not support paging." ) ); | 941 | KMessageBox::sorry( 0, i18n( "This version does not support paging." ) ); |
941 | #endif | 942 | #endif |
942 | 943 | ||
943 | 944 | ||
944 | return true; | 945 | return true; |
945 | } | 946 | } |
946 | 947 | ||
947 | /************************************************************************** | 948 | /************************************************************************** |
948 | * | 949 | * |
949 | **************************************************************************/ | 950 | **************************************************************************/ |
950 | 951 | ||
951 | //calls the faxapplication with the number | 952 | //calls the faxapplication with the number |
952 | bool ExternalAppHandler::callByFax( const QString& faxnumber ) | 953 | bool ExternalAppHandler::callByFax( const QString& faxnumber ) |
953 | { | 954 | { |
954 | #ifndef DESKTOP_VERSION | 955 | #ifndef DESKTOP_VERSION |
955 | QString channel; | 956 | QString channel; |
956 | QString message; | 957 | QString message; |
957 | QString parameters; | 958 | QString parameters; |
958 | 959 | ||
959 | 960 | ||
960 | int client = KPimGlobalPrefs::instance()->mFaxClient; | 961 | int client = KPimGlobalPrefs::instance()->mFaxClient; |
961 | if (client == KPimGlobalPrefs::OTHER_FAC) | 962 | if (client == KPimGlobalPrefs::OTHER_FAC) |
962 | { | 963 | { |
963 | channel = KPimGlobalPrefs::instance()->mFaxOtherChannel; | 964 | channel = KPimGlobalPrefs::instance()->mFaxOtherChannel; |
964 | message = KPimGlobalPrefs::instance()->mFaxOtherMessage; | 965 | message = KPimGlobalPrefs::instance()->mFaxOtherMessage; |
965 | parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters; | 966 | parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters; |
966 | } | 967 | } |
967 | else | 968 | else |
968 | { | 969 | { |
969 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(FAX, client); | 970 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(FAX, client); |
970 | if (!dai) | 971 | if (!dai) |
971 | { | 972 | { |
972 | qDebug("could not find configured fax application."); | 973 | qDebug("could not find configured fax application."); |
973 | return false; | 974 | return false; |
974 | } | 975 | } |
975 | channel = dai->_channel; | 976 | channel = dai->_channel; |
976 | message = dai->_message; | 977 | message = dai->_message; |
977 | parameters = dai->_parameters; | 978 | parameters = dai->_parameters; |
978 | } | 979 | } |
979 | 980 | ||
980 | 981 | ||
981 | //first check if one of the mailers need the emails right in the message. | 982 | //first check if one of the mailers need the emails right in the message. |
982 | message = translateMessage(message, faxnumber, ""); | 983 | message = translateMessage(message, faxnumber, ""); |
983 | 984 | ||
984 | 985 | ||
985 | #ifdef DEBUG_EXT_APP_HANDLER | 986 | #ifdef DEBUG_EXT_APP_HANDLER |
986 | qDebug("9Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); | 987 | qDebug("9Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); |
987 | qDebug("passing faxnumber(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1()); | 988 | qDebug("passing faxnumber(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1()); |
988 | #endif | 989 | #endif |
989 | 990 | ||
990 | QCopEnvelope e(channel.latin1(), message.latin1()); | 991 | QCopEnvelope e(channel.latin1(), message.latin1()); |
991 | //US we need no names in the To field. The emailadresses are enough | 992 | //US we need no names in the To field. The emailadresses are enough |
992 | 993 | ||
993 | passParameters(&e, parameters, faxnumber, ""); | 994 | passParameters(&e, parameters, faxnumber, ""); |
994 | 995 | ||
995 | 996 | ||
996 | #else | 997 | #else |
997 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of faxes." ) ); | 998 | KMessageBox::sorry( 0, i18n( "This version does not support the sending of faxes." ) ); |
998 | #endif | 999 | #endif |
999 | 1000 | ||
1000 | 1001 | ||
1001 | return true; | 1002 | return true; |
1002 | } | 1003 | } |
1003 | 1004 | ||
1004 | /************************************************************************** | 1005 | /************************************************************************** |
1005 | * | 1006 | * |
1006 | **************************************************************************/ | 1007 | **************************************************************************/ |
1007 | 1008 | ||
1008 | //calls the sipapplication with the number | 1009 | //calls the sipapplication with the number |
1009 | bool ExternalAppHandler::callBySIP( const QString& sipnumber ) | 1010 | bool ExternalAppHandler::callBySIP( const QString& sipnumber ) |
1010 | { | 1011 | { |
1011 | #ifndef DESKTOP_VERSION | 1012 | #ifndef DESKTOP_VERSION |
1012 | QString channel; | 1013 | QString channel; |
1013 | QString message; | 1014 | QString message; |
1014 | QString parameters; | 1015 | QString parameters; |
1015 | 1016 | ||
1016 | 1017 | ||
1017 | int client = KPimGlobalPrefs::instance()->mSipClient; | 1018 | int client = KPimGlobalPrefs::instance()->mSipClient; |
1018 | if (client == KPimGlobalPrefs::OTHER_SIC) | 1019 | if (client == KPimGlobalPrefs::OTHER_SIC) |
1019 | { | 1020 | { |
1020 | channel = KPimGlobalPrefs::instance()->mSipOtherChannel; | 1021 | channel = KPimGlobalPrefs::instance()->mSipOtherChannel; |
1021 | message = KPimGlobalPrefs::instance()->mSipOtherMessage; | 1022 | message = KPimGlobalPrefs::instance()->mSipOtherMessage; |
1022 | parameters = KPimGlobalPrefs::instance()->mSipOtherMessageParameters; | 1023 | parameters = KPimGlobalPrefs::instance()->mSipOtherMessageParameters; |
1023 | } | 1024 | } |
1024 | else | 1025 | else |
1025 | { | 1026 | { |
1026 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SIP, client); | 1027 | DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SIP, client); |
1027 | if (!dai) | 1028 | if (!dai) |
1028 | { | 1029 | { |
1029 | qDebug("could not find configured sip application."); | 1030 | qDebug("could not find configured sip application."); |
1030 | return false; | 1031 | return false; |
1031 | } | 1032 | } |
1032 | channel = dai->_channel; | 1033 | channel = dai->_channel; |
1033 | message = dai->_message; | 1034 | message = dai->_message; |
1034 | parameters = dai->_parameters; | 1035 | parameters = dai->_parameters; |
1035 | } | 1036 | } |
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 | ||
1067 | QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1, const QString& param2 ) const | 1068 | QString& 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 | ||
1077 | void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& parameters, const QString& param1 , const QString& param2) const | 1078 | void 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 | ||
1130 | void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data ) | 1131 | void 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 | ||
1157 | bool ExternalAppHandler::requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid) | 1163 | bool 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 | ||
1168 | bool ExternalAppHandler::returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3) | 1174 | bool 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 | ||
1176 | bool ExternalAppHandler::requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QString& email) | 1182 | bool 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 | ||
1182 | bool ExternalAppHandler::returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& list1, const QStringList& list2, const QStringList& list3) | 1188 | bool 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 | ||
1190 | bool ExternalAppHandler::requestDetailsFromKAPI(const QString& name, const QString& email, const QString& uid) | 1196 | bool 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 | ||
1196 | bool ExternalAppHandler::requestBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid) | 1202 | bool 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 | ||
1202 | bool 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) | 1208 | bool 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 | ||
diff --git a/libkdepim/externalapphandler.h b/libkdepim/externalapphandler.h index 097f306..b899ad7 100644 --- a/libkdepim/externalapphandler.h +++ b/libkdepim/externalapphandler.h | |||
@@ -1,293 +1,294 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef EXTERNALAPPHANDLER_H | 31 | #ifndef EXTERNALAPPHANDLER_H |
32 | #define EXTERNALAPPHANDLER_H | 32 | #define EXTERNALAPPHANDLER_H |
33 | 33 | ||
34 | #include <qobject.h> | 34 | #include <qobject.h> |
35 | #include <qlist.h> | 35 | #include <qlist.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | 37 | ||
38 | class QCopEnvelope; | 38 | class QCopEnvelope; |
39 | 39 | ||
40 | 40 | ||
41 | class ExternalAppHandler; | 41 | class ExternalAppHandler; |
42 | class QCopTransferItem : public QObject | 42 | class QCopTransferItem : public QObject |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | public: | 45 | public: |
46 | QCopTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); | 46 | QCopTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); |
47 | QCopTransferItem(); | 47 | QCopTransferItem(); |
48 | 48 | ||
49 | bool sendMessageToTarget(const QString& uid, const QString& param1 = QString::null, const QString& param2 = QString::null, const QString& param3 = QString::null); | 49 | bool sendMessageToTarget(const QString& uid, const QString& param1 = QString::null, const QString& param2 = QString::null, const QString& param3 = QString::null); |
50 | 50 | ||
51 | void setSourceChannel(const QString& sourceChannel); | 51 | void setSourceChannel(const QString& sourceChannel); |
52 | 52 | ||
53 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); | 53 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); |
54 | 54 | ||
55 | 55 | ||
56 | signals: | 56 | signals: |
57 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid); | 57 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid); |
58 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1); | 58 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1); |
59 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1, const QString& param2); | 59 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1, const QString& param2); |
60 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1, const QString& param2, const QString& param3); | 60 | void receivedMessageFromSource(const QString& sourceChannel, const QString& uid, const QString& param1, const QString& param2, const QString& param3); |
61 | 61 | ||
62 | public: | 62 | public: |
63 | int _usedSourceParameters; | 63 | int _usedSourceParameters; |
64 | QString _sourceChannel; | 64 | QString _sourceChannel; |
65 | QString _sourceMessage; | 65 | QString _sourceMessage; |
66 | QString _sourceMessageParameters; | 66 | QString _sourceMessageParameters; |
67 | QString _targetChannel; | 67 | QString _targetChannel; |
68 | QString _targetMessage; | 68 | QString _targetMessage; |
69 | QString _targetMessageParameters; | 69 | QString _targetMessageParameters; |
70 | 70 | ||
71 | }; | 71 | }; |
72 | 72 | ||
73 | /********************************************************************************* | 73 | /********************************************************************************* |
74 | * | 74 | * |
75 | ********************************************************************************/ | 75 | ********************************************************************************/ |
76 | 76 | ||
77 | class QCopMapTransferItem : public QCopTransferItem | 77 | class QCopMapTransferItem : public QCopTransferItem |
78 | { | 78 | { |
79 | Q_OBJECT | 79 | Q_OBJECT |
80 | public: | 80 | public: |
81 | QCopMapTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); | 81 | QCopMapTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); |
82 | 82 | ||
83 | bool sendMessageToSource(const QString& uid, const QMap<QString,QString>& nameEmailMap); | 83 | bool sendMessageToSource(const QString& uid, const QMap<QString,QString>& nameEmailMap); |
84 | 84 | ||
85 | 85 | ||
86 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); | 86 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); |
87 | 87 | ||
88 | 88 | ||
89 | signals: | 89 | signals: |
90 | void receivedMessageFromTarget(const QString& uid, const QMap<QString,QString>& nameEmailMap); | 90 | void receivedMessageFromTarget(const QString& uid, const QMap<QString,QString>& nameEmailMap); |
91 | 91 | ||
92 | }; | 92 | }; |
93 | 93 | ||
94 | /********************************************************************************* | 94 | /********************************************************************************* |
95 | * | 95 | * |
96 | ********************************************************************************/ | 96 | ********************************************************************************/ |
97 | 97 | ||
98 | class QCopListTransferItem : public QCopTransferItem | 98 | class QCopListTransferItem : public QCopTransferItem |
99 | { | 99 | { |
100 | Q_OBJECT | 100 | Q_OBJECT |
101 | public: | 101 | public: |
102 | QCopListTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); | 102 | QCopListTransferItem(int usedSourceParameters, const QString& sourceMessage, const QString& targetChannel, const QString& targetMessage); |
103 | ~QCopListTransferItem(); | 103 | ~QCopListTransferItem(); |
104 | bool sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6); | 104 | bool sendMessageToSource(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4, const QStringList& list5, const QStringList& list6); |
105 | 105 | ||
106 | 106 | ||
107 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); | 107 | virtual bool appMessage( const QCString& msg, const QByteArray& data ); |
108 | 108 | ||
109 | 109 | ||
110 | signals: | 110 | signals: |
111 | void receivedMessageFromTarget(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4 , const QStringList& list5, const QStringList& list6); | 111 | void receivedMessageFromTarget(const QString& uid, const QStringList& list1, const QStringList& list2, const QStringList& list3, const QStringList& list4 , const QStringList& list5, const QStringList& list6); |
112 | 112 | ||
113 | }; | 113 | }; |
114 | 114 | ||
115 | /********************************************************************************* | 115 | /********************************************************************************* |
116 | * | 116 | * |
117 | ********************************************************************************/ | 117 | ********************************************************************************/ |
118 | 118 | ||
119 | 119 | ||
120 | class DefaultAppItem | 120 | class DefaultAppItem |
121 | { | 121 | { |
122 | public: | 122 | public: |
123 | DefaultAppItem(int type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2) | 123 | DefaultAppItem(int type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2) |
124 | : _type(type), _id(id), _label(label), _channel(channel), _message(message), _parameters(parameters), _message2(message2), _parameters2(parameters2) | 124 | : _type(type), _id(id), _label(label), _channel(channel), _message(message), _parameters(parameters), _message2(message2), _parameters2(parameters2) |
125 | {} | 125 | {} |
126 | 126 | ||
127 | DefaultAppItem() | 127 | DefaultAppItem() |
128 | { } | 128 | { } |
129 | 129 | ||
130 | public: | 130 | public: |
131 | int _type; | 131 | int _type; |
132 | int _id; | 132 | int _id; |
133 | QString _label; | 133 | QString _label; |
134 | QString _channel; | 134 | QString _channel; |
135 | QString _message; | 135 | QString _message; |
136 | QString _parameters;// a list of parameters in stringrepresentation. Delimiter is ; | 136 | QString _parameters;// a list of parameters in stringrepresentation. Delimiter is ; |
137 | QString _message2; | 137 | QString _message2; |
138 | QString _parameters2; // a list of parameters in stringrepresentation. Delimiter is ; | 138 | QString _parameters2; // a list of parameters in stringrepresentation. Delimiter is ; |
139 | 139 | ||
140 | }; | 140 | }; |
141 | 141 | ||
142 | /********************************************************************************* | 142 | /********************************************************************************* |
143 | * | 143 | * |
144 | ********************************************************************************/ | 144 | ********************************************************************************/ |
145 | 145 | ||
146 | class ExternalAppHandler : public QObject | 146 | class ExternalAppHandler : public QObject |
147 | { | 147 | { |
148 | Q_OBJECT | 148 | Q_OBJECT |
149 | public: | 149 | public: |
150 | virtual ~ExternalAppHandler(); | 150 | virtual ~ExternalAppHandler(); |
151 | 151 | ||
152 | static ExternalAppHandler *instance(); | 152 | static ExternalAppHandler *instance(); |
153 | 153 | ||
154 | enum Types { | 154 | enum Types { |
155 | EMAIL = 0, | 155 | EMAIL = 0, |
156 | PHONE = 1, | 156 | PHONE = 1, |
157 | SMS = 2, | 157 | SMS = 2, |
158 | FAX = 3, | 158 | FAX = 3, |
159 | PAGER = 4, | 159 | PAGER = 4, |
160 | SIP = 5 | 160 | SIP = 5 |
161 | }; | 161 | }; |
162 | 162 | ||
163 | enum Availability { | 163 | enum Availability { |
164 | UNDEFINED = -1, | 164 | UNDEFINED = -1, |
165 | UNAVAILABLE = 0, | 165 | UNAVAILABLE = 0, |
166 | AVAILABLE = 1 | 166 | AVAILABLE = 1 |
167 | }; | 167 | }; |
168 | 168 | ||
169 | //calls the emailapplication with a number of attachments that need to be send. | 169 | //calls the emailapplication with a number of attachments that need to be send. |
170 | //either parameter can be left empty. | 170 | //either parameter can be left empty. |
171 | bool mailToMultipleContacts( const QString& recipients, const QString& attachmenturls ); | 171 | bool mailToMultipleContacts( const QString& recipients, const QString& attachmenturls ); |
172 | 172 | ||
173 | //calls the emailapplication and creates a mail with parameter emailadress as recipients | 173 | //calls the emailapplication and creates a mail with parameter emailadress as recipients |
174 | bool mailToOneContact( const QString& name, const QString& emailadress ); | 174 | bool mailToOneContact( const QString& name, const QString& emailadress ); |
175 | 175 | ||
176 | //calls the emailapplication and creates a mail with parameter as recipients | 176 | //calls the emailapplication and creates a mail with parameter as recipients |
177 | // parameters format is | 177 | // parameters format is |
178 | // NAME <EMAIL>:SUBJECT | 178 | // NAME <EMAIL>:SUBJECT |
179 | bool mailToOneContact( const QString& adressline ); | 179 | bool mailToOneContact( const QString& adressline ); |
180 | 180 | ||
181 | //calls the phoneapplication with the number | 181 | //calls the phoneapplication with the number |
182 | bool callByPhone( const QString& phonenumber ); | 182 | bool callByPhone( const QString& phonenumber ); |
183 | 183 | ||
184 | //calls the smsapplication with the number | 184 | //calls the smsapplication with the number |
185 | bool callBySMS( const QString& phonenumber ); | 185 | bool callBySMS( const QString& phonenumber ); |
186 | 186 | ||
187 | //calls the pagerapplication with the number | 187 | //calls the pagerapplication with the number |
188 | bool callByPager( const QString& pagernumber ); | 188 | bool callByPager( const QString& pagernumber ); |
189 | 189 | ||
190 | //calls the faxapplication with the number | 190 | //calls the faxapplication with the number |
191 | bool callByFax( const QString& faxnumber ); | 191 | bool callByFax( const QString& faxnumber ); |
192 | 192 | ||
193 | //calls the sipapplication with the number | 193 | //calls the sipapplication with the number |
194 | bool callBySIP( const QString& sipnumber ); | 194 | bool callBySIP( const QString& sipnumber ); |
195 | 195 | ||
196 | bool isEmailAppAvailable(); | 196 | bool isEmailAppAvailable(); |
197 | bool isSMSAppAvailable(); | 197 | bool isSMSAppAvailable(); |
198 | bool isPhoneAppAvailable(); | 198 | bool isPhoneAppAvailable(); |
199 | bool isFaxAppAvailable(); | 199 | bool isFaxAppAvailable(); |
200 | bool isPagerAppAvailable(); | 200 | bool isPagerAppAvailable(); |
201 | bool isSIPAppAvailable(); | 201 | bool isSIPAppAvailable(); |
202 | 202 | ||
203 | 203 | ||
204 | //Call this method on the source when you want to select names from the addressbook by using QCop | 204 | //Call this method on the source when you want to select names from the addressbook by using QCop |
205 | bool requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid); | 205 | bool requestNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid); |
206 | //Call this method on the target when you want to return the name/email map to the source (client). | 206 | //Call this method on the target when you want to return the name/email map to the source (client). |
207 | bool returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& name, const QStringList& email, const QStringList& uid); | 207 | bool returnNameEmailUidListFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& name, const QStringList& email, const QStringList& uid); |
208 | 208 | ||
209 | 209 | ||
210 | 210 | ||
211 | bool requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QString& email); | 211 | bool requestFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QString& email); |
212 | bool returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& name, const QStringList& email, const QStringList& uid); | 212 | bool returnFindByEmailFromKAPI(const QString& sourceChannel, const QString& sessionuid, const QStringList& name, const QStringList& email, const QStringList& uid); |
213 | 213 | ||
214 | bool requestDetailsFromKAPI(const QString& name, const QString& email, const QString& uid); | 214 | bool requestDetailsFromKAPI(const QString& name, const QString& email, const QString& uid); |
215 | 215 | ||
216 | 216 | ||
217 | 217 | ||
218 | bool requestBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid); | 218 | bool requestBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid); |
219 | bool returnBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid, | 219 | bool returnBirthdayListFromKAPI(const QString& sourceChannel, const QString& sessionuid, |
220 | const QStringList& birthdayList, const QStringList& anniversaryList, | 220 | const QStringList& birthdayList, const QStringList& anniversaryList, |
221 | const QStringList& realNameList, const QStringList& emailList, | 221 | const QStringList& realNameList, const QStringList& emailList, |
222 | const QStringList& assembledNameList, const QStringList& uidList); | 222 | const QStringList& assembledNameList, const QStringList& uidList); |
223 | 223 | ||
224 | 224 | ||
225 | //loadConfig clears the cache and checks again if the applications are available or not | 225 | //loadConfig clears the cache and checks again if the applications are available or not |
226 | void loadConfig(); | 226 | void loadConfig(); |
227 | 227 | ||
228 | QList<DefaultAppItem> getAvailableDefaultItems(Types); | 228 | QList<DefaultAppItem> getAvailableDefaultItems(Types); |
229 | DefaultAppItem* getDefaultItem(Types, int); | 229 | DefaultAppItem* getDefaultItem(Types, int); |
230 | 230 | ||
231 | public slots: | 231 | public slots: |
232 | void appMessage( const QCString& msg, const QByteArray& data ); | 232 | void appMessage( const QCString& msg, const QByteArray& data ); |
233 | 233 | ||
234 | 234 | ||
235 | signals: | 235 | signals: |
236 | void callContactdialog(); | 236 | void callContactdialog(); |
237 | void nextView(); | 237 | void nextView(); |
238 | void doRingSync(); | ||
238 | // Emmitted when the target app receives a request from the source app | 239 | // Emmitted when the target app receives a request from the source app |
239 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& uid); | 240 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& uid); |
240 | 241 | ||
241 | // Emitted when the source app recieves a list of name/email pairs (=addresses) from another target app. Usually Ka/Pi | 242 | // Emitted when the source app recieves a list of name/email pairs (=addresses) from another target app. Usually Ka/Pi |
242 | // The first parameter is a uniqueid. It can be used to identify the event | 243 | // The first parameter is a uniqueid. It can be used to identify the event |
243 | void receivedNameEmailUidListEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); | 244 | void receivedNameEmailUidListEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); |
244 | 245 | ||
245 | void requestFindByEmail(const QString& sourceChannel, const QString& uid, const QString& email); | 246 | void requestFindByEmail(const QString& sourceChannel, const QString& uid, const QString& email); |
246 | void receivedFindByEmailEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); | 247 | void receivedFindByEmailEvent(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList); |
247 | 248 | ||
248 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); | 249 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); |
249 | 250 | ||
250 | 251 | ||
251 | // Emmitted when the target app receives a request from the source app | 252 | // Emmitted when the target app receives a request from the source app |
252 | void requestForBirthdayList(const QString& sourceChannel, const QString& uid); | 253 | void requestForBirthdayList(const QString& sourceChannel, const QString& uid); |
253 | 254 | ||
254 | // Emitted when the source app recieves a list of name/email pairs (=addresses) from another target app. Usually Ka/Pi | 255 | // Emitted when the source app recieves a list of name/email pairs (=addresses) from another target app. Usually Ka/Pi |
255 | // The first parameter is a uniqueid. It can be used to identify the event | 256 | // The first parameter is a uniqueid. It can be used to identify the event |
256 | void receivedBirthdayListEvent(const QString& uid, const QStringList& birthdayList, | 257 | void receivedBirthdayListEvent(const QString& uid, const QStringList& birthdayList, |
257 | const QStringList& anniversaryList, const QStringList& realNameList, | 258 | const QStringList& anniversaryList, const QStringList& realNameList, |
258 | const QStringList& emailList, const QStringList& assembledNameList, | 259 | const QStringList& emailList, const QStringList& assembledNameList, |
259 | const QStringList& uidList); | 260 | const QStringList& uidList); |
260 | 261 | ||
261 | 262 | ||
262 | private: | 263 | private: |
263 | ExternalAppHandler(); | 264 | ExternalAppHandler(); |
264 | QList<DefaultAppItem> mDefaultItems; | 265 | QList<DefaultAppItem> mDefaultItems; |
265 | 266 | ||
266 | Availability mEmailAppAvailable; | 267 | Availability mEmailAppAvailable; |
267 | Availability mPhoneAppAvailable; | 268 | Availability mPhoneAppAvailable; |
268 | Availability mFaxAppAvailable; | 269 | Availability mFaxAppAvailable; |
269 | Availability mSMSAppAvailable; | 270 | Availability mSMSAppAvailable; |
270 | Availability mPagerAppAvailable; | 271 | Availability mPagerAppAvailable; |
271 | Availability mSIPAppAvailable; | 272 | Availability mSIPAppAvailable; |
272 | 273 | ||
273 | QCopListTransferItem* mNameEmailUidListFromKAPITransfer; | 274 | QCopListTransferItem* mNameEmailUidListFromKAPITransfer; |
274 | QCopListTransferItem* mFindByEmailFromKAPITransfer; | 275 | QCopListTransferItem* mFindByEmailFromKAPITransfer; |
275 | QCopTransferItem* mDisplayDetails; | 276 | QCopTransferItem* mDisplayDetails; |
276 | QCopListTransferItem* mBirthdayListFromKAPITransfer; | 277 | QCopListTransferItem* mBirthdayListFromKAPITransfer; |
277 | 278 | ||
278 | 279 | ||
279 | void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2); | 280 | void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2); |
280 | 281 | ||
281 | QString& translateMessage(QString& message, const QString& param1, const QString& param2) const; | 282 | QString& translateMessage(QString& message, const QString& param1, const QString& param2) const; |
282 | void passParameters(QCopEnvelope* e, const QString& parameters, const QString& param1, const QString& param2) const; | 283 | void passParameters(QCopEnvelope* e, const QString& parameters, const QString& param1, const QString& param2) const; |
283 | 284 | ||
284 | 285 | ||
285 | static ExternalAppHandler *sInstance; | 286 | static ExternalAppHandler *sInstance; |
286 | 287 | ||
287 | private slots: | 288 | private slots: |
288 | void receivedNameEmailUidList_Slot(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList, const QStringList&, const QStringList&, const QStringList& ); | 289 | void receivedNameEmailUidList_Slot(const QString& uid, const QStringList& nameList, const QStringList& emailList, const QStringList& uidList, const QStringList&, const QStringList&, const QStringList& ); |
289 | 290 | ||
290 | }; | 291 | }; |
291 | 292 | ||
292 | 293 | ||
293 | #endif | 294 | #endif |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index db815d6..038e032 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,1652 +1,1654 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | 58 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 59 | ||
60 | 60 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) | 62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) |
63 | { | 63 | { |
64 | mServerSocket = 0; | 64 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 66 | bar->setCaption (""); |
67 | mWriteBackInPast = 2; | 67 | mWriteBackInPast = 2; |
68 | 68 | ||
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | KSyncManager::~KSyncManager() | 72 | KSyncManager::~KSyncManager() |
73 | { | 73 | { |
74 | delete bar; | 74 | delete bar; |
75 | } | 75 | } |
76 | 76 | ||
77 | void KSyncManager::setDefaultFileName( QString s) | 77 | void KSyncManager::setDefaultFileName( QString s) |
78 | { | 78 | { |
79 | mDefFileName = s ; | 79 | mDefFileName = s ; |
80 | if ( mPrefs->mPassiveSyncAutoStart ) | 80 | if ( mPrefs->mPassiveSyncAutoStart ) |
81 | enableQuick( false ); | 81 | enableQuick( false ); |
82 | } | 82 | } |
83 | 83 | ||
84 | void KSyncManager::fillSyncMenu() | 84 | void KSyncManager::fillSyncMenu() |
85 | { | 85 | { |
86 | if ( mSyncMenu->count() ) | 86 | if ( mSyncMenu->count() ) |
87 | mSyncMenu->clear(); | 87 | mSyncMenu->clear(); |
88 | 88 | ||
89 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 89 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
90 | mSyncMenu->insertSeparator(); | 90 | mSyncMenu->insertSeparator(); |
91 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 91 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
92 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 92 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
93 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 93 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
94 | clearMenu->insertSeparator(); | 94 | clearMenu->insertSeparator(); |
95 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 95 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
96 | mSyncMenu->insertSeparator(); | 96 | mSyncMenu->insertSeparator(); |
97 | if ( mServerSocket == 0 ) { | 97 | if ( mServerSocket == 0 ) { |
98 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 98 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
99 | } else { | 99 | } else { |
100 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 100 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
101 | } | 101 | } |
102 | mSyncMenu->insertSeparator(); | 102 | mSyncMenu->insertSeparator(); |
103 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 103 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
104 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
105 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 105 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
106 | config.setGroup("General"); | 106 | config.setGroup("General"); |
107 | QStringList prof = config.readListEntry("SyncProfileNames"); | 107 | QStringList prof = config.readListEntry("SyncProfileNames"); |
108 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 108 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
109 | if ( prof.count() < 2 ) { | 109 | if ( prof.count() < 2 ) { |
110 | prof.clear(); | 110 | prof.clear(); |
111 | QString externalName; | 111 | QString externalName; |
112 | #ifdef DESKTOP_VERSION | 112 | #ifdef DESKTOP_VERSION |
113 | #ifdef _WIN32_ | 113 | #ifdef _WIN32_ |
114 | externalName = "OutLook(not_implemented)"; | 114 | externalName = "OutLook(not_implemented)"; |
115 | #else | 115 | #else |
116 | externalName = "KDE_Desktop"; | 116 | externalName = "KDE_Desktop"; |
117 | #endif | 117 | #endif |
118 | #else | 118 | #else |
119 | externalName = "Sharp_DTM"; | 119 | externalName = "Sharp_DTM"; |
120 | #endif | 120 | #endif |
121 | prof << externalName; | 121 | prof << externalName; |
122 | prof << i18n("Local_file"); | 122 | prof << i18n("Local_file"); |
123 | prof << i18n("Last_file"); | 123 | prof << i18n("Last_file"); |
124 | KSyncProfile* temp = new KSyncProfile (); | 124 | KSyncProfile* temp = new KSyncProfile (); |
125 | temp->setName( prof[0] ); | 125 | temp->setName( prof[0] ); |
126 | temp->writeConfig(&config); | 126 | temp->writeConfig(&config); |
127 | temp->setName( prof[1] ); | 127 | temp->setName( prof[1] ); |
128 | temp->writeConfig(&config); | 128 | temp->writeConfig(&config); |
129 | temp->setName( prof[2] ); | 129 | temp->setName( prof[2] ); |
130 | temp->writeConfig(&config); | 130 | temp->writeConfig(&config); |
131 | config.setGroup("General"); | 131 | config.setGroup("General"); |
132 | config.writeEntry("SyncProfileNames",prof); | 132 | config.writeEntry("SyncProfileNames",prof); |
133 | config.writeEntry("ExternSyncProfiles",externalName); | 133 | config.writeEntry("ExternSyncProfiles",externalName); |
134 | config.sync(); | 134 | config.sync(); |
135 | delete temp; | 135 | delete temp; |
136 | } | 136 | } |
137 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 137 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
138 | mSyncProfileNames = prof; | 138 | mSyncProfileNames = prof; |
139 | unsigned int i; | 139 | unsigned int i; |
140 | for ( i = 0; i < prof.count(); ++i ) { | 140 | for ( i = 0; i < prof.count(); ++i ) { |
141 | QString insertText = prof[i]; | 141 | QString insertText = prof[i]; |
142 | if ( i == 0 ) { | 142 | if ( i == 0 ) { |
143 | #ifdef DESKTOP_VERSION | 143 | #ifdef DESKTOP_VERSION |
144 | #ifdef _WIN32_ | 144 | #ifdef _WIN32_ |
145 | insertText = "OutLook(not_implemented)"; | 145 | insertText = "OutLook(not_implemented)"; |
146 | #else | 146 | #else |
147 | insertText = "KDE_Desktop"; | 147 | insertText = "KDE_Desktop"; |
148 | #endif | 148 | #endif |
149 | #else | 149 | #else |
150 | insertText = "Sharp_DTM"; | 150 | insertText = "Sharp_DTM"; |
151 | #endif | 151 | #endif |
152 | } | 152 | } |
153 | mSyncMenu->insertItem( insertText, 1000+i ); | 153 | mSyncMenu->insertItem( insertText, 1000+i ); |
154 | clearMenu->insertItem( insertText, 1000+i ); | 154 | clearMenu->insertItem( insertText, 1000+i ); |
155 | if ( i == 2 ) | 155 | if ( i == 2 ) |
156 | mSyncMenu->insertSeparator(); | 156 | mSyncMenu->insertSeparator(); |
157 | } | 157 | } |
158 | QDir app_dir; | 158 | QDir app_dir; |
159 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 159 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
160 | if ( mTargetApp == PWMPI) { | 160 | if ( mTargetApp == PWMPI) { |
161 | mSyncMenu->removeItem( 1000 ); | 161 | mSyncMenu->removeItem( 1000 ); |
162 | clearMenu->removeItem( 1000 ); | 162 | clearMenu->removeItem( 1000 ); |
163 | } | 163 | } |
164 | #ifndef DESKTOP_VERSION | 164 | #ifndef DESKTOP_VERSION |
165 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 165 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
166 | mSyncMenu->removeItem( 1000 ); | 166 | mSyncMenu->removeItem( 1000 ); |
167 | clearMenu->removeItem( 1000 ); | 167 | clearMenu->removeItem( 1000 ); |
168 | } | 168 | } |
169 | #endif | 169 | #endif |
170 | mSyncMenu->removeItem( 1002 ); | 170 | mSyncMenu->removeItem( 1002 ); |
171 | clearMenu->removeItem( 1002 ); | 171 | clearMenu->removeItem( 1002 ); |
172 | } | 172 | } |
173 | void KSyncManager::slotClearMenu( int action ) | 173 | void KSyncManager::slotClearMenu( int action ) |
174 | { | 174 | { |
175 | QString syncDevice; | 175 | QString syncDevice; |
176 | if ( action > 999 ) { | 176 | if ( action > 999 ) { |
177 | syncDevice = mSyncProfileNames[action - 1000] ; | 177 | syncDevice = mSyncProfileNames[action - 1000] ; |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | 181 | ||
182 | int result = 0; | 182 | int result = 0; |
183 | QString sd; | 183 | QString sd; |
184 | if ( syncDevice.isEmpty() ) | 184 | if ( syncDevice.isEmpty() ) |
185 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 185 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
186 | else | 186 | else |
187 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 187 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
188 | 188 | ||
189 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 189 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
190 | 0, 1 ); | 190 | 0, 1 ); |
191 | if ( result ) | 191 | if ( result ) |
192 | return; | 192 | return; |
193 | mImplementation->removeSyncInfo( syncDevice ); | 193 | mImplementation->removeSyncInfo( syncDevice ); |
194 | } | 194 | } |
195 | void KSyncManager::slotSyncMenu( int action ) | 195 | void KSyncManager::slotSyncMenu( int action ) |
196 | { | 196 | { |
197 | qDebug("KSM::syncaction %d ", action); | 197 | qDebug("KSM::syncaction %d ", action); |
198 | if ( action == 5000 ) | 198 | if ( action == 5000 ) |
199 | return; | 199 | return; |
200 | mSyncWithDesktop = false; | 200 | mSyncWithDesktop = false; |
201 | if ( action == 0 ) { | 201 | if ( action == 0 ) { |
202 | 202 | ||
203 | // seems to be a Qt2 event handling bug | 203 | // seems to be a Qt2 event handling bug |
204 | // syncmenu.clear causes a segfault at first time | 204 | // syncmenu.clear causes a segfault at first time |
205 | // when we call it after the main event loop, it is ok | 205 | // when we call it after the main event loop, it is ok |
206 | // same behaviour when calling OM/Pi via QCOP for the first time | 206 | // same behaviour when calling OM/Pi via QCOP for the first time |
207 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 207 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
208 | //confSync(); | 208 | //confSync(); |
209 | 209 | ||
210 | return; | 210 | return; |
211 | } | 211 | } |
212 | if ( action == 1 ) { | 212 | if ( action == 1 ) { |
213 | multiSync( true ); | 213 | multiSync( true ); |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | if ( action == 2 ) { | 216 | if ( action == 2 ) { |
217 | enableQuick(); | 217 | enableQuick(); |
218 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 218 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
219 | return; | 219 | return; |
220 | } | 220 | } |
221 | if ( action == 3 ) { | 221 | if ( action == 3 ) { |
222 | delete mServerSocket; | 222 | delete mServerSocket; |
223 | mServerSocket = 0; | 223 | mServerSocket = 0; |
224 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 224 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
225 | return; | 225 | return; |
226 | } | 226 | } |
227 | 227 | ||
228 | if (blockSave()) | 228 | if (blockSave()) |
229 | return; | 229 | return; |
230 | 230 | ||
231 | setBlockSave(true); | 231 | setBlockSave(true); |
232 | bool silent = false; | 232 | bool silent = false; |
233 | if ( action == 999 ) { | 233 | if ( action == 999 ) { |
234 | //special mode for silent syncing | 234 | //special mode for silent syncing |
235 | action = 1000; | 235 | action = 1000; |
236 | silent = true; | 236 | silent = true; |
237 | } | 237 | } |
238 | 238 | ||
239 | mCurrentSyncProfile = action - 1000 ; | 239 | mCurrentSyncProfile = action - 1000 ; |
240 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 240 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
241 | mCurrentSyncName = mLocalMachineName ; | 241 | mCurrentSyncName = mLocalMachineName ; |
242 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 242 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
243 | KSyncProfile* temp = new KSyncProfile (); | 243 | KSyncProfile* temp = new KSyncProfile (); |
244 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 244 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
245 | temp->readConfig(&config); | 245 | temp->readConfig(&config); |
246 | if (silent) { | 246 | if (silent) { |
247 | mAskForPreferences = false; | 247 | mAskForPreferences = false; |
248 | mShowSyncSummary = false; | 248 | mShowSyncSummary = false; |
249 | mWriteBackFile = true; | 249 | mWriteBackFile = true; |
250 | mSyncAlgoPrefs = 2;// take newest | 250 | mSyncAlgoPrefs = 2;// take newest |
251 | } | 251 | } |
252 | else { | 252 | else { |
253 | mAskForPreferences = temp->getAskForPreferences(); | 253 | mAskForPreferences = temp->getAskForPreferences(); |
254 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 254 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
255 | mWriteBackFile = temp->getWriteBackFile(); | 255 | mWriteBackFile = temp->getWriteBackFile(); |
256 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 256 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
257 | } | 257 | } |
258 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 258 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
259 | mIsKapiFile = temp->getIsKapiFile(); | 259 | mIsKapiFile = temp->getIsKapiFile(); |
260 | mWriteBackInFuture = 0; | 260 | mWriteBackInFuture = 0; |
261 | if ( temp->getWriteBackFuture() ) { | 261 | if ( temp->getWriteBackFuture() ) { |
262 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 262 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
263 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); | 263 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); |
264 | } | 264 | } |
265 | mFilterInCal = temp->getFilterInCal(); | 265 | mFilterInCal = temp->getFilterInCal(); |
266 | mFilterOutCal = temp->getFilterOutCal(); | 266 | mFilterOutCal = temp->getFilterOutCal(); |
267 | mFilterInAB = temp->getFilterInAB(); | 267 | mFilterInAB = temp->getFilterInAB(); |
268 | mFilterOutAB = temp->getFilterOutAB(); | 268 | mFilterOutAB = temp->getFilterOutAB(); |
269 | 269 | ||
270 | if ( action == 1000 ) { | 270 | if ( action == 1000 ) { |
271 | mIsKapiFile = false; | 271 | mIsKapiFile = false; |
272 | #ifdef DESKTOP_VERSION | 272 | #ifdef DESKTOP_VERSION |
273 | syncKDE(); | 273 | syncKDE(); |
274 | #else | 274 | #else |
275 | syncSharp(); | 275 | syncSharp(); |
276 | #endif | 276 | #endif |
277 | 277 | ||
278 | } else if ( action == 1001 ) { | 278 | } else if ( action == 1001 ) { |
279 | syncLocalFile(); | 279 | syncLocalFile(); |
280 | 280 | ||
281 | } else if ( action == 1002 ) { | 281 | } else if ( action == 1002 ) { |
282 | mWriteBackFile = false; | 282 | mWriteBackFile = false; |
283 | mAskForPreferences = false; | 283 | mAskForPreferences = false; |
284 | mShowSyncSummary = false; | 284 | mShowSyncSummary = false; |
285 | mSyncAlgoPrefs = 3; | 285 | mSyncAlgoPrefs = 3; |
286 | quickSyncLocalFile(); | 286 | quickSyncLocalFile(); |
287 | 287 | ||
288 | } else if ( action >= 1003 ) { | 288 | } else if ( action >= 1003 ) { |
289 | if ( temp->getIsLocalFileSync() ) { | 289 | if ( temp->getIsLocalFileSync() ) { |
290 | switch(mTargetApp) | 290 | switch(mTargetApp) |
291 | { | 291 | { |
292 | case (KAPI): | 292 | case (KAPI): |
293 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 293 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
294 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 294 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
295 | break; | 295 | break; |
296 | case (KOPI): | 296 | case (KOPI): |
297 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 297 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
298 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 298 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
299 | break; | 299 | break; |
300 | case (PWMPI): | 300 | case (PWMPI): |
301 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 301 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
302 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 302 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
303 | break; | 303 | break; |
304 | default: | 304 | default: |
305 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 305 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
306 | break; | 306 | break; |
307 | 307 | ||
308 | } | 308 | } |
309 | } else { | 309 | } else { |
310 | if ( temp->getIsPhoneSync() ) { | 310 | if ( temp->getIsPhoneSync() ) { |
311 | mPhoneDevice = temp->getPhoneDevice( ) ; | 311 | mPhoneDevice = temp->getPhoneDevice( ) ; |
312 | mPhoneConnection = temp->getPhoneConnection( ); | 312 | mPhoneConnection = temp->getPhoneConnection( ); |
313 | mPhoneModel = temp->getPhoneModel( ); | 313 | mPhoneModel = temp->getPhoneModel( ); |
314 | syncPhone(); | 314 | syncPhone(); |
315 | } else if ( temp->getIsPiSync() ) { | 315 | } else if ( temp->getIsPiSync() ) { |
316 | if ( mTargetApp == KAPI ) { | 316 | if ( mTargetApp == KAPI ) { |
317 | mPassWordPiSync = temp->getRemotePwAB(); | 317 | mPassWordPiSync = temp->getRemotePwAB(); |
318 | mActiveSyncPort = temp->getRemotePortAB(); | 318 | mActiveSyncPort = temp->getRemotePortAB(); |
319 | mActiveSyncIP = temp->getRemoteIPAB(); | 319 | mActiveSyncIP = temp->getRemoteIPAB(); |
320 | } else if ( mTargetApp == KOPI ) { | 320 | } else if ( mTargetApp == KOPI ) { |
321 | mPassWordPiSync = temp->getRemotePw(); | 321 | mPassWordPiSync = temp->getRemotePw(); |
322 | mActiveSyncPort = temp->getRemotePort(); | 322 | mActiveSyncPort = temp->getRemotePort(); |
323 | mActiveSyncIP = temp->getRemoteIP(); | 323 | mActiveSyncIP = temp->getRemoteIP(); |
324 | } else { | 324 | } else { |
325 | mPassWordPiSync = temp->getRemotePwPWM(); | 325 | mPassWordPiSync = temp->getRemotePwPWM(); |
326 | mActiveSyncPort = temp->getRemotePortPWM(); | 326 | mActiveSyncPort = temp->getRemotePortPWM(); |
327 | mActiveSyncIP = temp->getRemoteIPPWM(); | 327 | mActiveSyncIP = temp->getRemoteIPPWM(); |
328 | } | 328 | } |
329 | syncPi(); | 329 | syncPi(); |
330 | while ( !mPisyncFinished ) { | 330 | while ( !mPisyncFinished ) { |
331 | //qDebug("waiting "); | 331 | //qDebug("waiting "); |
332 | qApp->processEvents(); | 332 | qApp->processEvents(); |
333 | } | 333 | } |
334 | } else | 334 | } else |
335 | syncRemote( temp ); | 335 | syncRemote( temp ); |
336 | 336 | ||
337 | } | 337 | } |
338 | } | 338 | } |
339 | delete temp; | 339 | delete temp; |
340 | setBlockSave(false); | 340 | setBlockSave(false); |
341 | } | 341 | } |
342 | 342 | ||
343 | void KSyncManager::enableQuick( bool ask ) | 343 | void KSyncManager::enableQuick( bool ask ) |
344 | { | 344 | { |
345 | bool autoStart; | 345 | bool autoStart; |
346 | bool changed = false; | 346 | bool changed = false; |
347 | if ( ask ) { | 347 | if ( ask ) { |
348 | QDialog dia ( 0, "input-dialog", true ); | 348 | QDialog dia ( 0, "input-dialog", true ); |
349 | QLineEdit lab ( &dia ); | 349 | QLineEdit lab ( &dia ); |
350 | QVBoxLayout lay( &dia ); | 350 | QVBoxLayout lay( &dia ); |
351 | lab.setText( mPrefs->mPassiveSyncPort ); | 351 | lab.setText( mPrefs->mPassiveSyncPort ); |
352 | lay.setMargin(7); | 352 | lay.setMargin(7); |
353 | lay.setSpacing(7); | 353 | lay.setSpacing(7); |
354 | int po = 9197+mTargetApp; | 354 | int po = 9197+mTargetApp; |
355 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 355 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
356 | lay.addWidget( &label); | 356 | lay.addWidget( &label); |
357 | lay.addWidget( &lab); | 357 | lay.addWidget( &lab); |
358 | 358 | ||
359 | QLineEdit lepw ( &dia ); | 359 | QLineEdit lepw ( &dia ); |
360 | lepw.setText( mPrefs->mPassiveSyncPw ); | 360 | lepw.setText( mPrefs->mPassiveSyncPw ); |
361 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 361 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
362 | lay.addWidget( &label2); | 362 | lay.addWidget( &label2); |
363 | lay.addWidget( &lepw); | 363 | lay.addWidget( &lepw); |
364 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 364 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
365 | lay.addWidget( &autostart); | 365 | lay.addWidget( &autostart); |
366 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 366 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
367 | #ifdef DESKTOP_VERSION | 367 | #ifdef DESKTOP_VERSION |
368 | #ifdef _WIN32_ | 368 | #ifdef _WIN32_ |
369 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 369 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
370 | syncdesktop.hide();// not implemented! | 370 | syncdesktop.hide();// not implemented! |
371 | #else | 371 | #else |
372 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 372 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
373 | #endif | 373 | #endif |
374 | lay.addWidget( &syncdesktop); | 374 | lay.addWidget( &syncdesktop); |
375 | #else | 375 | #else |
376 | mPrefs->mPassiveSyncWithDesktop = false; | 376 | mPrefs->mPassiveSyncWithDesktop = false; |
377 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 377 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
378 | syncdesktop.hide(); | 378 | syncdesktop.hide(); |
379 | #endif | 379 | #endif |
380 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 380 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
381 | 381 | ||
382 | QPushButton pb ( "OK", &dia); | 382 | QPushButton pb ( "OK", &dia); |
383 | lay.addWidget( &pb ); | 383 | lay.addWidget( &pb ); |
384 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 384 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
385 | dia.resize( 230,120 ); | 385 | dia.resize( 230,120 ); |
386 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 386 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
387 | dia.show(); | 387 | dia.show(); |
388 | #ifndef DESKTOP_VERSION | 388 | #ifndef DESKTOP_VERSION |
389 | int dw = QApplication::desktop()->width(); | 389 | int dw = QApplication::desktop()->width(); |
390 | int dh = QApplication::desktop()->height(); | 390 | int dh = QApplication::desktop()->height(); |
391 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); | 391 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); |
392 | #endif | 392 | #endif |
393 | if ( ! dia.exec() ) | 393 | if ( ! dia.exec() ) |
394 | return; | 394 | return; |
395 | dia.hide(); | 395 | dia.hide(); |
396 | qApp->processEvents(); | 396 | qApp->processEvents(); |
397 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 397 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
398 | changed = true; | 398 | changed = true; |
399 | mPrefs->mPassiveSyncPw = lepw.text(); | 399 | mPrefs->mPassiveSyncPw = lepw.text(); |
400 | } | 400 | } |
401 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 401 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
402 | mPrefs->mPassiveSyncPort = lab.text(); | 402 | mPrefs->mPassiveSyncPort = lab.text(); |
403 | changed = true; | 403 | changed = true; |
404 | } | 404 | } |
405 | autoStart = autostart.isChecked(); | 405 | autoStart = autostart.isChecked(); |
406 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 406 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
407 | changed = true; | 407 | changed = true; |
408 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 408 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
409 | } | 409 | } |
410 | } | 410 | } |
411 | else | 411 | else |
412 | autoStart = mPrefs->mPassiveSyncAutoStart; | 412 | autoStart = mPrefs->mPassiveSyncAutoStart; |
413 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 413 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
414 | changed = true; | 414 | changed = true; |
415 | bool ok; | 415 | bool ok; |
416 | mPrefs->mPassiveSyncAutoStart = false; | 416 | mPrefs->mPassiveSyncAutoStart = false; |
417 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 417 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
418 | if ( ! ok ) { | 418 | if ( ! ok ) { |
419 | KMessageBox::information( 0, i18n("No valid port")); | 419 | KMessageBox::information( 0, i18n("No valid port")); |
420 | return; | 420 | return; |
421 | } | 421 | } |
422 | //qDebug("port %d ", port); | 422 | //qDebug("port %d ", port); |
423 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 423 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
424 | mServerSocket->setFileName( defaultFileName() );//bbb | 424 | mServerSocket->setFileName( defaultFileName() );//bbb |
425 | if ( !mServerSocket->ok() ) { | 425 | if ( !mServerSocket->ok() ) { |
426 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 426 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
427 | delete mServerSocket; | 427 | delete mServerSocket; |
428 | mServerSocket = 0; | 428 | mServerSocket = 0; |
429 | return; | 429 | return; |
430 | } | 430 | } |
431 | mPrefs->mPassiveSyncAutoStart = autoStart; | 431 | mPrefs->mPassiveSyncAutoStart = autoStart; |
432 | if ( changed ) { | 432 | if ( changed ) { |
433 | mPrefs->writeConfig(); | 433 | mPrefs->writeConfig(); |
434 | } | 434 | } |
435 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 435 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
436 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 436 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
437 | } | 437 | } |
438 | 438 | ||
439 | void KSyncManager::syncLocalFile() | 439 | void KSyncManager::syncLocalFile() |
440 | { | 440 | { |
441 | 441 | ||
442 | QString fn =mPrefs->mLastSyncedLocalFile; | 442 | QString fn =mPrefs->mLastSyncedLocalFile; |
443 | QString ext; | 443 | QString ext; |
444 | 444 | ||
445 | switch(mTargetApp) | 445 | switch(mTargetApp) |
446 | { | 446 | { |
447 | case (KAPI): | 447 | case (KAPI): |
448 | ext = "(*.vcf)"; | 448 | ext = "(*.vcf)"; |
449 | break; | 449 | break; |
450 | case (KOPI): | 450 | case (KOPI): |
451 | ext = "(*.ics/*.vcs)"; | 451 | ext = "(*.ics/*.vcs)"; |
452 | break; | 452 | break; |
453 | case (PWMPI): | 453 | case (PWMPI): |
454 | ext = "(*.pwm)"; | 454 | ext = "(*.pwm)"; |
455 | break; | 455 | break; |
456 | default: | 456 | default: |
457 | qDebug("KSM::syncLocalFile: invalid apptype selected"); | 457 | qDebug("KSM::syncLocalFile: invalid apptype selected"); |
458 | break; | 458 | break; |
459 | 459 | ||
460 | } | 460 | } |
461 | 461 | ||
462 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 462 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
463 | if ( fn == "" ) | 463 | if ( fn == "" ) |
464 | return; | 464 | return; |
465 | if ( syncWithFile( fn, false ) ) { | 465 | if ( syncWithFile( fn, false ) ) { |
466 | qDebug("KSM::syncLocalFile() successful "); | 466 | qDebug("KSM::syncLocalFile() successful "); |
467 | } | 467 | } |
468 | 468 | ||
469 | } | 469 | } |
470 | 470 | ||
471 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 471 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
472 | { | 472 | { |
473 | bool ret = false; | 473 | bool ret = false; |
474 | QFileInfo info; | 474 | QFileInfo info; |
475 | info.setFile( fn ); | 475 | info.setFile( fn ); |
476 | QString mess; | 476 | QString mess; |
477 | if ( !info. exists() ) { | 477 | if ( !info. exists() ) { |
478 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 478 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
479 | QMessageBox::warning( mParent, i18n("Warning!"), | 479 | QMessageBox::warning( mParent, i18n("Warning!"), |
480 | mess ); | 480 | mess ); |
481 | return ret; | 481 | return ret; |
482 | } | 482 | } |
483 | int result = 0; | 483 | int result = 0; |
484 | if ( !quick ) { | 484 | if ( !quick ) { |
485 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 485 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
486 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 486 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
487 | mess, | 487 | mess, |
488 | i18n("Sync"), i18n("Cancel"), 0, | 488 | i18n("Sync"), i18n("Cancel"), 0, |
489 | 0, 1 ); | 489 | 0, 1 ); |
490 | if ( result ) | 490 | if ( result ) |
491 | return false; | 491 | return false; |
492 | } | 492 | } |
493 | if ( mAskForPreferences ) | 493 | if ( mAskForPreferences ) |
494 | if ( !edit_sync_options()) { | 494 | if ( !edit_sync_options()) { |
495 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 495 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
496 | return false; | 496 | return false; |
497 | } | 497 | } |
498 | if ( result == 0 ) { | 498 | if ( result == 0 ) { |
499 | //qDebug("Now sycing ... "); | 499 | //qDebug("Now sycing ... "); |
500 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 500 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
501 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 501 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
502 | else | 502 | else |
503 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 503 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
504 | if ( ! quick ) | 504 | if ( ! quick ) |
505 | mPrefs->mLastSyncedLocalFile = fn; | 505 | mPrefs->mLastSyncedLocalFile = fn; |
506 | } | 506 | } |
507 | return ret; | 507 | return ret; |
508 | } | 508 | } |
509 | 509 | ||
510 | void KSyncManager::quickSyncLocalFile() | 510 | void KSyncManager::quickSyncLocalFile() |
511 | { | 511 | { |
512 | 512 | ||
513 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 513 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
514 | qDebug("KSM::quick syncLocalFile() successful "); | 514 | qDebug("KSM::quick syncLocalFile() successful "); |
515 | 515 | ||
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | void KSyncManager::multiSync( bool askforPrefs ) | 519 | void KSyncManager::multiSync( bool askforPrefs ) |
520 | { | 520 | { |
521 | if (blockSave()) | 521 | if (blockSave()) |
522 | return; | 522 | return; |
523 | setBlockSave(true); | 523 | setBlockSave(true); |
524 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 524 | if ( askforPrefs ) { |
525 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 525 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
526 | question, | 526 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
527 | i18n("Yes"), i18n("No"), | 527 | question, |
528 | 0, 0 ) != 0 ) { | 528 | i18n("Yes"), i18n("No"), |
529 | setBlockSave(false); | 529 | 0, 0 ) != 0 ) { |
530 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 530 | setBlockSave(false); |
531 | return; | 531 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
532 | return; | ||
533 | } | ||
532 | } | 534 | } |
533 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 535 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
534 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 536 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
535 | if ( askforPrefs ) { | 537 | if ( askforPrefs ) { |
536 | if ( !edit_sync_options()) { | 538 | if ( !edit_sync_options()) { |
537 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); | 539 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); |
538 | return; | 540 | return; |
539 | } | 541 | } |
540 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 542 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
541 | } | 543 | } |
542 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 544 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
543 | qApp->processEvents(); | 545 | qApp->processEvents(); |
544 | int num = ringSync() ; | 546 | int num = ringSync() ; |
545 | if ( num > 1 ) | 547 | if ( num > 1 ) |
546 | ringSync(); | 548 | ringSync(); |
547 | setBlockSave(false); | 549 | setBlockSave(false); |
548 | if ( num ) | 550 | if ( num ) |
549 | emit save(); | 551 | emit save(); |
550 | if ( num ) | 552 | if ( num ) |
551 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 553 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
552 | else | 554 | else |
553 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 555 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
554 | return; | 556 | return; |
555 | } | 557 | } |
556 | 558 | ||
557 | int KSyncManager::ringSync() | 559 | int KSyncManager::ringSync() |
558 | { | 560 | { |
559 | 561 | ||
560 | int syncedProfiles = 0; | 562 | int syncedProfiles = 0; |
561 | unsigned int i; | 563 | unsigned int i; |
562 | QTime timer; | 564 | QTime timer; |
563 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 565 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
564 | QStringList syncProfileNames = mSyncProfileNames; | 566 | QStringList syncProfileNames = mSyncProfileNames; |
565 | KSyncProfile* temp = new KSyncProfile (); | 567 | KSyncProfile* temp = new KSyncProfile (); |
566 | mAskForPreferences = false; | 568 | mAskForPreferences = false; |
567 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 569 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
568 | mCurrentSyncProfile = i; | 570 | mCurrentSyncProfile = i; |
569 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 571 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
570 | temp->readConfig(&config); | 572 | temp->readConfig(&config); |
571 | 573 | ||
572 | bool includeInRingSync = false; | 574 | bool includeInRingSync = false; |
573 | switch(mTargetApp) | 575 | switch(mTargetApp) |
574 | { | 576 | { |
575 | case (KAPI): | 577 | case (KAPI): |
576 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 578 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
577 | break; | 579 | break; |
578 | case (KOPI): | 580 | case (KOPI): |
579 | includeInRingSync = temp->getIncludeInRingSync(); | 581 | includeInRingSync = temp->getIncludeInRingSync(); |
580 | break; | 582 | break; |
581 | case (PWMPI): | 583 | case (PWMPI): |
582 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 584 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
583 | break; | 585 | break; |
584 | default: | 586 | default: |
585 | qDebug("KSM::ringSync: invalid apptype selected"); | 587 | qDebug("KSM::ringSync: invalid apptype selected"); |
586 | break; | 588 | break; |
587 | 589 | ||
588 | } | 590 | } |
589 | 591 | ||
590 | 592 | ||
591 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 593 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
592 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 594 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
593 | ++syncedProfiles; | 595 | ++syncedProfiles; |
594 | mSyncWithDesktop = false; | 596 | mSyncWithDesktop = false; |
595 | // mAskForPreferences = temp->getAskForPreferences(); | 597 | // mAskForPreferences = temp->getAskForPreferences(); |
596 | mWriteBackFile = temp->getWriteBackFile(); | 598 | mWriteBackFile = temp->getWriteBackFile(); |
597 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 599 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
598 | mIsKapiFile = temp->getIsKapiFile(); | 600 | mIsKapiFile = temp->getIsKapiFile(); |
599 | mWriteBackInFuture = 0; | 601 | mWriteBackInFuture = 0; |
600 | if ( temp->getWriteBackFuture() ) { | 602 | if ( temp->getWriteBackFuture() ) { |
601 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 603 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
602 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); | 604 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); |
603 | } | 605 | } |
604 | mFilterInCal = temp->getFilterInCal(); | 606 | mFilterInCal = temp->getFilterInCal(); |
605 | mFilterOutCal = temp->getFilterOutCal(); | 607 | mFilterOutCal = temp->getFilterOutCal(); |
606 | mFilterInAB = temp->getFilterInAB(); | 608 | mFilterInAB = temp->getFilterInAB(); |
607 | mFilterOutAB = temp->getFilterOutAB(); | 609 | mFilterOutAB = temp->getFilterOutAB(); |
608 | mShowSyncSummary = false; | 610 | mShowSyncSummary = false; |
609 | mCurrentSyncDevice = syncProfileNames[i] ; | 611 | mCurrentSyncDevice = syncProfileNames[i] ; |
610 | mCurrentSyncName = mLocalMachineName; | 612 | mCurrentSyncName = mLocalMachineName; |
611 | if ( i == 0 ) { | 613 | if ( i == 0 ) { |
612 | mIsKapiFile = false; | 614 | mIsKapiFile = false; |
613 | #ifdef DESKTOP_VERSION | 615 | #ifdef DESKTOP_VERSION |
614 | syncKDE(); | 616 | syncKDE(); |
615 | #else | 617 | #else |
616 | syncSharp(); | 618 | syncSharp(); |
617 | #endif | 619 | #endif |
618 | } else { | 620 | } else { |
619 | if ( temp->getIsLocalFileSync() ) { | 621 | if ( temp->getIsLocalFileSync() ) { |
620 | switch(mTargetApp) | 622 | switch(mTargetApp) |
621 | { | 623 | { |
622 | case (KAPI): | 624 | case (KAPI): |
623 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 625 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
624 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 626 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
625 | break; | 627 | break; |
626 | case (KOPI): | 628 | case (KOPI): |
627 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 629 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
628 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 630 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
629 | break; | 631 | break; |
630 | case (PWMPI): | 632 | case (PWMPI): |
631 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 633 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
632 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 634 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
633 | break; | 635 | break; |
634 | default: | 636 | default: |
635 | qDebug("KSM: invalid apptype selected"); | 637 | qDebug("KSM: invalid apptype selected"); |
636 | break; | 638 | break; |
637 | } | 639 | } |
638 | } else { | 640 | } else { |
639 | if ( temp->getIsPhoneSync() ) { | 641 | if ( temp->getIsPhoneSync() ) { |
640 | mPhoneDevice = temp->getPhoneDevice( ) ; | 642 | mPhoneDevice = temp->getPhoneDevice( ) ; |
641 | mPhoneConnection = temp->getPhoneConnection( ); | 643 | mPhoneConnection = temp->getPhoneConnection( ); |
642 | mPhoneModel = temp->getPhoneModel( ); | 644 | mPhoneModel = temp->getPhoneModel( ); |
643 | syncPhone(); | 645 | syncPhone(); |
644 | } else if ( temp->getIsPiSync() ) { | 646 | } else if ( temp->getIsPiSync() ) { |
645 | if ( mTargetApp == KAPI ) { | 647 | if ( mTargetApp == KAPI ) { |
646 | mPassWordPiSync = temp->getRemotePwAB(); | 648 | mPassWordPiSync = temp->getRemotePwAB(); |
647 | mActiveSyncPort = temp->getRemotePortAB(); | 649 | mActiveSyncPort = temp->getRemotePortAB(); |
648 | mActiveSyncIP = temp->getRemoteIPAB(); | 650 | mActiveSyncIP = temp->getRemoteIPAB(); |
649 | } else if ( mTargetApp == KOPI ) { | 651 | } else if ( mTargetApp == KOPI ) { |
650 | mPassWordPiSync = temp->getRemotePw(); | 652 | mPassWordPiSync = temp->getRemotePw(); |
651 | mActiveSyncPort = temp->getRemotePort(); | 653 | mActiveSyncPort = temp->getRemotePort(); |
652 | mActiveSyncIP = temp->getRemoteIP(); | 654 | mActiveSyncIP = temp->getRemoteIP(); |
653 | } else { | 655 | } else { |
654 | mPassWordPiSync = temp->getRemotePwPWM(); | 656 | mPassWordPiSync = temp->getRemotePwPWM(); |
655 | mActiveSyncPort = temp->getRemotePortPWM(); | 657 | mActiveSyncPort = temp->getRemotePortPWM(); |
656 | mActiveSyncIP = temp->getRemoteIPPWM(); | 658 | mActiveSyncIP = temp->getRemoteIPPWM(); |
657 | } | 659 | } |
658 | syncPi(); | 660 | syncPi(); |
659 | while ( !mPisyncFinished ) { | 661 | while ( !mPisyncFinished ) { |
660 | //qDebug("waiting "); | 662 | //qDebug("waiting "); |
661 | qApp->processEvents(); | 663 | qApp->processEvents(); |
662 | } | 664 | } |
663 | timer.start(); | 665 | timer.start(); |
664 | while ( timer.elapsed () < 2000 ) { | 666 | while ( timer.elapsed () < 2000 ) { |
665 | qApp->processEvents(); | 667 | qApp->processEvents(); |
666 | } | 668 | } |
667 | } else | 669 | } else |
668 | syncRemote( temp, false ); | 670 | syncRemote( temp, false ); |
669 | 671 | ||
670 | } | 672 | } |
671 | } | 673 | } |
672 | timer.start(); | 674 | timer.start(); |
673 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 675 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
674 | while ( timer.elapsed () < 2000 ) { | 676 | while ( timer.elapsed () < 2000 ) { |
675 | qApp->processEvents(); | 677 | qApp->processEvents(); |
676 | #ifndef _WIN32_ | 678 | #ifndef _WIN32_ |
677 | sleep (1); | 679 | sleep (1); |
678 | #endif | 680 | #endif |
679 | } | 681 | } |
680 | 682 | ||
681 | } | 683 | } |
682 | 684 | ||
683 | } | 685 | } |
684 | delete temp; | 686 | delete temp; |
685 | return syncedProfiles; | 687 | return syncedProfiles; |
686 | } | 688 | } |
687 | 689 | ||
688 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 690 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
689 | { | 691 | { |
690 | QString question; | 692 | QString question; |
691 | if ( ask ) { | 693 | if ( ask ) { |
692 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 694 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
693 | if ( QMessageBox::information( mParent, i18n("Sync"), | 695 | if ( QMessageBox::information( mParent, i18n("Sync"), |
694 | question, | 696 | question, |
695 | i18n("Yes"), i18n("No"), | 697 | i18n("Yes"), i18n("No"), |
696 | 0, 0 ) != 0 ) | 698 | 0, 0 ) != 0 ) |
697 | return; | 699 | return; |
698 | } | 700 | } |
699 | 701 | ||
700 | QString preCommand; | 702 | QString preCommand; |
701 | QString localTempFile; | 703 | QString localTempFile; |
702 | QString postCommand; | 704 | QString postCommand; |
703 | 705 | ||
704 | switch(mTargetApp) | 706 | switch(mTargetApp) |
705 | { | 707 | { |
706 | case (KAPI): | 708 | case (KAPI): |
707 | preCommand = prof->getPreSyncCommandAB(); | 709 | preCommand = prof->getPreSyncCommandAB(); |
708 | postCommand = prof->getPostSyncCommandAB(); | 710 | postCommand = prof->getPostSyncCommandAB(); |
709 | localTempFile = prof->getLocalTempFileAB(); | 711 | localTempFile = prof->getLocalTempFileAB(); |
710 | break; | 712 | break; |
711 | case (KOPI): | 713 | case (KOPI): |
712 | preCommand = prof->getPreSyncCommand(); | 714 | preCommand = prof->getPreSyncCommand(); |
713 | postCommand = prof->getPostSyncCommand(); | 715 | postCommand = prof->getPostSyncCommand(); |
714 | localTempFile = prof->getLocalTempFile(); | 716 | localTempFile = prof->getLocalTempFile(); |
715 | break; | 717 | break; |
716 | case (PWMPI): | 718 | case (PWMPI): |
717 | preCommand = prof->getPreSyncCommandPWM(); | 719 | preCommand = prof->getPreSyncCommandPWM(); |
718 | postCommand = prof->getPostSyncCommandPWM(); | 720 | postCommand = prof->getPostSyncCommandPWM(); |
719 | localTempFile = prof->getLocalTempFilePWM(); | 721 | localTempFile = prof->getLocalTempFilePWM(); |
720 | break; | 722 | break; |
721 | default: | 723 | default: |
722 | qDebug("KSM::syncRemote: invalid apptype selected"); | 724 | qDebug("KSM::syncRemote: invalid apptype selected"); |
723 | break; | 725 | break; |
724 | } | 726 | } |
725 | 727 | ||
726 | 728 | ||
727 | int fi; | 729 | int fi; |
728 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 730 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
729 | QString pwd = getPassword(); | 731 | QString pwd = getPassword(); |
730 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 732 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
731 | 733 | ||
732 | } | 734 | } |
733 | int maxlen = 30; | 735 | int maxlen = 30; |
734 | if ( QApplication::desktop()->width() > 320 ) | 736 | if ( QApplication::desktop()->width() > 320 ) |
735 | maxlen += 25; | 737 | maxlen += 25; |
736 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 738 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
737 | int fileSize = 0; | 739 | int fileSize = 0; |
738 | int result = system ( preCommand ); | 740 | int result = system ( preCommand ); |
739 | // 0 : okay | 741 | // 0 : okay |
740 | // 256: no such file or dir | 742 | // 256: no such file or dir |
741 | // | 743 | // |
742 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); | 744 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); |
743 | if ( result != 0 ) { | 745 | if ( result != 0 ) { |
744 | unsigned int len = maxlen; | 746 | unsigned int len = maxlen; |
745 | while ( len < preCommand.length() ) { | 747 | while ( len < preCommand.length() ) { |
746 | preCommand.insert( len , "\n" ); | 748 | preCommand.insert( len , "\n" ); |
747 | len += maxlen +2; | 749 | len += maxlen +2; |
748 | } | 750 | } |
749 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; | 751 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; |
750 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 752 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
751 | question, | 753 | question, |
752 | i18n("Okay!")) ; | 754 | i18n("Okay!")) ; |
753 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 755 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
754 | return; | 756 | return; |
755 | } | 757 | } |
756 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 758 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
757 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 759 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
758 | 760 | ||
759 | if ( syncWithFile( localTempFile, true ) ) { | 761 | if ( syncWithFile( localTempFile, true ) ) { |
760 | 762 | ||
761 | if ( mWriteBackFile ) { | 763 | if ( mWriteBackFile ) { |
762 | int fi; | 764 | int fi; |
763 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 765 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
764 | QString pwd = getPassword(); | 766 | QString pwd = getPassword(); |
765 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 767 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
766 | 768 | ||
767 | } | 769 | } |
768 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 770 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
769 | result = system ( postCommand ); | 771 | result = system ( postCommand ); |
770 | qDebug("KSM::Sync:Writing back file result: %d ", result); | 772 | qDebug("KSM::Sync:Writing back file result: %d ", result); |
771 | if ( result != 0 ) { | 773 | if ( result != 0 ) { |
772 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 774 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
773 | return; | 775 | return; |
774 | } else { | 776 | } else { |
775 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 777 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
776 | } | 778 | } |
777 | } | 779 | } |
778 | } | 780 | } |
779 | return; | 781 | return; |
780 | } | 782 | } |
781 | bool KSyncManager::edit_pisync_options() | 783 | bool KSyncManager::edit_pisync_options() |
782 | { | 784 | { |
783 | QDialog dia( mParent, "dia", true ); | 785 | QDialog dia( mParent, "dia", true ); |
784 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 786 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
785 | QVBoxLayout lay ( &dia ); | 787 | QVBoxLayout lay ( &dia ); |
786 | lay.setSpacing( 5 ); | 788 | lay.setSpacing( 5 ); |
787 | lay.setMargin( 3 ); | 789 | lay.setMargin( 3 ); |
788 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 790 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
789 | lay.addWidget( &lab1 ); | 791 | lay.addWidget( &lab1 ); |
790 | QLineEdit le1 (&dia ); | 792 | QLineEdit le1 (&dia ); |
791 | lay.addWidget( &le1 ); | 793 | lay.addWidget( &le1 ); |
792 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 794 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
793 | lay.addWidget( &lab2 ); | 795 | lay.addWidget( &lab2 ); |
794 | QLineEdit le2 (&dia ); | 796 | QLineEdit le2 (&dia ); |
795 | lay.addWidget( &le2 ); | 797 | lay.addWidget( &le2 ); |
796 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 798 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
797 | lay.addWidget( &lab3 ); | 799 | lay.addWidget( &lab3 ); |
798 | QLineEdit le3 (&dia ); | 800 | QLineEdit le3 (&dia ); |
799 | lay.addWidget( &le3 ); | 801 | lay.addWidget( &le3 ); |
800 | QPushButton pb ( "OK", &dia); | 802 | QPushButton pb ( "OK", &dia); |
801 | lay.addWidget( &pb ); | 803 | lay.addWidget( &pb ); |
802 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 804 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
803 | le1.setText( mPassWordPiSync ); | 805 | le1.setText( mPassWordPiSync ); |
804 | le2.setText( mActiveSyncIP ); | 806 | le2.setText( mActiveSyncIP ); |
805 | le3.setText( mActiveSyncPort ); | 807 | le3.setText( mActiveSyncPort ); |
806 | if ( dia.exec() ) { | 808 | if ( dia.exec() ) { |
807 | mPassWordPiSync = le1.text(); | 809 | mPassWordPiSync = le1.text(); |
808 | mActiveSyncPort = le3.text(); | 810 | mActiveSyncPort = le3.text(); |
809 | mActiveSyncIP = le2.text(); | 811 | mActiveSyncIP = le2.text(); |
810 | return true; | 812 | return true; |
811 | } | 813 | } |
812 | return false; | 814 | return false; |
813 | } | 815 | } |
814 | bool KSyncManager::edit_sync_options() | 816 | bool KSyncManager::edit_sync_options() |
815 | { | 817 | { |
816 | 818 | ||
817 | QDialog dia( mParent, "dia", true ); | 819 | QDialog dia( mParent, "dia", true ); |
818 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 820 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
819 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 821 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
820 | QVBoxLayout lay ( &dia ); | 822 | QVBoxLayout lay ( &dia ); |
821 | lay.setSpacing( 2 ); | 823 | lay.setSpacing( 2 ); |
822 | lay.setMargin( 3 ); | 824 | lay.setMargin( 3 ); |
823 | lay.addWidget(&gr); | 825 | lay.addWidget(&gr); |
824 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 826 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
825 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 827 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
826 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 828 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
827 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 829 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
828 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 830 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
829 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 831 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
830 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 832 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
831 | QPushButton pb ( "OK", &dia); | 833 | QPushButton pb ( "OK", &dia); |
832 | lay.addWidget( &pb ); | 834 | lay.addWidget( &pb ); |
833 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 835 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
834 | switch ( mSyncAlgoPrefs ) { | 836 | switch ( mSyncAlgoPrefs ) { |
835 | case 0: | 837 | case 0: |
836 | loc.setChecked( true); | 838 | loc.setChecked( true); |
837 | break; | 839 | break; |
838 | case 1: | 840 | case 1: |
839 | rem.setChecked( true ); | 841 | rem.setChecked( true ); |
840 | break; | 842 | break; |
841 | case 2: | 843 | case 2: |
842 | newest.setChecked( true); | 844 | newest.setChecked( true); |
843 | break; | 845 | break; |
844 | case 3: | 846 | case 3: |
845 | ask.setChecked( true); | 847 | ask.setChecked( true); |
846 | break; | 848 | break; |
847 | case 4: | 849 | case 4: |
848 | f_loc.setChecked( true); | 850 | f_loc.setChecked( true); |
849 | break; | 851 | break; |
850 | case 5: | 852 | case 5: |
851 | f_rem.setChecked( true); | 853 | f_rem.setChecked( true); |
852 | break; | 854 | break; |
853 | case 6: | 855 | case 6: |
854 | // both.setChecked( true); | 856 | // both.setChecked( true); |
855 | break; | 857 | break; |
856 | default: | 858 | default: |
857 | break; | 859 | break; |
858 | } | 860 | } |
859 | if ( dia.exec() ) { | 861 | if ( dia.exec() ) { |
860 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 862 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
861 | return true; | 863 | return true; |
862 | } | 864 | } |
863 | return false; | 865 | return false; |
864 | } | 866 | } |
865 | 867 | ||
866 | QString KSyncManager::getPassword( ) | 868 | QString KSyncManager::getPassword( ) |
867 | { | 869 | { |
868 | QString retfile = ""; | 870 | QString retfile = ""; |
869 | QDialog dia ( mParent, "input-dialog", true ); | 871 | QDialog dia ( mParent, "input-dialog", true ); |
870 | QLineEdit lab ( &dia ); | 872 | QLineEdit lab ( &dia ); |
871 | lab.setEchoMode( QLineEdit::Password ); | 873 | lab.setEchoMode( QLineEdit::Password ); |
872 | QVBoxLayout lay( &dia ); | 874 | QVBoxLayout lay( &dia ); |
873 | lay.setMargin(7); | 875 | lay.setMargin(7); |
874 | lay.setSpacing(7); | 876 | lay.setSpacing(7); |
875 | lay.addWidget( &lab); | 877 | lay.addWidget( &lab); |
876 | dia.setFixedSize( 230,50 ); | 878 | dia.setFixedSize( 230,50 ); |
877 | dia.setCaption( i18n("Enter password") ); | 879 | dia.setCaption( i18n("Enter password") ); |
878 | QPushButton pb ( "OK", &dia); | 880 | QPushButton pb ( "OK", &dia); |
879 | lay.addWidget( &pb ); | 881 | lay.addWidget( &pb ); |
880 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 882 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
881 | dia.show(); | 883 | dia.show(); |
882 | int res = dia.exec(); | 884 | int res = dia.exec(); |
883 | if ( res ) | 885 | if ( res ) |
884 | retfile = lab.text(); | 886 | retfile = lab.text(); |
885 | dia.hide(); | 887 | dia.hide(); |
886 | qApp->processEvents(); | 888 | qApp->processEvents(); |
887 | return retfile; | 889 | return retfile; |
888 | 890 | ||
889 | } | 891 | } |
890 | 892 | ||
891 | 893 | ||
892 | void KSyncManager::confSync() | 894 | void KSyncManager::confSync() |
893 | { | 895 | { |
894 | static KSyncPrefsDialog* sp = 0; | 896 | static KSyncPrefsDialog* sp = 0; |
895 | if ( ! sp ) { | 897 | if ( ! sp ) { |
896 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 898 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
897 | } | 899 | } |
898 | sp->usrReadConfig(); | 900 | sp->usrReadConfig(); |
899 | #ifndef DESKTOP_VERSION | 901 | #ifndef DESKTOP_VERSION |
900 | sp->showMaximized(); | 902 | sp->showMaximized(); |
901 | #else | 903 | #else |
902 | sp->show(); | 904 | sp->show(); |
903 | #endif | 905 | #endif |
904 | sp->exec(); | 906 | sp->exec(); |
905 | QStringList oldSyncProfileNames = mSyncProfileNames; | 907 | QStringList oldSyncProfileNames = mSyncProfileNames; |
906 | mSyncProfileNames = sp->getSyncProfileNames(); | 908 | mSyncProfileNames = sp->getSyncProfileNames(); |
907 | mLocalMachineName = sp->getLocalMachineName (); | 909 | mLocalMachineName = sp->getLocalMachineName (); |
908 | int ii; | 910 | int ii; |
909 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 911 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
910 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 912 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
911 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 913 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
912 | } | 914 | } |
913 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 915 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
914 | } | 916 | } |
915 | void KSyncManager::syncKDE() | 917 | void KSyncManager::syncKDE() |
916 | { | 918 | { |
917 | mSyncWithDesktop = true; | 919 | mSyncWithDesktop = true; |
918 | emit save(); | 920 | emit save(); |
919 | switch(mTargetApp) | 921 | switch(mTargetApp) |
920 | { | 922 | { |
921 | case (KAPI): | 923 | case (KAPI): |
922 | { | 924 | { |
923 | #ifdef DESKTOP_VERSION | 925 | #ifdef DESKTOP_VERSION |
924 | QString command = "kdeabdump33"; | 926 | QString command = "kdeabdump33"; |
925 | QString commandfile = "kdeabdump33"; | 927 | QString commandfile = "kdeabdump33"; |
926 | QString commandpath = qApp->applicationDirPath () + "/"; | 928 | QString commandpath = qApp->applicationDirPath () + "/"; |
927 | #else | 929 | #else |
928 | QString command = "kdeabdump33"; | 930 | QString command = "kdeabdump33"; |
929 | QString commandfile = "kdeabdump33"; | 931 | QString commandfile = "kdeabdump33"; |
930 | QString commandpath = QDir::homeDirPath ()+"/"; | 932 | QString commandpath = QDir::homeDirPath ()+"/"; |
931 | #endif | 933 | #endif |
932 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 934 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
933 | command = commandfile; | 935 | command = commandfile; |
934 | else | 936 | else |
935 | command = commandpath+commandfile; | 937 | command = commandpath+commandfile; |
936 | 938 | ||
937 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 939 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
938 | int result = system ( command.latin1()); | 940 | int result = system ( command.latin1()); |
939 | qDebug("AB dump 33 command call result: %d ", result); | 941 | qDebug("AB dump 33 command call result: %d ", result); |
940 | if ( result != 0 ) { | 942 | if ( result != 0 ) { |
941 | qDebug("Calling AB dump version 33 failed. Trying 34... "); | 943 | qDebug("Calling AB dump version 33 failed. Trying 34... "); |
942 | commandfile = "kdeabdump34"; | 944 | commandfile = "kdeabdump34"; |
943 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 945 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
944 | command = commandfile; | 946 | command = commandfile; |
945 | else | 947 | else |
946 | command = commandpath+commandfile; | 948 | command = commandpath+commandfile; |
947 | result = system ( command.latin1()); | 949 | result = system ( command.latin1()); |
948 | qDebug("AB dump 34 command call result: %d ", result); | 950 | qDebug("AB dump 34 command call result: %d ", result); |
949 | if ( result != 0 ) { | 951 | if ( result != 0 ) { |
950 | KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); | 952 | KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); |
951 | return; | 953 | return; |
952 | } | 954 | } |
953 | } | 955 | } |
954 | if ( syncWithFile( fileName,true ) ) { | 956 | if ( syncWithFile( fileName,true ) ) { |
955 | if ( mWriteBackFile ) { | 957 | if ( mWriteBackFile ) { |
956 | command += " --read"; | 958 | command += " --read"; |
957 | system ( command.latin1()); | 959 | system ( command.latin1()); |
958 | } | 960 | } |
959 | } | 961 | } |
960 | 962 | ||
961 | } | 963 | } |
962 | break; | 964 | break; |
963 | case (KOPI): | 965 | case (KOPI): |
964 | { | 966 | { |
965 | #ifdef DESKTOP_VERSION | 967 | #ifdef DESKTOP_VERSION |
966 | QString command = "kdecaldump33"; | 968 | QString command = "kdecaldump33"; |
967 | QString commandfile = "kdecaldump33"; | 969 | QString commandfile = "kdecaldump33"; |
968 | QString commandpath = qApp->applicationDirPath () + "/"; | 970 | QString commandpath = qApp->applicationDirPath () + "/"; |
969 | #else | 971 | #else |
970 | QString command = "kdecaldump33"; | 972 | QString command = "kdecaldump33"; |
971 | QString commandfile = "kdecaldump33"; | 973 | QString commandfile = "kdecaldump33"; |
972 | QString commandpath = QDir::homeDirPath ()+"/"; | 974 | QString commandpath = QDir::homeDirPath ()+"/"; |
973 | #endif | 975 | #endif |
974 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 976 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
975 | command = commandfile; | 977 | command = commandfile; |
976 | else | 978 | else |
977 | command = commandpath+commandfile; | 979 | command = commandpath+commandfile; |
978 | 980 | ||
979 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 981 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
980 | int result = system ( command.latin1()); | 982 | int result = system ( command.latin1()); |
981 | qDebug("Cal dump 33 command call result result: %d ", result); | 983 | qDebug("Cal dump 33 command call result result: %d ", result); |
982 | if ( result != 0 ) { | 984 | if ( result != 0 ) { |
983 | qDebug("Calling CAL dump version 33 failed. Trying 34... "); | 985 | qDebug("Calling CAL dump version 33 failed. Trying 34... "); |
984 | commandfile = "kdecaldump34"; | 986 | commandfile = "kdecaldump34"; |
985 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 987 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
986 | command = commandfile; | 988 | command = commandfile; |
987 | else | 989 | else |
988 | command = commandpath+commandfile; | 990 | command = commandpath+commandfile; |
989 | result = system ( command.latin1()); | 991 | result = system ( command.latin1()); |
990 | qDebug("Cal dump 34 command call result result: %d ", result); | 992 | qDebug("Cal dump 34 command call result result: %d ", result); |
991 | if ( result != 0 ) { | 993 | if ( result != 0 ) { |
992 | KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); | 994 | KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); |
993 | return; | 995 | return; |
994 | } | 996 | } |
995 | } | 997 | } |
996 | if ( syncWithFile( fileName,true ) ) { | 998 | if ( syncWithFile( fileName,true ) ) { |
997 | if ( mWriteBackFile ) { | 999 | if ( mWriteBackFile ) { |
998 | command += " --read"; | 1000 | command += " --read"; |
999 | system ( command.latin1()); | 1001 | system ( command.latin1()); |
1000 | } | 1002 | } |
1001 | } | 1003 | } |
1002 | 1004 | ||
1003 | } | 1005 | } |
1004 | break; | 1006 | break; |
1005 | case (PWMPI): | 1007 | case (PWMPI): |
1006 | 1008 | ||
1007 | break; | 1009 | break; |
1008 | default: | 1010 | default: |
1009 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 1011 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
1010 | break; | 1012 | break; |
1011 | 1013 | ||
1012 | } | 1014 | } |
1013 | } | 1015 | } |
1014 | 1016 | ||
1015 | void KSyncManager::syncSharp() | 1017 | void KSyncManager::syncSharp() |
1016 | { | 1018 | { |
1017 | 1019 | ||
1018 | if ( ! syncExternalApplication("sharp") ) | 1020 | if ( ! syncExternalApplication("sharp") ) |
1019 | qDebug("KSM::ERROR sync sharp "); | 1021 | qDebug("KSM::ERROR sync sharp "); |
1020 | } | 1022 | } |
1021 | 1023 | ||
1022 | bool KSyncManager::syncExternalApplication(QString resource) | 1024 | bool KSyncManager::syncExternalApplication(QString resource) |
1023 | { | 1025 | { |
1024 | 1026 | ||
1025 | emit save(); | 1027 | emit save(); |
1026 | 1028 | ||
1027 | if ( mAskForPreferences ) | 1029 | if ( mAskForPreferences ) |
1028 | if ( !edit_sync_options()) { | 1030 | if ( !edit_sync_options()) { |
1029 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1031 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1030 | return false; | 1032 | return false; |
1031 | } | 1033 | } |
1032 | 1034 | ||
1033 | qDebug("KSM::Sync extern %s", resource.latin1()); | 1035 | qDebug("KSM::Sync extern %s", resource.latin1()); |
1034 | 1036 | ||
1035 | bool syncOK = mImplementation->syncExternal(this, resource); | 1037 | bool syncOK = mImplementation->syncExternal(this, resource); |
1036 | 1038 | ||
1037 | return syncOK; | 1039 | return syncOK; |
1038 | 1040 | ||
1039 | } | 1041 | } |
1040 | 1042 | ||
1041 | void KSyncManager::syncPhone() | 1043 | void KSyncManager::syncPhone() |
1042 | { | 1044 | { |
1043 | 1045 | ||
1044 | syncExternalApplication("phone"); | 1046 | syncExternalApplication("phone"); |
1045 | 1047 | ||
1046 | } | 1048 | } |
1047 | 1049 | ||
1048 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 1050 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
1049 | { | 1051 | { |
1050 | if (!bar->isVisible()) | 1052 | if (!bar->isVisible()) |
1051 | { | 1053 | { |
1052 | int w = 300; | 1054 | int w = 300; |
1053 | if ( QApplication::desktop()->width() < 320 ) | 1055 | if ( QApplication::desktop()->width() < 320 ) |
1054 | w = 220; | 1056 | w = 220; |
1055 | int h = bar->sizeHint().height() ; | 1057 | int h = bar->sizeHint().height() ; |
1056 | int dw = QApplication::desktop()->width(); | 1058 | int dw = QApplication::desktop()->width(); |
1057 | int dh = QApplication::desktop()->height(); | 1059 | int dh = QApplication::desktop()->height(); |
1058 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1060 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1059 | bar->setCaption (caption); | 1061 | bar->setCaption (caption); |
1060 | bar->setTotalSteps ( total ) ; | 1062 | bar->setTotalSteps ( total ) ; |
1061 | bar->show(); | 1063 | bar->show(); |
1062 | } | 1064 | } |
1063 | bar->raise(); | 1065 | bar->raise(); |
1064 | bar->setProgress( percentage ); | 1066 | bar->setProgress( percentage ); |
1065 | qApp->processEvents(); | 1067 | qApp->processEvents(); |
1066 | } | 1068 | } |
1067 | 1069 | ||
1068 | void KSyncManager::hideProgressBar() | 1070 | void KSyncManager::hideProgressBar() |
1069 | { | 1071 | { |
1070 | bar->hide(); | 1072 | bar->hide(); |
1071 | qApp->processEvents(); | 1073 | qApp->processEvents(); |
1072 | } | 1074 | } |
1073 | 1075 | ||
1074 | bool KSyncManager::isProgressBarCanceled() | 1076 | bool KSyncManager::isProgressBarCanceled() |
1075 | { | 1077 | { |
1076 | return !bar->isVisible(); | 1078 | return !bar->isVisible(); |
1077 | } | 1079 | } |
1078 | 1080 | ||
1079 | QString KSyncManager::syncFileName() | 1081 | QString KSyncManager::syncFileName() |
1080 | { | 1082 | { |
1081 | 1083 | ||
1082 | QString fn = "tempfile"; | 1084 | QString fn = "tempfile"; |
1083 | switch(mTargetApp) | 1085 | switch(mTargetApp) |
1084 | { | 1086 | { |
1085 | case (KAPI): | 1087 | case (KAPI): |
1086 | fn = "tempsyncab.vcf"; | 1088 | fn = "tempsyncab.vcf"; |
1087 | break; | 1089 | break; |
1088 | case (KOPI): | 1090 | case (KOPI): |
1089 | fn = "tempsynccal.ics"; | 1091 | fn = "tempsynccal.ics"; |
1090 | break; | 1092 | break; |
1091 | case (PWMPI): | 1093 | case (PWMPI): |
1092 | fn = "tempsyncpw.pwm"; | 1094 | fn = "tempsyncpw.pwm"; |
1093 | break; | 1095 | break; |
1094 | default: | 1096 | default: |
1095 | break; | 1097 | break; |
1096 | } | 1098 | } |
1097 | #ifdef _WIN32_ | 1099 | #ifdef _WIN32_ |
1098 | return locateLocal( "tmp", fn ); | 1100 | return locateLocal( "tmp", fn ); |
1099 | #else | 1101 | #else |
1100 | return (QString( "/tmp/" )+ fn ); | 1102 | return (QString( "/tmp/" )+ fn ); |
1101 | #endif | 1103 | #endif |
1102 | } | 1104 | } |
1103 | 1105 | ||
1104 | void KSyncManager::syncPi() | 1106 | void KSyncManager::syncPi() |
1105 | { | 1107 | { |
1106 | mIsKapiFile = true; | 1108 | mIsKapiFile = true; |
1107 | mPisyncFinished = false; | 1109 | mPisyncFinished = false; |
1108 | qApp->processEvents(); | 1110 | qApp->processEvents(); |
1109 | if ( mAskForPreferences ) | 1111 | if ( mAskForPreferences ) |
1110 | if ( !edit_pisync_options()) { | 1112 | if ( !edit_pisync_options()) { |
1111 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1113 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1112 | mPisyncFinished = true; | 1114 | mPisyncFinished = true; |
1113 | return; | 1115 | return; |
1114 | } | 1116 | } |
1115 | bool ok; | 1117 | bool ok; |
1116 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1118 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1117 | if ( ! ok ) { | 1119 | if ( ! ok ) { |
1118 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1120 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1119 | mPisyncFinished = true; | 1121 | mPisyncFinished = true; |
1120 | return; | 1122 | return; |
1121 | } | 1123 | } |
1122 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1124 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1123 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1125 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1124 | commandSocket->readFile( syncFileName() ); | 1126 | commandSocket->readFile( syncFileName() ); |
1125 | } | 1127 | } |
1126 | 1128 | ||
1127 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1129 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1128 | { | 1130 | { |
1129 | //enum { success, errorW, errorR, quiet }; | 1131 | //enum { success, errorW, errorR, quiet }; |
1130 | 1132 | ||
1131 | 1133 | ||
1132 | 1134 | ||
1133 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || | 1135 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || |
1134 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { | 1136 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { |
1135 | if ( state == KCommandSocket::errorPW ) | 1137 | if ( state == KCommandSocket::errorPW ) |
1136 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); | 1138 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); |
1137 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) | 1139 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) |
1138 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1140 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1139 | else if ( state == KCommandSocket::errorCA ) | 1141 | else if ( state == KCommandSocket::errorCA ) |
1140 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); | 1142 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); |
1141 | else if ( state == KCommandSocket::errorFI ) | 1143 | else if ( state == KCommandSocket::errorFI ) |
1142 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); | 1144 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); |
1143 | else if ( state == KCommandSocket::errorED ) | 1145 | else if ( state == KCommandSocket::errorED ) |
1144 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); | 1146 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); |
1145 | else if ( state == KCommandSocket::errorUN ) | 1147 | else if ( state == KCommandSocket::errorUN ) |
1146 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); | 1148 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); |
1147 | delete s; | 1149 | delete s; |
1148 | if ( state == KCommandSocket::errorR ) { | 1150 | if ( state == KCommandSocket::errorR ) { |
1149 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1151 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1150 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1152 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1151 | commandSocket->sendStop(); | 1153 | commandSocket->sendStop(); |
1152 | } | 1154 | } |
1153 | mPisyncFinished = true; | 1155 | mPisyncFinished = true; |
1154 | return; | 1156 | return; |
1155 | 1157 | ||
1156 | } else if ( state == KCommandSocket::errorW ) { | 1158 | } else if ( state == KCommandSocket::errorW ) { |
1157 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1159 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1158 | mPisyncFinished = true; | 1160 | mPisyncFinished = true; |
1159 | 1161 | ||
1160 | } else if ( state == KCommandSocket::successR ) { | 1162 | } else if ( state == KCommandSocket::successR ) { |
1161 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1163 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1162 | 1164 | ||
1163 | } else if ( state == KCommandSocket::successW ) { | 1165 | } else if ( state == KCommandSocket::successW ) { |
1164 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 1166 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
1165 | mPisyncFinished = true; | 1167 | mPisyncFinished = true; |
1166 | } else if ( state == KCommandSocket::quiet ){ | 1168 | } else if ( state == KCommandSocket::quiet ){ |
1167 | qDebug("KSS: quiet "); | 1169 | qDebug("KSS: quiet "); |
1168 | mPisyncFinished = true; | 1170 | mPisyncFinished = true; |
1169 | } else { | 1171 | } else { |
1170 | qDebug("KSS: Error: unknown state: %d ", state); | 1172 | qDebug("KSS: Error: unknown state: %d ", state); |
1171 | mPisyncFinished = true; | 1173 | mPisyncFinished = true; |
1172 | } | 1174 | } |
1173 | 1175 | ||
1174 | delete s; | 1176 | delete s; |
1175 | } | 1177 | } |
1176 | 1178 | ||
1177 | void KSyncManager::readFileFromSocket() | 1179 | void KSyncManager::readFileFromSocket() |
1178 | { | 1180 | { |
1179 | QString fileName = syncFileName(); | 1181 | QString fileName = syncFileName(); |
1180 | bool syncOK = true; | 1182 | bool syncOK = true; |
1181 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1183 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1182 | if ( ! syncWithFile( fileName , true ) ) { | 1184 | if ( ! syncWithFile( fileName , true ) ) { |
1183 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1185 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1184 | syncOK = false; | 1186 | syncOK = false; |
1185 | } | 1187 | } |
1186 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1188 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1187 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1189 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1188 | if ( mWriteBackFile && syncOK ) | 1190 | if ( mWriteBackFile && syncOK ) |
1189 | commandSocket->writeFile( fileName ); | 1191 | commandSocket->writeFile( fileName ); |
1190 | else { | 1192 | else { |
1191 | commandSocket->sendStop(); | 1193 | commandSocket->sendStop(); |
1192 | if ( syncOK ) | 1194 | if ( syncOK ) |
1193 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1195 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1194 | mPisyncFinished = true; | 1196 | mPisyncFinished = true; |
1195 | } | 1197 | } |
1196 | } | 1198 | } |
1197 | 1199 | ||
1198 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1200 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1199 | { | 1201 | { |
1200 | mPassWord = pw; | 1202 | mPassWord = pw; |
1201 | mSocket = 0; | 1203 | mSocket = 0; |
1202 | mSyncActionDialog = 0; | 1204 | mSyncActionDialog = 0; |
1203 | blockRC = false; | 1205 | blockRC = false; |
1204 | mErrorMessage = 0; | 1206 | mErrorMessage = 0; |
1205 | } | 1207 | } |
1206 | 1208 | ||
1207 | void KServerSocket::newConnection ( int socket ) | 1209 | void KServerSocket::newConnection ( int socket ) |
1208 | { | 1210 | { |
1209 | // qDebug("KServerSocket:New connection %d ", socket); | 1211 | // qDebug("KServerSocket:New connection %d ", socket); |
1210 | if ( mSocket ) { | 1212 | if ( mSocket ) { |
1211 | qDebug("KSS::newConnection Socket deleted! "); | 1213 | qDebug("KSS::newConnection Socket deleted! "); |
1212 | delete mSocket; | 1214 | delete mSocket; |
1213 | mSocket = 0; | 1215 | mSocket = 0; |
1214 | } | 1216 | } |
1215 | mSocket = new QSocket( this ); | 1217 | mSocket = new QSocket( this ); |
1216 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1218 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1217 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1219 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1218 | mSocket->setSocket( socket ); | 1220 | mSocket->setSocket( socket ); |
1219 | } | 1221 | } |
1220 | 1222 | ||
1221 | void KServerSocket::discardClient() | 1223 | void KServerSocket::discardClient() |
1222 | { | 1224 | { |
1223 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1225 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1224 | } | 1226 | } |
1225 | void KServerSocket::deleteSocket() | 1227 | void KServerSocket::deleteSocket() |
1226 | { | 1228 | { |
1227 | qDebug("KSS::deleteSocket"); | 1229 | qDebug("KSS::deleteSocket"); |
1228 | if ( mSocket ) { | 1230 | if ( mSocket ) { |
1229 | delete mSocket; | 1231 | delete mSocket; |
1230 | mSocket = 0; | 1232 | mSocket = 0; |
1231 | } | 1233 | } |
1232 | if ( mErrorMessage ) | 1234 | if ( mErrorMessage ) |
1233 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1235 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1234 | } | 1236 | } |
1235 | void KServerSocket::readClient() | 1237 | void KServerSocket::readClient() |
1236 | { | 1238 | { |
1237 | if ( blockRC ) | 1239 | if ( blockRC ) |
1238 | return; | 1240 | return; |
1239 | if ( mSocket == 0 ) { | 1241 | if ( mSocket == 0 ) { |
1240 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1242 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1241 | return; | 1243 | return; |
1242 | } | 1244 | } |
1243 | if ( mErrorMessage ) { | 1245 | if ( mErrorMessage ) { |
1244 | mErrorMessage = 999; | 1246 | mErrorMessage = 999; |
1245 | error_connect("ERROR_ED\r\n\r\n"); | 1247 | error_connect("ERROR_ED\r\n\r\n"); |
1246 | return; | 1248 | return; |
1247 | } | 1249 | } |
1248 | mErrorMessage = 0; | 1250 | mErrorMessage = 0; |
1249 | //qDebug("KServerSocket::readClient()"); | 1251 | //qDebug("KServerSocket::readClient()"); |
1250 | if ( mSocket->canReadLine() ) { | 1252 | if ( mSocket->canReadLine() ) { |
1251 | QString line = mSocket->readLine(); | 1253 | QString line = mSocket->readLine(); |
1252 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1254 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1253 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1255 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1254 | if ( tokens[0] == "GET" ) { | 1256 | if ( tokens[0] == "GET" ) { |
1255 | if ( tokens[1] == mPassWord ) { | 1257 | if ( tokens[1] == mPassWord ) { |
1256 | //emit sendFile( mSocket ); | 1258 | //emit sendFile( mSocket ); |
1257 | bool ok = false; | 1259 | bool ok = false; |
1258 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1260 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1259 | if ( ok ) { | 1261 | if ( ok ) { |
1260 | KSyncManager::mRequestedSyncEvent = dt; | 1262 | KSyncManager::mRequestedSyncEvent = dt; |
1261 | } | 1263 | } |
1262 | else | 1264 | else |
1263 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1265 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1264 | send_file(); | 1266 | send_file(); |
1265 | } | 1267 | } |
1266 | else { | 1268 | else { |
1267 | mErrorMessage = 1; | 1269 | mErrorMessage = 1; |
1268 | error_connect("ERROR_PW\r\n\r\n"); | 1270 | error_connect("ERROR_PW\r\n\r\n"); |
1269 | } | 1271 | } |
1270 | } | 1272 | } |
1271 | if ( tokens[0] == "PUT" ) { | 1273 | if ( tokens[0] == "PUT" ) { |
1272 | if ( tokens[1] == mPassWord ) { | 1274 | if ( tokens[1] == mPassWord ) { |
1273 | //emit getFile( mSocket ); | 1275 | //emit getFile( mSocket ); |
1274 | blockRC = true; | 1276 | blockRC = true; |
1275 | get_file(); | 1277 | get_file(); |
1276 | } | 1278 | } |
1277 | else { | 1279 | else { |
1278 | mErrorMessage = 2; | 1280 | mErrorMessage = 2; |
1279 | error_connect("ERROR_PW\r\n\r\n"); | 1281 | error_connect("ERROR_PW\r\n\r\n"); |
1280 | end_connect(); | 1282 | end_connect(); |
1281 | } | 1283 | } |
1282 | } | 1284 | } |
1283 | if ( tokens[0] == "STOP" ) { | 1285 | if ( tokens[0] == "STOP" ) { |
1284 | //emit endConnect(); | 1286 | //emit endConnect(); |
1285 | end_connect(); | 1287 | end_connect(); |
1286 | } | 1288 | } |
1287 | } | 1289 | } |
1288 | } | 1290 | } |
1289 | void KServerSocket::displayErrorMessage() | 1291 | void KServerSocket::displayErrorMessage() |
1290 | { | 1292 | { |
1291 | if ( mErrorMessage == 1 ) { | 1293 | if ( mErrorMessage == 1 ) { |
1292 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1294 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1293 | mErrorMessage = 0; | 1295 | mErrorMessage = 0; |
1294 | } | 1296 | } |
1295 | else if ( mErrorMessage == 2 ) { | 1297 | else if ( mErrorMessage == 2 ) { |
1296 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1298 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1297 | mErrorMessage = 0; | 1299 | mErrorMessage = 0; |
1298 | } | 1300 | } |
1299 | } | 1301 | } |
1300 | void KServerSocket::error_connect( QString errmess ) | 1302 | void KServerSocket::error_connect( QString errmess ) |
1301 | { | 1303 | { |
1302 | QTextStream os( mSocket ); | 1304 | QTextStream os( mSocket ); |
1303 | os.setEncoding( QTextStream::Latin1 ); | 1305 | os.setEncoding( QTextStream::Latin1 ); |
1304 | os << errmess ; | 1306 | os << errmess ; |
1305 | mSocket->close(); | 1307 | mSocket->close(); |
1306 | if ( mSocket->state() == QSocket::Idle ) { | 1308 | if ( mSocket->state() == QSocket::Idle ) { |
1307 | QTimer::singleShot( 0, this , SLOT ( discardClient())); | 1309 | QTimer::singleShot( 0, this , SLOT ( discardClient())); |
1308 | } | 1310 | } |
1309 | } | 1311 | } |
1310 | void KServerSocket::end_connect() | 1312 | void KServerSocket::end_connect() |
1311 | { | 1313 | { |
1312 | delete mSyncActionDialog; | 1314 | delete mSyncActionDialog; |
1313 | mSyncActionDialog = 0; | 1315 | mSyncActionDialog = 0; |
1314 | } | 1316 | } |
1315 | void KServerSocket::send_file() | 1317 | void KServerSocket::send_file() |
1316 | { | 1318 | { |
1317 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1319 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1318 | if ( mSyncActionDialog ) | 1320 | if ( mSyncActionDialog ) |
1319 | delete mSyncActionDialog; | 1321 | delete mSyncActionDialog; |
1320 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1322 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1321 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1323 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1322 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1324 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1323 | label->setAlignment ( Qt::AlignHCenter ); | 1325 | label->setAlignment ( Qt::AlignHCenter ); |
1324 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1326 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1325 | lay->addWidget( label); | 1327 | lay->addWidget( label); |
1326 | lay->setMargin(7); | 1328 | lay->setMargin(7); |
1327 | lay->setSpacing(7); | 1329 | lay->setSpacing(7); |
1328 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1330 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1329 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1331 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1330 | //secs = 333; | 1332 | //secs = 333; |
1331 | if ( secs < 0 ) | 1333 | if ( secs < 0 ) |
1332 | secs = secs * (-1); | 1334 | secs = secs * (-1); |
1333 | if ( secs > 30 ) | 1335 | if ( secs > 30 ) |
1334 | //if ( true ) | 1336 | //if ( true ) |
1335 | { | 1337 | { |
1336 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1338 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1337 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1339 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1338 | label->setAlignment ( Qt::AlignHCenter ); | 1340 | label->setAlignment ( Qt::AlignHCenter ); |
1339 | lay->addWidget( label); | 1341 | lay->addWidget( label); |
1340 | if ( secs > 180 ) | 1342 | if ( secs > 180 ) |
1341 | { | 1343 | { |
1342 | if ( secs > 300 ) { | 1344 | if ( secs > 300 ) { |
1343 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1345 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1344 | qDebug("KSS::Sync cancelled ,cs"); | 1346 | qDebug("KSS::Sync cancelled ,cs"); |
1345 | mErrorMessage = 0; | 1347 | mErrorMessage = 0; |
1346 | end_connect(); | 1348 | end_connect(); |
1347 | error_connect("ERROR_CA\r\n\r\n"); | 1349 | error_connect("ERROR_CA\r\n\r\n"); |
1348 | return ; | 1350 | return ; |
1349 | } | 1351 | } |
1350 | } | 1352 | } |
1351 | QFont f = label->font(); | 1353 | QFont f = label->font(); |
1352 | f.setPointSize ( f.pointSize() *2 ); | 1354 | f.setPointSize ( f.pointSize() *2 ); |
1353 | f. setBold (true ); | 1355 | f. setBold (true ); |
1354 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1356 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1355 | label->setFont( f ); | 1357 | label->setFont( f ); |
1356 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1358 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1357 | label->setText( warning ); | 1359 | label->setText( warning ); |
1358 | label->setAlignment ( Qt::AlignHCenter ); | 1360 | label->setAlignment ( Qt::AlignHCenter ); |
1359 | lay->addWidget( label); | 1361 | lay->addWidget( label); |
1360 | mSyncActionDialog->setFixedSize( 230, 300); | 1362 | mSyncActionDialog->setFixedSize( 230, 300); |
1361 | } else { | 1363 | } else { |
1362 | mSyncActionDialog->setFixedSize( 230, 200); | 1364 | mSyncActionDialog->setFixedSize( 230, 200); |
1363 | } | 1365 | } |
1364 | } else { | 1366 | } else { |
1365 | mSyncActionDialog->setFixedSize( 230, 120); | 1367 | mSyncActionDialog->setFixedSize( 230, 120); |
1366 | } | 1368 | } |
1367 | } else | 1369 | } else |
1368 | mSyncActionDialog->setFixedSize( 230, 120); | 1370 | mSyncActionDialog->setFixedSize( 230, 120); |
1369 | mSyncActionDialog->show(); | 1371 | mSyncActionDialog->show(); |
1370 | mSyncActionDialog->raise(); | 1372 | mSyncActionDialog->raise(); |
1371 | emit request_file(); | 1373 | emit request_file(); |
1372 | qApp->processEvents(); | 1374 | qApp->processEvents(); |
1373 | QString fileName = mFileName; | 1375 | QString fileName = mFileName; |
1374 | QFile file( fileName ); | 1376 | QFile file( fileName ); |
1375 | if (!file.open( IO_ReadOnly ) ) { | 1377 | if (!file.open( IO_ReadOnly ) ) { |
1376 | mErrorMessage = 0; | 1378 | mErrorMessage = 0; |
1377 | end_connect(); | 1379 | end_connect(); |
1378 | error_connect("ERROR_FI\r\n\r\n"); | 1380 | error_connect("ERROR_FI\r\n\r\n"); |
1379 | return ; | 1381 | return ; |
1380 | } | 1382 | } |
1381 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1383 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1382 | QTextStream ts( &file ); | 1384 | QTextStream ts( &file ); |
1383 | ts.setEncoding( QTextStream::Latin1 ); | 1385 | ts.setEncoding( QTextStream::Latin1 ); |
1384 | 1386 | ||
1385 | QTextStream os( mSocket ); | 1387 | QTextStream os( mSocket ); |
1386 | os.setEncoding( QTextStream::Latin1 ); | 1388 | os.setEncoding( QTextStream::Latin1 ); |
1387 | while ( ! ts.atEnd() ) { | 1389 | while ( ! ts.atEnd() ) { |
1388 | os << ts.readLine() << "\r\n"; | 1390 | os << ts.readLine() << "\r\n"; |
1389 | } | 1391 | } |
1390 | os << "\r\n"; | 1392 | os << "\r\n"; |
1391 | //os << ts.read(); | 1393 | //os << ts.read(); |
1392 | file.close(); | 1394 | file.close(); |
1393 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1395 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1394 | mSocket->close(); | 1396 | mSocket->close(); |
1395 | if ( mSocket->state() == QSocket::Idle ) | 1397 | if ( mSocket->state() == QSocket::Idle ) |
1396 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1398 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1397 | } | 1399 | } |
1398 | void KServerSocket::get_file() | 1400 | void KServerSocket::get_file() |
1399 | { | 1401 | { |
1400 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1402 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1401 | 1403 | ||
1402 | piTime.start(); | 1404 | piTime.start(); |
1403 | piFileString = ""; | 1405 | piFileString = ""; |
1404 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1406 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1405 | } | 1407 | } |
1406 | 1408 | ||
1407 | 1409 | ||
1408 | void KServerSocket::readBackFileFromSocket() | 1410 | void KServerSocket::readBackFileFromSocket() |
1409 | { | 1411 | { |
1410 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1412 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1411 | while ( mSocket->canReadLine () ) { | 1413 | while ( mSocket->canReadLine () ) { |
1412 | piTime.restart(); | 1414 | piTime.restart(); |
1413 | QString line = mSocket->readLine (); | 1415 | QString line = mSocket->readLine (); |
1414 | piFileString += line; | 1416 | piFileString += line; |
1415 | //qDebug("readline: %s ", line.latin1()); | 1417 | //qDebug("readline: %s ", line.latin1()); |
1416 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1418 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1417 | 1419 | ||
1418 | } | 1420 | } |
1419 | if ( piTime.elapsed () < 3000 ) { | 1421 | if ( piTime.elapsed () < 3000 ) { |
1420 | // wait for more | 1422 | // wait for more |
1421 | //qDebug("waitformore "); | 1423 | //qDebug("waitformore "); |
1422 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1424 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1423 | return; | 1425 | return; |
1424 | } | 1426 | } |
1425 | QString fileName = mFileName; | 1427 | QString fileName = mFileName; |
1426 | QFile file ( fileName ); | 1428 | QFile file ( fileName ); |
1427 | if (!file.open( IO_WriteOnly ) ) { | 1429 | if (!file.open( IO_WriteOnly ) ) { |
1428 | delete mSyncActionDialog; | 1430 | delete mSyncActionDialog; |
1429 | mSyncActionDialog = 0; | 1431 | mSyncActionDialog = 0; |
1430 | qDebug("KSS:Error open read back file "); | 1432 | qDebug("KSS:Error open read back file "); |
1431 | piFileString = ""; | 1433 | piFileString = ""; |
1432 | emit file_received( false ); | 1434 | emit file_received( false ); |
1433 | blockRC = false; | 1435 | blockRC = false; |
1434 | return ; | 1436 | return ; |
1435 | 1437 | ||
1436 | } | 1438 | } |
1437 | 1439 | ||
1438 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1440 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1439 | QTextStream ts ( &file ); | 1441 | QTextStream ts ( &file ); |
1440 | ts.setEncoding( QTextStream::Latin1 ); | 1442 | ts.setEncoding( QTextStream::Latin1 ); |
1441 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1443 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1442 | ts << piFileString; | 1444 | ts << piFileString; |
1443 | mSocket->close(); | 1445 | mSocket->close(); |
1444 | if ( mSocket->state() == QSocket::Idle ) | 1446 | if ( mSocket->state() == QSocket::Idle ) |
1445 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1447 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1446 | file.close(); | 1448 | file.close(); |
1447 | piFileString = ""; | 1449 | piFileString = ""; |
1448 | emit file_received( true ); | 1450 | emit file_received( true ); |
1449 | delete mSyncActionDialog; | 1451 | delete mSyncActionDialog; |
1450 | mSyncActionDialog = 0; | 1452 | mSyncActionDialog = 0; |
1451 | blockRC = false; | 1453 | blockRC = false; |
1452 | 1454 | ||
1453 | } | 1455 | } |
1454 | 1456 | ||
1455 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) | 1457 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1456 | { | 1458 | { |
1457 | mPassWord = password; | 1459 | mPassWord = password; |
1458 | mSocket = 0; | 1460 | mSocket = 0; |
1459 | mFirst = false; | 1461 | mFirst = false; |
1460 | mFirstLine = true; | 1462 | mFirstLine = true; |
1461 | mPort = port; | 1463 | mPort = port; |
1462 | mHost = host; | 1464 | mHost = host; |
1463 | tlw = cap; | 1465 | tlw = cap; |
1464 | mRetVal = quiet; | 1466 | mRetVal = quiet; |
1465 | mTimerSocket = new QTimer ( this ); | 1467 | mTimerSocket = new QTimer ( this ); |
1466 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1468 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1467 | } | 1469 | } |
1468 | void KCommandSocket::sendFileRequest() | 1470 | void KCommandSocket::sendFileRequest() |
1469 | { | 1471 | { |
1470 | if ( tlw ) | 1472 | if ( tlw ) |
1471 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | 1473 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); |
1472 | mTimerSocket->start( 300000 ); | 1474 | mTimerSocket->start( 300000 ); |
1473 | QTextStream os( mSocket ); | 1475 | QTextStream os( mSocket ); |
1474 | os.setEncoding( QTextStream::Latin1 ); | 1476 | os.setEncoding( QTextStream::Latin1 ); |
1475 | 1477 | ||
1476 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1478 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1477 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; | 1479 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; |
1478 | } | 1480 | } |
1479 | 1481 | ||
1480 | void KCommandSocket::readFile( QString fn ) | 1482 | void KCommandSocket::readFile( QString fn ) |
1481 | { | 1483 | { |
1482 | if ( !mSocket ) { | 1484 | if ( !mSocket ) { |
1483 | mSocket = new QSocket( this ); | 1485 | mSocket = new QSocket( this ); |
1484 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1486 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1485 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1487 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1486 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | 1488 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); |
1487 | } | 1489 | } |
1488 | mFileString = ""; | 1490 | mFileString = ""; |
1489 | mFileName = fn; | 1491 | mFileName = fn; |
1490 | mFirst = true; | 1492 | mFirst = true; |
1491 | if ( tlw ) | 1493 | if ( tlw ) |
1492 | tlw->setCaption( i18n("Trying to connect to remote...") ); | 1494 | tlw->setCaption( i18n("Trying to connect to remote...") ); |
1493 | mTimerSocket->start( 20000 ); | 1495 | mTimerSocket->start( 20000 ); |
1494 | mSocket->connectToHost( mHost, mPort ); | 1496 | mSocket->connectToHost( mHost, mPort ); |
1495 | qDebug("KSS: Waiting for connection"); | 1497 | qDebug("KSS: Waiting for connection"); |
1496 | } | 1498 | } |
1497 | 1499 | ||
1498 | void KCommandSocket::writeFile( QString fileName ) | 1500 | void KCommandSocket::writeFile( QString fileName ) |
1499 | { | 1501 | { |
1500 | if ( !mSocket ) { | 1502 | if ( !mSocket ) { |
1501 | mSocket = new QSocket( this ); | 1503 | mSocket = new QSocket( this ); |
1502 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1504 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1503 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1505 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1504 | } | 1506 | } |
1505 | mFileName = fileName ; | 1507 | mFileName = fileName ; |
1506 | mTimerSocket->start( 20000 ); | 1508 | mTimerSocket->start( 20000 ); |
1507 | mSocket->connectToHost( mHost, mPort ); | 1509 | mSocket->connectToHost( mHost, mPort ); |
1508 | } | 1510 | } |
1509 | void KCommandSocket::writeFileToSocket() | 1511 | void KCommandSocket::writeFileToSocket() |
1510 | { | 1512 | { |
1511 | mTimerSocket->stop(); | 1513 | mTimerSocket->stop(); |
1512 | QFile file2( mFileName ); | 1514 | QFile file2( mFileName ); |
1513 | if (!file2.open( IO_ReadOnly ) ) { | 1515 | if (!file2.open( IO_ReadOnly ) ) { |
1514 | mRetVal= errorW; | 1516 | mRetVal= errorW; |
1515 | mSocket->close(); | 1517 | mSocket->close(); |
1516 | if ( mSocket->state() == QSocket::Idle ) | 1518 | if ( mSocket->state() == QSocket::Idle ) |
1517 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1519 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1518 | return ; | 1520 | return ; |
1519 | } | 1521 | } |
1520 | QTextStream ts2( &file2 ); | 1522 | QTextStream ts2( &file2 ); |
1521 | ts2.setEncoding( QTextStream::Latin1 ); | 1523 | ts2.setEncoding( QTextStream::Latin1 ); |
1522 | QTextStream os2( mSocket ); | 1524 | QTextStream os2( mSocket ); |
1523 | os2.setEncoding( QTextStream::Latin1 ); | 1525 | os2.setEncoding( QTextStream::Latin1 ); |
1524 | os2 << "PUT " << mPassWord << "\r\n\r\n";; | 1526 | os2 << "PUT " << mPassWord << "\r\n\r\n";; |
1525 | while ( ! ts2.atEnd() ) { | 1527 | while ( ! ts2.atEnd() ) { |
1526 | os2 << ts2.readLine() << "\r\n"; | 1528 | os2 << ts2.readLine() << "\r\n"; |
1527 | } | 1529 | } |
1528 | os2 << "\r\n"; | 1530 | os2 << "\r\n"; |
1529 | mRetVal= successW; | 1531 | mRetVal= successW; |
1530 | file2.close(); | 1532 | file2.close(); |
1531 | mSocket->close(); | 1533 | mSocket->close(); |
1532 | if ( mSocket->state() == QSocket::Idle ) | 1534 | if ( mSocket->state() == QSocket::Idle ) |
1533 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1535 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1534 | } | 1536 | } |
1535 | void KCommandSocket::sendStop() | 1537 | void KCommandSocket::sendStop() |
1536 | { | 1538 | { |
1537 | if ( !mSocket ) { | 1539 | if ( !mSocket ) { |
1538 | mSocket = new QSocket( this ); | 1540 | mSocket = new QSocket( this ); |
1539 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1541 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1540 | } | 1542 | } |
1541 | mSocket->connectToHost( mHost, mPort ); | 1543 | mSocket->connectToHost( mHost, mPort ); |
1542 | QTextStream os2( mSocket ); | 1544 | QTextStream os2( mSocket ); |
1543 | os2.setEncoding( QTextStream::Latin1 ); | 1545 | os2.setEncoding( QTextStream::Latin1 ); |
1544 | os2 << "STOP\r\n\r\n"; | 1546 | os2 << "STOP\r\n\r\n"; |
1545 | mSocket->close(); | 1547 | mSocket->close(); |
1546 | if ( mSocket->state() == QSocket::Idle ) | 1548 | if ( mSocket->state() == QSocket::Idle ) |
1547 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1549 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1548 | } | 1550 | } |
1549 | 1551 | ||
1550 | void KCommandSocket::startReadFileFromSocket() | 1552 | void KCommandSocket::startReadFileFromSocket() |
1551 | { | 1553 | { |
1552 | if ( ! mFirst ) | 1554 | if ( ! mFirst ) |
1553 | return; | 1555 | return; |
1554 | mFirst = false; | 1556 | mFirst = false; |
1555 | mTimerSocket->stop(); | 1557 | mTimerSocket->stop(); |
1556 | mFileString = ""; | 1558 | mFileString = ""; |
1557 | mTime.start(); | 1559 | mTime.start(); |
1558 | mFirstLine = true; | 1560 | mFirstLine = true; |
1559 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1561 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1560 | 1562 | ||
1561 | } | 1563 | } |
1562 | void KCommandSocket::readFileFromSocket() | 1564 | void KCommandSocket::readFileFromSocket() |
1563 | { | 1565 | { |
1564 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1566 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1565 | while ( mSocket->canReadLine () ) { | 1567 | while ( mSocket->canReadLine () ) { |
1566 | mTime.restart(); | 1568 | mTime.restart(); |
1567 | QString line = mSocket->readLine (); | 1569 | QString line = mSocket->readLine (); |
1568 | if ( mFirstLine ) { | 1570 | if ( mFirstLine ) { |
1569 | mFirstLine = false; | 1571 | mFirstLine = false; |
1570 | if ( line.left( 6 ) == "ERROR_" ) { | 1572 | if ( line.left( 6 ) == "ERROR_" ) { |
1571 | if ( line.left( 8 ) == "ERROR_PW" ) { | 1573 | if ( line.left( 8 ) == "ERROR_PW" ) { |
1572 | mRetVal = errorPW; | 1574 | mRetVal = errorPW; |
1573 | deleteSocket(); | 1575 | deleteSocket(); |
1574 | return ; | 1576 | return ; |
1575 | } | 1577 | } |
1576 | if ( line.left( 8 ) == "ERROR_CA" ) { | 1578 | if ( line.left( 8 ) == "ERROR_CA" ) { |
1577 | mRetVal = errorCA; | 1579 | mRetVal = errorCA; |
1578 | deleteSocket(); | 1580 | deleteSocket(); |
1579 | return ; | 1581 | return ; |
1580 | } | 1582 | } |
1581 | if ( line.left( 8 ) == "ERROR_FI" ) { | 1583 | if ( line.left( 8 ) == "ERROR_FI" ) { |
1582 | mRetVal = errorFI; | 1584 | mRetVal = errorFI; |
1583 | deleteSocket(); | 1585 | deleteSocket(); |
1584 | return ; | 1586 | return ; |
1585 | } | 1587 | } |
1586 | if ( line.left( 8 ) == "ERROR_ED" ) { | 1588 | if ( line.left( 8 ) == "ERROR_ED" ) { |
1587 | mRetVal = errorED; | 1589 | mRetVal = errorED; |
1588 | deleteSocket(); | 1590 | deleteSocket(); |
1589 | return ; | 1591 | return ; |
1590 | } | 1592 | } |
1591 | mRetVal = errorUN; | 1593 | mRetVal = errorUN; |
1592 | deleteSocket(); | 1594 | deleteSocket(); |
1593 | return ; | 1595 | return ; |
1594 | } | 1596 | } |
1595 | } | 1597 | } |
1596 | mFileString += line; | 1598 | mFileString += line; |
1597 | //qDebug("readline: %s ", line.latin1()); | 1599 | //qDebug("readline: %s ", line.latin1()); |
1598 | } | 1600 | } |
1599 | if ( mTime.elapsed () < 3000 ) { | 1601 | if ( mTime.elapsed () < 3000 ) { |
1600 | // wait for more | 1602 | // wait for more |
1601 | //qDebug("waitformore "); | 1603 | //qDebug("waitformore "); |
1602 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1604 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1603 | return; | 1605 | return; |
1604 | } | 1606 | } |
1605 | QString fileName = mFileName; | 1607 | QString fileName = mFileName; |
1606 | QFile file ( fileName ); | 1608 | QFile file ( fileName ); |
1607 | if (!file.open( IO_WriteOnly ) ) { | 1609 | if (!file.open( IO_WriteOnly ) ) { |
1608 | mFileString = ""; | 1610 | mFileString = ""; |
1609 | mRetVal = errorR; | 1611 | mRetVal = errorR; |
1610 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1612 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1611 | deleteSocket(); | 1613 | deleteSocket(); |
1612 | return ; | 1614 | return ; |
1613 | 1615 | ||
1614 | } | 1616 | } |
1615 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1617 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1616 | QTextStream ts ( &file ); | 1618 | QTextStream ts ( &file ); |
1617 | ts.setEncoding( QTextStream::Latin1 ); | 1619 | ts.setEncoding( QTextStream::Latin1 ); |
1618 | ts << mFileString; | 1620 | ts << mFileString; |
1619 | file.close(); | 1621 | file.close(); |
1620 | mFileString = ""; | 1622 | mFileString = ""; |
1621 | mRetVal = successR; | 1623 | mRetVal = successR; |
1622 | mSocket->close(); | 1624 | mSocket->close(); |
1623 | // if state is not idle, deleteSocket(); is called via | 1625 | // if state is not idle, deleteSocket(); is called via |
1624 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1626 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1625 | if ( mSocket->state() == QSocket::Idle ) | 1627 | if ( mSocket->state() == QSocket::Idle ) |
1626 | deleteSocket(); | 1628 | deleteSocket(); |
1627 | } | 1629 | } |
1628 | 1630 | ||
1629 | void KCommandSocket::deleteSocket() | 1631 | void KCommandSocket::deleteSocket() |
1630 | { | 1632 | { |
1631 | //qDebug("KCommandSocket::deleteSocket() "); | 1633 | //qDebug("KCommandSocket::deleteSocket() "); |
1632 | if ( mTimerSocket->isActive () ) { | 1634 | if ( mTimerSocket->isActive () ) { |
1633 | mTimerSocket->stop(); | 1635 | mTimerSocket->stop(); |
1634 | mRetVal = errorTO; | 1636 | mRetVal = errorTO; |
1635 | qDebug("KCS::Connection to remote host timed out"); | 1637 | qDebug("KCS::Connection to remote host timed out"); |
1636 | if ( mSocket ) { | 1638 | if ( mSocket ) { |
1637 | mSocket->close(); | 1639 | mSocket->close(); |
1638 | //if ( mSocket->state() == QSocket::Idle ) | 1640 | //if ( mSocket->state() == QSocket::Idle ) |
1639 | // deleteSocket(); | 1641 | // deleteSocket(); |
1640 | delete mSocket; | 1642 | delete mSocket; |
1641 | mSocket = 0; | 1643 | mSocket = 0; |
1642 | } | 1644 | } |
1643 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); | 1645 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); |
1644 | emit commandFinished( this, mRetVal ); | 1646 | emit commandFinished( this, mRetVal ); |
1645 | return; | 1647 | return; |
1646 | } | 1648 | } |
1647 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1649 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1648 | if ( mSocket) | 1650 | if ( mSocket) |
1649 | delete mSocket; | 1651 | delete mSocket; |
1650 | mSocket = 0; | 1652 | mSocket = 0; |
1651 | emit commandFinished( this, mRetVal ); | 1653 | emit commandFinished( this, mRetVal ); |
1652 | } | 1654 | } |