| 1 |
/* |
| 2 |
This file is part of Icecream. |
| 3 |
|
| 4 |
Copyright (c) 2012 Kevin Funk <[email protected]> |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License along |
| 17 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 18 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef JOBLISTMODEL_H |
| 22 |
#define JOBLISTMODEL_H |
| 23 |
|
| 24 |
#include "job.h" |
| 25 |
|
| 26 |
#include <QAbstractItemModel> |
| 27 |
#include <QSortFilterProxyModel> |
| 28 |
#include <QPointer> |
| 29 |
#include <QVector> |
| 30 |
|
| 31 |
class Monitor; |
| 32 |
class QTimer; |
| 33 |
|
| 34 |
class JobListModel |
| 35 |
: public QAbstractListModel |
| 36 |
{ |
| 37 |
Q_OBJECT |
| 38 |
|
| 39 |
public: |
| 40 |
enum Column |
| 41 |
{ |
| 42 |
JobColumnID, |
| 43 |
JobColumnFilename, |
| 44 |
JobColumnClient, |
| 45 |
JobColumnServer, |
| 46 |
JobColumnState, |
| 47 |
JobColumnReal, |
| 48 |
JobColumnUser, |
| 49 |
JobColumnFaults, |
| 50 |
JobColumnSizeIn, |
| 51 |
JobColumnSizeOut, |
| 52 |
_JobColumnCount |
| 53 |
}; |
| 54 |
|
| 55 |
enum JobType |
| 56 |
{ |
| 57 |
AllJobs, |
| 58 |
LocalJobs, |
| 59 |
RemoteJobs |
| 60 |
}; |
| 61 |
|
| 62 |
explicit JobListModel(QObject *parent = nullptr); |
| 63 |
|
| 64 |
Monitor *monitor() const; |
| 65 |
void setMonitor(Monitor *monitor); |
| 66 |
|
| 67 |
int expireDuration() const { |
| 68 |
return m_expireDuration; |
| 69 |
} |
| 70 |
|
| 71 |
void setExpireDuration(int duration) { |
| 72 |
m_expireDuration = duration; |
| 73 |
} |
| 74 |
|
| 75 |
int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 76 |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 77 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 78 |
QModelIndex parent(const QModelIndex &child) const override; |
| 79 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 80 |
|
| 81 |
Job jobForIndex(const QModelIndex &index) const; |
| 82 |
QModelIndex indexForJob(const Job &job, int column); |
| 83 |
|
| 84 |
void setHostId(unsigned int hostId); |
| 85 |
unsigned int hostId() const { return m_hostId; } |
| 86 |
void setJobType(JobType type) { m_jobType = type; } |
| 87 |
JobType jobType() const { return m_jobType; } |
| 88 |
|
| 89 |
private Q_SLOTS: |
| 90 |
void slotExpireFinishedJobs(); |
| 91 |
|
| 92 |
void updateJob(const Job &job); |
| 93 |
void clear(); |
| 94 |
|
| 95 |
private: |
| 96 |
QVector<Job> m_jobs; |
| 97 |
|
| 98 |
void expireItem(const Job &job); |
| 99 |
void removeItem(const Job &job); |
| 100 |
void removeItemById(unsigned int jobId); |
| 101 |
|
| 102 |
QPointer<Monitor> m_monitor; |
| 103 |
|
| 104 |
/** |
| 105 |
* Number of parts (directories) of the file path which should be displayed. |
| 106 |
* - < 0 for complete file path |
| 107 |
* - == 0 for the pure file name without path |
| 108 |
* - > 0 for only parts of the file path. If there are not enough parts |
| 109 |
* the complete file path is displayed else .../partN/.../part1/fileName. |
| 110 |
* Default is 2. |
| 111 |
*/ |
| 112 |
int m_numberOfFilePathParts{2}; |
| 113 |
|
| 114 |
/** |
| 115 |
* The number of seconds after which finished jobs should be expired. |
| 116 |
* - < 0 never |
| 117 |
* - == 0 at once |
| 118 |
* - > 0 after some seconds. |
| 119 |
* Default is -1. |
| 120 |
*/ |
| 121 |
int m_expireDuration{-1}; |
| 122 |
|
| 123 |
struct FinishedJob |
| 124 |
{ |
| 125 |
explicit FinishedJob(uint _time = 0, uint _jobId = 0) |
| 126 |
: time(_time) |
| 127 |
, jobId(_jobId) {} |
| 128 |
uint time; |
| 129 |
uint jobId; |
| 130 |
}; |
| 131 |
using FinishedJobs = QVector<JobListModel::FinishedJob>; |
| 132 |
|
| 133 |
/// List with job ids that are expired |
| 134 |
FinishedJobs m_finishedJobs; |
| 135 |
|
| 136 |
QTimer *m_expireTimer; |
| 137 |
JobType m_jobType{AllJobs}; |
| 138 |
unsigned int m_hostId{0}; |
| 139 |
}; |
| 140 |
|
| 141 |
class JobListSortFilterProxyModel |
| 142 |
: public QSortFilterProxyModel |
| 143 |
{ |
| 144 |
Q_OBJECT |
| 145 |
public: |
| 146 |
explicit JobListSortFilterProxyModel(QObject *parent = nullptr); |
| 147 |
|
| 148 |
protected: |
| 149 |
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; |
| 150 |
}; |
| 151 |
|
| 152 |
#endif |