2
This file is part of KOrganizer.
4
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License along
18
with this program; if not, write to the Free Software Foundation, Inc.,
19
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
As a special exception, permission is given to link this program
22
with any edition of Qt, and distribute the resulting executable,
23
without including the source code for Qt in the source distribution.
26
#include "urihandler.h"
27
#include <knodeinterface.h>
28
#include <kmailinterface.h>
29
#include <korganizerinterface.h>
31
#include <libkdepim/kdepimprotocols.h>
33
#include <kiconloader.h>
35
#include <kapplication.h>
38
#include <ktoolinvocation.h>
42
bool UriHandler::process( const QString &uri )
46
if ( uri.startsWith( KDEPIMPROTOCOL_EMAIL ) ) {
47
// make sure kmail is running or the part is shown
48
KToolInvocation::startServiceByDesktopPath( "kmail" );
51
int colon = uri.indexOf( ':' );
52
// extract 'number' from 'kmail:<number>/<id>'
53
QString serialNumberStr = uri.mid( colon + 1 );
54
serialNumberStr = serialNumberStr.left( serialNumberStr.indexOf( '/' ) );
56
org::kde::kmail::kmail kmail(
57
"org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
58
kmail.showMail( serialNumberStr.toUInt(), QString() );
60
} else if ( uri.startsWith( QLatin1String( "mailto:" ) ) ) {
61
KToolInvocation::invokeMailer( uri.mid(7), QString() );
63
} else if ( uri.startsWith( KDEPIMPROTOCOL_CONTACT ) ) {
64
if ( QDBusConnection::sessionBus().interface()->isServiceRegistered(
65
"org.kde.kaddressbook" ) ) {
66
/*FIXME: use external contact viewer
67
kapp->updateRemoteUserTimestamp( "org.kde.kaddressbook" );
68
org::kde::KAddressbook::Core kaddressbook(
69
"org.kde.kaddressbook", "/KAddressBook", QDBusConnection::sessionBus() );
70
kaddressbook.showContactEditor( uri.mid( ::qstrlen( KDEPIMPROTOCOL_CONTACT ) ) );
75
KaddressBook is not already running. Pass it the UID of the contact via
76
the command line while starting it - it is neater.
77
We start it without its main interface
80
KIconLoader::global()->iconPath( "view-pim-contacts", KIconLoader::SizeSmall );
82
QString tmpStr = "kaddressbook --editor-only --uid ";
83
tmpStr += KShell::quoteArg( uri.mid( ::qstrlen( KDEPIMPROTOCOL_CONTACT ) ) );
85
QString tmpStr = "kaddressbook";
86
KRun::runCommand( tmpStr, "KAddressBook", iconPath, 0 );
89
} else if ( uri.startsWith( KDEPIMPROTOCOL_INCIDENCE ) ) {
90
// make sure korganizer is running or the part is shown
91
KToolInvocation::startServiceByDesktopPath( "korganizer" );
93
// we must work around KUrl breakage (it doesn't know about URNs)
94
QString uid = KUrl::fromPercentEncoding( uri.toLatin1() ).mid( 11 );
95
OrgKdeKorganizerKorganizerInterface korganizerIface(
96
"org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
98
return korganizerIface.showIncidence( uid );
99
} else if ( uri.startsWith( KDEPIMPROTOCOL_NEWSARTICLE ) ) {
100
KToolInvocation::startServiceByDesktopPath( "knode" );
101
org::kde::knode knode(
102
"org.kde.knode", "/KNode", QDBusConnection::sessionBus() );
103
knode.openURL( uri );
104
} else { // no special URI, let KDE handle it
105
new KRun( KUrl( uri ), 0 );