You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
7.6 KiB
286 lines
7.6 KiB
15 years ago
|
/*
|
||
|
KSysGuard, the KDE System Guard
|
||
|
|
||
|
Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of version 2 of the GNU General Public
|
||
|
License as published by the Free Software Foundation.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <sys/types.h>
|
||
|
|
||
14 years ago
|
#include <tqpushbutton.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqfile.h>
|
||
|
#include <tqlistbox.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdefontdialog.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kcolorbutton.h>
|
||
|
|
||
|
#include <ksgrd/StyleEngine.h>
|
||
|
|
||
|
#include "LogFile.moc"
|
||
|
|
||
14 years ago
|
LogFile::LogFile(TQWidget *parent, const char *name, const TQString& title)
|
||
15 years ago
|
: KSGRD::SensorDisplay(parent, name, title)
|
||
|
{
|
||
14 years ago
|
monitor = new TQListBox(this);
|
||
13 years ago
|
TQ_CHECK_PTR(monitor);
|
||
15 years ago
|
|
||
|
setMinimumSize(50, 25);
|
||
|
|
||
|
setPlotterWidget(monitor);
|
||
|
|
||
|
setModified(false);
|
||
|
}
|
||
|
|
||
|
LogFile::~LogFile(void)
|
||
|
{
|
||
13 years ago
|
sendRequest(sensors().at(0)->hostName(), TQString("logfile_unregister %1" ).arg(logFileID), 43);
|
||
15 years ago
|
}
|
||
|
|
||
|
bool
|
||
14 years ago
|
LogFile::addSensor(const TQString& hostName, const TQString& sensorName, const TQString& sensorType, const TQString& title)
|
||
15 years ago
|
{
|
||
|
if (sensorType != "logfile")
|
||
|
return (false);
|
||
|
|
||
|
registerSensor(new KSGRD::SensorProperties(hostName, sensorName, sensorType, title));
|
||
|
|
||
13 years ago
|
TQString sensorID = sensorName.right(sensorName.length() - (sensorName.findRev("/") + 1));
|
||
15 years ago
|
|
||
13 years ago
|
sendRequest(sensors().at(0)->hostName(), TQString("logfile_register %1" ).arg(sensorID), 42);
|
||
15 years ago
|
|
||
|
if (title.isEmpty())
|
||
13 years ago
|
setTitle(sensors().at(0)->hostName() + ":" + sensorID);
|
||
15 years ago
|
else
|
||
|
setTitle(title);
|
||
|
|
||
|
setModified(true);
|
||
|
|
||
|
return (true);
|
||
|
}
|
||
|
|
||
|
|
||
|
void LogFile::configureSettings(void)
|
||
|
{
|
||
13 years ago
|
TQColorGroup cgroup = monitor->colorGroup();
|
||
15 years ago
|
|
||
|
lfs = new LogFileSettings(this);
|
||
13 years ago
|
TQ_CHECK_PTR(lfs);
|
||
15 years ago
|
|
||
|
lfs->fgColor->setColor(cgroup.text());
|
||
|
lfs->fgColor->setText(i18n("Foreground color:"));
|
||
|
lfs->bgColor->setColor(cgroup.base());
|
||
|
lfs->bgColor->setText(i18n("Background color:"));
|
||
|
lfs->fontButton->setFont(monitor->font());
|
||
|
lfs->ruleList->insertStringList(filterRules);
|
||
|
lfs->title->setText(title());
|
||
|
|
||
14 years ago
|
connect(lfs->okButton, TQT_SIGNAL(clicked()), lfs, TQT_SLOT(accept()));
|
||
|
connect(lfs->applyButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(applySettings()));
|
||
|
connect(lfs->cancelButton, TQT_SIGNAL(clicked()), lfs, TQT_SLOT(reject()));
|
||
15 years ago
|
|
||
14 years ago
|
connect(lfs->fontButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(settingsFontSelection()));
|
||
|
connect(lfs->addButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(settingsAddRule()));
|
||
|
connect(lfs->deleteButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(settingsDeleteRule()));
|
||
|
connect(lfs->changeButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(settingsChangeRule()));
|
||
|
connect(lfs->ruleList, TQT_SIGNAL(selected(int)), this, TQT_SLOT(settingsRuleListSelected(int)));
|
||
|
connect(lfs->ruleText, TQT_SIGNAL(returnPressed()), this, TQT_SLOT(settingsAddRule()));
|
||
15 years ago
|
|
||
|
if (lfs->exec()) {
|
||
|
applySettings();
|
||
|
}
|
||
|
|
||
|
delete lfs;
|
||
|
lfs = 0;
|
||
|
}
|
||
|
|
||
|
void LogFile::settingsFontSelection()
|
||
|
{
|
||
14 years ago
|
TQFont tmpFont = lfs->fontButton->font();
|
||
15 years ago
|
|
||
12 years ago
|
if (TDEFontDialog::getFont(tmpFont) == TDEFontDialog::Accepted) {
|
||
15 years ago
|
lfs->fontButton->setFont(tmpFont);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void LogFile::settingsAddRule()
|
||
|
{
|
||
|
if (!lfs->ruleText->text().isEmpty()) {
|
||
|
lfs->ruleList->insertItem(lfs->ruleText->text(), -1);
|
||
|
lfs->ruleText->setText("");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void LogFile::settingsDeleteRule()
|
||
|
{
|
||
|
lfs->ruleList->removeItem(lfs->ruleList->currentItem());
|
||
|
lfs->ruleText->setText("");
|
||
|
}
|
||
|
|
||
|
void LogFile::settingsChangeRule()
|
||
|
{
|
||
|
lfs->ruleList->changeItem(lfs->ruleText->text(), lfs->ruleList->currentItem());
|
||
|
lfs->ruleText->setText("");
|
||
|
}
|
||
|
|
||
|
void LogFile::settingsRuleListSelected(int index)
|
||
|
{
|
||
|
lfs->ruleText->setText(lfs->ruleList->text(index));
|
||
|
}
|
||
|
|
||
|
void LogFile::applySettings(void)
|
||
|
{
|
||
13 years ago
|
TQColorGroup cgroup = monitor->colorGroup();
|
||
15 years ago
|
|
||
14 years ago
|
cgroup.setColor(TQColorGroup::Text, lfs->fgColor->color());
|
||
|
cgroup.setColor(TQColorGroup::Base, lfs->bgColor->color());
|
||
|
monitor->setPalette(TQPalette(cgroup, cgroup, cgroup));
|
||
15 years ago
|
monitor->setFont(lfs->fontButton->font());
|
||
|
|
||
|
filterRules.clear();
|
||
|
for (uint i = 0; i < lfs->ruleList->count(); i++)
|
||
|
filterRules.append(lfs->ruleList->text(i));
|
||
|
|
||
|
setTitle(lfs->title->text());
|
||
|
|
||
|
setModified(true);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
LogFile::applyStyle()
|
||
|
{
|
||
13 years ago
|
TQColorGroup cgroup = monitor->colorGroup();
|
||
15 years ago
|
|
||
14 years ago
|
cgroup.setColor(TQColorGroup::Text, KSGRD::Style->firstForegroundColor());
|
||
|
cgroup.setColor(TQColorGroup::Base, KSGRD::Style->backgroundColor());
|
||
|
monitor->setPalette(TQPalette(cgroup, cgroup, cgroup));
|
||
15 years ago
|
|
||
|
setModified(true);
|
||
|
}
|
||
|
|
||
|
bool
|
||
14 years ago
|
LogFile::restoreSettings(TQDomElement& element)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQFont font;
|
||
13 years ago
|
TQColorGroup cgroup = monitor->colorGroup();
|
||
15 years ago
|
|
||
14 years ago
|
cgroup.setColor(TQColorGroup::Text, restoreColor(element, "textColor", Qt::green));
|
||
|
cgroup.setColor(TQColorGroup::Base, restoreColor(element, "backgroundColor", Qt::black));
|
||
|
monitor->setPalette(TQPalette(cgroup, cgroup, cgroup));
|
||
15 years ago
|
|
||
|
addSensor(element.attribute("hostName"), element.attribute("sensorName"), (element.attribute("sensorType").isEmpty() ? "logfile" : element.attribute("sensorType")), element.attribute("title"));
|
||
|
|
||
|
font.fromString( element.attribute( "font" ) );
|
||
|
monitor->setFont(font);
|
||
|
|
||
14 years ago
|
TQDomNodeList dnList = element.elementsByTagName("filter");
|
||
15 years ago
|
for (uint i = 0; i < dnList.count(); i++) {
|
||
14 years ago
|
TQDomElement element = dnList.item(i).toElement();
|
||
15 years ago
|
filterRules.append(element.attribute("rule"));
|
||
|
}
|
||
|
|
||
|
SensorDisplay::restoreSettings(element);
|
||
|
|
||
|
setModified(false);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool
|
||
14 years ago
|
LogFile::saveSettings(TQDomDocument& doc, TQDomElement& element, bool save)
|
||
15 years ago
|
{
|
||
13 years ago
|
element.setAttribute("hostName", sensors().at(0)->hostName());
|
||
|
element.setAttribute("sensorName", sensors().at(0)->name());
|
||
|
element.setAttribute("sensorType", sensors().at(0)->type());
|
||
15 years ago
|
|
||
|
element.setAttribute("font", monitor->font().toString());
|
||
|
|
||
13 years ago
|
saveColor(element, "textColor", monitor->colorGroup().text());
|
||
|
saveColor(element, "backgroundColor", monitor->colorGroup().base());
|
||
15 years ago
|
|
||
14 years ago
|
for (TQStringList::Iterator it = filterRules.begin();
|
||
15 years ago
|
it != filterRules.end(); it++)
|
||
|
{
|
||
14 years ago
|
TQDomElement filter = doc.createElement("filter");
|
||
15 years ago
|
filter.setAttribute("rule", (*it));
|
||
|
element.appendChild(filter);
|
||
|
}
|
||
|
|
||
|
SensorDisplay::saveSettings(doc, element);
|
||
|
|
||
|
if (save)
|
||
|
setModified(false);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
LogFile::updateMonitor()
|
||
|
{
|
||
13 years ago
|
sendRequest(sensors().at(0)->hostName(),
|
||
|
TQString("%1 %2" ).arg(sensors().at(0)->name()).arg(logFileID), 19);
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
LogFile::answerReceived(int id, const TQString& answer)
|
||
15 years ago
|
{
|
||
|
/* We received something, so the sensor is probably ok. */
|
||
|
sensorError(id, false);
|
||
|
|
||
|
switch (id)
|
||
|
{
|
||
|
case 19: {
|
||
|
KSGRD::SensorTokenizer lines(answer, '\n');
|
||
|
|
||
|
for (uint i = 0; i < lines.count(); i++) {
|
||
|
if (monitor->count() == MAXLINES)
|
||
|
monitor->removeItem(0);
|
||
|
|
||
|
monitor->insertItem(lines[i], -1);
|
||
|
|
||
14 years ago
|
for (TQStringList::Iterator it = filterRules.begin(); it != filterRules.end(); it++) {
|
||
|
TQRegExp *expr = new TQRegExp((*it).latin1());
|
||
15 years ago
|
if (expr->search(lines[i].latin1()) != -1) {
|
||
14 years ago
|
KNotifyClient::event(winId(), "pattern_match", TQString("rule '%1' matched").arg((*it).latin1()));
|
||
15 years ago
|
}
|
||
|
delete expr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
monitor->setCurrentItem( monitor->count() - 1 );
|
||
|
monitor->ensureCurrentVisible();
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
case 42: {
|
||
|
logFileID = answer.toULong();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
LogFile::resizeEvent(TQResizeEvent*)
|
||
15 years ago
|
{
|
||
|
frame()->setGeometry(0, 0, this->width(), this->height());
|
||
|
monitor->setGeometry(10, 20, this->width() - 20, this->height() - 30);
|
||
|
}
|