Horizon
pool-prj-mgr-app_win.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <memory>
4 #include "util/uuid.hpp"
5 #include <zmq.hpp>
6 #include "nlohmann/json_fwd.hpp"
7 #include "util/editor_process.hpp"
8 #include "util/window_state_store.hpp"
9 #include "pool-prj-mgr-process.hpp"
10 #include "project/project.hpp"
11 #include "prj-mgr/prj-mgr_views.hpp"
12 #include "pool-mgr/view_create_pool.hpp"
13 
14 namespace horizon {
15 using json = nlohmann::json;
16 
17 class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
18  friend class PoolProjectManagerViewProject;
20 
21 public:
22  PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
25 
27 
28  void open_file_view(const Glib::RefPtr<Gio::File> &file);
29  void prepare_close();
30  bool close_pool_or_project();
31  bool really_close_pool_or_project();
32  void wait_for_all_processes();
33  std::string get_filename() const;
34 
35  PoolProjectManagerProcess *spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
36  const std::vector<std::string> &env = {}, bool read_only = false);
37  PoolProjectManagerProcess *spawn_for_project(PoolProjectManagerProcess::Type type,
38  const std::vector<std::string> &args);
39 
40  std::map<std::string, PoolProjectManagerProcess *> get_processes();
41 
42  class Pool *pool = nullptr;
43 
44  typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
45  type_signal_process_exited signal_process_exited()
46  {
47  return s_signal_process_exited;
48  }
49  void reload();
50 
51  class ClosePolicy {
52  public:
53  bool can_close = true;
54  std::string reason;
55  std::vector<std::string> files_need_save;
56  };
57 
58  ClosePolicy get_close_policy();
59 
60  void process_save(const std::string &file);
61  void process_close(const std::string &file);
62  void cleanup_pool_cache();
63 
64 private:
65  Glib::RefPtr<Gtk::Builder> builder;
66  Gtk::Stack *stack = nullptr;
67  Gtk::Button *button_open = nullptr;
68  Gtk::Button *button_close = nullptr;
69  Gtk::Button *button_update = nullptr;
70  Gtk::Button *button_download = nullptr;
71  Gtk::Button *button_do_download = nullptr;
72  Gtk::Button *button_cancel = nullptr;
73  Gtk::MenuButton *button_new = nullptr;
74  Gtk::Button *button_create = nullptr;
75  Gtk::Button *button_save = nullptr;
76  Gtk::Spinner *spinner_update = nullptr;
77  Gtk::Revealer *download_revealer = nullptr;
78  Gtk::Label *download_label = nullptr;
79  Gtk::Spinner *download_spinner = nullptr;
80 
81  Gtk::Entry *download_gh_username_entry = nullptr;
82  Gtk::Entry *download_gh_repo_entry = nullptr;
83  Gtk::FileChooserButton *download_dest_dir_button = nullptr;
84 
85  Gtk::HeaderBar *header = nullptr;
86  Gtk::ListBox *recent_pools_listbox = nullptr;
87  Gtk::ListBox *recent_projects_listbox = nullptr;
88  std::vector<Gtk::ListBox *> recent_listboxes;
89  Gtk::Label *label_gitversion = nullptr;
90  Gtk::Box *pool_box = nullptr;
91  class PoolNotebook *pool_notebook = nullptr;
92 
93  Gtk::Label *pool_update_status_label = nullptr;
94  Gtk::Revealer *pool_update_status_rev = nullptr;
95  Gtk::Button *pool_update_status_close_button = nullptr;
96  Gtk::ProgressBar *pool_update_progress = nullptr;
97 
98  Gtk::InfoBar *info_bar = nullptr;
99  Gtk::Label *info_bar_label = nullptr;
100 
101  Gtk::MenuItem *menu_new_pool = nullptr;
102  Gtk::MenuItem *menu_new_project = nullptr;
103 
104  std::unique_ptr<Project> project = nullptr;
105  std::string project_filename;
106  bool project_needs_save = false;
107  void save_project();
108  class PartBrowserWindow *part_browser_window = nullptr;
109  class PoolCacheWindow *pool_cache_window = nullptr;
110 
111  enum class ViewMode { OPEN, POOL, DOWNLOAD, PROJECT, CREATE_PROJECT, CREATE_POOL };
112  ViewMode view_mode = ViewMode::OPEN;
113  void set_view_mode(ViewMode mode);
114 
115  void update_recent_items();
116 
117  void handle_open();
118  void handle_close();
119  void handle_recent();
120  void handle_update();
121  void handle_download();
122  void handle_do_download();
123  void handle_new_project();
124  void handle_new_pool();
125  void handle_create();
126  void handle_cancel();
127  void handle_save();
128  json handle_req(const json &j);
129 
130  bool on_delete_event(GdkEventAny *ev) override;
131 
132  void download_thread(std::string gh_username, std::string gh_repo, std::string dest_dir);
133 
134  Glib::Dispatcher download_dispatcher;
135 
136  bool downloading = false;
137  bool download_error = false;
138  std::string download_status;
139  std::mutex download_mutex;
140 
141  WindowStateStore state_store;
142 
143  std::map<std::string, PoolProjectManagerProcess> processes;
144  std::map<int, bool> pids_need_save;
145 
146  type_signal_process_exited s_signal_process_exited;
147 
148  PoolProjectManagerViewCreateProject view_create_project;
149  PoolProjectManagerViewProject view_project;
150  PoolProjectManagerViewCreatePool view_create_pool;
151 
152  void handle_place_part(const UUID &uu);
153  void handle_assign_part(const UUID &uu);
154 
155  zmq::socket_t sock_mgr;
156  std::string sock_mgr_ep;
157 
158  sigc::connection sock_mgr_conn;
159 
160  bool check_pools();
161  bool check_schema_update(const std::string &base_path);
162 
163 public:
164  zmq::context_t &zctx;
165  void set_pool_updating(bool v, bool success);
166  void set_pool_update_status_text(const std::string &txt);
167  void set_pool_update_progress(float progress);
168 };
169 }; // namespace horizon
Definition: pool-prj-mgr-app_win.hpp:51
Definition: part_browser_window.hpp:13
a class to store JSON values
Definition: json.hpp:161
Definition: pool_notebook.hpp:18
Definition: window_state_store.hpp:20
Definition: pool_cache_window.hpp:14
Definition: view_create_pool.hpp:8
Definition: pool-prj-mgr-app.hpp:19
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:19
Definition: block.cpp:9
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
Definition: prj-mgr_views.hpp:35
Definition: pool-prj-mgr-process.hpp:5
Definition: prj-mgr_views.hpp:9
Definition: pool-prj-mgr-app_win.hpp:17