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