00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "fortunepluginwidget.h"
00018
00019
00020 #include <opie2/odebug.h>
00021 #include <qpe/config.h>
00022 #include <qpe/qcopenvelope_qws.h>
00023 using namespace Opie::Core;
00024 using namespace Opie::Ui;
00025
00026
00027 #include <qvaluelist.h>
00028 #include <qtl.h>
00029 #include <qstring.h>
00030 #include <qscrollview.h>
00031 #include <qobject.h>
00032 #include <qlayout.h>
00033
00034 FortunePluginWidget::FortunePluginWidget( QWidget *parent, const char* name )
00035 : QWidget( parent, name )
00036 {
00037
00038 fortune = NULL;
00039 getFortune();
00040 }
00041
00042 FortunePluginWidget::~FortunePluginWidget() {
00043 if( fortuneProcess ){
00044 delete fortuneProcess;
00045 }
00046 }
00047
00051 void FortunePluginWidget::getFortune() {
00052
00053 QVBoxLayout* layoutFortune = new QVBoxLayout( this );
00054
00055 if ( fortune ) {
00056 delete fortune;
00057 }
00058
00059 fortune = new OTicker( this );
00060
00061
00062
00063 fortune->setText( QString("Obtaining fortune...") );
00064 layoutFortune->addWidget( fortune );
00065
00066 fortuneProcess = new OProcess();
00067 *fortuneProcess << "fortune";
00068
00069 connect(fortuneProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int) ),
00070 this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int) ) );
00071
00072 if(!fortuneProcess->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
00073 owarn << "could not start :(" << oendl;
00074 fortune->setText( QString("Failed to obtain fortune.") );
00075 delete fortuneProcess;
00076 fortuneProcess = 0;
00077 }
00078
00079 }
00080
00081 void FortunePluginWidget::slotStdOut( OProcess* , char* buf, int len )
00082 {
00083 QCString s( buf, len );
00084 s.replace( QRegExp("\n"), "" );
00085 fortune->setText( s );
00086 }