Kill EraseDiskPage, add PartitionActions.

main
Teo Mrnjavac 9 years ago
parent 6de8158bec
commit 9167a34f2e

@ -25,6 +25,7 @@ calamares_add_plugin( partition
core/ColorUtils.cpp
core/DeviceModel.cpp
core/KPMHelpers.cpp
core/PartitionActions.cpp
core/PartitionCoreModule.cpp
core/PartitionInfo.cpp
core/PartitionIterator.cpp
@ -34,7 +35,6 @@ calamares_add_plugin( partition
gui/CreatePartitionDialog.cpp
gui/EditExistingPartitionDialog.cpp
gui/AlongsidePage.cpp
gui/EraseDiskPage.cpp
gui/PartitionPage.cpp
gui/PartitionPreview.cpp
gui/PartitionSizeController.cpp

@ -16,123 +16,88 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "EraseDiskPage.h"
#include "PartitionActions.h"
#include "core/DeviceModel.h"
#include "core/PartitionCoreModule.h"
#include "core/KPMHelpers.h"
#include "core/PartitionInfo.h"
#include "gui/PartitionPreview.h"
#include "core/PartitionCoreModule.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include "utils/CalamaresUtilsSystem.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Logger.h"
#include "GlobalStorage.h"
// KPMcore
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
#include <QBoxLayout>
#include <QDir>
#include <QFormLayout>
#include <QListView>
#include <QLabel>
#include <QMutexLocker>
EraseDiskPage::EraseDiskPage( QWidget* parent )
: QWidget( parent )
, m_nextEnabled( false )
, m_core( nullptr )
namespace PartitionActions
{
QVBoxLayout* mainLayout = new QVBoxLayout;
setLayout( mainLayout );
QLabel* driveLabel = new QLabel( this );
mainLayout->addWidget( driveLabel );
CALAMARES_RETRANSLATE( driveLabel->setText( tr( "Select drive:" ) ); )
m_drivesView = new QListView;
mainLayout->addWidget( m_drivesView );
m_drivesView->setViewMode( QListView::IconMode );
m_drivesView->setWrapping( false );
m_drivesView->setFlow( QListView::LeftToRight );
m_drivesView->setSelectionRectVisible( false );
m_drivesView->setWordWrap( true );
m_drivesView->setUniformItemSizes( true );
m_drivesView->setSelectionMode( QAbstractItemView::SingleSelection );
m_drivesView->setIconSize( CalamaresUtils::defaultIconSize() * 3 );
m_drivesView->setGridSize( QSize( CalamaresUtils::defaultFontHeight() * 8,
m_drivesView->iconSize().height() +
CalamaresUtils::defaultFontHeight() * 4 ) );
m_drivesView->setMinimumHeight( m_drivesView->gridSize().height() +
CalamaresUtils::defaultFontHeight() / 2 );
m_drivesView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_previewFrame = new QWidget;
m_previewFrame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
mainLayout->addWidget( m_previewFrame );
qint64
swapSuggestion( const qint64 availableSpaceB )
{
setNextEnabled( false );
}
#define MiB * static_cast< qint64 >( 1024 ) * 1024
#define GiB * static_cast< qint64 >( 1024 ) * 1024 * 1024
// swap(mem) = max(2, 2 * mem), if mem < 2 GiB
// = mem, if 2 GiB <= mem < 8 GiB
// = mem / 2, if 8 GIB <= mem < 64 GiB
// = 4 GiB, if mem >= 64 GiB
void
EraseDiskPage::init( PartitionCoreModule* core )
{
if ( m_core ) //this should probably never happen
qint64 suggestedSwapSizeB = 0;
qint64 availableRamB = CalamaresUtils::System::instance()->getPhysicalMemoryB();
qreal overestimationFactor = 1.01;
if ( !availableRamB )
{
m_core->revert();
return;
availableRamB = CalamaresUtils::System::instance()->getTotalMemoryB();
overestimationFactor = 1.10;
}
m_core = core;
m_drivesView->setModel( core->deviceModel() );
bool ensureSuspendToDisk =
Calamares::JobQueue::instance()->globalStorage()->
value( "ensureSuspendToDisk" ).toBool();
connect( m_drivesView->selectionModel(), &QItemSelectionModel::currentChanged,
this, [ this ]( const QModelIndex& index,
const QModelIndex& oldIndex )
if ( ensureSuspendToDisk )
{
setNextEnabled( m_drivesView->selectionModel()->hasSelection() );
if ( m_core->isDirty() )
m_core->clearJobs();
Device* dev = m_core->deviceModel()->deviceForIndex( index );
if ( dev )
doAutopartition( dev );
} );
connect( m_core, &PartitionCoreModule::isDirtyChanged,
this, &EraseDiskPage::updatePreviews );
}
if ( availableRamB < 4 GiB )
suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
else if ( availableRamB >= 4 GiB && availableRamB < 8 GiB )
suggestedSwapSizeB = 8 GiB;
else
suggestedSwapSizeB = availableRamB;
suggestedSwapSizeB *= overestimationFactor;
}
else //if we don't care about suspend to disk
{
if ( availableRamB < 2 GiB )
suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
else if ( availableRamB >= 2 GiB && availableRamB < 8 GiB )
suggestedSwapSizeB = availableRamB;
else if ( availableRamB >= 8 GiB && availableRamB < 64 GiB )
suggestedSwapSizeB = availableRamB / 2;
else
suggestedSwapSizeB = 4 GiB;
bool
EraseDiskPage::isNextEnabled() const
{
return m_nextEnabled;
}
suggestedSwapSizeB *= overestimationFactor;
// don't use more than 10% of available space
qreal maxSwapDiskRatio = 1.10;
qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
if ( suggestedSwapSizeB > maxSwapSizeB )
suggestedSwapSizeB = maxSwapSizeB;
}
void
EraseDiskPage::setNextEnabled( bool enabled )
{
if ( enabled == m_nextEnabled )
return;
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. /1024. << "GiB";
m_nextEnabled = enabled;
emit nextStatusChanged( enabled );
return suggestedSwapSizeB;
}
void
EraseDiskPage::doAutopartition( Device* dev )
doAutopartition( PartitionCoreModule* core, Device* dev )
{
bool isEfi = false;
if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
@ -161,7 +126,7 @@ EraseDiskPage::doAutopartition( Device* dev )
if ( isEfi )
{
qint64 lastSector = firstFreeSector + ( uefisys_part_size MiB / dev->logicalSectorSize() );
m_core->createPartitionTable( dev, PartitionTable::gpt );
core->createPartitionTable( dev, PartitionTable::gpt );
Partition* efiPartition = KPMHelpers::createNewPartition(
dev->partitionTable(),
*dev,
@ -175,12 +140,12 @@ EraseDiskPage::doAutopartition( Device* dev )
->globalStorage()
->value( "efiSystemPartition" )
.toString() );
m_core->createPartition( dev, efiPartition );
core->createPartition( dev, efiPartition );
firstFreeSector = lastSector + 1;
}
else
{
m_core->createPartitionTable( dev, PartitionTable::msdos );
core->createPartitionTable( dev, PartitionTable::msdos );
}
bool shouldCreateSwap = false;
@ -211,7 +176,7 @@ EraseDiskPage::doAutopartition( Device* dev )
);
PartitionInfo::setFormat( rootPartition, true );
PartitionInfo::setMountPoint( rootPartition, "/" );
m_core->createPartition( dev, rootPartition );
core->createPartition( dev, rootPartition );
if ( shouldCreateSwap )
{
@ -224,112 +189,10 @@ EraseDiskPage::doAutopartition( Device* dev )
dev->totalSectors() - 1
);
PartitionInfo::setFormat( swapPartition, true );
m_core->createPartition( dev, swapPartition );
core->createPartition( dev, swapPartition );
}
updatePreviews();
m_core->dumpQueue();
core->dumpQueue();
}
void
EraseDiskPage::updatePreviews()
{
QMutexLocker locker( &m_previewsMutex );
cDebug() << "Updating partitioning preview widgets.";
qDeleteAll( m_previewFrame->children() );
m_previewFrame->layout()->deleteLater();
if ( m_drivesView->selectionModel()->currentIndex() == QModelIndex() )
{
cDebug() << "No disk selected, bailing out.";
return;
}
QFormLayout* layout = new QFormLayout;
m_previewFrame->setLayout( layout );
layout->setMargin( 0 );
QList< PartitionCoreModule::SummaryInfo > list = m_core->createSummaryInfo();
for ( const auto& info : list )
{
PartitionPreview* preview;
layout->addRow( new QLabel( info.deviceName ) );
preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelBefore );
info.partitionModelBefore->setParent( m_previewFrame );
layout->addRow( tr( "Before:" ), preview );
preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelAfter );
info.partitionModelAfter->setParent( m_previewFrame );
layout->addRow( tr( "After:" ), preview );
}
}
qint64
EraseDiskPage::swapSuggestion( const qint64 availableSpaceB ) const {
#define MiB * static_cast< qint64 >( 1024 ) * 1024
#define GiB * static_cast< qint64 >( 1024 ) * 1024 * 1024
// swap(mem) = max(2, 2 * mem), if mem < 2 GiB
// = mem, if 2 GiB <= mem < 8 GiB
// = mem / 2, if 8 GIB <= mem < 64 GiB
// = 4 GiB, if mem >= 64 GiB
qint64 suggestedSwapSizeB = 0;
qint64 availableRamB = CalamaresUtils::System::instance()->getPhysicalMemoryB();
qreal overestimationFactor = 1.01;
if ( !availableRamB )
{
availableRamB = CalamaresUtils::System::instance()->getTotalMemoryB();
overestimationFactor = 1.10;
}
bool ensureSuspendToDisk =
Calamares::JobQueue::instance()->globalStorage()->
value( "ensureSuspendToDisk" ).toBool();
if ( ensureSuspendToDisk )
{
if ( availableRamB < 4 GiB )
suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
else if ( availableRamB >= 4 GiB && availableRamB < 8 GiB )
suggestedSwapSizeB = 8 GiB;
else
suggestedSwapSizeB = availableRamB;
suggestedSwapSizeB *= overestimationFactor;
}
else //if we don't care about suspend to disk
{
if ( availableRamB < 2 GiB )
suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
else if ( availableRamB >= 2 GiB && availableRamB < 8 GiB )
suggestedSwapSizeB = availableRamB;
else if ( availableRamB >= 8 GiB && availableRamB < 64 GiB )
suggestedSwapSizeB = availableRamB / 2;
else
suggestedSwapSizeB = 4 GiB;
suggestedSwapSizeB *= overestimationFactor;
// don't use more than 10% of available space
qreal maxSwapDiskRatio = 1.10;
qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
if ( suggestedSwapSizeB > maxSwapSizeB )
suggestedSwapSizeB = maxSwapSizeB;
}
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. /1024. << "GiB";
return suggestedSwapSizeB;
}

@ -16,42 +16,15 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ERASEDISKPAGE_H
#define ERASEDISKPAGE_H
#include <QMutex>
#include <QWidget>
#ifndef PARTITIONACTIONS_H
#define PARTITIONACTIONS_H
class PartitionCoreModule;
class QListView;
class Device;
class EraseDiskPage : public QWidget
namespace PartitionActions
{
Q_OBJECT
public:
explicit EraseDiskPage( QWidget* parent = nullptr );
void init( PartitionCoreModule* core );
bool isNextEnabled() const;
signals:
void nextStatusChanged( bool );
private:
void setNextEnabled( bool enabled );
void doAutopartition( Device* dev );
void updatePreviews();
qint64 swapSuggestion( const qint64 availableSpaceB ) const;
QListView* m_drivesView;
PartitionCoreModule* m_core;
QWidget* m_previewFrame;
QMutex m_previewsMutex;
bool m_nextEnabled;
};
void doAutopartition( PartitionCoreModule* core, Device* dev );
}
#endif // ERASEDISKPAGE_H
#endif // PARTITIONACTIONS_H
Loading…
Cancel
Save