krun.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 00003 Copyright (C) 2006 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef __k_run_h__ 00022 #define __k_run_h__ 00023 00024 #include <sys/stat.h> 00025 #include <sys/types.h> 00026 00027 #include <tqobject.h> 00028 #include <tqtimer.h> 00029 #include <tqstring.h> 00030 #include <kurl.h> 00031 #include <kstartupinfo.h> 00032 00033 class KProcess; 00034 class KService; 00035 namespace KIO { 00036 class Job; 00037 class StatJob; 00038 } 00039 00058 class KIO_EXPORT KRun : public TQObject 00059 { 00060 Q_OBJECT 00061 public: 00085 KRun( const KURL& url, mode_t mode = 0, 00086 bool isLocalFile = false, bool showProgressInfo = true ); 00087 00112 KRun( const KURL& url, TQWidget* window, mode_t mode = 0, 00113 bool isLocalFile = false, bool showProgressInfo = true ); 00114 KRun( const KURL& url, TQWidget* window, const TQCString& asn, mode_t mode = 0, 00115 bool isLocalFile = false, bool showProgressInfo = true ); 00116 00121 virtual ~KRun(); 00122 00129 void abort(); 00130 00136 bool hasError() const { return m_bFault; } 00137 00143 bool hasFinished() const { return m_bFinished; } 00144 00152 bool autoDelete() const { return m_bAutoDelete; } 00153 00162 void setAutoDelete(bool b) { m_bAutoDelete = b; } 00163 00172 void setPreferredService( const TQString& desktopEntryName ); 00173 00181 void setRunExecutables(bool b); 00182 00190 void setEnableExternalBrowser(bool b); 00191 00200 void setSuggestedFileName( const TQString& fileName ); 00201 00214 static pid_t run( const KService& _service, const KURL::List& _urls, TQWidget* window, bool tempFiles = false ); 00215 static pid_t run( const KService& _service, const KURL::List& _urls, TQWidget* window, 00216 const TQCString& asn, bool tempFiles = false ); 00227 // BIC merge second overload with first one, using tempFiles=false 00228 static pid_t run( const KService& _service, const KURL::List& _urls, bool tempFiles ); 00229 static pid_t run( const KService& _service, const KURL::List& _urls ); 00232 static pid_t run( const KService& _service, const KURL::List& _urls, TQWidget* window, bool tempFiles, const TQString& suggestedFileName ); 00233 static pid_t run( const KService& _service, const KURL::List& _urls, TQWidget* window, 00234 const TQCString& asn, bool tempFiles, const TQString& suggestedFileName ); 00235 00249 static pid_t run( const TQString& _exec, const KURL::List& _urls, 00250 const TQString& _name = TQString::null, 00251 const TQString& _icon = TQString::null, 00252 const TQString& _obsolete1 = TQString::null, 00253 const TQString& _obsolete2 = TQString::null ); 00254 00270 // BIC Merge second overload with first one using runExecutables=true, and 00271 // merge third overload with first one as well using tempFiles=false and 00272 // runExecutables=true 00273 static pid_t runURL( const KURL& _url, const TQString& _mimetype, bool tempFile, bool runExecutables); 00274 static pid_t runURL( const KURL& _url, const TQString& _mimetype, bool tempFile); 00275 static pid_t runURL( const KURL& _url, const TQString& _mimetype ); 00278 static pid_t runURL( const KURL& _url, const TQString& _mimetype, TQWidget* window, const TQCString& asn, bool tempFile, bool runExecutables, const TQString& suggestedFileName ); 00279 static pid_t runURL( const KURL& _url, const TQString& _mimetype, bool tempFile, bool runExecutables, const TQString& suggestedFileName ); 00280 00295 static pid_t runCommand( TQString cmd ); 00296 00308 static pid_t runCommand( const TQString& cmd, const TQString & execName, const TQString & icon ); 00309 static pid_t runCommand( const TQString& cmd, const TQString & execName, const TQString & icon, 00310 TQWidget* window, const TQCString& asn ); 00311 00319 // BIC merge second overload with first one, using tempFiles=false 00320 static bool displayOpenWithDialog( const KURL::List& lst, bool tempFiles ); 00321 static bool displayOpenWithDialog( const KURL::List& lst ); 00324 static bool displayOpenWithDialog( const KURL::List& lst, bool tempFiles, const TQString& suggestedFileName ); 00325 00330 static void shellQuote( TQString &_str ); 00331 00346 static TQStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles); 00347 static TQStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell); 00350 static TQStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles, const TQString& suggestedFileName); 00351 00360 static TQString binaryName( const TQString & execLine, bool removePath ); 00361 00367 static bool isExecutable( const TQString& serviceType ); 00368 00382 static bool isExecutableFile( const KURL& url, const TQString &mimetype ); 00383 00388 static bool checkStartupNotify( const TQString& binName, const KService* service, bool* silent_arg, TQCString* wmclass_arg ); 00389 00390 signals: 00395 void finished(); 00400 void error(); 00401 00402 protected slots: 00403 void slotTimeout(); 00404 void slotScanFinished( KIO::Job * ); 00405 void slotScanMimeType( KIO::Job *, const TQString &type ); 00406 virtual void slotStatResult( KIO::Job * ); 00407 00408 protected: 00409 virtual void init(); 00410 00411 virtual void scanFile(); 00412 00418 virtual void foundMimeType( const TQString& _type ); 00419 00420 virtual void killJob(); 00421 00422 KURL m_strURL; 00423 bool m_bFault; 00424 bool m_bAutoDelete; 00425 bool m_bProgressInfo; 00426 bool m_bFinished; 00427 KIO::Job * m_job; 00428 TQTimer m_timer; 00429 00434 bool m_bScanFile; 00435 bool m_bIsDirectory; 00436 00441 bool m_bInit; 00442 00443 bool m_bIsLocalFile; 00444 mode_t m_mode; 00445 00446 protected: 00447 virtual void virtual_hook( int id, void* data ); 00448 00449 private: 00450 void init (const KURL& url, TQWidget* window, const TQCString& asn, mode_t mode, 00451 bool isLocalFile, bool showProgressInfo); 00452 private: 00453 class KRunPrivate; 00454 KRunPrivate *d; 00455 }; 00456 00457 #ifndef KDE_NO_COMPAT 00458 00464 class KIO_EXPORT_DEPRECATED KOpenWithHandler 00465 { 00466 public: 00467 KOpenWithHandler() {} 00468 static bool exists() { return true; } 00469 }; 00470 #endif 00471 00478 class KIO_EXPORT KProcessRunner : public TQObject 00479 { 00480 Q_OBJECT 00481 00482 public: 00483 00484 static pid_t run(KProcess *, const TQString & binName); 00485 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded 00486 static pid_t run(KProcess *, const TQString & binName, const KStartupInfoId& id ); 00487 #endif 00488 00489 virtual ~KProcessRunner(); 00490 00491 pid_t pid() const; 00492 00493 protected slots: 00494 00495 void slotProcessExited(KProcess *); 00496 00497 private: 00498 00499 KProcessRunner(KProcess *, const TQString & binName); 00500 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded 00501 KProcessRunner(KProcess *, const TQString & binName, const KStartupInfoId& id ); 00502 #endif 00503 KProcessRunner(); 00504 00505 KProcess * process_; 00506 TQString binName; 00507 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded 00508 KStartupInfoId id_; 00509 #endif 00510 }; 00511 00512 #endif