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.
311 lines
7.4 KiB
311 lines
7.4 KiB
#include "pagemountpoints.h"
|
|
|
|
#include <QLabel>
|
|
#include <QTreeWidget>
|
|
#include <QBoxLayout>
|
|
#include <QMessageBox>
|
|
|
|
#include <QDebug>
|
|
|
|
#include "calculateconfig.h"
|
|
#include "mountpointdialog.h"
|
|
|
|
PageMountPoints::PageMountPoints()
|
|
: InstallerPage()
|
|
{
|
|
setupUi();
|
|
}
|
|
|
|
void PageMountPoints::setupUi()
|
|
{
|
|
m_labMountPoints = new QLabel;
|
|
m_trwMountPoints = new QTreeWidget;
|
|
m_labMountPointHelp = new QLabel;
|
|
|
|
|
|
QVBoxLayout* vbox_0 = new QVBoxLayout;
|
|
vbox_0->addWidget(m_labMountPoints);
|
|
vbox_0->addWidget(m_trwMountPoints);
|
|
vbox_0->addWidget(m_labMountPointHelp);
|
|
|
|
setLayout(vbox_0);
|
|
|
|
connect( m_trwMountPoints, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
|
|
this, SLOT(partitionDoubleClicked(QTreeWidgetItem*,int))
|
|
);
|
|
|
|
retranslateUi();
|
|
}
|
|
|
|
void PageMountPoints::retranslateUi()
|
|
{
|
|
setTitle( tr("Mount points") );
|
|
|
|
QTreeWidgetItem* trwHeader = m_trwMountPoints->headerItem();
|
|
trwHeader->setText(0, tr("Partition") );
|
|
trwHeader->setText(1, tr("Label") );
|
|
trwHeader->setText(2, tr("Size") );
|
|
trwHeader->setText(3, tr("Mount point") );
|
|
trwHeader->setText(4, tr("File system") );
|
|
trwHeader->setText(5, tr("Format") );
|
|
|
|
m_labMountPoints->setText( tr("Select mount points:") );
|
|
|
|
m_labMountPointHelp->setText( tr("Set the desired mount points. For continue must be set mount point for /") );
|
|
}
|
|
|
|
void PageMountPoints::show()
|
|
{
|
|
// get tree from CalculateConfig
|
|
getTree();
|
|
showTree();
|
|
|
|
m_trwMountPoints->setColumnWidth(0, 120);
|
|
m_trwMountPoints->setColumnWidth(1, 100);
|
|
m_trwMountPoints->setColumnWidth(2, 80);
|
|
m_trwMountPoints->setColumnWidth(3, 110);
|
|
m_trwMountPoints->setColumnWidth(4, 80);
|
|
|
|
m_trwMountPoints->setEnabled(true);
|
|
CalculateConfig::instance()->showInstallParameters();
|
|
if ( CalculateConfig::instance()->getValue("gui_partitioning") == "auto" )
|
|
{
|
|
QMessageBox::information(
|
|
this,
|
|
tr("Information"),
|
|
tr("You select auto partitioning. Press \"Next\" to continue.")
|
|
);
|
|
m_trwMountPoints->setEnabled(false);
|
|
emit changeNext(true);
|
|
}
|
|
}
|
|
|
|
bool PageMountPoints::validate()
|
|
{
|
|
if ( CalculateConfig::instance()->getValue("gui_partitioning") != "auto" )
|
|
{
|
|
// check parameters
|
|
MountPointsTree::ConstIterator it = m_treeMountPoints.constBegin();
|
|
|
|
while( it != m_treeMountPoints.constEnd() )
|
|
{
|
|
foreach(const MountPoint& mp, it.value())
|
|
{
|
|
if ( !mp.mountpoint.isEmpty() && (mp.fs_new != "swap") )
|
|
{
|
|
if (mp.mountpoint == "/")
|
|
return true;
|
|
}
|
|
}
|
|
++it;
|
|
}
|
|
QMessageBox::warning(this, tr("Warning"), tr("Select mount point for /") );
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void PageMountPoints::partitionDoubleClicked ( QTreeWidgetItem* item, int index )
|
|
{
|
|
// skip disks
|
|
if (item->childCount() != 0)
|
|
return;
|
|
|
|
if (item->parent() == 0)
|
|
return;
|
|
|
|
QString dev = item->parent()->text(0);
|
|
QString part = item->text(0);
|
|
|
|
//qDebug() << "selected :" << dev << " " << part;
|
|
|
|
// find data
|
|
MountPointsList mpList = m_treeMountPoints[dev];
|
|
|
|
int mpIndex = -1;
|
|
foreach(const MountPoint& mpItem, mpList)
|
|
{
|
|
++mpIndex;
|
|
if (mpItem.dev == part)
|
|
break;
|
|
}
|
|
|
|
//qDebug() << "index: " << mpIndex;
|
|
|
|
if (mpIndex >= 0)
|
|
{
|
|
MountPoint mp( mpList.at(mpIndex) );
|
|
|
|
QScopedPointer<MountPointDialog> mpDlg( new MountPointDialog(this, &mp) );
|
|
|
|
if ( mpDlg->exec() == QDialog::Accepted )
|
|
{
|
|
// replace information
|
|
mpList.replace(mpIndex, mp);
|
|
m_treeMountPoints.remove(dev);
|
|
m_treeMountPoints[dev] = mpList;
|
|
|
|
showTree();
|
|
}
|
|
}
|
|
}
|
|
|
|
void PageMountPoints::getTree()
|
|
{
|
|
MountPointsTree copyTree(m_treeMountPoints);
|
|
|
|
m_treeMountPoints.clear();
|
|
|
|
QStringList os_disk_dev = CalculateConfig::instance()->getValue("os_disk_dev").toStringList();
|
|
QStringList os_disk_format = CalculateConfig::instance()->getValue("os_disk_format").toStringList();
|
|
QStringList os_disk_name = CalculateConfig::instance()->getValue("os_disk_name").toStringList();
|
|
QStringList os_disk_part = CalculateConfig::instance()->getValue("os_disk_part").toStringList();
|
|
QStringList os_disk_size = CalculateConfig::instance()->getValue("os_disk_size").toStringList();
|
|
|
|
QStringList os_dev_dev = CalculateConfig::instance()->getValue("os_device_dev").toStringList();
|
|
|
|
foreach(const QString& dev, os_dev_dev)
|
|
{
|
|
for (int i(0); i < os_disk_dev.size(); ++i)
|
|
{
|
|
MountPoint mountpoint;
|
|
|
|
if (
|
|
(os_disk_part.at(i) != "extended") &&
|
|
(os_disk_dev.at(i).contains(dev, Qt::CaseInsensitive))
|
|
)
|
|
{
|
|
mountpoint.dev = os_disk_dev.at(i);
|
|
mountpoint.label = os_disk_name.at(i);
|
|
mountpoint.size = os_disk_size.at(i);
|
|
mountpoint.fs = os_disk_format.at(i);
|
|
|
|
if ( m_treeMountPoints.contains(dev) )
|
|
{
|
|
if (copyTree.contains(dev))
|
|
{
|
|
foreach(MountPoint mp, copyTree[dev])
|
|
{
|
|
if (mp.dev == mountpoint.dev)
|
|
{
|
|
mountpoint.mountpoint = mp.mountpoint;
|
|
mountpoint.format = mp.format;
|
|
mountpoint.fs_new = mp.fs_new;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
m_treeMountPoints[dev] << mountpoint;
|
|
}
|
|
else
|
|
{
|
|
MountPointsList lst = MountPointsList() << mountpoint;
|
|
m_treeMountPoints[dev] = lst;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void PageMountPoints::showTree()
|
|
{
|
|
m_trwMountPoints->clear();
|
|
|
|
MountPointsTree::ConstIterator it = m_treeMountPoints.constBegin();
|
|
|
|
while( it != m_treeMountPoints.constEnd() )
|
|
{
|
|
showBranch( it.key(), it.value() );
|
|
++it;
|
|
}
|
|
|
|
m_trwMountPoints->expandAll();
|
|
|
|
generateCmdDisk();
|
|
}
|
|
|
|
void PageMountPoints::showBranch(const QString& dev, const MountPointsList& list)
|
|
{
|
|
QTreeWidgetItem* trwItem_0 = new QTreeWidgetItem;
|
|
trwItem_0->setText(0, dev );
|
|
trwItem_0->setText(1, "" );
|
|
trwItem_0->setText(2, "" );
|
|
trwItem_0->setText(3, "" );
|
|
trwItem_0->setText(4, "" );
|
|
trwItem_0->setText(5, "" );
|
|
|
|
foreach(const MountPoint& mp, list)
|
|
{
|
|
QTreeWidgetItem* trwItem_0_0 = new QTreeWidgetItem(trwItem_0);
|
|
trwItem_0_0->setText(0, mp.dev ); // Partition
|
|
trwItem_0_0->setText(1, mp.label ); // Label
|
|
trwItem_0_0->setText(2, mp.size ); // Size
|
|
trwItem_0_0->setText(3, mp.mountpoint ); // Mount point
|
|
trwItem_0_0->setText(4, mp.fs_new.isEmpty() ? mp.fs : mp.fs_new ); // File system
|
|
trwItem_0_0->setText(5, mp.fs_new.isEmpty() ? tr("no") : tr("YES") ); // Format
|
|
}
|
|
|
|
m_trwMountPoints->insertTopLevelItem(m_trwMountPoints->topLevelItemCount(), trwItem_0);
|
|
}
|
|
|
|
void PageMountPoints::generateCmdDisk()
|
|
{
|
|
if ( CalculateConfig::instance()->getValue("gui_partitioning") != "auto" )
|
|
{
|
|
QStringList diskCfg = parseMountPoint();
|
|
qDebug() << "--disk " << diskCfg.join(" ");
|
|
CalculateConfig::instance()->setValue( "--disk", diskCfg );
|
|
|
|
QString swapCfg = parseSwap();
|
|
qDebug() << "--swap " << swapCfg;
|
|
CalculateConfig::instance()->setValue( "--swap", swapCfg );
|
|
}
|
|
CalculateConfig::instance()->showInstallParameters();
|
|
}
|
|
|
|
QStringList PageMountPoints::parseMountPoint()
|
|
{
|
|
QStringList result;
|
|
|
|
MountPointsTree::ConstIterator it = m_treeMountPoints.constBegin();
|
|
|
|
while( it != m_treeMountPoints.constEnd() )
|
|
{
|
|
foreach(const MountPoint& mp, it.value())
|
|
{
|
|
if ( !mp.mountpoint.isEmpty() && (mp.fs_new != "swap") )
|
|
{
|
|
QString resultStr = mp.dev + ":" + mp.mountpoint;
|
|
if (mp.format && !mp.fs_new.isEmpty())
|
|
resultStr += ":" + mp.fs_new;
|
|
resultStr += " ";
|
|
|
|
result << resultStr;
|
|
}
|
|
}
|
|
++it;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
QString PageMountPoints::parseSwap()
|
|
{
|
|
QString result;
|
|
|
|
MountPointsTree::ConstIterator it = m_treeMountPoints.constBegin();
|
|
|
|
while( it != m_treeMountPoints.constEnd() )
|
|
{
|
|
foreach(const MountPoint& mp, it.value())
|
|
{
|
|
if ( mp.fs_new == "swap" )
|
|
return mp.dev;
|
|
}
|
|
++it;
|
|
}
|
|
|
|
return QString();
|
|
}
|