00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "sysloginfo.h"
00019 #include "detail.h"
00020
00021
00022 #include <opie2/olistview.h>
00023 #include <opie2/oconfig.h>
00024 using namespace Opie::Core;
00025 using namespace Opie::Ui;
00026
00027
00028 #include <qcombobox.h>
00029 #include <qfile.h>
00030 #include <qlayout.h>
00031 #include <qmessagebox.h>
00032 #include <qpushbutton.h>
00033 #include <qsocketnotifier.h>
00034 #include <qtextbrowser.h>
00035 #include <qtimer.h>
00036 #include <qwhatsthis.h>
00037 #include <qtextview.h>
00038
00039
00040 #include <sys/klog.h>
00041 #include <sys/types.h>
00042 #include <sys/stat.h>
00043 #include <fcntl.h>
00044 #include <assert.h>
00045 #include <unistd.h>
00046 #include <string.h>
00047 #include <errno.h>
00048
00049 #define SYSLOG_READ 2
00050 #define SYSLOG_READ_ALL 3
00051 #define SYSLOG_READ_ALL_CLEAR 4
00052 #define SYSLOG_UNREAD 9
00053
00054 #undef APPEND
00055
00056 const unsigned int bufsize = 16384;
00057 char buf[bufsize];
00058
00059 SyslogInfo::SyslogInfo( QWidget* parent, const char* name, WFlags fl )
00060 : QWidget( parent, name, fl )
00061 {
00062 QGridLayout *layout = new QGridLayout( this );
00063 layout->setSpacing( 2 );
00064 layout->setMargin( 0 );
00065
00066 syslogview = new QTextView( this );
00067 syslogview->setTextFormat( PlainText );
00068 OConfig cfg( "qpe" );
00069 cfg.setGroup( "Appearance" );
00070 syslogview->setFont( QFont( cfg.readEntry( "FixedFontFamily", "Fixed" ), cfg.readNumEntry( "FixedFontSize", 10 ) ) );
00071 layout->addWidget( syslogview, 0, 0 );
00072 syslogview->setText( "..." );
00073
00074 memset( buf, 0, bufsize );
00075 ::klogctl( SYSLOG_READ_ALL, buf, bufsize );
00076 syslogview->setText( buf );
00077
00078 #ifdef APPEND
00079 fd = ::open( "/proc/kmsg", O_RDONLY|O_SYNC );
00080 if ( fd == -1 )
00081 {
00082 syslogview->setText( "Couldn't open /proc/kmsg: " + QString( strerror( errno ) ) );
00083 return;
00084 }
00085 QSocketNotifier *sn = new QSocketNotifier( fd, QSocketNotifier::Read, this );
00086 QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(updateData()) );
00087 #else
00088 QPushButton* pb = new QPushButton( "&Refresh", this );
00089 layout->addWidget( pb, 1, 0 );
00090 QObject::connect( pb, SIGNAL(clicked()), this, SLOT(updateData()) );
00091 #endif
00092 }
00093
00094 SyslogInfo::~SyslogInfo()
00095 {
00096 if ( fd != -1 ) ::close( fd );
00097 }
00098
00099 void SyslogInfo::updateData()
00100 {
00101 qDebug( "SyslogInfo: updateData" );
00102 #ifdef APPEND
00103 memset( buf, 0, bufsize );
00104 int num = ::read( fd, buf, bufsize );
00105 if ( num )
00106 {
00107 syslogview->append( "\n" );
00108 syslogview->append( buf );
00109 qDebug( "SyslogInfo: adding '%s'", buf );
00110 }
00111 #else
00112 memset( buf, 0, bufsize );
00113 ::klogctl( SYSLOG_READ_ALL, buf, bufsize );
00114 syslogview->setText( buf );
00115 syslogview->ensureVisible( 0, syslogview->contentsHeight() );
00116 #endif
00117 }