urihandler.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 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 // make sure kmail is running or the part is shown 00080 kapp->startServiceByDesktopPath("kmail"); 00081 00082 // parse string, show 00083 int colon = uri.find( ':' ); 00084 // extract 'number' from 'kmail:<number>/<id>' 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 // KAddressbook is already running, so just DCOP to it to bring up the contact editor 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 // KaddressBook is not already running. 00118 // Pass it the UID of the contact via the command line while starting it - its neater. 00119 // We start it without its main interface 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 // a calendar incidence attachment 00130 return AttachmentHandler::view( parent, attachmentNameFromUri( uri ), uidFromUri( uri ) ); 00131 00132 } else { // no special URI, let KDE handle it 00133 new KRun( KURL( uri ) ); 00134 } 00135 #endif 00136 00137 return false; 00138 }