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."));
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;
980 KMessageBoxWrapper::error( d->m_window, i18n(
"Malformed URL\n%1" ).arg( m_strURL.url() ) );
981 d->m_showingError =
false;
985 m_timer.start( 0,
true );
988 if ( !kapp->authorizeURLAction(
"open", KURL(), m_strURL))
991 d->m_showingError =
true;
992 KMessageBoxWrapper::error( d->m_window, msg );
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* )
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.
TDEIO_EXPORT LocalURLJob * localURL(const KURL &remoteUrl)
Retrieve local URL if available.
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 MimetypeJob * mimetype(const KURL &url, bool showProgressInfo=true)
Find mimetype for one file or directory.
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.