You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-2.2-install.../src/pagepartitioning.cpp

201 lines
4.6 KiB

#include "pagepartitioning.h"
#include <QRadioButton>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QBoxLayout>
#include <QScopedPointer>
#include <QMessageBox>
#include <QtDebug>
#include "libparted.h"
PagePartitioning::PagePartitioning() :
InstallerPage( )
{
setupUi();
m_ButExistPartition->setChecked(true);
connect( m_ButExistPartition, SIGNAL(toggled(bool)), m_Partitions, SLOT(setEnabled(bool)));
connect( m_ButPartitioning, SIGNAL(clicked()), this, SLOT(partitioningCurrentDisk()) );
connect( m_Disks, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePartitions(int)) );
}
void PagePartitioning::setupUi()
{
// widgets
m_labelDisk = new QLabel;
m_ButExistPartition = new QRadioButton;
m_ButAllDisk = new QRadioButton;
m_ButPartitioning = new QPushButton;
m_Partitions = new QComboBox;
m_Disks = new QComboBox;
// layouts
QHBoxLayout* hbox_1 = new QHBoxLayout;
hbox_1->addWidget(m_labelDisk);
hbox_1->addWidget(m_Disks);
QHBoxLayout* hbox_2 = new QHBoxLayout;
hbox_2->addWidget( m_ButAllDisk );
hbox_2->addStretch();
QHBoxLayout* hbox_3 = new QHBoxLayout;
hbox_3->addWidget( m_ButExistPartition );
hbox_3->addWidget( m_Partitions );
QHBoxLayout* hbox_4 = new QHBoxLayout;
hbox_4->addWidget( m_ButPartitioning );
hbox_4->addStretch();
QVBoxLayout* vbox_1 = new QVBoxLayout;
vbox_1->addLayout(hbox_1);
vbox_1->addLayout(hbox_2);
vbox_1->addLayout(hbox_3);
vbox_1->addLayout(hbox_4);
vbox_1->addStretch();
setLayout(vbox_1);
retranslateUi();
}
void PagePartitioning::retranslateUi()
{
setTitle( tr("Partitioning") );
m_labelDisk->setText( tr("Disk for install: ") );
m_ButExistPartition->setText( tr("Use existing partition") );
m_ButAllDisk->setText( tr("Use automatical partitioning") );
m_ButPartitioning->setText( tr("Manualy partitioning") );
}
bool PagePartitioning::validate()
{
if ( m_Disks->count() == 0 )
{
QMessageBox::critical(this, tr("Critical error"), tr("Not found any disk for install") );
return false;
}
if ( m_ButAllDisk->isChecked() )
{
emit selectedVolume( m_Disks->itemData(m_Disks->currentIndex()).toString() );
return true;
}
if ( m_Partitions->count() == 0 )
{
QMessageBox::critical(this, tr("Critical error"), tr("Not found any partition for install") );
return false;
} else {
emit selectedVolume( m_Partitions->itemData(m_Partitions->currentIndex()).toString() );
}
return true;
}
void PagePartitioning::show()
{
m_Disks->clear();
m_Partitions->clear();
m_PartitionsMap.clear();
// get disk & partitions
QScopedPointer<LibParted> libParted( new LibParted );
QStringList disks = libParted->getDevices();
if ( disks.isEmpty() )
{
qDebug() << "disk not found";
QMessageBox::critical(this, tr("Error"), tr("Disks not found"));
emit changeNext(false);
return;
}
foreach(const QString& dev, disks)
{
DeviceInfo dev_info;
try {
dev_info = libParted->getDeviceInfo(dev);
}
catch(LibPartedError e)
{
qDebug() << QString("Cannot read disk info from %1").arg(dev);
continue;
}
QString disk_info = QString("%1 %2 %3").arg(dev, 10).arg(dev_info.size, 10).arg(dev_info.model, 25);
m_Disks->addItem(disk_info, QVariant(dev));
QList<PartitionInfo> part_list;
try {
part_list = libParted->getPartitionList(dev);
qDebug() << part_list.size();
}
catch(LibPartedError e)
{
qDebug() << tr("Cannot read partition table from %1").arg(dev);
continue;
}
QList<PartitionDesc> partitions;
PartitionDesc part_desc;
foreach(const PartitionInfo& part, part_list)
{
part_desc.first = QString("%1%2 %3 %4").arg(dev).arg(part.num).arg(part.size, 10).arg(part.fs, 20);
part_desc.second = QString("%1%2").arg(dev).arg(part.num);
partitions << part_desc;
}
m_PartitionsMap[dev] = partitions;
}
if (m_Disks->count() > 0)
{
m_Disks->setCurrentIndex(0);
updatePartitions(0);
}
if ( m_Disks->count() == 0 )
{
qDebug() << "disk not found";
QMessageBox::critical(this, tr("Error"), tr("Disks not found"));
emit changeNext(false);
}
}
void PagePartitioning::updatePartitions(int num)
{
m_Partitions->clear();
if (m_Disks->count() > 0 )
{
QString dev = m_Disks->itemData(num).toString();
if ( !dev.isEmpty() )
{
if ( m_PartitionsMap.find(dev) != m_PartitionsMap.end() )
{
QList<PartitionDesc> partitions = m_PartitionsMap[dev];
foreach(PartitionDesc part_desc, partitions )
m_Partitions->addItem(part_desc.first, QVariant(part_desc.second) );
}
}
}
}
void PagePartitioning::partitioningCurrentDisk()
{
if (m_Disks->count() != 0)
emit manualyPartitioning( m_Disks->itemData(m_Disks->currentIndex()).toString() );
}