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 "util/win32_undef.hpp"
7 #include "nlohmann/json_fwd.hpp"
8 #include "util/editor_process.hpp"
9 #include "util/window_state_store.hpp"
10 #include "pool-prj-mgr-process.hpp"
11 #include "prj-mgr/prj-mgr_views.hpp"
12 #include "pool-mgr/view_create_pool.hpp"
13 #include "common/common.hpp"
14 #include <thread>
15 
16 namespace horizon {
17 using json = nlohmann::json;
18 
19 enum class PoolUpdateStatus;
20 enum class CheckSchemaUpdateResult;
21 
22 class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
23  friend class PoolProjectManagerViewProject;
25 
26 public:
27  PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
30 
32 
33  void open_file_view(const Glib::RefPtr<Gio::File> &file);
34  void prepare_close();
35  bool close_pool_or_project();
36  bool really_close_pool_or_project();
37  void wait_for_all_processes();
38  std::string get_filename() const;
39 
40  enum class SpawnFlags { NONE = 0, READ_ONLY = (1 << 0), TEMP = (1 << 1) };
41 
42  struct SpawnResult {
44  bool spawned; // if false, an existing window got raised
45  };
46 
47  SpawnResult spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
48  SpawnFlags flags = SpawnFlags::NONE);
49 
50  std::map<UUID, PoolProjectManagerProcess *> get_processes();
51 
52  class Pool *pool = nullptr;
53  class PoolParametric *pool_parametric = nullptr;
54 
55  typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
56  type_signal_process_exited signal_process_exited()
57  {
58  return s_signal_process_exited;
59  }
60 
61  typedef sigc::signal<void, std::string> type_signal_process_saved;
62  type_signal_process_saved signal_process_saved()
63  {
64  return s_signal_process_saved;
65  }
66 
67  class ClosePolicy {
68  public:
69  bool can_close = true;
70  std::string reason;
71  std::vector<UUID> procs_need_save;
72  };
73 
74  ClosePolicy get_close_policy();
75 
76  std::string get_proc_filename(const UUID &uu);
77  void process_save(const UUID &uu);
78  void process_close(const UUID &uu);
79  bool cleanup_pool_cache(Gtk::Window *parent);
80 
81  enum class ViewMode { OPEN, POOL, PROJECT, CREATE_PROJECT, CREATE_POOL };
82  ViewMode get_view_mode() const;
83 
84  UUID get_pool_uuid() const;
85  void pool_notebook_go_to(ObjectType type, const UUID &uu);
86  void pool_notebook_show_settings_tab();
87  void open_pool(const std::string &pool_json);
88  void update_pool_cache_status_now();
89  const std::string &get_project_title() const;
90 
91  void pool_update(const std::vector<std::string> &filenames = {});
92 
93  PoolProjectManagerApplication &app;
94 
95 private:
96  Glib::RefPtr<Gtk::Builder> builder;
97  Gtk::Stack *stack = nullptr;
98  Gtk::Button *button_open = nullptr;
99  Gtk::Button *button_close = nullptr;
100  Gtk::Button *button_update = nullptr;
101  Gtk::Button *button_cancel = nullptr;
102  Gtk::MenuButton *button_new = nullptr;
103  Gtk::Button *button_create = nullptr;
104  Gtk::Button *button_save = nullptr;
105  Gtk::MenuButton *hamburger_menu_button = nullptr;
106 
107  Gtk::HeaderBar *header = nullptr;
108  Gtk::ListBox *recent_pools_listbox = nullptr;
109  Gtk::ListBox *recent_projects_listbox = nullptr;
110  std::vector<Gtk::ListBox *> recent_listboxes;
111  Gtk::Box *pool_box = nullptr;
112  class PoolNotebook *pool_notebook = nullptr;
113 
114  Gtk::Label *pool_update_status_label = nullptr;
115  Gtk::Revealer *pool_update_status_rev = nullptr;
116  Gtk::Button *pool_update_status_close_button = nullptr;
117  Gtk::ProgressBar *pool_update_progress = nullptr;
118  sigc::connection pool_update_conn;
119 
120  Gtk::InfoBar *info_bar = nullptr;
121  Gtk::Label *info_bar_label = nullptr;
122  Gtk::Button *show_output_button = nullptr;
123 
124  Gtk::InfoBar *info_bar_pool_not_added = nullptr;
125 
126  Gtk::MenuItem *menu_new_pool = nullptr;
127  Gtk::MenuItem *menu_new_project = nullptr;
128 
129  class OutputWindow *output_window = nullptr;
130 
131  Gtk::InfoBar *info_bar_pool_doc = nullptr;
132 
133  Gtk::InfoBar *info_bar_version = nullptr;
134  Gtk::Label *version_label = nullptr;
135 
136  Gtk::InfoBar *info_bar_gitignore = nullptr;
137 
138  Gtk::InfoBar *info_bar_installation_uuid_mismatch = nullptr;
139 
140  std::unique_ptr<class Project> project;
141  std::string project_filename;
142  bool project_needs_save = false;
143  void save_project();
144  class PartBrowserWindow *part_browser_window = nullptr;
145  void cleanup();
146 #if GTK_CHECK_VERSION(3, 24, 0)
147  static gboolean part_browser_key_pressed(GtkEventControllerKey *controller, guint keyval, guint keycode,
148  GdkModifierType state, gpointer user_data);
149 #endif
150 
151  ViewMode view_mode = ViewMode::OPEN;
152  void set_view_mode(ViewMode mode);
153 
154  void update_recent_items();
155 
156  void handle_open();
157  void handle_close();
158  void handle_recent();
159  void handle_update();
160  void handle_new_project();
161  void handle_new_pool();
162  void handle_create();
163  void handle_cancel();
164  void handle_save();
165  json handle_req(const json &j);
166 
167  bool on_delete_event(GdkEventAny *ev) override;
168 
169  WindowStateStore state_store;
170 
171  std::map<UUID, PoolProjectManagerProcess> processes;
172  std::map<int, bool> pids_need_save;
173  PoolProjectManagerProcess *find_process(const std::string &filename);
174  PoolProjectManagerProcess *find_top_schematic_process();
175  PoolProjectManagerProcess *find_board_process();
176 
177  const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
178  const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
179 
180  type_signal_process_exited s_signal_process_exited;
181  type_signal_process_saved s_signal_process_saved;
182 
183  PoolProjectManagerViewCreateProject view_create_project;
184  PoolProjectManagerViewProject view_project;
185  PoolProjectManagerViewCreatePool view_create_pool;
186 
187  void handle_place_part(const UUID &uu);
188  void handle_assign_part(const UUID &uu);
189 
190  zmq::socket_t sock_mgr;
191  std::string sock_mgr_ep;
192 
193  bool check_pools();
194  bool check_schema_update(const std::string &base_path);
195 
196  void check_pool_update(const std::string &base_path);
197  void check_mtimes(const std::string &base_path);
198  std::thread check_mtimes_thread;
199  Glib::Dispatcher check_mtimes_dispatcher;
200 
201  bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
202 
203  void set_version_info(const std::string &s);
204  bool project_read_only = false;
205 
206  bool migrate_project(const std::string &path);
207  std::string project_title;
208 
209  Glib::Dispatcher pool_update_dispatcher;
210  bool in_pool_update_handler = false;
211  std::mutex pool_update_status_queue_mutex;
212  std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_status_queue;
213  std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_error_queue;
214  bool pool_updating = false;
215  void pool_updated(bool success);
216  std::string pool_update_last_file;
217  std::string pool_update_last_info;
218  unsigned int pool_update_n_files = 0;
219  unsigned int pool_update_n_files_last = 0;
220  std::vector<std::string> pool_update_filenames;
221 
222  void pool_update_thread();
223  void handle_pool_update_progress();
224  void set_pool_updating(bool v, bool success);
225  void set_pool_update_status_text(const std::string &txt);
226  void set_pool_update_progress(float progress);
227 
228  std::string get_pool_base_path() const;
229 
230  std::string get_gitignore_filename() const;
231 
232 public:
233  zmq::context_t &zctx;
234 };
235 }; // namespace horizon
Definition: pool_parametric.hpp:10
Definition: pool-prj-mgr-app_win.hpp:67
Definition: pool-prj-mgr-app_win.hpp:22
Definition: pool-prj-mgr-app.hpp:16
Definition: pool-prj-mgr-process.hpp:6
Definition: prj-mgr_views.hpp:9
Definition: prj-mgr_views.hpp:35
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:22
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62
Definition: pool-prj-mgr-app_win.hpp:42