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

fortunepluginwidget.cpp

Go to the documentation of this file.
00001 /*
00002  * fortunepluginwidget.cpp
00003  *
00004  * copyright   : (c) 2002 by Maximilian Reiß
00005  * email       : harlekin@handhelds.org
00006  *
00007  */
00008 /***************************************************************************
00009  *   *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.     *
00014  *   *
00015  ***************************************************************************/
00016 
00017 #include "fortunepluginwidget.h"
00018 
00019 /* OPIE */
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 /* QT */
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 //      fortune->setReadOnly( TRUE );
00061 //      fortune->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
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* /*proc*/, char* buf, int len )
00082 {
00083         QCString s( buf, len );
00084         s.replace( QRegExp("\n"), "" );
00085         fortune->setText( s );
00086 }

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