2014-06-27 17:25:39 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* 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 "PartitionPage.h"
|
|
|
|
|
|
|
|
// Local
|
2014-06-30 18:08:13 +02:00
|
|
|
#include <CreatePartitionDialog.h>
|
2014-06-27 17:25:39 +02:00
|
|
|
#include <DeviceModel.h>
|
2014-06-30 13:37:46 +02:00
|
|
|
#include <PartitionCoreModule.h>
|
2014-06-27 17:25:39 +02:00
|
|
|
#include <PartitionModel.h>
|
2014-06-30 15:04:10 +02:00
|
|
|
#include <PMUtils.h>
|
2014-06-27 17:25:39 +02:00
|
|
|
#include <ui_PartitionPage.h>
|
|
|
|
|
2014-07-10 19:55:16 +02:00
|
|
|
// CalaPM
|
|
|
|
#include <core/device.h>
|
|
|
|
|
2014-06-27 17:25:39 +02:00
|
|
|
// Qt
|
|
|
|
#include <QDebug>
|
2014-07-02 17:55:53 +02:00
|
|
|
#include <QHeaderView>
|
2014-06-27 17:42:13 +02:00
|
|
|
#include <QItemSelectionModel>
|
2014-07-10 19:55:16 +02:00
|
|
|
#include <QMessageBox>
|
2014-07-01 16:46:33 +02:00
|
|
|
#include <QPointer>
|
2014-06-27 17:25:39 +02:00
|
|
|
|
2014-07-02 16:06:54 +02:00
|
|
|
PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent )
|
2014-07-03 18:00:40 +02:00
|
|
|
: QWidget( parent )
|
2014-06-27 17:25:39 +02:00
|
|
|
, m_ui( new Ui_PartitionPage )
|
2014-07-02 16:06:54 +02:00
|
|
|
, m_core( core )
|
2014-06-27 17:25:39 +02:00
|
|
|
{
|
|
|
|
m_ui->setupUi( this );
|
2014-06-30 13:48:40 +02:00
|
|
|
m_ui->deviceListView->setModel( m_core->deviceModel() );
|
2014-06-30 15:04:10 +02:00
|
|
|
updateButtons();
|
2014-06-27 17:25:39 +02:00
|
|
|
|
2014-06-27 17:42:13 +02:00
|
|
|
connect( m_ui->deviceListView->selectionModel(), &QItemSelectionModel::currentChanged,
|
2014-06-27 18:42:15 +02:00
|
|
|
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
|
|
|
{
|
2014-06-30 14:12:23 +02:00
|
|
|
Device* device = m_core->deviceModel()->deviceForIndex( index );
|
|
|
|
PartitionModel* model = m_core->partitionModelForDevice( device );
|
2014-07-02 17:55:53 +02:00
|
|
|
m_ui->partitionTreeView->setModel( model );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
2014-06-30 15:04:10 +02:00
|
|
|
updateButtons();
|
|
|
|
// Establish connection here because selection model is destroyed when
|
|
|
|
// model changes
|
2014-07-02 17:55:53 +02:00
|
|
|
connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
|
2014-06-30 15:04:10 +02:00
|
|
|
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
|
|
|
{
|
|
|
|
updateButtons();
|
|
|
|
} );
|
2014-06-30 16:17:28 +02:00
|
|
|
connect( model, &QAbstractItemModel::modelReset, this, &PartitionPage::updateButtons );
|
2014-06-27 18:42:15 +02:00
|
|
|
} );
|
2014-06-30 16:17:28 +02:00
|
|
|
|
2014-07-10 19:55:16 +02:00
|
|
|
connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
|
2014-06-30 16:17:28 +02:00
|
|
|
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
2014-07-02 15:49:35 +02:00
|
|
|
connect( m_ui->deleteButton, &QAbstractButton::clicked, this, &PartitionPage::onDeleteClicked );
|
2014-06-27 17:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PartitionPage::~PartitionPage()
|
|
|
|
{
|
|
|
|
}
|
2014-06-30 15:04:10 +02:00
|
|
|
|
2014-07-02 14:12:47 +02:00
|
|
|
void
|
|
|
|
PartitionPage::updateButtons()
|
2014-06-30 15:04:10 +02:00
|
|
|
{
|
|
|
|
bool create = false, edit = false, del = false;
|
|
|
|
|
2014-07-02 17:55:53 +02:00
|
|
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
2014-06-30 15:04:10 +02:00
|
|
|
if ( index.isValid() )
|
|
|
|
{
|
|
|
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
|
|
|
Q_ASSERT( model );
|
|
|
|
Partition* partition = model->partitionForIndex( index );
|
|
|
|
Q_ASSERT( partition );
|
|
|
|
bool isFree = PMUtils::isPartitionFreeSpace( partition );
|
|
|
|
create = isFree;
|
|
|
|
edit = del = !isFree;
|
|
|
|
}
|
|
|
|
m_ui->createButton->setEnabled( create );
|
|
|
|
m_ui->editButton->setEnabled( edit );
|
|
|
|
m_ui->deleteButton->setEnabled( del );
|
2014-07-10 19:55:16 +02:00
|
|
|
|
|
|
|
m_ui->newPartitionTableButton->setEnabled( m_ui->deviceListView->currentIndex().isValid() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PartitionPage::onNewPartitionTableClicked()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_ui->deviceListView->currentIndex();
|
|
|
|
Q_ASSERT( index.isValid() );
|
|
|
|
Device* device = m_core->deviceModel()->deviceForIndex( index );
|
|
|
|
|
|
|
|
auto answer = QMessageBox::warning( this,
|
2014-07-15 11:11:17 +02:00
|
|
|
tr( "New Partition Table" ),
|
|
|
|
tr( "Are you sure you want to create a new partition table on %1?\n"
|
|
|
|
"Creating a new partition table will delete all existing data on the disk." )
|
|
|
|
.arg( device->name() ),
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel,
|
|
|
|
QMessageBox::Cancel
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( answer != QMessageBox::Ok )
|
2014-07-10 19:55:16 +02:00
|
|
|
return;
|
|
|
|
m_core->createPartitionTable( device );
|
2014-06-30 15:04:10 +02:00
|
|
|
}
|
2014-06-30 16:17:28 +02:00
|
|
|
|
2014-07-02 14:12:47 +02:00
|
|
|
void
|
|
|
|
PartitionPage::onCreateClicked()
|
2014-06-30 16:17:28 +02:00
|
|
|
{
|
2014-07-02 17:55:53 +02:00
|
|
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
2014-06-30 16:17:28 +02:00
|
|
|
Q_ASSERT( index.isValid() );
|
|
|
|
|
|
|
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
|
|
|
Partition* partition = model->partitionForIndex( index );
|
|
|
|
Q_ASSERT( partition );
|
|
|
|
|
2014-07-01 16:46:33 +02:00
|
|
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition, this );
|
|
|
|
if ( dlg->exec() == QDialog::Accepted )
|
2014-07-04 17:58:32 +02:00
|
|
|
m_core->createPartition( model->device(), dlg->createPartitionInfo() );
|
2014-07-01 16:46:33 +02:00
|
|
|
delete dlg;
|
2014-06-30 16:17:28 +02:00
|
|
|
}
|
2014-07-02 15:49:35 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
PartitionPage::onDeleteClicked()
|
|
|
|
{
|
2014-07-02 17:55:53 +02:00
|
|
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
2014-07-02 15:49:35 +02:00
|
|
|
Q_ASSERT( index.isValid() );
|
|
|
|
|
|
|
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
|
|
|
Partition* partition = model->partitionForIndex( index );
|
|
|
|
Q_ASSERT( partition );
|
|
|
|
|
|
|
|
m_core->deletePartition( model->device(), partition );
|
|
|
|
}
|