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 #include "rules/rules.hpp"
14 
15 namespace horizon {
16 using json = nlohmann::json;
17 
18 class PoolRemoteBox : public Gtk::Box {
19 public:
20  PoolRemoteBox(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, class PoolNotebook &nb);
21  static PoolRemoteBox *create(class PoolNotebook &nb);
22 
23  void merge_item(ObjectType ty, const UUID &uu);
24  void merge_3d_model(const std::string &filename);
25  void handle_refresh_prs();
26  bool prs_refreshed_once = false;
27 
28  void login_once();
29 
30 private:
31  class PoolNotebook &notebook;
32 
33  class ListColumns : public Gtk::TreeModelColumnRecord {
34  public:
35  ListColumns()
36  {
37  Gtk::TreeModelColumnRecord::add(name);
38  Gtk::TreeModelColumnRecord::add(type);
39  Gtk::TreeModelColumnRecord::add(uuid);
40  Gtk::TreeModelColumnRecord::add(filename);
41  Gtk::TreeModelColumnRecord::add(check_result);
42  }
43  Gtk::TreeModelColumn<Glib::ustring> name;
44  Gtk::TreeModelColumn<ObjectType> type;
45  Gtk::TreeModelColumn<UUID> uuid;
46  Gtk::TreeModelColumn<std::string> filename;
47  Gtk::TreeModelColumn<RulesCheckResult> check_result;
48  };
49  ListColumns list_columns;
50 
51  Glib::RefPtr<Gtk::ListStore> item_store;
52  Gtk::TreeView *merge_items_view = nullptr;
53  Gtk::Label *merge_items_placeholder_label = nullptr;
54  Gtk::Label *pr_body_placeholder_label = nullptr;
55  Gtk::Button *create_pr_button = nullptr;
56  Gtk::Button *refresh_prs_button = nullptr;
57  Gtk::Revealer *upgrade_revealer = nullptr;
58  Gtk::Label *upgrade_label = nullptr;
59  Gtk::Spinner *upgrade_spinner = nullptr;
60  Gtk::Label *gh_repo_link_label = nullptr;
61  Gtk::Label *gh_signed_in_label = nullptr;
62  Gtk::Button *merge_items_clear_button = nullptr;
63  Gtk::Button *merge_items_remove_button = nullptr;
64  Gtk::Button *merge_items_run_checks_button = nullptr;
65  Gtk::Entry *pr_title_entry = nullptr;
66  Gtk::TextView *pr_body_textview = nullptr;
67  Gtk::ListBox *pull_requests_listbox = nullptr;
68  Gtk::Spinner *pr_spinner = nullptr;
69  StatusDispatcher pr_status_dispatcher;
70  Gtk::Button *login_button = nullptr;
71  Gtk::Button *logout_button = nullptr;
72  Gtk::CheckButton *show_only_my_prs_cb = nullptr;
73  Gtk::Button *pr_update_button = nullptr;
74  Gtk::Button *pr_update_cancel_button = nullptr;
75 
76 
77  void handle_create_pr();
78  void handle_update_pr();
79  void update_body_placeholder_label();
80 
81 
82  void create_pr_thread();
83  void update_pr_thread();
84  void update_prepare_pr_thread();
85  autofree_ptr<git_remote> get_or_create_remote(class GitHubClient &client, git_repository *repo);
86  void refresh_prs_thread();
87  void login_thread();
88  void checkout_master(git_repository *repo);
89  std::string get_token_filename() const;
90  bool update_login();
91  void set_pr_update_mode(unsigned int pr, const std::string branch_name);
92 
93  static int pr_diff_file_cb_c(const git_diff_delta *delta, float progress, void *pl);
94  void pr_diff_file_cb(const git_diff_delta *delta);
95 
96  Glib::Dispatcher git_thread_dispatcher;
97 
98  enum class GitThreadMode { PULL_REQUEST, PULL_REQUEST_UPDATE, LOGIN, PULL_REQUEST_UPDATE_PREPARE };
99  GitThreadMode git_thread_mode = GitThreadMode::LOGIN;
100  bool git_thread_busy = false;
101  std::string git_thread_status;
102  bool git_thread_error = false;
103  json pull_requests;
104  std::mutex git_thread_mutex;
105 
106  std::string gh_owner;
107  std::string gh_repo;
108 
109  ItemSet items_merge;
110  std::set<std::string> models_merge;
111  void update_items_merge();
112  ItemSet get_referenced(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:18
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:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62