2020-09-16 00:35:12 +01:00
/*
SPDX - FileCopyrightText : 2008 - 2012 Volker Lanz < vl @ fidra . de >
SPDX - FileCopyrightText : 2014 - 2020 Andrius Š tikonas < andrius @ stikonas . eu >
SPDX - FileCopyrightText : 2015 - 2016 Teo Mrnjavac < teo @ kde . org >
SPDX - FileCopyrightText : 2016 Chantara Tith < tith . chantara @ gmail . com >
SPDX - FileCopyrightText : 2018 Abhijeet Sharma < sharma . abhijeet2096 @ gmail . com >
SPDX - License - Identifier : GPL - 3.0 - or - later
*/
2009-04-21 17:36:43 +01:00
# include "gui/partitionmanagerwidget.h"
# include "gui/partpropsdialog.h"
# include "gui/resizedialog.h"
# include "gui/newdialog.h"
2010-02-11 18:47:51 +00:00
# include "gui/applyprogressdialog.h"
2009-04-21 17:36:43 +01:00
# include "gui/insertdialog.h"
2010-01-15 18:08:01 +00:00
# include "gui/editmountpointdialog.h"
2017-09-14 20:42:43 +01:00
# include "util/guihelpers.h"
2009-04-21 17:36:43 +01:00
2016-01-12 00:12:49 +00:00
# include <core/partition.h>
# include <core/device.h>
# include <core/operationstack.h>
# include <core/partitiontable.h>
2009-04-21 17:36:43 +01:00
2016-01-12 00:12:49 +00:00
# include <fs/filesystemfactory.h>
2016-03-31 17:20:34 +01:00
# include <fs/luks.h>
2009-04-21 17:36:43 +01:00
2016-01-12 00:12:49 +00:00
# include <gui/partwidget.h>
2015-07-08 17:16:03 +01:00
2016-01-12 00:12:49 +00:00
# include <ops/deleteoperation.h>
# include <ops/resizeoperation.h>
# include <ops/newoperation.h>
# include <ops/copyoperation.h>
# include <ops/checkoperation.h>
# include <ops/backupoperation.h>
# include <ops/restoreoperation.h>
# include <ops/setfilesystemlabeloperation.h>
# include <ops/setpartflagsoperation.h>
# include <ops/createfilesystemoperation.h>
2009-04-21 17:36:43 +01:00
2016-01-12 00:12:49 +00:00
# include <util/globallog.h>
# include <util/capacity.h>
# include <util/report.h>
# include <util/helpers.h>
2016-03-31 17:20:34 +01:00
2014-05-18 21:41:48 +01:00
# include <QFileDialog>
2014-05-13 23:53:37 +01:00
# include <QLocale>
2009-08-03 21:08:38 +01:00
# include <QPointer>
2010-02-13 11:25:56 +00:00
# include <QReadLocker>
2009-04-21 17:36:43 +01:00
2014-05-18 21:41:48 +01:00
# include <KLocalizedString>
# include <KMessageBox>
2009-04-21 17:36:43 +01:00
# include <config.h>
2016-04-19 16:08:01 +01:00
# include <typeinfo>
2009-04-21 17:36:43 +01:00
class PartitionTreeWidgetItem : public QTreeWidgetItem
{
2015-07-13 15:17:41 +01:00
Q_DISABLE_COPY ( PartitionTreeWidgetItem )
2009-11-09 13:51:08 +00:00
2015-07-13 15:17:41 +01:00
public :
PartitionTreeWidgetItem ( const Partition * p ) : QTreeWidgetItem ( ) , m_Partition ( p ) { }
const Partition * partition ( ) const {
return m_Partition ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
private :
const Partition * m_Partition ;
2009-04-21 17:36:43 +01:00
} ;
/** Creates a new PartitionManagerWidget instance.
2015-07-13 15:17:41 +01:00
@ param parent the parent widget
2009-04-21 17:36:43 +01:00
*/
2010-02-23 16:30:05 +00:00
PartitionManagerWidget : : PartitionManagerWidget ( QWidget * parent ) :
2015-07-13 15:17:41 +01:00
QWidget ( parent ) ,
Ui : : PartitionManagerWidgetBase ( ) ,
2016-03-31 17:20:34 +01:00
m_OperationStack ( nullptr ) ,
m_SelectedDevice ( nullptr ) ,
m_ClipboardPartition ( nullptr )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
setupUi ( this ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
treePartitions ( ) . header ( ) - > setStretchLastSection ( false ) ;
treePartitions ( ) . header ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2009-04-21 17:36:43 +01:00
}
PartitionManagerWidget : : ~ PartitionManagerWidget ( )
{
2015-07-13 15:17:41 +01:00
saveConfig ( ) ;
2009-04-21 17:36:43 +01:00
}
2010-03-07 19:02:02 +00:00
void PartitionManagerWidget : : init ( OperationStack * ostack )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
m_OperationStack = ostack ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
loadConfig ( ) ;
setupConnections ( ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : loadConfig ( )
{
2015-07-13 15:17:41 +01:00
QList < int > colWidths = Config : : treePartitionColumnWidths ( ) ;
QList < int > colPositions = Config : : treePartitionColumnPositions ( ) ;
QList < int > colVisible = Config : : treePartitionColumnVisible ( ) ;
QHeaderView * header = treePartitions ( ) . header ( ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
for ( int i = 0 ; i < treePartitions ( ) . columnCount ( ) ; i + + ) {
if ( colPositions [ 0 ] ! = - 1 & & colPositions . size ( ) > i )
header - > moveSection ( header - > visualIndex ( i ) , colPositions [ i ] ) ;
2010-02-16 20:07:33 +00:00
2015-07-13 15:17:41 +01:00
if ( colVisible [ 0 ] ! = - 1 & & colVisible . size ( ) > i )
treePartitions ( ) . setColumnHidden ( i , colVisible [ i ] = = 0 ) ;
2010-02-16 20:07:33 +00:00
2015-07-13 15:17:41 +01:00
if ( colWidths [ 0 ] ! = - 1 & & colWidths . size ( ) > i )
treePartitions ( ) . setColumnWidth ( i , colWidths [ i ] ) ;
}
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : saveConfig ( ) const
{
2015-07-13 15:17:41 +01:00
QList < int > colWidths ;
QList < int > colPositions ;
QList < int > colVisible ;
2010-02-16 20:07:33 +00:00
2015-07-13 15:17:41 +01:00
for ( int i = 0 ; i < treePartitions ( ) . columnCount ( ) ; i + + ) {
colPositions . append ( treePartitions ( ) . header ( ) - > visualIndex ( i ) ) ;
colVisible . append ( treePartitions ( ) . isColumnHidden ( i ) ? 0 : 1 ) ;
colWidths . append ( treePartitions ( ) . columnWidth ( i ) ) ;
}
2010-02-16 20:07:33 +00:00
2015-07-13 15:17:41 +01:00
Config : : setTreePartitionColumnPositions ( colPositions ) ;
Config : : setTreePartitionColumnVisible ( colVisible ) ;
Config : : setTreePartitionColumnWidths ( colWidths ) ;
2009-04-22 10:22:46 +01:00
2015-07-13 15:17:41 +01:00
Config : : self ( ) - > save ( ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : setupConnections ( )
{
2016-05-18 22:23:59 +01:00
connect ( treePartitions ( ) . header ( ) , & QHeaderView : : customContextMenuRequested , this , & PartitionManagerWidget : : onHeaderContextMenu ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : clear ( )
{
2016-03-31 17:20:34 +01:00
setSelectedDevice ( nullptr ) ;
setClipboardPartition ( nullptr ) ;
2015-07-13 15:17:41 +01:00
treePartitions ( ) . clear ( ) ;
partTableWidget ( ) . clear ( ) ;
2009-04-21 17:36:43 +01:00
}
2010-02-23 16:30:05 +00:00
void PartitionManagerWidget : : setSelectedPartition ( const Partition * p )
2009-04-21 17:36:43 +01:00
{
2016-03-31 17:20:34 +01:00
if ( p = = nullptr ) {
treePartitions ( ) . setCurrentItem ( nullptr ) ;
2020-09-15 02:26:38 +01:00
Q_EMIT selectedPartitionChanged ( nullptr ) ;
2015-07-13 15:17:41 +01:00
updatePartitions ( ) ;
} else
partTableWidget ( ) . setActivePartition ( p ) ;
2010-02-23 16:30:05 +00:00
}
Partition * PartitionManagerWidget : : selectedPartition ( )
{
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedDevice ( ) - > partitionTable ( ) = = nullptr | | partTableWidget ( ) . activeWidget ( ) = = nullptr )
return nullptr ;
2010-02-23 16:30:05 +00:00
2018-03-03 16:34:41 +00:00
return partTableWidget ( ) . activeWidget ( ) - > partition ( ) ;
2009-04-21 17:36:43 +01:00
}
2016-08-08 19:39:20 +01:00
void PartitionManagerWidget : : setSelectedDevice ( const QString & deviceNode )
2010-02-12 11:29:12 +00:00
{
2015-07-13 15:17:41 +01:00
QReadLocker lockDevices ( & operationStack ( ) . lock ( ) ) ;
2010-02-13 11:25:56 +00:00
2016-09-01 00:44:33 +01:00
const auto previewDevices = operationStack ( ) . previewDevices ( ) ;
for ( const auto & d : previewDevices ) {
2016-08-08 19:39:20 +01:00
if ( d - > deviceNode ( ) = = deviceNode ) {
setSelectedDevice ( d ) ;
return ;
}
2015-07-13 15:17:41 +01:00
}
2010-02-12 11:29:12 +00:00
2016-03-31 17:20:34 +01:00
setSelectedDevice ( nullptr ) ;
2010-02-12 11:29:12 +00:00
}
2010-01-19 10:34:53 +00:00
void PartitionManagerWidget : : setSelectedDevice ( Device * d )
{
2015-07-13 15:17:41 +01:00
m_SelectedDevice = d ;
2016-03-31 17:20:34 +01:00
setSelectedPartition ( nullptr ) ;
2010-01-19 10:34:53 +00:00
}
2009-04-21 17:36:43 +01:00
static QTreeWidgetItem * createTreeWidgetItem ( const Partition & p )
{
2015-07-13 15:17:41 +01:00
QTreeWidgetItem * item = new PartitionTreeWidgetItem ( & p ) ;
2009-04-21 17:36:43 +01:00
2017-09-11 18:46:48 +01:00
int i = 0 ;
2015-07-13 15:17:41 +01:00
item - > setText ( i + + , p . deviceNode ( ) ) ;
2010-02-17 19:39:24 +00:00
2018-04-07 19:54:55 +01:00
if ( p . roles ( ) . has ( PartitionRole : : Luks ) & & ( p . fileSystem ( ) . name ( ) ! = p . fileSystem ( ) . nameForType ( FileSystem : : Type : : Luks ) & & p . fileSystem ( ) . name ( ) ! = p . fileSystem ( ) . nameForType ( FileSystem : : Type : : Luks2 ) ) )
2017-12-28 00:53:45 +00:00
item - > setText ( i , xi18nc ( " @item:intable Encrypted file systems, e.g. btrfs[Encrypted] " , " %1 [Encrypted] " , p . fileSystem ( ) . name ( ) ) ) ;
2016-05-17 01:25:52 +01:00
else
item - > setText ( i , p . fileSystem ( ) . name ( ) ) ;
2015-07-13 15:17:41 +01:00
item - > setIcon ( i , createFileSystemColor ( p . fileSystem ( ) . type ( ) , 14 ) ) ;
i + + ;
2010-02-17 16:11:16 +00:00
2015-07-13 15:17:41 +01:00
item - > setText ( i , p . mountPoint ( ) ) ;
if ( p . isMounted ( ) )
2020-09-29 17:54:53 +01:00
item - > setIcon ( i , QIcon : : fromTheme ( QStringLiteral ( " object-locked " ) ) ) ;
2015-07-13 15:17:41 +01:00
i + + ;
2010-02-17 16:11:16 +00:00
2015-07-13 15:17:41 +01:00
item - > setText ( i + + , p . fileSystem ( ) . label ( ) ) ;
item - > setText ( i + + , p . fileSystem ( ) . uuid ( ) ) ;
2018-01-27 23:02:36 +00:00
item - > setText ( i + + , p . label ( ) ) ;
item - > setText ( i + + , p . uuid ( ) ) ;
2015-07-13 15:17:41 +01:00
item - > setText ( i + + , Capacity : : formatByteSize ( p . capacity ( ) ) ) ;
item - > setText ( i + + , Capacity : : formatByteSize ( p . used ( ) ) ) ;
item - > setText ( i + + , Capacity : : formatByteSize ( p . available ( ) ) ) ;
2010-02-17 16:11:16 +00:00
2015-07-13 15:17:41 +01:00
item - > setText ( i + + , QLocale ( ) . toString ( p . firstSector ( ) ) ) ;
item - > setText ( i + + , QLocale ( ) . toString ( p . lastSector ( ) ) ) ;
item - > setText ( i + + , QLocale ( ) . toString ( p . length ( ) ) ) ;
2010-02-17 16:11:16 +00:00
2015-07-13 15:17:41 +01:00
item - > setText ( i + + , PartitionTable : : flagNames ( p . activeFlags ( ) ) . join ( QStringLiteral ( " , " ) ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
item - > setSizeHint ( 0 , QSize ( 0 , 32 ) ) ;
2010-01-07 19:23:34 +00:00
2015-07-13 15:17:41 +01:00
return item ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : updatePartitions ( )
{
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr )
2015-07-13 15:17:41 +01:00
return ;
2010-01-28 16:43:27 +00:00
2015-07-13 15:17:41 +01:00
treePartitions ( ) . clear ( ) ;
partTableWidget ( ) . clear ( ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
partTableWidget ( ) . setPartitionTable ( selectedDevice ( ) - > partitionTable ( ) ) ;
2010-01-07 19:23:34 +00:00
2015-07-13 15:17:41 +01:00
QTreeWidgetItem * deviceItem = new QTreeWidgetItem ( ) ;
2010-05-19 19:38:00 +01:00
2015-07-13 15:17:41 +01:00
QFont font ;
font . setBold ( true ) ;
font . setWeight ( 75 ) ;
deviceItem - > setFont ( 0 , font ) ;
2010-05-19 19:38:00 +01:00
2015-07-13 15:17:41 +01:00
deviceItem - > setText ( 0 , selectedDevice ( ) - > prettyName ( ) ) ;
2020-09-29 17:54:53 +01:00
deviceItem - > setIcon ( 0 , QIcon : : fromTheme ( selectedDevice ( ) - > iconName ( ) ) ) ;
2015-04-09 21:26:40 +01:00
2015-07-13 15:17:41 +01:00
deviceItem - > setSizeHint ( 0 , QSize ( 0 , 32 ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
treePartitions ( ) . addTopLevelItem ( deviceItem ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) - > partitionTable ( ) ! = nullptr ) {
2016-09-01 00:44:33 +01:00
const auto children = selectedDevice ( ) - > partitionTable ( ) - > children ( ) ;
for ( const auto * p : children ) {
2015-07-13 15:17:41 +01:00
QTreeWidgetItem * item = createTreeWidgetItem ( * p ) ;
2009-04-21 17:36:43 +01:00
2016-09-01 00:44:33 +01:00
for ( const auto & child : p - > children ( ) ) {
2015-07-13 15:17:41 +01:00
QTreeWidgetItem * childItem = createTreeWidgetItem ( * child ) ;
item - > addChild ( childItem ) ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
deviceItem - > addChild ( item ) ;
item - > setExpanded ( true ) ;
}
}
2009-04-21 17:36:43 +01:00
2019-09-27 23:09:05 +01:00
deviceItem - > setFirstColumnSpanned ( true ) ;
2015-07-13 15:17:41 +01:00
deviceItem - > setExpanded ( true ) ;
deviceItem - > setFlags ( Qt : : ItemIsEnabled ) ;
2010-01-28 16:43:27 +00:00
2015-07-13 15:17:41 +01:00
partTableWidget ( ) . update ( ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : on_m_TreePartitions_currentItemChanged ( QTreeWidgetItem * current , QTreeWidgetItem * )
{
2015-07-13 15:17:41 +01:00
if ( current ) {
const PartitionTreeWidgetItem * ptwItem = dynamic_cast < PartitionTreeWidgetItem * > ( current ) ;
2016-03-31 17:20:34 +01:00
partTableWidget ( ) . setActivePartition ( ptwItem ? ptwItem - > partition ( ) : nullptr ) ;
2015-07-13 15:17:41 +01:00
} else
2016-03-31 17:20:34 +01:00
partTableWidget ( ) . setActiveWidget ( nullptr ) ;
2009-04-21 17:36:43 +01:00
}
2010-01-28 16:43:27 +00:00
void PartitionManagerWidget : : on_m_TreePartitions_itemDoubleClicked ( QTreeWidgetItem * item , int )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
if ( item = = treePartitions ( ) . topLevelItem ( 0 ) ) {
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) ! = nullptr )
2020-09-15 02:26:38 +01:00
Q_EMIT deviceDoubleClicked ( selectedDevice ( ) ) ;
2015-07-13 15:17:41 +01:00
} else {
2016-03-31 17:20:34 +01:00
if ( selectedPartition ( ) ! = nullptr )
2020-09-15 02:26:38 +01:00
Q_EMIT partitionDoubleClicked ( selectedPartition ( ) ) ;
2015-07-13 15:17:41 +01:00
}
2009-04-21 17:36:43 +01:00
}
2010-02-16 20:07:33 +00:00
void PartitionManagerWidget : : onHeaderContextMenu ( const QPoint & p )
{
2015-07-13 15:17:41 +01:00
showColumnsContextMenu ( p , treePartitions ( ) ) ;
2010-02-16 20:07:33 +00:00
}
2009-04-21 17:36:43 +01:00
void PartitionManagerWidget : : on_m_PartTableWidget_itemSelectionChanged ( PartWidget * item )
{
2016-03-31 17:20:34 +01:00
if ( item = = nullptr ) {
treePartitions ( ) . setCurrentItem ( nullptr ) ;
2020-09-15 02:26:38 +01:00
Q_EMIT selectedPartitionChanged ( nullptr ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
const Partition * p = item - > partition ( ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( p ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( p ) {
QList < QTreeWidgetItem * > findResult = treePartitions ( ) . findItems ( p - > deviceNode ( ) , Qt : : MatchFixedString | Qt : : MatchRecursive , 0 ) ;
2009-04-21 17:36:43 +01:00
2017-09-11 18:46:48 +01:00
for ( const auto & treeWidgetItem : findResult ) {
const PartitionTreeWidgetItem * ptwItem = dynamic_cast < PartitionTreeWidgetItem * > ( treeWidgetItem ) ;
2010-06-03 16:01:53 +01:00
2015-07-13 15:17:41 +01:00
if ( ptwItem & & ptwItem - > partition ( ) = = p ) {
2017-09-11 18:46:48 +01:00
treePartitions ( ) . setCurrentItem ( treeWidgetItem ) ;
2015-07-13 15:17:41 +01:00
break ;
}
}
}
2009-04-21 17:36:43 +01:00
2020-09-15 02:26:38 +01:00
Q_EMIT selectedPartitionChanged ( p ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : on_m_PartTableWidget_customContextMenuRequested ( const QPoint & pos )
{
2020-09-15 02:26:38 +01:00
Q_EMIT contextMenuRequested ( partTableWidget ( ) . mapToGlobal ( pos ) ) ;
2009-04-21 17:36:43 +01:00
}
2010-02-23 16:30:05 +00:00
void PartitionManagerWidget : : on_m_PartTableWidget_itemDoubleClicked ( )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
if ( selectedPartition ( ) )
2020-09-15 02:26:38 +01:00
Q_EMIT partitionDoubleClicked ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
}
2010-02-23 16:30:05 +00:00
void PartitionManagerWidget : : on_m_TreePartitions_customContextMenuRequested ( const QPoint & pos )
2009-04-21 17:36:43 +01:00
{
2020-09-15 02:26:38 +01:00
Q_EMIT contextMenuRequested ( treePartitions ( ) . viewport ( ) - > mapToGlobal ( pos ) ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onPropertiesPartition ( )
{
2015-07-13 15:17:41 +01:00
if ( selectedPartition ( ) ) {
Partition & p = * selectedPartition ( ) ;
2010-03-02 23:56:21 +00:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
QPointer < PartPropsDialog > dlg = new PartPropsDialog ( this , * selectedDevice ( ) , p ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
if ( dlg - > newFileSystemType ( ) ! = p . fileSystem ( ) . type ( ) | | dlg - > forceRecreate ( ) )
operationStack ( ) . push ( new CreateFileSystemOperation ( * selectedDevice ( ) , p , dlg - > newFileSystemType ( ) ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( dlg - > newLabel ( ) ! = p . fileSystem ( ) . label ( ) )
operationStack ( ) . push ( new SetFileSystemLabelOperation ( p , dlg - > newLabel ( ) ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( dlg - > newFlags ( ) ! = p . activeFlags ( ) )
operationStack ( ) . push ( new SetPartFlagsOperation ( * selectedDevice ( ) , p , dlg - > newFlags ( ) ) ) ;
}
2009-08-03 21:08:38 +01:00
2015-07-13 15:17:41 +01:00
delete dlg ;
}
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onMountPartition ( )
{
2015-07-13 15:17:41 +01:00
Partition * p = selectedPartition ( ) ;
2010-05-17 16:49:46 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( p ) ;
2010-05-17 16:49:46 +01:00
2016-03-31 17:20:34 +01:00
if ( p = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " no partition selected " ;
return ;
}
2010-05-17 16:49:46 +01:00
2016-03-31 17:20:34 +01:00
Report report ( nullptr ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( p - > canMount ( ) ) {
if ( ! p - > mount ( report ) )
2016-07-18 02:21:14 +01:00
KMessageBox : : detailedSorry ( this , xi18nc ( " @info " , " The file system on partition <filename>%1</filename> could not be mounted. " , p - > deviceNode ( ) ) , QStringLiteral ( " <pre>%1</pre> " ) . arg ( report . toText ( ) ) , xi18nc ( " @title:window " , " Could Not Mount File System. " ) ) ;
2015-07-13 15:17:41 +01:00
} else if ( p - > canUnmount ( ) ) {
if ( ! p - > unmount ( report ) )
2016-07-18 02:21:14 +01:00
KMessageBox : : detailedSorry ( this , xi18nc ( " @info " , " The file system on partition <filename>%1</filename> could not be unmounted. " , p - > deviceNode ( ) ) , QStringLiteral ( " <pre>%1</pre> " ) . arg ( report . toText ( ) ) , xi18nc ( " @title:window " , " Could Not Unmount File System. " ) ) ;
2015-07-13 15:17:41 +01:00
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( p - > roles ( ) . has ( PartitionRole : : Logical ) ) {
Partition * parent = dynamic_cast < Partition * > ( p - > parent ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( parent ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( parent ! = nullptr )
2015-07-13 15:17:41 +01:00
parent - > checkChildrenMounted ( ) ;
else
qWarning ( ) < < " parent is null " ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
updatePartitions ( ) ;
2009-04-21 17:36:43 +01:00
}
2016-03-31 17:20:34 +01:00
void PartitionManagerWidget : : onDecryptPartition ( )
{
Partition * p = selectedPartition ( ) ;
Q_ASSERT ( p ) ;
if ( p = = nullptr ) {
qWarning ( ) < < " no partition selected " ;
return ;
}
2016-04-19 16:08:01 +01:00
if ( ! p - > roles ( ) . has ( PartitionRole : : Luks ) )
2016-03-31 17:20:34 +01:00
return ;
2016-04-20 14:15:01 +01:00
const FileSystem & fsRef = p - > fileSystem ( ) ;
FS : : luks * luksFs = const_cast < FS : : luks * > ( dynamic_cast < const FS : : luks * > ( & fsRef ) ) ;
if ( ! luksFs )
2016-04-19 16:08:01 +01:00
return ;
2016-04-20 14:15:01 +01:00
if ( luksFs - > canCryptOpen ( p - > partitionPath ( ) ) ) {
2016-04-29 12:36:32 +01:00
if ( ! luksFs - > cryptOpen ( this , p - > partitionPath ( ) ) )
2016-04-20 14:15:01 +01:00
KMessageBox : : detailedSorry ( this ,
xi18nc ( " @info " ,
" The encrypted file system on partition "
" <filename>%1</filename> could not be "
" unlocked. " ,
p - > deviceNode ( ) ) ,
QString ( ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " ,
2016-04-20 14:15:01 +01:00
" Could Not Unlock Encrypted File System. " ) ) ;
} else if ( luksFs - > canCryptClose ( p - > partitionPath ( ) ) ) {
if ( ! luksFs - > cryptClose ( p - > partitionPath ( ) ) )
KMessageBox : : detailedSorry ( this ,
xi18nc ( " @info " ,
" The encrypted file system on partition "
" <filename>%1</filename> could not be "
" locked. " ,
p - > deviceNode ( ) ) ,
QString ( ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " ,
2016-04-20 14:15:01 +01:00
" Could Not Lock Encrypted File System. " ) ) ;
2016-03-31 17:20:34 +01:00
}
2016-04-20 14:15:01 +01:00
2016-03-31 17:20:34 +01:00
updatePartitions ( ) ;
}
2010-01-15 18:08:01 +00:00
void PartitionManagerWidget : : onEditMountPoint ( )
{
2015-07-13 15:17:41 +01:00
Partition * p = selectedPartition ( ) ;
2010-01-15 18:08:01 +00:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( p ) ;
2010-01-15 18:08:01 +00:00
2016-03-31 17:20:34 +01:00
if ( p = = nullptr )
2015-07-13 15:17:41 +01:00
return ;
2010-01-15 18:08:01 +00:00
2015-07-13 15:17:41 +01:00
QPointer < EditMountPointDialog > dlg = new EditMountPointDialog ( this , * p ) ;
2010-01-15 18:08:01 +00:00
2015-07-13 15:17:41 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted )
updatePartitions ( ) ;
2010-01-15 18:08:01 +00:00
2015-07-13 15:17:41 +01:00
delete dlg ;
2010-01-15 18:08:01 +00:00
}
2009-04-21 17:36:43 +01:00
static bool checkTooManyPartitions ( QWidget * parent , const Device & d , const Partition & p )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( d . partitionTable ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( p . roles ( ) . has ( PartitionRole : : Unallocated ) & & d . partitionTable ( ) - > numPrimaries ( ) > = d . partitionTable ( ) - > maxPrimaries ( ) & & ! p . roles ( ) . has ( PartitionRole : : Logical ) ) {
KMessageBox : : sorry ( parent , xi18ncp ( " @info " ,
" <para>There is already one primary partition on this device. This is the maximum number its partition table type can handle.</para> "
" <para>You cannot create, paste or restore a primary partition on it before you delete an existing one.</para> " ,
" <para>There are already %1 primary partitions on this device. This is the maximum number its partition table type can handle.</para> "
" <para>You cannot create, paste or restore a primary partition on it before you delete an existing one.</para> " ,
2016-07-18 02:21:14 +01:00
d . partitionTable ( ) - > numPrimaries ( ) ) , xi18nc ( " @title:window " , " Too Many Primary Partitions. " ) ) ;
2015-07-13 15:17:41 +01:00
return true ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
return false ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onNewPartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) - > partitionTable ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) - > partitionTable ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " partition table on selected device is null " ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( checkTooManyPartitions ( this , * selectedDevice ( ) , * selectedPartition ( ) ) )
return ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Partition * newPartition = NewOperation : : createNew ( * selectedPartition ( ) , static_cast < FileSystem : : Type > ( Config : : defaultFileSystem ( ) ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
QPointer < NewDialog > dlg = new NewDialog ( this , * selectedDevice ( ) , * newPartition , selectedDevice ( ) - > partitionTable ( ) - > childRoles ( * selectedPartition ( ) ) ) ;
2021-12-09 13:10:21 +00:00
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
if ( dlg - > useUnsecuredPartition ( ) ) {
2021-12-12 20:13:52 +00:00
newPartition - > fileSystem ( ) . setPosixPermissions ( QStringLiteral ( " 777 " ) ) ;
2021-12-09 13:10:21 +00:00
}
2021-12-09 15:56:52 +00:00
operationStack ( ) . push ( new NewOperation ( * selectedDevice ( ) , newPartition ) ) ;
2021-12-09 13:10:21 +00:00
} else {
2015-07-13 15:17:41 +01:00
delete newPartition ;
2021-12-09 13:10:21 +00:00
}
2009-08-03 21:08:38 +01:00
2015-07-13 15:17:41 +01:00
delete dlg ;
2009-04-21 17:36:43 +01:00
}
2010-01-18 12:31:00 +00:00
void PartitionManagerWidget : : onDeletePartition ( bool shred )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
if ( selectedPartition ( ) - > roles ( ) . has ( PartitionRole : : Logical ) ) {
Q_ASSERT ( selectedPartition ( ) - > parent ( ) ) ;
2016-03-31 17:20:34 +01:00
if ( selectedPartition ( ) - > parent ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " parent of selected partition is null. " ;
return ;
}
if ( selectedPartition ( ) - > number ( ) > 0 & & selectedPartition ( ) - > parent ( ) - > highestMountedChild ( ) > selectedPartition ( ) - > number ( ) ) {
KMessageBox : : sorry ( this ,
xi18nc ( " @info " ,
" <para>The partition <filename>%1</filename> cannot currently be deleted because one or more partitions with higher logical numbers are still mounted.</para> "
" <para>Please unmount all partitions with higher logical numbers than %2 first.</para> " ,
selectedPartition ( ) - > deviceNode ( ) , selectedPartition ( ) - > number ( ) ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Cannot Delete Partition. " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
}
if ( clipboardPartition ( ) = = selectedPartition ( ) ) {
if ( KMessageBox : : warningContinueCancel ( this ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @info " ,
2015-07-13 15:17:41 +01:00
" Do you really want to delete the partition that is currently in the clipboard? "
" It will no longer be available for pasting after it has been deleted. " ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Really Delete Partition in the Clipboard? " ) ,
KGuiItem ( xi18nc ( " @action:button " , " Delete It " ) , QStringLiteral ( " arrow-right " ) ) ,
2015-07-13 15:17:41 +01:00
KStandardGuiItem : : cancel ( ) , QStringLiteral ( " reallyDeleteClipboardPartition " ) ) = = KMessageBox : : Cancel )
return ;
2016-03-31 17:20:34 +01:00
setClipboardPartition ( nullptr ) ;
2015-07-13 15:17:41 +01:00
}
2009-04-21 17:36:43 +01:00
2015-07-10 14:57:02 +01:00
if ( shred & & Config : : shredSource ( ) = = Config : : EnumShredSource : : random )
2018-04-09 15:14:48 +01:00
operationStack ( ) . push ( new DeleteOperation ( * selectedDevice ( ) , selectedPartition ( ) , DeleteOperation : : ShredAction : : RandomShred ) ) ;
2015-07-10 14:57:02 +01:00
else if ( shred & & Config : : shredSource ( ) = = Config : : EnumShredSource : : zeros )
2018-04-09 15:14:48 +01:00
operationStack ( ) . push ( new DeleteOperation ( * selectedDevice ( ) , selectedPartition ( ) , DeleteOperation : : ShredAction : : ZeroShred ) ) ;
2015-07-10 14:57:02 +01:00
else
2018-04-09 15:14:48 +01:00
operationStack ( ) . push ( new DeleteOperation ( * selectedDevice ( ) , selectedPartition ( ) , DeleteOperation : : ShredAction : : NoShred ) ) ;
2009-04-21 17:36:43 +01:00
}
2010-01-18 12:31:00 +00:00
void PartitionManagerWidget : : onShredPartition ( )
{
2015-07-13 15:17:41 +01:00
onDeletePartition ( true ) ;
2010-01-18 12:31:00 +00:00
}
2009-04-21 17:36:43 +01:00
void PartitionManagerWidget : : onResizePartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) - > partitionTable ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) - > partitionTable ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " partition table on selected device is null " ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
// we cannot work with selectedPartition() here because opening and closing the dialog will
// clear the selection, so we'll lose the partition after the dialog's been exec'd
Partition & p = * selectedPartition ( ) ;
2009-04-21 17:36:43 +01:00
2016-06-29 09:38:31 +01:00
qint64 freeBefore = selectedDevice ( ) - > partitionTable ( ) - > freeSectorsBefore ( p ) ;
qint64 freeAfter = selectedDevice ( ) - > partitionTable ( ) - > freeSectorsAfter ( p ) ;
2018-04-09 02:58:03 +01:00
if ( selectedDevice ( ) - > type ( ) = = Device : : Type : : LVM_Device ) {
2016-06-29 09:38:31 +01:00
freeBefore = 0 ;
freeAfter = selectedDevice ( ) - > partitionTable ( ) - > freeSectors ( ) ;
}
2009-04-21 17:36:43 +01:00
2016-07-18 01:07:53 +01:00
QPointer < ResizeDialog > dlg = new ResizeDialog ( this , * selectedDevice ( ) , p , p . firstSector ( ) - freeBefore , p . lastSector ( ) + freeAfter ) ;
2010-04-15 11:38:48 +01:00
2015-07-13 15:17:41 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
if ( dlg - > resizedFirstSector ( ) = = p . firstSector ( ) & & dlg - > resizedLastSector ( ) = = p . lastSector ( ) )
2018-04-09 15:14:48 +01:00
Log ( Log : : Level : : information ) < < xi18nc ( " @info:status " , " Partition <filename>%1</filename> has the same position and size after resize/move. Ignoring operation. " , p . deviceNode ( ) ) ;
2015-07-13 15:17:41 +01:00
else
operationStack ( ) . push ( new ResizeOperation ( * selectedDevice ( ) , p , dlg - > resizedFirstSector ( ) , dlg - > resizedLastSector ( ) ) ) ;
}
2010-04-15 16:30:08 +01:00
2015-07-13 15:17:41 +01:00
if ( p . roles ( ) . has ( PartitionRole : : Extended ) ) {
// Even if the user dismissed the resize dialog we must update the partitions
// if it's an extended partition:
// The dialog has to remove and create unallocated children if the user resizes
// an extended partition. We can't know if that has happened, so to avoid
// any problems (like, the user resized an extended and then canceled, which would
// lead to the unallocated children having the wrong size) do this now.
updatePartitions ( ) ;
}
2009-08-03 21:08:38 +01:00
2015-07-13 15:17:41 +01:00
delete dlg ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onCopyPartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
setClipboardPartition ( selectedPartition ( ) ) ;
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:status " , " Partition <filename>%1</filename> has been copied to the clipboard. " , selectedPartition ( ) - > deviceNode ( ) ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onPastePartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( clipboardPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " no partition in the clipboard. " ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( checkTooManyPartitions ( this , * selectedDevice ( ) , * selectedPartition ( ) ) )
return ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Device * dSource = operationStack ( ) . findDeviceForPartition ( clipboardPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Q_ASSERT ( dSource ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( dSource = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " source partition is null. " ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
Partition * copiedPartition = CopyOperation : : createCopy ( * selectedPartition ( ) , * clipboardPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( showInsertDialog ( * copiedPartition , clipboardPartition ( ) - > length ( ) ) )
operationStack ( ) . push ( new CopyOperation ( * selectedDevice ( ) , copiedPartition , * dSource , clipboardPartition ( ) ) ) ;
else
delete copiedPartition ;
2009-04-21 17:36:43 +01:00
}
2010-03-19 14:13:04 +00:00
bool PartitionManagerWidget : : showInsertDialog ( Partition & insertedPartition , qint64 sourceLength )
2009-04-21 17:36:43 +01:00
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return false ;
}
const bool overwrite = ! selectedPartition ( ) - > roles ( ) . has ( PartitionRole : : Unallocated ) ;
// Make sure the inserted partition has the right parent and logical or primary set. Only then
// can PartitionTable::alignPartition() work correctly.
selectedPartition ( ) - > parent ( ) - > reparent ( insertedPartition ) ;
if ( ! overwrite ) {
QPointer < InsertDialog > dlg = new InsertDialog ( this , * selectedDevice ( ) , insertedPartition , * selectedPartition ( ) ) ;
int result = dlg - > exec ( ) ;
delete dlg ;
if ( result ! = QDialog : : Accepted )
return false ;
} else if ( KMessageBox : : warningContinueCancel ( this ,
xi18nc ( " @info " , " <para><warning>You are about to lose all data on partition "
" <filename>%1</filename>.</warning></para> "
" <para>Overwriting one partition with another (or with an image file) will "
" destroy all data on this target partition.</para> "
" <para>If you continue now and apply the resulting operation in the main "
" window, all data currently stored on <filename>%1</filename> will "
" unrecoverably be overwritten.</para> " ,
selectedPartition ( ) - > deviceNode ( ) ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Really Overwrite Existing Partition? " ) ,
KGuiItem ( xi18nc ( " @action:button " , " Overwrite Partition " ) , QStringLiteral ( " arrow-right " ) ) ,
2015-07-13 15:17:41 +01:00
KStandardGuiItem : : cancel ( ) ,
QStringLiteral ( " reallyOverwriteExistingPartition " ) ) = = KMessageBox : : Cancel )
return false ;
if ( insertedPartition . length ( ) < sourceLength ) {
if ( overwrite )
KMessageBox : : error ( this , xi18nc ( " @info " ,
" <para>The selected partition is not large enough to hold the source partition or the backup file.</para> "
2016-07-18 02:21:14 +01:00
" <para>Pick another target or resize this partition so it is as large as the source.</para> " ) , xi18nc ( " @title:window " , " Target Not Large Enough " ) ) ;
2015-07-13 15:17:41 +01:00
else
KMessageBox : : sorry ( this , xi18nc ( " @info " ,
" <para>It is not possible to create the target partition large enough to hold the source.</para> "
" <para>This may happen if not all partitions on a device are correctly aligned "
" or when copying a primary partition into an extended partition.</para> " ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Cannot Create Target Partition. " ) ) ;
2015-07-13 15:17:41 +01:00
return false ;
}
return true ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onCheckPartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
operationStack ( ) . push ( new CheckOperation ( * selectedDevice ( ) , * selectedPartition ( ) ) ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onBackupPartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2009-04-21 17:36:43 +01:00
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
2016-05-12 21:45:07 +01:00
QString fileName = QFileDialog : : getSaveFileName ( this ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
if ( fileName . isEmpty ( ) )
return ;
2009-04-21 17:36:43 +01:00
2018-02-05 13:14:36 +00:00
operationStack ( ) . push ( new BackupOperation ( * selectedDevice ( ) , * selectedPartition ( ) , fileName ) ) ;
2009-04-21 17:36:43 +01:00
}
void PartitionManagerWidget : : onRestorePartition ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( selectedDevice ( ) ) ;
Q_ASSERT ( selectedPartition ( ) ) ;
2016-03-31 17:20:34 +01:00
if ( selectedDevice ( ) = = nullptr | | selectedPartition ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device: " < < selectedDevice ( ) < < " , selected partition: " < < selectedPartition ( ) ;
return ;
}
if ( checkTooManyPartitions ( this , * selectedDevice ( ) , * selectedPartition ( ) ) )
return ;
2016-05-12 21:45:07 +01:00
QString fileName = QFileDialog : : getOpenFileName ( this ) ;
2015-07-13 15:17:41 +01:00
// QString fileName = "/tmp/backuptest.img";
if ( ! fileName . isEmpty ( ) & & QFile : : exists ( fileName ) ) {
Partition * restorePartition = RestoreOperation : : createRestorePartition ( * selectedDevice ( ) , * selectedPartition ( ) - > parent ( ) , selectedPartition ( ) - > firstSector ( ) , fileName ) ;
if ( restorePartition - > length ( ) > selectedPartition ( ) - > length ( ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " The file system in the image file <filename>%1</filename> is too large to be restored to the selected partition. " , fileName ) , xi18nc ( " @title:window " , " Not Enough Space to Restore File System. " ) ) ;
2015-07-13 15:17:41 +01:00
delete restorePartition ;
return ;
}
if ( showInsertDialog ( * restorePartition , restorePartition - > length ( ) ) )
operationStack ( ) . push ( new RestoreOperation ( * selectedDevice ( ) , restorePartition , fileName ) ) ;
else
delete restorePartition ;
}
2009-04-21 17:36:43 +01:00
}