File indexing completed on 2024-04-21 04:47:49

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Shane King <kde@dontletsstart.com>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef AMAROK_PROCESS_H
0018 #define AMAROK_PROCESS_H
0019 
0020 #include "amarok_export.h"
0021 
0022 #include <KProcess>
0023 
0024 class QTextCodec;
0025 
0026 // Classes needed to wrap some KProcess stuff to make it more like K3Process
0027 // Also need to close fds on fork under unix
0028 
0029 ////////////////////////////////////////////////////////////////////////////////
0030 // class Process
0031 ////////////////////////////////////////////////////////////////////////////////
0032 
0033 class AMAROK_EXPORT AmarokProcess : public KProcess
0034 {
0035     Q_OBJECT
0036 
0037     public:
0038         explicit AmarokProcess(QObject *parent = nullptr);
0039 
0040         void setLowPriority(bool lowPriority) { this->lowPriority = lowPriority; }
0041 
0042         void start();
0043 
0044     // for K3Process compat
0045     Q_SIGNALS:
0046         void processExited(AmarokProcess *proc);
0047         void receivedStdout(AmarokProcess *proc);
0048         void receivedStderr(AmarokProcess *proc);
0049 
0050     protected:
0051         void setupChildProcess() override;
0052 
0053     private Q_SLOTS:
0054         void finished();  // TODO: This has the same name as a signal in QProcess. Rename it.
0055         void readyReadStandardOutput();
0056         void readyReadStandardError();
0057 
0058     private:
0059         bool lowPriority;
0060 };
0061 
0062 ////////////////////////////////////////////////////////////////////////////////
0063 // class ProcIO
0064 ////////////////////////////////////////////////////////////////////////////////
0065 
0066 class AMAROK_EXPORT AmarokProcIO : public AmarokProcess
0067 {
0068     Q_OBJECT
0069 
0070     public:
0071         explicit AmarokProcIO(QObject *parent = nullptr);
0072 
0073         int readln (QString &line);
0074         bool writeStdin(const QString &line);
0075 
0076         void start();
0077 
0078     Q_SIGNALS:
0079         void readReady(AmarokProcIO *pio);
0080         
0081     private Q_SLOTS:
0082         void readyReadStandardOutput();
0083     
0084     private:
0085         QTextCodec *codec;
0086 };
0087 
0088 ////////////////////////////////////////////////////////////////////////////////
0089 // class ShellProcess
0090 ////////////////////////////////////////////////////////////////////////////////
0091 
0092 class AMAROK_EXPORT AmarokShellProcess : public AmarokProcess
0093 {
0094     public:
0095         explicit AmarokShellProcess(QObject *parent = nullptr) : AmarokProcess(parent) {}
0096 
0097         AmarokShellProcess &operator<<(const QString& arg);
0098         AmarokShellProcess &operator<<(const QStringList& args);
0099 };
0100 
0101 #endif // AMAROK_PROCESS_H