File indexing completed on 2024-04-28 04:20:53

0001 // SPDX-FileCopyrightText: 2012-2022 Jesper K. Pedersen <blackie@kde.org>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef BACKGROUNDTASKS_JOBMODEL_H
0006 #define BACKGROUNDTASKS_JOBMODEL_H
0007 
0008 #include "CompletedJobInfo.h"
0009 #include "JobInfo.h"
0010 #include "JobInterface.h"
0011 
0012 #include <QAbstractTableModel>
0013 
0014 namespace BackgroundTaskManager
0015 {
0016 
0017 class JobModel : public QAbstractTableModel
0018 {
0019     Q_OBJECT
0020 public:
0021     explicit JobModel(QObject *parent = nullptr);
0022     ~JobModel() override;
0023     int rowCount(const QModelIndex &) const override;
0024     int columnCount(const QModelIndex &) const override;
0025     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0026     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0027 
0028 public Q_SLOTS:
0029     void reset();
0030 
0031 private Q_SLOTS:
0032     void jobEnded(JobInterface *job);
0033     void jobStarted(JobInterface *job);
0034 
0035     /**
0036      * @brief heartbeat
0037      * Makes the running jobs blink.
0038      */
0039     void heartbeat();
0040 
0041 private:
0042     enum Column { IDCol = 0,
0043                   TitleCol = 1,
0044                   DetailsCol = 2,
0045                   ElapsedCol = 3 };
0046     bool blinkStateOn;
0047 
0048     JobInfo *info(int row) const;
0049     QPixmap statusImage(JobInfo::State state) const;
0050 
0051     QList<CompletedJobInfo *> m_previousJobs;
0052 };
0053 
0054 } // namespace BackgroundTaskManager
0055 
0056 #endif // BACKGROUNDTASKS_JOBMODEL_H
0057 // vi:expandtab:tabstop=4 shiftwidth=4: