.TH "KRun" 3 "28 Jan 2004" "kio Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KRun \- To open files with their associated applications in \fBKDE\fP, use KRun. Opens files with their associated applications in \fBKDE\fP.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <krun.h>\fP
.PP
Inherits \fBQObject\fP.
.PP
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBfinished\fP ()"
.br
.ti -1c
.RI "void \fBerror\fP ()"
.br
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKRun\fP (const  \fBKURL\fP &url, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true)"
.br
.RI "\fICreate a KRun object to run the preferred application for a file/URL. \fP"
.ti -1c
.RI "virtual \fB~KRun\fP ()"
.br
.RI "\fIDestructor. \fP"
.ti -1c
.RI "void \fBabort\fP ()"
.br
.RI "\fIAbort this KRun. \fP"
.ti -1c
.RI "bool \fBhasError\fP () const "
.br
.ti -1c
.RI "bool \fBhasFinished\fP () const "
.br
.ti -1c
.RI "bool \fBautoDelete\fP () const "
.br
.RI "\fIBy default auto deletion is on. \fP"
.ti -1c
.RI "void \fBsetAutoDelete\fP (bool b)"
.br
.ti -1c
.RI "void \fBsetPreferredService\fP (const  \fBQString\fP &desktopEntryName)"
.br
.RI "\fISet the preferred service for opening this URL, after its mimetype will have been found by KRun. \fP"
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "pid_t \fBrun\fP (const  \fBKService\fP &_service, const  \fBKURL::List\fP &_urls, bool tempFiles)"
.br
.RI "\fIOpen a list of URLs with a certain service (application). \fP"
.ti -1c
.RI "pid_t \fBrun\fP (const  \fBKService\fP &_service, const  \fBKURL::List\fP &_urls)"
.br
.ti -1c
.RI "pid_t \fBrun\fP (const  \fBQString\fP &_exec, const  \fBKURL::List\fP &_urls, const  \fBQString\fP &_name=QString::null, const  \fBQString\fP &_icon=QString::null, const  \fBQString\fP &_obsolete1=QString::null, const  \fBQString\fP &_obsolete2=QString::null)"
.br
.RI "\fIOpen a list of URLs with. \fP"
.ti -1c
.RI "pid_t \fBrunURL\fP (const  \fBKURL\fP &_url, const  \fBQString\fP &_mimetype, bool tempFile)"
.br
.RI "\fIOpen the given URL. \fP"
.ti -1c
.RI "pid_t \fBrunURL\fP (const  \fBKURL\fP &_url, const  \fBQString\fP &_mimetype)"
.br
.ti -1c
.RI "pid_t \fBrunCommand\fP (\fBQString\fP cmd)"
.br
.RI "\fIRun the given shell command and notifies kicker of the starting of the application. \fP"
.ti -1c
.RI "pid_t \fBrunCommand\fP (const  \fBQString\fP &cmd, const  \fBQString\fP &execName, const  \fBQString\fP &icon)"
.br
.RI "\fISame as the other runCommand, but it also takes the name of the binary, to display an error message in case it couldn't find it. \fP"
.ti -1c
.RI "bool \fBdisplayOpenWithDialog\fP (const  \fBKURL::List\fP &lst, bool tempFiles)"
.br
.RI "\fIDisplay the Open-With dialog for those URLs, and run the chosen application. \fP"
.ti -1c
.RI "bool \fBdisplayOpenWithDialog\fP (const  \fBKURL::List\fP &lst)"
.br
.ti -1c
.RI "void \fBshellQuote\fP (\fBQString\fP &_str)"
.br
.RI "\fIQuotes a string for the shell. \fP"
.ti -1c
.RI "\fBQStringList\fP \fBprocessDesktopExec\fP (const  \fBKService\fP &_service, const  \fBKURL::List\fP &_urls, bool has_shell, bool tempFiles)"
.br
.RI "\fIProcesses a Exec= line as found in .desktop files. \fP"
.ti -1c
.RI "\fBQStringList\fP \fBprocessDesktopExec\fP (const  \fBKService\fP &_service, const  \fBKURL::List\fP &_urls, bool has_shell)"
.br
.ti -1c
.RI "\fBQString\fP \fBbinaryName\fP (const  \fBQString\fP &execLine, bool removePath)"
.br
.RI "\fIGiven a full command line (e.g. \fP"
.in -1c
.SS "Protected Slots"

