From bd1f7b8c5dff553dee00d40b7229cafc1909cb9c Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Wed, 24 Feb 2010 10:47:22 +0000 Subject: [PATCH] allow changing the msdos partition alignment from the device properties svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1095438 --- src/gui/devicepropsdialog.cpp | 30 +++++ src/gui/devicepropsdialog.h | 8 ++ src/gui/devicepropswidget.h | 14 +++ src/gui/devicepropswidgetbase.ui | 183 ++++++++++++++++++------------- src/gui/mainwindow.cpp | 15 ++- 5 files changed, 172 insertions(+), 78 deletions(-) diff --git a/src/gui/devicepropsdialog.cpp b/src/gui/devicepropsdialog.cpp index d399072..2db0083 100644 --- a/src/gui/devicepropsdialog.cpp +++ b/src/gui/devicepropsdialog.cpp @@ -43,6 +43,7 @@ DevicePropsDialog::DevicePropsDialog(QWidget* parent, Device& d) : setCaption(i18nc("@title:window", "Device properties: %1", device().deviceNode())); setupDialog(); + setupConnections(); restoreDialogSize(KConfigGroup(KGlobal::config(), "devicePropsDialog")); } @@ -81,6 +82,35 @@ void DevicePropsDialog::setupDialog() dialogWidget().type().setText(type); + if (device().partitionTable()->type() == PartitionTable::msdos) + dialogWidget().radioLegacy().setChecked(true); + else if (device().partitionTable()->type() == PartitionTable::msdos_vista) + dialogWidget().radioVista().setChecked(true); + else + dialogWidget().hideTypeRadioButtons(); + setMinimumSize(dialogWidget().size()); resize(dialogWidget().size()); } + +void DevicePropsDialog::setupConnections() +{ + connect(&dialogWidget().radioVista(), SIGNAL(toggled(bool)), SLOT(setDirty(bool))); + connect(&dialogWidget().radioLegacy(), SIGNAL(toggled(bool)), SLOT(setDirty(bool))); +} + +void DevicePropsDialog::setDirty(bool) +{ + setDefaultButton(KDialog::Ok); + enableButtonOk(true); +} + +bool DevicePropsDialog::legacyAlignment() const +{ + return dialogWidget().radioLegacy().isChecked(); +} + +bool DevicePropsDialog::vistaAlignment() const +{ + return dialogWidget().radioVista().isChecked(); +} diff --git a/src/gui/devicepropsdialog.h b/src/gui/devicepropsdialog.h index f69f11f..c7641da 100644 --- a/src/gui/devicepropsdialog.h +++ b/src/gui/devicepropsdialog.h @@ -44,8 +44,13 @@ class DevicePropsDialog : public KDialog DevicePropsDialog(QWidget* parent, Device& d); ~DevicePropsDialog(); + public: + bool legacyAlignment() const; + bool vistaAlignment() const; + protected: void setupDialog(); + void setupConnections(); Device& device() { return m_Device; } const Device& device() const { return m_Device; } @@ -53,6 +58,9 @@ class DevicePropsDialog : public KDialog DevicePropsWidget& dialogWidget() { Q_ASSERT(m_DialogWidget); return *m_DialogWidget; } const DevicePropsWidget& dialogWidget() const { Q_ASSERT(m_DialogWidget); return *m_DialogWidget; } + protected slots: + void setDirty(bool); + private: Device& m_Device; DevicePropsWidget* m_DialogWidget; diff --git a/src/gui/devicepropswidget.h b/src/gui/devicepropswidget.h index b462192..cc6d93a 100644 --- a/src/gui/devicepropswidget.h +++ b/src/gui/devicepropswidget.h @@ -43,6 +43,20 @@ class DevicePropsWidget : public QWidget, public Ui::DevicePropsWidgetBase QLabel& sectorSize() { Q_ASSERT(m_LabelSectorSize); return *m_LabelSectorSize; } QLabel& totalSectors() { Q_ASSERT(m_LabelTotalSectors); return *m_LabelTotalSectors; } QLabel& type() { Q_ASSERT(m_LabelType); return *m_LabelType; } + + QRadioButton& radioLegacy() { Q_ASSERT(m_RadioLegacy); return *m_RadioLegacy; } + const QRadioButton& radioLegacy() const { Q_ASSERT(m_RadioLegacy); return *m_RadioLegacy; } + + QRadioButton& radioVista() { Q_ASSERT(m_RadioVista); return *m_RadioVista; } + const QRadioButton& radioVista() const { Q_ASSERT(m_RadioVista); return *m_RadioVista; } + + QSpacerItem& spacerType() { Q_ASSERT(m_SpacerType); return *m_SpacerType; } + + void hideTypeRadioButtons() + { + radioVista().setVisible(false); + radioLegacy().setVisible(false); + } }; #endif diff --git a/src/gui/devicepropswidgetbase.ui b/src/gui/devicepropswidgetbase.ui index 75675b7..8b9a5e5 100644 --- a/src/gui/devicepropswidgetbase.ui +++ b/src/gui/devicepropswidgetbase.ui @@ -6,15 +6,56 @@ 0 0 - 406 - 283 + 609 + 397 Form - + + + + + 0 + 0 + + + + + 0 + 80 + + + + + 16777215 + 80 + + + + Qt::CustomContextMenu + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + Type: @@ -24,7 +65,7 @@ - + @@ -37,6 +78,54 @@ + + + + + + Legacy Alignment + + + + + + + Vista Compatible Alignment + + + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + + + Qt::Horizontal + + + + + + + Capacity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -73,6 +162,13 @@ + + + + Qt::Horizontal + + + @@ -142,6 +238,13 @@ + + + + Qt::Horizontal + + + @@ -165,16 +268,6 @@ - - - - Capacity: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -191,68 +284,6 @@ - - - - - 0 - 0 - - - - - 0 - 80 - - - - - 16777215 - 80 - - - - Qt::CustomContextMenu - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index eb8e4a2..e398e03 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -683,8 +683,19 @@ void MainWindow::onPropertiesDevice(const QString&) if (pmWidget().selectedDevice()) { - QPointer dlg = new DevicePropsDialog(this, *pmWidget().selectedDevice()); - dlg->exec(); + Device& d = *pmWidget().selectedDevice(); + + QPointer dlg = new DevicePropsDialog(this, d); + if (dlg->exec() == KDialog::Accepted) + { + if (d.partitionTable()->type() == PartitionTable::msdos && dlg->vistaAlignment()) + d.partitionTable()->setType(d, PartitionTable::msdos_vista); + else if (d.partitionTable()->type() == PartitionTable::msdos_vista && dlg->legacyAlignment()) + d.partitionTable()->setType(d, PartitionTable::msdos); + + on_m_OperationStack_devicesChanged(); + } + delete dlg; } }