~ubuntu-branches/ubuntu/trusty/eiciel/trusty-proposed

« back to all changes in this revision

Viewing changes to src/eiciel_xattr_window.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2010-06-04 02:38:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100604023802-jp2v6c9uviiioc5z
* New upstream release.
* debian/patches/02-gio.patch
  - Removed, merged upstream.
* debian/patches/03-no-libgnomeui.patch
  - Removed, merged upstream.
* debian/patches/01-fix-gettext-translations.patch
  - Fix gettext translations by using dgettext and specifying the correct
    domainname.
* debian/patches/02-de-po.patch
  - Update and complete German translation.
* debian/rules
  - Remove de.gmo on clean and rebuild it on build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    Eiciel - GNOME editor of ACL file permissions.
3
 
    Copyright (C) 2004-2005 Roger Ferrer Ib��ez
 
3
    Copyright (C) 2004-2010 Roger Ferrer Ib��ez
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
6
6
    it under the terms of the GNU General Public License as published by
14
14
 
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
18
18
*/
19
19
 
20
20
#include "eiciel_xattr_window.hpp"
21
21
 
22
 
EicielXAttrWindow::EicielXAttrWindow(EicielXAttrControler* contr)
23
 
        : controlador(contr), 
24
 
        afegirAtribut(Gtk::Stock::ADD),
25
 
        eliminarAtribut(Gtk::Stock::REMOVE)
 
22
EicielXAttrWindow::EicielXAttrWindow(EicielXAttrController* contr)
 
23
        : _controller(contr), 
 
24
        _b_add_attribute(Gtk::Stock::ADD),
 
25
        _b_remove_attribute(Gtk::Stock::REMOVE)
26
26
{
27
 
        refLlistaXAttr = Gtk::ListStore::create(modelLlistaXAttr);
 
27
        _ref_xattr_list = Gtk::ListStore::create(_xattr_list_model);
28
28
 
29
 
        controlador->finestra = this;
 
29
        _controller->_window = this;
30
30
 
31
31
        set_border_width(4);
32
 
        vistaLlistaXAttr.set_size_request(100, 100);
33
 
 
34
 
        refLlistaXAttr->set_sort_column(modelLlistaXAttr.nomAtribut, Gtk::SORT_ASCENDING);
35
 
 
36
 
        vistaLlistaXAttr.set_reallocate_redraws();
37
 
        vistaLlistaXAttr.set_model(refLlistaXAttr);
38
 
 
39
 
        // Ara s'afegeixen les columnes i es vinculen amb el model
40
 
    vistaLlistaXAttr.append_column(_("Name"), modelLlistaXAttr.nomAtribut);
41
 
 
42
 
        // Aquesta columna requereix opcions especials
43
 
        Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
 
32
        _xattr_listview.set_size_request(100, 100);
 
33
 
 
34
        _ref_xattr_list->set_sort_column(_xattr_list_model._attribute_name, Gtk::SORT_ASCENDING);
 
35
 
 
36
        _xattr_listview.set_reallocate_redraws();
 
37
        _xattr_listview.set_model(_ref_xattr_list);
 
38
 
 
39
        // Add columns and link them to the model
 
40
    _xattr_listview.append_column(_("Name"), _xattr_list_model._attribute_name);
 
41
 
 
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;
47
47
 
48
48
        cellRendererText->signal_edited().connect(
49
 
                        sigc::mem_fun(*this, &EicielXAttrWindow::nomAtributEditat)
 
49
                        sigc::mem_fun(*this, &EicielXAttrWindow::set_name_edited_attribute)
50
50
                        );
51
51
 
52
 
    vistaLlistaXAttr.append_column_editable(_("Value"), modelLlistaXAttr.valorAtribut);
 
52
    _xattr_listview.append_column_editable(_("Value"), _xattr_list_model._attribute_value);
53
53
 
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;
58
58
 
59
59
        cellRendererText->signal_edited().connect(
60
 
                        sigc::mem_fun(*this, &EicielXAttrWindow::valorAtributEditat)
 
60
                        sigc::mem_fun(*this, &EicielXAttrWindow::set_value_edited_attribute)
61
61
                        );
62
62
 
63
 
        contenidorVistaLlistaXAttr.add(vistaLlistaXAttr);
64
 
        contenidorVistaLlistaXAttr.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
65
 
 
66
 
        pack_start(contenidorVistaLlistaXAttr, Gtk::PACK_EXPAND_WIDGET, 2);
67
 
 
68
 
        botoneraInferior.pack_start(afegirAtribut, Gtk::PACK_SHRINK, 2);
69
 
        botoneraInferior.pack_start(eliminarAtribut, Gtk::PACK_SHRINK, 2);
70
 
 
71
 
        pack_start(botoneraInferior, Gtk::PACK_SHRINK, 2);
72
 
 
73
 
        // Atributs de prova
74
 
        // Gtk::TreeModel::iterator iter = refLlistaXAttr->append();
75
 
        // Gtk::TreeModel::Row row;
76
 
        // row = *iter;
77
 
 
78
 
        // row[modelLlistaXAttr.nomAtribut] = "rev";
79
 
        // row[modelLlistaXAttr.valorAtribut] = "245";
80
 
 
81
 
        // iter = refLlistaXAttr->append();
82
 
        // row = *iter;
83
 
 
84
 
        // row[modelLlistaXAttr.nomAtribut] = "Confidencial";
85
 
        // row[modelLlistaXAttr.valorAtribut] = "No";
86
 
 
87
 
        // Vinculaci� dels senyals
88
 
        Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlistaXAttr = vistaLlistaXAttr.get_selection();
89
 
 
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);
 
