krun.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __k_run_h__
00021 #define __k_run_h__
00022 
00023 #include <sys/stat.h>
00024 #include <sys/types.h>
00025 
00026 #include <qobject.h>
00027 #include <qtimer.h>
00028 #include <qstring.h>
00029 #include <kurl.h>
00030 #include <kstartupinfo.h>
00031 
00032 class KProcess;
00033 class KService;
00034 namespace KIO {
00035    class Job;
00036    class StatJob;
00037 }
00038 
00057 class KIO_EXPORT KRun : public QObject
00058 {
00059   Q_OBJECT
00060 public:
00084   KRun( const KURL& url, mode_t mode = 0,
00085     bool isLocalFile = false, bool showProgressInfo = true );
00086 
00111   KRun( const KURL& url, QWidget* window, mode_t mode = 0,
00112     bool isLocalFile = false, bool showProgressInfo = true );
00113 
00118   virtual ~KRun();
00119 
00126   void abort();
00127 
00133   bool hasError() const { return m_bFault; }
00134 
00140   bool hasFinished() const { return m_bFinished; }
00141 
00149   bool autoDelete() const { return m_bAutoDelete; }
00150 
00159   void setAutoDelete(bool b) { m_bAutoDelete = b; }
00160 
00169   void setPreferredService( const QString& desktopEntryName );
00170 
00178   void setRunExecutables(bool b);
00179 
00187   void setEnableExternalBrowser(bool b);
00188 
00201   static pid_t run( const KService& _service, const KURL::List& _urls, QWidget* window, bool tempFiles = false );
00212   // BIC merge second overload with first one, using tempFiles=false
00213   static pid_t run( const KService& _service, const KURL::List& _urls, bool tempFiles );
00214   static pid_t run( const KService& _service, const KURL::List& _urls );
00215 
00229   static pid_t run( const QString& _exec, const KURL::List& _urls,
00230            const QString& _name = QString::null,
00231            const QString& _icon = QString::null,
00232            const QString& _obsolete1 = QString::null,
00233            const QString& _obsolete2 = QString::null );
00234 
00250   // BIC Merge second overload with first one using runExecutables=true, and
00251   // merge third overload with first one as well using tempFiles=false and
00252   // runExecutables=true
00253   static pid_t runURL( const KURL& _url, const QString& _mimetype, bool tempFile, bool runExecutables);
00254   static pid_t runURL( const KURL& _url, const QString& _mimetype, bool tempFile);
00255   static pid_t runURL( const KURL& _url, const QString& _mimetype );
00256 
00271   static pid_t runCommand( QString cmd );
00272 
00284   static pid_t runCommand( const QString& cmd, const QString & execName, const QString & icon );
00285 
00293   // BIC merge second overload with first one, using tempFiles=false
00294   static bool displayOpenWithDialog( const KURL::List& lst, bool tempFiles );
00295   static bool displayOpenWithDialog( const KURL::List& lst );
00296 
00301   static void shellQuote( QString &_str );
00302 
00317   // BIC merge second overload with first one, using tempFiles=false
00318   static QStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles);
00319   static QStringList processDesktopExec(const KService &_service, const KURL::List &_urls, bool has_shell);
00320 
00329   static QString binaryName( const QString & execLine, bool removePath );
00330 
00336   static bool isExecutable( const QString& serviceType );
00337 
00351    static bool isExecutableFile( const KURL& url, const QString &mimetype );
00352 
00357     static bool checkStartupNotify( const QString& binName, const KService* service, bool* silent_arg, QCString* wmclass_arg );
00358 
00359 signals:
00364   void finished();
00369   void error();
00370 
00371 protected slots:
00372   void slotTimeout();
00373   void slotScanFinished( KIO::Job * );
00374   void slotScanMimeType( KIO::Job *, const QString &type );
00375   virtual void slotStatResult( KIO::Job * );
00376 
00377 protected:
00378   virtual void init();
00379 
00380   virtual void scanFile();
00381 
00387   virtual void foundMimeType( const QString& _type );
00388 
00389   virtual void killJob();
00390 
00391   KURL m_strURL;
00392   bool m_bFault;
00393   bool m_bAutoDelete;
00394   bool m_bProgressInfo;
00395   bool m_bFinished;
00396   KIO::Job * m_job;
00397   QTimer m_timer;
00398 
00403   bool m_bScanFile;
00404   bool m_bIsDirectory;
00405 
00410   bool m_bInit;
00411 
00412   bool m_bIsLocalFile;
00413   mode_t m_mode;
00414 
00415 protected:
00416   virtual void virtual_hook( int id, void* data );
00417 
00418 private:
00419   void init (const KURL& url, QWidget* window, mode_t mode,
00420              bool isLocalFile, bool showProgressInfo);
00421 private:
00422   class KRunPrivate;
00423   KRunPrivate *d;
00424 };
00425 
00426 #ifndef KDE_NO_COMPAT
00427 
00433 class KIO_EXPORT_DEPRECATED KOpenWithHandler
00434 {
00435 public:
00436   KOpenWithHandler() {}
00437   static bool exists() { return true; }
00438 };
00439 #endif
00440 
00447 class KIO_EXPORT KProcessRunner : public QObject
00448 {
00449   Q_OBJECT
00450 
00451   public:
00452 
00453     static pid_t run(KProcess *, const QString & binName);
00454 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded
00455     static pid_t run(KProcess *, const QString & binName, const KStartupInfoId& id );
00456 #endif
00457 
00458     virtual ~KProcessRunner();
00459 
00460     pid_t pid() const;
00461 
00462   protected slots:
00463 
00464     void slotProcessExited(KProcess *);
00465 
00466   private:
00467 
00468     KProcessRunner(KProcess *, const QString & binName);
00469 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded
00470     KProcessRunner(KProcess *, const QString & binName, const KStartupInfoId& id );
00471 #endif
00472     KProcessRunner();
00473 
00474     KProcess * process_;
00475     QString binName;
00476 #ifdef Q_WS_X11 // We don't have KStartupInfo in Qt/Embedded
00477     KStartupInfoId id_;
00478 #endif
00479 };
00480 
00481 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys