1 #include "pool_browser_padstack.hpp"
2 #include "pool/ipool.hpp"
3 #include "util/sqlite.hpp"
4 #include <set>
5
6 namespace horizon {
PoolBrowserPadstack(IPool & p)7 PoolBrowserPadstack::PoolBrowserPadstack(IPool &p) : PoolBrowser(p)
8 {
9 construct();
10 name_entry = create_search_entry("Name", create_pool_selector());
11 focus_widget = name_entry;
12 install_pool_item_source_tooltip();
13 }
14
create_list_store()15 Glib::RefPtr<Gtk::ListStore> PoolBrowserPadstack::create_list_store()
16 {
17 return Gtk::ListStore::create(list_columns);
18 }
19
create_columns()20 void PoolBrowserPadstack::create_columns()
21 {
22 append_column_with_item_source_cr("Padstack", list_columns.padstack_name);
23 treeview->append_column("Type", list_columns.padstack_type);
24 treeview->append_column("Package", list_columns.package_name);
25 path_column = append_column("Path", list_columns.path, Pango::ELLIPSIZE_START);
26 install_column_tooltip(*path_column, list_columns.path);
27 }
28
add_sort_controller_columns()29 void PoolBrowserPadstack::add_sort_controller_columns()
30 {
31 sort_controller->add_column(0, "padstacks.name");
32 }
33
set_package_uuid(const UUID & uu)34 void PoolBrowserPadstack::set_package_uuid(const UUID &uu)
35 {
36 package_uuid = uu;
37 search();
38 }
39
get_padstacks_included() const40 const std::set<Padstack::Type> &PoolBrowserPadstack::get_padstacks_included() const
41 {
42 return padstacks_included;
43 }
44
set_padstacks_included(const std::set<Padstack::Type> & types)45 void PoolBrowserPadstack::set_padstacks_included(const std::set<Padstack::Type> &types)
46 {
47 padstacks_included = types;
48 search();
49 }
50
search()51 void PoolBrowserPadstack::search()
52 {
53 prepare_search();
54
55 std::string name_search = name_entry->get_text();
56
57 SQLite::Query q(
58 pool.get_db(),
59 "SELECT padstacks.uuid, padstacks.name, padstacks.type, "
60 "packages.name, padstacks.filename, padstacks.pool_uuid, padstacks.last_pool_uuid FROM padstacks LEFT "
61 "JOIN packages ON padstacks.package = packages.uuid WHERE "
62 "(packages.uuid=? OR ? OR padstacks.package = "
63 "'00000000-0000-0000-0000-000000000000') AND "
64 "padstacks.name LIKE ? AND padstacks.type IN (?, ?, ?, ?, "
65 "?, ?) " + get_pool_selector_query()
66 + sort_controller->get_order_by());
67 q.bind(1, package_uuid);
68 q.bind(2, package_uuid == UUID());
69 q.bind(3, "%" + name_search + "%");
70 if (padstacks_included.count(Padstack::Type::TOP))
71 q.bind(4, std::string("top"));
72 else
73 q.bind(4, std::string(""));
74
75 if (padstacks_included.count(Padstack::Type::BOTTOM))
76 q.bind(5, std::string("bottom"));
77 else
78 q.bind(5, std::string(""));
79
80 if (padstacks_included.count(Padstack::Type::THROUGH))
81 q.bind(6, std::string("through"));
82 else
83 q.bind(6, std::string(""));
84
85 if (padstacks_included.count(Padstack::Type::MECHANICAL))
86 q.bind(7, std::string("mechanical"));
87 else
88 q.bind(7, std::string(""));
89
90 if (padstacks_included.count(Padstack::Type::VIA))
91 q.bind(8, std::string("via"));
92 else
93 q.bind(8, std::string(""));
94
95 if (padstacks_included.count(Padstack::Type::HOLE))
96 q.bind(9, std::string("hole"));
97 else
98 q.bind(9, std::string(""));
99
100 bind_pool_selector_query(q);
101
102 Gtk::TreeModel::Row row;
103 if (show_none) {
104 row = *(store->append());
105 row[list_columns.uuid] = UUID();
106 row[list_columns.padstack_name] = "none";
107 }
108 try {
109 while (q.step()) {
110 row = *(store->append());
111 row[list_columns.uuid] = q.get<std::string>(0);
112 row[list_columns.padstack_name] = q.get<std::string>(1);
113 row[list_columns.padstack_type] = q.get<std::string>(2);
114 row[list_columns.package_name] = q.get<std::string>(3);
115 row[list_columns.path] = q.get<std::string>(4);
116 row[list_columns.source] = pool_item_source_from_db(q, 5, 6);
117 }
118 set_busy(false);
119 }
120 catch (SQLite::Error &e) {
121 if (e.rc == SQLITE_BUSY) {
122 set_busy(true);
123 }
124 else {
125 throw;
126 }
127 }
128
129 finish_search();
130 }
131
uuid_from_row(const Gtk::TreeModel::Row & row)132 UUID PoolBrowserPadstack::uuid_from_row(const Gtk::TreeModel::Row &row)
133 {
134 return row[list_columns.uuid];
135 }
pool_item_source_from_row(const Gtk::TreeModel::Row & row)136 PoolBrowser::PoolItemSource PoolBrowserPadstack::pool_item_source_from_row(const Gtk::TreeModel::Row &row)
137 {
138 return row[list_columns.source];
139 }
140 } // namespace horizon
141