| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2007 Shane King <kde@dontletsstart.com> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#ifndef AMAROK_PROCESS_H |
| 18 |
#define AMAROK_PROCESS_H |
| 19 |
|
| 20 |
#include "amarok_export.h" |
| 21 |
|
| 22 |
#include <KProcess> |
| 23 |
|
| 24 |
class QTextCodec; |
| 25 |
|
| 26 |
// Classes needed to wrap some KProcess stuff to make it more like K3Process |
| 27 |
// Also need to close fds on fork under unix |
| 28 |
|
| 29 |
//////////////////////////////////////////////////////////////////////////////// |
| 30 |
// class Process |
| 31 |
//////////////////////////////////////////////////////////////////////////////// |
| 32 |
|
| 33 |
class AMAROK_EXPORT AmarokProcess : public KProcess |
| 34 |
{ |
| 35 |
Q_OBJECT |
| 36 |
|
| 37 |
public: |
| 38 |
explicit AmarokProcess(QObject *parent = 0); |
| 39 |
|
| 40 |
void setLowPriority(bool lowPriority) { this->lowPriority = lowPriority; } |
| 41 |
|
| 42 |
void start(); |
| 43 |
|
| 44 |
// for K3Process compat |
| 45 |
Q_SIGNALS: |
| 46 |
void processExited(AmarokProcess *proc); |
| 47 |
void receivedStdout(AmarokProcess *proc); |
| 48 |
void receivedStderr(AmarokProcess *proc); |
| 49 |
|
| 50 |
protected: |
| 51 |
virtual void setupChildProcess(); |
| 52 |
|
| 53 |
private slots: |
| 54 |
void finished(); |
| 55 |
void readyReadStandardOutput(); |
| 56 |
void readyReadStandardError(); |
| 57 |
|
| 58 |
private: |
| 59 |
bool lowPriority; |
| 60 |
}; |
| 61 |
|
| 62 |
//////////////////////////////////////////////////////////////////////////////// |
| 63 |
// class ProcIO |
| 64 |
//////////////////////////////////////////////////////////////////////////////// |
| 65 |
|
| 66 |
class AMAROK_EXPORT AmarokProcIO : public AmarokProcess |
| 67 |
{ |
| 68 |
Q_OBJECT |
| 69 |
|
| 70 |
public: |
| 71 |
explicit AmarokProcIO(QObject *parent = 0); |
| 72 |
|
| 73 |
int readln (QString &line); |
| 74 |
bool writeStdin(const QString &line); |
| 75 |
|
| 76 |
void start(); |
| 77 |
|
| 78 |
Q_SIGNALS: |
| 79 |
void readReady(AmarokProcIO *pio); |
| 80 |
|
| 81 |
private slots: |
| 82 |
void readyReadStandardOutput(); |
| 83 |
|
| 84 |
private: |
| 85 |
QTextCodec *codec; |
| 86 |
}; |
| 87 |
|
| 88 |
//////////////////////////////////////////////////////////////////////////////// |
| 89 |
// class ShellProcess |
| 90 |
//////////////////////////////////////////////////////////////////////////////// |
| 91 |
|
| 92 |
class AMAROK_EXPORT AmarokShellProcess : public AmarokProcess |
| 93 |
{ |
| 94 |
public: |
| 95 |
explicit AmarokShellProcess(QObject *parent = 0) : AmarokProcess(parent) {} |
| 96 |
|
| 97 |
AmarokShellProcess &operator<<(const QString& arg); |
| 98 |
AmarokShellProcess &operator<<(const QStringList& args); |
| 99 |
}; |
| 100 |
|
| 101 |
#endif // AMAROK_PROCESS_H |