summaryrefslogtreecommitdiffabout
path: root/libkdepim/externalapphandler.cpp
Unidiff
Diffstat (limited to 'libkdepim/externalapphandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
index f376e6c..3fc548a 100644
--- a/libkdepim/externalapphandler.cpp
+++ b/libkdepim/externalapphandler.cpp
@@ -26,33 +26,35 @@ Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30#include <stdlib.h> 30#include <stdlib.h>
31 31
32#include <qfile.h> 32#include <qfile.h>
33#include <qtimer.h> 33#include <qtimer.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qregexp.h> 35#include <qregexp.h>
36 36
37#ifndef DESKTOP_VERSION 37#ifndef DESKTOP_VERSION
38#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
39#include <qtopia/qcopenvelope_qws.h> 39#include <qtopia/qcopenvelope_qws.h>
40#else 40#else
41#include <qapplication.h> 41#include <qapplication.h>
42#include <qprocess.h> 42#include <q3process.h>
43//Added by qt3to4:
44#include <Q3CString>
43#endif 45#endif
44 46
45#include <kstaticdeleter.h> 47#include <kstaticdeleter.h>
46#include <kmessagebox.h> 48#include <kmessagebox.h>
47 49
48 50
49#include "externalapphandler.h" 51#include "externalapphandler.h"
50 52
51#include "kpimglobalprefs.h" 53#include "kpimglobalprefs.h"
52 54
53//uncomment line to get debug output 55//uncomment line to get debug output
54//#define DEBUG_EXT_APP_HANDLER 56//#define DEBUG_EXT_APP_HANDLER
55 57
56/********************************************************************************* 58/*********************************************************************************
57 * 59 *
58 ********************************************************************************/ 60 ********************************************************************************/
@@ -110,56 +112,56 @@ bool QCopTransferItem::sendMessageToTarget(const QString& uid, const QString& pa
110 return false; 112 return false;
111#endif 113#endif
112 114
113} 115}
114 116
115 117
116/*********************************************************************************/ 118/*********************************************************************************/
117void QCopTransferItem::setSourceChannel(const QString& sourceChannel) 119void QCopTransferItem::setSourceChannel(const QString& sourceChannel)
118{ 120{
119 121
120 if ( !sourceChannel.isEmpty()) 122 if ( !sourceChannel.isEmpty())
121 _sourceChannel = sourceChannel; 123 _sourceChannel = sourceChannel;
122} 124}
123 125
124 126
125/*********************************************************************************/ 127/*********************************************************************************/
126bool QCopTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) 128bool QCopTransferItem::appMessage( const Q3CString& cmsg, const QByteArray& data )
127{ 129{
128 130
129 // copied from old mail2 131 // copied from old mail2
130/* 132/*
131 static int ii = 0; 133 static int ii = 0;
132 134
133 // block second call 135 // block second call
134 if ( ii < 2 ) { 136 if ( ii < 2 ) {
135 ++ii; 137 ++ii;
136 if ( ii > 1 ) { 138 if ( ii > 1 ) {
137 qDebug("qcop call blocked "); 139 qDebug("qcop call blocked ");
138 return true; 140 return true;
139 } 141 }
140 } 142 }
141*/ 143*/
142 144
143// qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() ); 145// qDebug("QCopTransferItem- QCOP message received: %s ", cmsg.data() );
144 146
145 //we are in the target and get a request from the source 147 //we are in the target and get a request from the source
146 if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data()) 148 if ( (_sourceMessage + _sourceMessageParameters) == cmsg.data())
147 { 149 {
148 150
149 QDataStream stream( data, IO_ReadOnly ); 151 QDataStream stream( const_cast<QByteArray*>(&data), QIODevice::ReadOnly );
150 152
151 153
152 QString sourceChannel; 154 QString sourceChannel;
153 QString uid; 155 QString uid;
154 QString param1; 156 QString param1;
155 QString param2; 157 QString param2;
156 QString param3; 158 QString param3;
157 159
158 stream >> sourceChannel >> uid; 160 stream >> sourceChannel >> uid;
159 161
160 if (_usedSourceParameters == 0) 162 if (_usedSourceParameters == 0)
161 { 163 {
162 emit receivedMessageFromSource(sourceChannel, uid); 164 emit receivedMessageFromSource(sourceChannel, uid);
163 } 165 }
164 else if (_usedSourceParameters == 1) 166 else if (_usedSourceParameters == 1)
165 { 167 {
@@ -213,39 +215,39 @@ bool QCopMapTransferItem::sendMessageToSource(const QString& uid, const QMap<QSt
213 215
214 e << uid << nameEmailMap; 216 e << uid << nameEmailMap;
215 217
216 qApp->processEvents(); 218 qApp->processEvents();
217 219
218 return true; 220 return true;
219 221
220#else 222#else
221 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); 223 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) );
222 return false; 224 return false;
223#endif 225#endif
224 226
225} 227}
226 228
227 229
228/*********************************************************************************/ 230/*********************************************************************************/
229bool QCopMapTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) 231bool QCopMapTransferItem::appMessage( const Q3CString& cmsg, const QByteArray& data )
230{ 232{
231 bool res = QCopTransferItem::appMessage( cmsg, data ); 233 bool res = QCopTransferItem::appMessage( cmsg, data );
232 234
233 if (res == false) 235 if (res == false)
234 { 236 {
235 QDataStream stream( data, IO_ReadOnly ); 237 QDataStream stream( const_cast<QByteArray*>(&data), QIODevice::ReadOnly );
236 238
237// qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() ); 239// qDebug("QCopMapTransferItem- QCOP message received: %s ", cmsg.data() );
238 240
239 //we are in the source and get an answer from the target 241 //we are in the source and get an answer from the target
240 if ((_targetMessage + _targetMessageParameters) == cmsg.data()) 242 if ((_targetMessage + _targetMessageParameters) == cmsg.data())
241 { 243 {
242 QMap<QString,QString> adrMap; 244 QMap<QString,QString> adrMap;
243 QString uid; 245 QString uid;
244 246
245 stream >> uid >> adrMap; 247 stream >> uid >> adrMap;
246 248
247 emit receivedMessageFromTarget(uid, adrMap); 249 emit receivedMessageFromTarget(uid, adrMap);
248 250
249 251
250 return true; 252 return true;
251 } 253 }
@@ -292,42 +294,42 @@ bool QCopListTransferItem::sendMessageToSource(const QString& uid, const QString
292 294
293 e << uid << list1 << list2 << list3 << list4 << list5 << list6; 295 e << uid << list1 << list2 << list3 << list4 << list5 << list6;
294 296
295 qApp->processEvents(); 297 qApp->processEvents();
296 298
297 return true; 299 return true;
298 300
299#else 301#else
300 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) ); 302 KMessageBox::sorry( 0, i18n( "This version does not support QCop." ) );
301 return false; 303 return false;
302#endif 304#endif
303 305
304} 306}
305 307
306 308
307/*********************************************************************************/ 309/*********************************************************************************/
308bool QCopListTransferItem::appMessage( const QCString& cmsg, const QByteArray& data ) 310bool QCopListTransferItem::appMessage( const Q3CString& cmsg, const QByteArray& data )
309{ 311{
310 bool res = QCopTransferItem::appMessage( cmsg, data ); 312 bool res = QCopTransferItem::appMessage( cmsg, data );
311#ifdef DEBUG_EXT_APP_HANDLER 313#ifdef DEBUG_EXT_APP_HANDLER
312 qDebug("1QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); 314 qDebug("1QCopListTransferItem- QCOP message received: %s ", cmsg.data() );
313#endif 315#endif
314 316
315 if (res == false) 317 if (res == false)
316 { 318 {
317 QDataStream stream( data, IO_ReadOnly ); 319 QDataStream stream( const_cast<QByteArray*>(&data), QIODevice::ReadOnly );
318 320
319#ifdef DEBUG_EXT_APP_HANDLER 321#ifdef DEBUG_EXT_APP_HANDLER
320 qDebug("2QCopListTransferItem- QCOP message received: %s ", cmsg.data() ); 322 qDebug("2QCopListTransferItem- QCOP message received: %s ", cmsg.data() );
321#endif 323#endif
322 324
323 //we are in the source and get an answer from the target 325 //we are in the source and get an answer from the target
324 if ((_targetMessage + _targetMessageParameters) == cmsg.data()) 326 if ((_targetMessage + _targetMessageParameters) == cmsg.data())
325 { 327 {
326 QStringList list1; 328 QStringList list1;
327 QStringList list2; 329 QStringList list2;
328 QStringList list3; 330 QStringList list3;
329 QStringList list4; 331 QStringList list4;
330 QStringList list5; 332 QStringList list5;
331 QStringList list6; 333 QStringList list6;
332 QString uid; 334 QString uid;
333 335
@@ -505,35 +507,35 @@ ExternalAppHandler *ExternalAppHandler::instance()
505 if ( !sInstance ) { 507 if ( !sInstance ) {
506 sInstance = staticDeleter.setObject( new ExternalAppHandler() ); 508 sInstance = staticDeleter.setObject( new ExternalAppHandler() );
507 sInstance->loadConfig(); 509 sInstance->loadConfig();
508 } 510 }
509 511
510 return sInstance; 512 return sInstance;
511} 513}
512 514
513void ExternalAppHandler::addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameter, const QString& message2, const QString& parameter2) 515void ExternalAppHandler::addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameter, const QString& message2, const QString& parameter2)
514{ 516{
515 DefaultAppItem* dai = new DefaultAppItem(type, id, label, channel, message, parameter, message2, parameter2); 517 DefaultAppItem* dai = new DefaultAppItem(type, id, label, channel, message, parameter, message2, parameter2);
516 // qDebug("%d %d %s %s ", type, id, label.latin1(), channel.latin1() ); 518 // qDebug("%d %d %s %s ", type, id, label.latin1(), channel.latin1() );
517 mDefaultItems.append(dai); 519 mDefaultItems.append(dai);
518} 520}
519 521
520 522
521QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type) 523Q3PtrList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type)
522{ 524{
523 QList<DefaultAppItem> list; 525 Q3PtrList<DefaultAppItem> list;
524 526
525 DefaultAppItem* dai; 527 DefaultAppItem* dai;
526 528
527 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() ) 529 for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
528 { 530 {
529 if (dai->_type == type) 531 if (dai->_type == type)
530 list.append(dai); 532 list.append(dai);
531 } 533 }
532 534
533 return list; 535 return list;
534} 536}
535 537
536DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid) 538DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid)
537{ 539{
538 DefaultAppItem* dai; 540 DefaultAppItem* dai;
539 541
@@ -733,59 +735,59 @@ bool ExternalAppHandler::mailToMultipleContacts( const QString& emails, const QS
733 } 735 }
734 channel = dai->_channel; 736 channel = dai->_channel;
735 message2 = dai->_message2; 737 message2 = dai->_message2;
736 parameters2 = dai->_parameters2; 738 parameters2 = dai->_parameters2;
737 message = dai->_message; 739 message = dai->_message;
738 parameters = dai->_parameters; 740 parameters = dai->_parameters;
739 } 741 }
740 742
741 //first check if one of the mailers need the emails right in the message. 743 //first check if one of the mailers need the emails right in the message.
742 message2 = translateMessage(message2, emails, urls); 744 message2 = translateMessage(message2, emails, urls);
743#ifdef DEBUG_EXT_APP_HANDLER 745#ifdef DEBUG_EXT_APP_HANDLER
744 qDebug("4Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1()); 746 qDebug("4Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message2.latin1());
745 qDebug("passing emailadresses(%s), attachmenturls(%s) as parameters in the form %s to QCopEnvelope", emails.latin1() , urls.latin1(), parameters2.latin1()); 747 qDebug("passing emailadresses(%s), attachmenturls(%s) as parameters in the form %s to QCopEnvelope", emails.latin1() , urls.latin1(), parameters2.latin1());
746#endif 748#endif
747 qDebug("%s --- %s %s --- %s %s", channel.latin1(), message.latin1(),message2.latin1(), parameters.latin1(), parameters2.latin1() ); 749 qDebug("%s --- %s %s --- %s %s", channel.latin1(), message.latin1(),message2.latin1(), parameters.latin1(), parameters2.latin1() );
748 //KMessageBox::sorry( 0, message2 ); 750 //KMessageBox::sorry( 0, message2 );
749 QProcess * proc = new QProcess( this ); 751 Q3Process * proc = new Q3Process( this );
750 int i = 0; 752 int i = 0;
751 proc->addArgument( channel ); 753 proc->addArgument( channel );
752 754
753 if ( message.find (" " ) > 0 ) { 755 if ( message.find (" " ) > 0 ) {
754 QStringList list = QStringList::split( " ", message ); 756 QStringList list = QStringList::split( " ", message );
755 int i = 0; 757 int i = 0;
756 while ( i < list.count ( ) ) { 758 while ( i < list.count ( ) ) {
757 //qDebug("add%sdd ",list[i].latin1() ); 759 //qDebug("add%sdd ",list[i].latin1() );
758 proc->addArgument( list[i] ); 760 proc->addArgument( list[i] );
759 //KMessageBox::sorry( 0,list[i]); 761 //KMessageBox::sorry( 0,list[i]);
760 ++i; 762 ++i;
761 } 763 }
762 } else { 764 } else {
763 proc->addArgument(message ); 765 proc->addArgument(message );
764 //KMessageBox::sorry( 0, message ); 766 //KMessageBox::sorry( 0, message );
765 767
766 } 768 }
767 769
768 parameters2 = translateMessage(parameters2, urls, "" ); 770 parameters2 = translateMessage(parameters2, urls, "" );
769 QString arg = "to='%1'"; 771 QString arg = "to='%1'";
770 arg = arg.arg( emails ) + ","+parameters2;; 772 arg = arg.arg( emails ) + ","+parameters2;;
771 773
772 //KMessageBox::sorry( 0,arg ); 774 //KMessageBox::sorry( 0,arg );
773 //qDebug("2add%sdd ",arg.latin1() ); 775 //qDebug("2add%sdd ",arg.latin1() );
774 proc->addArgument( arg); 776 proc->addArgument( arg);
775 proc->launch(""); 777 proc->launch(QString());
776#endif 778#endif
777 779
778 return true; 780 return true;
779} 781}
780 782
781/************************************************************************** 783/**************************************************************************
782 * 784 *
783 **************************************************************************/ 785 **************************************************************************/
784 786
785 787
786//calls the emailapplication and creates a mail with parameter emails as recipients 788//calls the emailapplication and creates a mail with parameter emails as recipients
787bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& emailadress ) 789bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& emailadress )
788{ 790{
789 791
790 QString channel; 792 QString channel;
791 QString message; 793 QString message;
@@ -818,52 +820,52 @@ bool ExternalAppHandler::mailToOneContact( const QString& name, const QString& e
818 //first check if one of the mailers need the emails right in the message. 820 //first check if one of the mailers need the emails right in the message.
819 message = translateMessage(message, name, emailadress); 821 message = translateMessage(message, name, emailadress);
820 822
821#ifdef DEBUG_EXT_APP_HANDLER 823#ifdef DEBUG_EXT_APP_HANDLER
822 qDebug("5Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1()); 824 qDebug("5Using QCopEnvelope e(\"%s\",\"%s\")", channel.latin1(), message.latin1());
823 qDebug("passing name(%s), emailadresses(%s) as parameters in the form %s to QCopEnvelope", name.latin1(), emailadress.latin1(), parameters.latin1()); 825 qDebug("passing name(%s), emailadresses(%s) as parameters in the form %s to QCopEnvelope", name.latin1(), emailadress.latin1(), parameters.latin1());
824#endif 826#endif
825 827
826#ifndef DESKTOP_VERSION 828#ifndef DESKTOP_VERSION
827 QCopEnvelope e(channel.latin1(), message.latin1()); 829 QCopEnvelope e(channel.latin1(), message.latin1());
828 //US we need no names in the To field. The emailadresses are enough 830 //US we need no names in the To field. The emailadresses are enough
829 831
830 passParameters(&e, parameters, name, emailadress); 832 passParameters(&e, parameters, name, emailadress);
831#else // DESKTOP_VERSION 833#else // DESKTOP_VERSION
832 834
833 //KMessageBox::sorry( 0,channel ); 835 //KMessageBox::sorry( 0,channel );
834 QProcess * proc = new QProcess( this ); 836 Q3Process * proc = new Q3Process( this );
835 proc->addArgument( channel ); 837 proc->addArgument( channel );
836 if ( message.find (" " ) > 0 ) { 838 if ( message.find (" " ) > 0 ) {
837 QStringList list = QStringList::split( " ", message ); 839 QStringList list = QStringList::split( " ", message );
838 int i = 0; 840 int i = 0;
839 while ( i < list.count ( ) ) { 841 while ( i < list.count ( ) ) {
840 //qDebug("add%sdd ",list[i].latin1() ); 842 //qDebug("add%sdd ",list[i].latin1() );
841 proc->addArgument( list[i] ); 843 proc->addArgument( list[i] );
842 //KMessageBox::sorry( 0,list[i]); 844 //KMessageBox::sorry( 0,list[i]);
843 ++i; 845 ++i;
844 } 846 }
845 } else { 847 } else {
846 proc->addArgument(message ); 848 proc->addArgument(message );
847 849
848 } 850 }
849 parameters = translateMessage(parameters, name, emailadress); 851 parameters = translateMessage(parameters, name, emailadress);
850 852
851 //KMessageBox::information(0,parameters); 853 //KMessageBox::information(0,parameters);
852 proc->addArgument( parameters ); 854 proc->addArgument( parameters );
853 proc->launch(""); 855 proc->launch(QString());
854#endif 856#endif
855 857
856 return true; 858 return true;
857} 859}
858 860
859/************************************************************************** 861/**************************************************************************
860 * 862 *
861 **************************************************************************/ 863 **************************************************************************/
862 864
863//calls the emailapplication and creates a mail with parameter as recipients 865//calls the emailapplication and creates a mail with parameter as recipients
864// parameters format is 866// parameters format is
865// NAME <EMAIL>:SUBJECT 867// NAME <EMAIL>:SUBJECT
866bool ExternalAppHandler::mailToOneContact( const QString& adressline ) 868bool ExternalAppHandler::mailToOneContact( const QString& adressline )
867{ 869{
868 QString line = adressline; 870 QString line = adressline;
869 871
@@ -1219,33 +1221,33 @@ void ExternalAppHandler::passParameters(QCopEnvelope* e, const QString& paramete
1219 } 1221 }
1220 } 1222 }
1221 1223
1222 if (useValMap == true) 1224 if (useValMap == true)
1223 (*e) << valmap; 1225 (*e) << valmap;
1224 1226
1225#endif 1227#endif
1226 1228
1227} 1229}
1228 1230
1229 1231
1230 1232
1231/************************************************************************** 1233/**************************************************************************
1232 * 1234 *
1233 **************************************************************************/ 1235 **************************************************************************/
1234 1236
1235void ExternalAppHandler::appMessage( const QCString& cmsg, const QByteArray& data ) 1237void ExternalAppHandler::appMessage( const Q3CString& cmsg, const QByteArray& data )
1236{ 1238{
1237 qDebug("ExternalAppHandler::appMessage %s %x", cmsg.data(), this); 1239 qDebug("ExternalAppHandler::appMessage %s %x", cmsg.data(), this);
1238 if ( cmsg == "nextView()" ) { 1240 if ( cmsg == "nextView()" ) {
1239 qDebug("nextView()"); 1241 qDebug("nextView()");
1240 QTimer::singleShot( 0, this, SIGNAL ( nextView() )); 1242 QTimer::singleShot( 0, this, SIGNAL ( nextView() ));
1241 return; 1243 return;
1242 } 1244 }
1243 if ( cmsg == "callContactdialog()" ) { 1245 if ( cmsg == "callContactdialog()" ) {
1244 qDebug("callContactdialog()"); 1246 qDebug("callContactdialog()");
1245 QTimer::singleShot( 0, this, SIGNAL ( callContactdialog() )); 1247 QTimer::singleShot( 0, this, SIGNAL ( callContactdialog() ));
1246 return; 1248 return;
1247 } 1249 }
1248 if ( cmsg == "doRingSync" ) { 1250 if ( cmsg == "doRingSync" ) {
1249 qDebug("doRingSync"); 1251 qDebug("doRingSync");
1250 QTimer::singleShot( 0, this, SIGNAL ( doRingSync() )); 1252 QTimer::singleShot( 0, this, SIGNAL ( doRingSync() ));
1251 return; 1253 return;