00001
00002
00003 #include <qvbox.h>
00004 #include <qhbox.h>
00005 #include <qvbuttongroup.h>
00006 #include <qhbuttongroup.h>
00007 #include <qlineedit.h>
00008 #include <qradiobutton.h>
00009 #include <qpushbutton.h>
00010
00011
00012
00013 #include <qpe/config.h>
00014
00015 #include <opie2/odebug.h>
00016 #include <opie2/oapplication.h>
00017 #include <opie2/oglobal.h>
00018 #include <opie2/oglobalsettings.h>
00019
00020 using namespace Opie::Core;
00021
00022 class DemoApp : public OApplication
00023 {
00024 Q_OBJECT
00025 public:
00026 DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2 debug demo" )
00027 {
00028
00029 odebug << "Process-wide OApplication object @ " << oApp << "" << oendl;
00030
00031
00032 int mode = OGlobalSettings::debugMode();
00033
00034 QVBox* vbox = new QVBox();
00035 setMainWidget( vbox );
00036
00037 g = new QVButtonGroup( "Output Strategy", vbox );
00038 QRadioButton* r0 = new QRadioButton( "file", g );
00039 QRadioButton* r1 = new QRadioButton( "messagebox", g );
00040 QRadioButton* r2 = new QRadioButton( "stderr", g );
00041 QRadioButton* r3 = new QRadioButton( "syslog", g );
00042 QRadioButton* r4 = new QRadioButton( "socket", g );
00043 g->insert( r0, 0 );
00044 g->insert( r1, 1 );
00045 g->insert( r2, 2 );
00046 g->insert( r3, 3 );
00047 g->insert( r4, 4 );
00048 g->setRadioButtonExclusive( true );
00049 connect( g, SIGNAL( clicked(int) ), this, SLOT( chooseMethod(int) ) );
00050
00051 if ( mode != -1 ) g->setButton( mode );
00052
00053 QHButtonGroup* hbox = new QHButtonGroup( "Extra Output Information", vbox );
00054 e = new QLineEdit( hbox );
00055 QPushButton* pb = new QPushButton( hbox );
00056
00057 connect( e, SIGNAL( returnPressed() ), this, SLOT( updateDebugOutput() ) );
00058 connect( pb, SIGNAL( clicked() ), this, SLOT( updateDebugOutput() ) );
00059
00060
00061 e->setText( OGlobalSettings::debugOutput() );
00062
00063
00064 QPushButton* info = new QPushButton( "Emit Debug(Info) Output!", vbox );
00065 connect( info, SIGNAL( clicked() ), this, SLOT( emitInfoOutput() ) );
00066 QPushButton* warn = new QPushButton( "Emit a Warning Output!", vbox );
00067 connect( warn, SIGNAL( clicked() ), this, SLOT( emitWarningOutput() ) );
00068 QPushButton* error = new QPushButton( "Emit an Error Output!", vbox );
00069 connect( error, SIGNAL( clicked() ), this, SLOT( emitErrorOutput() ) );
00070 QPushButton* fatal = new QPushButton( "Emit a Fatal Output!", vbox );
00071 connect( fatal, SIGNAL( clicked() ), this, SLOT( emitFatalOutput() ) );
00072
00073 QPushButton* tb = new QPushButton( "Emit a Fatal Backtrace!", vbox );
00074 connect( tb, SIGNAL( clicked() ), this, SLOT( emitTBOutput() ) );
00075
00076 info->show();
00077 warn->show();
00078 error->show();
00079 fatal->show();
00080 tb->show();
00081 g->show();
00082 hbox->show();
00083 e->show();
00084 vbox->show();
00085 showMainWidget( vbox );
00086 }
00087
00088 public slots:
00089 void chooseMethod(int method)
00090 {
00091 m = method;
00092 odebug << "choosing method: " << method << "" << oendl;
00093 OConfig* g = OGlobal::config();
00094 g->setGroup( "General" );
00095 g->writeEntry( "debugMode", m );
00096 e->setText( OGlobalSettings::debugOutput() );
00097 g->write();
00098 }
00099 void updateDebugOutput()
00100 {
00101 OConfig* g = OGlobal::config();
00102 g->setGroup( "General" );
00103 g->writeEntry( "debugOutput"+QString::number(OGlobalSettings::debugMode()), e->text() );
00104 g->write();
00105 }
00106 void emitInfoOutput()
00107 {
00108 odebug << "This is a debug message" << oendl;
00109 }
00110 void emitWarningOutput()
00111 {
00112 owarn << "This is a warning message" << oendl;
00113 }
00114 void emitErrorOutput()
00115 {
00116 oerr << "This is an errror message" << oendl;
00117 }
00118 void emitFatalOutput()
00119 {
00120 ofatal << "This is a fatal message" << oendl;
00121 }
00122 void emitTBOutput()
00123 {
00124 ofatal << "This is a fatal message + backtrace\n" + odBacktrace();
00125 }
00126
00127 private:
00128 QButtonGroup* g;
00129 int m;
00130 QLineEdit* e;
00131 };
00132
00133 int main( int argc, char** argv )
00134 {
00135 DemoApp* app = new DemoApp( argc, argv );
00136 app->exec();
00137
00138 return 0;
00139
00140 }
00141
00142 #include "odebugdemo.moc"