.in +1c
.ti -1c
.RI "void \fBslotTimeout\fP ()"
.br
.ti -1c
.RI "void \fBslotScanFinished\fP (\fBKIO::Job\fP *)"
.br
.ti -1c
.RI "void \fBslotScanMimeType\fP (\fBKIO::Job\fP *, const  \fBQString\fP &type)"
.br
.ti -1c
.RI "virtual void \fBslotStatResult\fP (\fBKIO::Job\fP *)"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "virtual void \fBinit\fP ()"
.br
.ti -1c
.RI "virtual void \fBscanFile\fP ()"
.br
.ti -1c
.RI "virtual void \fBfoundMimeType\fP (const  \fBQString\fP &_type)"
.br
.RI "\fICalled if the mimetype has been detected. \fP"
.ti -1c
.RI "virtual void \fBkillJob\fP ()"
.br
.ti -1c
.RI "virtual void \fBvirtual_hook\fP (int id, void *data)"
.br
.in -1c
.SS "Protected Attributes"

.in +1c
.ti -1c
.RI "\fBKURL\fP \fBm_strURL\fP"
.br
.ti -1c
.RI "bool \fBm_bFault\fP"
.br
.ti -1c
.RI "bool \fBm_bAutoDelete\fP"
.br
.ti -1c
.RI "bool \fBm_bProgressInfo\fP"
.br
.ti -1c
.RI "bool \fBm_bFinished\fP"
.br
.ti -1c
.RI "\fBKIO::Job\fP * \fBm_job\fP"
.br
.ti -1c
.RI "\fBQTimer\fP \fBm_timer\fP"
.br
.ti -1c
.RI "bool \fBm_bScanFile\fP"
.br
.RI "\fIUsed to indicate that the next action is to scan the file. \fP"
.ti -1c
.RI "bool \fBm_bIsDirectory\fP"
.br
.ti -1c
.RI "bool \fBm_bInit\fP"
.br
.RI "\fIUSed to indicate that the next action is to initialize. \fP"
.ti -1c
.RI "bool \fBm_bIsLocalFile\fP"
.br
.ti -1c
.RI "mode_t \fBm_mode\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
To open files with their associated applications in \fBKDE\fP, use KRun. Opens files with their associated applications in \fBKDE\fP. 

