overloaded operator == rewrote the graphical partitiondisplay. It now
* include/Partition.h, src/Partition.cc: overloaded operator == * include/VBox_VisualDisk.h, src/VBox_VisualDisk.cc: rewrote the graphical partitiondisplay. It now supports resizing and the extended partition is also selectable. see also #312656 * include/Win_GParted.h, src/Win_GParted.cc: use the new graphical partitiondisplay. * src/TreeView_Detail.cc: minor cleanups
This commit is contained in:
parent
afb93e5449
commit
adc76a7686
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2005-12-22 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/Partition.h,
|
||||
src/Partition.cc: overloaded operator ==
|
||||
* include/VBox_VisualDisk.h,
|
||||
src/VBox_VisualDisk.cc: rewrote the graphical partitiondisplay. It
|
||||
now supports resizing and the extended partition is also selectable.
|
||||
see also #312656
|
||||
* include/Win_GParted.h,
|
||||
src/Win_GParted.cc: use the new graphical partitiondisplay.
|
||||
* src/TreeView_Detail.cc: minor cleanups
|
||||
|
||||
2005-12-15 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/Dialog_Disklabel.h,
|
||||
|
|
|
@ -77,6 +77,8 @@ public:
|
|||
const long Get_Length_MB( ) const ;
|
||||
const long Get_Used_MB( ) const ;
|
||||
const long Get_Unused_MB( ) const ;
|
||||
|
||||
bool operator==( const Partition & partition ) ;
|
||||
|
||||
//some public members
|
||||
Glib::ustring partition;//the symbolic path (e.g. /dev/hda1 )
|
||||
|
|
|
@ -19,78 +19,111 @@
|
|||
#define VBOX_VISUALDISK
|
||||
|
||||
#include "../include/Partition.h"
|
||||
#include "../include/Device.h"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/frame.h>
|
||||
#include <gtkmm/eventbox.h>
|
||||
#include <gtkmm/tooltips.h>
|
||||
#include <gtkmm/checkbutton.h>
|
||||
#include <gtkmm/drawingarea.h>
|
||||
#include <gtkmm/image.h>
|
||||
|
||||
#define BORDER 8
|
||||
|
||||
namespace GParted
|
||||
{
|
||||
|
||||
class VBox_VisualDisk : public Gtk::VBox
|
||||
{
|
||||
//struct which contains visual information about the partitions. This prevents recalculation of everything after an expose en therefore saves performance..
|
||||
struct Visual_Partition
|
||||
{
|
||||
//2 attributes used for selection ( see Set_Selected() an drawingarea_on_expose() for more info )
|
||||
Sector sector_start;
|
||||
int index;
|
||||
|
||||
int length; //pixels
|
||||
int used; //pixels
|
||||
int height; //pixels
|
||||
int text_y; //pixels
|
||||
Gdk::Color color_fs;
|
||||
Gtk::DrawingArea *drawingarea;
|
||||
Glib::RefPtr<Gdk::GC> gc;
|
||||
Glib::RefPtr<Pango::Layout> pango_layout;
|
||||
};
|
||||
|
||||
public:
|
||||
VBox_VisualDisk( const std::vector<Partition> & partitions, const Sector device_length );
|
||||
~VBox_VisualDisk( );
|
||||
void Set_Selected( const Partition & );
|
||||
VBox_VisualDisk();
|
||||
~VBox_VisualDisk();
|
||||
|
||||
void load_partitions( const std::vector<Partition> & partitions, const Sector device_length );
|
||||
void set_selected( const Partition & partition ) ;
|
||||
void clear() ;
|
||||
|
||||
|
||||
//public signal for interclass communication
|
||||
sigc::signal<void,GdkEventButton *, const Partition &> signal_mouse_click;
|
||||
|
||||
sigc::signal<void, GdkEventButton *, const Partition &> signal_mouse_click;
|
||||
|
||||
private:
|
||||
void Build_Visual_Disk( ) ; //i still dream of some fully resizeable visualdisk....
|
||||
void Create_Visual_Partition( const Partition & partition ) ;
|
||||
void Prepare_Legend( std::vector<GParted::FILESYSTEM> & legend, const std::vector<Partition> & partitions ) ;
|
||||
void Build_Legend( ) ;
|
||||
|
||||
//signal handlers
|
||||
void drawingarea_on_realize( Visual_Partition * );
|
||||
bool drawingarea_on_expose( GdkEventExpose *, Visual_Partition* );
|
||||
bool on_drawingarea_button_press( GdkEventButton *, const Partition & );
|
||||
struct visual_partition ;
|
||||
|
||||
std::vector<Partition> partitions;
|
||||
Sector device_length;
|
||||
//private functions
|
||||
int get_total_separator_px( const std::vector<Partition> & partitions ) ;
|
||||
|
||||
void set_static_data( const std::vector<Partition> & partitions, std::vector<visual_partition> & visual_partitions, Sector length ) ;
|
||||
int calc_length( std::vector<visual_partition> & visual_partitions, int length_px ) ;
|
||||
void calc_position_and_height( std::vector<visual_partition> & visual_partitions, int start, int border ) ;
|
||||
void calc_used_unused( std::vector<visual_partition> & visual_partitions ) ;
|
||||
void calc_text( std::vector<visual_partition> & visual_partitions ) ;
|
||||
|
||||
void build_legend( const std::vector<Partition> & partitions ) ;
|
||||
void prepare_legend( const std::vector<Partition> & partitions, std::vector<GParted::FILESYSTEM> & legend) ;
|
||||
Gtk::HBox * create_legend_item( GParted::FILESYSTEM fs ) ;
|
||||
|
||||
void draw_partitions( const std::vector<visual_partition> & visual_partitions ) ;
|
||||
|
||||
bool set_selected( std::vector<visual_partition> & visual_partitions, int x, int y ) ;
|
||||
void set_selected( std::vector<visual_partition> & visual_partitions, const Partition & partition ) ;
|
||||
|
||||
void free_colors( std::vector<visual_partition> & visual_partitions ) ;
|
||||
|
||||
//signalhandlers
|
||||
void drawingarea_on_realize();
|
||||
bool drawingarea_on_expose( GdkEventExpose * event );
|
||||
bool on_drawingarea_button_press( GdkEventButton * event );
|
||||
void on_resize( Gtk::Allocation & allocation ) ;
|
||||
|
||||
Gtk::Frame *frame_disk_legend ;
|
||||
Gtk::HBox hbox_disk_main, *hbox_disk, *hbox_extended, hbox_legend_main, *hbox_legend;
|
||||
Gtk::CheckButton checkbutton_filesystem;
|
||||
Gtk::Tooltips tooltips;
|
||||
Gtk::Image *image ;
|
||||
//variables
|
||||
struct visual_partition
|
||||
{
|
||||
double fraction ;
|
||||
double fraction_used ;
|
||||
|
||||
int x_start, length ;
|
||||
int y_start, height ;
|
||||
int x_used_start, used_length ;
|
||||
int x_unused_start, unused_length ;
|
||||
int y_used_unused_start, used_unused_height ;
|
||||
int x_text, y_text ;
|
||||
|
||||
bool selected ;
|
||||
|
||||
Gdk::Color color ;
|
||||
Glib::RefPtr<Pango::Layout> pango_layout;
|
||||
|
||||
//real partition
|
||||
Partition partition ;
|
||||
|
||||
Visual_Partition *visual_partition;
|
||||
std::vector <Visual_Partition *> visual_partitions;
|
||||
Gtk::EventBox * eventbox_extended;
|
||||
std::vector<visual_partition> logicals ;
|
||||
|
||||
visual_partition()
|
||||
{
|
||||
fraction = fraction_used =
|
||||
x_start = length =
|
||||
y_start = height =
|
||||
x_used_start = used_length =
|
||||
x_unused_start = unused_length =
|
||||
y_used_unused_start = used_unused_height =
|
||||
x_text = y_text = 0 ;
|
||||
|
||||
selected = false ;
|
||||
|
||||
pango_layout .clear() ;
|
||||
}
|
||||
|
||||
~visual_partition()
|
||||
{
|
||||
pango_layout .clear() ;
|
||||
logicals .clear() ;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<visual_partition> visual_partitions ;
|
||||
visual_partition selected_vp ;
|
||||
int TOT_SEP, MIN_SIZE ;
|
||||
|
||||
Gtk::Frame *frame ;
|
||||
Gtk::DrawingArea drawingarea;
|
||||
Gtk::HBox hbox_legend ;
|
||||
Glib::RefPtr<Gdk::GC> gc;
|
||||
Gdk::Color color_used, color_unused, color_text;
|
||||
|
||||
|
||||
Glib::ustring str_temp ;
|
||||
int temp, selected_partition, SCREEN_WIDTH;
|
||||
};
|
||||
|
||||
} //GParted
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <gtkmm/separatortoolitem.h>
|
||||
#include <gtkmm/menubar.h>
|
||||
#include <gtkmm/statusbar.h>
|
||||
#include <gtkmm/radiobutton.h>
|
||||
#include <gtkmm/liststore.h>
|
||||
|
||||
#include <unistd.h> //should be included by gtkmm headers. but decided to include it anyway after getting some bugreports..
|
||||
|
@ -159,7 +158,7 @@ private:
|
|||
Gtk::HPaned hpaned_main;
|
||||
Gtk::VPaned vpaned_main;
|
||||
Gtk::VBox vbox_main,vbox_info, *vbox;
|
||||
Gtk::HBox hbox_toolbar,hbox_visual, hbox_operations, *hbox;
|
||||
Gtk::HBox hbox_toolbar, hbox_operations, *hbox;
|
||||
Gtk::Toolbar toolbar_main;
|
||||
Gtk::MenuBar menubar_main;
|
||||
Gtk::OptionMenu optionmenu_devices;
|
||||
|
@ -175,7 +174,7 @@ private:
|
|||
Gtk::MenuItem *menu_item;
|
||||
Gtk::ProgressBar *pulsebar ;
|
||||
|
||||
VBox_VisualDisk *vbox_visual_disk;
|
||||
VBox_VisualDisk vbox_visual_disk;
|
||||
TreeView_Detail treeview_detail;
|
||||
|
||||
//operations list
|
||||
|
@ -189,7 +188,12 @@ private:
|
|||
Gtk::TreeModelColumn<Glib::ustring> operation_description;
|
||||
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > operation_icon;
|
||||
|
||||
treeview_operations_Columns( ) { add( operation_number ); add( operation_description ); add( operation_icon ); }
|
||||
treeview_operations_Columns()
|
||||
{
|
||||
add( operation_number );
|
||||
add( operation_description );
|
||||
add( operation_icon );
|
||||
}
|
||||
};
|
||||
treeview_operations_Columns treeview_operations_columns;
|
||||
|
||||
|
|
|
@ -105,6 +105,13 @@ const long Partition::Get_Unused_MB( ) const
|
|||
return Get_Length_MB( ) - Get_Used_MB( ) ;
|
||||
}
|
||||
|
||||
bool Partition::operator==( const Partition & partition )
|
||||
{
|
||||
return this ->partition_number == partition .partition_number &&
|
||||
this ->sector_start == partition .sector_start &&
|
||||
this ->type == partition .type ;
|
||||
}
|
||||
|
||||
Partition::~Partition( )
|
||||
{
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ void TreeView_Detail::Load_Partitions( const std::vector<Partition> & partitions
|
|||
void TreeView_Detail::Set_Selected( const Partition & partition )
|
||||
{
|
||||
//look for appropiate row
|
||||
for( iter = treestore_detail ->children( ) .begin( ) ; iter != treestore_detail ->children( ) .end( ) ; iter++ )
|
||||
for( iter = treestore_detail ->children() .begin() ; iter != treestore_detail ->children() .end() ; iter++ )
|
||||
{
|
||||
row = *iter;
|
||||
partition_temp = row[ treeview_detail_columns.partition_struct ] ;
|
||||
|
@ -99,15 +99,15 @@ void TreeView_Detail::Set_Selected( const Partition & partition )
|
|||
}
|
||||
|
||||
//logicals
|
||||
if ( row .children( ) .size( ) > 0 ) //this is the row with the extended partition, search it's childrows...
|
||||
for( iter_child = row .children( ) .begin( ) ; iter_child != row.children( ) .end( ) ; iter_child++ )
|
||||
if ( row .children() .size( ) > 0 ) //this is the row with the extended partition, search it's childrows...
|
||||
for( iter_child = row .children() .begin() ; iter_child != row.children() .end() ; iter_child++ )
|
||||
{
|
||||
childrow = *iter_child;
|
||||
partition_temp = childrow[ treeview_detail_columns.partition_struct ] ;
|
||||
|
||||
if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <= partition_temp .sector_end )
|
||||
{
|
||||
this ->expand_all( );
|
||||
this ->expand_all();
|
||||
this ->set_cursor( static_cast <Gtk::TreePath> ( childrow ) );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -17,312 +17,449 @@
|
|||
|
||||
#include "../include/VBox_VisualDisk.h"
|
||||
|
||||
#include <gtkmm/image.h>
|
||||
|
||||
#define BORDER 8
|
||||
#define SEP 5
|
||||
#define HEIGHT 70
|
||||
|
||||
namespace GParted
|
||||
{
|
||||
|
||||
VBox_VisualDisk::VBox_VisualDisk( const std::vector<Partition> & partitions, const Sector device_length )
|
||||
VBox_VisualDisk::VBox_VisualDisk()
|
||||
{
|
||||
this ->partitions = partitions ;
|
||||
this ->device_length = device_length ;
|
||||
|
||||
selected_partition = -1;
|
||||
|
||||
//create frame which contains the visual disk
|
||||
frame_disk_legend = manage( new Gtk::Frame( ) ) ;
|
||||
frame_disk_legend ->set_shadow_type( Gtk::SHADOW_ETCHED_OUT );
|
||||
hbox_disk_main .pack_start( *frame_disk_legend, Gtk::PACK_EXPAND_PADDING );
|
||||
|
||||
hbox_disk = NULL ;
|
||||
hbox_extended = NULL ;
|
||||
|
||||
this ->set_border_width( 10 );
|
||||
this ->set_spacing( 12 );
|
||||
this ->pack_start( hbox_disk_main, Gtk::PACK_SHRINK );
|
||||
this ->set_spacing( 5 );
|
||||
|
||||
//set and allocated some standard colors
|
||||
color_used .set( "#F8F8BA" ); this ->get_colormap( ) ->alloc_color( color_used ) ;//bleach yellow ;)
|
||||
color_unused .set( "white" ); this ->get_colormap( ) ->alloc_color( color_unused ) ;
|
||||
color_text .set( "black" ); this ->get_colormap( ) ->alloc_color( color_text ) ;
|
||||
color_used .set( Utils::Get_Color( GParted::FS_USED ) );
|
||||
this ->get_colormap() ->alloc_color( color_used ) ;
|
||||
|
||||
color_unused .set( Utils::Get_Color( GParted::FS_UNUSED ) );
|
||||
this ->get_colormap() ->alloc_color( color_unused ) ;
|
||||
|
||||
//since disksegments have minimal sizes ( unallocated 15 and partitions 20 pixels ) i do some checking to prevent the visual disk from growing to much
|
||||
Sector sectors_per_pixel = Utils::Round( device_length / 750.00 ) ;
|
||||
|
||||
double extra_pixels = 0 ;
|
||||
color_text .set( "black" );
|
||||
this ->get_colormap() ->alloc_color( color_text ) ;
|
||||
|
||||
//prepare drawingarea and frame and pack them
|
||||
drawingarea .set_events( Gdk::BUTTON_PRESS_MASK );
|
||||
|
||||
for ( unsigned int t = 0; t < partitions .size( ) ; t++ )
|
||||
{
|
||||
double width = static_cast<double> (partitions[ t ] .sector_end - partitions[ t ] .sector_start) / sectors_per_pixel ;
|
||||
|
||||
if ( (partitions[ t ] .type == GParted::TYPE_PRIMARY || partitions[ t ] .type == GParted::TYPE_LOGICAL) && width < 20 )
|
||||
extra_pixels += (20 - width) ;
|
||||
else if ( partitions[ t ] .type == GParted::TYPE_UNALLOCATED && width < 15 )
|
||||
extra_pixels += (15 - width) ;
|
||||
}
|
||||
drawingarea .signal_realize() .connect( sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize) ) ;
|
||||
drawingarea .signal_expose_event() .connect( sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose) ) ;
|
||||
drawingarea .signal_button_press_event() .connect( sigc::mem_fun( *this, &VBox_VisualDisk::on_drawingarea_button_press) ) ;
|
||||
|
||||
//draw visual disk and its legend
|
||||
this ->SCREEN_WIDTH = 750 - Utils::Round( extra_pixels ) ;
|
||||
drawingarea .set_size_request( -1, HEIGHT ) ;
|
||||
|
||||
frame = manage( new Gtk::Frame() ) ;
|
||||
frame ->add( drawingarea );
|
||||
frame ->set_shadow_type( Gtk::SHADOW_ETCHED_OUT ) ;
|
||||
this ->pack_start( *frame, Gtk::PACK_EXPAND_WIDGET ) ;
|
||||
|
||||
//pack hbox which holds the legend
|
||||
this ->pack_start( hbox_legend );
|
||||
}
|
||||
|
||||
Build_Visual_Disk( ) ;
|
||||
Build_Legend( ) ;
|
||||
void VBox_VisualDisk::load_partitions( const std::vector<Partition> & partitions, const Sector device_length )
|
||||
{
|
||||
clear() ;
|
||||
|
||||
TOT_SEP = get_total_separator_px( partitions ) ;
|
||||
set_static_data( partitions, visual_partitions, device_length ) ;
|
||||
|
||||
drawingarea .queue_resize() ;
|
||||
|
||||
build_legend( partitions ) ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::Build_Visual_Disk( )
|
||||
void VBox_VisualDisk::set_selected( const Partition & partition )
|
||||
{
|
||||
//since there is a 5 pixel space between every partition.... ( extended adds 2 *5 more, but that doesn't matter that much.
|
||||
//NOTE that a part < 20 will also grow to 20, so length in pixels may vary across different devices..
|
||||
this ->SCREEN_WIDTH -= ( (partitions .size( ) -1) *5 ) ;
|
||||
set_selected( visual_partitions, partition ) ;
|
||||
|
||||
//create hbox_disk and add to frame
|
||||
hbox_disk = manage( new Gtk::HBox( ) ) ;
|
||||
hbox_disk ->set_spacing( 5 );
|
||||
frame_disk_legend ->add( *hbox_disk );
|
||||
|
||||
|
||||
//walk through all partitions....
|
||||
for ( unsigned int i = 0 ; i < partitions .size( ) ; i++ )
|
||||
{
|
||||
Create_Visual_Partition( partitions[ i ] ) ;
|
||||
|
||||
if ( partitions[ i ].type != GParted::TYPE_EXTENDED )
|
||||
hbox_disk ->pack_start( *( visual_partitions .back( ) ->drawingarea ), Gtk::PACK_SHRINK ) ;
|
||||
}
|
||||
|
||||
this ->show_all_children( ) ;
|
||||
draw_partitions( visual_partitions ) ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::Create_Visual_Partition( const Partition & partition )
|
||||
void VBox_VisualDisk::clear()
|
||||
{
|
||||
int x,y;//for pango_layout check
|
||||
free_colors( visual_partitions ) ;
|
||||
visual_partitions .clear() ;
|
||||
hbox_legend .children() .clear() ;
|
||||
|
||||
visual_partition = new Visual_Partition( ) ;
|
||||
visual_partitions .push_back( visual_partition ) ;
|
||||
visual_partitions .back( ) ->index = visual_partitions .size( ) -1 ; // <---- BELACHELIJK!! DOE DAAR IETS AAN!!!
|
||||
visual_partitions .back( ) ->sector_start = partition .sector_start ;
|
||||
|
||||
if ( partition .type == GParted::TYPE_EXTENDED )
|
||||
drawingarea .queue_resize() ;
|
||||
}
|
||||
|
||||
int VBox_VisualDisk::get_total_separator_px( const std::vector<Partition> & partitions )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
||||
if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
||||
return ( partitions[ t ] .logicals .size() -1 + partitions .size() -1 ) * SEP ;
|
||||
|
||||
|
||||
return ( partitions .size() -1 ) * SEP ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::set_static_data( const std::vector<Partition> & partitions, std::vector<visual_partition> & visual_partitions, Sector length )
|
||||
{
|
||||
Sector p_length ;
|
||||
visual_partition vp ;
|
||||
|
||||
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
||||
{
|
||||
visual_partitions.back( ) ->drawingarea = NULL ;//it's just a dummy ;-) ( see Set_Selected() )
|
||||
visual_partitions.back( ) ->length = 0 ; //keeps total_length clean
|
||||
|
||||
eventbox_extended = manage( new Gtk::EventBox( ) ) ;
|
||||
eventbox_extended ->set_size_request( -1, 60 );
|
||||
eventbox_extended ->modify_bg( eventbox_extended ->get_state( ), partition .color );
|
||||
hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ;
|
||||
visual_partitions .push_back( vp ) ;
|
||||
|
||||
visual_partitions .back() .partition = partitions[ t ] ;
|
||||
|
||||
p_length = partitions[ t ] .sector_end - partitions[ t ] .sector_start ;
|
||||
visual_partitions .back() .fraction = p_length / static_cast<double>( length ) ;
|
||||
|
||||
if ( partitions[ t ] .type == GParted::TYPE_UNALLOCATED || partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
||||
visual_partitions .back() .fraction_used = -1 ;
|
||||
else if ( partitions[ t ] .sectors_used > 0 )
|
||||
visual_partitions .back() .fraction_used = partitions[ t ] .sectors_used / static_cast<double>( p_length ) ;
|
||||
|
||||
visual_partitions .back() .color = partitions[ t ] .color;
|
||||
this ->get_colormap( ) ->alloc_color( visual_partitions .back() .color );
|
||||
|
||||
if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
||||
set_static_data( partitions[ t ] .logicals,
|
||||
visual_partitions .back() .logicals,
|
||||
partitions[ t ] .sector_end - partitions[ t ] .sector_start ) ;
|
||||
else
|
||||
visual_partitions .back() .pango_layout = drawingarea .create_pango_layout(
|
||||
partitions[ t ] .partition + "\n" + String::ucompose( _("%1 MB"), partitions[ t ] .Get_Length_MB() ) ) ;
|
||||
}
|
||||
}
|
||||
|
||||
int VBox_VisualDisk::calc_length( std::vector<visual_partition> & visual_partitions, int length_px )
|
||||
{
|
||||
int calced_length = 0 ;
|
||||
|
||||
for ( int t = 0 ; t < static_cast<int>( visual_partitions .size() ) ; t++ )
|
||||
{
|
||||
visual_partitions[ t ] .length = Utils::Round( length_px * visual_partitions[ t ] .fraction ) ;
|
||||
|
||||
hbox_extended = manage( new Gtk::HBox( ) ) ;
|
||||
hbox_extended ->set_border_width( 5 );
|
||||
hbox_extended ->set_spacing( 5 );
|
||||
eventbox_extended ->add( *hbox_extended ) ;
|
||||
|
||||
for ( unsigned int t = 0 ; t < partition .logicals .size( ) ; t++ )
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
{
|
||||
Create_Visual_Partition( partition .logicals[ t ] ) ;
|
||||
hbox_extended ->pack_start( *( visual_partitions .back( ) ->drawingarea ), Gtk::PACK_SHRINK ) ;
|
||||
int ext_length = calc_length( visual_partitions[ t ] .logicals, visual_partitions[ t ] .length - (2 * BORDER) ) ;
|
||||
|
||||
visual_partitions[ t ] .length = ext_length + (2 * BORDER) ;
|
||||
}
|
||||
|
||||
return ;
|
||||
else if ( visual_partitions[ t ] .length < MIN_SIZE )
|
||||
visual_partitions[ t ] .length = MIN_SIZE ;
|
||||
|
||||
calced_length += visual_partitions[ t ] .length ;
|
||||
}
|
||||
|
||||
visual_partitions .back( ) ->length = static_cast<int> ( SCREEN_WIDTH / ( device_length / static_cast<double>(partition .sector_end - partition .sector_start) ) );
|
||||
if ( visual_partitions .back( ) ->length < 20 )//we need a min. size. Otherwise some small partitions wouldn't be visible
|
||||
visual_partitions .back( ) ->length = ( partition .type == GParted::TYPE_UNALLOCATED ) ? 15 : 20 ;
|
||||
|
||||
if ( partition .inside_extended )
|
||||
{
|
||||
visual_partitions .back( ) ->height = 34 ;
|
||||
visual_partitions .back( ) ->text_y = 9 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
visual_partitions .back( ) ->height = 44 ;
|
||||
visual_partitions .back( ) ->text_y = 15 ;
|
||||
}
|
||||
|
||||
if ( partition .type == GParted::TYPE_UNALLOCATED )
|
||||
visual_partitions .back( ) ->used = -1;
|
||||
else
|
||||
visual_partitions .back( ) ->used = static_cast<int>( (visual_partitions .back( ) ->length - (BORDER *2)) / ( static_cast<double>(partition .sector_end - partition .sector_start) / partition .sectors_used ) );
|
||||
|
||||
visual_partitions.back( ) ->color_fs = partition .color;
|
||||
this ->get_colormap( ) ->alloc_color( visual_partitions .back( ) ->color_fs );
|
||||
|
||||
visual_partitions .back( ) ->drawingarea = manage( new Gtk::DrawingArea( ) ) ;
|
||||
visual_partitions .back( ) ->drawingarea ->set_size_request( visual_partitions .back( ) ->length +1, 60 );
|
||||
visual_partitions .back( ) ->drawingarea ->set_events( Gdk::BUTTON_PRESS_MASK );
|
||||
|
||||
//connect signal handlers
|
||||
visual_partitions .back( ) ->drawingarea ->signal_button_press_event( ) .connect( sigc::bind<Partition>(sigc::mem_fun(*this, &VBox_VisualDisk::on_drawingarea_button_press), partition ) );
|
||||
visual_partitions .back( ) ->drawingarea ->signal_realize( ) .connect( sigc::bind<Visual_Partition *>(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize), visual_partitions .back( ) ) );
|
||||
visual_partitions .back( ) ->drawingarea ->signal_expose_event( ) .connect( sigc::bind<Visual_Partition *>(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose), visual_partitions .back( ) ));
|
||||
|
||||
//create pangolayout and see if it fits in the visual partition
|
||||
str_temp = partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB( ) ) ;
|
||||
visual_partitions .back( ) ->pango_layout = visual_partitions .back( ) ->drawingarea ->create_pango_layout ( str_temp ) ;
|
||||
|
||||
visual_partitions .back( ) ->pango_layout ->get_pixel_size( x, y ) ;
|
||||
if ( visual_partitions .back( ) ->length - BORDER * 2 -2 < x )
|
||||
visual_partitions .back( ) ->pango_layout ->set_text( "" ) ;
|
||||
|
||||
//tooltip
|
||||
str_temp = "" ;
|
||||
if ( partition .type != GParted::TYPE_UNALLOCATED )
|
||||
str_temp = Utils::Get_Filesystem_String( partition .filesystem ) + "\n" ;
|
||||
|
||||
str_temp += partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB( ) ) ;
|
||||
tooltips .set_tip( *( visual_partitions.back( ) ->drawingarea ), str_temp ) ;
|
||||
return calced_length + (visual_partitions .size() - 1) * SEP ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::Prepare_Legend( std::vector<GParted::FILESYSTEM> & legend, const std::vector<Partition> & partitions )
|
||||
void VBox_VisualDisk::calc_position_and_height( std::vector<visual_partition> & visual_partitions, int start, int border )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < partitions .size( ) ; t++ )
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
if ( std::find( legend .begin( ), legend .end( ), partitions[ t ] .filesystem ) == legend .end( ) )
|
||||
visual_partitions[ t ] .x_start = start ;
|
||||
visual_partitions[ t ] .y_start = border ;
|
||||
visual_partitions[ t ] .height = HEIGHT - ( border * 2 ) ;
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
calc_position_and_height( visual_partitions[ t ] .logicals,
|
||||
visual_partitions[ t ] .x_start + BORDER,
|
||||
BORDER ) ;
|
||||
|
||||
start += visual_partitions[ t ] .length + SEP ;
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::calc_used_unused( std::vector<visual_partition> & visual_partitions )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
if ( visual_partitions[ t ] .fraction_used > -1 )
|
||||
{
|
||||
//used
|
||||
visual_partitions[ t ] .x_used_start = visual_partitions[ t ] .x_start + BORDER ;
|
||||
|
||||
if ( visual_partitions[ t ] .fraction_used )
|
||||
visual_partitions[ t ] .used_length =
|
||||
Utils::Round( ( visual_partitions[ t ] .length - (2*BORDER) ) * visual_partitions[ t ] .fraction_used ) ;
|
||||
|
||||
//unused
|
||||
visual_partitions[ t ] .x_unused_start = visual_partitions[ t ] .x_used_start + visual_partitions[ t ] .used_length ;
|
||||
visual_partitions[ t ] .unused_length
|
||||
= visual_partitions[ t ] .length - (2 * BORDER) - visual_partitions[ t ] .used_length ;
|
||||
|
||||
//y position and height
|
||||
visual_partitions[ t ] .y_used_unused_start = visual_partitions[ t ] .y_start + BORDER ;
|
||||
visual_partitions[ t ] .used_unused_height = visual_partitions[ t ] .height - (2 * BORDER) ;
|
||||
}
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
calc_used_unused( visual_partitions[ t ] .logicals ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::calc_text( std::vector<visual_partition> & visual_partitions )
|
||||
{
|
||||
int length, height ;
|
||||
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
if ( visual_partitions[ t ] .pango_layout )
|
||||
{
|
||||
//see if the text fits in the partition... (and if so, center the text..)
|
||||
visual_partitions[ t ] .pango_layout ->get_pixel_size( length, height ) ;
|
||||
if ( length < visual_partitions[ t ] .length - (2 * BORDER) - 2 )
|
||||
{
|
||||
visual_partitions[ t ] .x_text = visual_partitions[ t ] .x_start +
|
||||
Utils::Round( (visual_partitions[ t ] .length / 2) - (length / 2) ) ;
|
||||
|
||||
visual_partitions[ t ] .y_text = visual_partitions[ t ] .y_start +
|
||||
Utils::Round( (visual_partitions[ t ] .height / 2) - (height / 2) ) ;
|
||||
}
|
||||
else
|
||||
visual_partitions[ t ] .x_text = visual_partitions[ t ] .y_text = 0 ;
|
||||
}
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
calc_text( visual_partitions[ t ] .logicals ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::build_legend( const std::vector<Partition> & partitions )
|
||||
{
|
||||
std::vector<GParted::FILESYSTEM> legend ;
|
||||
prepare_legend( partitions, legend ) ;
|
||||
|
||||
frame = manage( new Gtk::Frame() ) ;
|
||||
hbox_legend .pack_start( *frame, Gtk::PACK_EXPAND_PADDING );
|
||||
|
||||
Gtk::HBox * hbox = manage( new Gtk::HBox( false, 15 ) );
|
||||
hbox ->set_border_width( 3 ) ;
|
||||
frame ->add( *hbox ) ;
|
||||
|
||||
bool hide_used_unused = true;
|
||||
for ( unsigned int t = 0 ; t < legend .size() ; t++ )
|
||||
{
|
||||
hbox ->pack_start( * create_legend_item( legend[ t ] ), Gtk::PACK_SHRINK ) ;
|
||||
|
||||
if ( legend[ t ] != GParted::FS_UNALLOCATED && legend[ t ] != GParted::FS_EXTENDED && legend[ t ] != GParted::FS_LINUX_SWAP )
|
||||
hide_used_unused = false ;
|
||||
}
|
||||
|
||||
if ( ! hide_used_unused )
|
||||
{
|
||||
frame = manage( new Gtk::Frame() ) ;
|
||||
hbox_legend .pack_start( *frame, Gtk::PACK_EXPAND_PADDING );
|
||||
|
||||
hbox = manage( new Gtk::HBox( false, 15 ) );
|
||||
hbox ->set_border_width( 3 ) ;
|
||||
frame ->add( *hbox ) ;
|
||||
|
||||
hbox ->pack_start( * create_legend_item( GParted::FS_USED ), Gtk::PACK_SHRINK ) ;
|
||||
hbox ->pack_start( * create_legend_item( GParted::FS_UNUSED ), Gtk::PACK_SHRINK ) ;
|
||||
}
|
||||
|
||||
hbox_legend .show_all_children() ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::prepare_legend( const std::vector<Partition> & partitions, std::vector<GParted::FILESYSTEM> & legend )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
||||
{
|
||||
if ( std::find( legend .begin(), legend .end(), partitions[ t ] .filesystem ) == legend .end() )
|
||||
legend .push_back( partitions[ t ] .filesystem );
|
||||
|
||||
if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
||||
Prepare_Legend( legend, partitions[ t ] .logicals ) ;
|
||||
prepare_legend( partitions[ t ] .logicals, legend ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::Build_Legend( )
|
||||
{
|
||||
//add the hboxes and frame_legenda
|
||||
frame_disk_legend = manage( new Gtk::Frame( ) ) ;
|
||||
hbox_legend_main .pack_start( *frame_disk_legend, Gtk::PACK_EXPAND_PADDING );
|
||||
|
||||
hbox_legend = manage( new Gtk::HBox( ) );
|
||||
hbox_legend ->set_border_width( 2 ) ;
|
||||
frame_disk_legend ->add( *hbox_legend ) ;
|
||||
this ->pack_start( hbox_legend_main );
|
||||
|
||||
std::vector<GParted::FILESYSTEM> legend ;
|
||||
Prepare_Legend( legend, partitions ) ;
|
||||
|
||||
bool hide_used_unused = true;
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
for ( unsigned int t = 0 ; t < legend .size( ) ; t++ )
|
||||
{
|
||||
if ( legend[ t ] != GParted::FS_UNALLOCATED && legend[ t ] != GParted::FS_EXTENDED && legend[ t ] != GParted::FS_LINUX_SWAP )
|
||||
hide_used_unused = false ;
|
||||
|
||||
if ( t )
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( legend[ t ], 16, 16 ) ) ) ;
|
||||
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( legend[ t ] ) ), Gtk::PACK_SHRINK );
|
||||
}
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
//if there are any partitions add used/unused
|
||||
if ( ! hide_used_unused )
|
||||
{
|
||||
frame_disk_legend = manage( new Gtk::Frame( ) ) ;
|
||||
hbox_legend_main .pack_start( *frame_disk_legend, Gtk::PACK_EXPAND_PADDING );
|
||||
|
||||
hbox_legend = manage( new Gtk::HBox( ) );
|
||||
hbox_legend ->set_border_width( 2 ) ;
|
||||
frame_disk_legend ->add( *hbox_legend );
|
||||
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
//used
|
||||
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( GParted::FS_USED, 16, 16 ) ) ) ;
|
||||
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( GParted::FS_USED ) ), Gtk::PACK_SHRINK );
|
||||
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
//unused
|
||||
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( GParted::FS_UNUSED, 16, 16 ) ) ) ;
|
||||
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
|
||||
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( GParted::FS_UNUSED ) ), Gtk::PACK_SHRINK );
|
||||
|
||||
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::Set_Selected( const Partition & partition )
|
||||
Gtk::HBox * VBox_VisualDisk::create_legend_item( GParted::FILESYSTEM fs )
|
||||
{
|
||||
//clean previously selected one
|
||||
temp = selected_partition ;
|
||||
selected_partition = -1;
|
||||
if ( temp >= 0 ) //prevent segfault at firsttime selection
|
||||
drawingarea_on_expose( NULL, visual_partitions[ temp ] ) ;
|
||||
Gtk::HBox * hbox = manage( new Gtk::HBox( false, 5 ) ) ;
|
||||
hbox ->pack_start( * manage( new Gtk::Image( Utils::get_color_as_pixbuf( fs, 16, 16 ) ) ), Gtk::PACK_SHRINK );
|
||||
|
||||
if ( partition.type == GParted::TYPE_EXTENDED )
|
||||
return; //extended can not be selected in visualdisk (yet )
|
||||
|
||||
//now set new selected one
|
||||
for ( unsigned int t = 0;t < visual_partitions.size() ; t++ )
|
||||
hbox ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( fs ) ), Gtk::PACK_SHRINK );
|
||||
|
||||
return hbox ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::draw_partitions( const std::vector<visual_partition> & visual_partitions )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
if ( visual_partitions[ t ] ->sector_start == partition .sector_start && visual_partitions[ t ] ->drawingarea != NULL )
|
||||
//partition...
|
||||
gc ->set_foreground( visual_partitions[ t ] .color );
|
||||
drawingarea .get_window() ->draw_rectangle( gc,
|
||||
true,
|
||||
visual_partitions[ t ] .x_start,
|
||||
visual_partitions[ t ] .y_start,
|
||||
visual_partitions[ t ] .length,
|
||||
visual_partitions[ t ] .height );
|
||||
|
||||
//used..
|
||||
if ( visual_partitions[ t ] .used_length > 0 )
|
||||
{
|
||||
selected_partition = t;
|
||||
drawingarea_on_expose( NULL, visual_partitions[ t ] ) ;
|
||||
return;
|
||||
gc ->set_foreground( color_used );
|
||||
drawingarea .get_window() ->draw_rectangle( gc,
|
||||
true,
|
||||
visual_partitions[ t ] .x_used_start,
|
||||
visual_partitions[ t ] .y_used_unused_start,
|
||||
visual_partitions[ t ] .used_length,
|
||||
visual_partitions[ t ] .used_unused_height );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp )
|
||||
{
|
||||
vp ->gc = Gdk::GC::create( vp ->drawingarea ->get_window( ) );
|
||||
|
||||
vp ->drawingarea ->get_window( ) ->set_background( vp ->color_fs );
|
||||
//eventmasks necessary for tooltips
|
||||
vp ->drawingarea ->add_events( Gdk::ENTER_NOTIFY_MASK );
|
||||
vp ->drawingarea ->add_events( Gdk::LEAVE_NOTIFY_MASK );
|
||||
}
|
||||
|
||||
bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partition* vp )
|
||||
{
|
||||
vp ->drawingarea ->get_window( ) ->clear( ) ;
|
||||
|
||||
if ( vp ->used != -1 ) //if not unknown or unallocated
|
||||
{
|
||||
vp ->gc ->set_foreground( color_used );
|
||||
vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, true, BORDER, BORDER, vp ->used, vp ->height );
|
||||
|
||||
vp ->gc ->set_foreground( color_unused );
|
||||
vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, true, BORDER + vp ->used, BORDER, vp ->length - vp ->used - BORDER *2 , vp ->height );
|
||||
//unused
|
||||
if ( visual_partitions[ t ] .unused_length > 0 )
|
||||
{
|
||||
gc ->set_foreground( color_unused );
|
||||
drawingarea .get_window() ->draw_rectangle( gc,
|
||||
true,
|
||||
visual_partitions[ t ] .x_unused_start,
|
||||
visual_partitions[ t ] .y_used_unused_start,
|
||||
visual_partitions[ t ] .unused_length,
|
||||
visual_partitions[ t ] .used_unused_height );
|
||||
}
|
||||
|
||||
//text
|
||||
if ( visual_partitions[ t ] .x_text > 0 )
|
||||
{
|
||||
gc ->set_foreground( color_text );
|
||||
drawingarea .get_window() ->draw_layout( gc,
|
||||
visual_partitions[ t ] .x_text,
|
||||
visual_partitions[ t ] .y_text,
|
||||
visual_partitions[ t ] .pango_layout ) ;
|
||||
}
|
||||
|
||||
//selection rectangle...
|
||||
if ( visual_partitions[ t ] .selected )
|
||||
{
|
||||
gc ->set_foreground( color_used );
|
||||
//selection start and ends at 4px from the borders, hence the >8 restriction
|
||||
if ( visual_partitions[ t ] .length > 8 )
|
||||
drawingarea .get_window() ->draw_rectangle( gc,
|
||||
false,
|
||||
visual_partitions[ t ] .x_start +4,
|
||||
visual_partitions[ t ] .y_start +4,
|
||||
visual_partitions[ t ] .length -9,
|
||||
visual_partitions[ t ] .height -9 );
|
||||
else
|
||||
drawingarea .get_window() ->draw_rectangle( gc,
|
||||
true,
|
||||
visual_partitions[ t ] .x_start,
|
||||
visual_partitions[ t ] .y_start +9,
|
||||
visual_partitions[ t ] .length,
|
||||
visual_partitions[ t ] .height -19 );
|
||||
}
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
draw_partitions( visual_partitions[ t ] .logicals ) ;
|
||||
}
|
||||
|
||||
vp ->gc ->set_foreground( color_text );
|
||||
vp ->drawingarea ->get_window( ) ->draw_layout( vp ->gc, BORDER +2, vp ->text_y, vp ->pango_layout ) ;
|
||||
|
||||
//if partition is selected one..
|
||||
if ( vp ->index == selected_partition )
|
||||
{
|
||||
vp ->gc ->set_foreground( color_used );
|
||||
vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, false, 4, 4, vp ->length -8, vp ->height +8 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VBox_VisualDisk::on_drawingarea_button_press( GdkEventButton *event, const Partition & partition )
|
||||
bool VBox_VisualDisk::set_selected( std::vector<visual_partition> & visual_partitions, int x, int y )
|
||||
{
|
||||
signal_mouse_click .emit( event, partition );
|
||||
return true;
|
||||
bool found = false ;
|
||||
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
if ( visual_partitions[ t ] .x_start <= x && x < visual_partitions[ t ] .x_start + visual_partitions[ t ] .length &&
|
||||
visual_partitions[ t ] .y_start <= y && y < visual_partitions[ t ] .y_start + visual_partitions[ t ] .height )
|
||||
{
|
||||
visual_partitions[ t ] .selected = true ;
|
||||
selected_vp = visual_partitions[ t ] ;
|
||||
found = true ;
|
||||
}
|
||||
else
|
||||
visual_partitions[ t ] .selected = false ;
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
visual_partitions[ t ] .selected &= ! set_selected( visual_partitions[ t ] .logicals, x, y ) ;
|
||||
|
||||
}
|
||||
|
||||
return found ;
|
||||
}
|
||||
|
||||
VBox_VisualDisk::~VBox_VisualDisk( )
|
||||
void VBox_VisualDisk::set_selected( std::vector<visual_partition> & visual_partitions, const Partition & partition )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size( ) ; t++ )
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
this ->get_colormap( ) ->free_colors( visual_partitions[ t ] ->color_fs, 1 ) ;
|
||||
delete visual_partitions[ t ] ;
|
||||
if ( visual_partitions[ t ] .partition == partition )
|
||||
{
|
||||
visual_partitions[ t ] .selected = true ;
|
||||
selected_vp = visual_partitions[ t ] ;
|
||||
}
|
||||
else
|
||||
visual_partitions[ t ] .selected = false ;
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
set_selected( visual_partitions[ t ] .logicals, partition ) ;
|
||||
}
|
||||
|
||||
visual_partitions .clear( ) ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::drawingarea_on_realize()
|
||||
{
|
||||
gc = Gdk::GC::create( drawingarea .get_window() );
|
||||
|
||||
//connect here to prevent premature signalling (only relevant at startup)
|
||||
drawingarea .signal_size_allocate() .connect( sigc::mem_fun( *this, &VBox_VisualDisk::on_resize ) ) ;
|
||||
}
|
||||
|
||||
bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * event )
|
||||
{
|
||||
draw_partitions( visual_partitions ) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool VBox_VisualDisk::on_drawingarea_button_press( GdkEventButton * event )
|
||||
{
|
||||
if ( set_selected( visual_partitions, static_cast<int>( event ->x ), static_cast<int>( event ->y ) ) )
|
||||
signal_mouse_click .emit( event, selected_vp .partition );
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::on_resize( Gtk::Allocation & allocation )
|
||||
{
|
||||
MIN_SIZE = 20 ;
|
||||
|
||||
int calced, TOTAL ;
|
||||
do
|
||||
{
|
||||
TOTAL = allocation .get_width() - TOT_SEP ;
|
||||
calced = allocation .get_width() ; //for first time :)
|
||||
do
|
||||
{
|
||||
TOTAL -= ( calced - allocation .get_width() ) ;
|
||||
calced = calc_length( visual_partitions, TOTAL ) ;
|
||||
}
|
||||
while ( calced > allocation .get_width() && TOTAL > 0 ) ;
|
||||
|
||||
MIN_SIZE-- ;
|
||||
}
|
||||
while ( TOTAL <= 0 && MIN_SIZE > 0 ) ;
|
||||
|
||||
calc_position_and_height( visual_partitions, 0, 0 ) ;
|
||||
calc_used_unused( visual_partitions ) ;
|
||||
calc_text( visual_partitions ) ;
|
||||
}
|
||||
|
||||
void VBox_VisualDisk::free_colors( std::vector<visual_partition> & visual_partitions )
|
||||
{
|
||||
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
|
||||
{
|
||||
this ->get_colormap( ) ->free_color( visual_partitions[ t ] .color ) ;
|
||||
|
||||
if ( visual_partitions[ t ] .logicals .size() > 0 )
|
||||
free_colors( visual_partitions[ t ] .logicals ) ;
|
||||
}
|
||||
}
|
||||
|
||||
VBox_VisualDisk::~VBox_VisualDisk()
|
||||
{
|
||||
clear() ;
|
||||
|
||||
//free the allocated colors
|
||||
this ->get_colormap( ) ->free_colors( color_used, 1 ) ;
|
||||
this ->get_colormap( ) ->free_colors( color_unused, 1 ) ;
|
||||
|
|
|
@ -28,7 +28,6 @@ Win_GParted::Win_GParted( )
|
|||
selected_partition .Reset( ) ;
|
||||
new_count = 1;
|
||||
current_device = 0 ;
|
||||
vbox_visual_disk = NULL;
|
||||
pulse = false ;
|
||||
|
||||
//==== GUI =========================
|
||||
|
@ -50,8 +49,9 @@ Win_GParted::Win_GParted( )
|
|||
init_toolbar( ) ;
|
||||
vbox_main.pack_start( hbox_toolbar, Gtk::PACK_SHRINK );
|
||||
|
||||
//hbox_visual... ( contains the visual represenation of the disks )
|
||||
vbox_main.pack_start( hbox_visual, Gtk::PACK_SHRINK );
|
||||
//vbox_visual_disk... ( contains the visual represenation of the disks )
|
||||
vbox_visual_disk .signal_mouse_click.connect( sigc::mem_fun( this, &Win_GParted::mouse_click ) ) ;
|
||||
vbox_main .pack_start( vbox_visual_disk, Gtk::PACK_SHRINK ) ;
|
||||
|
||||
//hpaned_main (NOTE: added to vpaned_main)
|
||||
init_hpaned_main( ) ;
|
||||
|
@ -459,41 +459,45 @@ void Win_GParted::Add_Operation( OperationType operationtype, const Partition &
|
|||
void Win_GParted::Refresh_Visual( )
|
||||
{
|
||||
std::vector<Partition> partitions = devices[ current_device ] .device_partitions ;
|
||||
liststore_operations ->clear( );
|
||||
liststore_operations ->clear();
|
||||
|
||||
//make all operations visible
|
||||
for ( unsigned int t = 0 ; t < operations .size( ); t++ )
|
||||
for ( unsigned int t = 0 ; t < operations .size(); t++ )
|
||||
{
|
||||
if ( operations[ t ] .device .path == devices[ current_device ] .path )
|
||||
operations[ t ] .Apply_Operation_To_Visual( partitions ) ;
|
||||
|
||||
treerow = *( liststore_operations ->append( ) );
|
||||
treerow = *( liststore_operations ->append() );
|
||||
treerow[ treeview_operations_columns .operation_number ] = t +1;
|
||||
treerow[ treeview_operations_columns .operation_description ] = operations[ t ] .str_operation ;
|
||||
switch ( operations[ t ] .operationtype )
|
||||
{
|
||||
case GParted::DELETE : treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::DELETE, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::CREATE : treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::RESIZE_MOVE: treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::CONVERT : treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::COPY : treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::DELETE :
|
||||
treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::DELETE, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::CREATE :
|
||||
treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::RESIZE_MOVE:
|
||||
treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::CONVERT :
|
||||
treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
case GParted::COPY :
|
||||
treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//set new statusbartext
|
||||
statusbar .pop( ) ;
|
||||
if ( operations .size( ) != 1 )
|
||||
statusbar .push( String::ucompose( _("%1 operations pending"), operations .size( ) ) );
|
||||
statusbar .pop() ;
|
||||
if ( operations .size() != 1 )
|
||||
statusbar .push( String::ucompose( _("%1 operations pending"), operations .size() ) );
|
||||
else
|
||||
statusbar .push( _( "1 operation pending" ) );
|
||||
|
||||
if ( ! operations .size( ) )
|
||||
if ( ! operations .size() )
|
||||
{
|
||||
allow_undo( false );
|
||||
allow_apply( false );
|
||||
|
@ -502,7 +506,7 @@ void Win_GParted::Refresh_Visual( )
|
|||
//count primary's, check for extended and logic and see if any logical is busy
|
||||
any_logic = any_extended = false;
|
||||
primary_count = 0;
|
||||
for ( unsigned int t = 0 ; t < partitions .size( ) ; t++ )
|
||||
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
||||
{
|
||||
if ( partitions[ t ] .partition == copied_partition .partition )
|
||||
copied_partition = partitions[ t ] ;
|
||||
|
@ -516,7 +520,7 @@ void Win_GParted::Refresh_Visual( )
|
|||
case GParted::TYPE_EXTENDED :
|
||||
any_extended = true;
|
||||
primary_count++;
|
||||
any_logic = partitions[ t ] .logicals .size( ) -1 ;
|
||||
any_logic = partitions[ t ] .logicals .size() -1 ;
|
||||
break;
|
||||
|
||||
default :
|
||||
|
@ -525,33 +529,24 @@ void Win_GParted::Refresh_Visual( )
|
|||
}
|
||||
|
||||
//vbox visual
|
||||
if ( vbox_visual_disk != NULL )
|
||||
{
|
||||
hbox_visual .remove( *vbox_visual_disk );
|
||||
delete ( vbox_visual_disk );
|
||||
}
|
||||
|
||||
vbox_visual_disk = new VBox_VisualDisk ( partitions, devices[ current_device ] .length ) ;
|
||||
vbox_visual_disk ->signal_mouse_click.connect( sigc::mem_fun( this, &Win_GParted::mouse_click ) ) ;
|
||||
hbox_visual .pack_start( *vbox_visual_disk, Gtk::PACK_EXPAND_PADDING ) ;
|
||||
hbox_visual .show_all_children( ) ;
|
||||
vbox_visual_disk .load_partitions( partitions, devices[ current_device ] .length ) ;
|
||||
|
||||
//treeview details
|
||||
treeview_detail .Load_Partitions( partitions ) ;
|
||||
|
||||
//no partition can be selected after a refresh..
|
||||
selected_partition .Reset( ) ;
|
||||
Set_Valid_Operations( ) ;
|
||||
selected_partition .Reset() ;
|
||||
Set_Valid_Operations() ;
|
||||
}
|
||||
|
||||
bool Win_GParted::Quit_Check_Operations( )
|
||||
{
|
||||
if ( operations .size( ) )
|
||||
if ( operations .size() )
|
||||
{
|
||||
str_temp = "<span weight=\"bold\" size=\"larger\">" + (Glib::ustring) _( "Quit GParted?" ) + "</span>\n\n" ;
|
||||
|
||||
if ( operations .size( ) != 1 )
|
||||
str_temp += String::ucompose( _("%1 operations are currently pending."), operations .size( ) ) ;
|
||||
if ( operations .size() != 1 )
|
||||
str_temp += String::ucompose( _("%1 operations are currently pending."), operations .size() ) ;
|
||||
else
|
||||
str_temp += _("1 operation is currently pending.");
|
||||
|
||||
|
@ -559,7 +554,7 @@ bool Win_GParted::Quit_Check_Operations( )
|
|||
dialog .add_button( Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE );
|
||||
dialog .add_button( Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL );
|
||||
|
||||
if ( dialog .run( ) == Gtk::RESPONSE_CANCEL )
|
||||
if ( dialog .run() == Gtk::RESPONSE_CANCEL )
|
||||
return false;//don't close GParted
|
||||
}
|
||||
|
||||
|
@ -703,20 +698,19 @@ void Win_GParted::menu_gparted_refresh_devices( )
|
|||
pulse = true ;//set to true before creating the thread to prevent _possible_ infinite loop in Show_Pulsebar( )
|
||||
thread = Glib::Thread::create( SigC::slot_class( *this, &Win_GParted::find_devices_thread ), true );
|
||||
|
||||
Show_Pulsebar( ) ;
|
||||
|
||||
Show_Pulsebar() ;
|
||||
//check if current_device is still available (think about hotpluggable shit like usbdevices)
|
||||
if ( current_device >= devices .size( ) )
|
||||
if ( current_device >= devices .size() )
|
||||
current_device = 0 ;
|
||||
|
||||
|
||||
//show read-only warning if necessary
|
||||
Glib::ustring readonly_paths ;
|
||||
|
||||
for ( unsigned int t = 0 ; t < devices .size( ) ; t++ )
|
||||
for ( unsigned int t = 0 ; t < devices .size() ; t++ )
|
||||
if ( devices[ t ] .readonly )
|
||||
readonly_paths += "\n- " + devices[ t ] .path ;
|
||||
|
||||
if ( ! readonly_paths .empty( ) )
|
||||
if ( ! readonly_paths .empty() )
|
||||
{
|
||||
str_temp = "<span weight=\"bold\" size=\"larger\">" ;
|
||||
str_temp += _("The kernel is unable to re-read the partitiontables on the following devices:") ;
|
||||
|
@ -744,32 +738,28 @@ void Win_GParted::menu_gparted_refresh_devices( )
|
|||
}
|
||||
|
||||
//if no devices were detected we disable some stuff and show a message in the statusbar
|
||||
if ( devices .empty( ) )
|
||||
if ( devices .empty() )
|
||||
{
|
||||
optionmenu_devices .hide( ) ;
|
||||
optionmenu_devices .hide() ;
|
||||
|
||||
menubar_main .items( )[ 2 ] .set_sensitive( false ) ;
|
||||
menubar_main .items( )[ 3 ] .set_sensitive( false ) ;
|
||||
menubar_main .items()[ 1 ] .set_sensitive( false ) ;
|
||||
menubar_main .items()[ 2 ] .set_sensitive( false ) ;
|
||||
menubar_main .items()[ 3 ] .set_sensitive( false ) ;
|
||||
menubar_main .items()[ 4 ] .set_sensitive( false ) ;
|
||||
toolbar_main .set_sensitive( false ) ;
|
||||
optionmenu_devices .set_sensitive( false ) ;
|
||||
|
||||
Fill_Label_Device_Info( true ) ;
|
||||
|
||||
if ( vbox_visual_disk != NULL )
|
||||
{
|
||||
hbox_visual .remove( *vbox_visual_disk );
|
||||
delete( vbox_visual_disk ) ;
|
||||
vbox_visual_disk = NULL ;
|
||||
}
|
||||
|
||||
treeview_detail .Clear( ) ;
|
||||
vbox_visual_disk .clear() ;
|
||||
treeview_detail .Clear() ;
|
||||
|
||||
//hmzz, this is really paranoid, but i think it's the right thing to do ;)
|
||||
liststore_operations ->clear( ) ;
|
||||
close_operationslist( ) ;
|
||||
operations .clear( ) ;
|
||||
close_operationslist() ;
|
||||
operations .clear() ;
|
||||
|
||||
statusbar .pop( ) ;
|
||||
statusbar .pop() ;
|
||||
statusbar .push( _( "No devices detected" ) );
|
||||
}
|
||||
|
||||
|
@ -886,7 +876,8 @@ void Win_GParted::mouse_click( GdkEventButton *event, const Partition & partitio
|
|||
Set_Valid_Operations( ) ;
|
||||
|
||||
treeview_detail .Set_Selected( partition );
|
||||
vbox_visual_disk ->Set_Selected( partition );
|
||||
|
||||
vbox_visual_disk .set_selected( partition ) ;
|
||||
|
||||
if ( event ->type == GDK_2BUTTON_PRESS && ! pulse )
|
||||
activate_info( ) ;
|
||||
|
|
Loading…
Reference in New Issue