Diffstat (limited to 'noncore/settings/sysinfo/sysloginfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/sysloginfo.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/noncore/settings/sysinfo/sysloginfo.cpp b/noncore/settings/sysinfo/sysloginfo.cpp new file mode 100644 index 0000000..89c04e0 --- a/dev/null +++ b/noncore/settings/sysinfo/sysloginfo.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | /********************************************************************** | ||
2 | ** SyslogInfo | ||
3 | ** | ||
4 | ** Display Syslog information | ||
5 | ** | ||
6 | ** Copyright (C) 2004, Michael Lauer | ||
7 | ** mickey@tm.informatik.uni-frankfurt.de | ||
8 | ** http://www.Vanille.de | ||
9 | ** | ||
10 | ** This file may be distributed and/or modified under the terms of the | ||
11 | ** GNU General Public License version 2 as published by the Free Software | ||
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
13 | ** packaging of this file. | ||
14 | ** | ||
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | ** | ||
18 | **********************************************************************/ | ||
19 | |||
20 | #include "sysloginfo.h" | ||
21 | #include "detail.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/olistview.h> | ||
25 | #include <qpe/qpeapplication.h> | ||
26 | using namespace Opie::Ui; | ||
27 | |||
28 | /* QT */ | ||
29 | #include <qcombobox.h> | ||
30 | #include <qfile.h> | ||
31 | #include <qlayout.h> | ||
32 | #include <qmessagebox.h> | ||
33 | #include <qpushbutton.h> | ||
34 | #include <qsocketnotifier.h> | ||
35 | #include <qtextbrowser.h> | ||
36 | #include <qtimer.h> | ||
37 | #include <qwhatsthis.h> | ||
38 | #include <qtextview.h> | ||
39 | |||
40 | /* STD */ | ||
41 | #include <sys/klog.h> | ||
42 | #include <sys/types.h> | ||
43 | #include <sys/stat.h> | ||
44 | #include <fcntl.h> | ||
45 | #include <assert.h> | ||
46 | #include <unistd.h> | ||
47 | #include <string.h> | ||
48 | #include <errno.h> | ||
49 | |||
50 | #define SYSLOG_READ 2 | ||
51 | #define SYSLOG_READ_ALL 3 | ||
52 | #define SYSLOG_READ_ALL_CLEAR 4 | ||
53 | #define SYSLOG_UNREAD 9 | ||
54 | |||
55 | #undef APPEND | ||
56 | |||
57 | const unsigned int bufsize = 16384; | ||
58 | char buf[bufsize]; | ||
59 | |||
60 | SyslogInfo::SyslogInfo( QWidget* parent, const char* name, WFlags fl ) | ||
61 | : QWidget( parent, name, fl ) | ||
62 | { | ||
63 | QGridLayout *layout = new QGridLayout( this ); | ||
64 | layout->setSpacing( 4 ); | ||
65 | layout->setMargin( 4 ); | ||
66 | |||
67 | syslogview = new QTextView( this ); | ||
68 | syslogview->setTextFormat( PlainText ); | ||
69 | syslogview->setFont( QFont( "Fixed" ) ); | ||
70 | layout->addWidget( syslogview, 0, 0 ); | ||
71 | syslogview->setText( "..." ); | ||
72 | |||
73 | memset( buf, 0, bufsize ); | ||
74 | ::klogctl( SYSLOG_READ_ALL, buf, bufsize ); | ||
75 | syslogview->setText( buf ); | ||
76 | |||
77 | #ifdef APPEND | ||
78 | fd = ::open( "/proc/kmsg", O_RDONLY|O_SYNC ); | ||
79 | if ( fd == -1 ) | ||
80 | { | ||
81 | syslogview->setText( "Couldn't open /proc/kmsg: " + QString( strerror( errno ) ) ); | ||
82 | return; | ||
83 | } | ||
84 | QSocketNotifier *sn = new QSocketNotifier( fd, QSocketNotifier::Read, this ); | ||
85 | QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(updateData()) ); | ||
86 | #else | ||
87 | QPushButton* pb = new QPushButton( "&Refresh", this ); | ||
88 | layout->addWidget( pb, 1, 0 ); | ||
89 | QObject::connect( pb, SIGNAL(clicked()), this, SLOT(updateData()) ); | ||
90 | #endif | ||
91 | } | ||
92 | |||
93 | SyslogInfo::~SyslogInfo() | ||
94 | { | ||
95 | if ( fd != -1 ) ::close( fd ); | ||
96 | } | ||
97 | |||
98 | void SyslogInfo::updateData() | ||
99 | { | ||
100 | qDebug( "SyslogInfo: updateData" ); | ||
101 | #ifdef APPEND | ||
102 | memset( buf, 0, bufsize ); | ||
103 | int num = ::read( fd, buf, bufsize ); | ||
104 | if ( num ) // -1 = error (permission denied) | ||
105 | { | ||
106 | syslogview->append( "\n" ); | ||
107 | syslogview->append( buf ); | ||
108 | qDebug( "SyslogInfo: adding '%s'", buf ); | ||
109 | } | ||
110 | #else | ||
111 | memset( buf, 0, bufsize ); | ||
112 | ::klogctl( SYSLOG_READ_ALL, buf, bufsize ); | ||
113 | syslogview->setText( buf ); | ||
114 | syslogview->ensureVisible( 0, syslogview->contentsHeight() ); | ||
115 | #endif | ||
116 | } | ||