2015-06-04 01:29:22 +01:00
/*************************************************************************
* Copyright ( C ) 2008 , 2010 by Volker Lanz < vl @ fidra . de > *
2016-03-02 19:00:31 +00:00
* Copyright ( C ) 2016 by Andrius Š tikonas < andrius @ stikonas . eu > *
2015-06-04 01:29:22 +01:00
* *
* This program 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 . *
* *
* This program 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 this program . If not , see < http : //www.gnu.org/licenses/>.*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ops/createpartitiontableoperation.h"
# include "core/device.h"
# include "core/partitiontable.h"
# include "core/partition.h"
# include "jobs/createpartitiontablejob.h"
# include <QString>
# include <KLocalizedString>
/** Creates a new CreatePartitionTableOperation.
2015-07-13 15:16:36 +01:00
@ param d the Device to create the new PartitionTable on
@ param t the type for the new PartitionTable
2015-06-04 01:29:22 +01:00
*/
CreatePartitionTableOperation : : CreatePartitionTableOperation ( Device & d , PartitionTable : : TableType t ) :
2015-07-13 15:16:36 +01:00
Operation ( ) ,
m_TargetDevice ( d ) ,
m_OldPartitionTable ( targetDevice ( ) . partitionTable ( ) ) ,
m_PartitionTable ( new PartitionTable ( t , PartitionTable : : defaultFirstUsable ( d , t ) , PartitionTable : : defaultLastUsable ( d , t ) ) ) ,
m_CreatePartitionTableJob ( new CreatePartitionTableJob ( targetDevice ( ) ) )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
addJob ( createPartitionTableJob ( ) ) ;
2015-06-04 01:29:22 +01:00
}
/** Creates a new CreatePartitionTableOperation.
2015-07-13 15:16:36 +01:00
@ param d the Device to create the new PartitionTable on
@ param ptable pointer to the new partition table object . the operation takes ownership .
2015-06-04 01:29:22 +01:00
*/
CreatePartitionTableOperation : : CreatePartitionTableOperation ( Device & d , PartitionTable * ptable ) :
2015-07-13 15:16:36 +01:00
Operation ( ) ,
m_TargetDevice ( d ) ,
m_OldPartitionTable ( targetDevice ( ) . partitionTable ( ) ) ,
m_PartitionTable ( ptable ) ,
m_CreatePartitionTableJob ( new CreatePartitionTableJob ( targetDevice ( ) ) )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
addJob ( createPartitionTableJob ( ) ) ;
2015-06-04 01:29:22 +01:00
}
CreatePartitionTableOperation : : ~ CreatePartitionTableOperation ( )
{
2015-07-13 15:16:36 +01:00
if ( status ( ) = = StatusPending )
delete m_PartitionTable ;
2015-06-04 01:29:22 +01:00
}
bool CreatePartitionTableOperation : : targets ( const Device & d ) const
{
2015-07-13 15:16:36 +01:00
return d = = targetDevice ( ) ;
2015-06-04 01:29:22 +01:00
}
void CreatePartitionTableOperation : : preview ( )
{
2015-07-13 15:16:36 +01:00
targetDevice ( ) . setPartitionTable ( partitionTable ( ) ) ;
targetDevice ( ) . partitionTable ( ) - > updateUnallocated ( targetDevice ( ) ) ;
2015-06-04 01:29:22 +01:00
}
void CreatePartitionTableOperation : : undo ( )
{
2015-07-13 15:16:36 +01:00
targetDevice ( ) . setPartitionTable ( oldPartitionTable ( ) ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
if ( targetDevice ( ) . partitionTable ( ) )
targetDevice ( ) . partitionTable ( ) - > updateUnallocated ( targetDevice ( ) ) ;
2015-06-04 01:29:22 +01:00
}
bool CreatePartitionTableOperation : : execute ( Report & parent )
{
2015-07-13 15:16:36 +01:00
targetDevice ( ) . setPartitionTable ( partitionTable ( ) ) ;
return Operation : : execute ( parent ) ;
2015-06-04 01:29:22 +01:00
}
/** Can a new partition table be created on a device?
2015-07-22 14:48:03 +01:00
@ param device pointer to the device , can be nullptr
2015-07-13 15:16:36 +01:00
@ return true if a new partition table can be created on @ p device
2015-06-04 01:29:22 +01:00
*/
bool CreatePartitionTableOperation : : canCreate ( const Device * device )
{
2015-07-22 14:48:03 +01:00
return device ! = nullptr & & ( device - > partitionTable ( ) = = nullptr | | ! device - > partitionTable ( ) - > isChildMounted ( ) ) ;
2015-06-04 01:29:22 +01:00
}
QString CreatePartitionTableOperation : : description ( ) const
{
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Create a new partition table (type: %1) on < filename > % 2 < / filename > " , partitionTable()->typeName(), targetDevice().deviceNode()) ;
2015-06-04 01:29:22 +01:00
}