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