Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

sysloginfo.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** SyslogInfo
00003 **
00004 ** Display Syslog information
00005 **
00006 ** Copyright (C) 2004-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
00007 **
00008 ** This file may be distributed and/or modified under the terms of the
00009 ** GNU General Public License version 2 as published by the Free Software
00010 ** Foundation and appearing in the file LICENSE.GPL included in the
00011 ** packaging of this file.
00012 **
00013 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00014 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00015 **
00016 **********************************************************************/
00017 
00018 #include "sysloginfo.h"
00019 #include "detail.h"
00020 
00021 /* OPIE */
00022 #include <opie2/olistview.h>
00023 #include <opie2/oconfig.h>
00024 using namespace Opie::Core;
00025 using namespace Opie::Ui;
00026 
00027 /* QT */
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 /* STD */
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 ) // -1 = error (permission denied)
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 }

Generated on Sat Nov 5 16:17:58 2005 for OPIE by  doxygen 1.4.2