Horizon
pool_remote_box.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <set>
4 #include <mutex>
5 #include "util/uuid.hpp"
6 #include "common/common.hpp"
7 #include "nlohmann/json.hpp"
8 #include <git2.h>
9 #include "util/status_dispatcher.hpp"
10 #include "util/item_set.hpp"
11 #include <atomic>
12 
13 namespace horizon {
14 using json = nlohmann::json;
15 
16 class PoolRemoteBox : public Gtk::Box {
17 public:
18  PoolRemoteBox(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, class PoolNotebook *nb);
19  static PoolRemoteBox *create(class PoolNotebook *nb);
20 
21  void merge_item(ObjectType ty, const UUID &uu);
22  void merge_3d_model(const std::string &filename);
23  void handle_refresh_prs();
24  bool prs_refreshed_once = false;
25 
26  void login_once();
27 
28 private:
29  class PoolNotebook *notebook = nullptr;
30 
31  class ListColumns : public Gtk::TreeModelColumnRecord {
32  public:
33  ListColumns()
34  {
35  Gtk::TreeModelColumnRecord::add(name);
36  Gtk::TreeModelColumnRecord::add(type);
37  Gtk::TreeModelColumnRecord::add(uuid);
38  Gtk::TreeModelColumnRecord::add(filename);
39  }
40  Gtk::TreeModelColumn<Glib::ustring> name;
41  Gtk::TreeModelColumn<ObjectType> type;
42  Gtk::TreeModelColumn<UUID> uuid;
43  Gtk::TreeModelColumn<std::string> filename;
44  };
45  ListColumns list_columns;
46 
47  Glib::RefPtr<Gtk::ListStore> item_store;
48  Gtk::TreeView *merge_items_view = nullptr;
49  Gtk::Label *merge_items_placeholder_label = nullptr;
50  Gtk::Label *pr_body_placeholder_label = nullptr;
51  Gtk::Button *upgrade_button = nullptr;
52  Gtk::Button *create_pr_button = nullptr;
53  Gtk::Button *refresh_prs_button = nullptr;
54  Gtk::Revealer *upgrade_revealer = nullptr;
55  Gtk::Label *upgrade_label = nullptr;
56  Gtk::Spinner *upgrade_spinner = nullptr;
57  Gtk::Label *gh_repo_link_label = nullptr;
58  Gtk::Label *gh_signed_in_label = nullptr;
59  Gtk::Button *merge_items_clear_button = nullptr;
60  Gtk::Button *merge_items_remove_button = nullptr;
61  Gtk::Entry *pr_title_entry = nullptr;
62  Gtk::TextView *pr_body_textview = nullptr;
63  Gtk::ListBox *pull_requests_listbox = nullptr;
64  Gtk::Spinner *pr_spinner = nullptr;
65  StatusDispatcher pr_status_dispatcher;
66  Gtk::Button *login_button = nullptr;
67  Gtk::Button *logout_button = nullptr;
68  Gtk::CheckButton *show_only_my_prs_cb = nullptr;
69  Gtk::Button *pr_update_button = nullptr;
70  Gtk::Button *pr_update_cancel_button = nullptr;
71 
72 
73  void handle_remote_upgrade();
74  void handle_create_pr();
75  void handle_update_pr();
76  void update_body_placeholder_label();
77 
78 
79  void remote_upgrade_thread();
80  void create_pr_thread();
81  void update_pr_thread();
82  void refresh_prs_thread();
83  void login_thread();
84  void checkout_master(git_repository *repo);
85  std::string get_token_filename() const;
86  bool update_login();
87  void set_pr_update_mode(unsigned int pr, const std::string branch_name);
88 
89  static int pr_diff_file_cb_c(const git_diff_delta *delta, float progress, void *pl);
90  void pr_diff_file_cb(const git_diff_delta *delta);
91 
92  Glib::Dispatcher git_thread_dispatcher;
93 
94  enum class GitThreadMode { UPGRADE, PULL_REQUEST, PULL_REQUEST_UPDATE, LOGIN };
95  GitThreadMode git_thread_mode = GitThreadMode::UPGRADE;
96  bool git_thread_busy = false;
97  std::string git_thread_status;
98  bool git_thread_error = false;
99  json pull_requests;
100  std::mutex git_thread_mutex;
101 
102  std::string gh_owner;
103  std::string gh_repo;
104 
105  ItemSet items_merge;
106  std::set<std::string> models_merge;
107  void update_items_merge();
108  ItemSet get_referenced(ObjectType ty, const UUID &uu);
109  bool exists_in_pool(class Pool &pool, ObjectType ty, const UUID &uu);
110  git_oid items_to_tree(git_repository *repo);
111  void push_branch(git_remote *remote, const std::string &branch_name);
112 
113  void update_prs();
114  void update_my_prs();
115 
116  std::string gh_username;
117  std::string gh_token;
118 
119  std::string pr_title;
120  std::string pr_body;
121 
122  unsigned int pr_update_nr = 0;
123  std::string pr_update_branch;
124 
125  bool logged_in_once = false;
126  std::atomic<bool> login_succeeded = true;
127 };
128 } // namespace horizon
horizon::PoolRemoteBox
Definition: pool_remote_box.hpp:16
horizon::PoolNotebook
Definition: pool_notebook.hpp:20
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
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:23
horizon::StatusDispatcher
Definition: status_dispatcher.hpp:8