summaryrefslogtreecommitdiff
path: root/examples/opiecore/odebugdemo/odebugdemo.cpp
Unidiff
Diffstat (limited to 'examples/opiecore/odebugdemo/odebugdemo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/odebugdemo/odebugdemo.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/examples/opiecore/odebugdemo/odebugdemo.cpp b/examples/opiecore/odebugdemo/odebugdemo.cpp
new file mode 100644
index 0000000..b046d28
--- a/dev/null
+++ b/examples/opiecore/odebugdemo/odebugdemo.cpp
@@ -0,0 +1,142 @@
1/* QT */
2
3#include <qvbox.h>
4#include <qhbox.h>
5#include <qvbuttongroup.h>
6#include <qhbuttongroup.h>
7#include <qlineedit.h>
8#include <qradiobutton.h>
9#include <qpushbutton.h>
10
11/* OPIE */
12
13#include <qpe/config.h>
14
15#include <opie2/odebug.h>
16#include <opie2/oapplication.h>
17#include <opie2/oglobal.h>
18#include <opie2/oglobalsettings.h>
19
20using namespace Opie::Core;
21
22class DemoApp : public OApplication
23{
24Q_OBJECT
25public:
26 DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2 debug demo" )
27 {
28 // you have access to your OApplication object via oApp
29 odebug << "Process-wide OApplication object @ " << oApp << "" << oendl;
30
31 // you have access to global settings via OGlobalSettings
32 int mode = OGlobalSettings::debugMode();
33
34 QVBox* vbox = new QVBox();
35 setMainWidget( vbox );
36
37 g = new QVButtonGroup( "Output Strategy", vbox );
38 QRadioButton* r0 = new QRadioButton( "file", g );
39 QRadioButton* r1 = new QRadioButton( "messagebox", g );
40 QRadioButton* r2 = new QRadioButton( "stderr", g );
41 QRadioButton* r3 = new QRadioButton( "syslog", g );
42 QRadioButton* r4 = new QRadioButton( "socket", g );
43 g->insert( r0, 0 );
44 g->insert( r1, 1 );
45 g->insert( r2, 2 );
46 g->insert( r3, 3 );
47 g->insert( r4, 4 );
48 g->setRadioButtonExclusive( true );
49 connect( g, SIGNAL( clicked(int) ), this, SLOT( chooseMethod(int) ) );
50
51 if ( mode != -1 ) g->setButton( mode );
52
53 QHButtonGroup* hbox = new QHButtonGroup( "Extra Output Information", vbox );
54 e = new QLineEdit( hbox );
55 QPushButton* pb = new QPushButton( hbox );
56
57 connect( e, SIGNAL( returnPressed() ), this, SLOT( updateDebugOutput() ) );
58 connect( pb, SIGNAL( clicked() ), this, SLOT( updateDebugOutput() ) );
59
60 // show the additional debug mode dependent output information
61 e->setText( OGlobalSettings::debugOutput() );
62
63 // buttos
64 QPushButton* info = new QPushButton( "Emit Debug(Info) Output!", vbox );
65 connect( info, SIGNAL( clicked() ), this, SLOT( emitInfoOutput() ) );
66 QPushButton* warn = new QPushButton( "Emit a Warning Output!", vbox );
67 connect( warn, SIGNAL( clicked() ), this, SLOT( emitWarningOutput() ) );
68 QPushButton* error = new QPushButton( "Emit an Error Output!", vbox );
69 connect( error, SIGNAL( clicked() ), this, SLOT( emitErrorOutput() ) );
70 QPushButton* fatal = new QPushButton( "Emit a Fatal Output!", vbox );
71 connect( fatal, SIGNAL( clicked() ), this, SLOT( emitFatalOutput() ) );
72
73 QPushButton* tb = new QPushButton( "Emit a Fatal Backtrace!", vbox );
74 connect( tb, SIGNAL( clicked() ), this, SLOT( emitTBOutput() ) );
75
76 info->show();
77 warn->show();
78 error->show();
79 fatal->show();
80 tb->show();
81 g->show();
82 hbox->show();
83 e->show();
84 vbox->show();
85 showMainWidget( vbox );
86 }
87
88public slots:
89 void chooseMethod(int method)
90 {
91 m = method;
92 odebug << "choosing method: " << method << "" << oendl;
93 OConfig* g = OGlobal::config();
94 g->setGroup( "General" );
95 g->writeEntry( "debugMode", m );
96 e->setText( OGlobalSettings::debugOutput() );
97 g->write();
98 }
99 void updateDebugOutput()
100 {
101 OConfig* g = OGlobal::config();
102 g->setGroup( "General" );
103 g->writeEntry( "debugOutput"+QString::number(OGlobalSettings::debugMode()), e->text() );
104 g->write();
105 }
106 void emitInfoOutput()
107 {
108 odebug << "This is a debug message" << oendl;
109 }
110 void emitWarningOutput()
111 {
112 owarn << "This is a warning message" << oendl;
113 }
114 void emitErrorOutput()
115 {
116 oerr << "This is an errror message" << oendl;
117 }
118 void emitFatalOutput()
119 {
120 ofatal << "This is a fatal message" << oendl;
121 }
122 void emitTBOutput()
123 {
124 ofatal << "This is a fatal message + backtrace\n" + odBacktrace(); // odBacktrace includes \n
125 }
126
127private:
128 QButtonGroup* g;
129 int m;
130 QLineEdit* e;
131};
132
133int main( int argc, char** argv )
134{
135 DemoApp* app = new DemoApp( argc, argv );
136 app->exec();
137
138 return 0;
139
140}
141
142#include "odebugdemo.moc"