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