File indexing completed on 2024-04-28 04:49:53

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef K3B_PROCESS_H
0007 #define K3B_PROCESS_H
0008 
0009 
0010 #include "k3b_export.h"
0011 
0012 #include "k3bkprocess.h"
0013 
0014 namespace K3b {
0015     class ExternalBin;
0016 
0017 
0018     /**
0019      * This is an enhanced K3Process.
0020      * It splits the stderr output to lines making sure the client gets every line as it
0021      * was written by the process.
0022      * Additionally one may set raw stdout and stdin handling using the stdin() and stdout() methods
0023      * to get the process' file descriptors.
0024      * Last but not least Process is able to duplicate stdout making it possible to connect two
0025      * Processes like used in DataJob to duplicate mkisofs' stdout to the stdin of the writer
0026      * (cdrecord or cdrdao)
0027      */
0028     class LIBK3B_EXPORT Process : public K3bKProcess
0029     {
0030         Q_OBJECT
0031 
0032     public:
0033         explicit Process( QObject* parent = 0 );
0034         ~Process() override;
0035 
0036         /**
0037          * In the future this might also set the nice value
0038          */
0039         Process& operator<<( const ExternalBin* );
0040 
0041         Process& operator<<( const char* arg );
0042         Process& operator<<( const QByteArray& arg );
0043         Process& operator<<( const QLatin1String& arg );
0044 
0045         /**
0046          * returned joined list of program arguments
0047          */
0048         QString joinedArgs();
0049 
0050         bool isRunning() const { return state() == QProcess::Running; }
0051 
0052         /**
0053          * Reimplemented from QProcess.
0054          * Closes the write channel but does not kill the process
0055          * as QProcess does.
0056          */
0057         void close() override;
0058 
0059         /**
0060          * Starts the process in \p mode and then waits for it
0061          * to be started.
0062          */
0063         bool start( KProcess::OutputChannelMode mode );
0064 
0065         using K3bKProcess::operator<<;
0066 
0067     public Q_SLOTS:
0068         void setSplitStdout( bool b );
0069 
0070         /**
0071          * default is true
0072          */
0073         void setSuppressEmptyLines( bool b );
0074 
0075     private Q_SLOTS:
0076         void slotReadyReadStandardError();
0077         void slotReadyReadStandardOutput();
0078 
0079     Q_SIGNALS:
0080         void stderrLine( const QString& line );
0081         void stdoutLine( const QString& line );
0082 
0083     private:
0084         class Private;
0085         Private* const d;
0086     };
0087 }
0088 
0089 #endif