korganizer

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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt 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 <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     // make sure kmail is running or the part is shown
00083     kapp->startServiceByDesktopPath("kmail");
00084 
00085     // parse string, show
00086     int colon = uri.find( ':' );
00087     // extract 'number' from 'kmail:<number>/<id>'
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       // KAddressbook is already running, so just DCOP to it to bring up the contact editor
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       // KaddressBook is not already running.
00121       // Pass it the UID of the contact via the command line while starting it - its neater.
00122       // We start it without its main interface
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     // a calendar incidence attachment
00133     return AttachmentHandler::view( parent, attachmentNameFromUri( uri ), uidFromUri( uri ) );
00134 
00135   } else {  // no special URI, let KDE handle it
00136     new KRun( KURL( uri ) );
00137   }
00138 #endif
00139 
00140   return false;
00141 }
KDE Home | KDE Accessibility Home | Description of Access Keys