summaryrefslogtreecommitdiffstats
path: root/src/processcontroller.cpp
blob: f39a4c60cacd6c1fab05b3770bf2e16e561b5227 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/***************************************************************************
 *   Copyright (C) 2005 by Will Entriken                                   *
 *   william.entriken@villanova.edu                                        *
 *                                                                         *
 *   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.             *
 ***************************************************************************/


#include "processcontroller.h"
#include "processlistviewitem.h"

ProcessController::ProcessController(ProcessListViewItem * parent)
  : TQObject((TQObject *)parent), myParent(parent), myStatus(false), myAutomatic(false), myProcess(new TQProcess(this))
{
	connect (myProcess, TQT_SIGNAL( readyReadStdout() ), (ProcessController *) this, TQT_SLOT( readStdout()) );
	// connect (myProcess, TQT_SIGNAL( destroyed() ), myProcess, TQT_SLOT( kill()) );
	// this should work, according to http://doc.trolltech.com/3.2/qobject.html#~TQObject but it doesn't
}

ProcessController::~ProcessController()
{
	myProcess->kill();
}

void ProcessController::readStdout()
{
	TQString tempOutput = myProcess->readStdout();
	
	if( tempOutput.contains( "ripping..." ))
	{
		TQString songname = tempOutput.mid( tempOutput.find( "]" )+1, tempOutput.findRev( "[" ) - tempOutput.find( "]" ) - 1);
		myParent->setText( 1, songname.stripWhiteSpace() );
		
		TQString bytesR = tempOutput.mid( tempOutput.findRev( "[" )+1, tempOutput.findRev( "]" ) - tempOutput.findRev( "[" ) - 1);
		myParent->setText( 2, bytesR.stripWhiteSpace() );
	}
		
	if( tempOutput.contains( "Connecting..." ))
	{
		myParent->setText( 1, "Connecting..." );
		myParent->setText( 2, "" );
	}
		
	if( tempOutput.contains( "buffering" ))
	{
		myParent->setText( 1, "Buffering..." );
		myParent->setText( 2, "" );
	}
		
	if( tempOutput.contains( "Time to stop is here" ))
	{
		myParent->setText( 1, "Complete" );
		myParent->setText( 2, "" );
		//TQTimer::singleShot( 1500, myParent, TQT_SLOT( setEmptyText(3) ));
	}
}


void ProcessController::startRip(TQString destination, TQString time)
{
	myStatus = true;
	myParent->setText( 1, "Ripping" );
	
	myProcess->clearArguments();
	myProcess->addArgument( "streamripper" );
	myProcess->addArgument( myUrl );
	myProcess->addArgument( "-d " );
	myProcess->addArgument( destination );
	if( time.toInt() )
	{
		myProcess->addArgument( "-l " );
		myProcess->addArgument( time );
	}

	myProcess->setCommunication( TQProcess::Stdout | TQProcess::Stderr | TQProcess::DupStderr );
	myProcess->start();
}


void ProcessController::stopRip()
{
	myStatus = false;
	myParent->setText( 1, "" );
	myParent->setText( 2, "" );

	myProcess->tryTerminate();
	TQTimer::singleShot( 2000, myProcess, TQT_SLOT( kill() ) );
}


bool ProcessController::getStatus()
{
	return myStatus;
}

TQString ProcessController::getUrl()
{
	return myUrl;
}

void ProcessController::setAutomatic(bool a)
{
	myAutomatic = a;
}

bool ProcessController::getAutomatic()
{
	return myAutomatic;
}
#if KDE_IS_VERSION(3,3,90)
void ProcessController::setService(DNSSD::RemoteService::Ptr service)
{
	myService = service;
}

DNSSD::RemoteService::Ptr ProcessController::getService()
{
	return myService;
}
#endif

TQString ProcessController::getDescription()
{
	return myDescription;
}

void ProcessController::setUrl(TQString Url)
{
	myUrl = Url;
}

void ProcessController::setDescription(TQString Description)
{
	myDescription = Description;
}

#include "processcontroller.moc"