30 #include <tqguardedptr.h>
32 #include "kuserprofile.h"
33 #include "kmimetype.h"
34 #include "kmimemagic.h"
35 #include "tdeio/job.h"
36 #include "tdeio/global.h"
37 #include "tdeio/scheduler.h"
38 #include "tdeio/netaccess.h"
39 #include "tdefile/kopenwith.h"
40 #include "tdefile/tderecentdocument.h"
42 #include <kdatastream.h>
43 #include <kmessageboxwrapper.h>
45 #include <tdeapplication.h>
47 #include <tdelocale.h>
48 #include <kprotocolinfo.h>
49 #include <kstandarddirs.h>
51 #include <dcopclient.h>
53 #include <tqfileinfo.h>
54 #include <tqtextstream.h>
55 #include <tqdatetime.h>
57 #include <kdesktopfile.h>
58 #include <tdestartupinfo.h>
59 #include <kmacroexpander.h>
62 #include <kstringhandler.h>
68 class KRun::KRunPrivate
71 KRunPrivate() { m_showingError =
false; }
74 bool m_runExecutables;
76 TQString m_preferredService;
77 TQString m_externalBrowser;
79 TQString m_suggestedFileName;
80 TQGuardedPtr <TQWidget> m_window;
84 pid_t
KRun::runURL(
const KURL& u,
const TQString& _mimetype )
86 return runURL( u, _mimetype,
false,
true, TQString::null );
89 pid_t
KRun::runURL(
const KURL& u,
const TQString& _mimetype,
bool tempFile )
91 return runURL( u, _mimetype, tempFile,
true, TQString::null );
94 pid_t
KRun::runURL(
const KURL& u,
const TQString& _mimetype,
bool tempFile,
bool runExecutables )
96 return runURL( u, _mimetype, tempFile, runExecutables, TQString::null );
101 if ( !url.isLocalFile() )
103 TQFileInfo file( url.path() );
104 if ( file.isExecutable() )
108 if ( mimeType->is(
"application/x-executable") || mimeType->is(
"application/x-executable-script") )
114 pid_t
KRun::runURL(
const KURL& u,
const TQString& _mimetype,
bool tempFile,
bool runExecutables,
const TQString& suggestedFileName )
116 return runURL( u, _mimetype, NULL,
"", tempFile, runExecutables, suggestedFileName );
120 pid_t
KRun::runURL(
const KURL& u,
const TQString& _mimetype, TQWidget* window,
const TQCString& asn,
121 bool tempFile,
bool runExecutables,
const TQString& suggestedFileName )
125 if ( _mimetype ==
"inode/directory-locked" )
127 KMessageBoxWrapper::error( window,
128 i18n(
"<qt>Unable to enter <b>%1</b>.\nYou do not have access rights to this location.</qt>").arg(u.htmlURL()) );
131 else if ( (_mimetype ==
"application/x-desktop") ||
132 (_mimetype ==
"media/builtin-mydocuments") ||
133 (_mimetype ==
"media/builtin-mycomputer") ||
134 (_mimetype ==
"media/builtin-mynetworkplaces") ||
135 (_mimetype ==
"media/builtin-printers") ||
136 (_mimetype ==
"media/builtin-trash") ||
137 (_mimetype ==
"media/builtin-webbrowser") )
139 if ( u.isLocalFile() && runExecutables )
144 if ( u.isLocalFile() && runExecutables)
146 if (kapp->authorize(
"shell_access"))
148 TQString path = u.path();
150 return (
KRun::runCommand(path, TQString::null, TQString::null, window, asn));
158 else if (_mimetype ==
"application/x-executable" || _mimetype ==
"application/x-pie-executable")
168 if (!kapp->authorize(
"shell_access"))
174 KMessageBox::sorry( window,
175 i18n(
"<qt>The file <b>%1</b> is an executable program. "
176 "For safety it will not be started.</qt>").arg(u.htmlURL()));
181 KMessageBoxWrapper::error( window,
182 i18n(
"<qt>You do not have permission to run <b>%1</b>.</qt>").arg(u.htmlURL()) );
189 static const TQString& app_str = TDEGlobal::staticQString(
"Application");
201 return KRun::run( *offer, lst, window, asn, tempFile, suggestedFileName );
216 if (kapp && !kapp->authorizeTDEAction(
"openwith"))
219 KMessageBox::sorry(0L, i18n(
"You are not authorized to open this file."));
223 KOpenWithDlg l( lst, i18n(
"Open with:"), TQString::null, 0L );
226 KService::Ptr service = l.service();
228 return KRun::run( *service, lst, 0 , tempFiles, suggestedFileName );
230 kdDebug(7010) <<
"No service set, running " << l.text() << endl;
231 return KRun::run( l.text(), lst, suggestedFileName );
242 _str.replace(q,
"'\\''").prepend(q).append(q);
246 class KRunMX1 :
public KMacroExpanderBase {
248 KRunMX1(
const KService &_service ) :
249 KMacroExpanderBase(
'%' ), hasUrls( false ), hasSpec( false ), service( _service ) {}
250 bool hasUrls:1, hasSpec:1;
253 virtual int expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret );
260 KRunMX1::expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret )
262 uint option = str[pos + 1];
265 ret << service.
name().replace(
'%',
"%%" );
268 ret << service.desktopEntryPath().replace(
'%',
"%%" );
271 ret <<
"-icon" << service.icon().replace(
'%',
"%%" );
274 ret <<
"-miniicon" << service.icon().replace(
'%',
"%%" );
295 class KRunMX2 :
public KMacroExpanderBase {
297 KRunMX2(
const KURL::List &_urls ) :
298 KMacroExpanderBase(
'%' ), ignFile( false ), urls( _urls ) {}
302 virtual int expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret );
305 void subst(
int option,
const KURL &url, TQStringList &ret );
307 const KURL::List &urls;
311 KRunMX2::subst(
int option,
const KURL &url, TQStringList &ret )
315 ret << url.pathOrURL();
318 ret << url.directory();
324 ret << url.fileName();
327 if (url.isLocalFile() && TQFile::exists( url.path() ) )
328 ret << KDesktopFile( url.path(),
true ).readEntry(
"Dev" );
335 KRunMX2::expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret )
337 uint option = str[pos + 1];
344 if( urls.isEmpty() ) {
346 kdDebug() <<
"KRun::processDesktopExec: No URLs supplied to single-URL service " << str << endl;
347 }
else if( urls.count() > 1 )
348 kdWarning() <<
"KRun::processDesktopExec: " << urls.count() <<
" URLs supplied to single-URL service " << str << endl;
350 subst( option, urls.first(), ret );
357 for( KURL::List::ConstIterator it = urls.begin(); it != urls.end(); ++it )
358 subst( option, *it, ret );
381 TQString exec = _service.
exec();
383 bool appHasTempFileOption;
385 KRunMX1 mx1( _service );
386 KRunMX2 mx2( _urls );
389 TQRegExp re(
"^\\s*(?:/bin/)?sh\\s+-c\\s+(.*)$");
390 if (!re.search( exec )) {
391 exec = TQString(re.cap( 1 )).stripWhiteSpace();
392 for (uint pos = 0; pos < exec.length(); ) {
393 TQChar c = exec.unicode()[pos];
394 if (c !=
'\'' && c !=
'"')
396 int pos2 = exec.find( c, pos + 1 ) - 1;
399 memcpy( (
void *)(exec.unicode() + pos), exec.unicode() + pos + 1, (pos2 - pos) *
sizeof(TQChar));
401 exec.remove( pos, 2 );
405 if( !mx1.expandMacrosShellQuote( exec ) )
411 appHasTempFileOption = tempFiles && _service.
property(
"X-TDE-HasTempFileOption").toBool();
412 if( tempFiles && !appHasTempFileOption && _urls.size() ) {
413 result <<
"tdeioexec" <<
"--tempfiles" << exec;
414 result += _urls.toStringList();
416 result = KShell::joinArgs( result );
422 for( KURL::List::ConstIterator it = _urls.begin(); it != _urls.end(); ++it )
425 result <<
"tdeioexec";
427 result <<
"--tempfiles";
428 if ( !suggestedFileName.isEmpty() ) {
429 result <<
"--suggestedfilename";
430 result << suggestedFileName;
433 result += _urls.toStringList();
435 result = KShell::joinArgs( result );
440 if ( appHasTempFileOption )
441 exec +=
" --tempfile";
451 mx2.expandMacrosShellQuote( exec );
481 TDEConfigGroupSaver gs(TDEGlobal::config(),
"General");
482 TQString terminal = TDEGlobal::config()->readPathEntry(
"TerminalApplication",
"konsole");
483 if (terminal ==
"konsole")
484 terminal +=
" -caption=%c %i %m";
487 if( !mx1.expandMacrosShellQuote( terminal ) ) {
488 kdWarning() <<
"KRun: syntax error in command `" << terminal <<
"', service `" << _service.
name() <<
"'" << endl;
489 return TQStringList();
491 mx2.expandMacrosShellQuote( terminal );
495 result = KShell::splitArgs( terminal );
504 result <<
"tdesu" <<
"-u";
505 result << _service.
username() <<
"-c";
506 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
507 if (err == KShell::FoundMeta) {
509 exec.prepend(
"/bin/sh -c " );
510 }
else if (err != KShell::NoError)
518 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
519 if (err == KShell::FoundMeta) {
521 exec.prepend(
"/bin/sh -c " );
522 }
else if (err != KShell::NoError)
527 result += KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
528 if (err == KShell::FoundMeta)
529 result <<
"/bin/sh" <<
"-c" << exec;
530 else if (err != KShell::NoError)
538 kdWarning() <<
"KRun: syntax error in command `" << _service.
exec() <<
"', service `" << _service.
name() <<
"'" << endl;
539 return TQStringList();
546 TQStringList args = KShell::splitArgs( execLine );
547 for (TQStringList::ConstIterator it = args.begin(); it != args.end(); ++it)
548 if (!(*it).contains(
'='))
550 return removePath ? (*it).mid(TQString(*it).findRev(
'/') + 1) : *it;
554 static pid_t runCommandInternal( TDEProcess* proc,
const KService* service,
const TQString& binName,
555 const TQString &execName,
const TQString & iconName, TQWidget* window, TQCString asn )
560 kdWarning() <<
"No authorization to execute " << service->
desktopEntryPath() << endl;
561 KMessageBox::sorry(window, i18n(
"You are not authorized to execute this file."));
569 bool startup_notify = ( asn !=
"0" && KRun::checkStartupNotify( binName, service, &silent, &wmclass ));
573 id.setupStartupEnv();
574 TDEStartupInfoData data;
577 if( !execName.isEmpty())
578 data.setName( execName );
579 else if( service && !service->
name().isEmpty())
580 data.setName( service->
name());
581 data.setDescription( i18n(
"Launching %1" ).arg( data.name()));
582 if( !iconName.isEmpty())
583 data.setIcon( iconName );
584 else if( service && !service->
icon().isEmpty())
585 data.setIcon( service->
icon());
586 if( !wmclass.isEmpty())
587 data.setWMClass( wmclass );
589 data.setSilent( TDEStartupInfoData::Yes );
590 data.setDesktop( KWin::currentDesktop());
592 data.setLaunchedBy( window->winId());
593 TDEStartupInfo::sendStartup(
id, data );
595 pid_t pid = TDEProcessRunner::run( proc, binName,
id );
596 if( startup_notify && pid )
598 TDEStartupInfoData data;
600 TDEStartupInfo::sendChange(
id, data );
601 TDEStartupInfo::resetStartupEnv();
605 Q_UNUSED( execName );
606 Q_UNUSED( iconName );
607 return TDEProcessRunner::run( proc, bin );
612 bool KRun::checkStartupNotify(
const TQString& ,
const KService* service,
bool* silent_arg, TQCString* wmclass_arg )
616 if( service && service->
property(
"StartupNotify" ).isValid())
618 silent = !service->
property(
"StartupNotify" ).toBool();
619 wmclass = service->
property(
"StartupWMClass" ).toString().latin1();
621 else if( service && service->
property(
"X-TDE-StartupNotify" ).isValid())
623 silent = !service->
property(
"X-TDE-StartupNotify" ).toBool();
624 wmclass = service->
property(
"X-TDE-WMClass" ).toString().latin1();
630 if( service->
type() ==
"Application" )
649 if( silent_arg != NULL )
650 *silent_arg = silent;
651 if( wmclass_arg != NULL )
652 *wmclass_arg = wmclass;
656 static pid_t runTempService(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
657 const TQCString& asn,
bool tempFiles,
const TQString& suggestedFileName )
659 if (!_urls.isEmpty()) {
660 kdDebug(7010) <<
"runTempService: first url " << _urls.first().url() << endl;
671 KURL::List::ConstIterator it = _urls.begin();
672 while(++it != _urls.end())
674 KURL::List singleUrl;
675 singleUrl.append(*it);
676 runTempService( _service, singleUrl, window,
"", tempFiles, suggestedFileName );
678 KURL::List singleUrl;
679 singleUrl.append(_urls.first());
686 kdDebug(7010) <<
"runTempService: TDEProcess args=" << args << endl;
688 TDEProcess * proc =
new TDEProcess;
691 if (!_service.
path().isEmpty())
692 proc->setWorkingDirectory(_service.
path());
695 _service.
name(), _service.
icon(), window, asn );
699 static KURL::List resolveURLs(
const KURL::List& _urls,
const KService& _service )
703 TQStringList supportedProtocols = _service.
property(
"X-TDE-Protocols").toStringList();
704 if (supportedProtocols.isEmpty())
706 supportedProtocols = _service.
property(
"X-KDE-Protocols").toStringList();
708 KRunMX1 mx1( _service );
709 TQString exec = _service.
exec();
710 if ( mx1.expandMacrosShellQuote( exec ) && !mx1.hasUrls ) {
711 Q_ASSERT( supportedProtocols.isEmpty() );
713 if ( supportedProtocols.isEmpty() )
716 TQStringList categories = _service.
property(
"Categories").toStringList();
717 if ((categories.find(
"TDE") != categories.end()) || (categories.find(
"KDE") != categories.end()))
718 supportedProtocols.append(
"TDEIO" );
720 supportedProtocols.append(
"http");
721 supportedProtocols.append(
"ftp");
725 kdDebug(7010) <<
"supportedProtocols:" << supportedProtocols << endl;
727 KURL::List urls( _urls );
728 if ((supportedProtocols.find(
"TDEIO") == supportedProtocols.end()) &&
729 (supportedProtocols.find(
"KIO") == supportedProtocols.end())) {
730 for( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) {
731 const KURL url = *it;
732 bool supported = url.isLocalFile() || supportedProtocols.find( url.protocol().lower() ) != supportedProtocols.end();
733 kdDebug(7010) <<
"Looking at url=" << url <<
" supported=" << supported << endl;
738 if ( localURL != url ) {
740 kdDebug(7010) <<
"Changed to " <<
localURL << endl;
751 return run( _service, _urls, 0,
false, TQString::null );
756 return run( _service, _urls, 0, tempFiles, TQString::null );
759 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles )
761 return run( _service, _urls, window,
"", tempFiles, TQString::null );
764 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
bool tempFiles )
766 return run( _service, _urls, window, asn, tempFiles, TQString::null );
769 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles,
const TQString& suggestedFileName )
771 return run( _service, _urls, window,
"", tempFiles, suggestedFileName );
774 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
775 bool tempFiles,
const TQString& suggestedFileName )
780 kdWarning() <<
"No authorization to execute " << _service.
desktopEntryPath() << endl;
781 KMessageBox::sorry(window, i18n(
"You are not authorized to execute this service."));
788 KURL::List::ConstIterator it = _urls.begin();
789 for(; it != _urls.end(); ++it) {
795 if ( tempFiles || _service.
desktopEntryPath().isEmpty() || !suggestedFileName.isEmpty() )
797 return runTempService(_service, _urls, window, asn, tempFiles, suggestedFileName);
802 if (!_urls.isEmpty()) {
803 kdDebug(7010) <<
"First url " << _urls.first().url() << endl;
807 const KURL::List urls = resolveURLs( _urls, _service );
812 TQCString myasn = asn;
817 myasn = TDEStartupInfo::createNewStartupId();
822 TDEStartupInfoData data;
823 data.setLaunchedBy( window->winId());
824 TDEStartupInfo::sendChange(
id, data );
828 int i = TDEApplication::startServiceByDesktopPath(
834 kdDebug(7010) <<
error << endl;
835 KMessageBox::sorry( window,
error );
839 kdDebug(7010) <<
"startServiceByDesktopPath worked fine" << endl;
844 pid_t
KRun::run(
const TQString& _exec,
const KURL::List& _urls,
const TQString& _name,
845 const TQString& _icon,
const TQString&,
const TQString&)
847 KService::Ptr service =
new KService(_name, _exec, _icon);
849 return run(*service, _urls);
857 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName )
862 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName,
863 TQWidget* window,
const TQCString& asn )
865 kdDebug(7010) <<
"runCommand " << cmd <<
"," << execName << endl;
866 TDEProcess * proc =
new TDEProcess;
867 proc->setUseShell(
true);
871 int pos = bin.findRev(
'/' );
873 proc->setWorkingDirectory( bin.mid(0, pos) );
875 return runCommandInternal( proc, service.data(),
binaryName( execName,
false ), execName, iconName, window, asn );
878 KRun::KRun(
const KURL& url, mode_t mode,
bool isLocalFile,
bool showProgressInfo )
879 :m_timer(0,
"KRun::timer")
881 init (url, 0,
"", mode, isLocalFile, showProgressInfo);
884 KRun::KRun(
const KURL& url, TQWidget* window, mode_t mode,
bool isLocalFile,
885 bool showProgressInfo )
886 :m_timer(0,
"KRun::timer")
888 init (url, window,
"", mode, isLocalFile, showProgressInfo);
891 KRun::KRun(
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
892 bool showProgressInfo )
893 :m_timer(0,
"KRun::timer")
895 init (url, window, asn, mode, isLocalFile, showProgressInfo);
898 void KRun::init (
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
899 bool showProgressInfo )
902 m_bAutoDelete =
true;
903 m_bProgressInfo = showProgressInfo;
908 m_bIsDirectory =
false;
909 m_bIsLocalFile = isLocalFile;
912 d->m_runExecutables =
true;
913 d->m_window = window;
921 connect( &m_timer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( slotTimeout() ) );
922 m_timer.start( 0,
true );
923 kdDebug(7010) <<
" new KRun " <<
this <<
" " << url.prettyURL() <<
" timer=" << &m_timer << endl;
930 kdDebug(7010) <<
"INIT called" << endl;
932 bool bypassErrorMessage =
false;
934 if (m_strURL.url().startsWith(
"$(")) {
936 TQString aValue = m_strURL.url();
937 int nDollarPos = aValue.find(
'$' );
939 while( nDollarPos != -1 && nDollarPos+1 <
static_cast<int>(aValue.length())) {
941 if( (aValue)[nDollarPos+1] !=
'$' ) {
942 uint nEndPos = nDollarPos+1;
945 if (aValue[nEndPos]==
'{')
947 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
'}') )
950 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
954 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
955 || aValue[nEndPos].isLetter() || aValue[nEndPos]==
'_' ) )
957 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
959 const char* pEnv = 0;
960 if (!aVarName.isEmpty())
961 pEnv = getenv( aVarName.ascii() );
966 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
968 aValue.remove( nDollarPos, nEndPos-nDollarPos );
971 aValue.remove( nDollarPos, 1 );
974 nDollarPos = aValue.find(
'$', nDollarPos );
976 m_strURL = KURL(aValue);
977 bypassErrorMessage =
true;
980 if ( !m_strURL.isValid() )
982 if (bypassErrorMessage ==
false) {
983 d->m_showingError =
true;
984 KMessageBoxWrapper::error( d->m_window, i18n(
"Malformed URL\n%1" ).arg( m_strURL.url() ) );
985 d->m_showingError =
false;
989 m_timer.start( 0,
true );
992 if ( !kapp->authorizeURLAction(
"open", KURL(), m_strURL))
995 d->m_showingError =
true;
996 KMessageBoxWrapper::error( d->m_window, msg );
997 d->m_showingError =
false;
1000 m_timer.start( 0,
true );
1004 if ( !m_bIsLocalFile && m_strURL.isLocalFile() )
1005 m_bIsLocalFile =
true;
1008 if (m_strURL.protocol().startsWith(
"http"))
1010 exec = d->m_externalBrowser;
1013 if ( m_bIsLocalFile )
1017 KDE_struct_stat buff;
1018 if ( KDE_stat( TQFile::encodeName(m_strURL.path()), &buff ) == -1 )
1020 d->m_showingError =
true;
1021 KMessageBoxWrapper::error( d->m_window, i18n(
"<qt>Unable to run the command specified. The file or folder <b>%1</b> does not exist.</qt>" ).arg( m_strURL.htmlURL() ) );
1022 d->m_showingError =
false;
1025 m_timer.start( 0,
true );
1028 m_mode = buff.st_mode;
1032 assert( mime != 0L );
1033 kdDebug(7010) <<
"MIME TYPE is " << mime->name() << endl;
1038 kdDebug(7010) <<
"Helper protocol" << endl;
1042 if (!((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")))
1043 urls.append( m_strURL );
1055 else if (exec.startsWith(
"!"))
1067 run( *service, urls, d->m_window, d->m_asn );
1076 m_timer.start( 0,
true );
1081 if ((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")) {
1083 run(
"kfmclient openProfile webbrowsing", urls );
1086 m_timer.start( 0,
true );
1091 if ( S_ISDIR( m_mode ) )
1107 kdDebug(7010) <<
"Testing directory (stating)" << endl;
1112 connect( job, TQ_SIGNAL( result(
TDEIO::Job * ) ),
1113 this, TQ_SLOT( slotStatResult(
TDEIO::Job * ) ) );
1115 kdDebug(7010) <<
" Job " << job <<
" is about stating " << m_strURL.url() << endl;
1120 kdDebug(7010) <<
"KRun::~KRun() " <<
this << endl;
1124 kdDebug(7010) <<
"KRun::~KRun() done " <<
this << endl;
1128 void KRun::scanFile()
1130 kdDebug(7010) <<
"###### KRun::scanFile " << m_strURL.url() << endl;
1133 if ( m_strURL.query().isEmpty() )
1136 assert( mime != 0L );
1137 if ( mime->name() !=
"application/octet-stream" || m_bIsLocalFile )
1139 kdDebug(7010) <<
"Scanfile: MIME TYPE is " << mime->name() << endl;
1151 kdError(7010) <<
"#### NO SUPPORT FOR READING!" << endl;
1154 m_timer.start( 0,
true );
1157 kdDebug(7010) <<
this <<
" Scanning file " << m_strURL.url() << endl;
1161 connect(job, TQ_SIGNAL( result(
TDEIO::Job *)),
1162 this, TQ_SLOT( slotScanFinished(
TDEIO::Job *)));
1164 this, TQ_SLOT( slotScanMimeType(
TDEIO::Job *,
const TQString &)));
1166 kdDebug(7010) <<
" Job " << job <<
" is about getting from " << m_strURL.url() << endl;
1169 void KRun::slotTimeout()
1171 kdDebug(7010) <<
this <<
" slotTimeout called" << endl;
1182 if ( m_bFinished ) {
1193 else if ( m_bIsDirectory )
1195 m_bIsDirectory =
false;
1201 if ( m_bAutoDelete )
1208 void KRun::slotStatResult(
TDEIO::Job * job )
1213 d->m_showingError =
true;
1214 kdError(7010) <<
this <<
" ERROR " << job->
error() <<
" " << job->
errorString() << endl;
1217 d->m_showingError =
false;
1223 m_timer.start( 0,
true );
1227 kdDebug(7010) <<
"Finished" << endl;
1229 kdFatal() <<
"job is a " <<
typeid(*job).name() <<
" should be a StatJob" << endl;
1231 TQString knownMimeType;
1233 TDEIO::UDSEntry::ConstIterator it = entry.begin();
1234 for( ; it != entry.end(); it++ ) {
1235 switch( (*it).m_uds ) {
1237 if ( S_ISDIR( (mode_t)((*it).m_long) ) )
1238 m_bIsDirectory =
true;
1243 knownMimeType = (*it).m_str;
1246 d->m_localPath = (*it).m_str;
1252 if ( !knownMimeType.isEmpty() )
1264 m_timer.start( 0,
true );
1268 void KRun::slotScanMimeType(
TDEIO::Job *,
const TQString &mimetype )
1271 kdWarning(7010) <<
"KRun::slotScanFinished : MimetypeJob didn't find a mimetype! Probably a tdeioslave bug." << endl;
1276 void KRun::slotScanFinished(
TDEIO::Job *job )
1281 d->m_showingError =
true;
1282 kdError(7010) <<
this <<
" ERROR (stat) : " << job->
error() <<
" " << job->
errorString() << endl;
1285 d->m_showingError =
false;
1291 m_timer.start( 0,
true );
1297 kdDebug(7010) <<
"Resulting mime type is " << type << endl;
1359 Q_ASSERT( !m_bFinished );
1362 if ( !d->m_preferredService.isEmpty() ) {
1363 kdDebug(7010) <<
"Attempting to open with preferred service: " << d->m_preferredService << endl;
1365 if ( serv && serv->hasServiceType( type ) )
1368 lst.append( m_strURL );
1369 m_bFinished =
KRun::run( *serv, lst, d->m_window, d->m_asn );
1378 if ( ((type ==
"application/x-desktop") ||
1379 (type ==
"media/builtin-mydocuments") ||
1380 (type ==
"media/builtin-mycomputer") ||
1381 (type ==
"media/builtin-mynetworkplaces") ||
1382 (type ==
"media/builtin-printers") ||
1383 (type ==
"media/builtin-trash") ||
1384 (type ==
"media/builtin-webbrowser")) && (!d->m_localPath.isEmpty()) )
1387 m_strURL.setPath( d->m_localPath );
1390 if (!m_bFinished &&
KRun::runURL( m_strURL, type, d->m_window, d->m_asn,
false, d->m_runExecutables, d->m_suggestedFileName )){
1398 m_timer.start( 0,
true );
1401 void KRun::killJob()
1405 kdDebug(7010) <<
"KRun::killJob run=" <<
this <<
" m_job=" << m_job << endl;
1413 kdDebug(7010) <<
"KRun::abort " <<
this <<
" m_showingError=" << d->m_showingError << endl;
1417 if ( d->m_showingError )
1425 m_timer.start( 0,
true );
1431 d->m_externalBrowser = TDEConfigGroup(TDEGlobal::config(),
"General").readEntry(
"BrowserApplication");
1433 d->m_externalBrowser = TQString::null;
1438 d->m_preferredService = desktopEntryName;
1443 d->m_runExecutables = b;
1448 d->m_suggestedFileName = fileName;
1453 return ( serviceType ==
"application/x-desktop" ||
1454 serviceType ==
"media/builtin-mydocuments" ||
1455 serviceType ==
"media/builtin-mycomputer" ||
1456 serviceType ==
"media/builtin-mynetworkplaces" ||
1457 serviceType ==
"media/builtin-printers" ||
1458 serviceType ==
"media/builtin-trash" ||
1459 serviceType ==
"media/builtin-webbrowser" ||
1460 serviceType ==
"application/x-executable" ||
1461 serviceType ==
"application/x-pie-executable" ||
1462 serviceType ==
"application/x-msdos-program" ||
1463 serviceType ==
"application/x-shellscript" );
1469 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName)
1471 return (
new TDEProcessRunner(p, binName))->pid();
1476 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName,
const TDEStartupInfoId&
id )
1478 return (
new TDEProcessRunner(p, binName,
id))->pid();
1482 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName )
1488 process_, TQ_SIGNAL(processExited(TDEProcess *)),
1489 this, TQ_SLOT(slotProcessExited(TDEProcess *)));
1492 if ( !process_->pid() )
1493 slotProcessExited( process_ );
1497 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName,
const TDEStartupInfoId&
id )
1500 binName( _binName ),
1504 process_, TQ_SIGNAL(processExited(TDEProcess *)),
1505 this, TQ_SLOT(slotProcessExited(TDEProcess *)));
1508 if ( !process_->pid() )
1509 slotProcessExited( process_ );
1513 TDEProcessRunner::~TDEProcessRunner()
1519 TDEProcessRunner::pid()
const
1521 return process_->pid();
1525 TDEProcessRunner::slotProcessExited(TDEProcess * p)
1530 kdDebug(7010) <<
"slotProcessExited " << binName << endl;
1531 kdDebug(7010) <<
"normalExit " << process_->normalExit() << endl;
1532 kdDebug(7010) <<
"exitStatus " << process_->exitStatus() << endl;
1533 bool showErr = process_->normalExit()
1534 && ( process_->exitStatus() == 127 || process_->exitStatus() == 1 );
1535 if ( !binName.isEmpty() && ( showErr || process_->pid() == 0 ) )
1541 if ( !TQFile( binName ).exists() && TDEStandardDirs::findExe( binName ).isEmpty() )
1544 KMessageBox::sorry( 0L, i18n(
"Could not find the program '%1'").arg( binName ) );
1551 TDEStartupInfoData data;
1552 data.addPid( pid());
1554 TDEStartupInfo::sendFinish( id_, data );
1560 void KRun::virtual_hook(
int,
void* )
static pid_t run(const KURL &_url, bool _is_local)
Invokes the default action for the desktop entry.
static Ptr findByURL(const KURL &_url, mode_t _mode=0, bool _is_local_file=false, bool _fast_mode=false)
Finds a KMimeType with the given _url.
static Ptr mimeType(const TQString &_name)
Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...
static TQString defaultMimetype(const KURL &url)
Returns default mimetype for this URL based on the protocol.
static bool supportsReading(const KURL &url)
Returns whether the protocol can retrieve data from URLs.
static bool isHelperProtocol(const KURL &url)
Returns whether the protocol can act as a helper protocol.
static TQString exec(const TQString &protocol)
Returns the library / executable to open for the protocol protocol Example : "tdeio_ftp",...
static TQString protocolClass(const TQString &protocol)
Returns the protocol class for the specified protocol.
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
virtual void foundMimeType(const TQString &_type)
Called if the mimetype has been detected.
void finished()
Emitted when the operation finished.
static pid_t runCommand(TQString cmd)
Run the given shell command and notifies kicker of the starting of the application.
bool m_bScanFile
Used to indicate that the next action is to scan the file.
static bool isExecutable(const TQString &serviceType)
Returns whether serviceType refers to an executable program instead of a data file.
bool m_bInit
USed to indicate that the next action is to initialize.
static TQStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles)
Processes a Exec= line as found in .desktop files.
void setPreferredService(const TQString &desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun.
static bool displayOpenWithDialog(const KURL::List &lst, bool tempFiles)
Display the Open-With dialog for those URLs, and run the chosen application.
void setRunExecutables(bool b)
Sets whether executables, .desktop files or shell scripts should be run by KRun.
void setEnableExternalBrowser(bool b)
Sets whether the external webbrowser setting should be honoured.
static pid_t runURL(const KURL &_url, const TQString &_mimetype, bool tempFile, bool runExecutables)
Open the given URL.
void error()
Emitted when the operation had an error.
void setSuggestedFileName(const TQString &fileName)
Sets the file name to use in the case of downloading the file to a tempfile in order to give to a non...
static bool isExecutableFile(const KURL &url, const TQString &mimetype)
Returns wether the url of mimetype is executable.
void abort()
Abort this KRun.
static void shellQuote(TQString &_str)
Quotes a string for the shell.
static TQString binaryName(const TQString &execLine, bool removePath)
Given a full command line (e.g.
virtual ~KRun()
Destructor.
KRun(const KURL &url, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true)
Create a KRun object to run the preferred application for a file/URL.
static pid_t run(const KService &_service, const KURL::List &_urls, TQWidget *window, bool tempFiles=false)
Open a list of URLs with a certain service (application).
static KService::Ptr preferredService(const TQString &serviceType, const TQString &genericServiceType)
Returns the preferred service for _serviceType and _genericServiceType ("Application",...
Represent a service, i.e.
TQString path() const
Returns the working directory to run the program in.
TQString username() const
Returns the user name, if the service runs with a different user id.
bool allowMultipleFiles() const
Checks whether this service can handle several files as startup arguments.
bool substituteUid() const
Checks whether the service runs with a different user id.
virtual TQVariant property(const TQString &_name) const
Returns the requested property.
bool terminal() const
Checks whethe the service should be run in a terminal.
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.
static Ptr serviceByStorageId(const TQString &_storageId)
Find a service by its storage-id or desktop-file path.
virtual TQString name() const
Returns the name of the service.
TQString icon() const
Returns the name of the icon.
TQString desktopEntryName() const
Returns the filename of the service desktop entry without any extension.
virtual TQString type() const
Returns the type of the service.
static Ptr serviceByDesktopName(const TQString &_name)
Find a service by the name of its desktop file, not depending on its actual location (as long as it's...
TQString exec() const
Returns the executable.
TQString terminalOptions() const
Returns any options associated with the terminal the service runs in, if it requires a terminal.
The base class for all jobs.
void showErrorDialog(TQWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
virtual void kill(bool quietly=true)
Abort this job.
int error() const
Returns the error code, if there has been an error.
void setWindow(TQWidget *window)
TQString errorString() const
static KURL mostLocalURL(const KURL &url, TQWidget *window)
Tries to map a local URL for the given URL.
static void publishSlaveOnHold()
Send the slave that was put on hold back to TDELauncher.
virtual void putOnHold()
Abort job.
A TDEIO job that retrieves information about a file or directory.
The transfer job pumps data into and/or out of a Slave.
TDEIO_EXPORT LocalURLJob * localURL(const KURL &remoteUrl)
Retrieve local URL if available.
TDEIO_EXPORT MimetypeJob * mimetype(const KURL &url, bool showProgressInfo=true)
Find mimetype for one file or directory.
@ UDS_FILE_TYPE
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
@ UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
@ UDS_MIME_TYPE
A mime type; prevents guessing.
TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
TDEIO_EXPORT TQString buildErrorString(int errorCode, const TQString &errorText)
Returns a translated error message for errorCode using the additional error information provided by e...
TDEIO_EXPORT TransferJob * get(const KURL &url, bool reload=false, bool showProgressInfo=true)
Get (a.k.a.
TDEIO_EXPORT StatJob * stat(const KURL &url, bool showProgressInfo=true)
Find all details for one file or directory.