korganizer
urihandler.cpp00001
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 <kmdcodec.h>
00043 #include <kmessagebox.h>
00044 #include <kmimetype.h>
00045 #include <kprocess.h>
00046 #include <krun.h>
00047 #include <ktempfile.h>
00048 #include <kdebug.h>
00049 #include <kio/netaccess.h>
00050
00051 #include <qfile.h>
00052
00053 QString UriHandler::attachmentNameFromUri( const QString &uri )
00054 {
00055 QString tmp;
00056 if ( uri.startsWith( "ATTACH:" ) ) {
00057 tmp = uri.mid( 9 ).section( ':', -1, -1 );
00058 const QCString decodedName = KCodecs::base64Decode(tmp.utf8());
00059 tmp = QString::fromUtf8(decodedName.data(), decodedName.length());
00060 }
00061 return tmp;
00062 }
00063
00064 QString UriHandler::uidFromUri( const QString &uri )
00065 {
00066 QString tmp;
00067 if ( uri.startsWith( "ATTACH:" ) ) {
00068 tmp = uri.mid( 9 ).section( ':', 0, 0 );
00069 } else if ( uri.startsWith( "uid:" ) ) {
00070 tmp = uri.mid( 6 );
00071 }
00072 return tmp;
00073 }
00074
00075 bool UriHandler::process( QWidget *parent, const QString &uri )
00076 {
00077 kdDebug(5850) << "UriHandler::process(): " << uri << endl;
00078
00079 #ifndef KORG_NODCOP
00080 if ( uri.startsWith( "kmail:" ) ) {
00081
00082
00083 kapp->startServiceByDesktopPath("kmail");
00084
00085
00086 int colon = uri.find( ':' );
00087
00088 QString serialNumberStr = uri.mid( colon + 1 );
00089 serialNumberStr = serialNumberStr.left( serialNumberStr.find( '/' ) );
00090
00091 KMailIface_stub kmailIface( "kmail", "KMailIface" );
00092 kmailIface.showMail( serialNumberStr.toUInt(), QString() );
00093 return true;
00094
00095 } else if ( uri.startsWith( "mailto:" ) ) {
00096
00097 KApplication::kApplication()->invokeMailer( uri.mid(7), QString::null );
00098 return true;
00099
00100 } else if ( uri.startsWith( "uid:" ) ) {
00101
00102 QString uid = uidFromUri( uri );
00103 DCOPClient *client = KApplication::kApplication()->dcopClient();
00104 const QByteArray noParamData;
00105 const QByteArray paramData;
00106 QByteArray replyData;
00107 QCString replyTypeStr;
00108 bool foundAbbrowser = client->call( "kaddressbook", "KAddressBookIface",
00109 "interfaces()", noParamData,
00110 replyTypeStr, replyData );
00111 if ( foundAbbrowser ) {
00112
00113 #if KDE_IS_VERSION( 3, 2, 90 )
00114 kapp->updateRemoteUserTimestamp("kaddressbook");
00115 #endif
00116 DCOPRef kaddressbook( "kaddressbook", "KAddressBookIface" );
00117 kaddressbook.send( "showContactEditor", uid );
00118 return true;
00119 } else {
00120
00121
00122
00123 QString iconPath = KGlobal::iconLoader()->iconPath( "go", KIcon::Small );
00124 QString tmpStr = "kaddressbook --editor-only --uid ";
00125 tmpStr += KProcess::quote( uid );
00126 KRun::runCommand( tmpStr, "KAddressBook", iconPath );
00127 return true;
00128 }
00129
00130 } else if ( uri.startsWith( "ATTACH:" ) ) {
00131
00132
00133 return AttachmentHandler::view( parent, attachmentNameFromUri( uri ), uidFromUri( uri ) );
00134
00135 } else {
00136 new KRun( KURL( uri ) );
00137 }
00138 #endif
00139
00140 return false;
00141 }
|