2
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "actions/actions.h"
21
#include "action_data/action_data.h"
23
#include <KDE/KAuthorized>
24
#include <KDE/KConfigGroup>
27
#include <KDE/KService>
28
#include <KDE/KUriFilter>
29
#include <kworkspace/kworkspace.h>
34
CommandUrlActionVisitor::~CommandUrlActionVisitor()
38
CommandUrlAction::CommandUrlAction( ActionData* data_P, const QString& command_url_P )
39
: Action( data_P ), _command_url( command_url_P )
44
QString CommandUrlAction::command_url() const
50
void CommandUrlAction::accept(ActionVisitor& visitor)
52
if (CommandUrlActionVisitor *v = dynamic_cast<CommandUrlActionVisitor*>(&visitor))
58
kDebug() << "Visitor error";
63
void CommandUrlAction::cfg_write( KConfigGroup& cfg_P ) const
65
base::cfg_write( cfg_P );
66
cfg_P.writeEntry( "CommandURL", command_url());
67
cfg_P.writeEntry( "Type", "COMMAND_URL" ); // overwrites value set in base::cfg_write()
71
Action* CommandUrlAction::copy( ActionData* data_P ) const
73
return new CommandUrlAction( data_P, command_url());
77
const QString CommandUrlAction::description() const
79
return i18n( "Command/URL : " ) + command_url();
83
void CommandUrlAction::execute()
86
if( command_url().isEmpty())
89
QString cmd = command_url();
90
static bool sm_ready = false;
93
KWorkSpace::propagateSessionManager();
96
// int space_pos = command_url().find( ' ' );
97
// if( command_url()[ 0 ] != '\'' && command_url()[ 0 ] != '"' && space_pos > -1
98
// && command_url()[ space_pos - 1 ] != '\\' )
99
// cmd = command_url().left( space_pos ); // get first 'word'
101
KUriFilter::self()->filterUri( uri );
102
if( uri.uri().isLocalFile() && !uri.uri().hasRef() )
103
cmd = uri.uri().toLocalFile();
105
cmd = uri.uri().url();
106
switch( uri.uriType())
108
case KUriFilterData::LocalFile:
109
case KUriFilterData::LocalDir:
110
case KUriFilterData::NetProtocol:
111
case KUriFilterData::Help:
113
( void ) new KRun( uri.uri(),0L);
116
case KUriFilterData::Executable:
118
if (!KAuthorized::authorizeKAction("shell_access"))
120
if( !uri.hasArgsAndOptions())
122
KService::Ptr service = KService::serviceByDesktopName( cmd );
125
KRun::run( *service, KUrl::List(), NULL );
131
case KUriFilterData::Shell:
133
if (!KAuthorized::authorizeKAction("shell_access"))
135
if( !KRun::runCommand(
136
cmd + ( uri.hasArgsAndOptions() ? uri.argsAndOptions() : "" ),
137
cmd, uri.iconName(), NULL )) {
148
void CommandUrlAction::set_command_url( const QString &command )
150
_command_url = command;
153
} // namespace KHotKeys