2018-06-04 21:31:58 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-06-04 21:31:58 +02:00
|
|
|
*
|
|
|
|
* 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 "VolumeGroupBaseDialog.h"
|
|
|
|
#include "ui_VolumeGroupBaseDialog.h"
|
|
|
|
|
|
|
|
#include "gui/ListPhysicalVolumeWidgetItem.h"
|
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
#include <kpmcore/util/capacity.h>
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, QVector< const Partition* > pvList, QWidget* parent )
|
|
|
|
: QDialog( parent )
|
|
|
|
, ui( new Ui::VolumeGroupBaseDialog )
|
|
|
|
, m_vgNameValue( vgName )
|
|
|
|
, m_totalSizeValue( 0 )
|
|
|
|
, m_usedSizeValue( 0 )
|
2018-06-04 21:31:58 +02:00
|
|
|
{
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->setupUi( this );
|
2018-06-04 21:31:58 +02:00
|
|
|
|
|
|
|
for ( const Partition* p : pvList )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-06-07 22:22:22 +02:00
|
|
|
ui->pvList->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->vgType->addItems( QStringList() << "LVM"
|
|
|
|
<< "RAID" );
|
|
|
|
ui->vgType->setCurrentIndex( 0 );
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
QRegularExpression re( R"(^(?!_|\.)[\w\-.+]+)" );
|
2018-06-07 22:22:22 +02:00
|
|
|
ui->vgName->setValidator( new QRegularExpressionValidator( re, this ) );
|
|
|
|
ui->vgName->setText( m_vgNameValue );
|
|
|
|
|
|
|
|
updateOkButton();
|
|
|
|
updateTotalSize();
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
connect( ui->pvList, &QListWidget::itemChanged, this, [&]( QListWidgetItem* ) {
|
|
|
|
updateTotalSize();
|
|
|
|
updateOkButton();
|
|
|
|
} );
|
|
|
|
|
|
|
|
connect( ui->peSize, qOverload< int >( &QSpinBox::valueChanged ), this, [&]( int ) {
|
|
|
|
updateTotalSectors();
|
|
|
|
updateOkButton();
|
|
|
|
} );
|
|
|
|
|
|
|
|
connect( ui->vgName, &QLineEdit::textChanged, this, [&]( const QString& ) { updateOkButton(); } );
|
2018-06-04 21:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VolumeGroupBaseDialog::~VolumeGroupBaseDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
|
|
|
|
QVector< const Partition* >
|
|
|
|
VolumeGroupBaseDialog::checkedItems() const
|
|
|
|
{
|
|
|
|
QVector< const Partition* > items;
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
for ( int i = 0; i < ui->pvList->count(); i++ )
|
|
|
|
{
|
|
|
|
ListPhysicalVolumeWidgetItem* item = dynamic_cast< ListPhysicalVolumeWidgetItem* >( ui->pvList->item( i ) );
|
2018-06-07 22:22:22 +02:00
|
|
|
|
|
|
|
if ( item && item->checkState() == Qt::Checked )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-06-07 22:22:22 +02:00
|
|
|
items << item->partition();
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VolumeGroupBaseDialog::isSizeValid() const
|
|
|
|
{
|
|
|
|
return m_totalSizeValue >= m_usedSizeValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VolumeGroupBaseDialog::updateOkButton()
|
|
|
|
{
|
2020-08-22 01:19:58 +02:00
|
|
|
okButton()->setEnabled( isSizeValid() && !checkedItems().empty() && !ui->vgName->text().isEmpty()
|
|
|
|
&& ui->peSize->value() > 0 );
|
2018-06-07 22:22:22 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 05:38:52 +02:00
|
|
|
void
|
|
|
|
VolumeGroupBaseDialog::setUsedSizeValue( qint64 usedSize )
|
|
|
|
{
|
|
|
|
m_usedSizeValue = usedSize;
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->usedSize->setText( Capacity::formatByteSize( m_usedSizeValue ) );
|
2018-06-26 05:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VolumeGroupBaseDialog::setLVQuantity( qint32 lvQuantity )
|
|
|
|
{
|
|
|
|
ui->lvQuantity->setText( QString::number( lvQuantity ) );
|
|
|
|
}
|
|
|
|
|
2018-06-07 22:22:22 +02:00
|
|
|
void
|
|
|
|
VolumeGroupBaseDialog::updateTotalSize()
|
|
|
|
{
|
|
|
|
m_totalSizeValue = 0;
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
for ( const Partition* p : checkedItems() )
|
|
|
|
{
|
|
|
|
m_totalSizeValue += p->capacity()
|
|
|
|
- p->capacity()
|
|
|
|
% ( ui->peSize->value() * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB ) );
|
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->totalSize->setText( Capacity::formatByteSize( m_totalSizeValue ) );
|
2018-06-07 22:22:22 +02:00
|
|
|
|
|
|
|
updateTotalSectors();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VolumeGroupBaseDialog::updateTotalSectors()
|
|
|
|
{
|
2019-05-14 10:39:19 +02:00
|
|
|
qint64 totalSectors = 0;
|
2018-06-07 22:22:22 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
qint64 extentSize = ui->peSize->value() * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB );
|
2018-06-07 22:22:22 +02:00
|
|
|
|
|
|
|
if ( extentSize > 0 )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-06-07 22:22:22 +02:00
|
|
|
totalSectors = m_totalSizeValue / extentSize;
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2018-06-07 22:22:22 +02:00
|
|
|
|
|
|
|
ui->totalSectors->setText( QString::number( totalSectors ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString&
|
|
|
|
VolumeGroupBaseDialog::vgNameValue() const
|
|
|
|
{
|
|
|
|
return m_vgNameValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineEdit*
|
|
|
|
VolumeGroupBaseDialog::vgName() const
|
|
|
|
{
|
|
|
|
return ui->vgName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QComboBox*
|
|
|
|
VolumeGroupBaseDialog::vgType() const
|
|
|
|
{
|
|
|
|
return ui->vgType;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSpinBox*
|
|
|
|
VolumeGroupBaseDialog::peSize() const
|
|
|
|
{
|
|
|
|
return ui->peSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QListWidget*
|
|
|
|
VolumeGroupBaseDialog::pvList() const
|
|
|
|
{
|
|
|
|
return ui->pvList;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton*
|
|
|
|
VolumeGroupBaseDialog::okButton() const
|
|
|
|
{
|
|
|
|
return ui->buttonBox->button( QDialogButtonBox::StandardButton::Ok );
|
|
|
|
}
|