Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
BackgroundTaskWithDialog.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_THREADS_PROCESSINGWITHDIALOG_HPP_
2#define IV_SRC_THREADS_PROCESSINGWITHDIALOG_HPP_
3
4#include "ui/gui/CDialog.hpp"
5
6#include <atomic>
7#include <chrono>
8#include <functional>
9#include <future>
10
11namespace iv::threads
12{
13
15{
16 std::string title {"Processing"};
17 std::string message {"Some processing is happening, please wait..."};
18 std::function<void(const std::atomic_bool &cancelRequest)> processingFunction;
19 std::function<void(bool wasCancelled)> completionCallback = [](auto) {};
20 bool showCancelButton {true};
21};
22
24{
25public:
28
29 void execute(CDialog *dlgFather);
30
31 [[nodiscard]] bool isCancelled() const;
32
33private:
34 void runTask() const;
35
37
38 std::atomic_bool m_cancelRequested;
39 std::thread m_thread;
40 std::weak_ptr<CDialog> m_dialog;
41};
42
43}// namespace iv::threads
44
45#endif//IV_SRC_THREADS_PROCESSINGWITHDIALOG_HPP_
Definition CDialog.hpp:21
Definition BackgroundTaskWithDialog.hpp:24
void runTask() const
Definition BackgroundTaskWithDialog.cpp:56
bool isCancelled() const
Definition BackgroundTaskWithDialog.cpp:51
std::thread m_thread
Definition BackgroundTaskWithDialog.hpp:39
std::weak_ptr< CDialog > m_dialog
Definition BackgroundTaskWithDialog.hpp:40
BackgroundTaskWithDialogParams m_params
Definition BackgroundTaskWithDialog.hpp:36
~BackgroundTaskWithDialog()
Definition BackgroundTaskWithDialog.cpp:15
void execute(CDialog *dlgFather)
Definition BackgroundTaskWithDialog.cpp:25
std::atomic_bool m_cancelRequested
Definition BackgroundTaskWithDialog.hpp:38
BackgroundTaskWithDialog(BackgroundTaskWithDialogParams params)
Definition BackgroundTaskWithDialog.cpp:10
Definition BackgroundTaskWithDialog.cpp:8
Definition BackgroundTaskWithDialog.hpp:15
std::string message
Definition BackgroundTaskWithDialog.hpp:17
bool showCancelButton
Definition BackgroundTaskWithDialog.hpp:20
std::string title
Definition BackgroundTaskWithDialog.hpp:16
std::function< void(const std::atomic_bool &cancelRequest)> processingFunction
Definition BackgroundTaskWithDialog.hpp:18
std::function< void(bool wasCancelled)> completionCallback
Definition BackgroundTaskWithDialog.hpp:19