add some config values for advanced stuff:

- allow applying operations for non-root users if
  "allowApplyOperationsForNonRoot" is set to true (default is false)

- hide the radio button to create vista msdos partition tables unless
  "allowCreateVistaPartitionTable" is true (default is false). The reason for
  this is that there are, of course, no "vista msdos partition tables" in
  reality, it's just a Microsoft stupidity that only works as long as there is
  actually a partition starting at sector 2048 in that partition table. If the
  partition table is just created empty, we have no way to determine it was
  meant to be a "vista msdos partition table".

- allow settings the sector alignment for msdos-vista partition tables (default
  is 2048, just like vista).


svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1088920
This commit is contained in:
Volker Lanz 2010-02-11 22:26:51 +00:00
parent bead785279
commit 921d6b18e6
4 changed files with 24 additions and 7 deletions

View File

@ -10,5 +10,14 @@
<entry name="firstRun" type="Bool">
<default>true</default>
</entry>
<entry name="vistaSectorAlignment" type="Int">
<default>2048</default>
</entry>
<entry name="allowCreateVistaPartitionTable" type="Bool">
<default>false</default>
</entry>
<entry name="allowApplyOperationsAsNonRoot" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>

View File

@ -32,6 +32,8 @@
#include <kdebug.h>
#include <klocale.h>
#include <config.h>
/** Creates a new PartitionTable object with type MSDOS
@param type name of the PartitionTable type (e.g. "msdos" or "gpt")
*/
@ -208,7 +210,7 @@ QStringList PartitionTable::flagNames(Flags flags)
*/
static qint64 sectorAlignment(const Device& d)
{
return d.partitionTable()->type() == PartitionTable::msdos ? d.cylinderSize() : 2048;
return d.partitionTable()->type() == PartitionTable::msdos ? d.cylinderSize() : Config::vistaSectorAlignment();
}
/** Checks if a given Partition on a given Device is snapped to cylinder boundaries.
@ -560,7 +562,7 @@ void PartitionTable::updateUnallocated(const Device& d)
qint64 PartitionTable::defaultFirstUsable(const Device& d, LabelType t)
{
if (t == msdos_vista)
return 2048;
return Config::vistaSectorAlignment();
return d.sectorsPerTrack() - 1;
}
@ -645,8 +647,8 @@ bool PartitionTable::isVistaDiskLabel() const
{
if (type() == PartitionTable::msdos)
{
const Partition* part = findPartitionBySector(2048, PartitionRole(PartitionRole::Primary));
if (part && part->firstSector() == 2048)
const Partition* part = findPartitionBySector(Config::vistaSectorAlignment(), PartitionRole(PartitionRole::Primary));
if (part && part->firstSector() == Config::vistaSectorAlignment())
return true;
}
@ -656,9 +658,10 @@ bool PartitionTable::isVistaDiskLabel() const
void PartitionTable::setType(LabelType t)
{
// hack: if the type has been msdos and is now set to vista, make sure to also
// set the first usable sector to 2048 now.
// set the first usable sector to Config::vistaSectorAlignment (which defaults to
// Vista's default, 2048) now.
if (type() == msdos && t == msdos_vista)
setFirstUsableSector(2048);
setFirstUsableSector(Config::vistaSectorAlignment());
m_Type = t;
}

View File

@ -25,6 +25,8 @@
#include <klocale.h>
#include <config.h>
CreatePartitionTableDialog::CreatePartitionTableDialog(QWidget* parent, const Device& d) :
KDialog(parent),
m_DialogWidget(new CreatePartitionTableWidget(this)),
@ -33,6 +35,9 @@ CreatePartitionTableDialog::CreatePartitionTableDialog(QWidget* parent, const De
setMainWidget(&widget());
setCaption(i18nc("@title:window", "Create a New Partition Table on <filename>%1</filename>", device().deviceNode()));
setButtonText(KDialog::Ok, i18nc("@action:button", "&Create New Partition Table"));
if (!Config::allowCreateVistaPartitionTable())
widget().radioMSDOSVista().hide();
}
PartitionTable::LabelType CreatePartitionTableDialog::type() const

View File

@ -352,7 +352,7 @@ void PartitionManagerWidget::enableActions()
actionCollection()->action("undoOperation")->setEnabled(numPendingOperations() > 0);
actionCollection()->action("clearAllOperations")->setEnabled(numPendingOperations() > 0);
actionCollection()->action("applyAllOperations")->setEnabled(numPendingOperations() > 0 && geteuid() == 0);
actionCollection()->action("applyAllOperations")->setEnabled(numPendingOperations() > 0 && (geteuid() == 0 || Config::allowApplyOperationsAsNonRoot()));
const bool readOnly = selectedDevice() == NULL || selectedDevice()->partitionTable() == NULL || selectedDevice()->partitionTable()->isReadOnly();