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 #ifndef KORG_NODCOP
00028 #include <dcopclient.h>
00029 #include "kmailIface_stub.h"
00030 #endif
00031 
00032 #include <kiconloader.h>
00033 #include <krun.h>
00034 #include <kapplication.h>
00035 #include <kprocess.h>
00036 #include <kdebug.h>
00037 
00038 bool UriHandler::process( const QString &uri )
00039 {
00040   kdDebug(5850) << "UriHandler::process(): " << uri << endl;
00041 
00042 #ifndef KORG_NODCOP
00043   if ( uri.startsWith( "kmail:" ) ) {
00044     // make sure kmail is running or the part is shown
00045     kapp->startServiceByDesktopPath("kmail");
00046 
00047     // parse string, show
00048     int colon = uri.find( ':' );
00049     // extract 'number' from 'kmail:<number>/<id>'
00050     QString serialNumberStr = uri.mid( colon + 1 );
00051     serialNumberStr = serialNumberStr.left( serialNumberStr.find( '/' ) );
00052 
00053     KMailIface_stub kmailIface( "kmail", "KMailIface" );
00054     kmailIface.showMail( serialNumberStr.toUInt(), QString() );
00055     return true;
00056   } else if ( uri.startsWith( "mailto:" ) ) {
00057     KApplication::kApplication()->invokeMailer( uri.mid(7), QString::null );
00058     return true;
00059   } else if ( uri.startsWith( "uid:" ) ) {
00060     DCOPClient *client = KApplication::kApplication()->dcopClient();
00061     const QByteArray noParamData;
00062     const QByteArray paramData;
00063     QByteArray replyData;
00064     QCString replyTypeStr;
00065     bool foundAbbrowser = client->call( "kaddressbook", "KAddressBookIface",
00066                                         "interfaces()",  noParamData,
00067                                         replyTypeStr, replyData );
00068     if ( foundAbbrowser ) {
00069       //KAddressbook is already running, so just DCOP to it to bring up the contact editor
00070 #if KDE_IS_VERSION( 3, 2, 90 )
00071       kapp->updateRemoteUserTimestamp("kaddressbook");
00072 #endif
00073       DCOPRef kaddressbook( "kaddressbook", "KAddressBookIface" );
00074       kaddressbook.send( "showContactEditor", uri.mid( 6 ) );
00075       return true;
00076     } else {
00077       /*
00078         KaddressBook is not already running.  Pass it the UID of the contact via the command line while starting it - its neater.
00079         We start it without its main interface
00080       */
00081       QString iconPath = KGlobal::iconLoader()->iconPath( "go", KIcon::Small );
00082       QString tmpStr = "kaddressbook --editor-only --uid ";
00083       tmpStr += KProcess::quote( uri.mid( 6 ) );
00084       KRun::runCommand( tmpStr, "KAddressBook", iconPath );
00085       return true;
00086     }
00087   }
00088   else {  // no special URI, let KDE handle it
00089     new KRun(KURL( uri ));
00090   }
00091 #endif
00092 
00093   return false;
00094 }
KDE Home | KDE Accessibility Home | Description of Access Keys