summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-10 19:37:46 (UTC)
committer ulf69 <ulf69>2004-08-10 19:37:46 (UTC)
commit2666ac52add8d79e34a04a64e4d5f092dd3d3d7e (patch) (unidiff)
tree268ecd1ce5d898f7bd6ce82f5d023b161dc38892
parent9f73ddc03d2b02934906193cf8db5ff0813fce0b (diff)
downloadkdepimpi-2666ac52add8d79e34a04a64e4d5f092dd3d3d7e.zip
kdepimpi-2666ac52add8d79e34a04a64e4d5f092dd3d3d7e.tar.gz
kdepimpi-2666ac52add8d79e34a04a64e4d5f092dd3d3d7e.tar.bz2
added methods to check if a certain application is available
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp128
-rw-r--r--libkdepim/externalapphandler.h19
2 files changed, 144 insertions, 3 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
index 0128cf7..5a56d68 100644
--- a/libkdepim/externalapphandler.cpp
+++ b/libkdepim/externalapphandler.cpp
@@ -45,63 +45,69 @@ $Id$
45 45
46#include "kpimglobalprefs.h" 46#include "kpimglobalprefs.h"
47 47
48 48
49 49
50 50
51 51
52 52
53 53
54ExternalAppHandler *ExternalAppHandler::sInstance = 0; 54ExternalAppHandler *ExternalAppHandler::sInstance = 0;
55static KStaticDeleter<ExternalAppHandler> staticDeleter; 55static KStaticDeleter<ExternalAppHandler> staticDeleter;
56 56
57 57
58ExternalAppHandler::ExternalAppHandler() 58ExternalAppHandler::ExternalAppHandler()
59{ 59{
60 mDefaultItems.setAutoDelete(true); 60 mDefaultItems.setAutoDelete(true);
61} 61}
62 62
63ExternalAppHandler::~ExternalAppHandler() 63ExternalAppHandler::~ExternalAppHandler()
64{ 64{
65} 65}
66 66
67void ExternalAppHandler::loadConfig() 67void ExternalAppHandler::loadConfig()
68{ 68{
69
69 mDefaultItems.clear(); 70 mDefaultItems.clear();
70 71
72 mEmailAppAvailable = UNDEFINED;
73 mPhoneAppAvailable = UNDEFINED;
74 mFaxAppAvailable = UNDEFINED;
75 mSMSAppAvailable = UNDEFINED;
76 mPagerAppAvailable = UNDEFINED;
71 77
72 78
73 QString opiepath = QString::fromLatin1( getenv("OPIEDIR") ); 79 QString opiepath = QString::fromLatin1( getenv("OPIEDIR") );
74 QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") ); 80 QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") );
75 81
76 if (opiepath.isEmpty()) 82 if (opiepath.isEmpty())
77 opiepath = qtopiapath; 83 opiepath = qtopiapath;
78 84
79 //mailclients 85 //mailclients
80 QString mailmsg1 = "writeMail(QString,QString)"; 86 QString mailmsg1 = "writeMail(QString,QString)";
81 QString mailmsg2 = "writeMail(QMap(QString,QString))"; 87 QString mailmsg2 = "writeMail(QMap(QString,QString))";
82 88
83 QString undefined = "undefined"; 89 QString undefined = "";
84 90
85 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined); 91 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined);
86 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined); 92 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined);
87 93
88 if (( QFile::exists( qtopiapath + "/bin/ompi" )) || 94 if (( QFile::exists( qtopiapath + "/bin/ompi" )) ||
89 ( QFile::exists( opiepath + "/bin/ompi" ))) 95 ( QFile::exists( opiepath + "/bin/ompi" )))
90 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", "newMail(QString)", "%1", mailmsg2, "ATTACHMENT=%1"); 96 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", "newMail(QString)", "%1", mailmsg2, "ATTACHMENT=%1");
91 97
92 if ( QFile::exists( qtopiapath + "/bin/qtmail" )) 98 if ( QFile::exists( qtopiapath + "/bin/qtmail" ))
93 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1"); 99 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
94 100
95 if ( QFile::exists( opiepath + "/bin/opiemail" )) 101 if ( QFile::exists( opiepath + "/bin/opiemail" ))
96 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1"); 102 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
97 103
98 104
99 105
100 //phoneclients 106 //phoneclients
101 107
102 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined); 108 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined);
103 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::OTHER_PHC, "Other phone client", undefined, undefined, undefined, undefined, undefined); 109 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::OTHER_PHC, "Other phone client", undefined, undefined, undefined, undefined, undefined);
104 if (( QFile::exists( qtopiapath + "/bin/kppi" )) || 110 if (( QFile::exists( qtopiapath + "/bin/kppi" )) ||
105 ( QFile::exists( opiepath + "/bin/kppi" ))) 111 ( QFile::exists( opiepath + "/bin/kppi" )))
106 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::KPPI_PHC, "KP/Pi phone client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined); 112 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::KPPI_PHC, "KP/Pi phone client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined);
107 113
@@ -144,48 +150,141 @@ QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type)
144 DefaultAppItem* dai; 150 DefaultAppItem* dai;
145 151
146 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) 152 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
147 { 153 {
148 if (dai->_type == type) 154 if (dai->_type == type)
149 list.append(dai); 155 list.append(dai);
150 } 156 }
151 157
152 return list; 158 return list;
153} 159}
154 160
155DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid) 161DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid)
156{ 162{
157 DefaultAppItem* dai; 163 DefaultAppItem* dai;
158 164
159 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) 165 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
160 { 166 {
161 if (dai->_type == type && dai->_id == clientid) 167 if (dai->_type == type && dai->_id == clientid)
162 return dai; 168 return dai;
163 } 169 }
164 170
165 return 0; 171 return 0;
166} 172}
167 173
174bool ExternalAppHandler::isEmailAppAvailable()
175{
176#ifndef DESKTOP_VERSION
177 if (mEmailAppAvailable == UNDEFINED)
178 {
179 int client = KPimGlobalPrefs::instance()->mEmailClient;
180 if (client == KPimGlobalPrefs::NONE_EMC)
181 mEmailAppAvailable = UNAVAILABLE;
182 else
183 mEmailAppAvailable = AVAILABLE;
184 }
185 return (mEmailAppAvailable == AVAILABLE);
186
187#else //DESKTOP_VERSION
188 return false;
189#endif //DESKTOP_VERSION
190}
191
192bool ExternalAppHandler::isSMSAppAvailable()
193{
194#ifndef DESKTOP_VERSION
195 if (mSMSAppAvailable == UNDEFINED)
196 {
197 int client = KPimGlobalPrefs::instance()->mSMSClient;
198 if (client == KPimGlobalPrefs::NONE_SMC)
199 mSMSAppAvailable = UNAVAILABLE;
200 else
201 mSMSAppAvailable = AVAILABLE;
202 }
203
204 return (mSMSAppAvailable == AVAILABLE);
205#else //DESKTOP_VERSION
206 return false;
207#endif //DESKTOP_VERSION
208}
209
210bool ExternalAppHandler::isPhoneAppAvailable()
211{
212#ifndef DESKTOP_VERSION
213 if (mPhoneAppAvailable == UNDEFINED)
214 {
215 int client = KPimGlobalPrefs::instance()->mPhoneClient;
216 if (client == KPimGlobalPrefs::NONE_PHC)
217 mPhoneAppAvailable = UNAVAILABLE;
218 else
219 mPhoneAppAvailable = AVAILABLE;
220 }
221
222 return (mPhoneAppAvailable == AVAILABLE);
223#else //DESKTOP_VERSION
224 return false;
225#endif //DESKTOP_VERSION
226}
227
228bool ExternalAppHandler::isFaxAppAvailable()
229{
230#ifndef DESKTOP_VERSION
231 if (mFaxAppAvailable == UNDEFINED)
232 {
233 int client = KPimGlobalPrefs::instance()->mFaxClient;
234 if (client == KPimGlobalPrefs::NONE_FAC)
235 mFaxAppAvailable = UNAVAILABLE;
236 else
237 mFaxAppAvailable = AVAILABLE;
238 }
239
240 return (mFaxAppAvailable == AVAILABLE);
241#else //DESKTOP_VERSION
242 return false;
243#endif //DESKTOP_VERSION
244}
245
246bool ExternalAppHandler::isPagerAppAvailable()
247{
248#ifndef DESKTOP_VERSION
249 if (mPagerAppAvailable == UNDEFINED)
250 {
251 int client = KPimGlobalPrefs::instance()->mPagerClient;
252 if (client == KPimGlobalPrefs::NONE_PAC)
253 mPagerAppAvailable = UNAVAILABLE;
254 else
255 mPagerAppAvailable = AVAILABLE;
256 }
257
258 return (mPagerAppAvailable == AVAILABLE);
259#else //DESKTOP_VERSION
260 return false;
261#endif //DESKTOP_VERSION
262}
263
264/**************************************************************************
265 *
266 **************************************************************************/
168 267
169 268
170//calls the emailapplication with a number of attachments that need to be send (Seperated by Comma) 269//calls the emailapplication with a number of attachments that need to be send (Seperated by Comma)
171bool ExternalAppHandler::mailAttachments( const QString& urls ) 270bool ExternalAppHandler::mailAttachments( const QString& urls )
172{ 271{
173 272
174#ifndef DESKTOP_VERSION 273#ifndef DESKTOP_VERSION
175 QString channel; 274 QString channel;
176 QString message2; 275 QString message2;
177 QString parameters2; 276 QString parameters2;
178 277
179 278
180 int client = KPimGlobalPrefs::instance()->mEmailClient; 279 int client = KPimGlobalPrefs::instance()->mEmailClient;
181 if (client == KPimGlobalPrefs::OTHER_EMC) 280 if (client == KPimGlobalPrefs::OTHER_EMC)
182 { 281 {
183 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; 282 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
184 message2 = KPimGlobalPrefs::instance()->mEmailOtherMessage; 283 message2 = KPimGlobalPrefs::instance()->mEmailOtherMessage;
185 parameters2 = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; 284 parameters2 = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters;
186 } 285 }
187 else 286 else
188 { 287 {
189 DefaultAppItem* dai = getDefaultItem(EMAIL, client); 288 DefaultAppItem* dai = getDefaultItem(EMAIL, client);
190 if (!dai) 289 if (!dai)
191 { 290 {
@@ -195,48 +294,51 @@ bool ExternalAppHandler::mailAttachments( const QString& urls )
195 channel = dai->_channel; 294 channel = dai->_channel;
196 message2 = dai->_message2; 295 message2 = dai->_message2;
197 parameters2 = dai->_parameters2; 296 parameters2 = dai->_parameters2;
198 } 297 }
199 298
200 299
201 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1()); 300 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1());
202 qDebug("passing attachmenturls:(%s) as parameter in the form %s to QCopEnvelope", urls.latin1(), parameters2.latin1()); 301 qDebug("passing attachmenturls:(%s) as parameter in the form %s to QCopEnvelope", urls.latin1(), parameters2.latin1());
203 302
204 303
205 QCopEnvelope e(channel.latin1(), message2.latin1()); 304 QCopEnvelope e(channel.latin1(), message2.latin1());
206 //US we need no names in the To field. The emailadresses are enough 305 //US we need no names in the To field. The emailadresses are enough
207 306
208 passParameter(&e, parameters2, urls); 307 passParameter(&e, parameters2, urls);
209 308
210 309
211 310
212#else 311#else
213 KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); 312 KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) );
214#endif 313#endif
215 314
216 return true; 315 return true;
217} 316}
218 317
318/**************************************************************************
319 *
320 **************************************************************************/
219 321
220 322
221//calls the emailapplication and creates a mail with parameter emails as recipients 323//calls the emailapplication and creates a mail with parameter emails as recipients
222bool ExternalAppHandler::mailToContacts( const QString& emails ) 324bool ExternalAppHandler::mailToContacts( const QString& emails )
223{ 325{
224#ifndef DESKTOP_VERSION 326#ifndef DESKTOP_VERSION
225 QString channel; 327 QString channel;
226 QString message; 328 QString message;
227 QString parameters; 329 QString parameters;
228 330
229 331
230 int client = KPimGlobalPrefs::instance()->mEmailClient; 332 int client = KPimGlobalPrefs::instance()->mEmailClient;
231 if (client == KPimGlobalPrefs::OTHER_EMC) 333 if (client == KPimGlobalPrefs::OTHER_EMC)
232 { 334 {
233 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel; 335 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
234 message = KPimGlobalPrefs::instance()->mEmailOtherMessage; 336 message = KPimGlobalPrefs::instance()->mEmailOtherMessage;
235 parameters = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters; 337 parameters = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters;
236 } 338 }
237 else 339 else
238 { 340 {
239 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(EMAIL, client); 341 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(EMAIL, client);
240 if (!dai) 342 if (!dai)
241 { 343 {
242 qDebug("could not find configured email application."); 344 qDebug("could not find configured email application.");
@@ -248,48 +350,51 @@ bool ExternalAppHandler::mailToContacts( const QString& emails )
248 } 350 }
249 351
250 352
251 //first check if one of the mailers need the emails right in the message. 353 //first check if one of the mailers need the emails right in the message.
252 message = translateMessage(message, emails); 354 message = translateMessage(message, emails);
253 355
254 356
255 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 357 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
256 qDebug("passing emailadresses:(%s) as parameter in the form %s to QCopEnvelope", emails.latin1(), parameters.latin1()); 358 qDebug("passing emailadresses:(%s) as parameter in the form %s to QCopEnvelope", emails.latin1(), parameters.latin1());
257 359
258 QCopEnvelope e(channel.latin1(), message.latin1()); 360 QCopEnvelope e(channel.latin1(), message.latin1());
259 //US we need no names in the To field. The emailadresses are enough 361 //US we need no names in the To field. The emailadresses are enough
260 362
261 passParameter(&e, parameters, emails); 363 passParameter(&e, parameters, emails);
262 364
263 365
264#else 366#else
265 KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) ); 367 KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) );
266#endif 368#endif
267 369
268 370
269 return true; 371 return true;
270} 372}
271 373
374/**************************************************************************
375 *
376 **************************************************************************/
272 377
273//calls the phoneapplication with the number 378//calls the phoneapplication with the number
274bool ExternalAppHandler::callByPhone( const QString& phonenumber ) 379bool ExternalAppHandler::callByPhone( const QString& phonenumber )
275{ 380{
276#ifndef DESKTOP_VERSION 381#ifndef DESKTOP_VERSION
277 QString channel; 382 QString channel;
278 QString message; 383 QString message;
279 QString parameters; 384 QString parameters;
280 385
281 386
282 int client = KPimGlobalPrefs::instance()->mPhoneClient; 387 int client = KPimGlobalPrefs::instance()->mPhoneClient;
283 if (client == KPimGlobalPrefs::OTHER_PHC) 388 if (client == KPimGlobalPrefs::OTHER_PHC)
284 { 389 {
285 channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel; 390 channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel;
286 message = KPimGlobalPrefs::instance()->mPhoneOtherMessage; 391 message = KPimGlobalPrefs::instance()->mPhoneOtherMessage;
287 parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters; 392 parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters;
288 } 393 }
289 else 394 else
290 { 395 {
291 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client); 396 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client);
292 if (!dai) 397 if (!dai)
293 { 398 {
294 qDebug("could not find configured phone application."); 399 qDebug("could not find configured phone application.");
295 return false; 400 return false;
@@ -300,48 +405,52 @@ bool ExternalAppHandler::callByPhone( const QString& phonenumber )
300 } 405 }
301 406
302 407
303 //first check if one of the mailers need the emails right in the message. 408 //first check if one of the mailers need the emails right in the message.
304 message = translateMessage(message, phonenumber); 409 message = translateMessage(message, phonenumber);
305 410
306 411
307 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 412 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
308 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); 413 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
309 414
310 QCopEnvelope e(channel.latin1(), message.latin1()); 415 QCopEnvelope e(channel.latin1(), message.latin1());
311 //US we need no names in the To field. The emailadresses are enough 416 //US we need no names in the To field. The emailadresses are enough
312 417
313 passParameter(&e, parameters, phonenumber); 418 passParameter(&e, parameters, phonenumber);
314 419
315 420
316#else 421#else
317 KMessageBox::sorry( 0, i18n( "This version does not support phonecalls." ) ); 422 KMessageBox::sorry( 0, i18n( "This version does not support phonecalls." ) );
318#endif 423#endif
319 424
320 425
321 return true; 426 return true;
322} 427}
323 428
429/**************************************************************************
430 *
431 **************************************************************************/
432
324//calls the smsapplication with the number 433//calls the smsapplication with the number
325bool ExternalAppHandler::callBySMS( const QString& phonenumber ) 434bool ExternalAppHandler::callBySMS( const QString& phonenumber )
326{ 435{
327#ifndef DESKTOP_VERSION 436#ifndef DESKTOP_VERSION
328 QString channel; 437 QString channel;
329 QString message; 438 QString message;
330 QString parameters; 439 QString parameters;
331 440
332 441
333 int client = KPimGlobalPrefs::instance()->mSMSClient; 442 int client = KPimGlobalPrefs::instance()->mSMSClient;
334 if (client == KPimGlobalPrefs::OTHER_SMC) 443 if (client == KPimGlobalPrefs::OTHER_SMC)
335 { 444 {
336 channel = KPimGlobalPrefs::instance()->mSMSOtherChannel; 445 channel = KPimGlobalPrefs::instance()->mSMSOtherChannel;
337 message = KPimGlobalPrefs::instance()->mSMSOtherMessage; 446 message = KPimGlobalPrefs::instance()->mSMSOtherMessage;
338 parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters; 447 parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters;
339 } 448 }
340 else 449 else
341 { 450 {
342 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SMS, client); 451 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SMS, client);
343 if (!dai) 452 if (!dai)
344 { 453 {
345 qDebug("could not find configured sms application."); 454 qDebug("could not find configured sms application.");
346 return false; 455 return false;
347 } 456 }
@@ -351,48 +460,52 @@ bool ExternalAppHandler::callBySMS( const QString& phonenumber )
351 } 460 }
352 461
353 462
354 //first check if one of the mailers need the emails right in the message. 463 //first check if one of the mailers need the emails right in the message.
355 message = translateMessage(message, phonenumber); 464 message = translateMessage(message, phonenumber);
356 465
357 466
358 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 467 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
359 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1()); 468 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
360 469
361 QCopEnvelope e(channel.latin1(), message.latin1()); 470 QCopEnvelope e(channel.latin1(), message.latin1());
362 //US we need no names in the To field. The emailadresses are enough 471 //US we need no names in the To field. The emailadresses are enough
363 472
364 passParameter(&e, parameters, phonenumber); 473 passParameter(&e, parameters, phonenumber);
365 474
366 475
367#else 476#else
368 KMessageBox::sorry( 0, i18n( "This version does not support the sending of sms." ) ); 477 KMessageBox::sorry( 0, i18n( "This version does not support the sending of sms." ) );
369#endif 478#endif
370 479
371 480
372 return true; 481 return true;
373} 482}
374 483
484/**************************************************************************
485 *
486 **************************************************************************/
487
375//calls the pagerapplication with the number 488//calls the pagerapplication with the number
376bool ExternalAppHandler::callByPager( const QString& pagernumber ) 489bool ExternalAppHandler::callByPager( const QString& pagernumber )
377{ 490{
378#ifndef DESKTOP_VERSION 491#ifndef DESKTOP_VERSION
379 QString channel; 492 QString channel;
380 QString message; 493 QString message;
381 QString parameters; 494 QString parameters;
382 495
383 496
384 int client = KPimGlobalPrefs::instance()->mPagerClient; 497 int client = KPimGlobalPrefs::instance()->mPagerClient;
385 if (client == KPimGlobalPrefs::OTHER_PAC) 498 if (client == KPimGlobalPrefs::OTHER_PAC)
386 { 499 {
387 channel = KPimGlobalPrefs::instance()->mPagerOtherChannel; 500 channel = KPimGlobalPrefs::instance()->mPagerOtherChannel;
388 message = KPimGlobalPrefs::instance()->mPagerOtherMessage; 501 message = KPimGlobalPrefs::instance()->mPagerOtherMessage;
389 parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters; 502 parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters;
390 } 503 }
391 else 504 else
392 { 505 {
393 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PAGER, client); 506 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PAGER, client);
394 if (!dai) 507 if (!dai)
395 { 508 {
396 qDebug("could not find configured pager application."); 509 qDebug("could not find configured pager application.");
397 return false; 510 return false;
398 } 511 }
@@ -402,48 +515,52 @@ bool ExternalAppHandler::callByPager( const QString& pagernumber )
402 } 515 }
403 516
404 517
405 //first check if one of the mailers need the emails right in the message. 518 //first check if one of the mailers need the emails right in the message.
406 message = translateMessage(message, pagernumber); 519 message = translateMessage(message, pagernumber);
407 520
408 521
409 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 522 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
410 qDebug("passing pagernumber:(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1()); 523 qDebug("passing pagernumber:(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1());
411 524
412 QCopEnvelope e(channel.latin1(), message.latin1()); 525 QCopEnvelope e(channel.latin1(), message.latin1());
413 //US we need no names in the To field. The emailadresses are enough 526 //US we need no names in the To field. The emailadresses are enough
414 527
415 passParameter(&e, parameters, pagernumber); 528 passParameter(&e, parameters, pagernumber);
416 529
417 530
418#else 531#else
419 KMessageBox::sorry( 0, i18n( "This version does not support paging." ) ); 532 KMessageBox::sorry( 0, i18n( "This version does not support paging." ) );
420#endif 533#endif
421 534
422 535
423 return true; 536 return true;
424} 537}
425 538
539/**************************************************************************
540 *
541 **************************************************************************/
542
426//calls the faxapplication with the number 543//calls the faxapplication with the number
427bool ExternalAppHandler::callByFax( const QString& faxnumber ) 544bool ExternalAppHandler::callByFax( const QString& faxnumber )
428{ 545{
429#ifndef DESKTOP_VERSION 546#ifndef DESKTOP_VERSION
430 QString channel; 547 QString channel;
431 QString message; 548 QString message;
432 QString parameters; 549 QString parameters;
433 550
434 551
435 int client = KPimGlobalPrefs::instance()->mFaxClient; 552 int client = KPimGlobalPrefs::instance()->mFaxClient;
436 if (client == KPimGlobalPrefs::OTHER_FAC) 553 if (client == KPimGlobalPrefs::OTHER_FAC)
437 { 554 {
438 channel = KPimGlobalPrefs::instance()->mFaxOtherChannel; 555 channel = KPimGlobalPrefs::instance()->mFaxOtherChannel;
439 message = KPimGlobalPrefs::instance()->mFaxOtherMessage; 556 message = KPimGlobalPrefs::instance()->mFaxOtherMessage;
440 parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters; 557 parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters;
441 } 558 }
442 else 559 else
443 { 560 {
444 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(FAX, client); 561 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(FAX, client);
445 if (!dai) 562 if (!dai)
446 { 563 {
447 qDebug("could not find configured fax application."); 564 qDebug("could not find configured fax application.");
448 return false; 565 return false;
449 } 566 }
@@ -453,58 +570,63 @@ bool ExternalAppHandler::callByFax( const QString& faxnumber )
453 } 570 }
454 571
455 572
456 //first check if one of the mailers need the emails right in the message. 573 //first check if one of the mailers need the emails right in the message.
457 message = translateMessage(message, faxnumber); 574 message = translateMessage(message, faxnumber);
458 575
459 576
460 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 577 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
461 qDebug("passing faxnumber:(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1()); 578 qDebug("passing faxnumber:(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1());
462 579
463 QCopEnvelope e(channel.latin1(), message.latin1()); 580 QCopEnvelope e(channel.latin1(), message.latin1());
464 //US we need no names in the To field. The emailadresses are enough 581 //US we need no names in the To field. The emailadresses are enough
465 582
466 passParameter(&e, parameters, faxnumber); 583 passParameter(&e, parameters, faxnumber);
467 584
468 585
469#else 586#else
470 KMessageBox::sorry( 0, i18n( "This version does not support the sending of faxes." ) ); 587 KMessageBox::sorry( 0, i18n( "This version does not support the sending of faxes." ) );
471#endif 588#endif
472 589
473 590
474 return true; 591 return true;
475} 592}
476 593
477 594/**************************************************************************
478 595 *
596 **************************************************************************/
479 597
480 598
481 599
482QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1) const 600QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1) const
483{ 601{
484 return message.replace( QRegExp("%1"), param1 ); 602 return message.replace( QRegExp("%1"), param1 );
485} 603}
486 604
605/**************************************************************************
606 *
607 **************************************************************************/
608
487void ExternalAppHandler::passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const 609void ExternalAppHandler::passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const
488{ 610{
489#ifndef DESKTOP_VERSION 611#ifndef DESKTOP_VERSION
490 QMap<QString, QString> valmap; 612 QMap<QString, QString> valmap;
491 bool useValMap = false; 613 bool useValMap = false;
492 614
493 // first extract all parts of the parameters. 615 // first extract all parts of the parameters.
494 QStringList paramlist = QStringList::split(";", parameters); 616 QStringList paramlist = QStringList::split(";", parameters);
495 617
496 //Now check how many parts we have. 618 //Now check how many parts we have.
497 //=0 :no params to pass 619 //=0 :no params to pass
498 //>0 :parameters to pass 620 //>0 :parameters to pass
499 for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it ) 621 for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it )
500 { 622 {
501 QString param = (*it); 623 QString param = (*it);
502 QStringList keyvallist = QStringList::split("=", param); 624 QStringList keyvallist = QStringList::split("=", param);
503 625
504 //if we have keyvalue pairs, we assume that we pass a map to the envelope 626 //if we have keyvalue pairs, we assume that we pass a map to the envelope
505 QStringList::Iterator it2 = keyvallist.begin(); 627 QStringList::Iterator it2 = keyvallist.begin();
506 QString key = (*it2); 628 QString key = (*it2);
507 key = key.replace( QRegExp("%1"), param1 ); 629 key = key.replace( QRegExp("%1"), param1 );
508 ++it2; 630 ++it2;
509 631
510 if(it2 != keyvallist.end()) 632 if(it2 != keyvallist.end())
diff --git a/libkdepim/externalapphandler.h b/libkdepim/externalapphandler.h
index 3ecf1b1..efcdd89 100644
--- a/libkdepim/externalapphandler.h
+++ b/libkdepim/externalapphandler.h
@@ -54,67 +54,86 @@ class DefaultAppItem
54 QString _label; 54 QString _label;
55 QString _channel; 55 QString _channel;
56 QString _message; 56 QString _message;
57 QString _parameters;// a list of parameters in stringrepresentation. Delimiter is ; 57 QString _parameters;// a list of parameters in stringrepresentation. Delimiter is ;
58 QString _message2; 58 QString _message2;
59 QString _parameters2; // a list of parameters in stringrepresentation. Delimiter is ; 59 QString _parameters2; // a list of parameters in stringrepresentation. Delimiter is ;
60 60
61}; 61};
62 62
63class ExternalAppHandler 63class ExternalAppHandler
64{ 64{
65 public: 65 public:
66 virtual ~ExternalAppHandler(); 66 virtual ~ExternalAppHandler();
67 67
68 static ExternalAppHandler *instance(); 68 static ExternalAppHandler *instance();
69 69
70 enum Types { 70 enum Types {
71 EMAIL = 0, 71 EMAIL = 0,
72 PHONE = 1, 72 PHONE = 1,
73 SMS = 2, 73 SMS = 2,
74 FAX = 3, 74 FAX = 3,
75 PAGER = 4 75 PAGER = 4
76 }; 76 };
77 77
78 enum Availability {
79 UNDEFINED = -1,
80 UNAVAILABLE = 0,
81 AVAILABLE = 1
82 };
83
78 //calls the emailapplication with a number of attachments that need to be send 84 //calls the emailapplication with a number of attachments that need to be send
79 bool mailAttachments( const QString& urls ); 85 bool mailAttachments( const QString& urls );
80 86
81 //calls the emailapplication and creates a mail with parameter emails as recipients 87 //calls the emailapplication and creates a mail with parameter emails as recipients
82 bool mailToContacts( const QString& emails ); 88 bool mailToContacts( const QString& emails );
83 89
84 //calls the phoneapplication with the number 90 //calls the phoneapplication with the number
85 bool callByPhone( const QString& phonenumber ); 91 bool callByPhone( const QString& phonenumber );
86 92
87 //calls the smsapplication with the number 93 //calls the smsapplication with the number
88 bool callBySMS( const QString& phonenumber ); 94 bool callBySMS( const QString& phonenumber );
89 95
90 //calls the pagerapplication with the number 96 //calls the pagerapplication with the number
91 bool callByPager( const QString& pagernumber ); 97 bool callByPager( const QString& pagernumber );
92 98
93 //calls the faxapplication with the number 99 //calls the faxapplication with the number
94 bool callByFax( const QString& faxnumber ); 100 bool callByFax( const QString& faxnumber );
95 101
102 bool isEmailAppAvailable();
103 bool isSMSAppAvailable();
104 bool isPhoneAppAvailable();
105 bool isFaxAppAvailable();
106 bool isPagerAppAvailable();
107
108
96 109
97 //loadConfig clears the cache and checks again if the applications are available or not 110 //loadConfig clears the cache and checks again if the applications are available or not
98 void loadConfig(); 111 void loadConfig();
99 112
100 QList<DefaultAppItem> getAvailableDefaultItems(Types); 113 QList<DefaultAppItem> getAvailableDefaultItems(Types);
101 DefaultAppItem* getDefaultItem(Types, int); 114 DefaultAppItem* getDefaultItem(Types, int);
102 115
103 116
104 private: 117 private:
105 ExternalAppHandler(); 118 ExternalAppHandler();
106 QList<DefaultAppItem> mDefaultItems; 119 QList<DefaultAppItem> mDefaultItems;
107 120
121 Availability mEmailAppAvailable;
122 Availability mPhoneAppAvailable;
123 Availability mFaxAppAvailable;
124 Availability mSMSAppAvailable;
125 Availability mPagerAppAvailable;
126
108 127
109 void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2); 128 void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2);
110 129
111 QString& translateMessage(QString& message, const QString& emails) const; 130 QString& translateMessage(QString& message, const QString& emails) const;
112 void passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const; 131 void passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const;
113 132
114 133
115 static ExternalAppHandler *sInstance; 134 static ExternalAppHandler *sInstance;
116 135
117 136
118}; 137};
119 138
120#endif 139#endif