<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>kio/kio: krun.cpp Source File (kio/kio)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../../.."><img id="nav_header_logo" alt="Home" align="left" src="../../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <div id="nav_header_title" align="left">KDE API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_right" style="text-align: left;"> / <a href="../../..">API Reference</a> / <a href="../../html/index.html">kio</a> / <a href=".">kio</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <a name="content"></a> <!-- Generated by Doxygen 1.7.4 --> <div class="header"> <div class="headertitle"> <div class="title">krun.cpp</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* This file is part of the KDE libraries</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2000 Torben Weis <weis@kde.org></span> <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2006 David Faure <faure@kde.org></span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public License</span> <a name="l00016"></a>00016 <span class="comment"> along with this library; see the file COPYING.LIB. If not, write to</span> <a name="l00017"></a>00017 <span class="comment"> the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,</span> <a name="l00018"></a>00018 <span class="comment"> Boston, MA 02110-1301, USA.</span> <a name="l00019"></a>00019 <span class="comment">*/</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="preprocessor">#include "krun.h"</span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include <assert.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <stdlib.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <string.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <unistd.h></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <typeinfo></span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include <qwidget.h></span> <a name="l00030"></a>00030 <span class="preprocessor">#include <qguardedptr.h></span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="preprocessor">#include "kuserprofile.h"</span> <a name="l00033"></a>00033 <span class="preprocessor">#include "kmimetype.h"</span> <a name="l00034"></a>00034 <span class="preprocessor">#include "kmimemagic.h"</span> <a name="l00035"></a>00035 <span class="preprocessor">#include "kio/job.h"</span> <a name="l00036"></a>00036 <span class="preprocessor">#include "kio/global.h"</span> <a name="l00037"></a>00037 <span class="preprocessor">#include "kio/scheduler.h"</span> <a name="l00038"></a>00038 <span class="preprocessor">#include "kio/netaccess.h"</span> <a name="l00039"></a>00039 <span class="preprocessor">#include "kfile/kopenwith.h"</span> <a name="l00040"></a>00040 <span class="preprocessor">#include "kfile/krecentdocument.h"</span> <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="preprocessor">#include <kdatastream.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <kmessageboxwrapper.h></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <kurl.h></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <kapplication.h></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <kdebug.h></span> <a name="l00047"></a>00047 <span class="preprocessor">#include <klocale.h></span> <a name="l00048"></a>00048 <span class="preprocessor">#include <kprotocolinfo.h></span> <a name="l00049"></a>00049 <span class="preprocessor">#include <kstandarddirs.h></span> <a name="l00050"></a>00050 <span class="preprocessor">#include <kprocess.h></span> <a name="l00051"></a>00051 <span class="preprocessor">#include <dcopclient.h></span> <a name="l00052"></a>00052 <span class="preprocessor">#include <qfile.h></span> <a name="l00053"></a>00053 <span class="preprocessor">#include <qfileinfo.h></span> <a name="l00054"></a>00054 <span class="preprocessor">#include <qtextstream.h></span> <a name="l00055"></a>00055 <span class="preprocessor">#include <qdatetime.h></span> <a name="l00056"></a>00056 <span class="preprocessor">#include <qregexp.h></span> <a name="l00057"></a>00057 <span class="preprocessor">#include <kdesktopfile.h></span> <a name="l00058"></a>00058 <span class="preprocessor">#include <kstartupinfo.h></span> <a name="l00059"></a>00059 <span class="preprocessor">#include <kmacroexpander.h></span> <a name="l00060"></a>00060 <span class="preprocessor">#include <kshell.h></span> <a name="l00061"></a>00061 <span class="preprocessor">#include <kde_file.h></span> <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="preprocessor">#ifdef Q_WS_X11</span> <a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#include <kwin.h></span> <a name="l00065"></a>00065 <span class="preprocessor">#endif</span> <a name="l00066"></a>00066 <span class="preprocessor"></span> <a name="l00067"></a>00067 <span class="keyword">class </span>KRun::KRunPrivate <a name="l00068"></a>00068 { <a name="l00069"></a>00069 <span class="keyword">public</span>: <a name="l00070"></a>00070 KRunPrivate() { m_showingError = <span class="keyword">false</span>; } <a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="keywordtype">bool</span> m_showingError; <a name="l00073"></a>00073 <span class="keywordtype">bool</span> m_runExecutables; <a name="l00074"></a>00074 <a name="l00075"></a>00075 <a class="codeRef" href="qstring.html">QString</a> m_preferredService; <a name="l00076"></a>00076 <a class="codeRef" href="qstring.html">QString</a> m_externalBrowser; <a name="l00077"></a>00077 <a class="codeRef" href="qstring.html">QString</a> m_localPath; <a name="l00078"></a>00078 <a class="codeRef" href="qstring.html">QString</a> m_suggestedFileName; <a name="l00079"></a>00079 <a class="codeRef" href="qguardedptr.html">QGuardedPtr <QWidget></a> m_window; <a name="l00080"></a>00080 }; <a name="l00081"></a>00081 <a name="l00082"></a>00082 pid_t <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">KRun::runURL</a>( <span class="keyword">const</span> KURL& u, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _mimetype ) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">runURL</a>( u, _mimetype, <span class="keyword">false</span>, <span class="keyword">true</span>, QString::null ); <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <a name="l00087"></a>00087 pid_t <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">KRun::runURL</a>( <span class="keyword">const</span> KURL& u, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _mimetype, <span class="keywordtype">bool</span> tempFile ) <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">runURL</a>( u, _mimetype, tempFile, <span class="keyword">true</span>, QString::null ); <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a><a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e">00092</a> pid_t <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">KRun::runURL</a>( <span class="keyword">const</span> KURL& u, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _mimetype, <span class="keywordtype">bool</span> tempFile, <span class="keywordtype">bool</span> runExecutables ) <a name="l00093"></a>00093 { <a name="l00094"></a>00094 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">runURL</a>( u, _mimetype, tempFile, runExecutables, QString::null ); <a name="l00095"></a>00095 } <a name="l00096"></a>00096 <a name="l00097"></a><a class="code" href="classKRun.html#a3b89fed66b4a7a9af9353caf6782ab55">00097</a> <span class="keywordtype">bool</span> <a class="code" href="classKRun.html#a3b89fed66b4a7a9af9353caf6782ab55" title="Returns wether the url of mimetype is executable.">KRun::isExecutableFile</a>( <span class="keyword">const</span> KURL& url, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &mimetype ) <a name="l00098"></a>00098 { <a name="l00099"></a>00099 <span class="keywordflow">if</span> ( !url.isLocalFile() ) <a name="l00100"></a>00100 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00101"></a>00101 <a class="codeRef" href="qfileinfo.html">QFileInfo</a> file( url.path() ); <a name="l00102"></a>00102 <span class="keywordflow">if</span> ( file.isExecutable() ) <span class="comment">// Got a prospective file to run</span> <a name="l00103"></a>00103 { <a name="l00104"></a>00104 KMimeType::Ptr mimeType = <a class="code" href="classKMimeType.html#a1fd115a75a84e762e31d8424eee683c0" title="Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...">KMimeType::mimeType</a>( mimetype ); <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="keywordflow">if</span> ( mimeType->is(<span class="stringliteral">"application/x-executable"</span>) || mimeType->is(<span class="stringliteral">"application/x-executable-script"</span>) ) <a name="l00107"></a>00107 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00108"></a>00108 } <a name="l00109"></a>00109 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00110"></a>00110 } <a name="l00111"></a>00111 <a name="l00112"></a>00112 <span class="comment">// This is called by foundMimeType, since it knows the mimetype of the URL</span> <a name="l00113"></a><a class="code" href="classKRun.html#ad897535fa88959dd80adf9afb0a4e447">00113</a> pid_t <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">KRun::runURL</a>( <span class="keyword">const</span> KURL& u, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _mimetype, <span class="keywordtype">bool</span> tempFile, <span class="keywordtype">bool</span> runExecutables, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& suggestedFileName ) <a name="l00114"></a>00114 { <a name="l00115"></a>00115 <span class="keywordtype">bool</span> noRun = <span class="keyword">false</span>; <a name="l00116"></a>00116 <span class="keywordtype">bool</span> noAuth = <span class="keyword">false</span>; <a name="l00117"></a>00117 <span class="keywordflow">if</span> ( _mimetype == <span class="stringliteral">"inode/directory-locked"</span> ) <a name="l00118"></a>00118 { <a name="l00119"></a>00119 <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">KMessageBoxWrapper::error</a>( 0L, <a name="l00120"></a>00120 i18n(<span class="stringliteral">"<qt>Unable to enter <b>%1</b>.\nYou do not have access rights to this location.</qt>"</span>).arg(u.htmlURL()) ); <a name="l00121"></a>00121 <span class="keywordflow">return</span> 0; <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( _mimetype == <span class="stringliteral">"application/x-desktop"</span> ) <a name="l00124"></a>00124 { <a name="l00125"></a>00125 <span class="keywordflow">if</span> ( u.isLocalFile() && runExecutables ) <a name="l00126"></a>00126 <span class="keywordflow">return</span> <a class="code" href="classKDEDesktopMimeType.html#a62b7a6e5dcb7dd8e14ec372dff6c93ed" title="Invokes the default action for the desktop entry.">KDEDesktopMimeType::run</a>( u, <span class="keyword">true</span> ); <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="classKRun.html#a3b89fed66b4a7a9af9353caf6782ab55" title="Returns wether the url of mimetype is executable.">isExecutableFile</a>(u, _mimetype) ) <a name="l00129"></a>00129 { <a name="l00130"></a>00130 <span class="keywordflow">if</span> ( u.isLocalFile() && runExecutables) <a name="l00131"></a>00131 { <a name="l00132"></a>00132 <span class="keywordflow">if</span> (kapp->authorize(<span class="stringliteral">"shell_access"</span>)) <a name="l00133"></a>00133 { <a name="l00134"></a>00134 <a class="codeRef" href="qstring.html">QString</a> path = u.path(); <a name="l00135"></a>00135 <a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97" title="Quotes a string for the shell.">shellQuote</a>( path ); <a name="l00136"></a>00136 <span class="keywordflow">return</span> (<a class="code" href="classKRun.html#acbf97c72c343ef24a427e744d63139bc" title="Run the given shell command and notifies kicker of the starting of the application.">KRun::runCommand</a>(path)); <span class="comment">// just execute the url as a command</span> <a name="l00137"></a>00137 <span class="comment">// ## TODO implement deleting the file if tempFile==true</span> <a name="l00138"></a>00138 } <a name="l00139"></a>00139 <span class="keywordflow">else</span> <a name="l00140"></a>00140 { <a name="l00141"></a>00141 noAuth = <span class="keyword">true</span>; <a name="l00142"></a>00142 } <a name="l00143"></a>00143 } <a name="l00144"></a>00144 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_mimetype == <span class="stringliteral">"application/x-executable"</span>) <a name="l00145"></a>00145 noRun = <span class="keyword">true</span>; <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="classKRun.html#abe21b7573533035c6613ebca1bf0dd18" title="Returns whether serviceType refers to an executable program instead of a data file.">isExecutable</a>(_mimetype) ) <a name="l00148"></a>00148 { <a name="l00149"></a>00149 <span class="keywordflow">if</span> (!runExecutables) <a name="l00150"></a>00150 noRun = <span class="keyword">true</span>; <a name="l00151"></a>00151 <a name="l00152"></a>00152 <span class="keywordflow">if</span> (!kapp->authorize(<span class="stringliteral">"shell_access"</span>)) <a name="l00153"></a>00153 noAuth = <span class="keyword">true</span>; <a name="l00154"></a>00154 } <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="keywordflow">if</span> ( noRun ) <a name="l00157"></a>00157 { <a name="l00158"></a>00158 KMessageBox::sorry( 0L, <a name="l00159"></a>00159 i18n(<span class="stringliteral">"<qt>The file <b>%1</b> is an executable program. "</span> <a name="l00160"></a>00160 <span class="stringliteral">"For safety it will not be started.</qt>"</span>).arg(u.htmlURL())); <a name="l00161"></a>00161 <span class="keywordflow">return</span> 0; <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <span class="keywordflow">if</span> ( noAuth ) <a name="l00164"></a>00164 { <a name="l00165"></a>00165 <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">KMessageBoxWrapper::error</a>( 0L, <a name="l00166"></a>00166 i18n(<span class="stringliteral">"<qt>You do not have permission to run <b>%1</b>.</qt>"</span>).arg(u.htmlURL()) ); <a name="l00167"></a>00167 <span class="keywordflow">return</span> 0; <a name="l00168"></a>00168 } <a name="l00169"></a>00169 <a name="l00170"></a>00170 KURL::List lst; <a name="l00171"></a>00171 lst.append( u ); <a name="l00172"></a>00172 <a name="l00173"></a>00173 <span class="keyword">static</span> <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& app_str = KGlobal::staticQString(<span class="stringliteral">"Application"</span>); <a name="l00174"></a>00174 <a name="l00175"></a>00175 KService::Ptr offer = <a class="code" href="classKServiceTypeProfile.html#a557b197082892e32adc88dee68d8e37e" title="Returns the preferred service for _serviceType and _genericServiceType ("Application", type of component, or null).">KServiceTypeProfile::preferredService</a>( _mimetype, app_str ); <a name="l00176"></a>00176 <a name="l00177"></a>00177 <span class="keywordflow">if</span> ( !offer ) <a name="l00178"></a>00178 { <a name="l00179"></a>00179 <span class="comment">// Open-with dialog</span> <a name="l00180"></a>00180 <span class="comment">// TODO : pass the mimetype as a parameter, to show it (comment field) in the dialog !</span> <a name="l00181"></a>00181 <span class="comment">// Hmm, in fact KOpenWithDlg::setServiceType already guesses the mimetype from the first URL of the list...</span> <a name="l00182"></a>00182 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">displayOpenWithDialog</a>( lst, tempFile, suggestedFileName ); <a name="l00183"></a>00183 } <a name="l00184"></a>00184 <a name="l00185"></a>00185 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( *offer, lst, 0 <span class="comment">/*window*/</span>, tempFile, suggestedFileName ); <a name="l00186"></a>00186 } <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="keywordtype">bool</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">KRun::displayOpenWithDialog</a>( <span class="keyword">const</span> KURL::List& lst ) <a name="l00189"></a>00189 { <a name="l00190"></a>00190 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">displayOpenWithDialog</a>( lst, <span class="keyword">false</span>, QString::null ); <a name="l00191"></a>00191 } <a name="l00192"></a>00192 <a name="l00193"></a><a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3">00193</a> <span class="keywordtype">bool</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">KRun::displayOpenWithDialog</a>( <span class="keyword">const</span> KURL::List& lst, <span class="keywordtype">bool</span> tempFiles ) <a name="l00194"></a>00194 { <a name="l00195"></a>00195 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">displayOpenWithDialog</a>( lst, tempFiles, QString::null ); <a name="l00196"></a>00196 } <a name="l00197"></a>00197 <a name="l00198"></a><a class="code" href="classKRun.html#a7cac381825d4143b03bc19fd563a0674">00198</a> <span class="keywordtype">bool</span> <a class="code" href="classKRun.html#a59f662f719e5941f79b56c65c2beeac3" title="Display the Open-With dialog for those URLs, and run the chosen application.">KRun::displayOpenWithDialog</a>( <span class="keyword">const</span> KURL::List& lst, <span class="keywordtype">bool</span> tempFiles, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& suggestedFileName ) <a name="l00199"></a>00199 { <a name="l00200"></a>00200 <span class="keywordflow">if</span> (kapp && !kapp->authorizeKAction(<span class="stringliteral">"openwith"</span>)) <a name="l00201"></a>00201 { <a name="l00202"></a>00202 <span class="comment">// TODO: Better message, i18n freeze :-(</span> <a name="l00203"></a>00203 KMessageBox::sorry(0L, i18n(<span class="stringliteral">"You are not authorized to open this file."</span>)); <a name="l00204"></a>00204 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00205"></a>00205 } <a name="l00206"></a>00206 <a name="l00207"></a>00207 KOpenWithDlg l( lst, i18n(<span class="stringliteral">"Open with:"</span>), QString::null, 0L ); <a name="l00208"></a>00208 <span class="keywordflow">if</span> ( l.exec() ) <a name="l00209"></a>00209 { <a name="l00210"></a>00210 KService::Ptr service = l.service(); <a name="l00211"></a>00211 <span class="keywordflow">if</span> ( !!service ) <a name="l00212"></a>00212 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( *service, lst, 0 <span class="comment">/*window*/</span>, tempFiles, suggestedFileName ); <a name="l00213"></a>00213 <a name="l00214"></a>00214 kdDebug(7010) << <span class="stringliteral">"No service set, running "</span> << l.text() << endl; <a name="l00215"></a>00215 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( l.text(), lst, suggestedFileName ); <span class="comment">// TODO handle tempFiles</span> <a name="l00216"></a>00216 } <a name="l00217"></a>00217 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00218"></a>00218 } <a name="l00219"></a>00219 <a name="l00220"></a><a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97">00220</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97" title="Quotes a string for the shell.">KRun::shellQuote</a>( <a class="codeRef" href="qstring.html">QString</a> &_str ) <a name="l00221"></a>00221 { <a name="l00222"></a>00222 <span class="comment">// Credits to Walter, says Bernd G. :)</span> <a name="l00223"></a>00223 <span class="keywordflow">if</span> (_str.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <span class="comment">// Don't create an explicit empty parameter</span> <a name="l00224"></a>00224 <span class="keywordflow">return</span>; <a name="l00225"></a>00225 <a class="codeRef" href="qchar.html">QChar</a> q(<span class="charliteral">'\''</span>); <a name="l00226"></a>00226 _str.<a class="codeRef" href="qstring.html#replace">replace</a>(q, <span class="stringliteral">"'\\''"</span>).prepend(q).append(q); <a name="l00227"></a>00227 } <a name="l00228"></a>00228 <a name="l00229"></a>00229 <a name="l00230"></a>00230 <span class="keyword">class </span>KRunMX1 : <span class="keyword">public</span> KMacroExpanderBase { <a name="l00231"></a>00231 <span class="keyword">public</span>: <a name="l00232"></a>00232 KRunMX1( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a> &_service ) : <a name="l00233"></a>00233 KMacroExpanderBase( <span class="stringliteral">'%'</span> ), hasUrls( false ), hasSpec( false ), service( _service ) {} <a name="l00234"></a>00234 <span class="keywordtype">bool</span> hasUrls:1, hasSpec:1; <a name="l00235"></a>00235 <a name="l00236"></a>00236 <span class="keyword">protected</span>: <a name="l00237"></a>00237 <span class="keyword">virtual</span> <span class="keywordtype">int</span> expandEscapedMacro( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &str, uint pos, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ); <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="keyword">private</span>: <a name="l00240"></a>00240 <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a> &service; <a name="l00241"></a>00241 }; <a name="l00242"></a>00242 <a name="l00243"></a>00243 <span class="keywordtype">int</span> <a name="l00244"></a>00244 KRunMX1::expandEscapedMacro( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &str, uint pos, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ) <a name="l00245"></a>00245 { <a name="l00246"></a>00246 uint option = str[pos + 1]; <a name="l00247"></a>00247 <span class="keywordflow">switch</span>( option ) { <a name="l00248"></a>00248 <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: <a name="l00249"></a>00249 ret << service.name().replace( <span class="charliteral">'%'</span>, <span class="stringliteral">"%%"</span> ); <a name="l00250"></a>00250 <span class="keywordflow">break</span>; <a name="l00251"></a>00251 <span class="keywordflow">case</span> <span class="charliteral">'k'</span>: <a name="l00252"></a>00252 ret << service.desktopEntryPath().replace( <span class="charliteral">'%'</span>, <span class="stringliteral">"%%"</span> ); <a name="l00253"></a>00253 <span class="keywordflow">break</span>; <a name="l00254"></a>00254 <span class="keywordflow">case</span> <span class="charliteral">'i'</span>: <a name="l00255"></a>00255 ret << <span class="stringliteral">"-icon"</span> << service.icon().replace( <span class="charliteral">'%'</span>, <span class="stringliteral">"%%"</span> ); <a name="l00256"></a>00256 <span class="keywordflow">break</span>; <a name="l00257"></a>00257 <span class="keywordflow">case</span> <span class="charliteral">'m'</span>: <a name="l00258"></a>00258 ret << <span class="stringliteral">"-miniicon"</span> << service.icon().replace( <span class="charliteral">'%'</span>, <span class="stringliteral">"%%"</span> ); <a name="l00259"></a>00259 <span class="keywordflow">break</span>; <a name="l00260"></a>00260 <span class="keywordflow">case</span> <span class="charliteral">'u'</span>: <a name="l00261"></a>00261 <span class="keywordflow">case</span> <span class="charliteral">'U'</span>: <a name="l00262"></a>00262 hasUrls = <span class="keyword">true</span>; <a name="l00263"></a>00263 <span class="comment">/* fallthrough */</span> <a name="l00264"></a>00264 <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: <a name="l00265"></a>00265 <span class="keywordflow">case</span> <span class="charliteral">'F'</span>: <a name="l00266"></a>00266 <span class="keywordflow">case</span> <span class="charliteral">'n'</span>: <a name="l00267"></a>00267 <span class="keywordflow">case</span> <span class="charliteral">'N'</span>: <a name="l00268"></a>00268 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <a name="l00269"></a>00269 <span class="keywordflow">case</span> <span class="charliteral">'D'</span>: <a name="l00270"></a>00270 <span class="keywordflow">case</span> <span class="charliteral">'v'</span>: <a name="l00271"></a>00271 hasSpec = <span class="keyword">true</span>; <a name="l00272"></a>00272 <span class="comment">/* fallthrough */</span> <a name="l00273"></a>00273 <span class="keywordflow">default</span>: <a name="l00274"></a>00274 <span class="keywordflow">return</span> -2; <span class="comment">// subst with same and skip</span> <a name="l00275"></a>00275 } <a name="l00276"></a>00276 <span class="keywordflow">return</span> 2; <a name="l00277"></a>00277 } <a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="keyword">class </span>KRunMX2 : <span class="keyword">public</span> KMacroExpanderBase { <a name="l00280"></a>00280 <span class="keyword">public</span>: <a name="l00281"></a>00281 KRunMX2( <span class="keyword">const</span> KURL::List &_urls ) : <a name="l00282"></a>00282 KMacroExpanderBase( <span class="stringliteral">'%'</span> ), ignFile( false ), urls( _urls ) {} <a name="l00283"></a>00283 <span class="keywordtype">bool</span> ignFile:1; <a name="l00284"></a>00284 <a name="l00285"></a>00285 <span class="keyword">protected</span>: <a name="l00286"></a>00286 <span class="keyword">virtual</span> <span class="keywordtype">int</span> expandEscapedMacro( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &str, uint pos, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ); <a name="l00287"></a>00287 <a name="l00288"></a>00288 <span class="keyword">private</span>: <a name="l00289"></a>00289 <span class="keywordtype">void</span> subst( <span class="keywordtype">int</span> option, <span class="keyword">const</span> KURL &url, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ); <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="keyword">const</span> KURL::List &urls; <a name="l00292"></a>00292 }; <a name="l00293"></a>00293 <a name="l00294"></a>00294 <span class="keywordtype">void</span> <a name="l00295"></a>00295 KRunMX2::subst( <span class="keywordtype">int</span> option, <span class="keyword">const</span> KURL &url, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ) <a name="l00296"></a>00296 { <a name="l00297"></a>00297 <span class="keywordflow">switch</span>( option ) { <a name="l00298"></a>00298 <span class="keywordflow">case</span> <span class="charliteral">'u'</span>: <a name="l00299"></a>00299 ret << url.pathOrURL(); <a name="l00300"></a>00300 <span class="keywordflow">break</span>; <a name="l00301"></a>00301 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <a name="l00302"></a>00302 ret << url.directory(); <a name="l00303"></a>00303 <span class="keywordflow">break</span>; <a name="l00304"></a>00304 <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: <a name="l00305"></a>00305 ret << url.path(); <a name="l00306"></a>00306 <span class="keywordflow">break</span>; <a name="l00307"></a>00307 <span class="keywordflow">case</span> <span class="charliteral">'n'</span>: <a name="l00308"></a>00308 ret << url.fileName(); <a name="l00309"></a>00309 <span class="keywordflow">break</span>; <a name="l00310"></a>00310 <span class="keywordflow">case</span> <span class="charliteral">'v'</span>: <a name="l00311"></a>00311 <span class="keywordflow">if</span> (url.isLocalFile() && <a class="codeRef" href="qfile.html#exists-2">QFile::exists</a>( url.path() ) ) <a name="l00312"></a>00312 ret << KDesktopFile( url.path(), true ).readEntry( <span class="stringliteral">"Dev"</span> ); <a name="l00313"></a>00313 <span class="keywordflow">break</span>; <a name="l00314"></a>00314 } <a name="l00315"></a>00315 <span class="keywordflow">return</span>; <a name="l00316"></a>00316 } <a name="l00317"></a>00317 <a name="l00318"></a>00318 <span class="keywordtype">int</span> <a name="l00319"></a>00319 KRunMX2::expandEscapedMacro( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &str, uint pos, <a class="codeRef" href="qstringlist.html">QStringList</a> &ret ) <a name="l00320"></a>00320 { <a name="l00321"></a>00321 uint option = str[pos + 1]; <a name="l00322"></a>00322 <span class="keywordflow">switch</span>( option ) { <a name="l00323"></a>00323 <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: <a name="l00324"></a>00324 <span class="keywordflow">case</span> <span class="charliteral">'u'</span>: <a name="l00325"></a>00325 <span class="keywordflow">case</span> <span class="charliteral">'n'</span>: <a name="l00326"></a>00326 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <a name="l00327"></a>00327 <span class="keywordflow">case</span> <span class="charliteral">'v'</span>: <a name="l00328"></a>00328 <span class="keywordflow">if</span>( urls.isEmpty() ) { <a name="l00329"></a>00329 <span class="keywordflow">if</span> (!ignFile) <a name="l00330"></a>00330 kdDebug() << <span class="stringliteral">"KRun::processDesktopExec: No URLs supplied to single-URL service "</span> << str << endl; <a name="l00331"></a>00331 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( urls.count() > 1 ) <a name="l00332"></a>00332 kdWarning() << <span class="stringliteral">"KRun::processDesktopExec: "</span> << urls.count() << <span class="stringliteral">" URLs supplied to single-URL service "</span> << str << endl; <a name="l00333"></a>00333 <span class="keywordflow">else</span> <a name="l00334"></a>00334 subst( option, urls.first(), ret ); <a name="l00335"></a>00335 <span class="keywordflow">break</span>; <a name="l00336"></a>00336 <span class="keywordflow">case</span> <span class="charliteral">'F'</span>: <a name="l00337"></a>00337 <span class="keywordflow">case</span> <span class="charliteral">'U'</span>: <a name="l00338"></a>00338 <span class="keywordflow">case</span> <span class="charliteral">'N'</span>: <a name="l00339"></a>00339 <span class="keywordflow">case</span> <span class="charliteral">'D'</span>: <a name="l00340"></a>00340 option += <span class="charliteral">'a'</span> - <span class="charliteral">'A'</span>; <a name="l00341"></a>00341 <span class="keywordflow">for</span>( KURL::List::ConstIterator it = urls.begin(); it != urls.end(); ++it ) <a name="l00342"></a>00342 subst( option, *it, ret ); <a name="l00343"></a>00343 <span class="keywordflow">break</span>; <a name="l00344"></a>00344 <span class="keywordflow">case</span> <span class="charliteral">'%'</span>: <a name="l00345"></a>00345 ret = <span class="stringliteral">"%"</span>; <a name="l00346"></a>00346 <span class="keywordflow">break</span>; <a name="l00347"></a>00347 <span class="keywordflow">default</span>: <a name="l00348"></a>00348 <span class="keywordflow">return</span> -2; <span class="comment">// subst with same and skip</span> <a name="l00349"></a>00349 } <a name="l00350"></a>00350 <span class="keywordflow">return</span> 2; <a name="l00351"></a>00351 } <a name="l00352"></a>00352 <a name="l00353"></a>00353 <span class="comment">// BIC: merge methods below</span> <a name="l00354"></a>00354 <a class="codeRef" href="qstringlist.html">QStringList</a> <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">KRun::processDesktopExec</a>(<span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a> &_service, <span class="keyword">const</span> KURL::List& _urls, <span class="keywordtype">bool</span> has_shell) { <a name="l00355"></a>00355 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">processDesktopExec</a>( _service, _urls, has_shell, <span class="keyword">false</span>, QString::null ); <a name="l00356"></a>00356 } <a name="l00357"></a>00357 <a name="l00358"></a><a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a">00358</a> <a class="codeRef" href="qstringlist.html">QStringList</a> <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">KRun::processDesktopExec</a>(<span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a> &_service, <span class="keyword">const</span> KURL::List& _urls, <span class="keywordtype">bool</span> has_shell <span class="comment">/* KDE4: remove */</span>, <span class="keywordtype">bool</span> tempFiles) <a name="l00359"></a>00359 { <a name="l00360"></a>00360 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">processDesktopExec</a>( _service, _urls, has_shell, tempFiles, QString::null ); <a name="l00361"></a>00361 } <a name="l00362"></a>00362 <a name="l00363"></a><a class="code" href="classKRun.html#aebeb8a36dfe9a31f0398c7123d91adb5">00363</a> <a class="codeRef" href="qstringlist.html">QStringList</a> <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">KRun::processDesktopExec</a>(<span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a> &_service, <span class="keyword">const</span> KURL::List& _urls, <span class="keywordtype">bool</span> has_shell <span class="comment">/* KDE4: remove */</span>, <span class="keywordtype">bool</span> tempFiles, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& suggestedFileName) <a name="l00364"></a>00364 { <a name="l00365"></a>00365 <a class="codeRef" href="qstring.html">QString</a> exec = _service.<a class="code" href="classKService.html#a4a0471572826ed8239b85505506b4c7c" title="Returns the executable.">exec</a>(); <a name="l00366"></a>00366 <a class="codeRef" href="qstringlist.html">QStringList</a> result; <a name="l00367"></a>00367 <span class="keywordtype">bool</span> appHasTempFileOption; <a name="l00368"></a>00368 <a name="l00369"></a>00369 KRunMX1 mx1( _service ); <a name="l00370"></a>00370 KRunMX2 mx2( _urls ); <a name="l00371"></a>00371 <a name="l00373"></a>00373 <a class="codeRef" href="qregexp.html">QRegExp</a> re(<span class="stringliteral">"^\\s*(?:/bin/)?sh\\s+-c\\s+(.*)$"</span>); <a name="l00374"></a>00374 <span class="keywordflow">if</span> (!re.<a class="codeRef" href="qregexp.html#search">search</a>( exec )) { <a name="l00375"></a>00375 exec = re.<a class="codeRef" href="qregexp.html#cap">cap</a>( 1 ).stripWhiteSpace(); <a name="l00376"></a>00376 <span class="keywordflow">for</span> (uint pos = 0; pos < exec.<a class="codeRef" href="qstring.html#length">length</a>(); ) { <a name="l00377"></a>00377 <a class="codeRef" href="qchar.html">QChar</a> c = exec.<a class="codeRef" href="qstring.html#unicode">unicode</a>()[pos]; <a name="l00378"></a>00378 <span class="keywordflow">if</span> (c != <span class="charliteral">'\''</span> && c != <span class="charliteral">'"'</span>) <a name="l00379"></a>00379 <span class="keywordflow">goto</span> synerr; <span class="comment">// what else can we do? after normal parsing the substs would be insecure</span> <a name="l00380"></a>00380 <span class="keywordtype">int</span> pos2 = exec.<a class="codeRef" href="qstring.html#find">find</a>( c, pos + 1 ) - 1; <a name="l00381"></a>00381 <span class="keywordflow">if</span> (pos2 < 0) <a name="l00382"></a>00382 <span class="keywordflow">goto</span> synerr; <span class="comment">// quoting error</span> <a name="l00383"></a>00383 memcpy( (<span class="keywordtype">void</span> *)(exec.<a class="codeRef" href="qstring.html#unicode">unicode</a>() + pos), exec.<a class="codeRef" href="qstring.html#unicode">unicode</a>() + pos + 1, (pos2 - pos) * <span class="keyword">sizeof</span>(<a class="codeRef" href="qchar.html">QChar</a>)); <a name="l00384"></a>00384 pos = pos2; <a name="l00385"></a>00385 exec.<a class="codeRef" href="qstring.html#remove">remove</a>( pos, 2 ); <a name="l00386"></a>00386 } <a name="l00387"></a>00387 } <a name="l00388"></a>00388 <a name="l00389"></a>00389 <span class="keywordflow">if</span>( !mx1.expandMacrosShellQuote( exec ) ) <a name="l00390"></a>00390 <span class="keywordflow">goto</span> synerr; <span class="comment">// error in shell syntax</span> <a name="l00391"></a>00391 <a name="l00392"></a>00392 <span class="comment">// FIXME: the current way of invoking kioexec disables term and su use</span> <a name="l00393"></a>00393 <a name="l00394"></a>00394 <span class="comment">// Check if we need "tempexec" (kioexec in fact)</span> <a name="l00395"></a>00395 appHasTempFileOption = tempFiles && _service.<a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>(<span class="stringliteral">"X-KDE-HasTempFileOption"</span>).<a class="codeRef" href="qvariant.html#toBool">toBool</a>(); <a name="l00396"></a>00396 <span class="keywordflow">if</span>( tempFiles && !appHasTempFileOption && _urls.size() ) { <a name="l00397"></a>00397 result << <span class="stringliteral">"kioexec"</span> << <span class="stringliteral">"--tempfiles"</span> << exec; <a name="l00398"></a>00398 result += _urls.toStringList(); <a name="l00399"></a>00399 <span class="keywordflow">if</span> (has_shell) <a name="l00400"></a>00400 result = KShell::joinArgs( result ); <a name="l00401"></a>00401 <span class="keywordflow">return</span> result; <a name="l00402"></a>00402 } <a name="l00403"></a>00403 <a name="l00404"></a>00404 <span class="comment">// Check if we need kioexec</span> <a name="l00405"></a>00405 <span class="keywordflow">if</span>( !mx1.hasUrls ) { <a name="l00406"></a>00406 <span class="keywordflow">for</span>( KURL::List::ConstIterator it = _urls.begin(); it != _urls.end(); ++it ) <a name="l00407"></a>00407 <span class="keywordflow">if</span> ( !(*it).isLocalFile() && !<a class="code" href="classKProtocolInfo.html#a6fd97e51d5f796233e47b576ffcb4758" title="Returns whether the protocol can act as a helper protocol.">KProtocolInfo::isHelperProtocol</a>(*it) ) { <a name="l00408"></a>00408 <span class="comment">// We need to run the app through kioexec</span> <a name="l00409"></a>00409 result << <span class="stringliteral">"kioexec"</span>; <a name="l00410"></a>00410 <span class="keywordflow">if</span> ( tempFiles ) <a name="l00411"></a>00411 result << <span class="stringliteral">"--tempfiles"</span>; <a name="l00412"></a>00412 <span class="keywordflow">if</span> ( !suggestedFileName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ) { <a name="l00413"></a>00413 result << <span class="stringliteral">"--suggestedfilename"</span>; <a name="l00414"></a>00414 result << suggestedFileName; <a name="l00415"></a>00415 } <a name="l00416"></a>00416 result << exec; <a name="l00417"></a>00417 result += _urls.toStringList(); <a name="l00418"></a>00418 <span class="keywordflow">if</span> (has_shell) <a name="l00419"></a>00419 result = KShell::joinArgs( result ); <a name="l00420"></a>00420 <span class="keywordflow">return</span> result; <a name="l00421"></a>00421 } <a name="l00422"></a>00422 } <a name="l00423"></a>00423 <a name="l00424"></a>00424 <span class="keywordflow">if</span> ( appHasTempFileOption ) <a name="l00425"></a>00425 exec += <span class="stringliteral">" --tempfile"</span>; <a name="l00426"></a>00426 <a name="l00427"></a>00427 <span class="comment">// Did the user forget to append something like '%f'?</span> <a name="l00428"></a>00428 <span class="comment">// If so, then assume that '%f' is the right choice => the application</span> <a name="l00429"></a>00429 <span class="comment">// accepts only local files.</span> <a name="l00430"></a>00430 <span class="keywordflow">if</span>( !mx1.hasSpec ) { <a name="l00431"></a>00431 exec += <span class="stringliteral">" %f"</span>; <a name="l00432"></a>00432 mx2.ignFile = <span class="keyword">true</span>; <a name="l00433"></a>00433 } <a name="l00434"></a>00434 <a name="l00435"></a>00435 mx2.expandMacrosShellQuote( exec ); <span class="comment">// syntax was already checked, so don't check return value</span> <a name="l00436"></a>00436 <a name="l00437"></a>00437 <span class="comment">/*</span> <a name="l00438"></a>00438 <span class="comment"> 1 = need_shell, 2 = terminal, 4 = su, 8 = has_shell</span> <a name="l00439"></a>00439 <span class="comment"></span> <a name="l00440"></a>00440 <span class="comment"> 0 << split(cmd)</span> <a name="l00441"></a>00441 <span class="comment"> 1 << "sh" << "-c" << cmd</span> <a name="l00442"></a>00442 <span class="comment"> 2 << split(term) << "-e" << split(cmd)</span> <a name="l00443"></a>00443 <span class="comment"> 3 << split(term) << "-e" << "sh" << "-c" << cmd</span> <a name="l00444"></a>00444 <span class="comment"></span> <a name="l00445"></a>00445 <span class="comment"> 4 << "kdesu" << "-u" << user << "-c" << cmd</span> <a name="l00446"></a>00446 <span class="comment"> 5 << "kdesu" << "-u" << user << "-c" << ("sh -c " + quote(cmd))</span> <a name="l00447"></a>00447 <span class="comment"> 6 << split(term) << "-e" << "su" << user << "-c" << cmd</span> <a name="l00448"></a>00448 <span class="comment"> 7 << split(term) << "-e" << "su" << user << "-c" << ("sh -c " + quote(cmd))</span> <a name="l00449"></a>00449 <span class="comment"></span> <a name="l00450"></a>00450 <span class="comment"> 8 << cmd</span> <a name="l00451"></a>00451 <span class="comment"> 9 << cmd</span> <a name="l00452"></a>00452 <span class="comment"> a << term << "-e" << cmd</span> <a name="l00453"></a>00453 <span class="comment"> b << term << "-e" << ("sh -c " + quote(cmd))</span> <a name="l00454"></a>00454 <span class="comment"></span> <a name="l00455"></a>00455 <span class="comment"> c << "kdesu" << "-u" << user << "-c" << quote(cmd)</span> <a name="l00456"></a>00456 <span class="comment"> d << "kdesu" << "-u" << user << "-c" << quote("sh -c " + quote(cmd))</span> <a name="l00457"></a>00457 <span class="comment"> e << term << "-e" << "su" << user << "-c" << quote(cmd)</span> <a name="l00458"></a>00458 <span class="comment"> f << term << "-e" << "su" << user << "-c" << quote("sh -c " + quote(cmd))</span> <a name="l00459"></a>00459 <span class="comment"></span> <a name="l00460"></a>00460 <span class="comment"> "sh -c" is needed in the "su" case, too, as su uses the user's login shell, not sh.</span> <a name="l00461"></a>00461 <span class="comment"> this could be optimized with the -s switch of some su versions (e.g., debian linux).</span> <a name="l00462"></a>00462 <span class="comment">*/</span> <a name="l00463"></a>00463 <a name="l00464"></a>00464 <span class="keywordflow">if</span> (_service.<a class="code" href="classKService.html#abf2c177682346064525deb776da4f25a" title="Checks whethe the service should be run in a terminal.">terminal</a>()) { <a name="l00465"></a>00465 KConfigGroupSaver gs(KGlobal::config(), <span class="stringliteral">"General"</span>); <a name="l00466"></a>00466 <a class="codeRef" href="qstring.html">QString</a> terminal = KGlobal::config()->readPathEntry(<span class="stringliteral">"TerminalApplication"</span>, <span class="stringliteral">"konsole"</span>); <a name="l00467"></a>00467 <span class="keywordflow">if</span> (terminal == <span class="stringliteral">"konsole"</span>) <a name="l00468"></a>00468 terminal += <span class="stringliteral">" -caption=%c %i %m"</span>; <a name="l00469"></a>00469 terminal += <span class="stringliteral">" "</span>; <a name="l00470"></a>00470 terminal += _service.<a class="code" href="classKService.html#a4c5b41b17fcce96710b6fe2b94ad9e86" title="Returns any options associated with the terminal the service runs in, if it requires a terminal...">terminalOptions</a>(); <a name="l00471"></a>00471 <span class="keywordflow">if</span>( !mx1.expandMacrosShellQuote( terminal ) ) { <a name="l00472"></a>00472 kdWarning() << <span class="stringliteral">"KRun: syntax error in command `"</span> << terminal << <span class="stringliteral">"', service `"</span> << _service.<a class="code" href="classKService.html#a206dd1927ae8f591074630c370cc39ee" title="Returns the name of the service.">name</a>() << <span class="stringliteral">"'"</span> << endl; <a name="l00473"></a>00473 <span class="keywordflow">return</span> <a class="codeRef" href="qstringlist.html">QStringList</a>(); <a name="l00474"></a>00474 } <a name="l00475"></a>00475 mx2.expandMacrosShellQuote( terminal ); <a name="l00476"></a>00476 <span class="keywordflow">if</span> (has_shell) <a name="l00477"></a>00477 result << terminal; <a name="l00478"></a>00478 <span class="keywordflow">else</span> <a name="l00479"></a>00479 result = KShell::splitArgs( terminal ); <span class="comment">// assuming that the term spec never needs a shell!</span> <a name="l00480"></a>00480 result << <span class="stringliteral">"-e"</span>; <a name="l00481"></a>00481 } <a name="l00482"></a>00482 <a name="l00483"></a>00483 <span class="keywordtype">int</span> err; <a name="l00484"></a>00484 <span class="keywordflow">if</span> (_service.<a class="code" href="classKService.html#a05759a1d0acfbb9997b95907c2afa688" title="Checks whether the service runs with a different user id.">substituteUid</a>()) { <a name="l00485"></a>00485 <span class="keywordflow">if</span> (_service.<a class="code" href="classKService.html#abf2c177682346064525deb776da4f25a" title="Checks whethe the service should be run in a terminal.">terminal</a>()) <a name="l00486"></a>00486 result << <span class="stringliteral">"su"</span>; <a name="l00487"></a>00487 <span class="keywordflow">else</span> <a name="l00488"></a>00488 result << <span class="stringliteral">"kdesu"</span> << <span class="stringliteral">"-u"</span>; <a name="l00489"></a>00489 result << _service.<a class="code" href="classKService.html#a031e97e187d994c45770bd0d1ac0c469" title="Returns the user name, if the service runs with a different user id.">username</a>() << <span class="stringliteral">"-c"</span>; <a name="l00490"></a>00490 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err); <a name="l00491"></a>00491 <span class="keywordflow">if</span> (err == KShell::FoundMeta) { <a name="l00492"></a>00492 <a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97" title="Quotes a string for the shell.">shellQuote</a>( exec ); <a name="l00493"></a>00493 exec.<a class="codeRef" href="qstring.html#prepend">prepend</a>( <span class="stringliteral">"/bin/sh -c "</span> ); <a name="l00494"></a>00494 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (err != KShell::NoError) <a name="l00495"></a>00495 <span class="keywordflow">goto</span> synerr; <a name="l00496"></a>00496 <span class="keywordflow">if</span> (has_shell) <a name="l00497"></a>00497 <a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97" title="Quotes a string for the shell.">shellQuote</a>( exec ); <a name="l00498"></a>00498 result << exec; <a name="l00499"></a>00499 } <span class="keywordflow">else</span> { <a name="l00500"></a>00500 <span class="keywordflow">if</span> (has_shell) { <a name="l00501"></a>00501 <span class="keywordflow">if</span> (_service.<a class="code" href="classKService.html#abf2c177682346064525deb776da4f25a" title="Checks whethe the service should be run in a terminal.">terminal</a>()) { <a name="l00502"></a>00502 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err); <a name="l00503"></a>00503 <span class="keywordflow">if</span> (err == KShell::FoundMeta) { <a name="l00504"></a>00504 <a class="code" href="classKRun.html#a1460a9e90e2002bc1448e8824800da97" title="Quotes a string for the shell.">shellQuote</a>( exec ); <a name="l00505"></a>00505 exec.<a class="codeRef" href="qstring.html#prepend">prepend</a>( <span class="stringliteral">"/bin/sh -c "</span> ); <a name="l00506"></a>00506 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (err != KShell::NoError) <a name="l00507"></a>00507 <span class="keywordflow">goto</span> synerr; <a name="l00508"></a>00508 } <a name="l00509"></a>00509 result << exec; <a name="l00510"></a>00510 } <span class="keywordflow">else</span> { <a name="l00511"></a>00511 result += KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err); <a name="l00512"></a>00512 <span class="keywordflow">if</span> (err == KShell::FoundMeta) <a name="l00513"></a>00513 result << <span class="stringliteral">"/bin/sh"</span> << <span class="stringliteral">"-c"</span> << exec; <a name="l00514"></a>00514 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (err != KShell::NoError) <a name="l00515"></a>00515 <span class="keywordflow">goto</span> synerr; <a name="l00516"></a>00516 } <a name="l00517"></a>00517 } <a name="l00518"></a>00518 <a name="l00519"></a>00519 <span class="keywordflow">return</span> result; <a name="l00520"></a>00520 <a name="l00521"></a>00521 synerr: <a name="l00522"></a>00522 kdWarning() << <span class="stringliteral">"KRun: syntax error in command `"</span> << _service.<a class="code" href="classKService.html#a4a0471572826ed8239b85505506b4c7c" title="Returns the executable.">exec</a>() << <span class="stringliteral">"', service `"</span> << _service.<a class="code" href="classKService.html#a206dd1927ae8f591074630c370cc39ee" title="Returns the name of the service.">name</a>() << <span class="stringliteral">"'"</span> << endl; <a name="l00523"></a>00523 <span class="keywordflow">return</span> <a class="codeRef" href="qstringlist.html">QStringList</a>(); <a name="l00524"></a>00524 } <a name="l00525"></a>00525 <a name="l00526"></a>00526 <span class="comment">//static</span> <a name="l00527"></a><a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0">00527</a> <a class="codeRef" href="qstring.html">QString</a> <a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0" title="Given a full command line (e.g.">KRun::binaryName</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & execLine, <span class="keywordtype">bool</span> removePath ) <a name="l00528"></a>00528 { <a name="l00529"></a>00529 <span class="comment">// Remove parameters and/or trailing spaces.</span> <a name="l00530"></a>00530 <a class="codeRef" href="qstringlist.html">QStringList</a> args = KShell::splitArgs( execLine ); <a name="l00531"></a>00531 <span class="keywordflow">for</span> (QStringList::ConstIterator it = args.begin(); it != args.end(); ++it) <a name="l00532"></a>00532 <span class="keywordflow">if</span> (!(*it).contains(<span class="charliteral">'='</span>)) <a name="l00533"></a>00533 <span class="comment">// Remove path if wanted</span> <a name="l00534"></a>00534 <span class="keywordflow">return</span> removePath ? (*it).mid((*it).findRev(<span class="charliteral">'/'</span>) + 1) : *it; <a name="l00535"></a>00535 <span class="keywordflow">return</span> QString::null; <a name="l00536"></a>00536 } <a name="l00537"></a>00537 <a name="l00538"></a>00538 <span class="keyword">static</span> pid_t runCommandInternal( KProcess* proc, <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>* service, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& binName, <a name="l00539"></a>00539 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &execName, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & iconName ) <a name="l00540"></a>00540 { <a name="l00541"></a>00541 <span class="keywordflow">if</span> (service && !service-><a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() <a name="l00542"></a>00542 && !KDesktopFile::isAuthorizedDesktopFile( service-><a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>() )) <a name="l00543"></a>00543 { <a name="l00544"></a>00544 kdWarning() << <span class="stringliteral">"No authorization to execute "</span> << service-><a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>() << endl; <a name="l00545"></a>00545 KMessageBox::sorry(0, i18n(<span class="stringliteral">"You are not authorized to execute this file."</span>)); <a name="l00546"></a>00546 <span class="keywordflow">return</span> 0; <a name="l00547"></a>00547 } <a name="l00548"></a>00548 <a class="codeRef" href="qstring.html">QString</a> bin = <a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0" title="Given a full command line (e.g.">KRun::binaryName</a>( binName, <span class="keyword">true</span> ); <a name="l00549"></a>00549 <span class="preprocessor">#ifdef Q_WS_X11 // Startup notification doesn't work with QT/E, service isn't needed without Startup notification</span> <a name="l00550"></a>00550 <span class="preprocessor"></span> <span class="keywordtype">bool</span> silent; <a name="l00551"></a>00551 <a class="codeRef" href="qcstring.html">QCString</a> wmclass; <a name="l00552"></a>00552 KStartupInfoId id; <a name="l00553"></a>00553 <span class="keywordtype">bool</span> startup_notify = KRun::checkStartupNotify( binName, service, &silent, &wmclass ); <a name="l00554"></a>00554 <span class="keywordflow">if</span>( startup_notify ) <a name="l00555"></a>00555 { <a name="l00556"></a>00556 <span class="keywordtype">id</span>.initId(); <a name="l00557"></a>00557 <span class="keywordtype">id</span>.setupStartupEnv(); <a name="l00558"></a>00558 KStartupInfoData data; <a name="l00559"></a>00559 data.setHostname(); <a name="l00560"></a>00560 data.setBin( bin ); <a name="l00561"></a>00561 <span class="keywordflow">if</span>( !execName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00562"></a>00562 data.setName( execName ); <a name="l00563"></a>00563 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( service && !service-><a class="code" href="classKService.html#a206dd1927ae8f591074630c370cc39ee" title="Returns the name of the service.">name</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00564"></a>00564 data.setName( service-><a class="code" href="classKService.html#a206dd1927ae8f591074630c370cc39ee" title="Returns the name of the service.">name</a>()); <a name="l00565"></a>00565 data.setDescription( i18n( <span class="stringliteral">"Launching %1"</span> ).arg( data.name())); <a name="l00566"></a>00566 <span class="keywordflow">if</span>( !iconName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00567"></a>00567 data.setIcon( iconName ); <a name="l00568"></a>00568 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( service && !service-><a class="code" href="classKService.html#a96986870204859dc90f9dbb1d432bc15" title="Returns the name of the icon.">icon</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00569"></a>00569 data.setIcon( service-><a class="code" href="classKService.html#a96986870204859dc90f9dbb1d432bc15" title="Returns the name of the icon.">icon</a>()); <a name="l00570"></a>00570 <span class="keywordflow">if</span>( !wmclass.<a class="codeRef" href="qcstring.html#isEmpty">isEmpty</a>()) <a name="l00571"></a>00571 data.setWMClass( wmclass ); <a name="l00572"></a>00572 <span class="keywordflow">if</span>( silent ) <a name="l00573"></a>00573 data.setSilent( KStartupInfoData::Yes ); <a name="l00574"></a>00574 data.setDesktop( KWin::currentDesktop()); <a name="l00575"></a>00575 KStartupInfo::sendStartup( <span class="keywordtype">id</span>, data ); <a name="l00576"></a>00576 } <a name="l00577"></a>00577 pid_t pid = KProcessRunner::run( proc, binName, <span class="keywordtype">id</span> ); <a name="l00578"></a>00578 <span class="keywordflow">if</span>( startup_notify && pid ) <a name="l00579"></a>00579 { <a name="l00580"></a>00580 KStartupInfoData data; <a name="l00581"></a>00581 data.addPid( pid ); <a name="l00582"></a>00582 KStartupInfo::sendChange( <span class="keywordtype">id</span>, data ); <a name="l00583"></a>00583 KStartupInfo::resetStartupEnv(); <a name="l00584"></a>00584 } <a name="l00585"></a>00585 <span class="keywordflow">return</span> pid; <a name="l00586"></a>00586 <span class="preprocessor">#else</span> <a name="l00587"></a>00587 <span class="preprocessor"></span> Q_UNUSED( execName ); <a name="l00588"></a>00588 Q_UNUSED( iconName ); <a name="l00589"></a>00589 <span class="keywordflow">return</span> KProcessRunner::run( proc, bin ); <a name="l00590"></a>00590 <span class="preprocessor">#endif</span> <a name="l00591"></a>00591 <span class="preprocessor"></span>} <a name="l00592"></a>00592 <a name="l00593"></a>00593 <span class="comment">// This code is also used in klauncher.</span> <a name="l00594"></a>00594 <span class="keywordtype">bool</span> KRun::checkStartupNotify( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& <span class="comment">/*binName*/</span>, <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>* service, <span class="keywordtype">bool</span>* silent_arg, <a class="codeRef" href="qcstring.html">QCString</a>* wmclass_arg ) <a name="l00595"></a>00595 { <a name="l00596"></a>00596 <span class="keywordtype">bool</span> silent = <span class="keyword">false</span>; <a name="l00597"></a>00597 <a class="codeRef" href="qcstring.html">QCString</a> wmclass; <a name="l00598"></a>00598 <span class="keywordflow">if</span>( service && service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"StartupNotify"</span> ).<a class="codeRef" href="qvariant.html#isValid">isValid</a>()) <a name="l00599"></a>00599 { <a name="l00600"></a>00600 silent = !service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"StartupNotify"</span> ).<a class="codeRef" href="qvariant.html#toBool">toBool</a>(); <a name="l00601"></a>00601 wmclass = service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"StartupWMClass"</span> ).<a class="codeRef" href="qvariant.html#toString">toString</a>().latin1(); <a name="l00602"></a>00602 } <a name="l00603"></a>00603 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( service && service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"X-KDE-StartupNotify"</span> ).<a class="codeRef" href="qvariant.html#isValid">isValid</a>()) <a name="l00604"></a>00604 { <a name="l00605"></a>00605 silent = !service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"X-KDE-StartupNotify"</span> ).<a class="codeRef" href="qvariant.html#toBool">toBool</a>(); <a name="l00606"></a>00606 wmclass = service-><a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>( <span class="stringliteral">"X-KDE-WMClass"</span> ).<a class="codeRef" href="qvariant.html#toString">toString</a>().latin1(); <a name="l00607"></a>00607 } <a name="l00608"></a>00608 <span class="keywordflow">else</span> <span class="comment">// non-compliant app</span> <a name="l00609"></a>00609 { <a name="l00610"></a>00610 <span class="keywordflow">if</span>( service ) <a name="l00611"></a>00611 { <a name="l00612"></a>00612 <span class="keywordflow">if</span>( service-><a class="code" href="classKService.html#a505ad4cbc782d8c84807aeb11ebef524" title="Returns the type of the service.">type</a>() == <span class="stringliteral">"Application"</span> ) <a name="l00613"></a>00613 wmclass = <span class="stringliteral">"0"</span>; <span class="comment">// doesn't have .desktop entries needed, start as non-compliant</span> <a name="l00614"></a>00614 <span class="keywordflow">else</span> <a name="l00615"></a>00615 <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// no startup notification at all</span> <a name="l00616"></a>00616 } <a name="l00617"></a>00617 <span class="keywordflow">else</span> <a name="l00618"></a>00618 { <a name="l00619"></a>00619 <span class="preprocessor">#if 0</span> <a name="l00620"></a>00620 <span class="preprocessor"></span> <span class="comment">// Create startup notification even for apps for which there shouldn't be any,</span> <a name="l00621"></a>00621 <span class="comment">// just without any visual feedback. This will ensure they'll be positioned on the proper</span> <a name="l00622"></a>00622 <span class="comment">// virtual desktop, and will get user timestamp from the ASN ID.</span> <a name="l00623"></a>00623 wmclass = <span class="stringliteral">"0"</span>; <a name="l00624"></a>00624 silent = <span class="keyword">true</span>; <a name="l00625"></a>00625 <span class="preprocessor">#else // That unfortunately doesn't work, when the launched non-compliant application</span> <a name="l00626"></a>00626 <span class="preprocessor"></span> <span class="comment">// launches another one that is compliant and there is any delay inbetween (bnc:#343359)</span> <a name="l00627"></a>00627 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00628"></a>00628 <span class="preprocessor">#endif</span> <a name="l00629"></a>00629 <span class="preprocessor"></span> } <a name="l00630"></a>00630 } <a name="l00631"></a>00631 <span class="keywordflow">if</span>( silent_arg != NULL ) <a name="l00632"></a>00632 *silent_arg = silent; <a name="l00633"></a>00633 <span class="keywordflow">if</span>( wmclass_arg != NULL ) <a name="l00634"></a>00634 *wmclass_arg = wmclass; <a name="l00635"></a>00635 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00636"></a>00636 } <a name="l00637"></a>00637 <a name="l00638"></a>00638 <span class="keyword">static</span> pid_t runTempService( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service, <span class="keyword">const</span> KURL::List& _urls, <span class="keywordtype">bool</span> tempFiles, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& suggestedFileName ) <a name="l00639"></a>00639 { <a name="l00640"></a>00640 <span class="keywordflow">if</span> (!_urls.isEmpty()) { <a name="l00641"></a>00641 kdDebug(7010) << <span class="stringliteral">"runTempService: first url "</span> << _urls.first().url() << endl; <a name="l00642"></a>00642 } <a name="l00643"></a>00643 <a name="l00644"></a>00644 <a class="codeRef" href="qstringlist.html">QStringList</a> args; <a name="l00645"></a>00645 <span class="keywordflow">if</span> ((_urls.count() > 1) && !_service.<a class="code" href="classKService.html#a754d3fe8b55e138d1f8c773f1606df4a" title="Checks whether this service can handle several files as startup arguments.">allowMultipleFiles</a>()) <a name="l00646"></a>00646 { <a name="l00647"></a>00647 <span class="comment">// We need to launch the application N times. That sucks.</span> <a name="l00648"></a>00648 <span class="comment">// We ignore the result for application 2 to N.</span> <a name="l00649"></a>00649 <span class="comment">// For the first file we launch the application in the</span> <a name="l00650"></a>00650 <span class="comment">// usual way. The reported result is based on this</span> <a name="l00651"></a>00651 <span class="comment">// application.</span> <a name="l00652"></a>00652 KURL::List::ConstIterator it = _urls.begin(); <a name="l00653"></a>00653 <span class="keywordflow">while</span>(++it != _urls.end()) <a name="l00654"></a>00654 { <a name="l00655"></a>00655 KURL::List singleUrl; <a name="l00656"></a>00656 singleUrl.append(*it); <a name="l00657"></a>00657 runTempService( _service, singleUrl, tempFiles, suggestedFileName ); <a name="l00658"></a>00658 } <a name="l00659"></a>00659 KURL::List singleUrl; <a name="l00660"></a>00660 singleUrl.append(_urls.first()); <a name="l00661"></a>00661 args = <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">KRun::processDesktopExec</a>(_service, singleUrl, <span class="keyword">false</span>, tempFiles, suggestedFileName); <a name="l00662"></a>00662 } <a name="l00663"></a>00663 <span class="keywordflow">else</span> <a name="l00664"></a>00664 { <a name="l00665"></a>00665 args = <a class="code" href="classKRun.html#aef7877016f7c1befedd20dd38549907a" title="Processes a Exec= line as found in .desktop files.">KRun::processDesktopExec</a>(_service, _urls, <span class="keyword">false</span>, tempFiles, suggestedFileName); <a name="l00666"></a>00666 } <a name="l00667"></a>00667 kdDebug(7010) << <span class="stringliteral">"runTempService: KProcess args="</span> << args << endl; <a name="l00668"></a>00668 <a name="l00669"></a>00669 KProcess * proc = <span class="keyword">new</span> KProcess; <a name="l00670"></a>00670 *proc << args; <a name="l00671"></a>00671 <a name="l00672"></a>00672 <span class="keywordflow">if</span> (!_service.<a class="code" href="classKService.html#a7377fcd95d57c81a01e2f270da6aec1d" title="Returns the working directory to run the program in.">path</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00673"></a>00673 proc->setWorkingDirectory(_service.<a class="code" href="classKService.html#a7377fcd95d57c81a01e2f270da6aec1d" title="Returns the working directory to run the program in.">path</a>()); <a name="l00674"></a>00674 <a name="l00675"></a>00675 <span class="keywordflow">return</span> runCommandInternal( proc, &_service, <a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0" title="Given a full command line (e.g.">KRun::binaryName</a>( _service.<a class="code" href="classKService.html#a4a0471572826ed8239b85505506b4c7c" title="Returns the executable.">exec</a>(), false ), <a name="l00676"></a>00676 _service.<a class="code" href="classKService.html#a206dd1927ae8f591074630c370cc39ee" title="Returns the name of the service.">name</a>(), _service.<a class="code" href="classKService.html#a96986870204859dc90f9dbb1d432bc15" title="Returns the name of the icon.">icon</a>() ); <a name="l00677"></a>00677 } <a name="l00678"></a>00678 <a name="l00679"></a>00679 <span class="comment">// WARNING: don't call this from processDesktopExec, since klauncher uses that too...</span> <a name="l00680"></a>00680 <span class="keyword">static</span> KURL::List resolveURLs( <span class="keyword">const</span> KURL::List& _urls, <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service ) <a name="l00681"></a>00681 { <a name="l00682"></a>00682 <span class="comment">// Check which protocols the application supports.</span> <a name="l00683"></a>00683 <span class="comment">// This can be a list of actual protocol names, or just KIO for KDE apps.</span> <a name="l00684"></a>00684 <a class="codeRef" href="qstringlist.html">QStringList</a> supportedProtocols = _service.<a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>(<span class="stringliteral">"X-KDE-Protocols"</span>).<a class="codeRef" href="qvariant.html#toStringList">toStringList</a>(); <a name="l00685"></a>00685 KRunMX1 mx1( _service ); <a name="l00686"></a>00686 <a class="codeRef" href="qstring.html">QString</a> exec = _service.<a class="code" href="classKService.html#a4a0471572826ed8239b85505506b4c7c" title="Returns the executable.">exec</a>(); <a name="l00687"></a>00687 <span class="keywordflow">if</span> ( mx1.expandMacrosShellQuote( exec ) && !mx1.hasUrls ) { <a name="l00688"></a>00688 Q_ASSERT( supportedProtocols.isEmpty() ); <span class="comment">// huh? If you support protocols you need %u or %U...</span> <a name="l00689"></a>00689 } <span class="keywordflow">else</span> { <a name="l00690"></a>00690 <span class="keywordflow">if</span> ( supportedProtocols.isEmpty() ) <a name="l00691"></a>00691 { <a name="l00692"></a>00692 <span class="comment">// compat mode: assume KIO if not set and it's a KDE app</span> <a name="l00693"></a>00693 <a class="codeRef" href="qstringlist.html">QStringList</a> categories = _service.<a class="code" href="classKService.html#aebaff8ace9dc52f73326b3086a6b687a" title="Returns the requested property.">property</a>(<span class="stringliteral">"Categories"</span>).<a class="codeRef" href="qvariant.html#toStringList">toStringList</a>(); <a name="l00694"></a>00694 <span class="keywordflow">if</span> ( categories.find(<span class="stringliteral">"KDE"</span>) != categories.end() ) <a name="l00695"></a>00695 supportedProtocols.append( <span class="stringliteral">"KIO"</span> ); <a name="l00696"></a>00696 <span class="keywordflow">else</span> { <span class="comment">// if no KDE app, be a bit over-generic</span> <a name="l00697"></a>00697 supportedProtocols.append( <span class="stringliteral">"http"</span>); <a name="l00698"></a>00698 supportedProtocols.append( <span class="stringliteral">"ftp"</span>); <a name="l00699"></a>00699 } <a name="l00700"></a>00700 } <a name="l00701"></a>00701 } <a name="l00702"></a>00702 kdDebug(7010) << <span class="stringliteral">"supportedProtocols:"</span> << supportedProtocols << endl; <a name="l00703"></a>00703 <a name="l00704"></a>00704 KURL::List urls( _urls ); <a name="l00705"></a>00705 <span class="keywordflow">if</span> ( supportedProtocols.find( <span class="stringliteral">"KIO"</span> ) == supportedProtocols.end() ) { <a name="l00706"></a>00706 <span class="keywordflow">for</span>( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) { <a name="l00707"></a>00707 <span class="keyword">const</span> KURL url = *it; <a name="l00708"></a>00708 <span class="keywordtype">bool</span> supported = url.isLocalFile() || supportedProtocols.find( url.protocol().lower() ) != supportedProtocols.end(); <a name="l00709"></a>00709 kdDebug(7010) << <span class="stringliteral">"Looking at url="</span> << url << <span class="stringliteral">" supported="</span> << supported << endl; <a name="l00710"></a>00710 <span class="keywordflow">if</span> ( !supported && <a class="code" href="classKProtocolInfo.html#a7f856e6bc5d76dfafec093835c406821" title="Returns the protocol class for the specified protocol.">KProtocolInfo::protocolClass</a>(url.protocol()) == <span class="stringliteral">":local"</span> ) <a name="l00711"></a>00711 { <a name="l00712"></a>00712 <span class="comment">// Maybe we can resolve to a local URL?</span> <a name="l00713"></a>00713 KURL localURL = <a class="code" href="classKIO_1_1NetAccess.html#a332f5c5a9b5f054ef581b6b5ddeca5e2" title="Tries to map a local URL for the given URL.">KIO::NetAccess::mostLocalURL</a>( url, 0 ); <a name="l00714"></a>00714 <span class="keywordflow">if</span> ( localURL != url ) { <a name="l00715"></a>00715 *it = localURL; <a name="l00716"></a>00716 kdDebug(7010) << <span class="stringliteral">"Changed to "</span> << localURL << endl; <a name="l00717"></a>00717 } <a name="l00718"></a>00718 } <a name="l00719"></a>00719 } <a name="l00720"></a>00720 } <a name="l00721"></a>00721 <span class="keywordflow">return</span> urls; <a name="l00722"></a>00722 } <a name="l00723"></a>00723 <a name="l00724"></a>00724 <span class="comment">// BIC merge methods below</span> <a name="l00725"></a>00725 pid_t <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service, <span class="keyword">const</span> KURL::List& _urls ) <a name="l00726"></a>00726 { <a name="l00727"></a>00727 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( _service, _urls, 0, <span class="keyword">false</span>, QString::null ); <a name="l00728"></a>00728 } <a name="l00729"></a>00729 <a name="l00730"></a><a class="code" href="classKRun.html#a3a73dc0693a3b17dd8f4c4dac18ae2b5">00730</a> pid_t <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service, <span class="keyword">const</span> KURL::List& _urls, <span class="keywordtype">bool</span> tempFiles ) <a name="l00731"></a>00731 { <a name="l00732"></a>00732 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( _service, _urls, 0, tempFiles, QString::null ); <a name="l00733"></a>00733 } <a name="l00734"></a>00734 <a name="l00735"></a><a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f">00735</a> pid_t <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service, <span class="keyword">const</span> KURL::List& _urls, <a class="codeRef" href="qwidget.html">QWidget</a>* window, <span class="keywordtype">bool</span> tempFiles ) <a name="l00736"></a>00736 { <a name="l00737"></a>00737 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( _service, _urls, window, tempFiles, QString::null ); <a name="l00738"></a>00738 } <a name="l00739"></a>00739 <a name="l00740"></a><a class="code" href="classKRun.html#adbccd08c050f7b7f6a871f559d2063df">00740</a> pid_t <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( <span class="keyword">const</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>& _service, <span class="keyword">const</span> KURL::List& _urls, <a class="codeRef" href="qwidget.html">QWidget</a>* window, <span class="keywordtype">bool</span> tempFiles, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& suggestedFileName ) <a name="l00741"></a>00741 { <a name="l00742"></a>00742 <span class="keywordflow">if</span> (!_service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() && <a name="l00743"></a>00743 !KDesktopFile::isAuthorizedDesktopFile( _service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>())) <a name="l00744"></a>00744 { <a name="l00745"></a>00745 kdWarning() << <span class="stringliteral">"No authorization to execute "</span> << _service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>() << endl; <a name="l00746"></a>00746 KMessageBox::sorry(window, i18n(<span class="stringliteral">"You are not authorized to execute this service."</span>)); <a name="l00747"></a>00747 <span class="keywordflow">return</span> 0; <a name="l00748"></a>00748 } <a name="l00749"></a>00749 <a name="l00750"></a>00750 <span class="keywordflow">if</span> ( !tempFiles ) <a name="l00751"></a>00751 { <a name="l00752"></a>00752 <span class="comment">// Remember we opened those urls, for the "recent documents" menu in kicker</span> <a name="l00753"></a>00753 KURL::List::ConstIterator it = _urls.begin(); <a name="l00754"></a>00754 <span class="keywordflow">for</span>(; it != _urls.end(); ++it) { <a name="l00755"></a>00755 <span class="comment">//kdDebug(7010) << "KRecentDocument::adding " << (*it).url() << endl;</span> <a name="l00756"></a>00756 KRecentDocument::add( *it, _service.<a class="code" href="classKService.html#a46068cdfad6f69c7e24992291cc879d0" title="Returns the filename of the service desktop entry without any extension.">desktopEntryName</a>() ); <a name="l00757"></a>00757 } <a name="l00758"></a>00758 } <a name="l00759"></a>00759 <a name="l00760"></a>00760 <span class="keywordflow">if</span> ( tempFiles || _service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() || !suggestedFileName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ) <a name="l00761"></a>00761 { <a name="l00762"></a>00762 <span class="keywordflow">return</span> runTempService(_service, _urls, tempFiles, suggestedFileName); <a name="l00763"></a>00763 } <a name="l00764"></a>00764 <a name="l00765"></a>00765 kdDebug(7010) << <span class="stringliteral">"KRun::run "</span> << _service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>() << endl; <a name="l00766"></a>00766 <a name="l00767"></a>00767 <span class="keywordflow">if</span> (!_urls.isEmpty()) { <a name="l00768"></a>00768 kdDebug(7010) << <span class="stringliteral">"First url "</span> << _urls.first().url() << endl; <a name="l00769"></a>00769 } <a name="l00770"></a>00770 <a name="l00771"></a>00771 <span class="comment">// Resolve urls if needed, depending on what the app supports</span> <a name="l00772"></a>00772 <span class="keyword">const</span> KURL::List urls = resolveURLs( _urls, _service ); <a name="l00773"></a>00773 <a name="l00774"></a>00774 <a class="codeRef" href="qstring.html">QString</a> <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">error</a>; <a name="l00775"></a>00775 <span class="keywordtype">int</span> pid = 0; <a name="l00776"></a>00776 <a name="l00777"></a>00777 <span class="keywordtype">int</span> i = KApplication::startServiceByDesktopPath( <a name="l00778"></a>00778 _service.<a class="code" href="classKService.html#a1dd162ea11b51511a37d202202aa96f1" title="Returns the path to the location where the service desktop entry is stored.">desktopEntryPath</a>(), urls.toStringList(), &<a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">error</a>, 0L, &pid <a name="l00779"></a>00779 ); <a name="l00780"></a>00780 <a name="l00781"></a>00781 <span class="keywordflow">if</span> (i != 0) <a name="l00782"></a>00782 { <a name="l00783"></a>00783 kdDebug(7010) << error << endl; <a name="l00784"></a>00784 KMessageBox::sorry( window, error ); <a name="l00785"></a>00785 <span class="keywordflow">return</span> 0; <a name="l00786"></a>00786 } <a name="l00787"></a>00787 <a name="l00788"></a>00788 kdDebug(7010) << <span class="stringliteral">"startServiceByDesktopPath worked fine"</span> << endl; <a name="l00789"></a>00789 <span class="keywordflow">return</span> (pid_t) pid; <a name="l00790"></a>00790 } <a name="l00791"></a>00791 <a name="l00792"></a>00792 <a name="l00793"></a><a class="code" href="classKRun.html#a995bc1308f9ccd35cf42b4d1e448006d">00793</a> pid_t <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _exec, <span class="keyword">const</span> KURL::List& _urls, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _name, <a name="l00794"></a>00794 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& _icon, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>&, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>&) <a name="l00795"></a>00795 { <a name="l00796"></a>00796 KService::Ptr service = <span class="keyword">new</span> <a class="code" href="classKService.html" title="Represent a service, i.e.">KService</a>(_name, _exec, _icon); <a name="l00797"></a>00797 <a name="l00798"></a>00798 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>(*service, _urls); <a name="l00799"></a>00799 } <a name="l00800"></a>00800 <a name="l00801"></a><a class="code" href="classKRun.html#acbf97c72c343ef24a427e744d63139bc">00801</a> pid_t <a class="code" href="classKRun.html#acbf97c72c343ef24a427e744d63139bc" title="Run the given shell command and notifies kicker of the starting of the application.">KRun::runCommand</a>( <a class="codeRef" href="qstring.html">QString</a> cmd ) <a name="l00802"></a>00802 { <a name="l00803"></a>00803 <span class="keywordflow">return</span> <a class="code" href="classKRun.html#acbf97c72c343ef24a427e744d63139bc" title="Run the given shell command and notifies kicker of the starting of the application.">KRun::runCommand</a>( cmd, QString::null, QString::null ); <a name="l00804"></a>00804 } <a name="l00805"></a>00805 <a name="l00806"></a><a class="code" href="classKRun.html#a83990b8cb95e5a1440ec63fe8d132e93">00806</a> pid_t <a class="code" href="classKRun.html#acbf97c72c343ef24a427e744d63139bc" title="Run the given shell command and notifies kicker of the starting of the application.">KRun::runCommand</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& cmd, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &execName, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & iconName ) <a name="l00807"></a>00807 { <a name="l00808"></a>00808 kdDebug(7010) << <span class="stringliteral">"runCommand "</span> << cmd << <span class="stringliteral">","</span> << execName << endl; <a name="l00809"></a>00809 KProcess * proc = <span class="keyword">new</span> KProcess; <a name="l00810"></a>00810 proc->setUseShell(<span class="keyword">true</span>); <a name="l00811"></a>00811 *proc << cmd; <a name="l00812"></a>00812 KService::Ptr service = <a class="code" href="classKService.html#a6261ba7fcb0954a985fdba31dc6b6cf7" title="Find a service by the name of its desktop file, not depending on its actual location (as long as it's...">KService::serviceByDesktopName</a>( <a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0" title="Given a full command line (e.g.">binaryName</a>( execName, <span class="keyword">true</span> ) ); <a name="l00813"></a>00813 <span class="keywordflow">return</span> runCommandInternal( proc, service.data(), <a class="code" href="classKRun.html#ae438b189a47858938d1428999a82a7c0" title="Given a full command line (e.g.">binaryName</a>( execName, <span class="keyword">false</span> ), execName, iconName ); <a name="l00814"></a>00814 } <a name="l00815"></a>00815 <a name="l00816"></a><a class="code" href="classKRun.html#adbd4d18bcb4c57ed5cac39f7c75e0617">00816</a> <a class="code" href="classKRun.html#adbd4d18bcb4c57ed5cac39f7c75e0617" title="Create a KRun object to run the preferred application for a file/URL.">KRun::KRun</a>( <span class="keyword">const</span> KURL& url, mode_t mode, <span class="keywordtype">bool</span> isLocalFile, <span class="keywordtype">bool</span> showProgressInfo ) <a name="l00817"></a>00817 :m_timer(0,<span class="stringliteral">"KRun::timer"</span>) <a name="l00818"></a>00818 { <a name="l00819"></a>00819 init (url, 0, mode, isLocalFile, showProgressInfo); <a name="l00820"></a>00820 } <a name="l00821"></a>00821 <a name="l00822"></a><a class="code" href="classKRun.html#aaf297eec7c336036bda8c6465f80d094">00822</a> <a class="code" href="classKRun.html#adbd4d18bcb4c57ed5cac39f7c75e0617" title="Create a KRun object to run the preferred application for a file/URL.">KRun::KRun</a>( <span class="keyword">const</span> KURL& url, <a class="codeRef" href="qwidget.html">QWidget</a>* window, mode_t mode, <span class="keywordtype">bool</span> isLocalFile, <a name="l00823"></a>00823 <span class="keywordtype">bool</span> showProgressInfo ) <a name="l00824"></a>00824 :m_timer(0,<span class="stringliteral">"KRun::timer"</span>) <a name="l00825"></a>00825 { <a name="l00826"></a>00826 init (url, window, mode, isLocalFile, showProgressInfo); <a name="l00827"></a>00827 } <a name="l00828"></a>00828 <a name="l00829"></a>00829 <span class="keywordtype">void</span> KRun::init ( <span class="keyword">const</span> KURL& url, <a class="codeRef" href="qwidget.html">QWidget</a>* window, mode_t mode, <span class="keywordtype">bool</span> isLocalFile, <a name="l00830"></a>00830 <span class="keywordtype">bool</span> showProgressInfo ) <a name="l00831"></a>00831 { <a name="l00832"></a>00832 m_bFault = <span class="keyword">false</span>; <a name="l00833"></a>00833 m_bAutoDelete = <span class="keyword">true</span>; <a name="l00834"></a>00834 m_bProgressInfo = showProgressInfo; <a name="l00835"></a>00835 m_bFinished = <span class="keyword">false</span>; <a name="l00836"></a>00836 m_job = 0L; <a name="l00837"></a>00837 m_strURL = url; <a name="l00838"></a>00838 <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> = <span class="keyword">false</span>; <a name="l00839"></a>00839 m_bIsDirectory = <span class="keyword">false</span>; <a name="l00840"></a>00840 m_bIsLocalFile = isLocalFile; <a name="l00841"></a>00841 m_mode = mode; <a name="l00842"></a>00842 d = <span class="keyword">new</span> KRunPrivate; <a name="l00843"></a>00843 d->m_runExecutables = <span class="keyword">true</span>; <a name="l00844"></a>00844 d->m_window = window; <a name="l00845"></a>00845 <a class="code" href="classKRun.html#a6a9a9f87d73a222e02a54f20e10d707f" title="Sets whether the external webbrowser setting should be honoured.">setEnableExternalBrowser</a>(<span class="keyword">true</span>); <a name="l00846"></a>00846 <a name="l00847"></a>00847 <span class="comment">// Start the timer. This means we will return to the event</span> <a name="l00848"></a>00848 <span class="comment">// loop and do initialization afterwards.</span> <a name="l00849"></a>00849 <span class="comment">// Reason: We must complete the constructor before we do anything else.</span> <a name="l00850"></a>00850 <a class="code" href="classKRun.html#a259e6cbfe56fd75f66816df50e77ef01" title="USed to indicate that the next action is to initialize.">m_bInit</a> = <span class="keyword">true</span>; <a name="l00851"></a>00851 <a class="codeRef" href="qobject.html#connect">connect</a>( &m_timer, SIGNAL( timeout() ), <span class="keyword">this</span>, SLOT( slotTimeout() ) ); <a name="l00852"></a>00852 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l00853"></a>00853 kdDebug(7010) << <span class="stringliteral">" new KRun "</span> << <span class="keyword">this</span> << <span class="stringliteral">" "</span> << url.prettyURL() << <span class="stringliteral">" timer="</span> << &m_timer << endl; <a name="l00854"></a>00854 <a name="l00855"></a>00855 kapp->ref(); <a name="l00856"></a>00856 } <a name="l00857"></a>00857 <a name="l00858"></a>00858 <span class="keywordtype">void</span> KRun::init() <a name="l00859"></a>00859 { <a name="l00860"></a>00860 kdDebug(7010) << <span class="stringliteral">"INIT called"</span> << endl; <a name="l00861"></a>00861 <span class="keywordflow">if</span> ( !m_strURL.isValid() ) <a name="l00862"></a>00862 { <a name="l00863"></a>00863 d->m_showingError = <span class="keyword">true</span>; <a name="l00864"></a>00864 <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">KMessageBoxWrapper::error</a>( d->m_window, i18n( <span class="stringliteral">"Malformed URL\n%1"</span> ).arg( m_strURL.url() ) ); <a name="l00865"></a>00865 d->m_showingError = <span class="keyword">false</span>; <a name="l00866"></a>00866 m_bFault = <span class="keyword">true</span>; <a name="l00867"></a>00867 m_bFinished = <span class="keyword">true</span>; <a name="l00868"></a>00868 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l00869"></a>00869 <span class="keywordflow">return</span>; <a name="l00870"></a>00870 } <a name="l00871"></a>00871 <span class="keywordflow">if</span> ( !kapp->authorizeURLAction( <span class="stringliteral">"open"</span>, KURL(), m_strURL)) <a name="l00872"></a>00872 { <a name="l00873"></a>00873 <a class="codeRef" href="qstring.html">QString</a> msg = <a class="code" href="namespaceKIO.html#a46521cadccc2b2e81a7469c61e413e52" title="Returns a translated error message for errorCode using the additional error information provided by e...">KIO::buildErrorString</a>(KIO::ERR_ACCESS_DENIED, m_strURL.prettyURL()); <a name="l00874"></a>00874 d->m_showingError = <span class="keyword">true</span>; <a name="l00875"></a>00875 <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">KMessageBoxWrapper::error</a>( d->m_window, msg ); <a name="l00876"></a>00876 d->m_showingError = <span class="keyword">false</span>; <a name="l00877"></a>00877 m_bFault = <span class="keyword">true</span>; <a name="l00878"></a>00878 m_bFinished = <span class="keyword">true</span>; <a name="l00879"></a>00879 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l00880"></a>00880 <span class="keywordflow">return</span>; <a name="l00881"></a>00881 } <a name="l00882"></a>00882 <a name="l00883"></a>00883 <span class="keywordflow">if</span> ( !m_bIsLocalFile && m_strURL.isLocalFile() ) <a name="l00884"></a>00884 m_bIsLocalFile = <span class="keyword">true</span>; <a name="l00885"></a>00885 <a name="l00886"></a>00886 <a class="codeRef" href="qstring.html">QString</a> exec; <a name="l00887"></a>00887 <span class="keywordflow">if</span> (m_strURL.protocol().startsWith(<span class="stringliteral">"http"</span>)) <a name="l00888"></a>00888 { <a name="l00889"></a>00889 exec = d->m_externalBrowser; <a name="l00890"></a>00890 } <a name="l00891"></a>00891 <a name="l00892"></a>00892 <span class="keywordflow">if</span> ( m_bIsLocalFile ) <a name="l00893"></a>00893 { <a name="l00894"></a>00894 <span class="keywordflow">if</span> ( m_mode == 0 ) <a name="l00895"></a>00895 { <a name="l00896"></a>00896 KDE_struct_stat buff; <a name="l00897"></a>00897 <span class="keywordflow">if</span> ( KDE_stat( <a class="codeRef" href="qfile.html#encodeName">QFile::encodeName</a>(m_strURL.path()), &buff ) == -1 ) <a name="l00898"></a>00898 { <a name="l00899"></a>00899 d->m_showingError = <span class="keyword">true</span>; <a name="l00900"></a>00900 <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">KMessageBoxWrapper::error</a>( d->m_window, i18n( <span class="stringliteral">"<qt>Unable to run the command specified. The file or folder <b>%1</b> does not exist.</qt>"</span> ).arg( m_strURL.htmlURL() ) ); <a name="l00901"></a>00901 d->m_showingError = <span class="keyword">false</span>; <a name="l00902"></a>00902 m_bFault = <span class="keyword">true</span>; <a name="l00903"></a>00903 m_bFinished = <span class="keyword">true</span>; <a name="l00904"></a>00904 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l00905"></a>00905 <span class="keywordflow">return</span>; <a name="l00906"></a>00906 } <a name="l00907"></a>00907 m_mode = buff.st_mode; <a name="l00908"></a>00908 } <a name="l00909"></a>00909 <a name="l00910"></a>00910 KMimeType::Ptr mime = <a class="code" href="classKMimeType.html#a19c6563574d22a7395c4686c06e1dec9" title="Finds a KMimeType with the given _url.">KMimeType::findByURL</a>( m_strURL, m_mode, m_bIsLocalFile ); <a name="l00911"></a>00911 assert( mime != 0L ); <a name="l00912"></a>00912 kdDebug(7010) << <span class="stringliteral">"MIME TYPE is "</span> << mime->name() << endl; <a name="l00913"></a>00913 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( mime->name() ); <a name="l00914"></a>00914 <span class="keywordflow">return</span>; <a name="l00915"></a>00915 } <a name="l00916"></a>00916 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !exec.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() || <a class="code" href="classKProtocolInfo.html#a6fd97e51d5f796233e47b576ffcb4758" title="Returns whether the protocol can act as a helper protocol.">KProtocolInfo::isHelperProtocol</a>( m_strURL ) ) { <a name="l00917"></a>00917 kdDebug(7010) << <span class="stringliteral">"Helper protocol"</span> << endl; <a name="l00918"></a>00918 <a name="l00919"></a>00919 <span class="keywordtype">bool</span> ok = <span class="keyword">false</span>; <a name="l00920"></a>00920 KURL::List urls; <a name="l00921"></a>00921 urls.append( m_strURL ); <a name="l00922"></a>00922 <span class="keywordflow">if</span> (exec.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00923"></a>00923 { <a name="l00924"></a>00924 exec = <a class="code" href="classKProtocolInfo.html#a7f45e3fbe8fecde9dbd4ad17008dd941" title="Returns the library / executable to open for the protocol protocol Example : "kio_ftp", meaning either the executable "kio_ftp" or the library "kio_ftp.la" (recommended), whichever is available.">KProtocolInfo::exec</a>( m_strURL.protocol() ); <a name="l00925"></a>00925 <span class="keywordflow">if</span> (exec.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) <a name="l00926"></a>00926 { <a name="l00927"></a>00927 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>(<a class="code" href="classKProtocolInfo.html#a633c57a28280593c73fdc6bae63859a3" title="Returns default mimetype for this URL based on the protocol.">KProtocolInfo::defaultMimetype</a>(m_strURL)); <a name="l00928"></a>00928 <span class="keywordflow">return</span>; <a name="l00929"></a>00929 } <a name="l00930"></a>00930 <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( exec, urls ); <a name="l00931"></a>00931 ok = <span class="keyword">true</span>; <a name="l00932"></a>00932 } <a name="l00933"></a>00933 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (exec.<a class="codeRef" href="qstring.html#startsWith">startsWith</a>(<span class="stringliteral">"!"</span>)) <a name="l00934"></a>00934 { <a name="l00935"></a>00935 exec = exec.<a class="codeRef" href="qstring.html#mid">mid</a>(1); <span class="comment">// Literal command</span> <a name="l00936"></a>00936 exec += <span class="stringliteral">" %u"</span>; <a name="l00937"></a>00937 <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( exec, urls ); <a name="l00938"></a>00938 ok = <span class="keyword">true</span>; <a name="l00939"></a>00939 } <a name="l00940"></a>00940 <span class="keywordflow">else</span> <a name="l00941"></a>00941 { <a name="l00942"></a>00942 KService::Ptr service = <a class="code" href="classKService.html#a18103ccedb6d50a2148af738ca78c721" title="Find a service by its storage-id or desktop-file path.">KService::serviceByStorageId</a>( exec ); <a name="l00943"></a>00943 <span class="keywordflow">if</span> (service) <a name="l00944"></a>00944 { <a name="l00945"></a>00945 <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">run</a>( *service, urls ); <a name="l00946"></a>00946 ok = <span class="keyword">true</span>; <a name="l00947"></a>00947 } <a name="l00948"></a>00948 } <a name="l00949"></a>00949 <a name="l00950"></a>00950 <span class="keywordflow">if</span> (ok) <a name="l00951"></a>00951 { <a name="l00952"></a>00952 m_bFinished = <span class="keyword">true</span>; <a name="l00953"></a>00953 <span class="comment">// will emit the error and autodelete this</span> <a name="l00954"></a>00954 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l00955"></a>00955 <span class="keywordflow">return</span>; <a name="l00956"></a>00956 } <a name="l00957"></a>00957 } <a name="l00958"></a>00958 <a name="l00959"></a>00959 <span class="comment">// Did we already get the information that it is a directory ?</span> <a name="l00960"></a>00960 <span class="keywordflow">if</span> ( S_ISDIR( m_mode ) ) <a name="l00961"></a>00961 { <a name="l00962"></a>00962 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( <span class="stringliteral">"inode/directory"</span> ); <a name="l00963"></a>00963 <span class="keywordflow">return</span>; <a name="l00964"></a>00964 } <a name="l00965"></a>00965 <a name="l00966"></a>00966 <span class="comment">// Let's see whether it is a directory</span> <a name="l00967"></a>00967 <a name="l00968"></a>00968 <span class="keywordflow">if</span> ( !<a class="code" href="classKProtocolInfo.html#aded7248cbb6534d8f200f98bfdbe8bfd" title="Returns whether the protocol can list files/objects.">KProtocolInfo::supportsListing</a>( m_strURL ) ) <a name="l00969"></a>00969 { <a name="l00970"></a>00970 <span class="comment">//kdDebug(7010) << "Protocol has no support for listing" << endl;</span> <a name="l00971"></a>00971 <span class="comment">// No support for listing => it can't be a directory (example: http)</span> <a name="l00972"></a>00972 scanFile(); <a name="l00973"></a>00973 <span class="keywordflow">return</span>; <a name="l00974"></a>00974 } <a name="l00975"></a>00975 <a name="l00976"></a>00976 kdDebug(7010) << <span class="stringliteral">"Testing directory (stating)"</span> << endl; <a name="l00977"></a>00977 <a name="l00978"></a>00978 <span class="comment">// It may be a directory or a file, let's stat</span> <a name="l00979"></a>00979 <a class="code" href="classKIO_1_1StatJob.html" title="A KIO job that retrieves information about a file or directory.">KIO::StatJob</a> *job = <a class="code" href="namespaceKIO.html#a4f24010fae6634055f8111c07e4fa068" title="Find all details for one file or directory.">KIO::stat</a>( m_strURL, <span class="keyword">true</span>, 0 <span class="comment">/* no details */</span>, m_bProgressInfo ); <a name="l00980"></a>00980 job-><a class="code" href="classKIO_1_1Job.html#a6a7dc461bef70853f3b04ff1d3db3318" title="Associate this job with a window given by window.">setWindow</a> (d->m_window); <a name="l00981"></a>00981 <a class="codeRef" href="qobject.html#connect">connect</a>( job, SIGNAL( result( <a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> * ) ), <a name="l00982"></a>00982 <span class="keyword">this</span>, SLOT( slotStatResult( <a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> * ) ) ); <a name="l00983"></a>00983 m_job = job; <a name="l00984"></a>00984 kdDebug(7010) << <span class="stringliteral">" Job "</span> << job << <span class="stringliteral">" is about stating "</span> << m_strURL.url() << endl; <a name="l00985"></a>00985 } <a name="l00986"></a>00986 <a name="l00987"></a><a class="code" href="classKRun.html#ad127a5f5753259a996800dcc0352170f">00987</a> <a class="code" href="classKRun.html#ad127a5f5753259a996800dcc0352170f" title="Destructor.">KRun::~KRun</a>() <a name="l00988"></a>00988 { <a name="l00989"></a>00989 kdDebug(7010) << <span class="stringliteral">"KRun::~KRun() "</span> << <span class="keyword">this</span> << endl; <a name="l00990"></a>00990 m_timer.<a class="codeRef" href="qtimer.html#stop">stop</a>(); <a name="l00991"></a>00991 killJob(); <a name="l00992"></a>00992 kapp->deref(); <a name="l00993"></a>00993 kdDebug(7010) << <span class="stringliteral">"KRun::~KRun() done "</span> << <span class="keyword">this</span> << endl; <a name="l00994"></a>00994 <span class="keyword">delete</span> d; <a name="l00995"></a>00995 } <a name="l00996"></a>00996 <a name="l00997"></a>00997 <span class="keywordtype">void</span> KRun::scanFile() <a name="l00998"></a>00998 { <a name="l00999"></a>00999 kdDebug(7010) << <span class="stringliteral">"###### KRun::scanFile "</span> << m_strURL.url() << endl; <a name="l01000"></a>01000 <span class="comment">// First, let's check for well-known extensions</span> <a name="l01001"></a>01001 <span class="comment">// Not when there is a query in the URL, in any case.</span> <a name="l01002"></a>01002 <span class="keywordflow">if</span> ( m_strURL.query().isEmpty() ) <a name="l01003"></a>01003 { <a name="l01004"></a>01004 KMimeType::Ptr mime = <a class="code" href="classKMimeType.html#a19c6563574d22a7395c4686c06e1dec9" title="Finds a KMimeType with the given _url.">KMimeType::findByURL</a>( m_strURL ); <a name="l01005"></a>01005 assert( mime != 0L ); <a name="l01006"></a>01006 <span class="keywordflow">if</span> ( mime->name() != <span class="stringliteral">"application/octet-stream"</span> || m_bIsLocalFile ) <a name="l01007"></a>01007 { <a name="l01008"></a>01008 kdDebug(7010) << <span class="stringliteral">"Scanfile: MIME TYPE is "</span> << mime->name() << endl; <a name="l01009"></a>01009 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( mime->name() ); <a name="l01010"></a>01010 <span class="keywordflow">return</span>; <a name="l01011"></a>01011 } <a name="l01012"></a>01012 } <a name="l01013"></a>01013 <a name="l01014"></a>01014 <span class="comment">// No mimetype found, and the URL is not local (or fast mode not allowed).</span> <a name="l01015"></a>01015 <span class="comment">// We need to apply the 'KIO' method, i.e. either asking the server or</span> <a name="l01016"></a>01016 <span class="comment">// getting some data out of the file, to know what mimetype it is.</span> <a name="l01017"></a>01017 <a name="l01018"></a>01018 <span class="keywordflow">if</span> ( !<a class="code" href="classKProtocolInfo.html#a2abb9dc61a6235f7f18b145570dd6356" title="Returns whether the protocol can retrieve data from URLs.">KProtocolInfo::supportsReading</a>( m_strURL ) ) <a name="l01019"></a>01019 { <a name="l01020"></a>01020 kdError(7010) << <span class="stringliteral">"#### NO SUPPORT FOR READING!"</span> << endl; <a name="l01021"></a>01021 m_bFault = <span class="keyword">true</span>; <a name="l01022"></a>01022 m_bFinished = <span class="keyword">true</span>; <a name="l01023"></a>01023 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01024"></a>01024 <span class="keywordflow">return</span>; <a name="l01025"></a>01025 } <a name="l01026"></a>01026 kdDebug(7010) << <span class="keyword">this</span> << <span class="stringliteral">" Scanning file "</span> << m_strURL.url() << endl; <a name="l01027"></a>01027 <a name="l01028"></a>01028 <a class="code" href="classKIO_1_1TransferJob.html" title="The transfer job pumps data into and/or out of a Slave.">KIO::TransferJob</a> *job = <a class="code" href="namespaceKIO.html#a0903950177f6943f35246a7ad577ac1c" title="Get (a.k.a.">KIO::get</a>( m_strURL, <span class="keyword">false</span> <span class="comment">/*reload*/</span>, m_bProgressInfo ); <a name="l01029"></a>01029 job-><a class="code" href="classKIO_1_1Job.html#a6a7dc461bef70853f3b04ff1d3db3318" title="Associate this job with a window given by window.">setWindow</a> (d->m_window); <a name="l01030"></a>01030 <a class="codeRef" href="qobject.html#connect">connect</a>(job, SIGNAL( result(<a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *)), <a name="l01031"></a>01031 <span class="keyword">this</span>, SLOT( slotScanFinished(<a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *))); <a name="l01032"></a>01032 <a class="codeRef" href="qobject.html#connect">connect</a>(job, SIGNAL( <a class="code" href="namespaceKIO.html#a612253f480b1c383e6c803f6092a6440" title="Find mimetype for one file or directory.">mimetype</a>(<a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &)), <a name="l01033"></a>01033 <span class="keyword">this</span>, SLOT( slotScanMimeType(<a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &))); <a name="l01034"></a>01034 m_job = job; <a name="l01035"></a>01035 kdDebug(7010) << <span class="stringliteral">" Job "</span> << job << <span class="stringliteral">" is about getting from "</span> << m_strURL.url() << endl; <a name="l01036"></a>01036 } <a name="l01037"></a>01037 <a name="l01038"></a>01038 <span class="keywordtype">void</span> KRun::slotTimeout() <a name="l01039"></a>01039 { <a name="l01040"></a>01040 kdDebug(7010) << <span class="keyword">this</span> << <span class="stringliteral">" slotTimeout called"</span> << endl; <a name="l01041"></a>01041 <span class="keywordflow">if</span> ( <a class="code" href="classKRun.html#a259e6cbfe56fd75f66816df50e77ef01" title="USed to indicate that the next action is to initialize.">m_bInit</a> ) <a name="l01042"></a>01042 { <a name="l01043"></a>01043 <a class="code" href="classKRun.html#a259e6cbfe56fd75f66816df50e77ef01" title="USed to indicate that the next action is to initialize.">m_bInit</a> = <span class="keyword">false</span>; <a name="l01044"></a>01044 init(); <a name="l01045"></a>01045 <span class="keywordflow">return</span>; <a name="l01046"></a>01046 } <a name="l01047"></a>01047 <a name="l01048"></a>01048 <span class="keywordflow">if</span> ( m_bFault ) { <a name="l01049"></a>01049 emit <a class="code" href="classKRun.html#a8b6f349976e50ef379fdda66037d3afb" title="Emitted when the operation had an error.">error</a>(); <a name="l01050"></a>01050 } <a name="l01051"></a>01051 <span class="keywordflow">if</span> ( m_bFinished ) { <a name="l01052"></a>01052 emit <a class="code" href="classKRun.html#a0811ba8471c6a70e6bd1f7c16f4ca775" title="Emitted when the operation finished.">finished</a>(); <a name="l01053"></a>01053 } <a name="l01054"></a>01054 <span class="keywordflow">else</span> <a name="l01055"></a>01055 { <a name="l01056"></a>01056 <span class="keywordflow">if</span> ( <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> ) <a name="l01057"></a>01057 { <a name="l01058"></a>01058 <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> = <span class="keyword">false</span>; <a name="l01059"></a>01059 scanFile(); <a name="l01060"></a>01060 <span class="keywordflow">return</span>; <a name="l01061"></a>01061 } <a name="l01062"></a>01062 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( m_bIsDirectory ) <a name="l01063"></a>01063 { <a name="l01064"></a>01064 m_bIsDirectory = <span class="keyword">false</span>; <a name="l01065"></a>01065 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( <span class="stringliteral">"inode/directory"</span> ); <a name="l01066"></a>01066 <span class="keywordflow">return</span>; <a name="l01067"></a>01067 } <a name="l01068"></a>01068 } <a name="l01069"></a>01069 <a name="l01070"></a>01070 <span class="keywordflow">if</span> ( m_bAutoDelete ) <a name="l01071"></a>01071 { <a name="l01072"></a>01072 <span class="keyword">delete</span> <span class="keyword">this</span>; <a name="l01073"></a>01073 <span class="keywordflow">return</span>; <a name="l01074"></a>01074 } <a name="l01075"></a>01075 } <a name="l01076"></a>01076 <a name="l01077"></a>01077 <span class="keywordtype">void</span> KRun::slotStatResult( <a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> * job ) <a name="l01078"></a>01078 { <a name="l01079"></a>01079 m_job = 0L; <a name="l01080"></a>01080 <span class="keywordflow">if</span> (job-><a class="code" href="classKIO_1_1Job.html#a45ef3327c7c11ead02d06501018bf441" title="Returns the error code, if there has been an error.">error</a>()) <a name="l01081"></a>01081 { <a name="l01082"></a>01082 d->m_showingError = <span class="keyword">true</span>; <a name="l01083"></a>01083 kdError(7010) << <span class="keyword">this</span> << <span class="stringliteral">" ERROR "</span> << job-><a class="code" href="classKIO_1_1Job.html#a45ef3327c7c11ead02d06501018bf441" title="Returns the error code, if there has been an error.">error</a>() << <span class="stringliteral">" "</span> << job-><a class="code" href="classKIO_1_1Job.html#a3af63c39410f3b35eb91409970c3463b" title="Converts an error code and a non-i18n error message into an error message in the current language...">errorString</a>() << endl; <a name="l01084"></a>01084 job-><a class="code" href="classKIO_1_1Job.html#ac780ea69e6e67f44a92cbbd6552c3021" title="Display a dialog box to inform the user of the error given by this job.">showErrorDialog</a>(); <a name="l01085"></a>01085 <span class="comment">//kdDebug(7010) << this << " KRun returning from showErrorDialog, starting timer to delete us" << endl;</span> <a name="l01086"></a>01086 d->m_showingError = <span class="keyword">false</span>; <a name="l01087"></a>01087 <a name="l01088"></a>01088 m_bFault = <span class="keyword">true</span>; <a name="l01089"></a>01089 m_bFinished = <span class="keyword">true</span>; <a name="l01090"></a>01090 <a name="l01091"></a>01091 <span class="comment">// will emit the error and autodelete this</span> <a name="l01092"></a>01092 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01093"></a>01093 <a name="l01094"></a>01094 } <span class="keywordflow">else</span> { <a name="l01095"></a>01095 <a name="l01096"></a>01096 kdDebug(7010) << <span class="stringliteral">"Finished"</span> << endl; <a name="l01097"></a>01097 <span class="keywordflow">if</span>(!dynamic_cast<KIO::StatJob*>(job)) <a name="l01098"></a>01098 kdFatal() << <span class="stringliteral">"job is a "</span> << <span class="keyword">typeid</span>(*job).name() << <span class="stringliteral">" should be a StatJob"</span> << endl; <a name="l01099"></a>01099 <a name="l01100"></a>01100 <a class="codeRef" href="qstring.html">QString</a> knownMimeType; <a name="l01101"></a>01101 <a class="codeRef" href="qvaluelist.html">KIO::UDSEntry</a> entry = ((<a class="code" href="classKIO_1_1StatJob.html" title="A KIO job that retrieves information about a file or directory.">KIO::StatJob</a>*)job)->statResult(); <a name="l01102"></a>01102 <a class="codeRef" href="qvaluelist.html#ConstIterator">KIO::UDSEntry::ConstIterator</a> it = entry.<a class="codeRef" href="qvaluelist.html#begin">begin</a>(); <a name="l01103"></a>01103 <span class="keywordflow">for</span>( ; it != entry.<a class="codeRef" href="qvaluelist.html#end">end</a>(); it++ ) { <a name="l01104"></a>01104 <span class="keywordflow">switch</span>( (*it).m_uds ) { <a name="l01105"></a>01105 <span class="keywordflow">case</span> <a class="code" href="namespaceKIO.html#ab329df4f691911c03bce444a035fd31fa4590810bdb9f536e059b4b56d20eaa80" title="File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...">KIO::UDS_FILE_TYPE</a>: <a name="l01106"></a>01106 <span class="keywordflow">if</span> ( S_ISDIR( (mode_t)((*it).m_long) ) ) <a name="l01107"></a>01107 m_bIsDirectory = <span class="keyword">true</span>; <span class="comment">// it's a dir</span> <a name="l01108"></a>01108 <span class="keywordflow">else</span> <a name="l01109"></a>01109 <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> = <span class="keyword">true</span>; <span class="comment">// it's a file</span> <a name="l01110"></a>01110 <span class="keywordflow">break</span>; <a name="l01111"></a>01111 <span class="keywordflow">case</span> <a class="code" href="namespaceKIO.html#ab329df4f691911c03bce444a035fd31fa395a47a2c972e9f25892b0d36f801f05" title="A mime type; prevents guessing.">KIO::UDS_MIME_TYPE</a>: <span class="comment">// mimetype already known? (e.g. print:/manager)</span> <a name="l01112"></a>01112 knownMimeType = (*it).m_str; <a name="l01113"></a>01113 <span class="keywordflow">break</span>; <a name="l01114"></a>01114 <span class="keywordflow">case</span> <a class="code" href="namespaceKIO.html#ab329df4f691911c03bce444a035fd31fa8c80e3448e660ec63ab98ae043711188" title="A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...">KIO::UDS_LOCAL_PATH</a>: <a name="l01115"></a>01115 d->m_localPath = (*it).m_str; <a name="l01116"></a>01116 <span class="keywordflow">break</span>; <a name="l01117"></a>01117 <span class="keywordflow">default</span>: <a name="l01118"></a>01118 <span class="keywordflow">break</span>; <a name="l01119"></a>01119 } <a name="l01120"></a>01120 } <a name="l01121"></a>01121 <span class="keywordflow">if</span> ( !knownMimeType.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ) <a name="l01122"></a>01122 { <a name="l01123"></a>01123 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( knownMimeType ); <a name="l01124"></a>01124 m_bFinished = <span class="keyword">true</span>; <a name="l01125"></a>01125 } <a name="l01126"></a>01126 <a name="l01127"></a>01127 <span class="comment">// We should have found something</span> <a name="l01128"></a>01128 assert ( <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> || m_bIsDirectory ); <a name="l01129"></a>01129 <a name="l01130"></a>01130 <span class="comment">// Start the timer. Once we get the timer event this</span> <a name="l01131"></a>01131 <span class="comment">// protocol server is back in the pool and we can reuse it.</span> <a name="l01132"></a>01132 <span class="comment">// This gives better performance than starting a new slave</span> <a name="l01133"></a>01133 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01134"></a>01134 } <a name="l01135"></a>01135 } <a name="l01136"></a>01136 <a name="l01137"></a>01137 <span class="keywordtype">void</span> KRun::slotScanMimeType( <a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &mimetype ) <a name="l01138"></a>01138 { <a name="l01139"></a>01139 <span class="keywordflow">if</span> ( mimetype.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ) <a name="l01140"></a>01140 kdWarning(7010) << <span class="stringliteral">"KRun::slotScanFinished : MimetypeJob didn't find a mimetype! Probably a kioslave bug."</span> << endl; <a name="l01141"></a>01141 <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">foundMimeType</a>( mimetype ); <a name="l01142"></a>01142 m_job = 0; <a name="l01143"></a>01143 } <a name="l01144"></a>01144 <a name="l01145"></a>01145 <span class="keywordtype">void</span> KRun::slotScanFinished( <a class="code" href="classKIO_1_1Job.html" title="The base class for all jobs.">KIO::Job</a> *job ) <a name="l01146"></a>01146 { <a name="l01147"></a>01147 m_job = 0; <a name="l01148"></a>01148 <span class="keywordflow">if</span> (job-><a class="code" href="classKIO_1_1Job.html#a45ef3327c7c11ead02d06501018bf441" title="Returns the error code, if there has been an error.">error</a>()) <a name="l01149"></a>01149 { <a name="l01150"></a>01150 d->m_showingError = <span class="keyword">true</span>; <a name="l01151"></a>01151 kdError(7010) << <span class="keyword">this</span> << <span class="stringliteral">" ERROR (stat) : "</span> << job-><a class="code" href="classKIO_1_1Job.html#a45ef3327c7c11ead02d06501018bf441" title="Returns the error code, if there has been an error.">error</a>() << <span class="stringliteral">" "</span> << job-><a class="code" href="classKIO_1_1Job.html#a3af63c39410f3b35eb91409970c3463b" title="Converts an error code and a non-i18n error message into an error message in the current language...">errorString</a>() << endl; <a name="l01152"></a>01152 job-><a class="code" href="classKIO_1_1Job.html#ac780ea69e6e67f44a92cbbd6552c3021" title="Display a dialog box to inform the user of the error given by this job.">showErrorDialog</a>(); <a name="l01153"></a>01153 <span class="comment">//kdDebug(7010) << this << " KRun returning from showErrorDialog, starting timer to delete us" << endl;</span> <a name="l01154"></a>01154 d->m_showingError = <span class="keyword">false</span>; <a name="l01155"></a>01155 <a name="l01156"></a>01156 m_bFault = <span class="keyword">true</span>; <a name="l01157"></a>01157 m_bFinished = <span class="keyword">true</span>; <a name="l01158"></a>01158 <a name="l01159"></a>01159 <span class="comment">// will emit the error and autodelete this</span> <a name="l01160"></a>01160 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01161"></a>01161 } <a name="l01162"></a>01162 } <a name="l01163"></a>01163 <a name="l01164"></a><a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181">01164</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#abdcfdd7a385d6f05a370c74391f23181" title="Called if the mimetype has been detected.">KRun::foundMimeType</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& type ) <a name="l01165"></a>01165 { <a name="l01166"></a>01166 kdDebug(7010) << <span class="stringliteral">"Resulting mime type is "</span> << type << endl; <a name="l01167"></a>01167 <a name="l01168"></a>01168 <span class="comment">/*</span> <a name="l01169"></a>01169 <span class="comment"> // Automatically unzip stuff</span> <a name="l01170"></a>01170 <span class="comment"></span> <a name="l01171"></a>01171 <span class="comment"> // Disabled since the new KIO doesn't have filters yet.</span> <a name="l01172"></a>01172 <span class="comment"></span> <a name="l01173"></a>01173 <span class="comment"> if ( type == "application/x-gzip" ||</span> <a name="l01174"></a>01174 <span class="comment"> type == "application/x-bzip" ||</span> <a name="l01175"></a>01175 <span class="comment"> type == "application/x-bzip2" )</span> <a name="l01176"></a>01176 <span class="comment"> {</span> <a name="l01177"></a>01177 <span class="comment"> KURL::List lst = KURL::split( m_strURL );</span> <a name="l01178"></a>01178 <span class="comment"> if ( lst.isEmpty() )</span> <a name="l01179"></a>01179 <span class="comment"> {</span> <a name="l01180"></a>01180 <span class="comment"> QString tmp = i18n( "Malformed URL" );</span> <a name="l01181"></a>01181 <span class="comment"> tmp += "\n";</span> <a name="l01182"></a>01182 <span class="comment"> tmp += m_strURL.url();</span> <a name="l01183"></a>01183 <span class="comment"> KMessageBoxWrapper::error( 0L, tmp );</span> <a name="l01184"></a>01184 <span class="comment"> return;</span> <a name="l01185"></a>01185 <span class="comment"> }</span> <a name="l01186"></a>01186 <span class="comment"></span> <a name="l01187"></a>01187 <span class="comment"> if ( type == "application/x-gzip" )</span> <a name="l01188"></a>01188 <span class="comment"> lst.prepend( KURL( "gzip:/decompress" ) );</span> <a name="l01189"></a>01189 <span class="comment"> else if ( type == "application/x-bzip" )</span> <a name="l01190"></a>01190 <span class="comment"> lst.prepend( KURL( "bzip:/decompress" ) );</span> <a name="l01191"></a>01191 <span class="comment"> else if ( type == "application/x-bzip2" )</span> <a name="l01192"></a>01192 <span class="comment"> lst.prepend( KURL( "bzip2:/decompress" ) );</span> <a name="l01193"></a>01193 <span class="comment"> else if ( type == "application/x-tar" )</span> <a name="l01194"></a>01194 <span class="comment"> lst.prepend( KURL( "tar:/" ) );</span> <a name="l01195"></a>01195 <span class="comment"></span> <a name="l01196"></a>01196 <span class="comment"> // Move the HTML style reference to the leftmost URL</span> <a name="l01197"></a>01197 <span class="comment"> KURL::List::Iterator it = lst.begin();</span> <a name="l01198"></a>01198 <span class="comment"> ++it;</span> <a name="l01199"></a>01199 <span class="comment"> (*lst.begin()).setRef( (*it).ref() );</span> <a name="l01200"></a>01200 <span class="comment"> (*it).setRef( QString::null );</span> <a name="l01201"></a>01201 <span class="comment"></span> <a name="l01202"></a>01202 <span class="comment"> // Create the new URL</span> <a name="l01203"></a>01203 <span class="comment"> m_strURL = KURL::join( lst );</span> <a name="l01204"></a>01204 <span class="comment"></span> <a name="l01205"></a>01205 <span class="comment"> kdDebug(7010) << "Now trying with " << debugString(m_strURL.url()) << endl;</span> <a name="l01206"></a>01206 <span class="comment"></span> <a name="l01207"></a>01207 <span class="comment"> killJob();</span> <a name="l01208"></a>01208 <span class="comment"></span> <a name="l01209"></a>01209 <span class="comment"> // We don't know if this is a file or a directory. Let's test this first.</span> <a name="l01210"></a>01210 <span class="comment"> // (For instance a tar.gz is a directory contained inside a file)</span> <a name="l01211"></a>01211 <span class="comment"> // It may be a directory or a file, let's stat</span> <a name="l01212"></a>01212 <span class="comment"> KIO::StatJob *job = KIO::stat( m_strURL, m_bProgressInfo );</span> <a name="l01213"></a>01213 <span class="comment"> connect( job, SIGNAL( result( KIO::Job * ) ),</span> <a name="l01214"></a>01214 <span class="comment"> this, SLOT( slotStatResult( KIO::Job * ) ) );</span> <a name="l01215"></a>01215 <span class="comment"> m_job = job;</span> <a name="l01216"></a>01216 <span class="comment"></span> <a name="l01217"></a>01217 <span class="comment"> return;</span> <a name="l01218"></a>01218 <span class="comment"> }</span> <a name="l01219"></a>01219 <span class="comment">*/</span> <a name="l01220"></a>01220 <a class="code" href="classKIO_1_1TransferJob.html" title="The transfer job pumps data into and/or out of a Slave.">KIO::TransferJob</a> *job = ::qt_cast<<a class="code" href="classKIO_1_1TransferJob.html" title="The transfer job pumps data into and/or out of a Slave.">KIO::TransferJob</a> *>( m_job ); <a name="l01221"></a>01221 <span class="keywordflow">if</span> ( job ) <a name="l01222"></a>01222 { <a name="l01223"></a>01223 job-><a class="code" href="classKIO_1_1SimpleJob.html#a2f791400cef8e49587675c1e4ecc0822" title="Abort job.">putOnHold</a>(); <a name="l01224"></a>01224 <a class="code" href="classKIO_1_1Scheduler.html#a6c7c0697f57599c12555a9455031d501" title="Send the slave that was put on hold back to KLauncher.">KIO::Scheduler::publishSlaveOnHold</a>(); <a name="l01225"></a>01225 m_job = 0; <a name="l01226"></a>01226 } <a name="l01227"></a>01227 <a name="l01228"></a>01228 Q_ASSERT( !m_bFinished ); <a name="l01229"></a>01229 <a name="l01230"></a>01230 <span class="comment">// Suport for preferred service setting, see setPreferredService</span> <a name="l01231"></a>01231 <span class="keywordflow">if</span> ( !d->m_preferredService.isEmpty() ) { <a name="l01232"></a>01232 kdDebug(7010) << <span class="stringliteral">"Attempting to open with preferred service: "</span> << d->m_preferredService << endl; <a name="l01233"></a>01233 KService::Ptr serv = <a class="code" href="classKService.html#a6261ba7fcb0954a985fdba31dc6b6cf7" title="Find a service by the name of its desktop file, not depending on its actual location (as long as it's...">KService::serviceByDesktopName</a>( d->m_preferredService ); <a name="l01234"></a>01234 <span class="keywordflow">if</span> ( serv && serv->hasServiceType( type ) ) <a name="l01235"></a>01235 { <a name="l01236"></a>01236 KURL::List lst; <a name="l01237"></a>01237 lst.append( m_strURL ); <a name="l01238"></a>01238 m_bFinished = <a class="code" href="classKRun.html#ad86a1cb147017c650f441f2a8abbb81f" title="Open a list of URLs with a certain service (application).">KRun::run</a>( *serv, lst ); <a name="l01243"></a>01243 } <a name="l01244"></a>01244 } <a name="l01245"></a>01245 <a name="l01246"></a>01246 <span class="comment">// Resolve .desktop files from media:/, remote:/, applications:/ etc.</span> <a name="l01247"></a>01247 <span class="keywordflow">if</span> ( type == <span class="stringliteral">"application/x-desktop"</span> <span class="comment">/* or inheriting? */</span> && !d->m_localPath.isEmpty() ) <a name="l01248"></a>01248 { <a name="l01249"></a>01249 m_strURL = KURL(); <a name="l01250"></a>01250 m_strURL.setPath( d->m_localPath ); <a name="l01251"></a>01251 } <a name="l01252"></a>01252 <a name="l01253"></a>01253 <span class="keywordflow">if</span> (!m_bFinished && <a class="code" href="classKRun.html#ac9b7d470640917274f3091c6e3eb305e" title="Open the given URL.">KRun::runURL</a>( m_strURL, type, <span class="keyword">false</span>, d->m_runExecutables, d->m_suggestedFileName )){ <a name="l01254"></a>01254 m_bFinished = <span class="keyword">true</span>; <a name="l01255"></a>01255 } <a name="l01256"></a>01256 <span class="keywordflow">else</span>{ <a name="l01257"></a>01257 m_bFinished = <span class="keyword">true</span>; <a name="l01258"></a>01258 m_bFault = <span class="keyword">true</span>; <a name="l01259"></a>01259 } <a name="l01260"></a>01260 <a name="l01261"></a>01261 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01262"></a>01262 } <a name="l01263"></a>01263 <a name="l01264"></a>01264 <span class="keywordtype">void</span> KRun::killJob() <a name="l01265"></a>01265 { <a name="l01266"></a>01266 <span class="keywordflow">if</span> ( m_job ) <a name="l01267"></a>01267 { <a name="l01268"></a>01268 kdDebug(7010) << <span class="stringliteral">"KRun::killJob run="</span> << <span class="keyword">this</span> << <span class="stringliteral">" m_job="</span> << m_job << endl; <a name="l01269"></a>01269 m_job-><a class="code" href="classKIO_1_1Job.html#a7584605a23d14cc29358daff4f420de3" title="Abort this job.">kill</a>(); <a name="l01270"></a>01270 m_job = 0L; <a name="l01271"></a>01271 } <a name="l01272"></a>01272 } <a name="l01273"></a>01273 <a name="l01274"></a><a class="code" href="classKRun.html#aae33f4c6a880306e005d06a15c903a88">01274</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#aae33f4c6a880306e005d06a15c903a88" title="Abort this KRun.">KRun::abort</a>() <a name="l01275"></a>01275 { <a name="l01276"></a>01276 kdDebug(7010) << <span class="stringliteral">"KRun::abort "</span> << <span class="keyword">this</span> << <span class="stringliteral">" m_showingError="</span> << d->m_showingError << endl; <a name="l01277"></a>01277 killJob(); <a name="l01278"></a>01278 <span class="comment">// If we're showing an error message box, the rest will be done</span> <a name="l01279"></a>01279 <span class="comment">// after closing the msgbox -> don't autodelete nor emit signals now.</span> <a name="l01280"></a>01280 <span class="keywordflow">if</span> ( d->m_showingError ) <a name="l01281"></a>01281 <span class="keywordflow">return</span>; <a name="l01282"></a>01282 m_bFault = <span class="keyword">true</span>; <a name="l01283"></a>01283 m_bFinished = <span class="keyword">true</span>; <a name="l01284"></a>01284 <a class="code" href="classKRun.html#a259e6cbfe56fd75f66816df50e77ef01" title="USed to indicate that the next action is to initialize.">m_bInit</a> = <span class="keyword">false</span>; <a name="l01285"></a>01285 <a class="code" href="classKRun.html#a13ae5ae5f6020360eea6e2d8ab20b62a" title="Used to indicate that the next action is to scan the file.">m_bScanFile</a> = <span class="keyword">false</span>; <a name="l01286"></a>01286 <a name="l01287"></a>01287 <span class="comment">// will emit the error and autodelete this</span> <a name="l01288"></a>01288 m_timer.<a class="codeRef" href="qtimer.html#start">start</a>( 0, <span class="keyword">true</span> ); <a name="l01289"></a>01289 } <a name="l01290"></a>01290 <a name="l01291"></a><a class="code" href="classKRun.html#a6a9a9f87d73a222e02a54f20e10d707f">01291</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#a6a9a9f87d73a222e02a54f20e10d707f" title="Sets whether the external webbrowser setting should be honoured.">KRun::setEnableExternalBrowser</a>(<span class="keywordtype">bool</span> b) <a name="l01292"></a>01292 { <a name="l01293"></a>01293 <span class="keywordflow">if</span> (b) <a name="l01294"></a>01294 d->m_externalBrowser = KConfigGroup(KGlobal::config(), <span class="stringliteral">"General"</span>).readEntry(<span class="stringliteral">"BrowserApplication"</span>); <a name="l01295"></a>01295 <span class="keywordflow">else</span> <a name="l01296"></a>01296 d->m_externalBrowser = QString::null; <a name="l01297"></a>01297 } <a name="l01298"></a>01298 <a name="l01299"></a><a class="code" href="classKRun.html#a84f99406c29dc580299e25ea779c100c">01299</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#a84f99406c29dc580299e25ea779c100c" title="Set the preferred service for opening this URL, after its mimetype will have been found by KRun...">KRun::setPreferredService</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& desktopEntryName ) <a name="l01300"></a>01300 { <a name="l01301"></a>01301 d->m_preferredService = desktopEntryName; <a name="l01302"></a>01302 } <a name="l01303"></a>01303 <a name="l01304"></a><a class="code" href="classKRun.html#a67257f7b3e7feef8b16d49485fd221f5">01304</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#a67257f7b3e7feef8b16d49485fd221f5" title="Sets whether executables, .desktop files or shell scripts should be run by KRun.">KRun::setRunExecutables</a>(<span class="keywordtype">bool</span> b) <a name="l01305"></a>01305 { <a name="l01306"></a>01306 d->m_runExecutables = b; <a name="l01307"></a>01307 } <a name="l01308"></a>01308 <a name="l01309"></a><a class="code" href="classKRun.html#a768ff89c98ff1315e002dac28f40cc1d">01309</a> <span class="keywordtype">void</span> <a class="code" href="classKRun.html#a768ff89c98ff1315e002dac28f40cc1d" title="Sets the file name to use in the case of downloading the file to a tempfile in order to give to a non...">KRun::setSuggestedFileName</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& fileName ) <a name="l01310"></a>01310 { <a name="l01311"></a>01311 d->m_suggestedFileName = fileName; <a name="l01312"></a>01312 } <a name="l01313"></a>01313 <a name="l01314"></a><a class="code" href="classKRun.html#abe21b7573533035c6613ebca1bf0dd18">01314</a> <span class="keywordtype">bool</span> <a class="code" href="classKRun.html#abe21b7573533035c6613ebca1bf0dd18" title="Returns whether serviceType refers to an executable program instead of a data file.">KRun::isExecutable</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& serviceType ) <a name="l01315"></a>01315 { <a name="l01316"></a>01316 <span class="keywordflow">return</span> ( serviceType == <span class="stringliteral">"application/x-desktop"</span> || <a name="l01317"></a>01317 serviceType == <span class="stringliteral">"application/x-executable"</span> || <a name="l01318"></a>01318 serviceType == <span class="stringliteral">"application/x-msdos-program"</span> || <a name="l01319"></a>01319 serviceType == <span class="stringliteral">"application/x-shellscript"</span> ); <a name="l01320"></a>01320 } <a name="l01321"></a>01321 <a name="l01322"></a>01322 <span class="comment">/****************/</span> <a name="l01323"></a>01323 <a name="l01324"></a>01324 pid_t <a name="l01325"></a>01325 KProcessRunner::run(KProcess * p, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & binName) <a name="l01326"></a>01326 { <a name="l01327"></a>01327 <span class="keywordflow">return</span> (<span class="keyword">new</span> KProcessRunner(p, binName))->pid(); <a name="l01328"></a>01328 } <a name="l01329"></a>01329 <a name="l01330"></a>01330 <span class="preprocessor">#ifdef Q_WS_X11</span> <a name="l01331"></a>01331 <span class="preprocessor"></span>pid_t <a name="l01332"></a>01332 KProcessRunner::run(KProcess * p, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & binName, <span class="keyword">const</span> KStartupInfoId& <span class="keywordtype">id</span> ) <a name="l01333"></a>01333 { <a name="l01334"></a>01334 <span class="keywordflow">return</span> (<span class="keyword">new</span> KProcessRunner(p, binName, <span class="keywordtype">id</span>))->pid(); <a name="l01335"></a>01335 } <a name="l01336"></a>01336 <span class="preprocessor">#endif</span> <a name="l01337"></a>01337 <span class="preprocessor"></span> <a name="l01338"></a>01338 KProcessRunner::KProcessRunner(KProcess * p, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & _binName ) <a name="l01339"></a>01339 : <a class="codeRef" href="qobject.html">QObject</a>(), <a name="l01340"></a>01340 process_(p), <a name="l01341"></a>01341 binName( _binName ) <a name="l01342"></a>01342 { <a name="l01343"></a>01343 <a class="codeRef" href="qobject.html#connect">QObject::connect</a>( <a name="l01344"></a>01344 process_, SIGNAL(processExited(KProcess *)), <a name="l01345"></a>01345 <span class="keyword">this</span>, SLOT(slotProcessExited(KProcess *))); <a name="l01346"></a>01346 <a name="l01347"></a>01347 process_->start(); <a name="l01348"></a>01348 <span class="keywordflow">if</span> ( !process_->pid() ) <a name="l01349"></a>01349 slotProcessExited( process_ ); <a name="l01350"></a>01350 } <a name="l01351"></a>01351 <a name="l01352"></a>01352 <span class="preprocessor">#ifdef Q_WS_X11</span> <a name="l01353"></a>01353 <span class="preprocessor"></span>KProcessRunner::KProcessRunner(KProcess * p, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & _binName, <span class="keyword">const</span> KStartupInfoId& <span class="keywordtype">id</span> ) <a name="l01354"></a>01354 : <a class="codeRef" href="qobject.html">QObject</a>(), <a name="l01355"></a>01355 process_(p), <a name="l01356"></a>01356 binName( _binName ), <a name="l01357"></a>01357 id_( id ) <a name="l01358"></a>01358 { <a name="l01359"></a>01359 <a class="codeRef" href="qobject.html#connect">QObject::connect</a>( <a name="l01360"></a>01360 process_, SIGNAL(processExited(KProcess *)), <a name="l01361"></a>01361 <span class="keyword">this</span>, SLOT(slotProcessExited(KProcess *))); <a name="l01362"></a>01362 <a name="l01363"></a>01363 process_->start(); <a name="l01364"></a>01364 <span class="keywordflow">if</span> ( !process_->pid() ) <a name="l01365"></a>01365 slotProcessExited( process_ ); <a name="l01366"></a>01366 } <a name="l01367"></a>01367 <span class="preprocessor">#endif</span> <a name="l01368"></a>01368 <span class="preprocessor"></span> <a name="l01369"></a>01369 KProcessRunner::~KProcessRunner() <a name="l01370"></a>01370 { <a name="l01371"></a>01371 <span class="keyword">delete</span> process_; <a name="l01372"></a>01372 } <a name="l01373"></a>01373 <a name="l01374"></a>01374 pid_t <a name="l01375"></a>01375 KProcessRunner::pid()<span class="keyword"> const</span> <a name="l01376"></a>01376 <span class="keyword"></span>{ <a name="l01377"></a>01377 <span class="keywordflow">return</span> process_->pid(); <a name="l01378"></a>01378 } <a name="l01379"></a>01379 <a name="l01380"></a>01380 <span class="keywordtype">void</span> <a name="l01381"></a>01381 KProcessRunner::slotProcessExited(KProcess * p) <a name="l01382"></a>01382 { <a name="l01383"></a>01383 <span class="keywordflow">if</span> (p != process_) <a name="l01384"></a>01384 <span class="keywordflow">return</span>; <span class="comment">// Eh ?</span> <a name="l01385"></a>01385 <a name="l01386"></a>01386 kdDebug(7010) << <span class="stringliteral">"slotProcessExited "</span> << binName << endl; <a name="l01387"></a>01387 kdDebug(7010) << <span class="stringliteral">"normalExit "</span> << process_->normalExit() << endl; <a name="l01388"></a>01388 kdDebug(7010) << <span class="stringliteral">"exitStatus "</span> << process_->exitStatus() << endl; <a name="l01389"></a>01389 <span class="keywordtype">bool</span> showErr = process_->normalExit() <a name="l01390"></a>01390 && ( process_->exitStatus() == 127 || process_->exitStatus() == 1 ); <a name="l01391"></a>01391 <span class="keywordflow">if</span> ( !binName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() && ( showErr || process_->pid() == 0 ) ) <a name="l01392"></a>01392 { <a name="l01393"></a>01393 <span class="comment">// Often we get 1 (zsh, csh) or 127 (ksh, bash) because the binary doesn't exist.</span> <a name="l01394"></a>01394 <span class="comment">// We can't just rely on that, but it's a good hint.</span> <a name="l01395"></a>01395 <span class="comment">// Before assuming its really so, we'll try to find the binName</span> <a name="l01396"></a>01396 <span class="comment">// relatively to current directory, and then in the PATH.</span> <a name="l01397"></a>01397 <span class="keywordflow">if</span> ( !<a class="codeRef" href="qfile.html">QFile</a>( binName ).<a class="codeRef" href="qfile.html#exists">exists</a>() && KStandardDirs::findExe( binName ).isEmpty() ) <a name="l01398"></a>01398 { <a name="l01399"></a>01399 kapp-><a class="codeRef" href="qstring.html#ref">ref</a>(); <a name="l01400"></a>01400 KMessageBox::sorry( 0L, i18n(<span class="stringliteral">"Could not find the program '%1'"</span>).arg( binName ) ); <a name="l01401"></a>01401 kapp->deref(); <a name="l01402"></a>01402 } <a name="l01403"></a>01403 } <a name="l01404"></a>01404 <span class="preprocessor">#ifdef Q_WS_X11</span> <a name="l01405"></a>01405 <span class="preprocessor"></span> <span class="keywordflow">if</span>( !id_.none()) <a name="l01406"></a>01406 { <a name="l01407"></a>01407 KStartupInfoData data; <a name="l01408"></a>01408 data.addPid( pid()); <span class="comment">// announce this pid for the startup notification has finished</span> <a name="l01409"></a>01409 data.setHostname(); <a name="l01410"></a>01410 KStartupInfo::sendFinish( id_, data ); <a name="l01411"></a>01411 } <a name="l01412"></a>01412 <span class="preprocessor">#endif</span> <a name="l01413"></a>01413 <span class="preprocessor"></span> deleteLater(); <a name="l01414"></a>01414 } <a name="l01415"></a>01415 <a name="l01416"></a>01416 <span class="keywordtype">void</span> KRun::virtual_hook( <span class="keywordtype">int</span>, <span class="keywordtype">void</span>* ) <a name="l01417"></a>01417 { <span class="comment">/*BASE::virtual_hook( id, data );*/</span> } <a name="l01418"></a>01418 <a name="l01419"></a>01419 <span class="preprocessor">#include "krun.moc"</span> </pre></div></div> </div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>kio/kio</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="modules.html">Modules</a></li><li><a href="namespaces.html">Namespace List</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="namespacemembers.html">Namespace Members</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classKACL.html">kacl</option>, <option value="classKAr.html">kar</option>, <option value="classKArchive.html">karchive</option>, <option value="classKArchiveDirectory.html">karchivedirectory</option>, <option value="classKArchiveEntry.html">karchiveentry</option>, <option value="classKArchiveFile.html">karchivefile</option>, <option value="classKAutoMount.html">kautomount</option>, <option value="classKAutoUnmount.html">kautounmount</option>, <option value="classKDataTool.html">kdatatool</option>, <option value="classKDataToolAction.html">kdatatoolaction</option>, <option value="classKDataToolInfo.html">kdatatoolinfo</option>, <option value="classKDCOPServiceStarter.html">kdcopservicestarter</option>, <option value="classKDEDesktopMimeType.html">kdedesktopmimetype</option>, <option value="classKDirLister.html">kdirlister</option>, <option value="classKDirNotify.html">kdirnotify</option>, <option value="classKDirWatch.html">kdirwatch</option>, <option value="classKEMailSettings.html">kemailsettings</option>, <option value="classKExecMimeType.html">kexecmimetype</option>, <option value="classKFileFilter.html">kfilefilter</option>, <option value="classKFileItem.html">kfileitem</option>, <option value="classKFileMetaInfo.html">kfilemetainfo</option>, <option value="classKFileMetaInfoGroup.html">kfilemetainfogroup</option>, <option value="classKFileMetaInfoItem.html">kfilemetainfoitem</option>, <option value="classKFileMimeTypeInfo.html">kfilemimetypeinfo</option>, <option value="classKFileMimeTypeInfo_1_1GroupInfo.html">kfilemimetypeinfo::groupinfo</option>, <option value="classKFileMimeTypeInfo_1_1ItemInfo.html">kfilemimetypeinfo::iteminfo</option>, <option value="classKFilePlugin.html">kfileplugin</option>, <option value="classKFileShare.html">kfileshare</option>, <option value="classKFilterBase.html">kfilterbase</option>, <option value="classKFilterDev.html">kfilterdev</option>, <option value="classKFolderType.html">kfoldertype</option>, <option value="classKImageIO.html">kimageio</option>, <option value="classKIO_1_1AuthInfo.html">kio::authinfo</option>, <option value="classKIO_1_1ChmodJob.html">kio::chmodjob</option>, <option value="classKIO_1_1Connection.html">kio::connection</option>, <option value="classKIO_1_1CopyJob.html">kio::copyjob</option>, <option value="classKIO_1_1DataProtocol.html">kio::dataprotocol</option>, <option value="classKIO_1_1DataSlave.html">kio::dataslave</option>, <option value="classKIO_1_1DavJob.html">kio::davjob</option>, <option value="classKIO_1_1DeleteJob.html">kio::deletejob</option>, <option value="classKIO_1_1FileCopyJob.html">kio::filecopyjob</option>, <option value="classKIO_1_1ForwardingSlaveBase.html">kio::forwardingslavebase</option>, <option value="classKIO_1_1Job.html">kio::job</option>, <option value="classKIO_1_1ListJob.html">kio::listjob</option>, <option value="classKIO_1_1MetaData.html">kio::metadata</option>, <option value="classKIO_1_1MetaInfoJob.html">kio::metainfojob</option>, <option value="classKIO_1_1MimetypeJob.html">kio::mimetypejob</option>, <option value="classKIO_1_1MkdirJob.html">kio::mkdirjob</option>, <option value="classKIO_1_1MultiGetJob.html">kio::multigetjob</option>, <option value="classKIO_1_1NetAccess.html">kio::netaccess</option>, <option value="classKIO_1_1NetRC.html">kio::netrc</option>, <option value="classKIO_1_1PasswordDialog.html">kio::passworddialog</option>, <option value="classKIO_1_1PreviewJob.html">kio::previewjob</option>, <option value="classKIO_1_1ProgressBase.html">kio::progressbase</option>, <option value="classKIO_1_1RenameDlg.html">kio::renamedlg</option>, <option value="classKIO_1_1Scheduler.html">kio::scheduler</option>, <option value="classKIO_1_1SimpleJob.html">kio::simplejob</option>, <option value="classKIO_1_1Slave.html">kio::slave</option>, <option value="classKIO_1_1SlaveBase.html">kio::slavebase</option>, <option value="classKIO_1_1SlaveConfig.html">kio::slaveconfig</option>, <option value="classKIO_1_1SlaveInterface.html">kio::slaveinterface</option>, <option value="classKIO_1_1StatJob.html">kio::statjob</option>, <option value="classKIO_1_1StatusbarProgress.html">kio::statusbarprogress</option>, <option value="classKIO_1_1StoredTransferJob.html">kio::storedtransferjob</option>, <option value="classKIO_1_1TCPSlaveBase.html">kio::tcpslavebase</option>, <option value="classKIO_1_1TransferJob.html">kio::transferjob</option>, <option value="classKLimitedIODevice.html">klimitediodevice</option>, <option value="classKMimeMagic.html">kmimemagic</option>, <option value="classKMimeMagicResult.html">kmimemagicresult</option>, <option value="classKMimeType.html">kmimetype</option>, <option value="classKMimeTypeChooser.html">kmimetypechooser</option>, <option value="classKMimeTypeChooserDialog.html">kmimetypechooserdialog</option>, <option value="classKMimeTypeResolver.html">kmimetyperesolver</option>, <option value="classKNFSShare.html">knfsshare</option>, <option value="classKOCRDialog.html">kocrdialog</option>, <option value="classKOCRDialogFactory.html">kocrdialogfactory</option>, <option value="classKOpenWithHandler.html">kopenwithhandler</option>, <option value="classKProtocolInfo.html">kprotocolinfo</option>, <option value="classKProtocolManager.html">kprotocolmanager</option>, <option value="classKRemoteEncoding.html">kremoteencoding</option>, <option value="classKRun.html">krun</option>, <option value="classKSambaShare.html">ksambashare</option>, <option value="classKScanDialog.html">kscandialog</option>, <option value="classKScanDialogFactory.html">kscandialogfactory</option>, <option value="classKService.html">kservice</option>, <option value="classKServiceGroup.html">kservicegroup</option>, <option value="classKServiceOffer.html">kserviceoffer</option>, <option value="classKServiceType.html">kservicetype</option>, <option value="classKServiceTypeProfile.html">kservicetypeprofile</option>, <option value="classKShellCompletion.html">kshellcompletion</option>, <option value="classKShred.html">kshred</option>, <option value="classKSimpleFileFilter.html">ksimplefilefilter</option>, <option value="classKTar.html">ktar</option>, <option value="classKTrader.html">ktrader</option>, <option value="classKURIFilter.html">kurifilter</option>, <option value="classKURIFilterData.html">kurifilterdata</option>, <option value="classKURIFilterPlugin.html">kurifilterplugin</option>, <option value="classKURIFilterPluginList.html">kurifilterpluginlist</option>, <option value="classKURLCompletion.html">kurlcompletion</option>, <option value="classKURLPixmapProvider.html">kurlpixmapprovider</option>, <option value="classKZip.html">kzip</option>, <option value="classObserver.html">observer</option>, <option value="classRenameDlgPlugin.html">renamedlgplugin</option>, <option value="classThumbCreator.html">thumbcreator</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../../arts/html/index.html">arts</a></li><li><a href="../../../dcop/html/index.html">dcop</a></li><li><a href="../../../dnssd/html/index.html">dnssd</a></li><li><a href="../../../interfaces/html/index.html">interfaces</a></li><li> <a href="../../../interfaces/kimproxy/interface/html/index.html">interface</a></li><li> <a href="../../../interfaces/kimproxy/library/html/index.html">library</a></li><li> <a href="../../../interfaces/kspeech/html/index.html">kspeech</a></li><li> <a href="../../../interfaces/ktexteditor/html/index.html">ktexteditor</a></li><li><a href="../../../kabc/html/index.html">kabc</a></li><li><a href="../../../kate/html/index.html">kate</a></li><li><a href="../../../kcmshell/html/index.html">kcmshell</a></li><li><a href="../../../kdecore/html/index.html">kdecore</a></li><li><a href="../../../kded/html/index.html">kded</a></li><li><a href="../../../kdefx/html/index.html">kdefx</a></li><li><a href="../../../kdeprint/html/index.html">kdeprint</a></li><li><a href="../../../kdesu/html/index.html">kdesu</a></li><li><a href="../../../kdeui/html/index.html">kdeui</a></li><li><a href="../../../kdoctools/html/index.html">kdoctools</a></li><li><a href="../../../khtml/html/index.html">khtml</a></li><li><a href="../../../kimgio/html/index.html">kimgio</a></li><li><a href="../../../kinit/html/index.html">kinit</a></li><li><a href="../../../kio/html/index.html">kio</a></li><li> <a href="../../../kio/bookmarks/html/index.html">bookmarks</a></li><li> <a href="../../../kio/httpfilter/html/index.html">httpfilter</a></li><li> <a href="../../../kio/kfile/html/index.html">kfile</a></li><li> <a href="../../../kio/kio/html/index.html">kio</a></li><li> <a href="../../../kio/kioexec/html/index.html">kioexec</a></li><li> <a href="../../../kio/kpasswdserver/html/index.html">kpasswdserver</a></li><li> <a href="../../../kio/kssl/html/index.html">kssl</a></li><li><a href="../../../kioslave/html/index.html">kioslave</a></li><li> <a href="../../../kioslave/http/html/index.html">http</a></li><li><a href="../../../kjs/html/index.html">kjs</a></li><li><a href="../../../kmdi/html/index.html">kmdi</a></li><li> <a href="../../../kmdi/kmdi/html/index.html">kmdi</a></li><li><a href="../../../knewstuff/html/index.html">knewstuff</a></li><li><a href="../../../kparts/html/index.html">kparts</a></li><li><a href="../../../kresources/html/index.html">kresources</a></li><li><a href="../../../kspell2/html/index.html">kspell2</a></li><li><a href="../../../kunittest/html/index.html">kunittest</a></li><li><a href="../../../kutils/html/index.html">kutils</a></li><li><a href="../../../kwallet/html/index.html">kwallet</a></li><li><a href="../../../libkmid/html/index.html">libkmid</a></li><li><a href="../../../libkscreensaver/html/index.html">libkscreensaver</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>