| 1 |
/* |
| 2 |
This file is part of Icecream. |
| 3 |
|
| 4 |
Copyright (c) 2003 Frerich Raabe <[email protected]> |
| 5 |
Copyright (c) 2003,2004 Stephan Kulow <[email protected]> |
| 6 |
Copyright (c) 2003,2004 Cornelius Schumacher <[email protected]> |
| 7 |
Copyright (c) 2014 Kevin Funk <[email protected]> |
| 8 |
|
| 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. |
| 13 |
|
| 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. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License along |
| 20 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 21 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "statusview.h" |
| 25 |
|
| 26 |
#include "hostinfo.h" |
| 27 |
#include "job.h" |
| 28 |
|
| 29 |
#include <QDebug> |
| 30 |
#include <QTime> |
| 31 |
|
| 32 |
StatusView::StatusView(QObject *parent) |
| 33 |
: QObject(parent) |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
StatusView::~StatusView() |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
StatusView::Options StatusView::options() const |
| 42 |
{ |
| 43 |
return NoOptions; |
| 44 |
} |
| 45 |
|
| 46 |
Monitor *StatusView::monitor() const |
| 47 |
{ |
| 48 |
return m_monitor; |
| 49 |
} |
| 50 |
|
| 51 |
void StatusView::setMonitor(Monitor *monitor) |
| 52 |
{ |
| 53 |
if (m_monitor == monitor) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
if (m_monitor) { |
| 58 |
disconnect(m_monitor.data(), &Monitor::jobUpdated, this, &StatusView::update); |
| 59 |
disconnect(m_monitor.data(), &Monitor::nodeRemoved, this, &StatusView::removeNode); |
| 60 |
disconnect(m_monitor.data(), &Monitor::nodeUpdated, this, &StatusView::checkNode); |
| 61 |
disconnect(m_monitor.data(), &Monitor::schedulerStateChanged, |
| 62 |
this, &StatusView::updateSchedulerState); |
| 63 |
} |
| 64 |
|
| 65 |
m_monitor = monitor; |
| 66 |
|
| 67 |
if (m_monitor) { |
| 68 |
connect(m_monitor.data(), &Monitor::jobUpdated, this, &StatusView::update); |
| 69 |
connect(m_monitor.data(), &Monitor::nodeRemoved, this, &StatusView::removeNode); |
| 70 |
connect(m_monitor.data(), &Monitor::nodeUpdated, this, &StatusView::checkNode); |
| 71 |
connect(m_monitor.data(), &Monitor::schedulerStateChanged, |
| 72 |
this, &StatusView::updateSchedulerState); |
| 73 |
|
| 74 |
if (options().testFlag(RememberJobsOption)) { |
| 75 |
foreach(const Job &job, m_monitor->jobHistory()) { |
| 76 |
update(job); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
HostInfoManager *StatusView::hostInfoManager() const |
| 83 |
{ |
| 84 |
return (m_monitor ? m_monitor->hostInfoManager() : nullptr); |
| 85 |
} |
| 86 |
|
| 87 |
void StatusView::update(const Job &) |
| 88 |
{ |
| 89 |
} |
| 90 |
|
| 91 |
void StatusView::checkNode(HostId) |
| 92 |
{ |
| 93 |
} |
| 94 |
|
| 95 |
void StatusView::removeNode(HostId) |
| 96 |
{ |
| 97 |
} |
| 98 |
|
| 99 |
void StatusView::updateSchedulerState(Monitor::SchedulerState state) |
| 100 |
{ |
| 101 |
Q_UNUSED(state); |
| 102 |
} |
| 103 |
|
| 104 |
QString StatusView::nameForHost(HostId id) |
| 105 |
{ |
| 106 |
if (!m_monitor) { |
| 107 |
return QString(); |
| 108 |
} |
| 109 |
|
| 110 |
return m_monitor->hostInfoManager()->nameForHost(id); |
| 111 |
} |
| 112 |
|
| 113 |
QColor StatusView::hostColor(HostId id) |
| 114 |
{ |
| 115 |
if (!m_monitor) { |
| 116 |
return QColor(); |
| 117 |
} |
| 118 |
|
| 119 |
return m_monitor->hostInfoManager()->hostColor(id); |
| 120 |
} |
| 121 |
|
| 122 |
unsigned int StatusView::processor(const Job &job) |
| 123 |
{ |
| 124 |
unsigned int ret = 0; |
| 125 |
if (job.state == Job::LocalOnly || job.state == Job::WaitingForCS) { |
| 126 |
ret = job.client; |
| 127 |
} else { |
| 128 |
ret = job.server; |
| 129 |
if (!ret) { |
| 130 |
// Q_ASSERT( job.m_state == Job::Finished ); |
| 131 |
ret = job.client; |
| 132 |
} |
| 133 |
} |
| 134 |
Q_ASSERT(ret); |
| 135 |
return ret; |
| 136 |
} |
| 137 |
|
| 138 |
void StatusView::togglePause() |
| 139 |
{ |
| 140 |
if (m_paused) { |
| 141 |
start(); |
| 142 |
} else { |
| 143 |
stop(); |
| 144 |
} |
| 145 |
|
| 146 |
m_paused = !m_paused; |
| 147 |
} |