00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "urihandler.h"
00026
00027 #include <libkcal/attachment.h>
00028 #include <libkcal/attachmenthandler.h>
00029 #include <libkcal/calendarresources.h>
00030 #include <libkcal/incidence.h>
00031 using namespace KCal;
00032
00033 #ifndef KORG_NODCOP
00034 #include <dcopclient.h>
00035 #include "kmailIface_stub.h"
00036 #endif
00037
00038 #include <kapplication.h>
00039 #include <kiconloader.h>
00040 #include <klocale.h>
00041 #include <kfiledialog.h>
00042 #include <kmessagebox.h>
00043 #include <kmimetype.h>
00044 #include <kprocess.h>
00045 #include <krun.h>
00046 #include <ktempfile.h>
00047 #include <kdebug.h>
00048 #include <kio/netaccess.h>
00049
00050 #include <tqfile.h>
00051
00052 TQString UriHandler::attachmentNameFromUri( const TQString &uri )
00053 {
00054 TQString tmp;
00055 if ( uri.startsWith( "ATTACH:" ) ) {
00056 tmp = uri.mid( 9 ).section( ':', -1, -1 );
00057 }
00058 return tmp;
00059 }
00060
00061 TQString UriHandler::uidFromUri( const TQString &uri )
00062 {
00063 TQString tmp;
00064 if ( uri.startsWith( "ATTACH:" ) ) {
00065 tmp = uri.mid( 9 ).section( ':', 0, 0 );
00066 } else if ( uri.startsWith( "uid:" ) ) {
00067 tmp = uri.mid( 6 );
00068 }
00069 return tmp;
00070 }
00071
00072 bool UriHandler::process( TQWidget *parent, const TQString &uri )
00073 {
00074 kdDebug(5850) << "UriHandler::process(): " << uri << endl;
00075
00076 #ifndef KORG_NODCOP
00077 if ( uri.startsWith( "kmail:" ) ) {
00078
00079
00080 kapp->startServiceByDesktopPath("kmail");
00081
00082
00083 int colon = uri.find( ':' );
00084
00085 TQString serialNumberStr = uri.mid( colon + 1 );
00086 serialNumberStr = serialNumberStr.left( serialNumberStr.find( '/' ) );
00087
00088 KMailIface_stub kmailIface( "kmail", "KMailIface" );
00089 kmailIface.showMail( serialNumberStr.toUInt(), TQString() );
00090 return true;
00091
00092 } else if ( uri.startsWith( "mailto:" ) ) {
00093
00094 KApplication::kApplication()->invokeMailer( uri.mid(7), TQString() );
00095 return true;
00096
00097 } else if ( uri.startsWith( "uid:" ) ) {
00098
00099 TQString uid = uidFromUri( uri );
00100 DCOPClient *client = KApplication::kApplication()->dcopClient();
00101 const TQByteArray noParamData;
00102 const TQByteArray paramData;
00103 TQByteArray replyData;
00104 TQCString replyTypeStr;
00105 bool foundAbbrowser = client->call( "kaddressbook", "KAddressBookIface",
00106 "interfaces()", noParamData,
00107 replyTypeStr, replyData );
00108 if ( foundAbbrowser ) {
00109
00110 #if KDE_IS_VERSION( 3, 2, 90 )
00111 kapp->updateRemoteUserTimestamp("kaddressbook");
00112 #endif
00113 DCOPRef kaddressbook( "kaddressbook", "KAddressBookIface" );
00114 kaddressbook.send( "showContactEditor", uid );
00115 return true;
00116 } else {
00117
00118
00119
00120 TQString iconPath = KGlobal::iconLoader()->iconPath( "go", KIcon::Small );
00121 TQString tmpStr = "kaddressbook --editor-only --uid ";
00122 tmpStr += KProcess::quote( uid );
00123 KRun::runCommand( tmpStr, "KAddressBook", iconPath );
00124 return true;
00125 }
00126
00127 } else if ( uri.startsWith( "ATTACH:" ) ) {
00128
00129
00130 return AttachmentHandler::view( parent, attachmentNameFromUri( uri ), uidFromUri( uri ) );
00131
00132 } else {
00133 new KRun( KURL( uri ) );
00134 }
00135 #endif
00136
00137 return false;
00138 }