| 1 |
/* |
| 2 |
This file is part of Icecream. |
| 3 |
|
| 4 |
Copyright (c) 2004-2006 Andre Wöbbeking <[email protected]> |
| 5 |
(c) 2014 Allan Sandfeld Jensen <[email protected]> |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 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. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License along |
| 18 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 19 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <QLabel> |
| 23 |
#include <QBoxLayout> |
| 24 |
#include <QSortFilterProxyModel> |
| 25 |
#include <QSplitter> |
| 26 |
|
| 27 |
#include "detailedhostview.h" |
| 28 |
|
| 29 |
#include "joblistview.h" |
| 30 |
#include "hostinfo.h" |
| 31 |
#include "hostlistview.h" |
| 32 |
#include "models/joblistmodel.h" |
| 33 |
#include "models/hostlistmodel.h" |
| 34 |
|
| 35 |
#include <sys/utsname.h> |
| 36 |
|
| 37 |
static QString myHostName() |
| 38 |
{ |
| 39 |
struct utsname uname_buf; |
| 40 |
if (::uname(&uname_buf) == 0) { |
| 41 |
return QLatin1String(uname_buf.nodename); |
| 42 |
} else { |
| 43 |
return QString(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
DetailedHostView::DetailedHostView(QObject *parent) |
| 48 |
: StatusView(parent) |
| 49 |
, m_widget(new QWidget) |
| 50 |
{ |
| 51 |
QBoxLayout *topLayout = new QVBoxLayout(m_widget.data()); |
| 52 |
topLayout->setContentsMargins({10, 10, 10, 10}); |
| 53 |
|
| 54 |
auto viewSplitter = new QSplitter(Qt::Vertical); |
| 55 |
topLayout->addWidget(viewSplitter); |
| 56 |
|
| 57 |
auto hosts = new QWidget(viewSplitter); |
| 58 |
auto dummy = new QVBoxLayout(hosts); |
| 59 |
dummy->setSpacing(10); |
| 60 |
dummy->setContentsMargins({}); |
| 61 |
|
| 62 |
mHostListModel = new HostListModel(this); |
| 63 |
|
| 64 |
mSortedHostListModel = new QSortFilterProxyModel(this); |
| 65 |
mSortedHostListModel->setDynamicSortFilter(true); |
| 66 |
mSortedHostListModel->setSourceModel(mHostListModel); |
| 67 |
|
| 68 |
dummy->addWidget(new QLabel(tr("Hosts"), hosts)); |
| 69 |
mHostListView = new HostListView(hosts); |
| 70 |
mHostListView->setModel(mSortedHostListModel); |
| 71 |
dummy->addWidget(mHostListView); |
| 72 |
connect(mHostListView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), |
| 73 |
SLOT(slotNodeActivated())); |
| 74 |
|
| 75 |
auto locals = new QWidget(viewSplitter); |
| 76 |
dummy = new QVBoxLayout(locals); |
| 77 |
dummy->setSpacing(10); |
| 78 |
dummy->setContentsMargins({}); |
| 79 |
|
| 80 |
mLocalJobsModel = new JobListModel(this); |
| 81 |
mLocalJobsModel->setExpireDuration(5); |
| 82 |
mLocalJobsModel->setJobType(JobListModel::LocalJobs); |
| 83 |
mSortedLocalJobsModel = new JobListSortFilterProxyModel(this); |
| 84 |
mSortedLocalJobsModel->setDynamicSortFilter(true); |
| 85 |
mSortedLocalJobsModel->setSourceModel(mLocalJobsModel); |
| 86 |
|
| 87 |
dummy->addWidget(new QLabel(tr("Outgoing jobs"), locals)); |
| 88 |
mLocalJobsView = new JobListView(locals); |
| 89 |
mLocalJobsView->setModel(mSortedLocalJobsModel); |
| 90 |
mLocalJobsView->setClientColumnVisible(false); |
| 91 |
dummy->addWidget(mLocalJobsView); |
| 92 |
|
| 93 |
auto remotes = new QWidget(viewSplitter); |
| 94 |
dummy = new QVBoxLayout(remotes); |
| 95 |
dummy->setSpacing(10); |
| 96 |
dummy->setContentsMargins({}); |
| 97 |
|
| 98 |
mRemoteJobsModel = new JobListModel(this); |
| 99 |
mRemoteJobsModel->setExpireDuration(5); |
| 100 |
mRemoteJobsModel->setJobType(JobListModel::RemoteJobs); |
| 101 |
mSortedRemoteJobsModel = new JobListSortFilterProxyModel(this); |
| 102 |
mSortedRemoteJobsModel->setDynamicSortFilter(true); |
| 103 |
mSortedRemoteJobsModel->setSourceModel(mRemoteJobsModel); |
| 104 |
|
| 105 |
dummy->addWidget(new QLabel(tr("Incoming jobs"), remotes)); |
| 106 |
mRemoteJobsView = new JobListView(remotes); |
| 107 |
mRemoteJobsView->setModel(mSortedRemoteJobsModel); |
| 108 |
mRemoteJobsView->setServerColumnVisible(false); |
| 109 |
dummy->addWidget(mRemoteJobsView); |
| 110 |
|
| 111 |
createKnownHosts(); |
| 112 |
} |
| 113 |
|
| 114 |
void DetailedHostView::setMonitor(Monitor *monitor) |
| 115 |
{ |
| 116 |
StatusView::setMonitor(monitor); |
| 117 |
|
| 118 |
mHostListModel->setMonitor(monitor); |
| 119 |
mLocalJobsModel->setMonitor(monitor); |
| 120 |
mRemoteJobsModel->setMonitor(monitor); |
| 121 |
|
| 122 |
createKnownHosts(); |
| 123 |
} |
| 124 |
|
| 125 |
void DetailedHostView::checkNode(unsigned int hostid) |
| 126 |
{ |
| 127 |
if (!hostid) { |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
if (!mHostListView->selectionModel()->hasSelection()) { |
| 132 |
HostInfo *info = hostInfoManager()->find(hostid); |
| 133 |
if (info->name() == myHostName()) { |
| 134 |
mHostListView->setCurrentIndex(mSortedHostListModel->mapFromSource(mHostListModel->indexForHostInfo(*info, 0))); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
void DetailedHostView::createKnownHosts() |
| 140 |
{ |
| 141 |
if (!hostInfoManager()) { |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
const HostInfoManager::HostMap hosts(hostInfoManager()->hostMap()); |
| 146 |
foreach(int hostid, hosts.keys()) { |
| 147 |
checkNode(hostid); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
void DetailedHostView::slotNodeActivated() |
| 152 |
{ |
| 153 |
const auto hostid = mHostListView->currentIndex().data(HostListModel::HostIdRole).value<unsigned int>(); |
| 154 |
if (!hostid) |
| 155 |
return; |
| 156 |
mLocalJobsModel->setHostId(hostid); |
| 157 |
mRemoteJobsModel->setHostId(hostid); |
| 158 |
} |
| 159 |
|
| 160 |
QWidget *DetailedHostView::widget() const |
| 161 |
{ |
| 162 |
return m_widget.data(); |
| 163 |
} |