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;
937 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
')') )
940 TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
943 FILE *fs = popen(TQFile::encodeName(cmd).data(),
"r");
947 TQTextStream ts(fs, IO_ReadOnly);
948 result = ts.read().stripWhiteSpace();
952 aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
953 }
else if( (aValue)[nDollarPos+1] !=
'$' ) {
954 uint nEndPos = nDollarPos+1;
957 if (aValue[nEndPos]==
'{')
959 while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=
'}') )
962 aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
966 while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
967 || aValue[nEndPos].isLetter() || aValue[nEndPos]==
'_' ) )
969 aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
971 const char* pEnv = 0;
972 if (!aVarName.isEmpty())
973 pEnv = getenv( aVarName.ascii() );
978 aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
980 aValue.remove( nDollarPos, nEndPos-nDollarPos );
983 aValue.remove( nDollarPos, 1 );
986 nDollarPos = aValue.find(
'$', nDollarPos );
988 m_strURL = KURL(aValue);
989 bypassErrorMessage =
true;
992 if ( !m_strURL.isValid() )
994 if (bypassErrorMessage ==
false) {
995 d->m_showingError =
true;
996 KMessageBoxWrapper::error( d->m_window, i18n(
"Malformed URL\n%1" ).arg( m_strURL.url() ) );
997 d->m_showingError =
false;
1001 m_timer.start( 0,
true );
1004 if ( !kapp->authorizeURLAction(
"open", KURL(), m_strURL))
1007 d->m_showingError =
true;
1008 KMessageBoxWrapper::error( d->m_window, msg );
1009 d->m_showingError =
false;
1012 m_timer.start( 0,
true );
1016 if ( !m_bIsLocalFile && m_strURL.isLocalFile() )
1017 m_bIsLocalFile =
true;
1020 if (m_strURL.protocol().startsWith(
"http"))
1022 exec = d->m_externalBrowser;
1025 if ( m_bIsLocalFile )
1029 KDE_struct_stat buff;
1030 if ( KDE_stat( TQFile::encodeName(m_strURL.path()), &buff ) == -1 )
1032 d->m_showingError =
true;
1033 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() ) );
1034 d->m_showingError =
false;
1037 m_timer.start( 0,
true );
1040 m_mode = buff.st_mode;
1044 assert( mime != 0L );
1045 kdDebug(7010) <<
"MIME TYPE is " << mime->name() << endl;
1050 kdDebug(7010) <<
"Helper protocol" << endl;
1054 if (!((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")))
1055 urls.append( m_strURL );
1067 else if (exec.startsWith(
"!"))
1079 run( *service, urls, d->m_window, d->m_asn );
1088 m_timer.start( 0,
true );
1093 if ((m_strURL.protocol().startsWith(
"http")) && (m_strURL.url() ==
"http://default.browser")) {
1095 run(
"kfmclient openProfile webbrowsing", urls );
1098 m_timer.start( 0,
true );
1103 if ( S_ISDIR( m_mode ) )
1119 kdDebug(7010) <<
"Testing directory (stating)" << endl;
1124 connect( job, TQT_SIGNAL( result(
TDEIO::Job * ) ),
1125 this, TQT_SLOT( slotStatResult(
TDEIO::Job * ) ) );
1127 kdDebug(7010) <<
" Job " << job <<
" is about stating " << m_strURL.url() << endl;
1132 kdDebug(7010) <<
"KRun::~KRun() " <<
this << endl;
1136 kdDebug(7010) <<
"KRun::~KRun() done " <<
this << endl;
1140 void KRun::scanFile()
1142 kdDebug(7010) <<
"###### KRun::scanFile " << m_strURL.url() << endl;
1145 if ( m_strURL.query().isEmpty() )
1148 assert( mime != 0L );
1149 if ( mime->name() !=
"application/octet-stream" || m_bIsLocalFile )
1151 kdDebug(7010) <<
"Scanfile: MIME TYPE is " << mime->name() << endl;
1163 kdError(7010) <<
"#### NO SUPPORT FOR READING!" << endl;
1166 m_timer.start( 0,
true );
1169 kdDebug(7010) <<
this <<
" Scanning file " << m_strURL.url() << endl;
1173 connect(job, TQT_SIGNAL( result(
TDEIO::Job *)),
1174 this, TQT_SLOT( slotScanFinished(
TDEIO::Job *)));
1175 connect(job, TQT_SIGNAL( mimetype(
TDEIO::Job *,
const TQString &)),
1176 this, TQT_SLOT( slotScanMimeType(
TDEIO::Job *,
const TQString &)));
1178 kdDebug(7010) <<
" Job " << job <<
" is about getting from " << m_strURL.url() << endl;
1181 void KRun::slotTimeout()
1183 kdDebug(7010) <<
this <<
" slotTimeout called" << endl;
1194 if ( m_bFinished ) {
1205 else if ( m_bIsDirectory )
1207 m_bIsDirectory =
false;
1213 if ( m_bAutoDelete )
1220 void KRun::slotStatResult(
TDEIO::Job * job )
1225 d->m_showingError =
true;
1226 kdError(7010) <<
this <<
" ERROR " << job->
error() <<
" " << job->
errorString() << endl;
1229 d->m_showingError =
false;
1235 m_timer.start( 0,
true );
1239 kdDebug(7010) <<
"Finished" << endl;
1240 if(!dynamic_cast<TDEIO::StatJob*>(job))
1241 kdFatal() <<
"job is a " <<
typeid(*job).name() <<
" should be a StatJob" << endl;
1243 TQString knownMimeType;
1245 TDEIO::UDSEntry::ConstIterator it = entry.begin();
1246 for( ; it != entry.end(); it++ ) {
1247 switch( (*it).m_uds ) {
1249 if ( S_ISDIR( (mode_t)((*it).m_long) ) )
1250 m_bIsDirectory =
true;
1255 knownMimeType = (*it).m_str;
1258 d->m_localPath = (*it).m_str;
1264 if ( !knownMimeType.isEmpty() )
1276 m_timer.start( 0,
true );
1280 void KRun::slotScanMimeType(
TDEIO::Job *,
const TQString &mimetype )
1282 if ( mimetype.isEmpty() )
1283 kdWarning(7010) <<
"KRun::slotScanFinished : MimetypeJob didn't find a mimetype! Probably a tdeioslave bug." << endl;
1288 void KRun::slotScanFinished(
TDEIO::Job *job )
1293 d->m_showingError =
true;
1294 kdError(7010) <<
this <<
" ERROR (stat) : " << job->
error() <<
" " << job->
errorString() << endl;
1297 d->m_showingError =
false;
1303 m_timer.start( 0,
true );
1309 kdDebug(7010) <<
"Resulting mime type is " << type << endl;
1371 Q_ASSERT( !m_bFinished );
1374 if ( !d->m_preferredService.isEmpty() ) {
1375 kdDebug(7010) <<
"Attempting to open with preferred service: " << d->m_preferredService << endl;
1377 if ( serv && serv->hasServiceType( type ) )
1380 lst.append( m_strURL );
1381 m_bFinished =
KRun::run( *serv, lst, d->m_window, d->m_asn );
1390 if ( ((type ==
"application/x-desktop") ||
1391 (type ==
"media/builtin-mydocuments") ||
1392 (type ==
"media/builtin-mycomputer") ||
1393 (type ==
"media/builtin-mynetworkplaces") ||
1394 (type ==
"media/builtin-printers") ||
1395 (type ==
"media/builtin-trash") ||
1396 (type ==
"media/builtin-webbrowser")) && (!d->m_localPath.isEmpty()) )
1399 m_strURL.setPath( d->m_localPath );
1402 if (!m_bFinished &&
KRun::runURL( m_strURL, type, d->m_window, d->m_asn,
false, d->m_runExecutables, d->m_suggestedFileName )){
1410 m_timer.start( 0,
true );
1413 void KRun::killJob()
1417 kdDebug(7010) <<
"KRun::killJob run=" <<
this <<
" m_job=" << m_job << endl;
1425 kdDebug(7010) <<
"KRun::abort " <<
this <<
" m_showingError=" << d->m_showingError << endl;
1429 if ( d->m_showingError )
1437 m_timer.start( 0,
true );
1443 d->m_externalBrowser = TDEConfigGroup(TDEGlobal::config(),
"General").readEntry(
"BrowserApplication");
1445 d->m_externalBrowser = TQString::null;
1450 d->m_preferredService = desktopEntryName;
1455 d->m_runExecutables = b;
1460 d->m_suggestedFileName = fileName;
1465 return ( serviceType ==
"application/x-desktop" ||
1466 serviceType ==
"media/builtin-mydocuments" ||
1467 serviceType ==
"media/builtin-mycomputer" ||
1468 serviceType ==
"media/builtin-mynetworkplaces" ||
1469 serviceType ==
"media/builtin-printers" ||
1470 serviceType ==
"media/builtin-trash" ||
1471 serviceType ==
"media/builtin-webbrowser" ||
1472 serviceType ==
"application/x-executable" ||
1473 serviceType ==
"application/x-msdos-program" ||
1474 serviceType ==
"application/x-shellscript" );
1480 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName)
1482 return (
new TDEProcessRunner(p, binName))->pid();
1487 TDEProcessRunner::run(TDEProcess * p,
const TQString & binName,
const TDEStartupInfoId&
id )
1489 return (
new TDEProcessRunner(p, binName,
id))->pid();
1493 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName )
1499 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1500 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1503 if ( !process_->pid() )
1504 slotProcessExited( process_ );
1508 TDEProcessRunner::TDEProcessRunner(TDEProcess * p,
const TQString & _binName,
const TDEStartupInfoId&
id )
1511 binName( _binName ),
1515 process_, TQT_SIGNAL(processExited(TDEProcess *)),
1516 this, TQT_SLOT(slotProcessExited(TDEProcess *)));
1519 if ( !process_->pid() )
1520 slotProcessExited( process_ );
1524 TDEProcessRunner::~TDEProcessRunner()
1530 TDEProcessRunner::pid()
const 1532 return process_->pid();
1536 TDEProcessRunner::slotProcessExited(TDEProcess * p)
1541 kdDebug(7010) <<
"slotProcessExited " << binName << endl;
1542 kdDebug(7010) <<
"normalExit " << process_->normalExit() << endl;
1543 kdDebug(7010) <<
"exitStatus " << process_->exitStatus() << endl;
1544 bool showErr = process_->normalExit()
1545 && ( process_->exitStatus() == 127 || process_->exitStatus() == 1 );
1546 if ( !binName.isEmpty() && ( showErr || process_->pid() == 0 ) )
1552 if ( !TQFile( binName ).exists() && TDEStandardDirs::findExe( binName ).isEmpty() )
1555 KMessageBox::sorry( 0L, i18n(
"Could not find the program '%1'").arg( binName ) );
1562 TDEStartupInfoData data;
1563 data.addPid( pid());
1565 TDEStartupInfo::sendFinish( id_, data );
1571 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.
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.
TQString terminalOptions() const
Returns any options associated with the terminal the service runs in, if it requires a terminal...
TQString desktopEntryName() const
Returns the filename of the service desktop entry without any extension.
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...
virtual TQVariant property(const TQString &_name) const
Returns the requested property.
void setRunExecutables(bool b)
Sets whether executables, .desktop files or shell scripts should be run by KRun.
Represent a service, i.e.
TQString errorString() const
Converts an error code and a non-i18n error message into an error message in the current language...
void setPreferredService(const TQString &desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun...
bool substituteUid() const
Checks whether the service runs with a different user id.
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.
TQString username() const
Returns the user name, if 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.
virtual TQString type() const
Returns the type of the service.
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.
int error() const
Returns the error code, if there has been an error.
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
TQString path() const
Returns the working directory to run the program in.
TDEIO_EXPORT StatJob * stat(const KURL &url, bool showProgressInfo=true)
Find all details for one file or directory.
A mime type; prevents guessing.
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.
static TQString protocolClass(const TQString &protocol)
Returns the protocol class for the specified protocol.
TQString exec() const
Returns the executable.
static void publishSlaveOnHold()
Send the slave that was put on hold back to TDELauncher.
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.
bool allowMultipleFiles() const
Checks whether this service can handle several files as startup arguments.
bool terminal() const
Checks whethe the service should be run in a terminal.
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.
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.
virtual TQString name() const
Returns the name 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...
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.
bool m_bInit
USed to indicate that the next action is to initialize.
virtual void putOnHold()
Abort job.
TQString icon() const
Returns the name of the icon.