2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999 - 2001 Chris Schlaeger <cs@kde.org>
5 Copyright (c) 2006 John Tapsell <john.tapsell@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; version 2 of
10 the License, or (at your option) version 3.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <QDomElement>
25 #include <QHeaderView>
26 #include <QStackedLayout>
30 #include "ProcessController.moc"
31 #include "ProcessController.h"
32 #include "processui/ksysguardprocesslist.h"
33 #include "processes.h"
35 //#define DO_MODELCHECK
37 #include "modeltest.h"
39 ProcessController::ProcessController(QWidget
* parent
, const QString
&title
, SharedSettings
*workSheetSettings
)
40 : KSGRD::SensorDisplay(parent
, title
, workSheetSettings
)
47 ProcessController::sensorError(int, bool err
)
49 if (err
== sensors().at(0)->isOk())
54 kDebug() << "SensorError called with an error";
56 /* This happens only when the sensorOk status needs to be changed. */
57 sensors().at(0)->setIsOk( !err
);
59 setSensorOk(sensors().at(0)->isOk());
63 ProcessController::restoreSettings(QDomElement
& element
)
65 bool result
= addSensor(element
.attribute("hostName"),
66 element
.attribute("sensorName"),
67 (element
.attribute("sensorType").isEmpty() ? "table" : element
.attribute("sensorType")),
69 if(!result
) return false;
71 int version
= element
.attribute("version", "0").toUInt();
72 if(version
== PROCESSHEADERVERSION
) { //If the header has changed, the old settings are no longer valid. Only restore if version is the same
73 mProcessList
->restoreHeaderState(QByteArray::fromBase64(element
.attribute("treeViewHeader").toLatin1()));
76 bool showTotals
= element
.attribute("showTotals", "1").toUInt();
77 mProcessList
->setShowTotals(showTotals
);
80 int units
= element
.attribute("units", QString::number((int)ProcessModel::UnitsKB
)).toUInt();
81 mProcessList
->setUnits((ProcessModel::Units
)units
);
83 int filterState
= element
.attribute("filterState", QString::number((int)ProcessFilter::AllProcesses
)).toUInt();
84 mProcessList
->setState((ProcessFilter::State
)filterState
);
86 SensorDisplay::restoreSettings(element
);
90 bool ProcessController::saveSettings(QDomDocument
& doc
, QDomElement
& element
)
94 element
.setAttribute("hostName", sensors().at(0)->hostName());
95 element
.setAttribute("sensorName", sensors().at(0)->name());
96 element
.setAttribute("sensorType", sensors().at(0)->type());
98 element
.setAttribute("version", QString::number(PROCESSHEADERVERSION
));
99 element
.setAttribute("treeViewHeader", QString::fromLatin1(mProcessList
->treeView()->header()->saveState().toBase64()));
100 element
.setAttribute("showTotals", mProcessList
->showTotals()?1:0);
102 element
.setAttribute("units", (int)(mProcessList
->units()));
103 element
.setAttribute("filterState", (int)(mProcessList
->state()));
105 SensorDisplay::saveSettings(doc
, element
);
110 void ProcessController::answerReceived( int id
, const QList
<QByteArray
>& answer
) {
112 mProcesses
->answerReceived(id
, answer
);
115 bool ProcessController::addSensor(const QString
& hostName
,
116 const QString
& sensorName
,
117 const QString
& sensorType
,
118 const QString
& title
)
120 if (sensorType
!= "table")
124 QStackedLayout
*layout
= new QStackedLayout(this);
125 mProcessList
= new KSysGuardProcessList(this, hostName
);
126 mProcessList
->setContentsMargins(0,0,0,0);
127 kDebug() << "Number of Actions: " << mProcessList
->actions().size();
128 addActions(mProcessList
->actions());
130 layout
->addWidget(mProcessList
);
132 /** To use a remote sensor, we need to drill down through the layers, to connect to the remote processes. Then connect to its signals and slots.
133 * It's horrible I know :( */
134 if(!hostName
.isEmpty() && hostName
!= "localhost") {
135 KSysGuard::Processes
*processes
= mProcessList
->processModel()->processController();
136 mProcesses
= processes
;
138 connect( processes
, SIGNAL(runCommand(const QString
&, int)), SLOT(runCommand(const QString
&, int)));
145 setPlotterWidget(mProcessList
);
147 QTimer::singleShot(0, mProcessList
->filterLineEdit(), SLOT(setFocus()));
149 registerSensor(new KSGRD::SensorProperties(hostName
, sensorName
, sensorType
, title
));
150 /* This just triggers the first communication. The full set of
151 * requests are send whenever the sensor reconnects (detected in
153 sensors().at(0)->setIsOk(true); //Assume it is okay from the start
154 setSensorOk(sensors().at(0)->isOk());
158 void ProcessController::runCommand(const QString
&command
, int id
) {
159 sendRequest(sensors().at(0)->hostName(), command
, id
);