Add flags ui to edit partition dialog.

main
Teo Mrnjavac 9 years ago
parent 97108d0beb
commit b83e91b951

@ -1,6 +1,11 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
*
* Flags handling originally from KDE Partition Manager,
* Copyright 2008-2009, Volker Lanz <vl@fidra.de>
* Copyright 2016, Andrius Štikonas <andrius@stikonas.eu>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -99,19 +104,61 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() ); m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() );
m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() ); m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );
setupFlagsList();
} }
EditExistingPartitionDialog::~EditExistingPartitionDialog() EditExistingPartitionDialog::~EditExistingPartitionDialog()
{} {}
PartitionTable::Flags
EditExistingPartitionDialog::newFlags() const
{
PartitionTable::Flags flags;
for ( int i = 0; i < m_ui->m_listFlags->count(); i++ )
if ( m_ui->m_listFlags->item( i )->checkState() == Qt::Checked )
flags |= static_cast< PartitionTable::Flag >(
m_ui->m_listFlags->item( i )->data( Qt::UserRole ).toInt() );
return flags;
}
void
EditExistingPartitionDialog::setupFlagsList()
{
int f = 1;
QString s;
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
{
if ( m_partition->availableFlags() & f )
{
QListWidgetItem* item = new QListWidgetItem( s );
m_ui->m_listFlags->addItem( item );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
item->setData( Qt::UserRole, f );
item->setCheckState( ( m_partition->activeFlags() & f ) ?
Qt::Checked :
Qt::Unchecked );
}
f <<= 1;
}
}
void void
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
{ {
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() ); PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
qint64 newFirstSector = m_partitionSizeController->firstSector(); qint64 newFirstSector = m_partitionSizeController->firstSector();
qint64 newLastSector = m_partitionSizeController->lastSector(); qint64 newLastSector = m_partitionSizeController->lastSector();
bool partitionChanged = newFirstSector != m_partition->firstSector() || newLastSector != m_partition->lastSector(); bool partResizedMoved = newFirstSector != m_partition->firstSector() ||
newLastSector != m_partition->lastSector();
FileSystem::Type fsType = FileSystem::Unknown; FileSystem::Type fsType = FileSystem::Unknown;
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
@ -121,7 +168,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
: FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() ); : FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
} }
if ( partitionChanged ) if ( partResizedMoved )
{ {
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
{ {
@ -131,12 +178,14 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition->roles(), m_partition->roles(),
fsType, fsType,
newFirstSector, newFirstSector,
newLastSector ); newLastSector,
newFlags() );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true ); PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition ); core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition ); core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() );
} }
else else
{ {
@ -144,6 +193,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition, m_partition,
newFirstSector, newFirstSector,
newLastSector ); newLastSector );
if ( m_partition->activeFlags() != newFlags() )
core->setPartitionFlags( m_device, m_partition, newFlags() );
} }
} }
else else
@ -155,6 +206,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
if ( m_partition->fileSystem().type() == fsType ) if ( m_partition->fileSystem().type() == fsType )
{ {
core->formatPartition( m_device, m_partition ); core->formatPartition( m_device, m_partition );
if ( m_partition->activeFlags() != newFlags() )
core->setPartitionFlags( m_device, m_partition, newFlags() );
} }
else // otherwise, we delete and recreate the partition with new fs type else // otherwise, we delete and recreate the partition with new fs type
{ {
@ -164,21 +217,26 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition->roles(), m_partition->roles(),
fsType, fsType,
m_partition->firstSector(), m_partition->firstSector(),
m_partition->lastSector() ); m_partition->lastSector(),
newFlags() );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true ); PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition ); core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition ); core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() );
} }
} }
else else
{ {
core->refreshPartition( m_device, m_partition ); core->refreshPartition( m_device, m_partition );
if ( m_partition->activeFlags() != newFlags() )
core->setPartitionFlags( m_device, m_partition, newFlags() );
} }
} }
} }
void void
EditExistingPartitionDialog::replacePartResizerWidget() EditExistingPartitionDialog::replacePartResizerWidget()
{ {
@ -197,6 +255,7 @@ EditExistingPartitionDialog::replacePartResizerWidget()
m_partitionSizeController->setPartResizerWidget( widget, m_ui->formatRadioButton->isChecked() ); m_partitionSizeController->setPartResizerWidget( widget, m_ui->formatRadioButton->isChecked() );
} }
void void
EditExistingPartitionDialog::updateMountPointPicker() EditExistingPartitionDialog::updateMountPointPicker()
{ {

@ -19,6 +19,8 @@
#ifndef EDITEXISTINGPARTITIONDIALOG_H #ifndef EDITEXISTINGPARTITIONDIALOG_H
#define EDITEXISTINGPARTITIONDIALOG_H #define EDITEXISTINGPARTITIONDIALOG_H
#include <kpmcore/core/partitiontable.h>
#include <QDialog> #include <QDialog>
#include <QScopedPointer> #include <QScopedPointer>
@ -49,6 +51,8 @@ private:
Partition* m_partition; Partition* m_partition;
PartitionSizeController* m_partitionSizeController; PartitionSizeController* m_partitionSizeController;
PartitionTable::Flags newFlags() const;
void setupFlagsList();
void replacePartResizerWidget(); void replacePartResizerWidget();
void updateMountPointPicker(); void updateMountPointPicker();
}; };

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>450</width> <width>450</width>
<height>430</height> <height>579</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -139,6 +139,26 @@
<item row="5" column="1"> <item row="5" column="1">
<widget class="QComboBox" name="fileSystemComboBox"/> <widget class="QComboBox" name="fileSystemComboBox"/>
</item> </item>
<item row="7" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Flags:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QListWidget" name="m_listFlags">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

Loading…
Cancel
Save