15
15
You should have received a copy of the GNU General Public License
16
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
20
#include "eiciel_xattr_window.hpp"
22
EicielXAttrWindow::EicielXAttrWindow(EicielXAttrControler* contr)
24
afegirAtribut(Gtk::Stock::ADD),
25
eliminarAtribut(Gtk::Stock::REMOVE)
22
EicielXAttrWindow::EicielXAttrWindow(EicielXAttrController* contr)
24
_b_add_attribute(Gtk::Stock::ADD),
25
_b_remove_attribute(Gtk::Stock::REMOVE)
27
refLlistaXAttr = Gtk::ListStore::create(modelLlistaXAttr);
27
_ref_xattr_list = Gtk::ListStore::create(_xattr_list_model);
29
controlador->finestra = this;
29
_controller->_window = this;
31
31
set_border_width(4);
32
vistaLlistaXAttr.set_size_request(100, 100);
34
refLlistaXAttr->set_sort_column(modelLlistaXAttr.nomAtribut, Gtk::SORT_ASCENDING);
36
vistaLlistaXAttr.set_reallocate_redraws();
37
vistaLlistaXAttr.set_model(refLlistaXAttr);
39
// Ara s'afegeixen les columnes i es vinculen amb el model
40
vistaLlistaXAttr.append_column(_("Name"), modelLlistaXAttr.nomAtribut);
42
// Aquesta columna requereix opcions especials
43
Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
32
_xattr_listview.set_size_request(100, 100);
34
_ref_xattr_list->set_sort_column(_xattr_list_model._attribute_name, Gtk::SORT_ASCENDING);
36
_xattr_listview.set_reallocate_redraws();
37
_xattr_listview.set_model(_ref_xattr_list);
39
// Add columns and link them to the model
40
_xattr_listview.append_column(_("Name"), _xattr_list_model._attribute_name);
42
// This column has special requirements
43
Gtk::TreeViewColumn* col = _xattr_listview.get_column(0);
44
44
Gtk::CellRenderer* cellRenderer = col->get_first_cell_renderer();
45
45
Gtk::CellRendererText* cellRendererText = dynamic_cast<Gtk::CellRendererText*>(cellRenderer);
46
46
cellRendererText->property_editable() = true;
48
48
cellRendererText->signal_edited().connect(
49
sigc::mem_fun(*this, &EicielXAttrWindow::nomAtributEditat)
49
sigc::mem_fun(*this, &EicielXAttrWindow::set_name_edited_attribute)
52
vistaLlistaXAttr.append_column_editable(_("Value"), modelLlistaXAttr.valorAtribut);
52
_xattr_listview.append_column_editable(_("Value"), _xattr_list_model._attribute_value);
54
col = vistaLlistaXAttr.get_column(1);
54
col = _xattr_listview.get_column(1);
55
55
cellRenderer = col->get_first_cell_renderer();
56
56
cellRendererText = dynamic_cast<Gtk::CellRendererText*>(cellRenderer);
57
57
cellRendererText->property_editable() = true;
59
59
cellRendererText->signal_edited().connect(
60
sigc::mem_fun(*this, &EicielXAttrWindow::valorAtributEditat)
60
sigc::mem_fun(*this, &EicielXAttrWindow::set_value_edited_attribute)
63
contenidorVistaLlistaXAttr.add(vistaLlistaXAttr);
64
contenidorVistaLlistaXAttr.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
66
pack_start(contenidorVistaLlistaXAttr, Gtk::PACK_EXPAND_WIDGET, 2);
68
botoneraInferior.pack_start(afegirAtribut, Gtk::PACK_SHRINK, 2);
69
botoneraInferior.pack_start(eliminarAtribut, Gtk::PACK_SHRINK, 2);
71
pack_start(botoneraInferior, Gtk::PACK_SHRINK, 2);
74
// Gtk::TreeModel::iterator iter = refLlistaXAttr->append();
75
// Gtk::TreeModel::Row row;
78
// row[modelLlistaXAttr.nomAtribut] = "rev";
79
// row[modelLlistaXAttr.valorAtribut] = "245";
81
// iter = refLlistaXAttr->append();
84
// row[modelLlistaXAttr.nomAtribut] = "Confidencial";
85
// row[modelLlistaXAttr.valorAtribut] = "No";
87
// Vinculaci� dels senyals
88
Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlistaXAttr = vistaLlistaXAttr.get_selection();
90
// Canvi de sel�lecci� XAttr
63
_xattr_listview_container.add(_xattr_listview);
64
_xattr_listview_container.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
66
pack_start(_xattr_listview_container, Gtk::PACK_EXPAND_WIDGET, 2);
68
_bottom_buttonbox.pack_start(_b_add_attribute, Gtk::PACK_SHRINK, 2);
69
_bottom_buttonbox.pack_start(_b_remove_attribute, Gtk::PACK_SHRINK, 2);
71
pack_start(_bottom_buttonbox, Gtk::PACK_SHRINK, 2);
74
Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlistaXAttr = _xattr_listview.get_selection();
76
// Selection change in XAttr
91
77
referenciaSeleccioLlistaXAttr->signal_changed().connect(
92
sigc::mem_fun(*this, &EicielXAttrWindow::canviDeSeleccioXAttr)
78
sigc::mem_fun(*this, &EicielXAttrWindow::_xattr_selection_change)
96
eliminarAtribut.signal_clicked().connect(
97
sigc::mem_fun(*this, &EicielXAttrWindow::eliminarAtributSeleccionat)
82
_b_remove_attribute.signal_clicked().connect(
83
sigc::mem_fun(*this, &EicielXAttrWindow::remove_selected_attribute)
101
afegirAtribut.signal_clicked().connect(
102
sigc::mem_fun(*this, &EicielXAttrWindow::afegirAtributSeleccionat)
87
_b_add_attribute.signal_clicked().connect(
88
sigc::mem_fun(*this, &EicielXAttrWindow::add_selected_attribute)
108
void EicielXAttrWindow::activacio(bool b)
96
void EicielXAttrWindow::set_active(bool b)
110
98
this->set_sensitive(b);
113
101
EicielXAttrWindow::~EicielXAttrWindow()
118
void EicielXAttrWindow::canviDeSeleccioXAttr()
106
void EicielXAttrWindow::_xattr_selection_change()
120
Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlista = vistaLlistaXAttr.get_selection();
108
Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlista = _xattr_listview.get_selection();
121
109
Gtk::TreeModel::iterator iter = referenciaSeleccioLlista->get_selected();
124
noHiHaSeleccioXAttr();
112
there_is_no_xattr_selection();
116
there_is_xattr_selection();
132
void EicielXAttrWindow::noHiHaSeleccioXAttr()
120
void EicielXAttrWindow::there_is_no_xattr_selection()
134
eliminarAtribut.set_sensitive(false);
122
_b_remove_attribute.set_sensitive(false);
137
void EicielXAttrWindow::hiHaSeleccioXAttr()
125
void EicielXAttrWindow::there_is_xattr_selection()
139
if (!this->nomesLectura)
127
if (!this->_readonly)
141
eliminarAtribut.set_sensitive(true);
129
_b_remove_attribute.set_sensitive(true);
145
void EicielXAttrWindow::nomAtributEditat(const Glib::ustring& path, const Glib::ustring& value)
133
void EicielXAttrWindow::set_name_edited_attribute(const Glib::ustring& path, const Glib::ustring& value)
147
Gtk::TreeModel::iterator iter = refLlistaXAttr->get_iter(path);
135
Gtk::TreeModel::iterator iter = _ref_xattr_list->get_iter(path);
151
139
Gtk::TreeModel::Row row(*iter);
154
142
if (value.empty())
159
// No admetem repetits
160
Gtk::TreeModel::Children children = refLlistaXAttr->children();
147
// We do not allow repeated
148
Gtk::TreeModel::Children children = _ref_xattr_list->children();
162
150
for(Gtk::TreeModel::Children::iterator iter = children.begin();
163
151
iter != children.end(); ++iter)
165
153
Gtk::TreeModel::Row irow(*iter);
167
if (irow[modelLlistaXAttr.nomAtribut] == value)
155
if (irow[_xattr_list_model._attribute_name] == value)
234
void EicielXAttrWindow::afegirAtributSeleccionat()
222
void EicielXAttrWindow::add_selected_attribute()
236
// Calculem el nom del nou atribut
224
// Compute the name of the new attribute
240
Glib::ustring nomNou;
228
Glib::ustring new_name;
245
nomNou = _("New attribute");
233
new_name = _("New attribute");
249
char* numCopsStr = new char[20];
251
snprintf(numCopsStr, 20, " (%d)", numCops);
252
numCopsStr[19] = '\0';
254
nomNou = _("New attribute");
255
nomNou += numCopsStr;
237
char* num_timesStr = new char[20];
239
snprintf(num_timesStr, 20, " (%d)", num_times);
240
num_timesStr[19] = '\0';
242
new_name = _("New attribute");
243
new_name += num_timesStr;
245
delete[] num_timesStr;
261
Gtk::TreeModel::Children children = refLlistaXAttr->children();
249
Gtk::TreeModel::Children children = _ref_xattr_list->children();
264
252
for(Gtk::TreeModel::Children::iterator iter = children.begin();
265
253
iter != children.end(); ++iter)
267
255
Gtk::TreeModel::Row irow(*iter);
269
if (irow[modelLlistaXAttr.nomAtribut] == nomNou)
257
if (irow[_xattr_list_model._attribute_name] == new_name)
279
Gtk::TreeModel::iterator iter = refLlistaXAttr->append();
266
Gtk::TreeModel::iterator iter = _ref_xattr_list->append();
280
267
Gtk::TreeModel::Row row;
283
row[modelLlistaXAttr.nomAtribut] = nomNou;
284
row[modelLlistaXAttr.valorAtribut] = _("New value");
270
row[_xattr_list_model._attribute_name] = new_name;
271
row[_xattr_list_model._attribute_value] = _("New value");
288
controlador->afegirAtribut(row[modelLlistaXAttr.nomAtribut],
289
row[modelLlistaXAttr.valorAtribut]);
291
Gtk::TreePath path = refLlistaXAttr->get_path(iter);
292
Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
294
vistaLlistaXAttr.set_cursor(path, *col, true);
275
_controller->add_attribute(row[_xattr_list_model._attribute_name],
276
row[_xattr_list_model._attribute_value]);
278
Gtk::TreePath path = _ref_xattr_list->get_path(iter);
279
Gtk::TreeViewColumn* col = _xattr_listview.get_column(0);
281
_xattr_listview.set_cursor(path, *col, true);
296
catch (GestorXAttrException e)
283
catch (XAttrManagerException e)
298
refLlistaXAttr->erase(iter);
285
_ref_xattr_list->erase(iter);
299
286
Glib::ustring s = _("Could not add attribute: ") + e.getMessage();
300
Gtk::MessageDialog afegirXAttr(s, false,
287
Gtk::MessageDialog addXAttr_message(s, false,
301
288
Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
289
addXAttr_message.run();
306
void EicielXAttrWindow::ompleAtributs(GestorXAttr::atributs_t llista)
293
void EicielXAttrWindow::fill_attributes(XAttrManager::attributes_t llista)
308
GestorXAttr::atributs_t::iterator it;
309
refLlistaXAttr->clear();
295
XAttrManager::attributes_t::iterator it;
296
_ref_xattr_list->clear();
311
298
Gtk::TreeModel::iterator iter;
312
299
Gtk::TreeModel::Row row;
314
301
for (it = llista.begin(); it != llista.end(); it++)
316
iter = refLlistaXAttr->append();
303
iter = _ref_xattr_list->append();
319
row[modelLlistaXAttr.nomAtribut] = it->first;
320
row[modelLlistaXAttr.valorAtribut] = it->second;
306
row[_xattr_list_model._attribute_name] = it->first;
307
row[_xattr_list_model._attribute_value] = it->second;
324
void EicielXAttrWindow::establirNomesLectura(bool b)
311
void EicielXAttrWindow::set_readonly(bool b)
328
afegirAtribut.set_sensitive(!b);
329
eliminarAtribut.set_sensitive(!b);
331
Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
315
_b_add_attribute.set_sensitive(!b);
316
_b_remove_attribute.set_sensitive(!b);
318
Gtk::TreeViewColumn* col = _xattr_listview.get_column(0);
332
319
Gtk::CellRenderer* cellRenderer = col->get_first_cell_renderer();
333
320
Gtk::CellRendererText* cellRendererText = dynamic_cast<Gtk::CellRendererText*>(cellRenderer);
334
321
cellRendererText->property_editable() = !b;
336
col = vistaLlistaXAttr.get_column(1);
323
col = _xattr_listview.get_column(1);
337
324
cellRenderer = col->get_first_cell_renderer();
338
325
cellRendererText = dynamic_cast<Gtk::CellRendererText*>(cellRenderer);
339
326
cellRendererText->property_editable() = !b;