65
 
 
66
        pack_start(_xattr_listview_container, Gtk::PACK_EXPAND_WIDGET, 2);
 
67
 
 
68
        _bottom_buttonbox.pack_start(_b_add_attribute, Gtk::PACK_SHRINK, 2);
 
69
        _bottom_buttonbox.pack_start(_b_remove_attribute, Gtk::PACK_SHRINK, 2);
 
70
 
 
71
        pack_start(_bottom_buttonbox, Gtk::PACK_SHRINK, 2);
 
72
 
 
73
        // Signal binding
 
74
        Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlistaXAttr = _xattr_listview.get_selection();
 
75
 
 
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)
93
79
                        );
94
80
 
95
 
        // Boto eliminar
96
 
        eliminarAtribut.signal_clicked().connect(
97
 
                        sigc::mem_fun(*this, &EicielXAttrWindow::eliminarAtributSeleccionat)
 
81
        // Remove button
 
82
        _b_remove_attribute.signal_clicked().connect(
 
83
                        sigc::mem_fun(*this, &EicielXAttrWindow::remove_selected_attribute)
98
84
                        );
99
85
        
100
 
        // Boto editar
101
 
        afegirAtribut.signal_clicked().connect(
102
 
                        sigc::mem_fun(*this, &EicielXAttrWindow::afegirAtributSeleccionat)
 
86
        // Edit button
 
87
        _b_add_attribute.signal_clicked().connect(
 
88
                        sigc::mem_fun(*this, &EicielXAttrWindow::add_selected_attribute)
103
89
                        );
104
90
 
105
 
        activacio(false);
 
91
    show_all();
 
92
 
 
93
        set_active(false);
106
94
}
107
95
 
108
 
void EicielXAttrWindow::activacio(bool b)
 
96
void EicielXAttrWindow::set_active(bool b)
109
97
{
110
98
        this->set_sensitive(b);
111
99
}
112
100
 
113
101
EicielXAttrWindow::~EicielXAttrWindow()
114
102
{
115
 
        delete controlador;
 
103
        delete _controller;
116
104
}
117
105
 
118
 
void EicielXAttrWindow::canviDeSeleccioXAttr()
 
106
void EicielXAttrWindow::_xattr_selection_change()
119
107
{
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();
122
110
        if (!iter)
123
111
        {
124
 
                noHiHaSeleccioXAttr();
 
112
                there_is_no_xattr_selection();
125
113
        }
126
114
        else
127
115
        {
128
 
                hiHaSeleccioXAttr();
 
116
                there_is_xattr_selection();
129
117
        }
130
118
}
131
119
 
132
 
void EicielXAttrWindow::noHiHaSeleccioXAttr()
 
120
void EicielXAttrWindow::there_is_no_xattr_selection()
133
121
{
134
 
        eliminarAtribut.set_sensitive(false);
 
122
        _b_remove_attribute.set_sensitive(false);
135
123
}
136
124
 
137
 
void EicielXAttrWindow::hiHaSeleccioXAttr()
 
125
void EicielXAttrWindow::there_is_xattr_selection()
138
126
{
139
 
        if (!this->nomesLectura)
 
127
        if (!this->_readonly)
140
128
        {
141
 
                eliminarAtribut.set_sensitive(true);
 
129
                _b_remove_attribute.set_sensitive(true);
142
130
        }
143
131
}
144
132
 
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)
146
134
{
147
 
        Gtk::TreeModel::iterator iter = refLlistaXAttr->get_iter(path);
 
135
        Gtk::TreeModel::iterator iter = _ref_xattr_list->get_iter(path);
148
136
 
149
137
        if (iter)
150
138
        {
151
139
                Gtk::TreeModel::Row row(*iter);
152
140
 
153
 
                // No pot estar buit
 
141
                // Can't be empty
154
142
                if (value.empty())
155
143
                {
156
144
                        return;
157
145
                }
158
146
 
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();
161
149
 
162
150
                for(Gtk::TreeModel::Children::iterator iter = children.begin(); 
163
151
                                iter != children.end(); ++iter)
164
152
                {
165
153
                        Gtk::TreeModel::Row irow(*iter);
166
154
 
167
 
                        if (irow[modelLlistaXAttr.nomAtribut] == value)
 
155
                        if (irow[_xattr_list_model._attribute_name] == value)
168
156
                        {
169
157
                                return;
170
158
                        }
172
160
 
173
161
                try
174
162
                {
175
 
                        controlador->modificarNomAtribut(row[modelLlistaXAttr.nomAtribut], value);
176
 
                        row[modelLlistaXAttr.nomAtribut] = value;
 
163
                        _controller->update_attribute_name(row[_xattr_list_model._attribute_name], value);
 
164
                        row[_xattr_list_model._attribute_name] = value;
177
165
                }
178
 
                catch (GestorXAttrException e)
 
166
                catch (XAttrManagerException e)
179
167
                {
180
168
                        Glib::ustring s = _("Could not rename attribute name: ") + e.getMessage();
181
169
                        Gtk::MessageDialog renombrarXAttr(s, false,
185
173
        }
186
174
}
187
175
 
188
 
void EicielXAttrWindow::valorAtributEditat(const Glib::ustring& path, const Glib::ustring& value)
 
176
void EicielXAttrWindow::set_value_edited_attribute(const Glib::ustring& path, const Glib::ustring& value)
189
177
{
190
 
        Gtk::TreeModel::iterator iter = refLlistaXAttr->get_iter(path);
 
178
        Gtk::TreeModel::iterator iter = _ref_xattr_list->get_iter(path);
191
179
 
192
180
        if (iter)
193
181
        {
194
182
                Gtk::TreeModel::Row row(*iter);
195
183
                try
196
184
                {
197
 
                        controlador->actualitzarValorAtribut(row[modelLlistaXAttr.nomAtribut], value);
198
 
                        row[modelLlistaXAttr.valorAtribut] = value;
 
185
                        _controller->update_attribute_value(row[_xattr_list_model._attribute_name], value);
 
186
                        row[_xattr_list_model._attribute_value] = value;
199
187
                }
200
 
                catch (GestorXAttrException e)
 
188
                catch (XAttrManagerException e)
201
189
                {
202
190
                        Glib::ustring s = _("Could not change attribute value: ") + e.getMessage();
203
191
                        Gtk::MessageDialog editarXAttr(s, false,
207
195
        }
208
196
}
209
197
 
210
 
void EicielXAttrWindow::eliminarAtributSeleccionat()
 
198
void EicielXAttrWindow::remove_selected_attribute()
211
199
{
212
 
        Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlista = vistaLlistaXAttr.get_selection();
 
200
        Glib::RefPtr<Gtk::TreeSelection> referenciaSeleccioLlista = _xattr_listview.get_selection();
213
201
        Gtk::TreeModel::iterator iter = referenciaSeleccioLlista->get_selected();
214
202
 
215
203
        if (iter)
218
206
 
219
207
                try
220
208
                {
221
 
                        controlador->eliminarAtribut(row[modelLlistaXAttr.nomAtribut]);
222
 
                        refLlistaXAttr->erase(iter);
 
209
                        _controller->remove_attribute(row[_xattr_list_model._attribute_name]);
 
210
                        _ref_xattr_list->erase(iter);
223
211
                }
224
 
                catch (GestorXAttrException e)
 
212
                catch (XAttrManagerException e)
225
213
                {
226
214
                        Glib::ustring s = _("Could not remove attribute: ") + e.getMessage();
227
215
                        Gtk::MessageDialog eliminarXAttr(s, false,
231
219
        }
232
220
}
233
221
 
234
 
void EicielXAttrWindow::afegirAtributSeleccionat()
 
222
void EicielXAttrWindow::add_selected_attribute()
235
223
{
236
 
        // Calculem el nom del nou atribut
237
 
        bool repetit;
238
 
        int numCops = 0;
 
224
        // Compute the name of the new attribute
 
225
        bool repeated;
 
226
        int num_times = 0;
239
227
 
240
 
        Glib::ustring nomNou;
 
228
        Glib::ustring new_name;
241
229
 
242
230
        do {
243
 
                if (numCops == 0)
 
231
                if (num_times == 0)
244
232
                {
245
 
                        nomNou = _("New attribute");
 
233
                        new_name = _("New attribute");
246
234
                }
247
235
                else
248
236
                {
249
 
                        char* numCopsStr = new char[20];
250
 
 
251
 
                        snprintf(numCopsStr, 20, " (%d)", numCops);
252
 
                        numCopsStr[19] = '\0';
253
 
 
254
 
                        nomNou = _("New attribute");
255
 
                        nomNou += numCopsStr;
256
 
 
257
 
                        delete[] numCopsStr;
 
237
                        char* num_timesStr = new char[20];
 
238
 
 
239
                        snprintf(num_timesStr, 20, " (%d)", num_times);
 
240
                        num_timesStr[19] = '\0';
 
241
 
 
242
                        new_name = _("New attribute");
 
243
                        new_name += num_timesStr;
 
244
 
 
245
                        delete[] num_timesStr;
258
246
                }
259
 
                numCops++;
260
 
 
261
 
                Gtk::TreeModel::Children children = refLlistaXAttr->children();
262
 
 
263
 
                repetit = false;
 
247
                num_times++;
 
248
 
 
249
                Gtk::TreeModel::Children children = _ref_xattr_list->children();
 
250
 
 
251
                repeated = false;
264
252
                for(Gtk::TreeModel::Children::iterator iter = children.begin(); 
265
253
                                iter != children.end(); ++iter)
266
254
                {
267
255
                        Gtk::TreeModel::Row irow(*iter);
268
256
 
269
 
                        if (irow[modelLlistaXAttr.nomAtribut] == nomNou)
 
257
                        if (irow[_xattr_list_model._attribute_name] == new_name)
270
258
                        {
271
 
                                repetit = true;
 
259
                                repeated = true;
272
260
                                break;
273
261
                        }
274
262
                }
275
263
        }
276
 
        while (repetit);
277
 
 
 
264
        while (repeated);
278
265
        
279
 
        Gtk::TreeModel::iterator iter = refLlistaXAttr->append();
 
266
        Gtk::TreeModel::iterator iter = _ref_xattr_list->append();
280
267
        Gtk::TreeModel::Row row;
281
268
        row = *iter;
282
269
 
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");
285
272
 
286
273
        try
287
274
        {
288
 
                controlador->afegirAtribut(row[modelLlistaXAttr.nomAtribut],
289
 
                                row[modelLlistaXAttr.valorAtribut]);
290
 
 
291
 
                Gtk::TreePath path = refLlistaXAttr->get_path(iter);
292
 
                Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
293
 
 
294
 
                vistaLlistaXAttr.set_cursor(path, *col, true);
 
275
                _controller->add_attribute(row[_xattr_list_model._attribute_name],
 
276
                                row[_xattr_list_model._attribute_value]);
 
277
 
 
278
                Gtk::TreePath path = _ref_xattr_list->get_path(iter);
 
279
                Gtk::TreeViewColumn* col = _xattr_listview.get_column(0);
 
280
 
 
281
                _xattr_listview.set_cursor(path, *col, true);
295
282
        }
296
 
        catch (GestorXAttrException e)
 
283
        catch (XAttrManagerException e)
297
284
        {
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);
302
 
                afegirXAttr.run();
 
289
                addXAttr_message.run();
303
290
        }
304
291
}
305
292
 
306
 
void EicielXAttrWindow::ompleAtributs(GestorXAttr::atributs_t llista)
 
293
void EicielXAttrWindow::fill_attributes(XAttrManager::attributes_t llista)
307
294
{
308
 
        GestorXAttr::atributs_t::iterator it;
309
 
        refLlistaXAttr->clear();
 
295
        XAttrManager::attributes_t::iterator it;
 
296
        _ref_xattr_list->clear();
310
297
 
311
298
        Gtk::TreeModel::iterator iter;
312
299
        Gtk::TreeModel::Row row;
313
300
        
314
301
        for (it = llista.begin(); it != llista.end(); it++)
315
302
        {
316
 
                iter = refLlistaXAttr->append();
 
303
                iter = _ref_xattr_list->append();
317
304
                row = *iter;
318
305
                
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;
321
308
        }
322
309
}
323
310
 
324
 
void EicielXAttrWindow::establirNomesLectura(bool b)
 
311
void EicielXAttrWindow::set_readonly(bool b)
325
312
{
326
 
        nomesLectura = b;
327
 
 
328
 
        afegirAtribut.set_sensitive(!b);
329
 
        eliminarAtribut.set_sensitive(!b);
330
 
 
331
 
        Gtk::TreeViewColumn* col = vistaLlistaXAttr.get_column(0);
 
313
        _readonly = b;
 
314
 
 
315
        _b_add_attribute.set_sensitive(!b);
 
316
        _b_remove_attribute.set_sensitive(!b);
 
317
 
 
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;
335
322
 
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;