2008-09-24 20:32:01 +01:00
/***************************************************************************
2010-02-23 18:04:45 +00:00
* Copyright ( C ) 2008 , 2010 by Volker Lanz < vl @ fidra . de > *
2008-09-24 20:32:01 +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 2 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 , write to the *
* Free Software Foundation , Inc . , *
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ops/createpartitiontableoperation.h"
# include "core/device.h"
# include "core/partitiontable.h"
# include "core/partition.h"
# include "jobs/createpartitiontablejob.h"
# include <QString>
# include <kdebug.h>
# include <klocale.h>
/** Creates a new CreatePartitionTableOperation.
@ param d the Device to create the new PartitionTable on
2010-02-01 16:32:45 +00:00
@ param t the type for the new PartitionTable
2008-09-24 20:32:01 +01:00
*/
2010-02-24 11:32:12 +00:00
CreatePartitionTableOperation : : CreatePartitionTableOperation ( Device & d , PartitionTable : : TableType t ) :
2008-09-24 20:32:01 +01:00
Operation ( ) ,
m_TargetDevice ( d ) ,
2009-01-09 07:10:59 +00:00
m_OldPartitionTable ( targetDevice ( ) . partitionTable ( ) ) ,
2010-02-01 16:32:45 +00:00
m_PartitionTable ( new PartitionTable ( t , PartitionTable : : defaultFirstUsable ( d , t ) , PartitionTable : : defaultLastUsable ( d , t ) ) ) ,
2008-09-24 20:32:01 +01:00
m_CreatePartitionTableJob ( new CreatePartitionTableJob ( targetDevice ( ) ) )
{
addJob ( createPartitionTableJob ( ) ) ;
}
2010-03-03 00:15:26 +00:00
/** Creates a new CreatePartitionTableOperation.
@ param d the Device to create the new PartitionTable on
@ param ptable pointer to the new partition table object . the operation takes ownership .
*/
CreatePartitionTableOperation : : CreatePartitionTableOperation ( Device & d , PartitionTable * ptable ) :
Operation ( ) ,
m_TargetDevice ( d ) ,
m_OldPartitionTable ( targetDevice ( ) . partitionTable ( ) ) ,
m_PartitionTable ( ptable ) ,
m_CreatePartitionTableJob ( new CreatePartitionTableJob ( targetDevice ( ) ) )
{
addJob ( createPartitionTableJob ( ) ) ;
}
2008-09-24 20:32:01 +01:00
CreatePartitionTableOperation : : ~ CreatePartitionTableOperation ( )
{
if ( status ( ) = = StatusPending )
delete m_PartitionTable ;
}
2010-05-23 21:13:46 +01:00
bool CreatePartitionTableOperation : : targets ( const Device & d ) const
{
return d = = targetDevice ( ) ;
}
2008-09-24 20:32:01 +01:00
void CreatePartitionTableOperation : : preview ( )
{
2009-01-09 07:10:59 +00:00
targetDevice ( ) . setPartitionTable ( partitionTable ( ) ) ;
targetDevice ( ) . partitionTable ( ) - > updateUnallocated ( targetDevice ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void CreatePartitionTableOperation : : undo ( )
{
2009-01-09 07:10:59 +00:00
targetDevice ( ) . setPartitionTable ( oldPartitionTable ( ) ) ;
if ( targetDevice ( ) . partitionTable ( ) )
targetDevice ( ) . partitionTable ( ) - > updateUnallocated ( targetDevice ( ) ) ;
2008-09-24 20:32:01 +01:00
}
bool CreatePartitionTableOperation : : execute ( Report & parent )
{
2009-01-09 07:10:59 +00:00
targetDevice ( ) . setPartitionTable ( partitionTable ( ) ) ;
2008-09-24 20:32:01 +01:00
return Operation : : execute ( parent ) ;
}
2008-10-06 08:31:11 +01:00
/** Can a new partition table be created on a device?
@ param device pointer to the device , can be NULL
@ return true if a new partition table can be created on @ p device
*/
bool CreatePartitionTableOperation : : canCreate ( const Device * device )
{
2009-01-09 07:10:59 +00:00
return device ! = NULL & & ( device - > partitionTable ( ) = = NULL | | ! device - > partitionTable ( ) - > isChildMounted ( ) ) ;
2008-10-06 08:31:11 +01:00
}
2008-09-24 20:32:01 +01:00
QString CreatePartitionTableOperation : : description ( ) const
{
2010-03-01 22:48:23 +00:00
return QString ( i18nc ( " @info/plain " , " Create a new partition table (type: %1) on < filename > % 2 < / filename > " , partitionTable()->typeName(), targetDevice().deviceNode())) ;
2008-09-24 20:32:01 +01:00
}