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  void reload();
60 
61  class ClosePolicy {
62  public:
63  bool can_close = true;
64  std::string reason;
65  std::vector<UUID> procs_need_save;
66  };
67 
68  ClosePolicy get_close_policy();
69 
70  std::string get_proc_filename(const UUID &uu);
71  void process_save(const UUID &uu);
72  void process_close(const UUID &uu);
73  void cleanup_pool_cache();
74 
75  enum class ViewMode { OPEN, POOL, DOWNLOAD, PROJECT, CREATE_PROJECT, CREATE_POOL };
76  ViewMode get_view_mode() const;
77 
78  UUID get_pool_uuid() const;
79  void pool_notebook_go_to(ObjectType type, const UUID &uu);
80  void open_pool(const std::string &pool_json, ObjectType type = ObjectType::INVALID, const UUID &uu = UUID());
81  void handle_download(bool back_to_start = false);
82  void update_pool_cache_status_now();
83 
84 private:
85  Glib::RefPtr<Gtk::Builder> builder;
86  Gtk::Stack *stack = nullptr;
87  Gtk::Button *button_open = nullptr;
88  Gtk::Button *button_close = nullptr;
89  Gtk::Button *button_update = nullptr;
90  Gtk::Button *button_download = nullptr;
91  Gtk::Button *button_do_download = nullptr;
92  Gtk::Button *button_cancel = nullptr;
93  Gtk::MenuButton *button_new = nullptr;
94  Gtk::Button *button_create = nullptr;
95  Gtk::Button *button_save = nullptr;
96  Gtk::Spinner *spinner_update = nullptr;
97  Gtk::Revealer *download_revealer = nullptr;
98  Gtk::Label *download_label = nullptr;
99  Gtk::Spinner *download_spinner = nullptr;
100  Gtk::MenuButton *hamburger_menu_button = nullptr;
101 
102  Gtk::Entry *download_gh_username_entry = nullptr;
103  Gtk::Entry *download_gh_repo_entry = nullptr;
104  Gtk::Entry *download_dest_dir_entry = nullptr;
105  Gtk::Button *download_dest_dir_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  std::unique_ptr<Project> project = nullptr;
132  std::string project_filename;
133  bool project_needs_save = false;
134  void save_project();
135  class PartBrowserWindow *part_browser_window = nullptr;
136  class PoolCacheWindow *pool_cache_window = nullptr;
137  std::unique_ptr<class PoolCacheMonitor> pool_cache_monitor;
138  void cleanup();
139 
140  ViewMode view_mode = ViewMode::OPEN;
141  void set_view_mode(ViewMode mode);
142 
143  void update_recent_items();
144 
145  void handle_open();
146  void handle_close();
147  void handle_recent();
148  void handle_update();
149  void handle_do_download();
150  void handle_new_project();
151  void handle_new_pool();
152  void handle_create();
153  void handle_cancel();
154  void handle_save();
155  json handle_req(const json &j);
156 
157  bool on_delete_event(GdkEventAny *ev) override;
158 
159  void download_thread(std::string gh_username, std::string gh_repo, std::string dest_dir);
160 
161  StatusDispatcher download_status_dispatcher;
162 
163  WindowStateStore state_store;
164 
165  std::map<UUID, PoolProjectManagerProcess> processes;
166  std::map<int, bool> pids_need_save;
167  PoolProjectManagerProcess *find_process(const std::string &filename);
168  PoolProjectManagerProcess *find_top_schematic_process();
169  PoolProjectManagerProcess *find_board_process();
170 
171  const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
172  const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
173 
174  type_signal_process_exited s_signal_process_exited;
175 
176  PoolProjectManagerViewCreateProject view_create_project;
177  PoolProjectManagerViewProject view_project;
178  PoolProjectManagerViewCreatePool view_create_pool;
179 
180  void handle_place_part(const UUID &uu);
181  void handle_assign_part(const UUID &uu);
182 
184  zmq::socket_t sock_mgr;
185  std::string sock_mgr_ep;
186 
187  bool check_pools();
188  bool check_schema_update(const std::string &base_path);
189 
190  bool download_back_to_start = false;
191 
192  bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
193 
194  static int git_transfer_cb(const git_transfer_progress *stats, void *payload);
195  bool downloading = false;
196  bool download_cancel = false;
197 
198 public:
199  zmq::context_t &zctx;
200  void set_pool_updating(bool v, bool success);
201  void set_pool_update_status_text(const std::string &txt);
202  void set_pool_update_progress(float progress);
203 };
204 }; // 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:61
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:165
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