It can execute any desktop entry, as well as any file, using the default application or another application 'bound' to the file type.
.PP
In that example, the mimetype of the file is not known by the application, so a KRun instance must be created. It will determine the mimetype by itself. If the mimetype is known, or if you even know the service (application) to use for this file, use one of the static methods.
.PP
Definition at line 52 of file krun.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KRun::KRun (const \fBKURL\fP & url, mode_t mode = 0, bool isLocalFile = false, bool showProgressInfo = true)"
.PP
Create a KRun object to run the preferred application for a file/URL. KRun will first determine the type of the file, and will then run the associated application.
.PP
\fBParameters:\fP
.RS 4
\fIurl\fP the URL of the file or directory to 'run'
.br
\fImode\fP The \fCst_mode\fP field of \fCstruct stat\fP. If you don't know this set it to 0.
.br
\fIisLocalFile\fP If this parameter is set to \fCfalse\fP then \fCurl\fP is examined to find out whether it is a local URL or not. This flag is just used to improve speed, since the function \fBKURL::isLocalFile\fP is a bit slow.
.br
\fIshowProgressInfo\fP Whether to show progress information when determining the type of the file (i.e. when using \fBKIO::stat\fP and \fBKIO::mimetype\fP) Before you set this to false to avoid a dialog box, think about a very slow FTP server... It is always better to provide progress info in such cases. 
.RE
.PP
Definition at line 737 of file krun.cpp.
.PP
References QObject::connect(), m_bInit, m_bScanFile, and QTimer::start().
.SS "KRun::~\fBKRun\fP ()\fC [virtual]\fP"
.PP
Destructor. Don't call it yourself, since a KRun object auto-deletes itself. Definition at line 857 of file krun.cpp.
.PP
References QTimer::stop().
.SH "Member Function Documentation"
.PP 
.SS "void KRun::abort ()"
.PP
Abort this KRun. This kills any jobs launched by it, and leads to deletion if auto-deletion is on. This is much safer than deleting the KRun (in case it's currently showing an error dialog box, for instance) Definition at line 1119 of file krun.cpp.
.PP
References QTimer::start().
.SS "bool KRun::autoDelete () const\fC [inline]\fP"
.PP
By default auto deletion is on. Definition at line 102 of file krun.h.
.SS "void KRun::setPreferredService (const \fBQString\fP & desktopEntryName)"
.PP
Set the preferred service for opening this URL, after its mimetype will have been found by KRun. IMPORTANT: the service is only used if its configuration says it can handle this mimetype. This is used for instance for the X-KDE-LastOpenedWith key, for the recent documents list. 
.PP
\fBParameters:\fP
.RS 4
\fIdesktopEntryName\fP the desktopEntryName of the service, e.g. 'kate'. 
.RE
.PP
Definition at line 1134 of file krun.cpp.
.SS "pid_t KRun::run (const \fBKService\fP & _service, const \fBKURL::List\fP & _urls, bool tempFiles)\fC [static]\fP"
.PP
Open a list of URLs with a certain service (application). \fBParameters:\fP
.RS 4
\fI_service\fP the service to run 
.br
\fI_urls\fP the list of URLs, can be empty (app launched without argument) 
.br
\fItempFiles\fP if true and _urls are local files, they will be deleted when the application exits. 
.RE
.PP
\fBReturns:\fP
.RS 4
the process id, or 0 on error 
.RE
.PP
Definition at line 664 of file krun.cpp.
.PP
References KRecentDocument::add(), QValueList< KURL >::begin(), QValueList< KURL >::ConstIterator(), KService::desktopEntryName(), KService::desktopEntryPath(), QValueList< KURL >::end(), QValueList< KURL >::first(), KDesktopFile::isAuthorizedDesktopFile(), QValueList< KURL >::isEmpty(), QString::isEmpty(), KMessageBox::sorry(), KApplication::startServiceByDesktopPath(), and KURL::List::toStringList().
.PP
Referenced by displayOpenWithDialog(), KFileOpenWithHandler::displayOpenWithDialog(), KDEDesktopMimeType::executeService(), foundMimeType(), run(), and runURL().
.SS "pid_t KRun::run (const \fBQString\fP & _exec, const \fBKURL::List\fP & _urls, const \fBQString\fP & _name = QString::null, const \fBQString\fP & _icon = QString::null, const \fBQString\fP & _obsolete1 = QString::null, const \fBQString\fP & _obsolete2 = QString::null)\fC [static]\fP"
.PP
Open a list of URLs with. \fBParameters:\fP
.RS 4
\fI_exec\fP The name of the executable, for example '/usr/bin/netscape'. 
.br
\fI_name\fP The logical name of the application, for example 'Netscape 4.06'. 
.br
\fI_icon\fP The icon which should be used by the application. 
.br
\fI_obsolete1\fP Do not use! 
.br
\fI_obsolete2\fP Do not use! 
.RE
.PP
Definition at line 713 of file krun.cpp.
.PP
References run().
.SS "pid_t KRun::runURL (const \fBKURL\fP & _url, const \fBQString\fP & _mimetype, bool tempFile)\fC [static]\fP"
.PP
Open the given URL. This function is used after the mime type is found out. It will search for all services which can handle the mime type and call \fBrun\fP() afterwards. 
.PP
\fBParameters:\fP
.RS 4
\fI_url\fP the URL to open 
.br
\fI_mimetype\fP the mime type of the resource 
.br
\fItempFile\fP if true and _url is a local file, it will be deleted when the launched application exits. 
.RE
.PP
\fBReturns:\fP
.RS 4
the process id, or 0 on error 
.RE
.PP
Definition at line 68 of file krun.cpp.
.PP
References QValueList< KURL >::append(), displayOpenWithDialog(), KMessageBox::error(), KURL::htmlURL(), KURL::isLocalFile(), KURL::path(), KServiceTypeProfile::preferredService(), run(), KDEDesktopMimeType::run(), runCommand(), shellQuote(), and KGlobal::staticQString().
.PP
Referenced by foundMimeType().
.SS "pid_t KRun::runCommand (\fBQString\fP cmd)\fC [static]\fP"
.PP
Run the given shell command and notifies kicker of the starting of the application. If the program to be called doesn't exist, an error box will be displayed.
.PP
\fC_cmd\fP must be a shell command. You must not append '&' to it, since the function will do that for you.
.PP
\fBReturns:\fP
.RS 4
PID of running command, 0 if it could not be started, 0 - (PID of running command) if command was unsafe for map notification.
.RE
.PP
Use only when you know the full command line. Otherwise use the other static methods, or KRun's constructor. Definition at line 721 of file krun.cpp.
.PP
Referenced by runURL().
.SS "pid_t KRun::runCommand (const \fBQString\fP & cmd, const \fBQString\fP & execName, const \fBQString\fP & icon)\fC [static]\fP"
.PP
Same as the other runCommand, but it also takes the name of the binary, to display an error message in case it couldn't find it. \fBParameters:\fP
.RS 4
\fIicon\fP icon for app starting notification 
.RE
.PP
Definition at line 726 of file krun.cpp.
.PP
References binaryName(), KSharedPtr< T >::data(), KService::serviceByDesktopName(), and KProcess::setUseShell().
.SS "bool KRun::displayOpenWithDialog (const \fBKURL::List\fP & lst, bool tempFiles)\fC [static]\fP"
.PP
Display the Open-With dialog for those URLs, and run the chosen application. \fBParameters:\fP
.RS 4
\fIlst\fP the list of applications to run 
.br
\fItempFiles\fP if true and lst are local files, they will be deleted when the application exits. 
.RE
.PP
\fBReturns:\fP
.RS 4
false if the dialog was canceled 
.RE
.PP
Definition at line 123 of file krun.cpp.
.PP
References QDialog::exec(), run(), KOpenWithDlg::service(), and KOpenWithDlg::text().
.PP
Referenced by runURL().
.SS "void KRun::shellQuote (\fBQString\fP & _str)\fC [static]\fP"
.PP
Quotes a string for the shell. Definition at line 138 of file krun.cpp.
.PP
References QString::isEmpty(), and QString::replace().
.PP
Referenced by processDesktopExec(), and runURL().
.SS "\fBQStringList\fP KRun::processDesktopExec (const \fBKService\fP & _service, const \fBKURL::List\fP & _urls, bool has_shell, bool tempFiles)\fC [static]\fP"
.PP
Processes a Exec= line as found in .desktop files. \fBParameters:\fP
.RS 4
\fI_service\fP the service to extract information from. 
.br
\fI_urls\fP The urls the service should open. 
.br
\fIhas_shell\fP If true, the arguments are going to be fed into a shell e.g by using system(). If false, the arguments are going to be fed into a exec() kind call. If the arguments are intended for an exec() kind of call and the Exec line contains shell commands then '/bin/sh -c' is added. 
.br
\fItempFiles\fP if true and _urls are local files, they will be deleted when the application exits. 
.RE
.PP
\fBReturns:\fP
.RS 4
a list of arguments suitable for either system() or exec(). 
.RE
.PP
Definition at line 417 of file krun.cpp.
.PP
References QString::arg(), QValueList< KURL >::begin(), KGlobal::config(), QValueList< KURL >::ConstIterator(), QValueList< KURL >::end(), KService::exec(), QString::find(), QString::isEmpty(), QStringList::join(), KConfigBase::readPathEntry(), shellQuote(), KService::substituteUid(), KService::terminal(), KService::terminalOptions(), and KService::username().
.SS "\fBQString\fP KRun::binaryName (const \fBQString\fP & execLine, bool removePath)\fC [static]\fP"
.PP
Given a full command line (e.g. the Exec= line from a .desktop file), extract the name of the binary being run. 
.PP
\fBParameters:\fP
.RS 4
\fIexecLine\fP the full command line 
.br
\fIremovePath\fP if true, remove a (relative or absolute) path. E.g. /usr/bin/ls becomes ls. 
.RE
.PP
\fBSince:\fP
.RS 4
3.1 
.RE
.PP
Definition at line 535 of file krun.cpp.
.PP
References QString::contains(), QString::findRev(), and QString::mid().
.PP
Referenced by runCommand().
.SS "void KRun::foundMimeType (const \fBQString\fP & _type)\fC [protected, virtual]\fP"
.PP
Called if the mimetype has been detected. The function checks whether the document and appends the gzip protocol to the URL. Otherwise \fBrunURL\fP is called to finish the job. Definition at line 1016 of file krun.cpp.
.PP
References QValueList< KURL >::append(), QObject::inherits(), KIO::Scheduler::publishSlaveOnHold(), KIO::SimpleJob::putOnHold(), run(), runURL(), KService::serviceByDesktopName(), and QTimer::start().
.SH "Member Data Documentation"
.PP 
.SS "bool \fBKRun::m_bScanFile\fP\fC [protected]\fP"
.PP
Used to indicate that the next action is to scan the file. This action is invoked from \fBslotTimeout\fP. Definition at line 264 of file krun.h.
.PP
Referenced by KRun().
.SS "bool \fBKRun::m_bInit\fP\fC [protected]\fP"
.PP
USed to indicate that the next action is to initialize. This action is invoked from \fBslotTimeout\fP Definition at line 271 of file krun.h.
.PP
Referenced by KRun().

.SH "Author"
.PP 
Generated automatically by Doxygen for kio Library from the source code.
