Пример #1
0
void
ProcessController::sensorError(int, bool err)
{
    if (err == sensors().at(0)->isOk())
    {
        if (err)  {
            kDebug(1215) << "SensorError called with an error";
        }
        /* This happens only when the sensorOk status needs to be changed. */
        sensors().at(0)->setIsOk( !err );
    }
    setSensorOk(sensors().at(0)->isOk());
}
bool ProcessController::addSensor(const QString& hostName,
                                 const QString& sensorName,
                                 const QString& sensorType,
                                 const QString& title)
{
    if (sensorType != "table")
        return false;


    QStackedLayout *layout = new QStackedLayout(this);
    mProcessList = new KSysGuardProcessList(this, hostName);
    mProcessList->setUpdateIntervalMSecs(0); //we will call updateList() manually
    mProcessList->setContentsMargins(0,0,0,0);
    mProcessList->setScriptingEnabled(true);
    addActions(mProcessList->actions());
    connect(mProcessList, &KSysGuardProcessList::updated, this, &ProcessController::updated);
    connect(mProcessList, &KSysGuardProcessList::processListChanged, this, &ProcessController::processListChanged);
    mProcessList->setContextMenuPolicy( Qt::CustomContextMenu );
    connect(mProcessList, &KSysGuardProcessList::customContextMenuRequested, this, &ProcessController::showContextMenu);

    layout->addWidget(mProcessList);

    /** 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.
     *  It's horrible I know :( */
    if(!hostName.isEmpty() && hostName != "localhost") {
        KSysGuard::Processes *processes = mProcessList->processModel()->processController();
        mProcesses = processes;
        if(processes) {
            connect(processes, &KSysGuard::Processes::runCommand, this, &ProcessController::runCommand);
        }

    }

    setPlotterWidget(mProcessList);

    QTimer::singleShot(0, mProcessList->filterLineEdit(), SLOT(setFocus()));

    registerSensor(new KSGRD::SensorProperties(hostName, sensorName, sensorType, title));
    /* This just triggers the first communication. The full set of
    * requests are send whenever the sensor reconnects (detected in
    * sensorError(). */
    sensors().at(0)->setIsOk(true); //Assume it is okay from the start
    setSensorOk(sensors().at(0)->isOk());
    emit processListChanged();
    return true;
}