summaryrefslogtreecommitdiff
path: root/src/myprocess.h
blob: cfe083205bb9d1a8a04f6268d6c04352cdfee6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef MY_PROCESS_H
#define MY_PROCESS_H

#include <QProcess>
#include <QTemporaryFile>
#include <QTimer>

//! MyProcess is a specialized QProcess designed to properly work with mplayer.

/*!
 It can split the mplayer status line into lines.
 It also provides some Qt 3 like functions like addArgument().

 There are two working modes, controlled by the USE_TEMP_FILE define.
 If USE_TEMP_FILE is 1 it will send the output of mplayer to a temporary
 file, and then it will be read from it. Otherwise it will read from
 standard ouput as usual.
*/

class MyProcess : public QProcess
{
	Q_OBJECT

public:
	MyProcess ( QObject * parent = 0 );

	virtual void setExecutable(const QString & p) { program = p; };
	QString executable() { return program; };

	virtual void addArgument(const QString & a); 	//!< Add an argument

	void clearArguments(); 		//!< Clear the list of arguments
	QStringList arguments(); 	//!< Return the list of arguments

	void start();				//!< Start the process
	bool isRunning();			//!< Return true if the process is running

	static QStringList splitArguments(const QString & args);

signals:
	//! Emitted when there's a line available
	void lineAvailable(QByteArray ba);

protected slots:
	void readStdOut();			//!< Called for reading from standard output
	void readTmpFile();			//!< Called for reading from the temp file
	void procFinished();		//!< Called when the process has finished

protected:
	//! Return true if it's possible to read an entire line.
	/*! @param from specifies the position to begin. */
	int canReadLine(const QByteArray & ba, int from = 0);
	//! Called from readStdOut() and readTmpFile() to do all the work
	void genericRead(QByteArray buffer);

protected:
	QString program;
	QStringList arg;

	QByteArray remaining_output;

	QTemporaryFile temp_file;
	QTimer timer;
};

#endif