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> ===
*
* 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
* 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->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );
setupFlagsList();
}
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
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
{
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
qint64 newFirstSector = m_partitionSizeController->firstSector();
qint64 newLastSector = m_partitionSizeController->lastSector();
bool partitionChanged = newFirstSector != m_partition->firstSector() || newLastSector != m_partition->lastSector();
qint64 newLastSector = m_partitionSizeController->lastSector();
bool partResizedMoved = newFirstSector != m_partition->firstSector() ||
newLastSector != m_partition->lastSector();
FileSystem::Type fsType = FileSystem::Unknown;
if ( m_ui->formatRadioButton->isChecked() )
@ -121,7 +168,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
: FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
}
if ( partitionChanged )
if ( partResizedMoved )
{
if ( m_ui->formatRadioButton->isChecked() )
{
@ -131,12 +178,14 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition->roles(),
fsType,
newFirstSector,
newLastSector );
newLastSector,
newFlags() );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() );
}
else
{
@ -144,6 +193,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition,
newFirstSector,
newLastSector );
if ( m_partition->activeFlags() != newFlags() )
core->setPartitionFlags( m_device, m_partition, newFlags() );
}
}
else
@ -155,6 +206,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
if ( m_partition->fileSystem().type() == fsType )
{
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
{
@ -164,21 +217,26 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition->roles(),
fsType,
m_partition->firstSector(),
m_partition->lastSector() );
m_partition->lastSector(),
newFlags() );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() );
}
}
else
{
core->refreshPartition( m_device, m_partition );
if ( m_partition->activeFlags() != newFlags() )
core->setPartitionFlags( m_device, m_partition, newFlags() );
}
}
}
void
EditExistingPartitionDialog::replacePartResizerWidget()
{
@ -197,6 +255,7 @@ EditExistingPartitionDialog::replacePartResizerWidget()
m_partitionSizeController->setPartResizerWidget( widget, m_ui->formatRadioButton->isChecked() );
}
void
EditExistingPartitionDialog::updateMountPointPicker()
{

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

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>450</width>
<height>430</height>
<height>579</height>
</rect>
</property>
<property name="sizePolicy">
@ -139,6 +139,26 @@
<item row="5" column="1">
<widget class="QComboBox" name="fileSystemComboBox"/>
</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>
</item>
<item>

Loading…
Cancel
Save