korganizer

urihandler.cpp
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "urihandler.h"
26
27#include <libkcal/attachment.h>
30#include <libkcal/incidence.h>
31using namespace KCal;
32
33#ifndef KORG_NODCOP
34#include <dcopclient.h>
35#include "kmailIface_stub.h"
36#endif
37
38#include <tdeapplication.h>
39#include <kiconloader.h>
40#include <tdelocale.h>
41#include <tdefiledialog.h>
42#include <tdemessagebox.h>
43#include <kmimetype.h>
44#include <tdeprocess.h>
45#include <krun.h>
46#include <tdetempfile.h>
47#include <kdebug.h>
48#include <tdeio/netaccess.h>
49
50#include <tqfile.h>
51
52TQString UriHandler::attachmentNameFromUri( const TQString &uri )
53{
54 TQString tmp;
55 if ( uri.startsWith( "ATTACH:" ) ) {
56 tmp = uri.mid( 9 ).section( ':', -1, -1 );
57 }
58 return tmp;
59}
60
61TQString UriHandler::uidFromUri( const TQString &uri )
62{
63 TQString tmp;
64 if ( uri.startsWith( "ATTACH:" ) ) {
65 tmp = uri.mid( 9 ).section( ':', 0, 0 );
66 } else if ( uri.startsWith( "uid:" ) ) {
67 tmp = uri.mid( 6 );
68 }
69 return tmp;
70}
71
72bool UriHandler::process( TQWidget *parent, const TQString &uri )
73{
74 kdDebug(5850) << "UriHandler::process(): " << uri << endl;
75
76#ifndef KORG_NODCOP
77 if ( uri.startsWith( "kmail:" ) ) {
78
79 // make sure kmail is running or the part is shown
80 tdeApp->startServiceByDesktopPath("kmail");
81
82 // parse string, show
83 int colon = uri.find( ':' );
84 // extract 'number' from 'kmail:<number>/<id>'
85 TQString serialNumberStr = uri.mid( colon + 1 );
86 serialNumberStr = serialNumberStr.left( serialNumberStr.find( '/' ) );
87
88 KMailIface_stub kmailIface( "kmail", "KMailIface" );
89 kmailIface.showMail( serialNumberStr.toUInt(), TQString() );
90 return true;
91
92 } else if ( uri.startsWith( "mailto:" ) ) {
93
94 tdeApp->invokeMailer( uri.mid(7), TQString() );
95 return true;
96
97 } else if ( uri.startsWith( "uid:" ) ) {
98
99 TQString uid = uidFromUri( uri );
100 DCOPClient *client = tdeApp->dcopClient();
101 const TQByteArray noParamData;
102 const TQByteArray paramData;
103 TQByteArray replyData;
104 TQCString replyTypeStr;
105 bool foundAbbrowser = client->call( "kaddressbook", "KAddressBookIface",
106 "interfaces()", noParamData,
107 replyTypeStr, replyData );
108 if ( foundAbbrowser ) {
109 // KAddressbook is already running, so just DCOP to it to bring up the contact editor
110 tdeApp->updateRemoteUserTimestamp("kaddressbook");
111 DCOPRef kaddressbook( "kaddressbook", "KAddressBookIface" );
112 kaddressbook.send( "showContactEditor", uid );
113 return true;
114 } else {
115 // KaddressBook is not already running.
116 // Pass it the UID of the contact via the command line while starting it - its neater.
117 // We start it without its main interface
118 TQString iconPath = TDEGlobal::iconLoader()->iconPath( "go", TDEIcon::Small );
119 TQString tmpStr = "kaddressbook --editor-only --uid ";
120 tmpStr += TDEProcess::quote( uid );
121 KRun::runCommand( tmpStr, "KAddressBook", iconPath );
122 return true;
123 }
124
125 } else if ( uri.startsWith( "ATTACH:" ) ) {
126
127 // a calendar incidence attachment
128 return AttachmentHandler::view( parent, attachmentNameFromUri( uri ), uidFromUri( uri ) );
129
130 } else { // no special URI, let KDE handle it
131 new KRun( KURL( uri ) );
132 }
133#endif
134
135 return false;
136}