[PC-BSD Commits] r5125 - pcbsd/trunk/SysInstaller
svn at pcbsd.org
svn at pcbsd.org
Mon Nov 23 13:22:59 PST 2009
Author: kris
Date: 2009-11-23 13:22:59 -0800 (Mon, 23 Nov 2009)
New Revision: 5125
Modified:
pcbsd/trunk/SysInstaller/dialogFileSystem.cpp
pcbsd/trunk/SysInstaller/dialogFileSystem.h
pcbsd/trunk/SysInstaller/dialogFileSystem.ui
pcbsd/trunk/SysInstaller/sys-diskwidget.cpp
Log:
Added all the support for sanity checking of the add partition dialog, started getting all
checks into place to make sure you don't add conflicting partitions
Modified: pcbsd/trunk/SysInstaller/dialogFileSystem.cpp
===================================================================
--- pcbsd/trunk/SysInstaller/dialogFileSystem.cpp 2009-11-23 19:01:02 UTC (rev 5124)
+++ pcbsd/trunk/SysInstaller/dialogFileSystem.cpp 2009-11-23 21:22:59 UTC (rev 5125)
@@ -12,6 +12,7 @@
void dialogFileSystem::dialogInit(QList<QStringList> disks, QList<QStringList> disklayout)
{
+
// Connnect our slots
connect(pushCancel, SIGNAL(clicked()), this, SLOT(slotPushCancel()));
connect(pushSave, SIGNAL(clicked()), this, SLOT(slotPushSave()));
@@ -20,6 +21,7 @@
connect(horizontalSizeSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotSliderChangedValue(int)));
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
+
// Add the file-system types
comboDiskType->addItem("UFS");
comboDiskType->addItem("UFS+S");
@@ -35,21 +37,76 @@
sysDisks = disks;
sysFinalDiskLayout = disklayout;
+
+ // Add the disks to the combobox
+ addDisksSane();
+
+
+ // Check if we should enable the save slot
+ slotCheckSanity();
+
+ // Connect all the sanity checking slots
+ connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(slotCheckSanity()));
+ connect(comboDiskSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckSanity()));
+ connect(comboDiskType, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckSanity()));
+ connect(comboMirrorDisk, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckSanity()));
+ connect(lineEditMount, SIGNAL(textChanged ( const QString &)), this, SLOT(slotCheckSanity()));
+
+}
+
+// Function which checks that we don't have any partitions selected for this disk when using a partition
+bool dialogFileSystem::sliceNoExistingDiskPartition(QString Device)
+{
+ QString Disk = Device;
+ Disk.truncate(Disk.size() -2);
+ QString Slice = Device;
+ Slice = Slice.remove(0, Slice.size() -2);
+
+ // Loop through the disk layouts, and check if we have any partitions on this device
+ for (int i=0; i < sysFinalDiskLayout.count(); ++i) {
+ // Check if this drive already has some partitions created for it
+ if ( sysFinalDiskLayout.at(i).at(0) == Disk && \
+ ( sysFinalDiskLayout.at(i).at(1) == Slice || sysFinalDiskLayout.at(i).at(1) == "ALL" ) )
+ return false;
+ }
+ return true;
+}
+
+// Function which checks that we don't have any partitions on this disk already specified
+bool dialogFileSystem::diskNoExistingPartition(QString Device)
+{
+ // Loop through the disk layouts, and check if we have any partitions on this device
+ for (int i=0; i < sysFinalDiskLayout.count(); ++i) {
+ // Check if this drive already has some partitions created for it
+ if ( sysFinalDiskLayout.at(i).at(0) == Device && sysFinalDiskLayout.at(i).at(1) != "ALL" )
+ return false;
+ }
+ return true;
+}
+
+// Function which adds our disks / slices to the combo boxes in a sane manner
+void dialogFileSystem::addDisksSane()
+{
comboDiskSelection->clear();
-
// Start adding / listing our disks / partitions available
for (int i=0; i < sysDisks.count(); ++i) {
// Make sure to only add the drives to the comboDiskList
- if ( sysDisks.at(i).at(0) == "DRIVE" ) {
+ if ( sysDisks.at(i).at(0) == "DRIVE" && diskNoExistingPartition(sysDisks.at(i).at(1)) ) {
comboDiskSelection->addItem(sysDisks.at(i).at(1) + " - " + sysDisks.at(i).at(2) + "MB " + sysDisks.at(i).at(3));
comboMirrorDisk->addItem(sysDisks.at(i).at(1) + " - " + sysDisks.at(i).at(2) + "MB " + sysDisks.at(i).at(3));
- } else {
- comboDiskSelection->addItem(" " + sysDisks.at(i).at(2) + " - " + sysDisks.at(i).at(3) + "MB " + sysDisks.at(i).at(4));
+ } else if ( sysDisks.at(i).at(0) == "SLICE" && sliceNoExistingDiskPartition(sysDisks.at(i).at(2) ) ) {
+ comboDiskSelection->addItem(sysDisks.at(i).at(2) + " - " + sysDisks.at(i).at(3) + "MB " + sysDisks.at(i).at(4));
}
}
}
+// Public slot which lets us set if we are editing a partition, or creating a new one
+void dialogFileSystem::setEditing(int id )
+{
+
+}
+
// Slot for checking the current type
void dialogFileSystem::slotTypeChanged(int index)
{
@@ -57,6 +114,8 @@
stackedWidgetOptions->setCurrentIndex(1);
else
stackedWidgetOptions->setCurrentIndex(0);
+
+ slotCheckSanity();
}
// Slot for checking the current selected disk / partition
@@ -110,9 +169,70 @@
// function which calculates the free space available for a disk / partition that we can show the user
int dialogFileSystem::calculateFreeSpace(int diskIndex)
{
- return 500;
+ QString Disk, Slice, tmp;
+ int fullSize, workingSize, availSize;
+ bool ok;
+
+ availSize = 0;
+
+ // Set our vars with Disk / Slice info, size, etc
+ if ( sysDisks.at(diskIndex).at(0) == "DRIVE") {
+ Disk = sysDisks.at(diskIndex).at(1);
+ Slice = "ALL";
+ tmp = sysDisks.at(diskIndex).at(2);
+ fullSize = tmp.toInt(&ok);
+ } else {
+ Disk = sysDisks.at(diskIndex).at(2);
+ Slice = sysDisks.at(diskIndex).at(2);
+ Slice = Slice.remove(0, Slice.size() -2);
+ tmp = sysDisks.at(diskIndex).at(3);
+ fullSize = tmp.toInt(&ok);
+ }
+
+ // Make sure we don't have invalid fullSize data
+ if (!ok)
+ return 0;
+
+ // Set the available size to the entire thing, and start decrementing
+ availSize = fullSize;
+
+ for (int i=0; i < sysFinalDiskLayout.count(); ++i) {
+ // Check if this mount is on the target partition / drive
+ if ( sysFinalDiskLayout.at(i).at(0) == Disk && sysFinalDiskLayout.at(i).at(1) == Slice ) {
+ tmp = sysFinalDiskLayout.at(i).at(4);
+ workingSize = tmp.toInt(&ok);
+ if(!ok)
+ return 0;
+ availSize = availSize - workingSize;
+ }
+ }
+
+ return availSize;
}
+// Slot which does basic sanity checking before enabling the save button
+void dialogFileSystem::slotCheckSanity()
+{
+ bool ready;
+ ready = true;
+
+
+ // If we are on a non-mirror type
+ if ( comboDiskType->currentText() != "MIRROR" ) {
+ if ( spinSize->value() <= 0)
+ ready = false;
+ if ( lineEditMount->text().isEmpty() || lineEditMount->text().indexOf("/") != 0 )
+ ready = false;
+ } else {
+ // Using a mirror, make sure we don't have the same disk selected as target as source
+ if ( comboDiskSelection->currentText() == comboMirrorDisk->currentText() )
+ ready = false;
+ }
+
+ pushSave->setEnabled(ready);
+
+}
+
// Slot for closing the dialog
void dialogFileSystem::slotPushCancel()
{
Modified: pcbsd/trunk/SysInstaller/dialogFileSystem.h
===================================================================
--- pcbsd/trunk/SysInstaller/dialogFileSystem.h 2009-11-23 19:01:02 UTC (rev 5124)
+++ pcbsd/trunk/SysInstaller/dialogFileSystem.h 2009-11-23 21:22:59 UTC (rev 5125)
@@ -22,6 +22,7 @@
~dialogFileSystem();
void dialogInit(QList<QStringList> disks, QList<QStringList> disklayout);
+ void setEditing(int id);
private slots:
void slotPushCancel();
@@ -30,8 +31,12 @@
void slotTypeChanged(int index);
void slotSpinBoxChanged(int newVal);
void slotSliderChangedValue(int newVal);
+ void slotCheckSanity();
private:
+ bool diskNoExistingPartition(QString Device);
+ bool sliceNoExistingDiskPartition(QString Device);
+ void addDisksSane();
int calculateFreeSpace(int diskIndex);
QList<QStringList> sysDisks; // Our lists which contains disk info
QList<QStringList> sysFinalDiskLayout; // Our lists which contains the final disk layout
Modified: pcbsd/trunk/SysInstaller/dialogFileSystem.ui
===================================================================
--- pcbsd/trunk/SysInstaller/dialogFileSystem.ui 2009-11-23 19:01:02 UTC (rev 5124)
+++ pcbsd/trunk/SysInstaller/dialogFileSystem.ui 2009-11-23 21:22:59 UTC (rev 5125)
@@ -115,7 +115,7 @@
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Modified: pcbsd/trunk/SysInstaller/sys-diskwidget.cpp
===================================================================
--- pcbsd/trunk/SysInstaller/sys-diskwidget.cpp 2009-11-23 19:01:02 UTC (rev 5124)
+++ pcbsd/trunk/SysInstaller/sys-diskwidget.cpp 2009-11-23 21:22:59 UTC (rev 5125)
@@ -211,7 +211,7 @@
{
dialogFileSystem *dls = new dialogFileSystem();
dls->dialogInit(sysDisks, sysFinalDiskLayout);
- //dls->editLayout(ID);
+ //dls->setEditing(id);
dls->show();
}
More information about the Commits
mailing list