4
* Copyright (c) 2000 Alexander Neundorf <neundorf@kde.org>
6
* Requires the Qt widget libraries, available at no cost at
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include <QApplication>
28
#include <kmessagebox.h>
32
#include "kcmsambalog.h"
33
#include "kcmsambalog.moc"
35
#define LOG_SCREEN_XY_OFFSET 10
37
LogView::LogView(QWidget *parent, KConfig *config) :
38
QWidget(parent), configFile(config), filesCount(0), connectionsCount(0), logFileName(KUrl::fromPath("/var/log/samba.log"), this), label(i18n("Samba log file: "), this), viewHistory(this), showConnOpen(i18n("Show opened connections"), this), showConnClose(i18n("Show closed connections"), this),
39
showFileOpen(i18n("Show opened files"), this), showFileClose(i18n("Show closed files"), this), updateButton(i18n("&Update"), this) {
40
label.setBuddy( &logFileName);
41
QVBoxLayout *mainLayout=new QVBoxLayout(this);
42
mainLayout->setMargin(KDialog::marginHint());
43
mainLayout->setSpacing(KDialog::spacingHint());
44
QHBoxLayout *leLayout=new QHBoxLayout();
45
mainLayout->addItem(leLayout);
46
leLayout->addWidget(&label);
47
leLayout->addWidget(&logFileName, 1);
48
mainLayout->addWidget(&viewHistory, 1);
49
QGridLayout *subLayout=new QGridLayout();
50
mainLayout->addItem(subLayout);
51
subLayout->addWidget(&showConnOpen, 0, 0);
52
subLayout->addWidget(&showConnClose, 1, 0);
53
subLayout->addWidget(&showFileOpen, 0, 1);
54
subLayout->addWidget(&showFileClose, 1, 1);
55
mainLayout->addWidget(&updateButton, 0, Qt::AlignLeft);
57
logFileName.setWhatsThis(i18n("This page presents the contents of"
58
" your samba log file in a friendly layout. Check that the correct log"
59
" file for your computer is listed here. If you need to, correct the name"
60
" or location of the log file, and then click the \"Update\" button.") );
62
showConnOpen.setWhatsThis(i18n("Check this option if you want to"
63
" view the details for connections opened to your computer.") );
65
showConnClose.setWhatsThis(i18n("Check this option if you want to"
66
" view the events when connections to your computer were closed.") );
68
showFileOpen.setWhatsThis(i18n("Check this option if you want to"
69
" see the files which were opened on your computer by remote users."
70
" Note that file open/close events are not logged unless the samba"
71
" log level is set to at least 2 (you cannot set the log level"
72
" using this module).") );
74
showFileClose.setWhatsThis(i18n("Check this option if you want to"
75
" see the events when files opened by remote users were closed."
76
" Note that file open/close events are not logged unless the samba"
77
" log level is set to at least 2 (you cannot set the log level"
78
" using this module).") );
80
updateButton.setWhatsThis(i18n("Click here to refresh the information"
81
" on this page. The log file (shown above) will be read to obtain the"
82
" events logged by samba.") );
84
viewHistory.setAllColumnsShowFocus(true);
85
viewHistory.setFocusPolicy(Qt::ClickFocus);
86
viewHistory.setShowSortIndicator(true);
88
viewHistory.addColumn(i18n("Date & Time"), 130);
89
viewHistory.addColumn(i18n("Event"), 150);
90
viewHistory.addColumn(i18n("Service/File"), 210);
91
viewHistory.addColumn(i18n("Host/User"), 150);
93
viewHistory.setWhatsThis(i18n("<p>This list shows details of the events"
94
" logged by samba. Note that events at the file level are not logged"
95
" unless you have configured the log level for samba to 2 or greater.</p><p>"
96
" As with many other lists in KDE, you can click on a column heading"
97
" to sort on that column. Click again to change the sorting direction"
98
" from ascending to descending or vice versa.</p><p>"
99
" If the list is empty, try clicking the \"Update\" button. The samba"
100
" log file will be read and the list refreshed.</p>") );
102
showConnOpen.setChecked(true);
103
showConnClose.setChecked(true);
104
showFileOpen.setChecked(false);
105
showFileClose.setChecked(false);
107
connect(&updateButton, SIGNAL(clicked()), this, SLOT(updateList()));
108
emit contentsChanged(&viewHistory, 0, 0);
110
label.setMinimumSize(label.sizeHint());
111
logFileName.setMinimumSize(250, logFileName.sizeHint().height());
112
viewHistory.setMinimumSize(425, 200);
113
showConnOpen.setMinimumSize(showConnOpen.sizeHint());
114
showConnClose.setMinimumSize(showConnClose.sizeHint());
115
showFileOpen.setMinimumSize(showFileOpen.sizeHint());
116
showFileClose.setMinimumSize(showFileClose.sizeHint());
117
updateButton.setFixedSize(updateButton.sizeHint());
120
void LogView::loadSettings() {
123
KConfigGroup group = configFile->group(LOGGROUPNAME);
124
logFileName.setPath(group.readPathEntry("SambaLogFile", "/var/log/samba.log"));
126
showConnOpen.setChecked(group.readEntry("ShowConnectionOpen", true));
127
showConnClose.setChecked(group.readEntry("ShowConnectionClose", false));
128
showFileOpen.setChecked(group.readEntry("ShowFileOpen", true));
129
showFileClose.setChecked(group.readEntry("ShowFileClose", false));
132
void LogView::saveSettings() {
135
KConfigGroup group = configFile->group(LOGGROUPNAME);
136
group.writePathEntry("SambaLogFile", logFileName.url().path());
138
group.writeEntry("ShowConnectionOpen", showConnOpen.isChecked());
139
group.writeEntry("ShowConnectionClose", showConnClose.isChecked());
140
group.writeEntry("ShowFileOpen", showFileOpen.isChecked());
141
group.writeEntry("ShowFileClose", showFileClose.isChecked());
144
#define CONN_OPEN " connect to service "
145
#define CONN_CLOSE " closed connection to service "
146
#define FILE_OPEN " opened file "
147
#define FILE_CLOSE " closed file "
149
//caution ! high optimized code :-)
150
void LogView::updateList() {
151
QFile logFile(logFileName.url().path());
152
if (logFile.open(QIODevice::ReadOnly)) {
153
QApplication::setOverrideCursor(Qt::WaitCursor);
158
int connOpenLen(strlen(CONN_OPEN));
159
int connCloseLen(strlen(CONN_CLOSE));
160
int fileOpenLen(strlen(FILE_OPEN));
161
int fileCloseLen(strlen(FILE_CLOSE));
164
char *c1, *c2, *c3, *c4, *c, time[25];
167
while (!logFile.atEnd()) {
168
logFile.readLine(buf, sizeof(buf));
174
strncpy(time, buf+1, sizeof(time));
175
time[sizeof(time)-1] = '\0';
184
if (showConnOpen.isChecked())
185
c1=strstr(buf, CONN_OPEN);
187
if (showConnClose.isChecked())
188
c2=strstr(buf, CONN_CLOSE);
190
if (showFileOpen.isChecked())
191
c3=strstr(buf, FILE_OPEN);
193
if (showFileClose.isChecked())
194
c4=strstr(buf, FILE_CLOSE);
201
c=strstr(buf, " as user");
204
new QListViewItemX(&viewHistory,time,I18N_NOOP("CONNECTION OPENED"),c1+connOpenLen,buf+2);
208
new QListViewItemX(&viewHistory,time,I18N_NOOP("CONNECTION CLOSED"),c2+connCloseLen,buf+2);
210
c=strstr(buf, " read=");
213
new QListViewItemX(&viewHistory,time,I18N_NOOP(" FILE OPENED"),c3+fileOpenLen,buf+2);
216
c=strstr(buf, " (numopen=");
219
new QListViewItemX(&viewHistory,time,I18N_NOOP(" FILE CLOSED"),c4+fileCloseLen,buf+2);
224
emit contentsChanged(&viewHistory, filesCount, connectionsCount);
225
QApplication::restoreOverrideCursor();
227
QString tmp = i18n("Could not open file %1", logFileName.url().path());
228
KMessageBox::error(this, tmp);