~ubuntu-branches/ubuntu/trusty/gparted/trusty

« back to all changes in this revision

Viewing changes to src/Win_GParted.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2010-10-30 11:08:59 UTC
  • mfrom: (6.3.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20101030110859-2pgeh1y8p7z8tsb6
Tags: 0.7.0-1
New upstream release
Fix gparted crash at start with glibmm-ERROR
Closes: 601818
LP: #609477, #617885
Fix crash moving more than one logical partition right
Closes: 601817
Skip move/copy action because linux swap contains no data
LP: #401228
Fix several memory leaks and valgrind errors
Remove unnecessary null pointer checks
Fix partitions moved or copied are 1 MiB larger
Insert additional translator comments
Add initial support for btrfs

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "../include/OperationFormat.h"
34
34
#include "../include/OperationResizeMove.h"
35
35
#include "../include/OperationLabelPartition.h"
 
36
#include "../config.h"
36
37
 
37
38
#include <gtkmm/aboutdialog.h>
38
39
#include <gtkmm/messagedialog.h>
392
393
 
393
394
        for ( unsigned int t =0; t < gparted_core .get_filesystems() .size() ; t++ )
394
395
        {
395
 
                //Skip btrfs, luks, lvm2, and unknown because these are not file systems
396
 
                if ( gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_BTRFS ||
 
396
                //Skip luks, lvm2, and unknown because these are not file systems
 
397
                if (
397
398
                     gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_LUKS ||
398
399
                     gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_LVM2 ||
399
400
                     gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_UNKNOWN
1264
1265
        tmp_msg += "\n" ;
1265
1266
        tmp_msg += _( "Documentation is available at the project web site." ) ;
1266
1267
        tmp_msg += "\n" ;
1267
 
        tmp_msg += "http://gparted.sourceforge.net" ;
 
1268
        tmp_msg += "http://gparted.org" ;
1268
1269
        dialog .set_secondary_text( tmp_msg ) ;
1269
1270
        dialog .run() ;
1270
1271
#else
1293
1294
        strings .clear() ;
1294
1295
 
1295
1296
        //artists
1296
 
        strings .push_back( "http://gparted.sourceforge.net/artwork.php" ) ;
 
1297
        strings .push_back( "http://gparted.org/artwork.php" ) ;
1297
1298
        dialog .set_artists( strings ) ;
1298
1299
        strings .clear() ;
1299
1300
 
1305
1306
 
1306
1307
 
1307
1308
        //the url is not clickable because this would introduce an new dep (gnome-vfsmm) 
1308
 
        dialog .set_website( "http://gparted.sourceforge.net" ) ;
 
1309
        dialog .set_website( "http://gparted.org" ) ;
1309
1310
 
1310
1311
        dialog .run() ;
1311
1312
}
1341
1342
        {
1342
1343
                Gtk::MessageDialog dialog( 
1343
1344
                        *this,
1344
 
                        String::ucompose( _("It is not possible to create more than %1 primary partitions"),
1345
 
                                          devices[ current_device ] .max_prims ),
 
1345
                        String::ucompose( ngettext( "It is not possible to create more than %1 primary partition"
 
1346
                                                  , "It is not possible to create more than %1 primary partitions"
 
1347
                                                  , devices[ current_device ] .max_prims
 
1348
                                                  )
 
1349
                                        , devices[ current_device ] .max_prims
 
1350
                                        ),
1346
1351
                        false,
1347
1352
                        Gtk::MESSAGE_ERROR,
1348
1353
                        Gtk::BUTTONS_OK,
1424
1429
                        operation ->icon = render_icon( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU );
1425
1430
 
1426
1431
                        Add_Operation( operation ) ;
 
1432
 
 
1433
                        //Display notification if move operation has been queued
 
1434
                        if ( operation ->partition_original .sector_start != operation ->partition_new .sector_start )
 
1435
                        {
 
1436
                                //Warn that move operation might break boot process
 
1437
                                Gtk::MessageDialog dialog( *this
 
1438
                                                         , _( "Moving a partition might cause your operating system to fail to boot." )
 
1439
                                                         , false
 
1440
                                                         , Gtk::MESSAGE_WARNING
 
1441
                                                         , Gtk::BUTTONS_OK
 
1442
                                                         , true
 
1443
                                                         ) ;
 
1444
                                Glib::ustring tmp_msg =
 
1445
                                        /*TO TRANSLATORS: looks like   You queued an operation to move the start sector of partition /dev/sda3. */
 
1446
                                        String::ucompose( _( "You have queued an operation to move the start sector of partition %1." )
 
1447
                                                        , operation ->partition_original .get_path()
 
1448
                                                        ) ;
 
1449
                                tmp_msg += "  Failure to boot is most likely to occur if you move the GNU/Linux partition containing /boot, or if you move the Windows system partition C:." ;
 
1450
                                tmp_msg += "\n" ;
 
1451
                                tmp_msg += _( "You can learn how to repair the boot configuration in the GParted FAQ." ) ;
 
1452
                                tmp_msg += "\n" ;
 
1453
                                tmp_msg += "http://gparted.org/faq.php" ;
 
1454
                                tmp_msg += "\n\n" ;
 
1455
                                tmp_msg += "Moving a partition might take a very long time to apply." ;
 
1456
                                dialog .set_secondary_text( tmp_msg ) ;
 
1457
                                dialog .run() ;
 
1458
                        }
1427
1459
                }
1428
1460
        }
1429
1461
}
1643
1675
             ( fs .MAX && selected_partition .get_byte_length() > fs .MAX ) )
1644
1676
        {
1645
1677
                Gtk::MessageDialog dialog( *this,
1646
 
                                           String::ucompose( _("Cannot format this file system to %1."),
1647
 
                                                             Utils::get_filesystem_string( new_fs ) ) ,
 
1678
                                           String::ucompose( 
 
1679
                                                        /* TO TRANSLATORS: looks like
 
1680
                                                        * Cannot format this file system to fat16.
 
1681
                                                        */
 
1682
                                                        _( "Cannot format this file system to %1." ),
 
1683
                                                           Utils::get_filesystem_string( new_fs ) ) ,
1648
1684
                                           false,
1649
1685
                                           Gtk::MESSAGE_ERROR,
1650
1686
                                           Gtk::BUTTONS_OK,
1651
1687
                                           true );
1652
1688
 
1653
1689
                if ( selected_partition .get_byte_length() < fs .MIN )
1654
 
                        dialog .set_secondary_text( String::ucompose( 
 
1690
                        dialog .set_secondary_text( String::ucompose(
 
1691
                                                /* TO TRANSLATORS: looks like
 
1692
                                                 * A fat16 file system requires a partition of at least 16.00 MiB.
 
1693
                                                 */
1655
1694
                                                _( "A %1 file system requires a partition of at least %2."),
1656
1695
                                                Utils::get_filesystem_string( new_fs ),
1657
1696
                                                Utils::format_size( fs .MIN, 1 /* Byte */ ) ) );
1658
1697
                else
1659
 
                        dialog .set_secondary_text( String::ucompose( 
 
1698
                        dialog .set_secondary_text( String::ucompose(
 
1699
                                                /* TO TRANSLATORS: looks like
 
1700
                                                 * A partition with a hfs file system has a maximum size of 2.00 GiB.
 
1701
                                                 */
1660
1702
                                                _( "A partition with a %1 file system has a maximum size of %2."),
1661
1703
                                                Utils::get_filesystem_string( new_fs ),
1662
1704
                                                Utils::format_size( fs .MAX, 1 /* Byte */ ) ) );
1780
1822
 
1781
1823
        pulse = false ;
1782
1824
}
1783
 
        
 
1825
 
1784
1826
void Win_GParted::toggle_swap_mount_state() 
1785
 
{       
 
1827
{
 
1828
        int operation_count = partition_in_operation_queue_count( selected_partition ) ;
 
1829
        if ( operation_count > 0 )
 
1830
        {
 
1831
                //Note that this situation will only occur when trying to swapon a partition.
 
1832
                //  This is because GParted does not permit queueing operations on partitions
 
1833
                //  that are currently active (i.e., swap enabled, or mounted).  Hence this
 
1834
                //  situation will not occur for the swapoff or unmount actions that this
 
1835
                //  method handles.
 
1836
 
 
1837
                /*TO TRANSLATORS: Singular case looks like   1 operation is currently pending for partition /dev/sdd8. */
 
1838
                Glib::ustring tmp_msg =
 
1839
                    String::ucompose( ngettext( "%1 operation is currently pending for partition %2."
 
1840
                                              , "%1 operations are currently pending for partition %2."
 
1841
                                              , operation_count
 
1842
                                              )
 
1843
                                    , operation_count
 
1844
                                    , selected_partition .get_path()
 
1845
                                    ) ;
 
1846
                Gtk::MessageDialog dialog( *this
 
1847
                                         , tmp_msg
 
1848
                                         , false
 
1849
                                         , Gtk::MESSAGE_INFO
 
1850
                                         , Gtk::BUTTONS_OK
 
1851
                                         , true
 
1852
                                         ) ;
 
1853
                tmp_msg  = _( "The swapon action cannot be performed if an operation is pending for the partition." ) ;
 
1854
                tmp_msg += "\n" ;
 
1855
                tmp_msg += _( "Use the Edit menu to undo, clear, or apply operations before using swapon with this partition." ) ;
 
1856
                dialog .set_secondary_text( tmp_msg ) ;
 
1857
                dialog .run() ;
 
1858
                return ;
 
1859
        }
 
1860
 
1786
1861
        bool succes = false ;
1787
1862
        Glib::ustring error ;
1788
1863
 
1837
1912
 
1838
1913
        menu_gparted_refresh_devices() ;
1839
1914
}
1840
 
        
 
1915
 
1841
1916
void Win_GParted::activate_mount_partition( unsigned int index ) 
1842
1917
{
 
1918
        int operation_count = partition_in_operation_queue_count( selected_partition ) ;
 
1919
        if ( operation_count > 0 )
 
1920
        {
 
1921
                /*TO TRANSLATORS: Plural case looks like   4 operations are currently pending for partition /dev/sdd8. */
 
1922
                Glib::ustring tmp_msg =
 
1923
                    String::ucompose( ngettext( "%1 operation is currently pending for partition %2."
 
1924
                                              , "%1 operations are currently pending for partition %2."
 
1925
                                              , operation_count
 
1926
                                              )
 
1927
                                    , operation_count
 
1928
                                    , selected_partition .get_path()
 
1929
                                    ) ;
 
1930
                Gtk::MessageDialog dialog( *this
 
1931
                                         , tmp_msg
 
1932
                                         , false
 
1933
                                         , Gtk::MESSAGE_INFO
 
1934
                                         , Gtk::BUTTONS_OK
 
1935
                                         , true
 
1936
                                         ) ;
 
1937
                tmp_msg  = _( "The mount action cannot be performed if an operation is pending for the partition." ) ;
 
1938
                tmp_msg += "\n" ;
 
1939
                tmp_msg += _( "Use the Edit menu to undo, clear, or apply operations before using mount with this partition." ) ;
 
1940
                dialog .set_secondary_text( tmp_msg ) ;
 
1941
                dialog .run() ;
 
1942
                return ;
 
1943
        }
 
1944
 
1843
1945
        bool succes = false ;
1844
1946
        Glib::ustring error ;
1845
 
        
 
1947
 
1846
1948
        pulse = true ;
1847
1949
 
1848
1950
        thread = Glib::Thread::create( sigc::bind<Glib::ustring, bool *, Glib::ustring *>( 
1877
1979
 
1878
1980
void Win_GParted::activate_disklabel()
1879
1981
{
 
1982
        //If there are active mounted partitions on the device then warn
 
1983
        //  the user that all partitions must be unactive before creating
 
1984
        //  a new partition table
 
1985
        int active_count = active_partitions_on_device_count( devices[ current_device ] ) ;
 
1986
        if ( active_count > 0 )
 
1987
        {
 
1988
                Glib::ustring tmp_msg =
 
1989
                    String::ucompose( /*TO TRANSLATORS: Singular case looks like  1 partition is currently active on device /dev/sda. */
 
1990
                                      ngettext( "%1 partition is currently active on device %2."
 
1991
                                      /*TO TRANSLATORS: Plural case looks like    3 partitions are currently active on device /dev/sda. */
 
1992
                                              , "%1 partitions are currently active on device %2."
 
1993
                                              , active_count
 
1994
                                              )
 
1995
                                    , active_count
 
1996
                                    , devices[ current_device ] .get_path()
 
1997
                                    ) ;
 
1998
                Gtk::MessageDialog dialog( *this
 
1999
                                         , tmp_msg
 
2000
                                         , false
 
2001
                                         , Gtk::MESSAGE_INFO
 
2002
                                         , Gtk::BUTTONS_OK
 
2003
                                         , true
 
2004
                                         ) ;
 
2005
                tmp_msg  = _( "A new partition table cannot be created when there are active partitions." ) ;
 
2006
                tmp_msg += "  " ;
 
2007
                tmp_msg += _( "Active partitions are those that are in use, such as a mounted file system, or enabled swap space." ) ;
 
2008
                tmp_msg += "\n" ;
 
2009
                tmp_msg += _( "Use Partition menu options, such as unmount or swapoff, to deactivate all partitions on this device before creating a new partition table." ) ;
 
2010
                dialog .set_secondary_text( tmp_msg ) ;
 
2011
                dialog .run() ;
 
2012
                return ;
 
2013
        }
 
2014
 
1880
2015
        //If there are pending operations then warn the user that these
1881
2016
        //  operations must either be applied or cleared before creating
1882
2017
        //  a new partition table.
2002
2137
        if ( ! operations .size() )
2003
2138
                close_operationslist() ;
2004
2139
}
2005
 
        
 
2140
 
2006
2141
void Win_GParted::remove_operation( int index, bool remove_all ) 
2007
2142
{
2008
2143
        if ( remove_all )
2024
2159
        }
2025
2160
}
2026
2161
 
 
2162
int Win_GParted::partition_in_operation_queue_count( const Partition & partition )
 
2163
{
 
2164
        int operation_count = 0 ;
 
2165
 
 
2166
        for ( unsigned int t = 0 ; t < operations .size() ; t++ )
 
2167
        {
 
2168
                if ( partition .get_path() == operations[ t ] ->partition_original .get_path() )
 
2169
                        operation_count++ ;
 
2170
        }
 
2171
 
 
2172
        return operation_count ;
 
2173
}
 
2174
 
 
2175
int  Win_GParted::active_partitions_on_device_count( const Device & device )
 
2176
{
 
2177
        int active_count = 0 ;
 
2178
 
 
2179
        //Count the active partitions on the device
 
2180
        for ( unsigned int k=0; k < device .partitions .size(); k++ )
 
2181
        {
 
2182
                //FIXME:  Should also count other types of active partitions, such as LVM2 when we know how.
 
2183
 
 
2184
                //Count the active primary partitions
 
2185
                if (   device .partitions[ k ] .busy
 
2186
                    && device .partitions[ k ] .type != TYPE_EXTENDED
 
2187
                    && device .partitions[ k ] .type != TYPE_UNALLOCATED
 
2188
                   )
 
2189
                        active_count++ ;
 
2190
 
 
2191
                //Count the active logical partitions
 
2192
                if (   device .partitions[ k ] .busy
 
2193
                    && device .partitions[ k ] .type == TYPE_EXTENDED
 
2194
                   )
 
2195
                {
 
2196
                        for ( unsigned int j=0; j < device .partitions[ k ] .logicals .size(); j++ )
 
2197
                        {
 
2198
                                if (   device .partitions[ k ] .logicals [ j ] .busy
 
2199
                                    && device .partitions[ k ] .logicals [ j ] .type != TYPE_UNALLOCATED
 
2200
                                   )
 
2201
                                        active_count++ ;
 
2202
                        }
 
2203
                }
 
2204
        }
 
2205
 
 
2206
        return active_count ;
 
2207
}
 
2208
 
2027
2209
void Win_GParted::activate_apply()
2028
2210
{
2029
2211
        Gtk::MessageDialog dialog( *this,