SVN_SILENT made messages (after extraction)
[kdepim.git] / libkdepimdbusinterfaces / urihandler.cpp
blob4243505f968be5b28113bf0c14cd21b0eec7ac92
1 /*
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>
32 #include <krun.h>
33 #include <kshell.h>
34 #include <qdebug.h>
35 #include <ktoolinvocation.h>
36 #include <QUrl>
37 #include <QObject>
39 bool UriHandler::process(const QString &uri, const Akonadi::Item &item)
41 qDebug() << uri;
43 if (uri.startsWith(QLatin1String("kmail:"))) {
44 // make sure kmail is running or the part is shown
45 KToolInvocation::startServiceByDesktopPath(QLatin1String("kmail"));
47 // parse string, show
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());
56 return true;
57 } else if (uri.startsWith(QLatin1String("mailto:"))) {
58 KToolInvocation::invokeMailer(uri.mid(7), QString());
59 return true;
60 } else if (uri.startsWith(QLatin1String("uid:"))) {
62 Akonadi::ContactEditorDialog *dlg = new Akonadi::ContactEditorDialog(Akonadi::ContactEditorDialog::EditMode, (QWidget *)0);
63 if (item.isValid()) {
64 dlg->setContact(item);
65 dlg->show();
66 return true;
67 } else {
68 qDebug() << "Item is not valid.";
69 return false;
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:"))) {
82 const QUrl url(uri);
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);
91 return true;
93 } else { // no special URI, let KDE handle it
94 new KRun(QUrl(uri), 0);
97 return false;