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 #ifdef G_OS_WIN32
7 #undef ERROR
8 #undef DELETE
9 #undef DUPLICATE
10 #endif
11 #include "nlohmann/json_fwd.hpp"
12 #include "util/editor_process.hpp"
13 #include "util/window_state_store.hpp"
14 #include "util/status_dispatcher.hpp"
15 #include "pool-prj-mgr-process.hpp"
16 #include "project/project.hpp"
17 #include "prj-mgr/prj-mgr_views.hpp"
18 #include "pool-mgr/view_create_pool.hpp"
19 #include "common/common.hpp"
20 #include <git2.h>
21 
22 namespace horizon {
23 using json = nlohmann::json;
24 
25 class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
26  friend class PoolProjectManagerViewProject;
28 
29 public:
30  PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
33 
35 
36  void open_file_view(const Glib::RefPtr<Gio::File> &file);
37  void prepare_close();
38  bool close_pool_or_project();
39  bool really_close_pool_or_project();
40  void wait_for_all_processes();
41  std::string get_filename() const;
42 
43  PoolProjectManagerProcess *spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
44  const std::vector<std::string> &env = {}, bool read_only = false,
45  bool is_temp = false);
46  PoolProjectManagerProcess *spawn_for_project(PoolProjectManagerProcess::Type type,
47  const std::vector<std::string> &args);
48 
49  std::map<UUID, PoolProjectManagerProcess *> get_processes();
50 
51  class Pool *pool = nullptr;
52  class PoolParametric *pool_parametric = nullptr;
53 
54  typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
55  type_signal_process_exited signal_process_exited()
56  {
57  return s_signal_process_exited;
58  }
59 
60  typedef sigc::signal<void, std::string> type_signal_process_saved;
61  type_signal_process_saved signal_process_saved()
62  {
63  return s_signal_process_saved;
64  }
65 
66  void reload();
67 
68  class ClosePolicy {
69  public:
70  bool can_close = true;
71  std::string reason;
72  std::vector<UUID> procs_need_save;
73  };
74 
75  ClosePolicy get_close_policy();
76 
77  std::string get_proc_filename(const UUID &uu);
78  void process_save(const UUID &uu);
79  void process_close(const UUID &uu);
80  void cleanup_pool_cache();
81 
82  enum class ViewMode { OPEN, POOL, DOWNLOAD, PROJECT, CREATE_PROJECT, CREATE_POOL };
83  ViewMode get_view_mode() const;
84 
85  UUID get_pool_uuid() const;
86  void pool_notebook_go_to(ObjectType type, const UUID &uu);
87  void open_pool(const std::string &pool_json, ObjectType type = ObjectType::INVALID, const UUID &uu = UUID());
88  void handle_download(bool back_to_start = false);
89  void update_pool_cache_status_now();
90 
91 private:
92  Glib::RefPtr<Gtk::Builder> builder;
93  Gtk::Stack *stack = nullptr;
94  Gtk::Button *button_open = nullptr;
95  Gtk::Button *button_close = nullptr;
96  Gtk::Button *button_update = nullptr;
97  Gtk::Button *button_download = nullptr;
98  Gtk::Button *button_do_download = nullptr;
99  Gtk::Button *button_cancel = nullptr;
100  Gtk::MenuButton *button_new = nullptr;
101  Gtk::Button *button_create = nullptr;
102  Gtk::Button *button_save = nullptr;
103  Gtk::Spinner *spinner_update = nullptr;
104  Gtk::Revealer *download_revealer = nullptr;
105  Gtk::Label *download_label = nullptr;
106  Gtk::Spinner *download_spinner = nullptr;
107  Gtk::MenuButton *hamburger_menu_button = nullptr;
108 
109  Gtk::Entry *download_gh_username_entry = nullptr;
110  Gtk::Entry *download_gh_repo_entry = nullptr;
111  Gtk::Entry *download_dest_dir_entry = nullptr;
112  Gtk::Button *download_dest_dir_button = nullptr;
113 
114  Gtk::HeaderBar *header = nullptr;
115  Gtk::ListBox *recent_pools_listbox = nullptr;
116  Gtk::ListBox *recent_projects_listbox = nullptr;
117  std::vector<Gtk::ListBox *> recent_listboxes;
118  Gtk::Box *pool_box = nullptr;
119  class PoolNotebook *pool_notebook = nullptr;
120 
121  Gtk::Label *pool_update_status_label = nullptr;
122  Gtk::Revealer *pool_update_status_rev = nullptr;
123  Gtk::Button *pool_update_status_close_button = nullptr;
124  Gtk::ProgressBar *pool_update_progress = nullptr;
125  sigc::connection pool_update_conn;
126 
127  Gtk::InfoBar *info_bar = nullptr;
128  Gtk::Label *info_bar_label = nullptr;
129  Gtk::Button *show_output_button = nullptr;
130 
131  Gtk::InfoBar *info_bar_pool_not_added = nullptr;
132 
133  Gtk::MenuItem *menu_new_pool = nullptr;
134  Gtk::MenuItem *menu_new_project = nullptr;
135 
136  class OutputWindow *output_window = nullptr;
137 
138  Gtk::InfoBar *info_bar_pool_doc = nullptr;
139 
140  std::unique_ptr<Project> project = nullptr;
141  std::string project_filename;
142  bool project_needs_save = false;
143  void save_project();
144  class PartBrowserWindow *part_browser_window = nullptr;
145  class PoolCacheWindow *pool_cache_window = nullptr;
146  std::unique_ptr<class PoolCacheMonitor> pool_cache_monitor;
147  void cleanup();
148 
149  ViewMode view_mode = ViewMode::OPEN;
150  void set_view_mode(ViewMode mode);
151 
152  void update_recent_items();
153 
154  void handle_open();
155  void handle_close();
156  void handle_recent();
157  void handle_update();
158  void handle_do_download();
159  void handle_new_project();
160  void handle_new_pool();
161  void handle_create();
162  void handle_cancel();
163  void handle_save();
164  json handle_req(const json &j);
165 
166  bool on_delete_event(GdkEventAny *ev) override;
167 
168  void download_thread(std::string gh_username, std::string gh_repo, std::string dest_dir);
169 
170  StatusDispatcher download_status_dispatcher;
171 
172  WindowStateStore state_store;
173 
174  std::map<UUID, PoolProjectManagerProcess> processes;
175  std::map<int, bool> pids_need_save;
176  PoolProjectManagerProcess *find_process(const std::string &filename);
177  PoolProjectManagerProcess *find_top_schematic_process();
178  PoolProjectManagerProcess *find_board_process();
179 
180  const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
181  const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
182 
183  type_signal_process_exited s_signal_process_exited;
184  type_signal_process_saved s_signal_process_saved;
185 
186  PoolProjectManagerViewCreateProject view_create_project;
187  PoolProjectManagerViewProject view_project;
188  PoolProjectManagerViewCreatePool view_create_pool;
189 
190  void handle_place_part(const UUID &uu);
191  void handle_assign_part(const UUID &uu);
192 
194  zmq::socket_t sock_mgr;
195  std::string sock_mgr_ep;
196 
197  bool check_pools();
198  bool check_schema_update(const std::string &base_path);
199 
200  bool download_back_to_start = false;
201 
202  bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
203 
204  static int git_transfer_cb(const git_transfer_progress *stats, void *payload);
205  bool downloading = false;
206  bool download_cancel = false;
207 
208 public:
209  zmq::context_t &zctx;
210  void set_pool_updating(bool v, bool success);
211  void set_pool_update_status_text(const std::string &txt);
212  void set_pool_update_progress(float progress);
213 };
214 }; // namespace horizon
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::PartBrowserWindow
Definition: part_browser_window.hpp:15
horizon::OutputWindow
Definition: output_window.hpp:8
horizon::WindowStateStore
Definition: window_state_store.hpp:20
horizon::PoolProjectManagerAppWindow::ClosePolicy
Definition: pool-prj-mgr-app_win.hpp:68
horizon::PoolProjectManagerProcess
Definition: pool-prj-mgr-process.hpp:6
horizon::PoolProjectManagerViewCreateProject
Definition: prj-mgr_views.hpp:9
horizon::PoolNotebook
Definition: pool_notebook.hpp:24
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:166
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::PoolProjectManagerViewProject
Definition: prj-mgr_views.hpp:34
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
horizon::PoolProjectManagerViewCreatePool
Definition: view_create_pool.hpp:8
horizon::PoolCacheWindow
Definition: pool_cache_window.hpp:15
horizon::PoolProjectManagerApplication
Definition: pool-prj-mgr-app.hpp:19
horizon::PoolParametric
Definition: pool_parametric.hpp:10
horizon::PoolProjectManagerAppWindow
Definition: pool-prj-mgr-app_win.hpp:25
horizon::StatusDispatcher
Definition: status_dispatcher.hpp:8