New ReplacePage
This commit is contained in:
parent
d3ea92ef3d
commit
8f8e1ad6d4
276
src/modules/partition/gui/ReplacePage.cpp
Normal file
276
src/modules/partition/gui/ReplacePage.cpp
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ReplacePage.h"
|
||||||
|
#include "ui_ReplacePage.h"
|
||||||
|
|
||||||
|
#include <core/PartitionCoreModule.h>
|
||||||
|
#include <core/DeviceModel.h>
|
||||||
|
#include <core/partition.h>
|
||||||
|
#include <fs/filesystem.h>
|
||||||
|
#include <core/PMUtils.h>
|
||||||
|
#include <core/PartitionInfo.h>
|
||||||
|
|
||||||
|
#include <JobQueue.h>
|
||||||
|
#include <GlobalStorage.h>
|
||||||
|
#include <utils/Retranslator.h>
|
||||||
|
#include <utils/CalamaresUtilsGui.h>
|
||||||
|
#include <utils/Logger.h>
|
||||||
|
#include <Branding.h>
|
||||||
|
|
||||||
|
|
||||||
|
ReplacePage::ReplacePage( PartitionCoreModule* core, QWidget* parent )
|
||||||
|
: QWidget( parent )
|
||||||
|
, m_ui( new Ui_ReplacePage )
|
||||||
|
, m_core( core )
|
||||||
|
{
|
||||||
|
m_ui->setupUi( this );
|
||||||
|
m_ui->deviceComboBox->setModel( m_core->deviceModel() );
|
||||||
|
|
||||||
|
// updateButtons();
|
||||||
|
|
||||||
|
updateFromCurrentDevice();
|
||||||
|
|
||||||
|
connect( m_ui->deviceComboBox, &QComboBox::currentTextChanged,
|
||||||
|
[ this ]( const QString& /* text */ )
|
||||||
|
{
|
||||||
|
updateFromCurrentDevice();
|
||||||
|
} );
|
||||||
|
|
||||||
|
connect( m_ui->partitionTreeView, &QAbstractItemView::activated,
|
||||||
|
this, &ReplacePage::onPartitionViewActivated );
|
||||||
|
|
||||||
|
CALAMARES_RETRANSLATE(
|
||||||
|
m_ui->retranslateUi( this );
|
||||||
|
onPartitionSelected();
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReplacePage::~ReplacePage()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ReplacePage::isNextEnabled() const
|
||||||
|
{
|
||||||
|
return m_nextEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::applyChanges()
|
||||||
|
{
|
||||||
|
PartitionModel* model = qobject_cast< PartitionModel* >( m_ui->partitionTreeView->model() );
|
||||||
|
if ( model )
|
||||||
|
{
|
||||||
|
Partition* partition = model->partitionForIndex( m_ui->partitionTreeView->currentIndex() );
|
||||||
|
if ( partition )
|
||||||
|
{
|
||||||
|
Device* dev = model->device();
|
||||||
|
Partition* newPartition = PMUtils::createNewPartition(
|
||||||
|
partition->parent(),
|
||||||
|
*dev,
|
||||||
|
partition->roles(),
|
||||||
|
FileSystem::Ext4,
|
||||||
|
partition->firstSector(),
|
||||||
|
partition->lastSector() );
|
||||||
|
PartitionInfo::setMountPoint( newPartition, "/" );
|
||||||
|
PartitionInfo::setFormat( newPartition, true );
|
||||||
|
|
||||||
|
m_core->deletePartition( dev, partition );
|
||||||
|
m_core->createPartition( dev, newPartition );
|
||||||
|
|
||||||
|
m_core->dumpQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::onPartitionSelected()
|
||||||
|
{
|
||||||
|
if ( m_ui->partitionTreeView->currentIndex() == QModelIndex() )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Partitions,
|
||||||
|
tr( "Select where to install %1.<br/>"
|
||||||
|
"<font color=\"red\">Warning: </font>This will delete all files "
|
||||||
|
"on the selected partition." )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
double requiredSpaceB = Calamares::JobQueue::instance()
|
||||||
|
->globalStorage()
|
||||||
|
->value( "requiredStorageGB" )
|
||||||
|
.toDouble( &ok ) * 1024 * 1024 * 1024;
|
||||||
|
|
||||||
|
PartitionModel* model = qobject_cast< PartitionModel* >( m_ui->partitionTreeView->model() );
|
||||||
|
if ( model && ok )
|
||||||
|
{
|
||||||
|
Partition* partition = model->partitionForIndex( m_ui->partitionTreeView->currentIndex() );
|
||||||
|
if ( !partition ||
|
||||||
|
partition->state() != Partition::StateNone )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Fail,
|
||||||
|
tr( "The selected item does not appear to be a valid partition." ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( partition->roles().has( PartitionRole::Unallocated ) )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Fail,
|
||||||
|
tr( "%1 cannot be installed on empty space. Please select an "
|
||||||
|
"existing partition." )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Fail,
|
||||||
|
tr( "%1 cannot be installed on an extended partition. Please select an "
|
||||||
|
"existing primary or logical partition." )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( partition->partitionPath().isEmpty() )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Fail,
|
||||||
|
tr( "%1 cannot be installed on this partition." )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( partition->capacity() < requiredSpaceB )
|
||||||
|
{
|
||||||
|
updateStatus( CalamaresUtils::Fail,
|
||||||
|
tr( "The partition %1 is too small for %2. Please select a partition "
|
||||||
|
"with capacity at least %3 GB." )
|
||||||
|
.arg( partition->partitionPath() )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) )
|
||||||
|
.arg( requiredSpaceB / ( 1024. * 1024. * 1024. ),
|
||||||
|
0, 'f', 1 ) );
|
||||||
|
setNextEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateStatus( CalamaresUtils::Partitions,
|
||||||
|
tr( "%1 will be installed on %2." )
|
||||||
|
.arg( Calamares::Branding::instance()->
|
||||||
|
string( Calamares::Branding::VersionedName ) )
|
||||||
|
.arg( partition->partitionPath() ) );
|
||||||
|
setNextEnabled( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::setNextEnabled( bool enabled )
|
||||||
|
{
|
||||||
|
if ( enabled == m_nextEnabled )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_nextEnabled = enabled;
|
||||||
|
emit nextStatusChanged( enabled );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::updateStatus( CalamaresUtils::ImageType imageType, const QString& text )
|
||||||
|
{
|
||||||
|
int iconSize = CalamaresUtils::defaultFontHeight() * 8;
|
||||||
|
m_ui->selectedIconLabel->setPixmap( CalamaresUtils::defaultPixmap( imageType,
|
||||||
|
CalamaresUtils::Original,
|
||||||
|
QSize( iconSize, iconSize ) ) );
|
||||||
|
m_ui->selectedIconLabel->setFixedHeight( iconSize );
|
||||||
|
m_ui->selectedStatusLabel->setText( text );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::updateFromCurrentDevice()
|
||||||
|
{
|
||||||
|
QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
|
||||||
|
if ( !index.isValid() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Device* device = m_core->deviceModel()->deviceForIndex( index );
|
||||||
|
|
||||||
|
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
|
||||||
|
if ( oldModel )
|
||||||
|
disconnect( oldModel, 0, this, 0 );
|
||||||
|
|
||||||
|
PartitionModel* model = m_core->partitionModelForDevice( device );
|
||||||
|
m_ui->partitionPreview->setModel( model );
|
||||||
|
m_ui->partitionTreeView->setModel( model );
|
||||||
|
m_ui->partitionTreeView->expandAll();
|
||||||
|
|
||||||
|
// Must be done here because we need to have a model set to define
|
||||||
|
// individual column resize mode
|
||||||
|
QHeaderView* header = m_ui->partitionTreeView->header();
|
||||||
|
header->setSectionResizeMode( QHeaderView::ResizeToContents );
|
||||||
|
header->setSectionResizeMode( 0, QHeaderView::Stretch );
|
||||||
|
|
||||||
|
//updateButtons();
|
||||||
|
// Establish connection here because selection model is destroyed when
|
||||||
|
// model changes
|
||||||
|
connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
|
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
||||||
|
{
|
||||||
|
// updateButtons();
|
||||||
|
} );
|
||||||
|
connect( model, &QAbstractItemModel::modelReset, this, &ReplacePage::onPartitionModelReset );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::onPartitionViewActivated()
|
||||||
|
{
|
||||||
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
||||||
|
if ( !index.isValid() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
||||||
|
Q_ASSERT( model );
|
||||||
|
Partition* partition = model->partitionForIndex( index );
|
||||||
|
Q_ASSERT( partition );
|
||||||
|
|
||||||
|
onPartitionSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ReplacePage::onPartitionModelReset()
|
||||||
|
{
|
||||||
|
m_ui->partitionTreeView->expandAll();
|
||||||
|
onPartitionSelected();
|
||||||
|
}
|
65
src/modules/partition/gui/ReplacePage.h
Normal file
65
src/modules/partition/gui/ReplacePage.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REPLACEPAGE_H
|
||||||
|
#define REPLACEPAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
class Ui_ReplacePage;
|
||||||
|
class PartitionCoreModule;
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
enum ImageType : int;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReplacePage : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ReplacePage( PartitionCoreModule* core , QWidget* parent = nullptr );
|
||||||
|
virtual ~ReplacePage();
|
||||||
|
|
||||||
|
bool isNextEnabled() const;
|
||||||
|
|
||||||
|
void applyChanges();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void nextStatusChanged( bool );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onPartitionSelected();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer< Ui_ReplacePage > m_ui;
|
||||||
|
void setNextEnabled( bool enabled );
|
||||||
|
|
||||||
|
void updateStatus( CalamaresUtils::ImageType imageType, const QString& text );
|
||||||
|
|
||||||
|
PartitionCoreModule* m_core;
|
||||||
|
|
||||||
|
bool m_nextEnabled;
|
||||||
|
|
||||||
|
void updateFromCurrentDevice();
|
||||||
|
void onPartitionViewActivated();
|
||||||
|
void onPartitionModelReset();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REPLACEPAGE_H
|
124
src/modules/partition/gui/ReplacePage.ui
Normal file
124
src/modules/partition/gui/ReplacePage.ui
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ReplacePage</class>
|
||||||
|
<widget class="QWidget" name="ReplacePage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>643</width>
|
||||||
|
<height>292</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Disk:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>deviceComboBox</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="deviceComboBox"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="PartitionPreview" name="partitionPreview"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="partitionTreeView">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="allColumnsShowFocus">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="expandsOnDoubleClick">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="headerStretchLastSection">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="selectedIconLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="selectedStatusLabel">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PartitionPreview</class>
|
||||||
|
<extends>QFrame</extends>
|
||||||
|
<header location="global">gui/PartitionPreview.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>deviceComboBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user