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

124 lines
2.9 KiB

#include "pagepartitioning.h"
#include <QRadioButton>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QBoxLayout>
#include <QScopedPointer>
#include <QtDebug>
#include "libparted.h"
PagePartitioning::PagePartitioning(const QString& title) :
InstallerPage(title)
{
// widgets
QLabel* labDisk = new QLabel( tr("Disk for install: ") );
m_ButExistPartition = new QRadioButton( tr("Use existing partition") );
m_ButAllDisk = new QRadioButton( tr("Use automatical partitioning") );
m_ButPartitioning = new QPushButton( tr("Manualy partitioning") );
m_Partitions = new QComboBox;
m_Disks = new QComboBox;
// layouts
QHBoxLayout* hbox_1 = new QHBoxLayout;
hbox_1->addWidget(labDisk);
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();
m_Widget->setLayout(vbox_1);
m_ButExistPartition->setChecked(true);
connect( m_ButExistPartition, SIGNAL(toggled(bool)), m_Partitions, SLOT(setEnabled(bool)));
connect( m_ButPartitioning, SIGNAL(clicked()), this, SIGNAL(manualyPartitioning()) );
connect( m_Disks, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePartitions(int)) );
}
bool PagePartitioning::validate()
{
return true;
}
void PagePartitioning::show()
{
m_Disks->clear();
m_Partitions->clear();
m_PartitionsMap.clear();
// get disk & partitions
QScopedPointer<LibParted> libParted( new LibParted );
qDebug() << "parted version: " << libParted->getVersion();
QStringList disks = libParted->getDevices();
foreach(const QString& dev, disks)
{
DeviceInfo dev_info = libParted->getDeviceInfo(dev);
QString disk_info = QString("%1 (%2) - %3 MB").arg(dev).arg(dev_info.model).arg(dev_info.size);
m_Disks->addItem(disk_info, QVariant(dev));
QList<PartitionInfo> part_list = libParted->getPartitionList(dev);
QStringList partitions;
foreach(const PartitionInfo& part, part_list)
{
if (part.type == "extended")
continue;
QString part_info = QString("%1%2\t%3 MB\t%4").arg(dev).arg(part.num).arg(part.size).arg(part.fs);
partitions << part_info;
}
m_PartitionsMap[dev] = partitions;
}
if (m_Disks->count() > 0)
{
m_Disks->setCurrentIndex(0);
updatePartitions(0);
}
}
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() )
{
QStringList part_list = m_PartitionsMap[dev];
m_Partitions->addItems(part_list);
}
}
}
}