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 <kmailinterface.h>
28 #include <korganizerinterface.h>
29 #include <Akonadi/Contact/ContactEditorDialog>
31 #include <kiconloader.h>
35 #include <ktoolinvocation.h>
39 bool UriHandler::process(const QString
&uri
, const Akonadi::Item
&item
)
43 if (uri
.startsWith(QLatin1String("kmail:"))) {
44 // make sure kmail is running or the part is shown
45 KToolInvocation::startServiceByDesktopPath(QLatin1String("kmail"));
48 int colon
= uri
.indexOf(QLatin1Char(':'));
49 // extract 'number' from 'kmail:<number>/<id>'
50 QString serialNumberStr
= uri
.mid(colon
+ 1);
51 serialNumberStr
= serialNumberStr
.left(serialNumberStr
.indexOf(QLatin1Char('/')));
53 org::kde::kmail::kmail
kmail(
54 QLatin1String("org.kde.kmail"), QLatin1String("/KMail"), QDBusConnection::sessionBus());
55 kmail
.showMail(serialNumberStr
.toLongLong());
57 } else if (uri
.startsWith(QLatin1String("mailto:"))) {
58 KToolInvocation::invokeMailer(uri
.mid(7), QString());
60 } else if (uri
.startsWith(QLatin1String("uid:"))) {
62 Akonadi::ContactEditorDialog
*dlg
= new Akonadi::ContactEditorDialog(Akonadi::ContactEditorDialog::EditMode
, (QWidget
*)0);
64 dlg
->setContact(item
);
68 qDebug() << "Item is not valid.";
71 } else if (uri
.startsWith(QLatin1String("urn:x-ical"))) {
72 // make sure korganizer is running or the part is shown
73 KToolInvocation::startServiceByDesktopPath(QLatin1String("korganizer"));
75 // we must work around QUrl breakage (it doesn't know about URNs)
76 const QString uid
= QUrl::fromPercentEncoding(uri
.toLatin1()).mid(11);
77 OrgKdeKorganizerKorganizerInterface
korganizerIface(
78 QLatin1String("org.kde.korganizer"), QLatin1String("/Korganizer"), QDBusConnection::sessionBus());
80 return korganizerIface
.showIncidence(uid
);
81 } else if (uri
.startsWith(QLatin1String("akonadi:"))) {
83 const QString mimeType
= QUrlQuery(url
).queryItemValue(QLatin1String("type"));
84 if (mimeType
.toLower() == QLatin1String("message/rfc822")) {
85 // make sure kmail is running or the part is shown
86 KToolInvocation::startServiceByDesktopPath(QLatin1String("kmail"));
88 org::kde::kmail::kmail
kmail(
89 QLatin1String("org.kde.kmail"), QLatin1String("/KMail"), QDBusConnection::sessionBus());
90 kmail
.viewMessage(uri
);
93 } else { // no special URI, let KDE handle it
94 new KRun(QUrl(uri
), 0);