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" )
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()));
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."));
565 #ifdef Q_WS_X11 // Startup notification doesn't work with QT/E, service isn't needed without Startup notification
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" )
643 #else // That unfortunately doesn't work, when the launched non-compliant 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 KRunMX1 mx1( _service );
705 TQString exec = _service.
exec();
706 if ( mx1.expandMacrosShellQuote( exec ) && !mx1.hasUrls ) {
707 Q_ASSERT( supportedProtocols.isEmpty() );
709 if ( supportedProtocols.isEmpty() )
712 TQStringList categories = _service.
property(
"Categories").toStringList();
713 if (( categories.find(
"TDE") != categories.end() ) && ( categories.find(
"KDE") != categories.end() ))
714 supportedProtocols.append(
"TDEIO" );
716 supportedProtocols.append(
"http");
717 supportedProtocols.append(
"ftp");
721 kdDebug(7010) <<
"supportedProtocols:" << supportedProtocols << endl;
723 KURL::List urls( _urls );
724 if ( supportedProtocols.find(
"TDEIO" ) == supportedProtocols.end() ) {
725 for( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) {
726 const KURL url = *it;
727 bool supported = url.isLocalFile() || supportedProtocols.find( url.protocol().lower() ) != supportedProtocols.end();
728 kdDebug(7010) <<
"Looking at url=" << url <<
" supported=" << supported << endl;
730 !url.url().startsWith(
"media:/") && !url.url().startsWith(
"system:/media"))
734 if ( localURL != url ) {
736 kdDebug(7010) <<
"Changed to " << localURL << endl;
747 return run( _service, _urls, 0,
false, TQString::null );
752 return run( _service, _urls, 0, tempFiles, TQString::null );
755 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles )
757 return run( _service, _urls, window,
"", tempFiles, TQString::null );
760 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
bool tempFiles )
762 return run( _service, _urls, window, asn, tempFiles, TQString::null );
765 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles,
const TQString& suggestedFileName )
767 return run( _service, _urls, window,
"", tempFiles, suggestedFileName );
770 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
771 bool tempFiles,
const TQString& suggestedFileName )
776 kdWarning() <<
"No authorization to execute " << _service.
desktopEntryPath() << endl;
777 KMessageBox::sorry(window, i18n(
"You are not authorized to execute this service."));
784 KURL::List::ConstIterator it = _urls.begin();
785 for(; it != _urls.end(); ++it) {
791 if ( tempFiles || _service.
desktopEntryPath().isEmpty() || !suggestedFileName.isEmpty() )
793 return runTempService(_service, _urls, window, asn, tempFiles, suggestedFileName);
798 if (!_urls.isEmpty()) {
799 kdDebug(7010) <<
"First url " << _urls.first().url() << endl;
803 const KURL::List urls = resolveURLs( _urls, _service );
808 TQCString myasn = asn;
813 myasn = TDEStartupInfo::createNewStartupId();
818 TDEStartupInfoData data;
819 data.setLaunchedBy( window->winId());
820 TDEStartupInfo::sendChange(
id, data );
824 int i = TDEApplication::startServiceByDesktopPath(
830 kdDebug(7010) << error << endl;
831 KMessageBox::sorry( window, error );
835 kdDebug(7010) <<
"startServiceByDesktopPath worked fine" << endl;
840 pid_t
KRun::run(
const TQString& _exec,
const KURL::List& _urls,
const TQString& _name,
841 const TQString& _icon,
const TQString&,
const TQString&)
843 KService::Ptr service =
new KService(_name, _exec, _icon);
845 return run(*service, _urls);
853 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName )
858 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName,
859 TQWidget* window,
const TQCString& asn )
861 kdDebug(7010) <<
"runCommand " << cmd <<
"," << execName << endl;
862 TDEProcess * proc =
new TDEProcess;
863 proc->setUseShell(
true);
867 int pos = bin.findRev(
'/' );
869 proc->setWorkingDirectory( bin.mid(0, pos) );
871 return runCommandInternal( proc, service.data(),
binaryName( execName,
false ), execName, iconName, window, asn );
874 KRun::KRun(
const KURL& url, mode_t mode,
bool isLocalFile,
bool showProgressInfo )
875 :m_timer(0,
"KRun::timer")
877 init (url, 0,
"", mode, isLocalFile, showProgressInfo);
880 KRun::KRun(
const KURL& url, TQWidget* window, mode_t mode,
bool isLocalFile,
881 bool showProgressInfo )
882 :m_timer(0,
"KRun::timer")
884 init (url, window,
"", mode, isLocalFile, showProgressInfo);
887 KRun::KRun(
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
888 bool showProgressInfo )
889 :m_timer(0,
"KRun::timer")
891 init (url, window, asn, mode, isLocalFile, showProgressInfo);
894 void KRun::init (
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
895 bool showProgressInfo )
898 m_bAutoDelete =
true;
899 m_bProgressInfo = showProgressInfo;
904 m_bIsDirectory =
false;
905 m_bIsLocalFile = isLocalFile;
908 d->m_runExecutables =
true;
909 d->m_window = window;
917 connect( &m_timer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( slotTimeout() ) );
918 m_timer.start( 0,
true );
919 kdDebug(7010) <<
" new KRun " <<
this <<
" " << url.prettyURL() <<
" timer=" << &m_timer << endl;
926 kdDebug(7010) <<
"INIT called" << endl;
928 bool bypassErrorMessage =
false;
930 if (m_strURL.url().startsWith(
"$(")) {
932 TQString aValue = m_strURL.url();
933 int nDollarPos = aValue.find(
'$' );
935 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
937 if( (aValue)[nDollarPos+1] !=
'$' ) {
938 uint nEndPos = nDollarPos+1;
941 if (aValue[nEndPos]==
'{')
943 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
'}') )
946 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
950 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
951 || aValue[nEndPos].isLetter() || aValue[nEndPos]==
'_' ) )
953 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
955 const char* pEnv = 0;
956 if (!aVarName.isEmpty())
957 pEnv = getenv( aVarName.ascii() );
962 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
964 aValue.remove( nDollarPos, nEndPos-nDollarPos );
967 aValue.remove( nDollarPos, 1 );
970 nDollarPos = aValue.find(
'$', nDollarPos );
972 m_strURL = KURL(aValue);
973 bypassErrorMessage =
true;
976 if ( !m_strURL.isValid() )
978 if (bypassErrorMessage ==
false) {
979 d->m_showingError =
true;
981 d->m_showingError =
false;
985 m_timer.start( 0,
true );
988 if ( !kapp->authorizeURLAction(
"open", KURL(), m_strURL))
991 d->m_showingError =
true;
993 d->m_showingError =
false;
996 m_timer.start( 0,
true );
1000 if ( !m_bIsLocalFile && m_strURL.isLocalFile() )
1001 m_bIsLocalFile =
true;
1004 if (m_strURL.protocol().startsWith(
"http"))
1006 exec = d->m_externalBrowser;
1009 if ( m_bIsLocalFile )
1013 KDE_struct_stat buff;
1014 if ( KDE_stat( TQFile::encodeName(m_strURL.path()), &buff ) == -1 )
1016 d->m_showingError =
true;
1017 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() ) );
1018 d->m_showingError =
false;
1021 m_timer.start( 0,
true );
1024 m_mode = buff.st_mode;
1028 assert( mime != 0L );
1029 kdDebug(7010) <<
"MIME TYPE is " << mime->name() << endl;
1034 kdDebug(7010) <<
"Helper protocol" << endl;
1038 if (!((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")))
1039 urls.append( m_strURL );
1051 else if (exec.startsWith(
"!"))
1063 run( *service, urls, d->m_window, d->m_asn );
1072 m_timer.start( 0,
true );
1077 if ((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")) {
1079 run(
"kfmclient openProfile webbrowsing", urls );
1082 m_timer.start( 0,
true );
1087 if ( S_ISDIR( m_mode ) )
1103 kdDebug(7010) <<
"Testing directory (stating)" << endl;
1108 connect( job, TQT_SIGNAL( result(
TDEIO::Job * ) ),
1109 this, TQT_SLOT( slotStatResult(
TDEIO::Job * ) ) );
1111 kdDebug(7010) <<
" Job " << job <<
" is about stating " << m_strURL.url() << endl;
1116 kdDebug(7010) <<
"KRun::~KRun() " <<
this << endl;
1120 kdDebug(7010) <<
"KRun::~KRun() done " <<
this << endl;
1124 void KRun::scanFile()
1126 kdDebug(7010) <<
"###### KRun::scanFile " << m_strURL.url() << endl;
1129 if ( m_strURL.query().isEmpty() )
1132 assert( mime != 0L );
1133 if ( mime->name() !=
"application/octet-stream" || m_bIsLocalFile )
1135 kdDebug(7010) <<
"Scanfile: MIME TYPE is " << mime->name() << endl;
1147 kdError(7010) <<
"#### NO SUPPORT FOR READING!" << endl;
1150 m_timer.start( 0,
true );
1153 kdDebug(7010) <<
this <<
" Scanning file " << m_strURL.url() << endl;
1157 connect(job, TQT_SIGNAL( result(
TDEIO::Job *)),
1158 this, TQT_SLOT( slotScanFinished(
TDEIO::Job *)));
1160 this, TQT_SLOT( slotScanMimeType(
TDEIO::Job *,
const TQString &)));
1162 kdDebug(7010) <<
" Job " << job <<
" is about getting from " << m_strURL.url() << endl;
1165 void KRun::slotTimeout()
1167 kdDebug(7010) <<
this <<
" slotTimeout called" << endl;
1178 if ( m_bFinished ) {
1189 else if ( m_bIsDirectory )
1191 m_bIsDirectory =
false;
1197 if ( m_bAutoDelete )
1204 void KRun::slotStatResult(
TDEIO::Job * job )
1209 d->m_showingError =
true;
1210 kdError(7010) <<
this <<
" ERROR " << job->
error() <<
" " << job->
errorString() << endl;
1213 d->m_showingError =
false;
1219 m_timer.start( 0,
true );
1223 kdDebug(7010) <<
"Finished" << endl;
1224 if(!dynamic_cast<TDEIO::StatJob*>(job))
1225 kdFatal() <<
"job is a " <<
typeid(*job).name() <<
" should be a StatJob" << endl;
1227 TQString knownMimeType;
1229 TDEIO::UDSEntry::ConstIterator it = entry.begin();
1230 for( ; it != entry.end(); it++ ) {
1231 switch( (*it).m_uds ) {
1233 if ( S_ISDIR( (mode_t)((*it).m_long) ) )
1234 m_bIsDirectory =
true;
1239 knownMimeType = (*it).m_str;
1242 d->m_localPath = (*it).m_str;
1248 if ( !knownMimeType.isEmpty() )
1260 m_timer.start( 0,
true );
1264 void KRun::slotScanMimeType(
TDEIO::Job *,
const TQString &mimetype )
1266 if ( mimetype.isEmpty() )
1267 kdWarning(7010) <<
"KRun::slotScanFinished : MimetypeJob didn't find a mimetype! Probably a tdeioslave bug." << endl;
1272 void KRun::slotScanFinished(
TDEIO::Job *job )
1277 d->m_showingError =
true;
1278 kdError(7010) <<
this <<
" ERROR (stat) : " << job->
error() <<
" " << job->
errorString() << endl;
1281 d->m_showingError =
false;
1287 m_timer.start( 0,
true );
1293 kdDebug(7010) <<
"Resulting mime type is " << type << endl;
1355 Q_ASSERT( !m_bFinished );
1358 if ( !d->m_preferredService.isEmpty() ) {
1359 kdDebug(7010) <<
"Attempting to open with preferred service: " << d->m_preferredService << endl;
1361 if ( serv && serv->hasServiceType( type ) )
1364 lst.append( m_strURL );
1365 m_bFinished =
KRun::run( *serv, lst, d->m_window, d->m_asn );
1374 if ( ((type ==
"application/x-desktop") ||
1375 (type ==
"media/builtin-mydocuments") ||
1376 (type ==
"media/builtin-mycomputer") ||
1377 (type ==
"media/builtin-mynetworkplaces") ||
1378 (type ==
"media/builtin-printers") ||
1379 (type ==
"media/builtin-trash") ||
1380 (type ==
"media/builtin-webbrowser")) && (!d->m_localPath.isEmpty()) )
1383 m_strURL.setPath( d->m_localPath );
1386 if (!m_bFinished &&
KRun::runURL( m_strURL, type, d->m_window, d->m_asn,
false, d->m_runExecutables, d->m_suggestedFileName )){
1394 m_timer.start( 0,
true );
1397 void KRun::killJob()
1401 kdDebug(7010) <<
"KRun::killJob run=" <<
this <<
" m_job=" << m_job << endl;
1409 kdDebug(7010) <<
"KRun::abort " <<
this <<
" m_showingError=" << d->m_showingError << endl;
1413 if ( d->m_showingError )
1421 m_timer.start( 0,
true );
1427 d->m_externalBrowser = TDEConfigGroup(TDEGlobal::config(),
"General").readEntry(
"BrowserApplication");
1429 d->m_externalBrowser = TQString::null;
1434 d->m_preferredService = desktopEntryName;
1439 d->m_runExecutables = b;
1444 d->m_suggestedFileName = fileName;
1449 return ( serviceType ==
"application/x-desktop" ||
1450 serviceType ==
"media/builtin-mydocuments" ||
1451 serviceType ==
"media/builtin-mycomputer" ||
1452 serviceType ==
"media/builtin-mynetworkplaces" ||
1453 serviceType ==
"media/builtin-printers" ||
1454 serviceType ==
"media/builtin-trash" ||
1455 serviceType ==
"media/builtin-webbrowser" ||
1456 serviceType ==
"application/x-executable" ||
1457 serviceType ==
"application/x-pie-executable" ||
1458 serviceType ==
"application/x-msdos-program" ||
1459 serviceType ==
"application/x-shellscript" );
1465 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName)
1467 return (
new TDEProcessRunner(p, binName))->pid();
1472 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName,
const TDEStartupInfoId&
id )
1474 return (
new TDEProcessRunner(p, binName,
id))->pid();
1478 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName )
1484 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1485 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1488 if ( !process_->pid() )
1489 slotProcessExited( process_ );
1493 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName,
const TDEStartupInfoId&
id )
1496 binName( _binName ),
1500 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1501 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1504 if ( !process_->pid() )
1505 slotProcessExited( process_ );
1509 TDEProcessRunner::~TDEProcessRunner()
1515 TDEProcessRunner::pid()
const
1517 return process_->pid();
1521 TDEProcessRunner::slotProcessExited(TDEProcess * p)
1526 kdDebug(7010) <<
"slotProcessExited " << binName << endl;
1527 kdDebug(7010) <<
"normalExit " << process_->normalExit() << endl;
1528 kdDebug(7010) <<
"exitStatus " << process_->exitStatus() << endl;
1529 bool showErr = process_->normalExit()
1530 && ( process_->exitStatus() == 127 || process_->exitStatus() == 1 );
1531 if ( !binName.isEmpty() && ( showErr || process_->pid() == 0 ) )
1537 if ( !TQFile( binName ).exists() && TDEStandardDirs::findExe( binName ).isEmpty() )
1540 KMessageBox::sorry( 0L, i18n(
"Could not find the program '%1'").arg( binName ) );
1547 TDEStartupInfoData data;
1548 data.addPid( pid());
1550 TDEStartupInfo::sendFinish( id_, data );
1556 void KRun::virtual_hook(
int,
void* )