Horizon
status_dispatcher.hpp
1 #pragma once
2 #include <glibmm/dispatcher.h>
3 #include <mutex>
4 #include <string>
5 #include <gtkmm.h>
6 
7 namespace horizon {
8 class StatusDispatcher : public sigc::trackable {
9 public:
11 
12  enum class Status { BUSY, DONE, ERROR };
13 
14  void reset(const std::string &msg);
15  void set_status(Status status, const std::string &msg, double progress = 0);
16 
17  class Notification {
18  public:
19  Status status;
20  std::string msg;
21  double progress;
22  };
23 
24  typedef sigc::signal<void, const Notification &> type_signal_notified;
25  type_signal_notified signal_notified()
26  {
27  return s_signal_notified;
28  }
29 
30  void attach(Gtk::Spinner *w);
31  void attach(Gtk::Label *w);
32  void attach(Gtk::Revealer *w);
33  void attach(Gtk::ProgressBar *w);
34 
35 private:
36  void notify();
37  Glib::Dispatcher dispatcher;
38  std::mutex mutex;
39  std::string msg;
40  double progress = 0;
41  Status status = Status::DONE;
42 
43  type_signal_notified s_signal_notified;
44  sigc::connection timeout_conn;
45 
46  Gtk::Spinner *spinner = nullptr;
47  Gtk::Label *label = nullptr;
48  Gtk::Revealer *revealer = nullptr;
49  Gtk::ProgressBar *progress_bar = nullptr;
50 };
51 } // namespace horizon
horizon::StatusDispatcher::Notification
Definition: status_dispatcher.hpp:17
horizon::StatusDispatcher
Definition: status_dispatcher.hpp:8