Diffstat (limited to 'noncore/todayplugins/fortune/fortunepluginwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/todayplugins/fortune/fortunepluginwidget.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/noncore/todayplugins/fortune/fortunepluginwidget.cpp b/noncore/todayplugins/fortune/fortunepluginwidget.cpp new file mode 100644 index 0000000..583bf0b --- a/dev/null +++ b/noncore/todayplugins/fortune/fortunepluginwidget.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * fortunepluginwidget.cpp | ||
3 | * | ||
4 | * copyright : (c) 2002 by Maximilian Reiß | ||
5 | * email : harlekin@handhelds.org | ||
6 | * | ||
7 | */ | ||
8 | /*************************************************************************** | ||
9 | * * | ||
10 | * This program is free software; you can redistribute it and/or modify * | ||
11 | * it under the terms of the GNU General Public License as published by * | ||
12 | * the Free Software Foundation; either version 2 of the License, or * | ||
13 | * (at your option) any later version. * | ||
14 | * * | ||
15 | ***************************************************************************/ | ||
16 | |||
17 | #include "fortunepluginwidget.h" | ||
18 | |||
19 | #include <qvaluelist.h> | ||
20 | #include <qtl.h> | ||
21 | #include <qstring.h> | ||
22 | #include <qscrollview.h> | ||
23 | #include <qobject.h> | ||
24 | #include <qlayout.h> | ||
25 | |||
26 | #include <qpe/config.h> | ||
27 | #include <qpe/qcopenvelope_qws.h> | ||
28 | |||
29 | #include <opie/oprocess.h> | ||
30 | #include <opie/oticker.h> | ||
31 | |||
32 | FortunePluginWidget::FortunePluginWidget( QWidget *parent, const char* name ) | ||
33 | : QWidget( parent, name ) | ||
34 | { | ||
35 | |||
36 | fortune = NULL; | ||
37 | getFortune(); | ||
38 | } | ||
39 | |||
40 | FortunePluginWidget::~FortunePluginWidget() { | ||
41 | if( fortuneProcess ){ | ||
42 | delete fortuneProcess; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Get the fortunes | ||
48 | */ | ||
49 | void FortunePluginWidget::getFortune() { | ||
50 | |||
51 | QVBoxLayout* layoutFortune = new QVBoxLayout( this ); | ||
52 | |||
53 | if ( fortune ) { | ||
54 | delete fortune; | ||
55 | } | ||
56 | |||
57 | fortune = new OTicker( this ); | ||
58 | //fortune->setReadOnly( TRUE ); | ||
59 | //fortune->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); | ||
60 | |||
61 | fortune->setText( QString("Obtaining fortune...") ); | ||
62 | layoutFortune->addWidget( fortune ); | ||
63 | |||
64 | fortuneProcess = new OProcess(); | ||
65 | *fortuneProcess << "fortune"; | ||
66 | |||
67 | connect(fortuneProcess, SIGNAL(receivedStdout(OProcess*, char*, int ) ), | ||
68 | this, SLOT(slotStdOut(OProcess*, char*, int) ) ); | ||
69 | |||
70 | if(!fortuneProcess->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | ||
71 | qWarning("could not start :("); | ||
72 | fortune->setText( QString("Failed to obtain fortune.") ); | ||
73 | delete fortuneProcess; | ||
74 | fortuneProcess = 0; | ||
75 | } | ||
76 | |||
77 | } | ||
78 | |||
79 | void FortunePluginWidget::slotStdOut( OProcess* proc, char* buf, int len ) | ||
80 | { | ||
81 | QCString cstring( buf, len ); | ||
82 | fortune->setText( cstring ); | ||
83 | } | ||