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