Diffstat (limited to 'noncore/apps/advancedfm/output.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/output.cpp | 128 |
1 files changed, 115 insertions, 13 deletions
diff --git a/noncore/apps/advancedfm/output.cpp b/noncore/apps/advancedfm/output.cpp index 82e78a7..946d038 100644 --- a/noncore/apps/advancedfm/output.cpp +++ b/noncore/apps/advancedfm/output.cpp | |||
@@ -4,20 +4,25 @@ | |||
4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> | 4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> |
5 | ****************************************************************************/ | 5 | ****************************************************************************/ |
6 | #include "output.h" | 6 | #include "output.h" |
7 | #include "inputDialog.h" | 7 | |
8 | #include <opie/oprocess.h> | ||
8 | 9 | ||
9 | #include <qpe/filemanager.h> | 10 | #include <qpe/filemanager.h> |
10 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/applnk.h> | 12 | #include <qpe/applnk.h> |
12 | 13 | ||
14 | #include <qmessagebox.h> | ||
15 | #include <qstringlist.h> | ||
13 | #include <qfile.h> | 16 | #include <qfile.h> |
14 | 17 | #include <qcstring.h> | |
15 | #include <qlineedit.h> | 18 | #include <qlineedit.h> |
16 | #include <qmultilineedit.h> | 19 | #include <qmultilineedit.h> |
17 | #include <qpushbutton.h> | 20 | #include <qpushbutton.h> |
18 | #include <qlayout.h> | 21 | #include <qlayout.h> |
19 | #include <qvariant.h> | 22 | #include <qvariant.h> |
20 | 23 | ||
24 | #include <errno.h> | ||
25 | |||
21 | /* XPM */ | 26 | /* XPM */ |
22 | static char * filesave_xpm[] = { | 27 | static char * filesave_xpm[] = { |
23 | "16 16 78 1", | 28 | "16 16 78 1", |
@@ -116,16 +121,21 @@ static char * filesave_xpm[] = { | |||
116 | " +...z]n$ ", | 121 | " +...z]n$ ", |
117 | " +... "}; | 122 | " +... "}; |
118 | 123 | ||
119 | Output::Output( QWidget* parent, const char* name, bool modal, WFlags fl ) | 124 | Output::Output( const QStringList commands, QWidget* parent, const char* name, bool modal, WFlags fl) |
120 | : QDialog( parent, name, modal, fl ) | 125 | : QDialog( parent, name, modal, fl ) |
121 | { | 126 | { |
127 | QStringList cmmds; | ||
128 | // cmmds=QStringList::split( " ", commands, false); | ||
129 | cmmds=commands; | ||
130 | // qDebug("count %d", cmmds.count()); | ||
122 | if ( !name ) | 131 | if ( !name ) |
123 | setName( "Output" ); | 132 | setName( tr("Output")); |
124 | resize( 196, 269 ); | 133 | resize( 196, 269 ); |
125 | setCaption( name ); | 134 | setCaption( name ); |
135 | |||
126 | OutputLayout = new QGridLayout( this ); | 136 | OutputLayout = new QGridLayout( this ); |
127 | OutputLayout->setSpacing( 6 ); | 137 | OutputLayout->setSpacing( 2); |
128 | OutputLayout->setMargin( 11 ); | 138 | OutputLayout->setMargin( 2); |
129 | 139 | ||
130 | QPushButton *docButton; | 140 | QPushButton *docButton; |
131 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); | 141 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); |
@@ -134,19 +144,41 @@ Output::Output( QWidget* parent, const char* name, bool modal, WFlags fl ) | |||
134 | // docButton->setFlat(TRUE); | 144 | // docButton->setFlat(TRUE); |
135 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); | 145 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); |
136 | 146 | ||
137 | |||
138 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); | 147 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); |
139 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); | 148 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); |
140 | 149 | ||
150 | proc = new OProcess(); | ||
141 | 151 | ||
152 | connect(proc, SIGNAL(processExited(OProcess *)), | ||
153 | this, SLOT( processFinished())); | ||
154 | |||
155 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | ||
156 | this, SLOT(commandStdout(OProcess *, char *, int))); | ||
157 | |||
158 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | ||
159 | this, SLOT(commandStderr(OProcess *, char *, int))); | ||
160 | |||
161 | // connect( , SIGNAL(received(const QByteArray &)), | ||
162 | // this, SLOT(commandStdin(const QByteArray &))); | ||
163 | |||
164 | // * proc << commands.latin1(); | ||
165 | for ( QStringList::Iterator it = cmmds.begin(); it != cmmds.end(); ++it ) { | ||
166 | qDebug( "%s", (*it).latin1() ); | ||
167 | * proc << (*it).latin1(); | ||
142 | } | 168 | } |
143 | 169 | ||
144 | /* | 170 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) { |
145 | * Destroys the object and frees any allocated resources | 171 | |
146 | */ | 172 | OutputEdit->append("Process could not start"); |
147 | Output::~Output() | 173 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
148 | { | 174 | perror("Error: "); |
149 | // no need to delete child widgets, Qt does it all for us | 175 | QString errorMsg="Error\n"+(QString)strerror(errno); |
176 | OutputEdit->append( errorMsg); | ||
177 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | Output::~Output() { | ||
150 | } | 182 | } |
151 | 183 | ||
152 | void Output::saveOutput() { | 184 | void Output::saveOutput() { |
@@ -175,6 +207,76 @@ void Output::saveOutput() { | |||
175 | } else | 207 | } else |
176 | qWarning("Could not write file"); | 208 | qWarning("Could not write file"); |
177 | f.close(); | 209 | f.close(); |
210 | } | ||
211 | } | ||
212 | |||
213 | void Output::commandStdout(OProcess*, char *buffer, int buflen) { | ||
214 | qWarning("received stdout %d bytes", buflen); | ||
215 | |||
216 | // QByteArray data(buflen); | ||
217 | // data.fill(*buffer, buflen); | ||
218 | // for (uint i = 0; i < data.count(); i++ ) { | ||
219 | // printf("%c", buffer[i] ); | ||
220 | // } | ||
221 | // printf("\n"); | ||
178 | 222 | ||
223 | QString lineStr = buffer; | ||
224 | lineStr=lineStr.left(lineStr.length()-1); | ||
225 | OutputEdit->append(lineStr); | ||
226 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
179 | } | 227 | } |
228 | |||
229 | |||
230 | void Output::commandStdin( const QByteArray &data) { | ||
231 | qWarning("received stdin %d bytes", data.size()); | ||
232 | // recieved data from the io layer goes to sz | ||
233 | proc->writeStdin(data.data(), data.size()); | ||
234 | } | ||
235 | |||
236 | void Output::commandStderr(OProcess*, char *buffer, int buflen) { | ||
237 | qWarning("received stderrt %d bytes", buflen); | ||
238 | |||
239 | QString lineStr = buffer; | ||
240 | // lineStr=lineStr.left(lineStr.length()-1); | ||
241 | OutputEdit->append(lineStr); | ||
242 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
243 | } | ||
244 | |||
245 | void Output::processFinished() { | ||
246 | |||
247 | delete proc; | ||
248 | OutputEdit->append( "\nFinished\n"); | ||
249 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
250 | // close(); | ||
251 | // disconnect( layer(), SIGNAL(received(const QByteArray &)), | ||
252 | // this, SLOT(commandStdin(const QByteArray &))); | ||
253 | } | ||
254 | |||
255 | //============================== | ||
256 | |||
257 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | ||
258 | : QDialog( parent, name, modal, fl ) | ||
259 | { | ||
260 | if ( !name ) | ||
261 | setName( "InputDialog" ); | ||
262 | resize( 234, 50 ); | ||
263 | setMaximumSize( QSize( 240, 50 ) ); | ||
264 | setCaption( tr(name ) ); | ||
265 | |||
266 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | ||
267 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); | ||
268 | connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(returned() )); | ||
269 | } | ||
270 | |||
271 | InputDialog::~InputDialog() { | ||
272 | inputText = LineEdit1->text(); | ||
273 | } | ||
274 | |||
275 | void InputDialog::setInputText(const QString &string) { | ||
276 | LineEdit1->setText( string); | ||
277 | } | ||
278 | |||
279 | void InputDialog::returned() { | ||
280 | inputText = LineEdit1->text(); | ||
281 | this->accept(); | ||
180 | } | 282 | } |