summaryrefslogtreecommitdiffabout
path: root/libkdepim/externalapphandler.cpp
authorulf69 <ulf69>2004-08-10 16:10:42 (UTC)
committer ulf69 <ulf69>2004-08-10 16:10:42 (UTC)
commitc56c4729e32a9c8ba8709493b3ea11cf7cf229d3 (patch) (unidiff)
tree10072e3a37eb3dca26482e67c08229bd2a1cbba6 /libkdepim/externalapphandler.cpp
parentc9d570427f3d5bead7bee1301514a2d4b82836ea (diff)
downloadkdepimpi-c56c4729e32a9c8ba8709493b3ea11cf7cf229d3.zip
kdepimpi-c56c4729e32a9c8ba8709493b3ea11cf7cf229d3.tar.gz
kdepimpi-c56c4729e32a9c8ba8709493b3ea11cf7cf229d3.tar.bz2
additional files for external application configuration
Diffstat (limited to 'libkdepim/externalapphandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp526
1 files changed, 526 insertions, 0 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
new file mode 100644
index 0000000..6f812d0
--- a/dev/null
+++ b/libkdepim/externalapphandler.cpp
@@ -0,0 +1,526 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
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
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30#include <stdlib.h>
31
32#include <qfile.h>
33#include <qmap.h>
34
35
36#include <qtopia/qcopenvelope_qws.h>
37
38
39#include <kstaticdeleter.h>
40
41
42#include "externalapphandler.h"
43
44#include "kpimglobalprefs.h"
45
46
47
48
49
50
51
52ExternalAppHandler *ExternalAppHandler::sInstance = 0;
53static KStaticDeleter<ExternalAppHandler> staticDeleter;
54
55
56ExternalAppHandler::ExternalAppHandler()
57{
58 mDefaultItems.setAutoDelete(true);
59}
60
61ExternalAppHandler::~ExternalAppHandler()
62{
63}
64
65void ExternalAppHandler::loadConfig()
66{
67 mDefaultItems.clear();
68
69
70
71 QString opiepath = QString::fromLatin1( getenv("OPIEDIR") );
72 QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") );
73
74 if (opiepath.isEmpty())
75 opiepath = qtopiapath;
76
77 //mailclients
78 QString mailmsg1 = "writeMail(QString,QString)";
79 QString mailmsg2 = "writeMail(QMap(QString,QString))";
80
81 QString undefined = "undefined";
82
83 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined);
84 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined);
85
86 if (( QFile::exists( qtopiapath + "/bin/ompi" )) ||
87 ( QFile::exists( opiepath + "/bin/ompi" )))
88 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", "newMail(QString)", "%1", mailmsg2, "ATTACHMENT=%1");
89
90 if ( QFile::exists( qtopiapath + "/bin/qtmail" ))
91 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
92
93 if ( QFile::exists( opiepath + "/bin/opiemail" ))
94 addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
95
96
97
98 //phoneclients
99
100 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::NONE_PHC, "No phone client installed", undefined, undefined, undefined, undefined, undefined);
101 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::OTHER_PHC, "Other phone client", undefined, undefined, undefined, undefined, undefined);
102 if (( QFile::exists( qtopiapath + "/bin/kppi" )) ||
103 ( QFile::exists( opiepath + "/bin/kppi" )))
104 addDefaultAppItem(ExternalAppHandler::PHONE, KPimGlobalPrefs::KPPI_PHC, "KP/Pi phone client", "QPE/Application/kppi", "-ring:%1", "", undefined, undefined);
105
106 //faxclients
107 addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::NONE_FAC, "No fax client installed", undefined, undefined, undefined, undefined, undefined);
108 addDefaultAppItem(ExternalAppHandler::FAX, KPimGlobalPrefs::OTHER_FAC, "Other fax client", undefined, undefined, undefined, undefined, undefined);
109
110 //smsclients
111 addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::NONE_SMC, "No sms client installed", undefined, undefined, undefined, undefined, undefined);
112 addDefaultAppItem(ExternalAppHandler::SMS, KPimGlobalPrefs::OTHER_SMC, "Other sms client", undefined, undefined, undefined, undefined, undefined);
113
114 //pagerclients
115 addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::NONE_PAC, "No pager client installed", undefined, undefined, undefined, undefined, undefined);
116 addDefaultAppItem(ExternalAppHandler::PAGER, KPimGlobalPrefs::OTHER_PAC, "Other pager client", undefined, undefined, undefined, undefined, undefined);
117
118}
119
120ExternalAppHandler *ExternalAppHandler::instance()
121{
122 if ( !sInstance ) {
123 sInstance = staticDeleter.setObject( new ExternalAppHandler() );
124 sInstance->loadConfig();
125 }
126
127 return sInstance;
128}
129
130void ExternalAppHandler::addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameter, const QString& message2, const QString& parameter2)
131{
132 DefaultAppItem* dai = new DefaultAppItem(type, id, label, channel, message, parameter, message2, parameter2);
133
134 mDefaultItems.append(dai);
135}
136
137
138QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type)
139{
140 QList<DefaultAppItem> list;
141
142 DefaultAppItem* dai;
143
144 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
145 {
146 if (dai->_type == type)
147 list.append(dai);
148 }
149
150 return list;
151}
152
153DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid)
154{
155 DefaultAppItem* dai;
156
157 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
158 {
159 if (dai->_type == type && dai->_id == clientid)
160 return dai;
161 }
162
163 return 0;
164}
165
166
167
168//calls the emailapplication with a number of attachments that need to be send (Seperated by Comma)
169bool ExternalAppHandler::mailAttachments( const QString& urls )
170{
171#ifndef QT_NO_COP
172 QString channel;
173 QString message2;
174 QString parameters2;
175
176
177 int client = KPimGlobalPrefs::instance()->mEmailClient;
178 if (client == KPimGlobalPrefs::OTHER_EMC)
179 {
180 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
181 message2 = KPimGlobalPrefs::instance()->mEmailOtherMessage;
182 parameters2 = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters;
183 }
184 else
185 {
186 DefaultAppItem* dai = getDefaultItem(EMAIL, client);
187 if (!dai)
188 {
189 qDebug("could not find configured email application.");
190 return false;
191 }
192 channel = dai->_channel;
193 message2 = dai->_message2;
194 parameters2 = dai->_parameters2;
195 }
196
197
198 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1());
199 qDebug("passing attachmenturls:(%s) as parameter in the form %s to QCopEnvelope", urls.latin1(), parameters2.latin1());
200
201 QCopEnvelope e(channel.latin1(), message2.latin1());
202 //US we need no names in the To field. The emailadresses are enough
203
204 passParameter(&e, parameters2, urls);
205
206
207#else
208 KMessageBox::sorry( this, i18n( "This version does not support the sending of emails." ) );
209#endif
210
211 return true;
212}
213
214
215
216//calls the emailapplication and creates a mail with parameter emails as recipients
217bool ExternalAppHandler::mailToContacts( const QString& emails )
218{
219#ifndef QT_NO_COP
220 QString channel;
221 QString message;
222 QString parameters;
223
224
225 int client = KPimGlobalPrefs::instance()->mEmailClient;
226 if (client == KPimGlobalPrefs::OTHER_EMC)
227 {
228 channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
229 message = KPimGlobalPrefs::instance()->mEmailOtherMessage;
230 parameters = KPimGlobalPrefs::instance()->mEmailOtherMessageParameters;
231 }
232 else
233 {
234 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(EMAIL, client);
235 if (!dai)
236 {
237 qDebug("could not find configured email application.");
238 return false;
239 }
240 channel = dai->_channel;
241 message = dai->_message;
242 parameters = dai->_parameters;
243 }
244
245
246 //first check if one of the mailers need the emails right in the message.
247 message = translateMessage(message, emails);
248
249
250 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
251 qDebug("passing emailadresses:(%s) as parameter in the form %s to QCopEnvelope", emails.latin1(), parameters.latin1());
252
253 QCopEnvelope e(channel.latin1(), message.latin1());
254 //US we need no names in the To field. The emailadresses are enough
255
256 passParameter(&e, parameters, emails);
257
258
259#else
260 KMessageBox::sorry( this, i18n( "This version does not support the sending of emails." ) );
261#endif
262
263
264 return true;
265}
266
267
268//calls the phoneapplication with the number
269bool ExternalAppHandler::callByPhone( const QString& phonenumber )
270{
271#ifndef QT_NO_COP
272 QString channel;
273 QString message;
274 QString parameters;
275
276
277 int client = KPimGlobalPrefs::instance()->mPhoneClient;
278 if (client == KPimGlobalPrefs::OTHER_PHC)
279 {
280 channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel;
281 message = KPimGlobalPrefs::instance()->mPhoneOtherMessage;
282 parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters;
283 }
284 else
285 {
286 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PHONE, client);
287 if (!dai)
288 {
289 qDebug("could not find configured phone application.");
290 return false;
291 }
292 channel = dai->_channel;
293 message = dai->_message;
294 parameters = dai->_parameters;
295 }
296
297
298 //first check if one of the mailers need the emails right in the message.
299 message = translateMessage(message, phonenumber);
300
301
302 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
303 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
304
305 QCopEnvelope e(channel.latin1(), message.latin1());
306 //US we need no names in the To field. The emailadresses are enough
307
308 passParameter(&e, parameters, phonenumber);
309
310
311#else
312 KMessageBox::sorry( this, i18n( "This version does not support phonecalls." ) );
313#endif
314
315
316 return true;
317}
318
319//calls the smsapplication with the number
320bool ExternalAppHandler::callBySMS( const QString& phonenumber )
321{
322#ifndef QT_NO_COP
323 QString channel;
324 QString message;
325 QString parameters;
326
327
328 int client = KPimGlobalPrefs::instance()->mSMSClient;
329 if (client == KPimGlobalPrefs::OTHER_SMC)
330 {
331 channel = KPimGlobalPrefs::instance()->mSMSOtherChannel;
332 message = KPimGlobalPrefs::instance()->mSMSOtherMessage;
333 parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters;
334 }
335 else
336 {
337 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(SMS, client);
338 if (!dai)
339 {
340 qDebug("could not find configured sms application.");
341 return false;
342 }
343 channel = dai->_channel;
344 message = dai->_message;
345 parameters = dai->_parameters;
346 }
347
348
349 //first check if one of the mailers need the emails right in the message.
350 message = translateMessage(message, phonenumber);
351
352
353 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
354 qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
355
356 QCopEnvelope e(channel.latin1(), message.latin1());
357 //US we need no names in the To field. The emailadresses are enough
358
359 passParameter(&e, parameters, phonenumber);
360
361
362#else
363 KMessageBox::sorry( this, i18n( "This version does not support the sending of sms." ) );
364#endif
365
366
367 return true;
368}
369
370//calls the pagerapplication with the number
371bool ExternalAppHandler::callByPager( const QString& pagernumber )
372{
373#ifndef QT_NO_COP
374 QString channel;
375 QString message;
376 QString parameters;
377
378
379 int client = KPimGlobalPrefs::instance()->mPagerClient;
380 if (client == KPimGlobalPrefs::OTHER_PAC)
381 {
382 channel = KPimGlobalPrefs::instance()->mPagerOtherChannel;
383 message = KPimGlobalPrefs::instance()->mPagerOtherMessage;
384 parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters;
385 }
386 else
387 {
388 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(PAGER, client);
389 if (!dai)
390 {
391 qDebug("could not find configured pager application.");
392 return false;
393 }
394 channel = dai->_channel;
395 message = dai->_message;
396 parameters = dai->_parameters;
397 }
398
399
400 //first check if one of the mailers need the emails right in the message.
401 message = translateMessage(message, pagernumber);
402
403
404 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
405 qDebug("passing pagernumber:(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1());
406
407 QCopEnvelope e(channel.latin1(), message.latin1());
408 //US we need no names in the To field. The emailadresses are enough
409
410 passParameter(&e, parameters, pagernumber);
411
412
413#else
414 KMessageBox::sorry( this, i18n( "This version does not support paging." ) );
415#endif
416
417
418 return true;
419}
420
421//calls the faxapplication with the number
422bool ExternalAppHandler::callByFax( const QString& faxnumber )
423{
424#ifndef QT_NO_COP
425 QString channel;
426 QString message;
427 QString parameters;
428
429
430 int client = KPimGlobalPrefs::instance()->mFaxClient;
431 if (client == KPimGlobalPrefs::OTHER_FAC)
432 {
433 channel = KPimGlobalPrefs::instance()->mFaxOtherChannel;
434 message = KPimGlobalPrefs::instance()->mFaxOtherMessage;
435 parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters;
436 }
437 else
438 {
439 DefaultAppItem* dai = ExternalAppHandler::getDefaultItem(FAX, client);
440 if (!dai)
441 {
442 qDebug("could not find configured fax application.");
443 return false;
444 }
445 channel = dai->_channel;
446 message = dai->_message;
447 parameters = dai->_parameters;
448 }
449
450
451 //first check if one of the mailers need the emails right in the message.
452 message = translateMessage(message, faxnumber);
453
454
455 qDebug("Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
456 qDebug("passing faxnumber:(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1());
457
458 QCopEnvelope e(channel.latin1(), message.latin1());
459 //US we need no names in the To field. The emailadresses are enough
460
461 passParameter(&e, parameters, faxnumber);
462
463
464#else
465 KMessageBox::sorry( this, i18n( "This version does not support the sending of faxes." ) );
466#endif
467
468
469 return true;
470}
471
472
473
474
475
476
477QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1) const
478{
479 return message.replace( QRegExp("%1"), param1 );
480}
481
482void ExternalAppHandler::passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const
483{
484 QMap<QString, QString> valmap;
485 bool useValMap = false;
486
487 // first extract all parts of the parameters.
488 QStringList paramlist = QStringList::split(";", parameters);
489
490 //Now check how many parts we have.
491 //=0 :no params to pass
492 //>0 :parameters to pass
493 for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it )
494 {
495 QString param = (*it);
496 QStringList keyvallist = QStringList::split("=", param);
497
498 //if we have keyvalue pairs, we assume that we pass a map to the envelope
499 QStringList::Iterator it2 = keyvallist.begin();
500 QString key = (*it2);
501 key = key.replace( QRegExp("%1"), param1 );
502 ++it2;
503
504 if(it2 != keyvallist.end())
505 {
506 QString value = (*it2);
507 value = value.replace( QRegExp("%1"), param1 );
508
509 valmap.insert(key, value);
510 useValMap = true;
511 }
512 else
513 {
514 (*e) << key.latin1();
515 }
516 }
517
518 if (useValMap == true)
519 (*e) << valmap;
520
521
522
523}
524
525
526