source: src-qt4/pc-zmanager/dialogprop.cpp @ 125dbc9

9.2-releaseenter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since 125dbc9 was 125dbc9, checked in by Kris Moore <kris@…>, 20 months ago

Welcome the new 'pc-zmanager' for ZFS & Disk Management

A HUGE Thank You to: Claudio L <claudio@…>

Update pkg-plist and add it to the control panel

  • Property mode set to 100644
File size: 14.4 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. Dis‐\n"
133                       "covering 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 automati‐\n"
138                       "cally 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 fail‐\n"
152                       "ure. 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 fol‐\n"
155                       "lows:\n\n"
156
157                       "wait    Blocks all I/O access until the device connectivity is recov‐\n"
158                       "        ered and the errors are cleared.  This is the default behav‐\n"
159                       "        ior.\n\n"
160
161                       "continue\n"
162                       "        Returns EIO to any new write I/O requests but allows reads to\n"
163                       "        any of the remaining healthy devices. Any write requests that\n"
164                       "        have yet to be committed to disk would be blocked.\n\n"
165
166                       "panic   Prints out a message to the console and generates a system\n"
167                       "        crash dump.\n");
168    tmp.Flags=PROP_ISOPTION;
169    tmp.ValidOptions.clear();
170    tmp.ValidOptions.append("wait");
171    tmp.ValidOptions.append("continue");
172    tmp.ValidOptions.append("panic");
173    AllProperties.append(tmp);
174
175//     listsnapshots
176
177    tmp.Name="listsnapshots";
178    tmp.Description=tr("Controls whether information about snapshots associated with this\n"
179                       "pool is output when \"zfs list\" is run without the -t option. The\n"
180                       "default value is off.");
181    tmp.Flags=PROP_ISOPTION;
182    tmp.ValidOptions.clear();
183    tmp.ValidOptions.append("on");
184    tmp.ValidOptions.append("off");
185    AllProperties.append(tmp);
186
187//     autoexpand
188
189    tmp.Name="autoexpand";
190    tmp.Description=tr("Controls automatic pool expansion when the underlying LUN is grown.\n"
191                       "If set to \"on\", the pool will be resized according to the size of the\n"
192                       "expanded device. If the device is part of a mirror or raidz then all\n"
193                       "devices within that mirror/raidz group must be expanded before the\n"
194                       "new space is made available to the pool. The default behavior is\n"
195                       "\"off\".  This property can also be referred to by its shortened column\n"
196                       "name, expand.");
197    tmp.Flags=PROP_ISOPTION;
198    tmp.ValidOptions.clear();
199    tmp.ValidOptions.append("on");
200    tmp.ValidOptions.append("off");
201    AllProperties.append(tmp);
202
203
204//     dedupditto
205
206    tmp.Name="dedupditto";
207    tmp.Description=tr("Threshold for the number of block ditto copies. If the reference\n"
208                       "count for a deduplicated block increases above this number, a new\n"
209                       "ditto copy of this block is automatically stored. Default setting is\n"
210                       "0.");
211    tmp.Flags=PROP_ISNUMBER;
212    tmp.ValidOptions.clear();
213    AllProperties.append(tmp);
214
215
216
217//     dedupratio
218    tmp.Name="dedupratio";
219    tmp.Description=tr("The deduplication ratio specified for a pool, expressed as a multiplier. For\n"
220                       "example, a value of 1.76 indicates that 1.76 units of data were stored but\n"
221                       "only 1 unit of disk space was actually consumed. See zfs(8) for a description\n"
222                       "of the deduplication feature.");
223    tmp.Flags=PROP_READONLY;
224    tmp.ValidOptions.clear();
225    AllProperties.append(tmp);
226
227//     free
228
229    tmp.Name="free";
230    tmp.Description=tr("Number of blocks within the pool that are not allocated.");
231    tmp.Flags=PROP_READONLY;
232    tmp.ValidOptions.clear();
233    AllProperties.append(tmp);
234
235//     allocated
236    tmp.Name="allocated";
237    tmp.Description=tr("Amount of storage space within the pool that has been physically allocated.");
238    tmp.Flags=PROP_READONLY;
239    tmp.ValidOptions.clear();
240    AllProperties.append(tmp);
241//     readonly
242
243    tmp.Name="readonly";
244    tmp.Description=tr("If set to on, pool will be imported in read-only mode with the fol‐\n"
245                       "lowing restrictions:\n"
246
247                       "  ·   Synchronous data in the intent log will not be accessible\n"
248
249                       "  ·   Properties of the pool can not be changed\n"
250
251                       "  ·   Datasets of this pool can only be mounted read-only\n"
252
253                       "  ·   To write to a read-only pool, a export and import of the pool\n"
254                       "      is required.\n");
255    tmp.Flags=PROP_READONLY;    // CAN ONLY BE SET WHILE IMPORTING
256    tmp.ValidOptions.clear();
257    tmp.ValidOptions.append("on");
258    tmp.ValidOptions.append("off");
259    AllProperties.append(tmp);
260
261//     comment
262
263    tmp.Name="comment";
264    tmp.Description=tr("An arbitrary comment string set by the administrator.");
265    tmp.Flags=PROP_ISSTRING;
266    tmp.ValidOptions.clear();
267    AllProperties.append(tmp);
268
269
270//     expandsize
271
272    tmp.Name="expandsize";
273    tmp.Description=tr("This property has currently no value on FreeBSD.");
274    tmp.Flags=PROP_READONLY;
275    tmp.ValidOptions.clear();
276    AllProperties.append(tmp);
277
278}
279
280QString DialogProp::getPoolProperty(zpool_t *pool,QString Property)
281{
282    zprop_t tmp;
283
284    foreach(tmp,pool->Properties) {
285        if(tmp.Name==Property) {
286            if(tmp.Value=="-") return "";
287            else return tmp.Value;
288        }
289    }
290
291    return "";
292
293}
294
295void DialogProp::refreshList(zpool_t *pool)
296{
297
298    zproperty pr;
299    int index=0;
300
301    // PREVENT SIGNALS FROM BEING SENT
302    ui->propList->blockSignals(true);
303
304
305    foreach(pr,AllProperties)
306    {
307        QTreeWidgetItem *item=new QTreeWidgetItem(ui->propList);
308        if(!item) return;
309        item->setText(0,pr.Name);
310        item->setToolTip(0,pr.Description);
311        if(pr.Flags&PROP_ISOPTION) {
312            // TODO: ADD A DROPDOWN BOX HERE
313            QComboBox *opt=new QComboBox();
314            if(!opt) return;    // EXIT IF OUT OF MEMORY
315            opt->setEditable(false);
316            opt->addItems(pr.ValidOptions);
317            opt->setItemData(0,QVariant(index));
318
319            opt->setCurrentIndex(pr.ValidOptions.indexOf(QRegExp(getPoolProperty(pool,pr.Name))));
320            ui->propList->setItemWidget(item,1,opt);
321            connect(opt,SIGNAL(currentIndexChanged(int)),SLOT(on_propList_comboChanged(int)));
322        }
323        else{
324        item->setText(1,getPoolProperty(pool,pr.Name));
325        }
326        if(pr.Flags&PROP_READONLY) {
327            item->setIcon(0,QIcon(":/icons/user-busy-small-32.png"));
328        }
329        else {
330            item->setIcon(0,QIcon(":/icons/user-online-small-32.png"));
331            item->setFlags(item->flags()|Qt::ItemIsEditable);
332        }
333
334
335        ++index;
336
337    }
338
339
340    // RE-ENABLE SIGNALS
341    ui->propList->blockSignals(false);
342
343
344}
345
346void DialogProp::on_propList_itemDoubleClicked(QTreeWidgetItem *item, int column)
347{
348    Q_UNUSED(column);
349
350        ui->propList->editItem(item,1);
351}
352
353
354QStringList DialogProp::getAllChangedProps()
355{
356    QStringList result;
357    zproperty pr;
358
359    foreach(pr,AllProperties)
360    {
361        if( !(pr.Flags&PROP_READONLY) && (pr.Flags&PROP_CHANGED))
362        {
363            result.append(pr.Name);
364        }
365    }
366    return result;
367}
368
369QStringList DialogProp::getAllChangedValues()
370{
371    QStringList result;
372    zproperty pr;
373
374    foreach(pr,AllProperties)
375    {
376        if( !(pr.Flags&PROP_READONLY) && (pr.Flags&PROP_CHANGED))
377        {
378            QTreeWidgetItemIterator it(ui->propList);
379            while(*it) {
380                if((*it)->text(0)==pr.Name) {
381                    if(pr.Flags&PROP_ISOPTION) {
382                        // READ IT FROM THE COMBO WIDGET
383                        QComboBox *combo=(QComboBox *)ui->propList->itemWidget((*it),1);
384                        result.append(combo->currentText());
385                    }
386                    else {
387                        // READ VALUE DIRECTLY
388                        result.append((*it)->text(1));
389                    }
390                }
391                ++it;
392            }
393        }
394    }
395    return result;
396}
397
398void DialogProp::on_propList_itemChanged(QTreeWidgetItem *item, int column)
399{
400    Q_UNUSED(column);
401
402    QString prop=item->text(0);
403
404    QList<zproperty>::iterator pr=AllProperties.begin();
405
406    while(pr!=AllProperties.end())
407    {
408        if((*pr).Name==prop) { (*pr).Flags|=PROP_CHANGED; return; }
409    ++pr;
410    }
411}
412
413
414void DialogProp::on_propList_comboChanged(int index)
415{
416    Q_UNUSED(index);
417
418    QComboBox *caller=(QComboBox *)sender();
419    int idx=caller->itemData(0).toInt(),compare;
420
421    QTreeWidgetItemIterator it(ui->propList);
422    compare=0;
423    while((*it)) {
424        if(compare==idx) on_propList_itemChanged((*it),1);
425        ++compare;
426        ++it;
427    }
428
429    return;
430}
Note: See TracBrowser for help on using the repository browser.