Horizon
pool_browser.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <memory>
4 #include <set>
5 #include "util/uuid.hpp"
6 #include "util/sort_controller.hpp"
7 #include "util/selection_provider.hpp"
8 #include "common/common.hpp"
9 #include "util/treeview_state_store.hpp"
10 #include <optional>
11 
12 namespace horizon {
13 namespace SQLite {
14 class Query;
15 }
16 class PoolBrowser : public Gtk::Box, public SelectionProvider {
17 public:
18  PoolBrowser(class IPool &pool, const std::string &prefix = "");
19  UUID get_selected() override;
20  bool get_any_selected();
21  void set_show_none(bool v);
22  void set_show_path(bool v);
23  void add_context_menu_item(const std::string &label, std::function<void(UUID)> cb,
24  std::function<bool(UUID)> cb_sensitive = nullptr);
25  virtual void add_copy_name_context_menu_item(){};
26  virtual void search() = 0;
27  void search_once();
28  void clear_search_once();
29  virtual ObjectType get_type() const
30  {
31  return ObjectType::INVALID;
32  };
33  void go_to(const UUID &uu);
34  void clear_search();
35  void focus_search();
36  void reload_pools();
37 
38  enum class PoolItemSource { LOCAL, INCLUDED, OVERRIDDEN, OVERRIDDEN_LOCAL, CACHED };
39 
40 protected:
41  void construct(Gtk::Widget *search_box = nullptr);
42  class IPool &pool;
43  UUID pool_uuid;
44  bool pools_included = false;
45  bool show_none = false;
46  bool show_path = false;
47  Gtk::TreeViewColumn *path_column = nullptr;
48 
49 
50  Gtk::TreeView *treeview = nullptr;
51  Gtk::ScrolledWindow *scrolled_window = nullptr;
52 
53  Gtk::TreeViewColumn *append_column(const std::string &name, const Gtk::TreeModelColumnBase &column,
54  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
55  Gtk::TreeViewColumn *append_column_with_item_source_cr(const std::string &name,
56  const Gtk::TreeModelColumnBase &column,
57  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
58  class CellRendererColorBox *create_pool_item_source_cr(Gtk::TreeViewColumn *tvc);
59  void install_column_tooltip(Gtk::TreeViewColumn &tvc, const Gtk::TreeModelColumnBase &col);
60 
61  Gtk::Entry *create_search_entry(const std::string &label, Gtk::Widget *extra_widget = nullptr);
62  class TagEntry *create_tag_entry(const std::string &label, Gtk::Widget *extra_widget = nullptr);
63  void add_search_widget(const std::string &label, Gtk::Widget &w, Gtk::Widget *extra_widget = nullptr);
64 
65  virtual Glib::RefPtr<Gtk::ListStore> create_list_store() = 0;
66  virtual void create_columns() = 0;
67  virtual void add_sort_controller_columns() = 0;
68  virtual UUID uuid_from_row(const Gtk::TreeModel::Row &row) = 0;
69 
70  Glib::RefPtr<Gtk::ListStore> store;
71  std::unique_ptr<SortController> sort_controller;
72 
73  void row_activated(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *column);
74  void selection_changed();
75 
76  void select_uuid(const UUID &uu);
77  void scroll_to_selection();
78 
79  Gtk::Menu context_menu;
80  std::set<Gtk::Entry *> search_entries;
81  std::set<TagEntry *> tag_entries;
82 
83  PoolItemSource pool_item_source_from_db(const SQLite::Query &q, int idx_uu, int idx_last_uu) const;
84  PoolItemSource pool_item_source_from_db(const UUID &uu, const UUID &last_uu) const;
85 
86  void install_pool_item_source_tooltip();
87  virtual PoolItemSource pool_item_source_from_row(const Gtk::TreeModel::Row &row);
88  bool searched_once = false;
89 
90  void set_busy(bool busy);
91  void prepare_search();
92  void finish_search();
93 
94  Gtk::Box *status_box = nullptr;
95 
96  std::string get_tags_query(const std::set<std::string> &tags) const;
97  void bind_tags_query(SQLite::Query &q, const std::set<std::string> &tags) const;
98 
99  Gtk::Widget *create_pool_selector();
100  std::string get_pool_selector_query() const;
101  void bind_pool_selector_query(SQLite::Query &q) const;
102 
103  Gtk::Widget *focus_widget = nullptr;
104 
105 private:
106  Gtk::Grid *grid = nullptr;
107  int grid_top = 0;
108  class CellRendererColorBox *cell_renderer_item_source = nullptr;
109  Gtk::Box *busy_box = nullptr;
110  UUID selected_uuid_before_search;
111 
112  Gtk::Label *status_label = nullptr;
113  const std::string store_prefix;
114  std::optional<TreeViewStateStore> state_store;
115 
116  std::vector<std::pair<Gtk::Widget *, std::function<bool(UUID)>>> menu_item_sensitive_cbs;
117 
118  class PoolSelector *pool_selector = nullptr;
119  bool pools_reloading = false;
120 };
121 } // namespace horizon
Definition: cell_renderer_color_box.hpp:6
Definition: ipool.hpp:14
Definition: pool_browser.hpp:16
Definition: pool_selector.hpp:6
Definition: sqlite.hpp:25
Definition: selection_provider.hpp:6
Definition: tag_entry.hpp:9
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16