Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

output.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** outputEdit.cpp
00003 **
00004 ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com>
00005 ****************************************************************************/
00006 #include "output.h"
00007 
00008 /* OPIE */
00009 #include <opie2/odebug.h>
00010 #include <qpe/qpeapplication.h>
00011 #include <qpe/applnk.h>
00012 using namespace Opie::Core;
00013 
00014 /* QT */
00015 #include <qfile.h>
00016 #include <qmultilineedit.h>
00017 #include <qpushbutton.h>
00018 #include <qlayout.h>
00019 
00020 /* STD */
00021 #include <errno.h>
00022 
00023 /* XPM */
00024 static char * filesave_xpm[] = {
00025 "16 16 78 1",
00026 "   c None",
00027 ".  c #343434",
00028 "+  c #A0A0A0",
00029 "@  c #565656",
00030 "#  c #9E9E9E",
00031 "$  c #525252",
00032 "%  c #929292",
00033 "&  c #676767",
00034 "*  c #848484",
00035 "=  c #666666",
00036 "-  c #D8D8D8",
00037 ";  c #FFFFFF",
00038 ">  c #DBDBDB",
00039 ",  c #636363",
00040 "'  c #989898",
00041 ")  c #2D2D2D",
00042 "!  c #909090",
00043 "~  c #AEAEAE",
00044 "{  c #EAEAEA",
00045 "]  c #575757",
00046 "^  c #585858",
00047 "/  c #8A8A8A",
00048 "(  c #828282",
00049 "_  c #6F6F6F",
00050 ":  c #C9C9C9",
00051 "<  c #050505",
00052 "[  c #292929",
00053 "}  c #777777",
00054 "|  c #616161",
00055 "1  c #3A3A3A",
00056 "2  c #BEBEBE",
00057 "3  c #2C2C2C",
00058 "4  c #7C7C7C",
00059 "5  c #F6F6F6",
00060 "6  c #FCFCFC",
00061 "7  c #6B6B6B",
00062 "8  c #959595",
00063 "9  c #4F4F4F",
00064 "0  c #808080",
00065 "a  c #767676",
00066 "b  c #818181",
00067 "c  c #B8B8B8",
00068 "d  c #FBFBFB",
00069 "e  c #F9F9F9",
00070 "f  c #CCCCCC",
00071 "g  c #030303",
00072 "h  c #737373",
00073 "i  c #7A7A7A",
00074 "j  c #7E7E7E",
00075 "k  c #6A6A6A",
00076 "l  c #FAFAFA",
00077 "m  c #505050",
00078 "n  c #9D9D9D",
00079 "o  c #333333",
00080 "p  c #7B7B7B",
00081 "q  c #787878",
00082 "r  c #696969",
00083 "s  c #494949",
00084 "t  c #555555",
00085 "u  c #949494",
00086 "v  c #E6E6E6",
00087 "w  c #424242",
00088 "x  c #515151",
00089 "y  c #535353",
00090 "z  c #3E3E3E",
00091 "A  c #D4D4D4",
00092 "B  c #0C0C0C",
00093 "C  c #353535",
00094 "D  c #474747",
00095 "E  c #ECECEC",
00096 "F  c #919191",
00097 "G  c #7D7D7D",
00098 "H  c #000000",
00099 "I  c #404040",
00100 "J  c #858585",
00101 "K  c #323232",
00102 "L  c #D0D0D0",
00103 "M  c #1C1C1C",
00104 "    ...+        ",
00105 "   @#$%&..+     ",
00106 "   .*=-;;>,..+  ",
00107 "  ')!~;;;;;;{]..",
00108 "  ^/(-;;;;;;;_:<",
00109 "  [}|;;;;;;;{12$",
00110 " #34-55;;;;678$+",
00111 " 90ab=c;dd;e1fg ",
00112 " [ahij((kbl0mn$ ",
00113 " op^q^^7r&]s/$+ ",
00114 "@btu;vbwxy]zAB  ",
00115 "CzDEvEv;;DssF$  ",
00116 "G.H{E{E{IxsJ$+  ",
00117 "  +...vEKxzLM   ",
00118 "     +...z]n$   ",
00119 "        +...    "};
00120 
00121 Output::Output( const QStringList commands, QWidget* parent,  const char* name, bool modal, WFlags fl)
00122     : QDialog( parent, name, modal, fl )
00123 {
00124    QStringList cmmds;
00125 //   cmmds=QStringList::split( " ", commands, false);
00126    cmmds=commands;
00127 //   odebug << "count " << cmmds.count() << "" << oendl; 
00128    if ( !name )
00129        setName( tr("Output"));
00130     resize( 196, 269 );
00131     setCaption( name );
00132 
00133     OutputLayout = new QGridLayout( this );
00134     OutputLayout->setSpacing( 2);
00135     OutputLayout->setMargin( 2);
00136 
00137     QPushButton *docButton;
00138      docButton = new QPushButton(  QPixmap(( const char** ) filesave_xpm  ) ,"",this,"saveButton");
00139      docButton->setFixedSize( QSize( 20, 20 ) );
00140      connect( docButton,SIGNAL(released()),this,SLOT( saveOutput() ));
00141  //    docButton->setFlat(TRUE);
00142      OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 );
00143 
00144     OutputEdit = new QMultiLineEdit( this, "OutputEdit" );
00145     OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 );
00146 
00147     proc = new OProcess();
00148 
00149     connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)),
00150             this, SLOT( processFinished()));
00151 
00152     connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
00153             this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int)));
00154 
00155     connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),
00156             this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int)));
00157 
00158 //     connect( , SIGNAL(received(const QByteArray&)),
00159 //             this, SLOT(commandStdin(const QByteArray&)));
00160 
00161 //    * proc << commands.latin1();
00162       for ( QStringList::Iterator it = cmmds.begin(); it != cmmds.end(); ++it ) {
00163          odebug << "" << (*it).latin1() << "" << oendl; 
00164          * proc << (*it).latin1();
00165       }
00166 
00167      if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) {
00168 
00169          OutputEdit->append(tr("Process could not start") );
00170          OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE);
00171          perror("Error: ");
00172          QString errorMsg=tr("Error\n")+(QString)strerror(errno);
00173          OutputEdit->append( errorMsg);
00174          OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE);
00175      }
00176 }
00177 
00178 Output::~Output() {
00179 }
00180 
00181 void Output::saveOutput() {
00182 
00183     InputDialog *fileDlg;
00184     fileDlg = new InputDialog(this,tr("Save output to file (name only)"),TRUE, 0);
00185     fileDlg->exec();
00186     if( fileDlg->result() == 1 ) {
00187       QString  filename = QPEApplication::documentDir();
00188       if(filename.right(1).find('/') == -1)
00189           filename+="/";
00190       QString name = fileDlg->LineEdit1->text();
00191       filename+="text/plain/"+name;
00192       odebug << filename << oendl; 
00193 
00194       QFile f(filename);
00195       f.open( IO_WriteOnly);
00196       if( f.writeBlock( OutputEdit->text(), qstrlen( OutputEdit->text()) ) != -1) {
00197           DocLnk lnk;
00198           lnk.setName(name); //sets file name
00199           lnk.setFile(filename); //sets File property
00200           lnk.setType("text/plain");
00201           if(!lnk.writeLink()) {
00202               odebug << "Writing doclink did not work" << oendl; 
00203           }
00204       } else
00205           owarn << "Could not write file" << oendl; 
00206       f.close();
00207     }
00208 }
00209 
00210 void Output::commandStdout(OProcess*, char *buffer, int buflen) {
00211     owarn << "received stdout " << buflen << " bytes" << oendl; 
00212 
00213 //     QByteArray data(buflen);
00214 //     data.fill(*buffer, buflen);
00215 //     for (uint i = 0; i < data.count(); i++ ) {
00216 //         printf("%c", buffer[i] );
00217 //     }
00218 //     printf("\n");
00219 
00220     QString lineStr = buffer;
00221     lineStr=lineStr.left(lineStr.length()-1);
00222     OutputEdit->append(lineStr);
00223     OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE);
00224 }
00225 
00226 
00227 void Output::commandStdin( const QByteArray &data) {
00228     owarn << "received stdin  " << data.size() << " bytes" << oendl; 
00229     // recieved data from the io layer goes to sz
00230     proc->writeStdin(data.data(), data.size());
00231 }
00232 
00233 void Output::commandStderr(OProcess*, char *buffer, int buflen) {
00234     owarn << "received stderrt " << buflen << " bytes" << oendl; 
00235 
00236     QString lineStr = buffer;
00237 //    lineStr=lineStr.left(lineStr.length()-1);
00238     OutputEdit->append(lineStr);
00239     OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE);
00240 }
00241 
00242 void Output::processFinished() {
00243 
00244     delete proc;
00245     OutputEdit->append( tr("\nFinished\n") );
00246     OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE);
00247 //    close();
00248 //     disconnect( layer(), SIGNAL(received(const QByteArray&)),
00249 //                this, SLOT(commandStdin(const QByteArray&)));
00250 }
00251 
00252 //==============================
00253 
00254 InputDialog::InputDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
00255     : QDialog( parent, name, modal, fl )
00256 {
00257     if ( !name )
00258         setName( "InputDialog" );
00259     resize( 234, 50 );
00260     setMaximumSize( QSize( 240, 50 ) );
00261     setCaption( tr(name ) );
00262 
00263     LineEdit1 = new QLineEdit( this, "LineEdit1" );
00264     LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) );
00265     LineEdit1->setFocus();
00266     LineEdit1->setFocus();
00267     connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(returned() ));
00268 }
00269 
00270 InputDialog::~InputDialog() {
00271     inputText = LineEdit1->text();
00272 }
00273 
00274 void InputDialog::setInputText(const QString &string) {
00275     LineEdit1->setText( string);
00276 }
00277 
00278 void InputDialog::returned() {
00279     inputText = LineEdit1->text();
00280     this->accept();
00281 }

Generated on Sat Nov 5 16:16:47 2005 for OPIE by  doxygen 1.4.2