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")
166 if (!kapp->authorize(
"shell_access"))
172 KMessageBox::sorry( window,
173 i18n(
"<qt>The file <b>%1</b> is an executable program. " 174 "For safety it will not be started.</qt>").arg(u.htmlURL()));
179 KMessageBoxWrapper::error( window,
180 i18n(
"<qt>You do not have permission to run <b>%1</b>.</qt>").arg(u.htmlURL()) );
187 static const TQString& app_str = TDEGlobal::staticQString(
"Application");
199 return KRun::run( *offer, lst, window, asn, tempFile, suggestedFileName );
214 if (kapp && !kapp->authorizeTDEAction(
"openwith"))
217 KMessageBox::sorry(0L, i18n(
"You are not authorized to open this file."));
221 KOpenWithDlg l( lst, i18n(
"Open with:"), TQString::null, 0L );
224 KService::Ptr service = l.service();
226 return KRun::run( *service, lst, 0 , tempFiles, suggestedFileName );
228 kdDebug(7010) <<
"No service set, running " << l.text() << endl;
229 return KRun::run( l.text(), lst, suggestedFileName );
240 _str.replace(q,
"'\\''").prepend(q).append(q);
244 class KRunMX1 :
public KMacroExpanderBase {
246 KRunMX1(
const KService &_service ) :
247 KMacroExpanderBase(
'%' ), hasUrls(
false ), hasSpec(
false ), service( _service ) {}
248 bool hasUrls:1, hasSpec:1;
251 virtual int expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret );
258 KRunMX1::expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret )
260 uint option = str[pos + 1];
263 ret << service.
name().replace(
'%',
"%%" );
266 ret << service.desktopEntryPath().replace(
'%',
"%%" );
269 ret <<
"-icon" << service.icon().replace(
'%',
"%%" );
272 ret <<
"-miniicon" << service.icon().replace(
'%',
"%%" );
293 class KRunMX2 :
public KMacroExpanderBase {
295 KRunMX2(
const KURL::List &_urls ) :
296 KMacroExpanderBase(
'%' ), ignFile(
false ), urls( _urls ) {}
300 virtual int expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret );
303 void subst(
int option,
const KURL &url, TQStringList &ret );
305 const KURL::List &urls;
309 KRunMX2::subst(
int option,
const KURL &url, TQStringList &ret )
313 ret << url.pathOrURL();
316 ret << url.directory();
322 ret << url.fileName();
325 if (url.isLocalFile() && TQFile::exists( url.path() ) )
326 ret << KDesktopFile( url.path(), true ).readEntry(
"Dev" );
333 KRunMX2::expandEscapedMacro(
const TQString &str, uint pos, TQStringList &ret )
335 uint option = str[pos + 1];
342 if( urls.isEmpty() ) {
344 kdDebug() <<
"KRun::processDesktopExec: No URLs supplied to single-URL service " << str << endl;
345 }
else if( urls.count() > 1 )
346 kdWarning() <<
"KRun::processDesktopExec: " << urls.count() <<
" URLs supplied to single-URL service " << str << endl;
348 subst( option, urls.first(), ret );
355 for( KURL::List::ConstIterator it = urls.begin(); it != urls.end(); ++it )
356 subst( option, *it, ret );
379 TQString exec = _service.
exec();
381 bool appHasTempFileOption;
383 KRunMX1 mx1( _service );
384 KRunMX2 mx2( _urls );
387 TQRegExp re(
"^\\s*(?:/bin/)?sh\\s+-c\\s+(.*)$");
388 if (!re.search( exec )) {
389 exec = TQString(re.cap( 1 )).stripWhiteSpace();
390 for (uint pos = 0; pos < exec.length(); ) {
391 TQChar c = exec.unicode()[pos];
392 if (c !=
'\'' && c !=
'"')
394 int pos2 = exec.find( c, pos + 1 ) - 1;
397 memcpy( (
void *)(exec.unicode() + pos), exec.unicode() + pos + 1, (pos2 - pos) *
sizeof(TQChar));
399 exec.remove( pos, 2 );
403 if( !mx1.expandMacrosShellQuote( exec ) )
409 appHasTempFileOption = tempFiles && _service.
property(
"X-TDE-HasTempFileOption").toBool();
410 if( tempFiles && !appHasTempFileOption && _urls.size() ) {
411 result <<
"tdeioexec" <<
"--tempfiles" << exec;
412 result += _urls.toStringList();
414 result = KShell::joinArgs( result );
420 for( KURL::List::ConstIterator it = _urls.begin(); it != _urls.end(); ++it )
423 result <<
"tdeioexec";
425 result <<
"--tempfiles";
426 if ( !suggestedFileName.isEmpty() ) {
427 result <<
"--suggestedfilename";
428 result << suggestedFileName;
431 result += _urls.toStringList();
433 result = KShell::joinArgs( result );
438 if ( appHasTempFileOption )
439 exec +=
" --tempfile";
449 mx2.expandMacrosShellQuote( exec );
479 TDEConfigGroupSaver gs(TDEGlobal::config(),
"General");
480 TQString terminal = TDEGlobal::config()->readPathEntry(
"TerminalApplication",
"konsole");
481 if (terminal ==
"konsole")
482 terminal +=
" -caption=%c %i %m";
485 if( !mx1.expandMacrosShellQuote( terminal ) ) {
486 kdWarning() <<
"KRun: syntax error in command `" << terminal <<
"', service `" << _service.
name() <<
"'" << endl;
487 return TQStringList();
489 mx2.expandMacrosShellQuote( terminal );
493 result = KShell::splitArgs( terminal );
502 result <<
"tdesu" <<
"-u";
503 result << _service.
username() <<
"-c";
504 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
505 if (err == KShell::FoundMeta) {
507 exec.prepend(
"/bin/sh -c " );
508 }
else if (err != KShell::NoError)
516 KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
517 if (err == KShell::FoundMeta) {
519 exec.prepend(
"/bin/sh -c " );
520 }
else if (err != KShell::NoError)
525 result += KShell::splitArgs(exec, KShell::AbortOnMeta | KShell::TildeExpand, &err);
526 if (err == KShell::FoundMeta)
527 result <<
"/bin/sh" <<
"-c" << exec;
528 else if (err != KShell::NoError)
536 kdWarning() <<
"KRun: syntax error in command `" << _service.
exec() <<
"', service `" << _service.
name() <<
"'" << endl;
537 return TQStringList();
544 TQStringList args = KShell::splitArgs( execLine );
545 for (TQStringList::ConstIterator it = args.begin(); it != args.end(); ++it)
546 if (!(*it).contains(
'='))
548 return removePath ? (*it).mid(TQString(*it).findRev(
'/') + 1) : *it;
552 static pid_t runCommandInternal( TDEProcess* proc,
const KService* service,
const TQString& binName,
553 const TQString &execName,
const TQString & iconName, TQWidget* window, TQCString asn )
558 kdWarning() <<
"No authorization to execute " << service->
desktopEntryPath() << endl;
559 KMessageBox::sorry(window, i18n(
"You are not authorized to execute this file."));
563 #ifdef Q_WS_X11 // Startup notification doesn't work with QT/E, service isn't needed without Startup notification 567 bool startup_notify = ( asn !=
"0" && KRun::checkStartupNotify( binName, service, &silent, &wmclass ));
571 id.setupStartupEnv();
572 TDEStartupInfoData data;
575 if( !execName.isEmpty())
576 data.setName( execName );
577 else if( service && !service->
name().isEmpty())
578 data.setName( service->
name());
579 data.setDescription( i18n(
"Launching %1" ).arg( data.name()));
580 if( !iconName.isEmpty())
581 data.setIcon( iconName );
582 else if( service && !service->
icon().isEmpty())
583 data.setIcon( service->
icon());
584 if( !wmclass.isEmpty())
585 data.setWMClass( wmclass );
587 data.setSilent( TDEStartupInfoData::Yes );
588 data.setDesktop( KWin::currentDesktop());
590 data.setLaunchedBy( window->winId());
591 TDEStartupInfo::sendStartup(
id, data );
593 pid_t pid = TDEProcessRunner::run( proc, binName,
id );
594 if( startup_notify && pid )
596 TDEStartupInfoData data;
598 TDEStartupInfo::sendChange(
id, data );
599 TDEStartupInfo::resetStartupEnv();
603 Q_UNUSED( execName );
604 Q_UNUSED( iconName );
605 return TDEProcessRunner::run( proc, bin );
610 bool KRun::checkStartupNotify(
const TQString& ,
const KService* service,
bool* silent_arg, TQCString* wmclass_arg )
614 if( service && service->
property(
"StartupNotify" ).isValid())
616 silent = !service->
property(
"StartupNotify" ).toBool();
617 wmclass = service->
property(
"StartupWMClass" ).toString().latin1();
619 else if( service && service->
property(
"X-TDE-StartupNotify" ).isValid())
621 silent = !service->
property(
"X-TDE-StartupNotify" ).toBool();
622 wmclass = service->
property(
"X-TDE-WMClass" ).toString().latin1();
628 if( service->
type() ==
"Application" )
641 #else // That unfortunately doesn't work, when the launched non-compliant application 647 if( silent_arg != NULL )
648 *silent_arg = silent;
649 if( wmclass_arg != NULL )
650 *wmclass_arg = wmclass;
654 static pid_t runTempService(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
655 const TQCString& asn,
bool tempFiles,
const TQString& suggestedFileName )
657 if (!_urls.isEmpty()) {
658 kdDebug(7010) <<
"runTempService: first url " << _urls.first().url() << endl;
669 KURL::List::ConstIterator it = _urls.begin();
670 while(++it != _urls.end())
672 KURL::List singleUrl;
673 singleUrl.append(*it);
674 runTempService( _service, singleUrl, window,
"", tempFiles, suggestedFileName );
676 KURL::List singleUrl;
677 singleUrl.append(_urls.first());
684 kdDebug(7010) <<
"runTempService: TDEProcess args=" << args << endl;
686 TDEProcess * proc =
new TDEProcess;
689 if (!_service.
path().isEmpty())
690 proc->setWorkingDirectory(_service.
path());
693 _service.
name(), _service.
icon(), window, asn );
697 static KURL::List resolveURLs(
const KURL::List& _urls,
const KService& _service )
701 TQStringList supportedProtocols = _service.
property(
"X-TDE-Protocols").toStringList();
702 KRunMX1 mx1( _service );
703 TQString exec = _service.
exec();
704 if ( mx1.expandMacrosShellQuote( exec ) && !mx1.hasUrls ) {
705 Q_ASSERT( supportedProtocols.isEmpty() );
707 if ( supportedProtocols.isEmpty() )
710 TQStringList categories = _service.
property(
"Categories").toStringList();
711 if (( categories.find(
"TDE") != categories.end() ) && ( categories.find(
"KDE") != categories.end() ))
712 supportedProtocols.append(
"TDEIO" );
714 supportedProtocols.append(
"http");
715 supportedProtocols.append(
"ftp");
719 kdDebug(7010) <<
"supportedProtocols:" << supportedProtocols << endl;
721 KURL::List urls( _urls );
722 if ( supportedProtocols.find(
"TDEIO" ) == supportedProtocols.end() ) {
723 for( KURL::List::Iterator it = urls.begin(); it != urls.end(); ++it ) {
724 const KURL url = *it;
725 bool supported = url.isLocalFile() || supportedProtocols.find( url.protocol().lower() ) != supportedProtocols.end();
726 kdDebug(7010) <<
"Looking at url=" << url <<
" supported=" << supported << endl;
731 if ( localURL != url ) {
733 kdDebug(7010) <<
"Changed to " << localURL << endl;
744 return run( _service, _urls, 0,
false, TQString::null );
749 return run( _service, _urls, 0, tempFiles, TQString::null );
752 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles )
754 return run( _service, _urls, window,
"", tempFiles, TQString::null );
757 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
bool tempFiles )
759 return run( _service, _urls, window, asn, tempFiles, TQString::null );
762 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
bool tempFiles,
const TQString& suggestedFileName )
764 return run( _service, _urls, window,
"", tempFiles, suggestedFileName );
767 pid_t
KRun::run(
const KService& _service,
const KURL::List& _urls, TQWidget* window,
const TQCString& asn,
768 bool tempFiles,
const TQString& suggestedFileName )
773 kdWarning() <<
"No authorization to execute " << _service.
desktopEntryPath() << endl;
774 KMessageBox::sorry(window, i18n(
"You are not authorized to execute this service."));
781 KURL::List::ConstIterator it = _urls.begin();
782 for(; it != _urls.end(); ++it) {
788 if ( tempFiles || _service.
desktopEntryPath().isEmpty() || !suggestedFileName.isEmpty() )
790 return runTempService(_service, _urls, window, asn, tempFiles, suggestedFileName);
795 if (!_urls.isEmpty()) {
796 kdDebug(7010) <<
"First url " << _urls.first().url() << endl;
800 const KURL::List urls = resolveURLs( _urls, _service );
805 TQCString myasn = asn;
810 myasn = TDEStartupInfo::createNewStartupId();
815 TDEStartupInfoData data;
816 data.setLaunchedBy( window->winId());
817 TDEStartupInfo::sendChange(
id, data );
821 int i = TDEApplication::startServiceByDesktopPath(
827 kdDebug(7010) << error << endl;
828 KMessageBox::sorry( window, error );
832 kdDebug(7010) <<
"startServiceByDesktopPath worked fine" << endl;
837 pid_t
KRun::run(
const TQString& _exec,
const KURL::List& _urls,
const TQString& _name,
838 const TQString& _icon,
const TQString&,
const TQString&)
840 KService::Ptr service =
new KService(_name, _exec, _icon);
842 return run(*service, _urls);
850 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName )
855 pid_t
KRun::runCommand(
const TQString& cmd,
const TQString &execName,
const TQString & iconName,
856 TQWidget* window,
const TQCString& asn )
858 kdDebug(7010) <<
"runCommand " << cmd <<
"," << execName << endl;
859 TDEProcess * proc =
new TDEProcess;
860 proc->setUseShell(
true);
864 int pos = bin.findRev(
'/' );
866 proc->setWorkingDirectory( bin.mid(0, pos) );
868 return runCommandInternal( proc, service.data(),
binaryName( execName,
false ), execName, iconName, window, asn );
871 KRun::KRun(
const KURL& url, mode_t mode,
bool isLocalFile,
bool showProgressInfo )
872 :m_timer(0,
"KRun::timer")
874 init (url, 0,
"", mode, isLocalFile, showProgressInfo);
877 KRun::KRun(
const KURL& url, TQWidget* window, mode_t mode,
bool isLocalFile,
878 bool showProgressInfo )
879 :m_timer(0,
"KRun::timer")
881 init (url, window,
"", mode, isLocalFile, showProgressInfo);
884 KRun::KRun(
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
885 bool showProgressInfo )
886 :m_timer(0,
"KRun::timer")
888 init (url, window, asn, mode, isLocalFile, showProgressInfo);
891 void KRun::init (
const KURL& url, TQWidget* window,
const TQCString& asn, mode_t mode,
bool isLocalFile,
892 bool showProgressInfo )
895 m_bAutoDelete =
true;
896 m_bProgressInfo = showProgressInfo;
901 m_bIsDirectory =
false;
902 m_bIsLocalFile = isLocalFile;
905 d->m_runExecutables =
true;
906 d->m_window = window;
914 connect( &m_timer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( slotTimeout() ) );
915 m_timer.start( 0,
true );
916 kdDebug(7010) <<
" new KRun " <<
this <<
" " << url.prettyURL() <<
" timer=" << &m_timer << endl;
923 kdDebug(7010) <<
"INIT called" << endl;
925 bool bypassErrorMessage =
false;
927 if (m_strURL.url().startsWith(
"$(")) {
929 TQString aValue = m_strURL.url();
930 int nDollarPos = aValue.find(
'$' );
932 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
934 if( (aValue)[nDollarPos+1] !=
'$' ) {
935 uint nEndPos = nDollarPos+1;
938 if (aValue[nEndPos]==
'{')
940 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
'}') )
943 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
947 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
948 || aValue[nEndPos].isLetter() || aValue[nEndPos]==
'_' ) )
950 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
952 const char* pEnv = 0;
953 if (!aVarName.isEmpty())
954 pEnv = getenv( aVarName.ascii() );
959 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
961 aValue.remove( nDollarPos, nEndPos-nDollarPos );
964 aValue.remove( nDollarPos, 1 );
967 nDollarPos = aValue.find(
'$', nDollarPos );
969 m_strURL = KURL(aValue);
970 bypassErrorMessage =
true;
973 if ( !m_strURL.isValid() )
975 if (bypassErrorMessage ==
false) {
976 d->m_showingError =
true;
977 KMessageBoxWrapper::error( d->m_window, i18n(
"Malformed URL\n%1" ).arg( m_strURL.url() ) );
978 d->m_showingError =
false;
982 m_timer.start( 0,
true );
985 if ( !kapp->authorizeURLAction(
"open", KURL(), m_strURL))
988 d->m_showingError =
true;
989 KMessageBoxWrapper::error( d->m_window, msg );
990 d->m_showingError =
false;
993 m_timer.start( 0,
true );
997 if ( !m_bIsLocalFile && m_strURL.isLocalFile() )
998 m_bIsLocalFile =
true;
1001 if (m_strURL.protocol().startsWith(
"http"))
1003 exec = d->m_externalBrowser;
1006 if ( m_bIsLocalFile )
1010 KDE_struct_stat buff;
1011 if ( KDE_stat( TQFile::encodeName(m_strURL.path()), &buff ) == -1 )
1013 d->m_showingError =
true;
1014 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() ) );
1015 d->m_showingError =
false;
1018 m_timer.start( 0,
true );
1021 m_mode = buff.st_mode;
1025 assert( mime != 0L );
1026 kdDebug(7010) <<
"MIME TYPE is " << mime->name() << endl;
1031 kdDebug(7010) <<
"Helper protocol" << endl;
1035 if (!((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")))
1036 urls.append( m_strURL );
1048 else if (exec.startsWith(
"!"))
1060 run( *service, urls, d->m_window, d->m_asn );
1069 m_timer.start( 0,
true );
1074 if ((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")) {
1076 run(
"kfmclient openProfile webbrowsing", urls );
1079 m_timer.start( 0,
true );
1084 if ( S_ISDIR( m_mode ) )
1100 kdDebug(7010) <<
"Testing directory (stating)" << endl;
1105 connect( job, TQT_SIGNAL( result(
TDEIO::Job * ) ),
1106 this, TQT_SLOT( slotStatResult(
TDEIO::Job * ) ) );
1108 kdDebug(7010) <<
" Job " << job <<
" is about stating " << m_strURL.url() << endl;
1113 kdDebug(7010) <<
"KRun::~KRun() " <<
this << endl;
1117 kdDebug(7010) <<
"KRun::~KRun() done " <<
this << endl;
1121 void KRun::scanFile()
1123 kdDebug(7010) <<
"###### KRun::scanFile " << m_strURL.url() << endl;
1126 if ( m_strURL.query().isEmpty() )
1129 assert( mime != 0L );
1130 if ( mime->name() !=
"application/octet-stream" || m_bIsLocalFile )
1132 kdDebug(7010) <<
"Scanfile: MIME TYPE is " << mime->name() << endl;
1144 kdError(7010) <<
"#### NO SUPPORT FOR READING!" << endl;
1147 m_timer.start( 0,
true );
1150 kdDebug(7010) <<
this <<
" Scanning file " << m_strURL.url() << endl;
1154 connect(job, TQT_SIGNAL( result(
TDEIO::Job *)),
1155 this, TQT_SLOT( slotScanFinished(
TDEIO::Job *)));
1156 connect(job, TQT_SIGNAL( mimetype(
TDEIO::Job *,
const TQString &)),
1157 this, TQT_SLOT( slotScanMimeType(
TDEIO::Job *,
const TQString &)));
1159 kdDebug(7010) <<
" Job " << job <<
" is about getting from " << m_strURL.url() << endl;
1162 void KRun::slotTimeout()
1164 kdDebug(7010) <<
this <<
" slotTimeout called" << endl;
1175 if ( m_bFinished ) {
1186 else if ( m_bIsDirectory )
1188 m_bIsDirectory =
false;
1194 if ( m_bAutoDelete )
1201 void KRun::slotStatResult(
TDEIO::Job * job )
1206 d->m_showingError =
true;
1207 kdError(7010) <<
this <<
" ERROR " << job->
error() <<
" " << job->
errorString() << endl;
1210 d->m_showingError =
false;
1216 m_timer.start( 0,
true );
1220 kdDebug(7010) <<
"Finished" << endl;
1221 if(!dynamic_cast<TDEIO::StatJob*>(job))
1222 kdFatal() <<
"job is a " <<
typeid(*job).name() <<
" should be a StatJob" << endl;
1224 TQString knownMimeType;
1226 TDEIO::UDSEntry::ConstIterator it = entry.begin();
1227 for( ; it != entry.end(); it++ ) {
1228 switch( (*it).m_uds ) {
1230 if ( S_ISDIR( (mode_t)((*it).m_long) ) )
1231 m_bIsDirectory =
true;
1236 knownMimeType = (*it).m_str;
1239 d->m_localPath = (*it).m_str;
1245 if ( !knownMimeType.isEmpty() )
1257 m_timer.start( 0,
true );
1261 void KRun::slotScanMimeType(
TDEIO::Job *,
const TQString &mimetype )
1263 if ( mimetype.isEmpty() )
1264 kdWarning(7010) <<
"KRun::slotScanFinished : MimetypeJob didn't find a mimetype! Probably a tdeioslave bug." << endl;
1269 void KRun::slotScanFinished(
TDEIO::Job *job )
1274 d->m_showingError =
true;
1275 kdError(7010) <<
this <<
" ERROR (stat) : " << job->
error() <<
" " << job->
errorString() << endl;
1278 d->m_showingError =
false;
1284 m_timer.start( 0,
true );
1290 kdDebug(7010) <<
"Resulting mime type is " << type << endl;
1352 Q_ASSERT( !m_bFinished );
1355 if ( !d->m_preferredService.isEmpty() ) {
1356 kdDebug(7010) <<
"Attempting to open with preferred service: " << d->m_preferredService << endl;
1358 if ( serv && serv->hasServiceType( type ) )
1361 lst.append( m_strURL );
1362 m_bFinished =
KRun::run( *serv, lst, d->m_window, d->m_asn );
1371 if ( ((type ==
"application/x-desktop") ||
1372 (type ==
"media/builtin-mydocuments") ||
1373 (type ==
"media/builtin-mycomputer") ||
1374 (type ==
"media/builtin-mynetworkplaces") ||
1375 (type ==
"media/builtin-printers") ||
1376 (type ==
"media/builtin-trash") ||
1377 (type ==
"media/builtin-webbrowser")) && (!d->m_localPath.isEmpty()) )
1380 m_strURL.setPath( d->m_localPath );
1383 if (!m_bFinished &&
KRun::runURL( m_strURL, type, d->m_window, d->m_asn,
false, d->m_runExecutables, d->m_suggestedFileName )){
1391 m_timer.start( 0,
true );
1394 void KRun::killJob()
1398 kdDebug(7010) <<
"KRun::killJob run=" <<
this <<
" m_job=" << m_job << endl;
1406 kdDebug(7010) <<
"KRun::abort " <<
this <<
" m_showingError=" << d->m_showingError << endl;
1410 if ( d->m_showingError )
1418 m_timer.start( 0,
true );
1424 d->m_externalBrowser = TDEConfigGroup(TDEGlobal::config(),
"General").readEntry(
"BrowserApplication");
1426 d->m_externalBrowser = TQString::null;
1431 d->m_preferredService = desktopEntryName;
1436 d->m_runExecutables = b;
1441 d->m_suggestedFileName = fileName;
1446 return ( serviceType ==
"application/x-desktop" ||
1447 serviceType ==
"media/builtin-mydocuments" ||
1448 serviceType ==
"media/builtin-mycomputer" ||
1449 serviceType ==
"media/builtin-mynetworkplaces" ||
1450 serviceType ==
"media/builtin-printers" ||
1451 serviceType ==
"media/builtin-trash" ||
1452 serviceType ==
"media/builtin-webbrowser" ||
1453 serviceType ==
"application/x-executable" ||
1454 serviceType ==
"application/x-msdos-program" ||
1455 serviceType ==
"application/x-shellscript" );
1461 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName)
1463 return (
new TDEProcessRunner(p, binName))->pid();
1468 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName,
const TDEStartupInfoId&
id )
1470 return (
new TDEProcessRunner(p, binName,
id))->pid();
1474 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName )
1480 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1481 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1484 if ( !process_->pid() )
1485 slotProcessExited( process_ );
1489 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName,
const TDEStartupInfoId&
id )
1492 binName( _binName ),
1496 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1497 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1500 if ( !process_->pid() )
1501 slotProcessExited( process_ );
1505 TDEProcessRunner::~TDEProcessRunner()
1511 TDEProcessRunner::pid()
const 1513 return process_->pid();
1517 TDEProcessRunner::slotProcessExited(TDEProcess * p)
1522 kdDebug(7010) <<
"slotProcessExited " << binName << endl;
1523 kdDebug(7010) <<
"normalExit " << process_->normalExit() << endl;
1524 kdDebug(7010) <<
"exitStatus " << process_->exitStatus() << endl;
1525 bool showErr = process_->normalExit()
1526 && ( process_->exitStatus() == 127 || process_->exitStatus() == 1 );
1527 if ( !binName.isEmpty() && ( showErr || process_->pid() == 0 ) )
1533 if ( !TQFile( binName ).exists() && TDEStandardDirs::findExe( binName ).isEmpty() )
1536 KMessageBox::sorry( 0L, i18n(
"Could not find the program '%1'").arg( binName ) );
1543 TDEStartupInfoData data;
1544 data.addPid( pid());
1546 TDEStartupInfo::sendFinish( id_, data );
1552 void KRun::virtual_hook(
int,
void* )
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
void setEnableExternalBrowser(bool b)
Sets whether the external webbrowser setting should be honoured.
TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
bool allowMultipleFiles() const
Checks whether this service can handle several files as startup arguments.
int error() const
Returns the error code, if there has been an error.
static KURL mostLocalURL(const KURL &url, TQWidget *window)
Tries to map a local URL for the given URL.
void abort()
Abort this KRun.
static pid_t runURL(const KURL &_url, const TQString &_mimetype, bool tempFile, bool runExecutables)
Open the given URL.
virtual TQString name() const
Returns the name of the service.
TQString exec() const
Returns the executable.
static Ptr serviceByStorageId(const TQString &_storageId)
Find a service by its storage-id or desktop-file path.
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...
void setRunExecutables(bool b)
Sets whether executables, .desktop files or shell scripts should be run by KRun.
Represent a service, i.e.
void setPreferredService(const TQString &desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun...
virtual TQString type() const
Returns the type of the service.
virtual TQVariant property(const TQString &_name) const
Returns the requested property.
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 bool supportsReading(const KURL &url)
Returns whether the protocol can retrieve data from URLs.
bool substituteUid() const
Checks whether the service runs with a different user id.
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).
The base class for all jobs.
A TDEIO job that retrieves information about a file or directory.
static TQString binaryName(const TQString &execLine, bool removePath)
Given a full command line (e.g.
static TQString exec(const TQString &protocol)
Returns the library / executable to open for the protocol protocol Example : "tdeio_ftp", meaning either the executable "tdeio_ftp" or the library "tdeio_ftp.la" (recommended), whichever is available.
bool terminal() const
Checks whethe the service should be run in a terminal.
TQString errorString() const
Converts an error code and a non-i18n error message into an error message in the current language...
void setWindow(TQWidget *window)
Associate this job with a window given by window.
void finished()
Emitted when the operation finished.
static TQStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles)
Processes a Exec= line as found in .desktop files.
virtual void kill(bool quietly=true)
Abort this job.
TQString icon() const
Returns the name of the icon.
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
TDEIO_EXPORT StatJob * stat(const KURL &url, bool showProgressInfo=true)
Find all details for one file or directory.
A mime type; prevents guessing.
TQString path() const
Returns the working directory to run the program in.
TQString desktopEntryName() const
Returns the filename of the service desktop entry without any extension.
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.
TDEIO_EXPORT TransferJob * get(const KURL &url, bool reload=false, bool showProgressInfo=true)
Get (a.k.a.
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.
TQString username() const
Returns the user name, if the service runs with a different user id.
static TQString protocolClass(const TQString &protocol)
Returns the protocol class for the specified protocol.
static void publishSlaveOnHold()
Send the slave that was put on hold back to TDELauncher.
static bool isExecutable(const TQString &serviceType)
Returns whether serviceType refers to an executable program instead of a data file.
static bool isExecutableFile(const KURL &url, const TQString &mimetype)
Returns wether the url of mimetype is executable.
void showErrorDialog(TQWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
TQString terminalOptions() const
Returns any options associated with the terminal the service runs in, if it requires a terminal...
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
static pid_t run(const KURL &_url, bool _is_local)
Invokes the default action for the desktop entry.
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...
void error()
Emitted when the operation had an error.
bool m_bScanFile
Used to indicate that the next action is to scan the file.
static pid_t runCommand(TQString cmd)
Run the given shell command and notifies kicker of the starting of the application.
static bool isHelperProtocol(const KURL &url)
Returns whether the protocol can act as a helper protocol.
static KService::Ptr preferredService(const TQString &serviceType, const TQString &genericServiceType)
Returns the preferred service for _serviceType and _genericServiceType ("Application", type of component, or null).
TDEIO_EXPORT TQString buildErrorString(int errorCode, const TQString &errorText)
Returns a translated error message for errorCode using the additional error information provided by e...
virtual ~KRun()
Destructor.
The transfer job pumps data into and/or out of a Slave.
static bool displayOpenWithDialog(const KURL::List &lst, bool tempFiles)
Display the Open-With dialog for those URLs, and run the chosen application.
virtual void foundMimeType(const TQString &_type)
Called if the mimetype has been detected.
static void shellQuote(TQString &_str)
Quotes a string for the shell.
static TQString defaultMimetype(const KURL &url)
Returns default mimetype for this URL based on the protocol.
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.
bool m_bInit
USed to indicate that the next action is to initialize.
virtual void putOnHold()
Abort job.