added set_used() and operator!= it's now possible to copy from partition
* include/Partition.h, src/Partition.cc: added set_used() and operator!= * src/Dialog_Partition_Copy.cc, src/GParted_Core.cc, src/OperationCopy.cc, src/Win_GParted.cc: it's now possible to copy from partition to partition. (before this it was only possible to copy to unallocated space)
This commit is contained in:
parent
91c4ca2b45
commit
70bfe578d4
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2006-03-29 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/Partition.h,
|
||||
src/Partition.cc: added set_used() and operator!=
|
||||
* src/Dialog_Partition_Copy.cc,
|
||||
src/GParted_Core.cc,
|
||||
src/OperationCopy.cc,
|
||||
src/Win_GParted.cc: it's now possible to copy from partition to
|
||||
partition. (before this it was only possible to copy to unallocated
|
||||
space)
|
||||
|
||||
2006-03-28 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/GParted_Core.h,
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
bool busy ) ;
|
||||
|
||||
void Set_Unused( Sector sectors_unused ) ;
|
||||
void set_used( Sector sectors_used ) ;
|
||||
|
||||
void Set_Unallocated( const Glib::ustring & device_path,
|
||||
Sector sector_start,
|
||||
|
@ -85,6 +86,7 @@ public:
|
|||
std::vector<Glib::ustring> get_mountpoints() const ;
|
||||
|
||||
bool operator==( const Partition & partition ) const ;
|
||||
bool operator!=( const Partition & partition ) const ;
|
||||
|
||||
//some public members
|
||||
Glib::ustring device_path ;
|
||||
|
|
|
@ -98,7 +98,7 @@ Partition Dialog_Partition_Copy::Get_New_Partition()
|
|||
selected_partition = Dialog_Base_Partition::Get_New_Partition() ;
|
||||
|
||||
//set proper name and status for partition
|
||||
selected_partition .status = GParted::STAT_COPY ;
|
||||
selected_partition .status = GParted::STAT_NEW ;
|
||||
|
||||
return selected_partition ;
|
||||
}
|
||||
|
|
|
@ -585,6 +585,7 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
|
|||
case FORMAT:
|
||||
return format( operation ->partition_new, operation ->operation_details .sub_details ) ;
|
||||
case COPY:
|
||||
operation ->partition_new .add_path( operation ->partition_original .get_path(), true ) ;
|
||||
return copy( static_cast<OperationCopy*>( operation ) ->partition_copied .get_path(),
|
||||
operation ->partition_new,
|
||||
static_cast<OperationCopy*>( operation ) ->partition_copied .get_length(),
|
||||
|
@ -719,17 +720,24 @@ bool GParted_Core::copy( const Glib::ustring & src_part_path,
|
|||
Sector min_size,
|
||||
std::vector<OperationDetails> & operation_details )
|
||||
{
|
||||
set_proper_filesystem( partition_dest .filesystem ) ;
|
||||
Partition src_partition( src_part_path ) ;
|
||||
//FIXME: some filesystems (e.g. fat*) can be copied using libparted..
|
||||
return ( p_filesystem &&
|
||||
p_filesystem ->Check_Repair( src_partition, operation_details ) &&
|
||||
create_empty_partition( partition_dest, operation_details, min_size ) > 0 &&
|
||||
set_partition_type( partition_dest, operation_details ) &&
|
||||
p_filesystem ->Copy( src_part_path, partition_dest .get_path(), operation_details ) &&
|
||||
p_filesystem ->Check_Repair( partition_dest, operation_details ) &&
|
||||
p_filesystem ->Resize( partition_dest, operation_details, true ) &&
|
||||
p_filesystem ->Check_Repair( partition_dest, operation_details ) ) ;
|
||||
|
||||
set_proper_filesystem( partition_dest .filesystem ) ;
|
||||
if ( p_filesystem && p_filesystem ->Check_Repair( Partition( src_part_path ), operation_details ) )
|
||||
{
|
||||
bool succes = true ;
|
||||
if ( partition_dest .status == GParted::STAT_NEW )
|
||||
succes = create_empty_partition( partition_dest, operation_details, min_size ) ;
|
||||
|
||||
return ( succes &&
|
||||
set_partition_type( partition_dest, operation_details ) &&
|
||||
p_filesystem ->Copy( src_part_path, partition_dest .get_path(), operation_details ) &&
|
||||
p_filesystem ->Check_Repair( partition_dest, operation_details ) &&
|
||||
p_filesystem ->Resize( partition_dest, operation_details, true ) &&
|
||||
p_filesystem ->Check_Repair( partition_dest, operation_details ) ) ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool GParted_Core::Set_Disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel )
|
||||
|
@ -827,7 +835,7 @@ void GParted_Core::LP_Set_Used_Sectors( Partition & partition )
|
|||
int GParted_Core::create_empty_partition( Partition & new_partition,
|
||||
std::vector<OperationDetails> & operation_details,
|
||||
Sector min_size )
|
||||
{
|
||||
{//FIXME:make this one return a boolean...
|
||||
operation_details .push_back( OperationDetails( _("create empty partition") ) ) ;
|
||||
|
||||
new_partition .partition_number = 0 ;
|
||||
|
@ -1162,9 +1170,11 @@ bool GParted_Core::wait_for_node( const Glib::ustring & node )
|
|||
//we'll loop for 10 seconds or till 'node' appeares...
|
||||
for( short t = 0 ; t < 50 ; t++ )
|
||||
{
|
||||
//FIXME: find a better way to check if a file exists
|
||||
//the current way is suboptimal (at best)
|
||||
if ( Glib::file_test( node, Glib::FILE_TEST_EXISTS ) )
|
||||
{
|
||||
sleep( 1 ) ; //apperantly the node isn't available immediatly after file_test returns succesfully :/
|
||||
sleep( 2 ) ; //apperantly the node isn't available immediatly after file_test returns succesfully :/
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
|
@ -1260,7 +1270,8 @@ PedExceptionOption GParted_Core::ped_exception_handler( PedException * e )
|
|||
|
||||
GParted_Core::~GParted_Core()
|
||||
{
|
||||
delete p_filesystem ;
|
||||
if ( p_filesystem )
|
||||
delete p_filesystem ;
|
||||
}
|
||||
|
||||
} //GParted
|
||||
|
|
|
@ -35,7 +35,7 @@ OperationCopy::OperationCopy( const Device & device,
|
|||
create_description() ;
|
||||
|
||||
this ->partition_new .add_path(
|
||||
String::ucompose( _("copy of %1"), this ->partition_new .get_path() ), true ) ;
|
||||
String::ucompose( _("copy of %1"), this ->partition_copied .get_path() ), true ) ;
|
||||
}
|
||||
|
||||
void OperationCopy::apply_to_visual( std::vector<Partition> & partitions )
|
||||
|
@ -74,11 +74,22 @@ void OperationCopy::apply_to_visual( std::vector<Partition> & partitions )
|
|||
|
||||
void OperationCopy::create_description()
|
||||
{
|
||||
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 250 MiB) */
|
||||
description = String::ucompose( _("Copy %1 to %2 (start at %3)"),
|
||||
partition_new .get_path(),
|
||||
device .get_path(),
|
||||
Utils::format_size( partition_new .sector_start ) ) ;
|
||||
if ( partition_original .type == GParted::TYPE_UNALLOCATED )
|
||||
{
|
||||
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 250 MiB) */
|
||||
description = String::ucompose( _("Copy %1 to %2 (start at %3)"),
|
||||
partition_copied .get_path(),
|
||||
device .get_path(),
|
||||
Utils::format_size( partition_new .sector_start ) ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd1 */
|
||||
description = String::ucompose( _("Copy %1 to %2"),
|
||||
partition_copied .get_path(),
|
||||
partition_original .get_path() ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //GParted
|
||||
|
|
|
@ -80,6 +80,15 @@ void Partition::Set_Unused( Sector sectors_unused )
|
|||
this ->sectors_used = ( sectors_unused == -1 ) ? -1 : get_length() - sectors_unused ;
|
||||
}
|
||||
}
|
||||
|
||||
void Partition::set_used( Sector sectors_used )
|
||||
{
|
||||
if ( sectors_used < get_length() )
|
||||
{
|
||||
this ->sectors_used = sectors_used ;
|
||||
this ->sectors_unused = ( sectors_used == -1 ) ? -1 : get_length() - sectors_used ;
|
||||
}
|
||||
}
|
||||
|
||||
void Partition::Set_Unallocated( const Glib::ustring & device_path,
|
||||
Sector sector_start,
|
||||
|
@ -162,6 +171,11 @@ bool Partition::operator==( const Partition & partition ) const
|
|||
this ->type == partition .type ;
|
||||
}
|
||||
|
||||
bool Partition::operator!=( const Partition & partition ) const
|
||||
{
|
||||
return ! ( *this == partition ) ;
|
||||
}
|
||||
|
||||
void Partition::sort_paths_and_remove_duplicates()
|
||||
{
|
||||
//remove duplicates
|
||||
|
|
|
@ -834,6 +834,13 @@ void Win_GParted::set_valid_operations()
|
|||
menu_partition .items()[ 10 ] .hide() ;
|
||||
menu_partition .items()[ 11 ] .show() ;
|
||||
}
|
||||
|
||||
//see if there is an copied partition and if it passes all tests
|
||||
if ( ! copied_partition .get_path() .empty() &&
|
||||
copied_partition .get_length() <= selected_partition .get_length() &&
|
||||
selected_partition .status == GParted::STAT_REAL &&
|
||||
copied_partition != selected_partition )
|
||||
allow_paste( true ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1235,22 +1242,37 @@ void Win_GParted::activate_copy()
|
|||
|
||||
void Win_GParted::activate_paste()
|
||||
{
|
||||
if ( ! max_amount_prim_reached() )
|
||||
if ( selected_partition .type == GParted::TYPE_UNALLOCATED )
|
||||
{
|
||||
Dialog_Partition_Copy dialog( gparted_core .get_fs( copied_partition .filesystem ),
|
||||
devices[ current_device ] .cylsize ) ;
|
||||
//we don't need the errors/mountpoints of the source partition.
|
||||
copied_partition .error .clear() ;
|
||||
copied_partition .clear_mountpoints() ;
|
||||
dialog .Set_Data( selected_partition, copied_partition ) ;
|
||||
dialog .set_transient_for( *this );
|
||||
|
||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||
|
||||
if ( ! max_amount_prim_reached() )
|
||||
{
|
||||
dialog .hide() ;
|
||||
Add_Operation( GParted::COPY, dialog .Get_New_Partition() );
|
||||
Dialog_Partition_Copy dialog( gparted_core .get_fs( copied_partition .filesystem ),
|
||||
devices[ current_device ] .cylsize ) ;
|
||||
//we don't need the errors/mountpoints of the source partition.
|
||||
copied_partition .error .clear() ;
|
||||
copied_partition .clear_mountpoints() ;
|
||||
dialog .Set_Data( selected_partition, copied_partition ) ;
|
||||
dialog .set_transient_for( *this );
|
||||
|
||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||
{
|
||||
dialog .hide() ;
|
||||
Add_Operation( GParted::COPY, dialog .Get_New_Partition() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Partition partition_new = selected_partition ;
|
||||
partition_new .filesystem = copied_partition .filesystem ;
|
||||
partition_new .color = copied_partition .color ;
|
||||
partition_new .set_used( copied_partition .sectors_used ) ;
|
||||
partition_new .error .clear() ;
|
||||
partition_new .status = GParted::STAT_COPY ;
|
||||
|
||||
Add_Operation( GParted::COPY, partition_new ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void Win_GParted::activate_new()
|
||||
|
|
Loading…
Reference in New Issue