1 #pragma once
2 #include "common/common.hpp"
3 #include "pool/part.hpp"
4 #include "pool/pool.hpp"
5 #include "pool/pool_parametric.hpp"
6 #include "util/uuid.hpp"
7 #include "util/window_state_store.hpp"
8 #include "util/paned_state_store.hpp"
9 #include <array>
10 #include <gtkmm.h>
11 #include <set>
12 #include "util/item_set.hpp"
13 #include <optional>
14 
15 namespace horizon {
16 
17 class PartBrowserWindow : public Gtk::Window {
18 public:
19     PartBrowserWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, const std::string &pool_path,
20                       std::deque<UUID> &favs);
21     static PartBrowserWindow *create(Gtk::Window *p, const std::string &pool_path, std::deque<UUID> &favs);
22     typedef sigc::signal<void, UUID> type_signal_place_part;
signal_place_part()23     type_signal_place_part signal_place_part()
24     {
25         return s_signal_place_part;
26     }
signal_assign_part()27     type_signal_place_part signal_assign_part()
28     {
29         return s_signal_assign_part;
30     }
31 
32     typedef sigc::signal<void, ItemSet> type_signal_open_pool_cache_window;
signal_open_pool_cache_window()33     type_signal_open_pool_cache_window signal_open_pool_cache_window()
34     {
35         return s_signal_open_pool_cache_window;
36     }
37 
38     void placed_part(const UUID &uu);
39     void go_to_part(const UUID &uu);
40     void set_can_assign(bool v);
41     void set_pool_cache_status(const class PoolCacheStatus &st);
42     void focus_search();
43     void pool_updated(const std::string &bp);
44 
45 private:
46     Gtk::Menu *add_search_menu = nullptr;
47     Gtk::Notebook *notebook = nullptr;
48     Gtk::Button *place_part_button = nullptr;
49     Gtk::Button *assign_part_button = nullptr;
50     Gtk::ToggleButton *fav_button = nullptr;
51     Gtk::ListBox *lb_favorites = nullptr;
52     Gtk::ListBox *lb_recent = nullptr;
53     Gtk::InfoBar *out_of_date_info_bar = nullptr;
54     class PartPreview *preview = nullptr;
55     class PoolBrowserPart *add_search(const UUID &part = UUID());
56     class PoolBrowserParametric *add_search_parametric(const std::string &table_name);
57     void handle_switch_page(Gtk::Widget *w, guint index);
58     void handle_fav_toggled();
59     void update_favorites();
60     void update_recents();
61     void handle_favorites_selected(Gtk::ListBoxRow *row);
62     void handle_favorites_activated(Gtk::ListBoxRow *row);
63     void handle_place_part();
64     void handle_assign_part();
65     sigc::connection fav_toggled_conn;
66     std::set<Gtk::Widget *> search_views;
67     Pool pool;
68     PoolParametric pool_parametric;
69     UUID part_current;
70     void update_part_current();
71     void update_out_of_date_info_bar();
72     ItemSet items_out_of_date;
73     std::deque<UUID> &favorites;
74     std::deque<UUID> recents;
75 
76     type_signal_place_part s_signal_place_part;
77     type_signal_place_part s_signal_assign_part;
78     type_signal_open_pool_cache_window s_signal_open_pool_cache_window;
79     bool can_assign = false;
80     const class PoolCacheStatus *pool_cache_status = nullptr;
81 
82     WindowStateStore state_store;
83     std::optional<PanedStateStore> paned_state_store;
84 
85     sigc::connection pool_updated_conn;
86     bool needs_reload = false;
87     void reload();
88 };
89 } // namespace horizon
90