~ubuntu-branches/debian/sid/gsmartcontrol/sid

« back to all changes in this revision

Viewing changes to src/gsc_preferences_window.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano
  • Date: 2011-07-15 14:59:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715145929-2o1o4phm5w1rwttz
Tags: 0.8.6-1
* [dbb993d] Updated my email address and removed DM-Upload-Allowed
  control field
* [b681b5b] Imported Upstream version 0.8.6
* [ab9bb7a] Refreshed patches
* [a909506] Bump to Standards-Version 3.9.2, no changes needed
* [48dd13d] Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**************************************************************************
2
2
 Copyright:
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
***************************************************************************/
6
6
 
17
17
#include <gdk/gdkkeysyms.h>  // GDK_Escape
18
18
 
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"
22
24
 
23
25
#include "gsc_preferences_window.h"
24
26
 
36
38
                {
37
39
                        Gtk::TreeModelColumnRecord model_columns;
38
40
 
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 "".
41
44
 
42
45
                        model_columns.add(col_device);
43
46
                        this->append_column("Device", col_device);
44
47
                        this->set_search_column(col_device.index());
45
48
 
 
49
                        model_columns.add(col_type);
 
50
                        this->append_column("Type", col_type);
 
51
 
46
52
                        model_columns.add(col_parameters);
47
 
 
48
53
                        model_columns.add(col_device_real);
 
54
                        model_columns.add(col_type_real);
49
55
 
50
56
 
51
57
                        // create a TreeModel (ListStore)
76
82
                }
77
83
 
78
84
 
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)
80
86
                {
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;
85
93
 
86
94
                        if (select)
87
95
                                this->get_selection()->select(row);
98
106
                }
99
107
 
100
108
 
 
109
                void update_selected_row_type(const std::string& type)
 
110
                {
 
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;
 
115
                        }
 
116
                }
 
117
 
 
118
 
101
119
                void update_selected_row_params(const std::string& params)
102
120
                {
103
121
                        if (this->get_selection()->count_selected_rows()) {
123
141
                {
124
142
                        clear_all();
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);
127
150
                        }
128
151
                }
129
152
 
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);
 
162
                                if (!dev.empty()) {
 
163
                                        std::string par = row.get_value(col_type_real);
 
164
                                        if (!par.empty()) {
 
165
                                                dev += "::" + par;
 
166
                                        }
 
167
                                        if (devmap.find(dev) == devmap.end()) {
 
168
                                                devmap[dev] = row.get_value(col_parameters);
 
169
                                        }
 
170
                                }
140
171
                        }
141
172
 
142
173
                        return devmap;
147
178
                // callback
148
179
                void on_selection_changed()
149
180
                {
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);
156
188
 
158
190
                                preferences_window->device_widget_set_remove_possible(false);
159
191
                        }
160
192
 
161
 
                        preferences_window->update_device_widgets(dev, par);
 
193
                        preferences_window->update_device_widgets(dev, type, par);
162
194
                }
163
195
 
164
196
 
166
198
                Glib::RefPtr<Gtk::ListStore> model;
167
199
 
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;
171
205
 
172
206
                GscPreferencesWindow* preferences_window;
173
207
 
206
240
        Gtk::Button* device_options_remove_device_button = 0;
207
241
        APP_UI_RES_AUTO_CONNECT(device_options_remove_device_button, clicked);
208
242
 
 
243
 
209
244
        Gtk::Entry* device_options_device_entry = 0;
210
245
        APP_UI_RES_AUTO_CONNECT(device_options_device_entry, changed);
211
246
 
 
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)";
 
252
#endif
 
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);
 
255
        }
 
256
        if (device_options_device_entry) {
 
257
                app_gtkmm_set_widget_tooltip(*device_options_device_entry, device_options_tooltip);
 
258
        }
 
259
 
 
260
 
 
261
        Gtk::Entry* device_options_type_entry = 0;
 
262
        APP_UI_RES_AUTO_CONNECT(device_options_type_entry, changed);
 
263
 
 
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\".";
 
267
#endif
 
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);
 
270
        }
 
271
        if (device_options_type_entry) {
 
272
                app_gtkmm_set_widget_tooltip(*device_options_type_entry, device_type_tooltip);
 
273
        }
 
274
 
 
275
 
212
276
        Gtk::Entry* device_options_parameter_entry = 0;
213
277
        APP_UI_RES_AUTO_CONNECT(device_options_parameter_entry, changed);
214
278
 
247
311
 
248
312
 
249
313
 
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)
251
315
{
252
316
        Gtk::Entry* entry = 0;
253
317
 
254
318
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_device_entry")))
255
319
                entry->set_text(device);
256
320
 
 
321
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_type_entry")))
 
322
                entry->set_text(type);
 
323
 
257
324
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_parameter_entry")))
258
325
                entry->set_text(params);
259
326
}
469
536
void GscPreferencesWindow::on_device_options_add_device_button_clicked()
470
537
{
471
538
        Gtk::Entry* entry = 0;
472
 
        std::string dev, par;
 
539
        std::string dev, type, par;
473
540
 
474
541
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_device_entry")))
475
542
                dev = entry->get_text();
476
543
 
 
544
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_type_entry")))
 
545
                type = entry->get_text();
 
546
 
477
547
        if ((entry = this->lookup_widget<Gtk::Entry*>("device_options_parameter_entry")))
478
548
                par = entry->get_text();
479
549
 
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.
482
552
        } else {
483
 
                device_options_treeview->add_new_row(dev, par);
 
553
                device_options_treeview->add_new_row(dev, type, par);
484
554
        }
485
555
}
486
556
 
495
565
 
496
566
 
497
567
 
 
568
void GscPreferencesWindow::on_device_options_type_entry_changed()
 
569
{
 
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());
 
573
}
 
574
 
 
575
 
 
576
 
498
577
void GscPreferencesWindow::on_device_options_parameter_entry_changed()
499
578
{
500
579
        Gtk::Entry* entry = 0;