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