source: src-qt4/pc-zmanager/dialogprop.cpp @ 6a5c6a1

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 6a5c6a1 was 6a5c6a1, checked in by Ken Moore <ken@…>, 9 months ago

Fix typo's and corrupt translation strings in pc-zmanager. Thanks to Jun Yamashiro for discovering them.

  • Property mode set to 100644
File size: 14.3 KB
Line 
1#include "dialogprop.h"
2#include "ui_dialogprop.h"
3#include <QTreeWidget>
4#include <QTreeWidgetItem>
5#include <QTreeWidgetItemIterator>
6#include <QComboBox>
7#include <QColor>
8
9DialogProp::DialogProp(QWidget *parent) :
10    QDialog(parent),
11    ui(new Ui::DialogProp)
12{
13    ui->setupUi(this);
14    ui->propList->setIconSize(QSize(32,32));
15    ui->propList->header()->setResizeMode(1,QHeaderView::Stretch);
16    ui->propList->header()->setResizeMode(0,QHeaderView::ResizeToContents);
17    InitAllProperties();
18
19}
20
21DialogProp::~DialogProp()
22{
23    delete ui;
24}
25
26
27void DialogProp::InitAllProperties()
28{
29    // INITIALIZATION CANNOT BE STATIC DUE TO CALLS TO tr() FOR PROPER TRANSLATION
30    // IT MUST BE DONE AT RUNTIME AND AS PART OF A CLASS BASED IN QOBJECT
31    zproperty tmp;
32
33    // ADD ONE BY ONE ALL VALID PROPERTIES. THE FOLLOWING CORRESPOND TO ZFS VERSION 28
34
35
36
37//     size
38    tmp.Name="size";
39    tmp.Description=tr("Total size of the storage pool.");
40    tmp.Flags=PROP_READONLY;
41    tmp.ValidOptions.clear();
42    AllProperties.append(tmp);
43//     capacity
44    tmp.Name="capacity";
45    tmp.Description=tr("Percentage of pool space used.");
46    tmp.Flags=PROP_READONLY;
47    tmp.ValidOptions.clear();
48    AllProperties.append(tmp);
49//     altroot
50    tmp.Name="altroot";
51    tmp.Description=tr("Alternate root directory. If set, this directory is prepended to any\n"
52                       "mount points within the pool. This can be used when examining an\n"
53                       "unknown pool where the mount points cannot be trusted, or in an\n"
54                       "alternate boot environment, where the typical paths are not valid.\n"
55                       "altroot is not a persistent property. It is valid only while the\n"
56                       "system is up.  Setting altroot defaults to using cachefile=none, though\n"
57                       "this may be overridden using an explicit setting.");
58    tmp.Flags=PROP_READONLY;    // HAS TO BE SET ONLY WHILE IMPORTING
59    tmp.ValidOptions.clear();
60    AllProperties.append(tmp);
61
62
63
64//     health
65
66    tmp.Name="health";
67    tmp.Description=tr("The current health of the pool.");
68    tmp.Flags=PROP_READONLY;
69    tmp.ValidOptions.clear();
70    AllProperties.append(tmp);
71
72//     guid
73
74    tmp.Name="guid";
75    tmp.Description=tr("A unique identifier for the pool.");
76    tmp.Flags=PROP_READONLY;
77    tmp.ValidOptions.clear();
78    AllProperties.append(tmp);
79
80//     version
81
82    tmp.Name="version";
83    tmp.Description=tr("The current on-disk version of the pool. This can be increased, but\n"
84                       "never decreased. The preferred method of updating pools is with the\n"
85                       "\"zpool upgrade\" command, though this property can be used when a\n"
86                       "specific version is needed for backwards compatibility. This property\n"
87                       "can be any number between 1 and the current version reported by\n"
88                       "\"zpool upgrade -v\".");
89    tmp.Flags=PROP_ISNUMBER;
90    tmp.ValidOptions.clear();
91    AllProperties.append(tmp);
92
93//     bootfs
94    tmp.Name="bootfs";
95    tmp.Description=tr("Identifies the default bootable dataset for the root pool. This\n"
96                       "property is expected to be set mainly by the installation and upgrade\n"
97                       "programs.");
98    tmp.Flags=PROP_ISPATH;
99    tmp.ValidOptions.clear();
100    AllProperties.append(tmp);
101
102
103
104//     delegation
105
106    tmp.Name="delegation";
107    tmp.Description=tr("Controls whether a non-privileged user is granted access based on the\n"
108                       "dataset permissions defined on the dataset. See zfs(8) for more\n"
109                       "information on ZFS delegated administration.");
110    tmp.Flags=PROP_ISOPTION;
111    tmp.ValidOptions.clear();
112    tmp.ValidOptions.append("on");
113    tmp.ValidOptions.append("off");
114    AllProperties.append(tmp);
115
116//     autoreplace
117    tmp.Name="autoreplace";
118    tmp.Description=tr("Controls automatic device replacement. If set to \"off\", device\n"
119                       "replacement must be initiated by the administrator by using the\n"
120                       "\"zpool replace\" command. If set to \"on\", any new device, found in the\n"
121                       "same physical location as a device that previously belonged to the\n"
122                       "pool, is automatically formatted and replaced. The default behavior\n"
123                       "is \"off\".  This property can also be referred to by its shortened\n"
124                       "column name, \"replace\".");
125    tmp.Flags=PROP_ISOPTION;
126    tmp.ValidOptions.clear();
127    tmp.ValidOptions.append("on");
128    tmp.ValidOptions.append("off");
129    AllProperties.append(tmp);
130//     cachefile
131    tmp.Name="cachefile";
132    tmp.Description=tr("Controls the location of where the pool configuration is cached.\n"
133                       "Discovering all pools on system startup requires a cached copy of the\n"
134                       "configuration data that is stored on the root file system. All pools\n"
135                       "in this cache are automatically imported when the system boots. Some\n"
136                       "environments, such as install and clustering, need to cache this\n"
137                       "information in a different location so that pools are not automatically\n"
138                       "imported. Setting this property caches the pool configuration\n"
139                       "in a different location that can later be imported with \"zpool import\n"
140                       "-c\".  Setting it to the special value \"none\" creates a temporary pool\n"
141                       "that is never cached, and the special value '' (empty string) uses\n"
142                       "the default location.");
143    tmp.Flags=PROP_ISPATH;
144    tmp.ValidOptions.clear();
145    AllProperties.append(tmp);
146
147
148//     failmode
149
150    tmp.Name="failmode";
151    tmp.Description=tr("Controls the system behavior in the event of catastrophic pool failure\n"
152                       "This condition is typically a result of a loss of connectivity\n"
153                       "to the underlying storage device(s) or a failure of all devices\n"
154                       "within the pool. The behavior of such an event is determined as follows\n"
155                       "wait\n"
156                       "Blocks all I/O access until the device connectivity is recovered\n"
157                       "and the errors are cleared. This is the default behavior\n"
158                       "continue\n"
159                       "Returns EIO to any new write I/O requests but allows reads to\n"
160                       "any of the remaining healthy devices. Any write requests that\n"
161                       "have yet to be committed to disk would be blocked.\n\n"
162
163                       "panic\n" 
164                       "Prints out a message to the console and generates a system\n"
165                       "crash dump.\n");
166    tmp.Flags=PROP_ISOPTION;
167    tmp.ValidOptions.clear();
168    tmp.ValidOptions.append("wait");
169    tmp.ValidOptions.append("continue");
170    tmp.ValidOptions.append("panic");
171    AllProperties.append(tmp);
172
173//     listsnapshots
174
175    tmp.Name="listsnapshots";
176    tmp.Description=tr("Controls whether information about snapshots associated with this\n"
177                       "pool is output when \"zfs list\" is run without the -t option. The\n"
178                       "default value is off.");
179    tmp.Flags=PROP_ISOPTION;
180    tmp.ValidOptions.clear();
181    tmp.ValidOptions.append("on");
182    tmp.ValidOptions.append("off");
183    AllProperties.append(tmp);
184
185//     autoexpand
186
187    tmp.Name="autoexpand";
188    tmp.Description=tr("Controls automatic pool expansion when the underlying LUN is grown.\n"
189                       "If set to \"on\", the pool will be resized according to the size of the\n"
190                       "expanded device. If the device is part of a mirror or raidz then all\n"
191                       "devices within that mirror/raidz group must be expanded before the\n"
192                       "new space is made available to the pool. The default behavior is\n"
193                       "\"off\".  This property can also be referred to by its shortened column\n"
194                       "name, expand.");
195    tmp.Flags=PROP_ISOPTION;
196    tmp.ValidOptions.clear();
197    tmp.ValidOptions.append("on");
198    tmp.ValidOptions.append("off");
199    AllProperties.append(tmp);
200
201
202//     dedupditto
203
204    tmp.Name="dedupditto";
205    tmp.Description=tr("Threshold for the number of block ditto copies. If the reference\n"
206                       "count for a deduplicated block increases above this number, a new\n"
207                       "ditto copy of this block is automatically stored. Default setting is\n"
208                       "0.");
209    tmp.Flags=PROP_ISNUMBER;
210    tmp.ValidOptions.clear();
211    AllProperties.append(tmp);
212
213
214
215//     dedupratio
216    tmp.Name="dedupratio";
217    tmp.Description=tr("The deduplication ratio specified for a pool, expressed as a multiplier. For\n"
218                       "example, a value of 1.76 indicates that 1.76 units of data were stored but\n"
219                       "only 1 unit of disk space was actually consumed. See zfs(8) for a description\n"
220                       "of the deduplication feature.");
221    tmp.Flags=PROP_READONLY;
222    tmp.ValidOptions.clear();
223    AllProperties.append(tmp);
224
225//     free
226
227    tmp.Name="free";
228    tmp.Description=tr("Number of blocks within the pool that are not allocated.");
229    tmp.Flags=PROP_READONLY;
230    tmp.ValidOptions.clear();
231    AllProperties.append(tmp);
232
233//     allocated
234    tmp.Name="allocated";
235    tmp.Description=tr("Amount of storage space within the pool that has been physically allocated.");
236    tmp.Flags=PROP_READONLY;
237    tmp.ValidOptions.clear();
238    AllProperties.append(tmp);
239//     readonly
240
241    tmp.Name="readonly";
242    tmp.Description=tr("If set to on, pool will be imported in read-only mode with the\n"
243                       "following restrictions:\n"
244
245                       "  *   Synchronous data in the intent log will not be accessible\n"
246
247                       "  *   Properties of the pool can not be changed\n"
248
249                       "  *   Datasets of this pool can only be mounted read-only\n"
250
251                       "  *   To write to a read-only pool, a export and import of the pool\n"
252                       "      is required.\n");
253    tmp.Flags=PROP_READONLY;    // CAN ONLY BE SET WHILE IMPORTING
254    tmp.ValidOptions.clear();
255    tmp.ValidOptions.append("on");
256    tmp.ValidOptions.append("off");
257    AllProperties.append(tmp);
258
259//     comment
260
261    tmp.Name="comment";
262    tmp.Description=tr("An arbitrary comment string set by the administrator.");
263    tmp.Flags=PROP_ISSTRING;
264    tmp.ValidOptions.clear();
265    AllProperties.append(tmp);
266
267
268//     expandsize
269
270    tmp.Name="expandsize";
271    tmp.Description=tr("This property has currently no value on FreeBSD.");
272    tmp.Flags=PROP_READONLY;
273    tmp.ValidOptions.clear();
274    AllProperties.append(tmp);
275
276}
277
278QString DialogProp::getPoolProperty(zpool_t *pool,QString Property)
279{
280    zprop_t tmp;
281
282    foreach(tmp,pool->Properties) {
283        if(tmp.Name==Property) {
284            if(tmp.Value=="-") return "";
285            else return tmp.Value;
286        }
287    }
288
289    return "";
290
291}
292
293void DialogProp::refreshList(zpool_t *pool)
294{
295
296    zproperty pr;
297    int index=0;
298
299    // PREVENT SIGNALS FROM BEING SENT
300    ui->propList->blockSignals(true);
301
302
303    foreach(pr,AllProperties)
304    {
305        QTreeWidgetItem *item=new QTreeWidgetItem(ui->propList);
306        if(!item) return;
307        item->setText(0,pr.Name);
308        item->setToolTip(0,pr.Description);
309        if(pr.Flags&PROP_ISOPTION) {
310            // TODO: ADD A DROPDOWN BOX HERE
311            QComboBox *opt=new QComboBox();
312            if(!opt) return;    // EXIT IF OUT OF MEMORY
313            opt->setEditable(false);
314            opt->addItems(pr.ValidOptions);
315            opt->setItemData(0,QVariant(index));
316
317            opt->setCurrentIndex(pr.ValidOptions.indexOf(QRegExp(getPoolProperty(pool,pr.Name))));
318            ui->propList->setItemWidget(item,1,opt);
319            connect(opt,SIGNAL(currentIndexChanged(int)),SLOT(on_propList_comboChanged(int)));
320        }
321        else{
322        item->setText(1,getPoolProperty(pool,pr.Name));
323        }
324        if(pr.Flags&PROP_READONLY) {
325            item->setIcon(0,QIcon(":/icons/user-busy-small-32.png"));
326        }
327        else {
328            item->setIcon(0,QIcon(":/icons/user-online-small-32.png"));
329            item->setFlags(item->flags()|Qt::ItemIsEditable);
330        }
331
332
333        ++index;
334
335    }
336
337
338    // RE-ENABLE SIGNALS
339    ui->propList->blockSignals(false);
340
341
342}
343
344void DialogProp::on_propList_itemDoubleClicked(QTreeWidgetItem *item, int column)
345{
346    Q_UNUSED(column);
347
348        ui->propList->editItem(item,1);
349}
350
351
352QStringList DialogProp::getAllChangedProps()
353{
354    QStringList result;
355    zproperty pr;
356
357    foreach(pr,AllProperties)
358    {
359        if( !(pr.Flags&PROP_READONLY) && (pr.Flags&PROP_CHANGED))
360        {
361            result.append(pr.Name);
362        }
363    }
364    return result;
365}
366
367QStringList DialogProp::getAllChangedValues()
368{
369    QStringList result;
370    zproperty pr;
371
372    foreach(pr,AllProperties)
373    {
374        if( !(pr.Flags&PROP_READONLY) && (pr.Flags&PROP_CHANGED))
375        {
376            QTreeWidgetItemIterator it(ui->propList);
377            while(*it) {
378                if((*it)->text(0)==pr.Name) {
379                    if(pr.Flags&PROP_ISOPTION) {
380                        // READ IT FROM THE COMBO WIDGET
381                        QComboBox *combo=(QComboBox *)ui->propList->itemWidget((*it),1);
382                        result.append(combo->currentText());
383                    }
384                    else {
385                        // READ VALUE DIRECTLY
386                        result.append((*it)->text(1));
387                    }
388                }
389                ++it;
390            }
391        }
392    }
393    return result;
394}
395
396void DialogProp::on_propList_itemChanged(QTreeWidgetItem *item, int column)
397{
398    Q_UNUSED(column);
399
400    QString prop=item->text(0);
401
402    QList<zproperty>::iterator pr=AllProperties.begin();
403
404    while(pr!=AllProperties.end())
405    {
406        if((*pr).Name==prop) { (*pr).Flags|=PROP_CHANGED; return; }
407    ++pr;
408    }
409}
410
411
412void DialogProp::on_propList_comboChanged(int index)
413{
414    Q_UNUSED(index);
415
416    QComboBox *caller=(QComboBox *)sender();
417    int idx=caller->itemData(0).toInt(),compare;
418
419    QTreeWidgetItemIterator it(ui->propList);
420    compare=0;
421    while((*it)) {
422        if(compare==idx) on_propList_itemChanged((*it),1);
423        ++compare;
424        ++it;
425    }
426
427    return;
428}
Note: See TracBrowser for help on using the repository browser.