ORE Studio 0.0.4
Loading...
Searching...
No Matches
ComputeTransferModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_COMPUTE_TRANSFER_MODEL_HPP
21#define ORES_QT_COMPUTE_TRANSFER_MODEL_HPP
22
23#include <vector>
24#include <QString>
25#include <QAbstractTableModel>
26
27namespace ores::qt {
28
33 QString id;
34 QString direction;
35 QString filename;
36 int progress = 0;
37 QString speed;
38 QString status;
39};
40
47class ComputeTransferModel final : public QAbstractTableModel {
48 Q_OBJECT
49
50public:
51 enum Column {
52 Direction,
53 Filename,
54 Progress,
55 Speed,
56 Status,
57 ColumnCount
58 };
59
60 explicit ComputeTransferModel(QObject* parent = nullptr);
61
62 // QAbstractTableModel interface
63 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
64 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
65 QVariant data(const QModelIndex& index,
66 int role = Qt::DisplayRole) const override;
67 QVariant headerData(int section, Qt::Orientation orientation,
68 int role = Qt::DisplayRole) const override;
69
73 int add_transfer(const QString& id,
74 const QString& direction,
75 const QString& filename);
76
80 void update_progress(const QString& id, int progress,
81 const QString& speed = {});
82
86 void complete_transfer(const QString& id);
87
91 void fail_transfer(const QString& id, const QString& reason = {});
92
96 void clear_finished();
97
98private:
99 int find_row(const QString& id) const;
100
101 std::vector<transfer_item> transfers_;
102};
103
104} // namespace ores::qt
105
106#endif
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
A single in-flight or completed file transfer.
Definition ComputeTransferModel.hpp:32
int progress
0–100
Definition ComputeTransferModel.hpp:36
QString direction
"↑" (upload) or "↓" (download)
Definition ComputeTransferModel.hpp:34
QString id
Unique token (e.g. result_id + direction)
Definition ComputeTransferModel.hpp:33
QString speed
e.g. "1.2 MB/s"; empty when idle
Definition ComputeTransferModel.hpp:37
QString status
"Transferring", "Complete", "Failed"
Definition ComputeTransferModel.hpp:38
Pure Qt model tracking upload/download progress.
Definition ComputeTransferModel.hpp:47
void clear_finished()
Removes all completed and failed entries.
Definition ComputeTransferModel.cpp:127
void complete_transfer(const QString &id)
Marks a transfer as complete (progress = 100).
Definition ComputeTransferModel.cpp:105
void update_progress(const QString &id, int progress, const QString &speed={})
Updates progress (0–100) and speed string for an existing entry.
Definition ComputeTransferModel.cpp:94
void fail_transfer(const QString &id, const QString &reason={})
Marks a transfer as failed.
Definition ComputeTransferModel.cpp:116
int add_transfer(const QString &id, const QString &direction, const QString &filename)
Adds a new transfer entry and returns its row index.
Definition ComputeTransferModel.cpp:78