1
1
/**************************************************************************
3
(C) 2008 - 2009 Alexander Shaduri <ashaduri 'at' gmail.com>
3
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
4
4
License: See LICENSE_gsmartcontrol.txt
5
5
***************************************************************************/
17
17
#include <gdk/gdkkeysyms.h> // GDK_Escape
19
19
#include "hz/fs_path.h"
20
#include "hz/string_sprintf.h"
20
21
#include "rconfig/rconfig_mini.h"
21
22
#include "applib/storage_settings.h"
23
#include "applib/app_gtkmm_utils.h"
23
25
#include "gsc_preferences_window.h"
37
39
Gtk::TreeModelColumnRecord model_columns;
39
// Device, [Parameters], [Device Real].
41
// Device, Type, [Parameters], [Device Real], [Type Real].
40
42
// Device may hold "<empty>", while Device Real is "".
43
// Type may hold "<all>", while Type Real is "".
42
45
model_columns.add(col_device);
43
46
this->append_column("Device", col_device);
44
47
this->set_search_column(col_device.index());
49
model_columns.add(col_type);
50
this->append_column("Type", col_type);
46
52
model_columns.add(col_parameters);
48
53
model_columns.add(col_device_real);
54
model_columns.add(col_type_real);
51
57
// create a TreeModel (ListStore)
79
void add_new_row(const std::string& device, const std::string& params, bool select = true)
85
void add_new_row(const std::string& device, const std::string& type, const std::string& params, bool select = true)
81
87
Gtk::TreeRow row = *(model->append());
82
88
row[col_device] = (device.empty() ? "<empty>" : device);
89
row[col_type] = (type.empty() ? "<all>" : type);
83
90
row[col_parameters] = params;
84
91
row[col_device_real] = device;
92
row[col_type_real] = type;
87
95
this->get_selection()->select(row);
109
void update_selected_row_type(const std::string& type)
111
if (this->get_selection()->count_selected_rows()) {
112
Gtk::TreeRow row = *(this->get_selection()->get_selected());
113
row[col_type] = (type.empty() ? "<all>" : type);
114
row[col_type_real] = type;
101
119
void update_selected_row_params(const std::string& params)
103
121
if (this->get_selection()->count_selected_rows()) {
125
143
for (device_option_map_t::const_iterator iter = devmap.begin(); iter != devmap.end(); ++iter) {
126
this->add_new_row(iter->first, iter->second, false);
144
std::vector<std::string> parts;
145
hz::string_split(iter->first, "::", parts, 2);
146
std::string dev = (parts.size() > 0 ? parts.at(0) : "");
147
std::string type = (parts.size() > 1 ? parts.at(1) : "");
148
std::string params = iter->second;
149
this->add_new_row(dev, type, params, false);
135
158
Gtk::TreeNodeChildren children = model->children();
136
159
for (Gtk::TreeNodeChildren::iterator iter = children.begin(); iter != children.end(); ++iter) {
137
160
Gtk::TreeModel::Row row = *iter;
138
if (!row.get_value(col_device_real).empty() && devmap.find(row.get_value(col_device_real)) == devmap.end())
139
devmap[row.get_value(col_device_real)] = row.get_value(col_parameters);
161
std::string dev = row.get_value(col_device_real);
163
std::string par = row.get_value(col_type_real);
167
if (devmap.find(dev) == devmap.end()) {
168
devmap[dev] = row.get_value(col_parameters);
148
179
void on_selection_changed()
150
std::string dev, par;
181
std::string dev, type, par;
151
182
if (this->get_selection()->count_selected_rows()) {
152
183
Gtk::TreeRow row = *(this->get_selection()->get_selected());
153
184
dev = row[col_device_real];
185
type = row[col_type_real];
154
186
par = row[col_parameters];
155
187
preferences_window->device_widget_set_remove_possible(true);
158
190
preferences_window->device_widget_set_remove_possible(false);
161
preferences_window->update_device_widgets(dev, par);
193
preferences_window->update_device_widgets(dev, type, par);
166
198
Glib::RefPtr<Gtk::ListStore> model;
168
200
Gtk::TreeModelColumn<Glib::ustring> col_device;
201
Gtk::TreeModelColumn<Glib::ustring> col_type;
169
202
Gtk::TreeModelColumn<std::string> col_parameters;
170
203
Gtk::TreeModelColumn<std::string> col_device_real;
204
Gtk::TreeModelColumn<std::string> col_type_real;
172
206
GscPreferencesWindow* preferences_window;
206
240
Gtk::Button* device_options_remove_device_button = 0;
207
241
APP_UI_RES_AUTO_CONNECT(device_options_remove_device_button, clicked);
209
244
Gtk::Entry* device_options_device_entry = 0;
210
245
APP_UI_RES_AUTO_CONNECT(device_options_device_entry, changed);
247
Glib::ustring device_options_tooltip = "Device name";
248
#if defined CONFIG_KERNEL_FAMILY_WINDOWS
249
device_options_tooltip = "Device name (for example, use \"pd0\" for the first physical drive)";
250
#elif defined CONFIG_KERNEL_LINUX
251
device_options_tooltip = "Device name (for example, /dev/sda or /dev/twa0)";
253
if (Gtk::Label* device_options_device_label = lookup_widget<Gtk::Label*>("device_options_device_label")) {
254
app_gtkmm_set_widget_tooltip(*device_options_device_label, device_options_tooltip);
256
if (device_options_device_entry) {
257
app_gtkmm_set_widget_tooltip(*device_options_device_entry, device_options_tooltip);
261
Gtk::Entry* device_options_type_entry = 0;
262
APP_UI_RES_AUTO_CONNECT(device_options_type_entry, changed);
264
Glib::ustring device_type_tooltip = "Match only this type of device (as specified to -d smartctl parameter)";
265
#if defined CONFIG_KERNEL_LINUX
266
device_type_tooltip = "Match only this type of device (as specified to -d smartctl parameter). Leave empty for all types. This can be used to specify a drive behind a RAID device, e.g. \"3ware,2\".";
268
if (Gtk::Label* device_options_type_label = lookup_widget<Gtk::Label*>("device_options_type_label")) {
269
app_gtkmm_set_widget_tooltip(*device_options_type_label, device_type_tooltip);
271
if (device_options_type_entry) {
272
app_gtkmm_set_widget_tooltip(*device_options_type_entry, device_type_tooltip);
212
276
Gtk::Entry* device_options_parameter_entry = 0;
213
277
APP_UI_RES_AUTO_CONNECT(device_options_parameter_entry, changed);
250
void GscPreferencesWindow::update_device_widgets(const std::string& device, const std::string& params)
314
void GscPreferencesWindow::update_device_widgets(const std::string& device, const std::string& type, const std::string& params)
252
316
Gtk::Entry* entry = 0;
254
318
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_device_entry")))
255
319
entry->set_text(device);
321
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_type_entry")))
322
entry->set_text(type);
257
324
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_parameter_entry")))
258
325
entry->set_text(params);
469
536
void GscPreferencesWindow::on_device_options_add_device_button_clicked()
471
538
Gtk::Entry* entry = 0;
472
std::string dev, par;
539
std::string dev, type, par;
474
541
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_device_entry")))
475
542
dev = entry->get_text();
544
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_type_entry")))
545
type = entry->get_text();
477
547
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_parameter_entry")))
478
548
par = entry->get_text();
480
550
if (device_options_treeview->has_selected_row()) {
481
device_options_treeview->add_new_row("", ""); // without this it would clone the existing.
551
device_options_treeview->add_new_row("", "", ""); // without this it would clone the existing.
483
device_options_treeview->add_new_row(dev, par);
553
device_options_treeview->add_new_row(dev, type, par);
568
void GscPreferencesWindow::on_device_options_type_entry_changed()
570
Gtk::Entry* entry = 0;
571
if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_type_entry")))
572
device_options_treeview->update_selected_row_type(entry->get_text());
498
577
void GscPreferencesWindow::on_device_options_parameter_entry_changed()
500
579
Gtk::Entry* entry = 0;