Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
progress_info.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2022, 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
9
10#ifndef __UTILS_PROGRESS_INFO_H__
11#define __UTILS_PROGRESS_INFO_H__
12
13#include <atomic>
14#include <mutex>
15#include <string>
16#include <utility>
17
18#include "utils/debug.h"
19
25
31class [[deprecated ("Use QFuture")]] ProgressInfo
32{
33public:
34 enum Status
35 {
36 PENDING_START,
37 PENDING_CANCELLATION,
38 RUNNING,
39 COMPLETED,
40 };
41
42 enum CompletionType
43 {
44 CANCELLED,
45 HAS_WARNING,
46 HAS_ERROR,
47 SUCCESS,
48 };
49
50 Status get_status () const { return status_; };
51
52 CompletionType get_completion_type () const
53 {
54 z_return_val_if_fail (status_ == COMPLETED, HAS_ERROR);
55 return completion_type_;
56 }
57
62
66 void mark_completed (CompletionType type, const utils::Utf8String &msg);
67
71 utils::Utf8String get_message () const { return completion_str_; }
72
76 std::tuple<double, utils::Utf8String> get_progress ()
77 {
78 std::scoped_lock guard (m_);
79
80 return std::make_tuple (progress_, progress_str_);
81 }
82
86 void update_progress (double progress, const utils::Utf8String &msg);
87
88 bool pending_cancellation () const
89 {
90 return status_ == PENDING_CANCELLATION;
91 };
92
93private:
95 double progress_{};
96
98 Status status_{};
99
101 CompletionType completion_type_{};
102
105 utils::Utf8String completion_str_;
106
109 utils::Utf8String progress_str_;
110
113 // utils::Utf8String label_done_str;
114
116 std::mutex m_;
117};
118
122
123#endif
Generic progress info.
std::tuple< double, utils::Utf8String > get_progress()
To be called by the task caller.
void mark_completed(CompletionType type, const utils::Utf8String &msg)
To be called by the task itself.
void request_cancellation()
To be called by the task caller.
utils::Utf8String get_message() const
Returns a newly allocated string.
void update_progress(double progress, const utils::Utf8String &msg)
To be called by the task itself.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38