2004-10-06 09:32:40 -06:00
|
|
|
/* Copyright (C) 2004 Bart
|
|
|
|
*
|
|
|
|
* 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* UTILS
|
|
|
|
* Some stuff i need in a lot of places so i dropped in all together in one file.
|
|
|
|
* If you think this approach sucks, dont tell me, i know =)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTILS
|
|
|
|
#define UTILS
|
|
|
|
|
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef long long Sector;
|
|
|
|
|
|
|
|
#define MEGABYTE 2048 //try it: 2048 * 512 / 1024 /1024 == 1 :P
|
|
|
|
|
|
|
|
|
|
|
|
//struct to store filesystems
|
|
|
|
struct FS
|
|
|
|
{
|
|
|
|
Glib::ustring filesystem ;
|
2004-11-21 14:49:38 -07:00
|
|
|
bool read ; //can we get the amount of used sectors?
|
2004-11-17 06:00:25 -07:00
|
|
|
bool create ;
|
2004-12-13 06:58:51 -07:00
|
|
|
bool grow ;
|
|
|
|
bool shrink ;
|
2004-11-17 06:00:25 -07:00
|
|
|
bool move ; //startpoint and endpoint
|
2004-11-21 14:49:38 -07:00
|
|
|
bool check ; //some checktool available?
|
|
|
|
bool copy ;
|
2004-12-09 15:56:33 -07:00
|
|
|
int MIN ;
|
|
|
|
int MAX ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2004-12-09 15:56:33 -07:00
|
|
|
FS( )
|
|
|
|
{
|
2004-12-13 06:58:51 -07:00
|
|
|
read = create = grow = shrink = move = check = copy = false ;
|
2004-12-10 13:42:23 -07:00
|
|
|
MIN = 0 ;
|
2004-12-09 15:56:33 -07:00
|
|
|
MAX = 0 ;
|
|
|
|
}
|
2004-10-06 09:32:40 -06:00
|
|
|
};
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
|
|
|
|
//globally used convenience functions
|
|
|
|
inline long Sector_To_MB( Sector sectors )
|
|
|
|
{
|
|
|
|
return (long) ( (double) sectors * 512/1024/1024 +0.5) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline long Round( double double_value )
|
|
|
|
{
|
|
|
|
return (long) ( double_value + 0.5) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Sector Abs( Sector sectors )
|
|
|
|
{
|
|
|
|
return sectors < 0 ? sectors - 2*sectors : sectors ;
|
|
|
|
}
|
|
|
|
|
2004-10-07 08:12:34 -06:00
|
|
|
inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false, const Glib::ustring & text_color = "black" )
|
2004-10-06 09:32:40 -06:00
|
|
|
{
|
2004-10-06 13:06:43 -06:00
|
|
|
Gtk::Label * label = manage( new Gtk::Label( text ) ) ;
|
|
|
|
|
|
|
|
label ->set_use_markup( use_markup ) ;
|
|
|
|
|
|
|
|
if ( align_left )
|
|
|
|
label ->set_alignment( Gtk::ALIGN_LEFT ) ;
|
|
|
|
|
|
|
|
label ->set_line_wrap( wrap ) ;
|
|
|
|
|
2004-10-07 08:12:34 -06:00
|
|
|
if ( text_color != "black" )
|
|
|
|
{
|
|
|
|
Gdk::Color color( text_color ) ;
|
|
|
|
label ->modify_fg( label ->get_state(), color ) ;
|
|
|
|
}
|
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
return label ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Glib::ustring num_to_str( Sector number )
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os .imbue( std::locale("") );
|
|
|
|
os << number ;
|
|
|
|
return os .str() ;
|
|
|
|
}
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
inline FS Get_FS( const Glib::ustring & filesystem, const std::vector<FS> & FILESYSTEMS )
|
2004-10-06 09:32:40 -06:00
|
|
|
{
|
2004-11-17 06:00:25 -07:00
|
|
|
unsigned int t = 0 ;
|
|
|
|
|
|
|
|
for ( t = 0 ; t < FILESYSTEMS .size( ) ; t++ )
|
|
|
|
if ( FILESYSTEMS[ t ] .filesystem == filesystem )
|
2004-11-22 13:40:19 -07:00
|
|
|
return FILESYSTEMS[ t ] ;
|
2004-10-06 09:32:40 -06:00
|
|
|
|
2004-11-22 13:40:19 -07:00
|
|
|
return FILESYSTEMS .back( ) ;
|
2004-10-06 09:32:40 -06:00
|
|
|
}
|
|
|
|
|
2004-12-13 14:24:12 -07:00
|
|
|
//use http://developer.gnome.org/projects/gup/hig/2.0/design.html#Palette as a starting point..
|
2004-10-30 16:17:20 -06:00
|
|
|
inline Glib::ustring Get_Color( const Glib::ustring & filesystem )
|
|
|
|
{
|
|
|
|
//blue teints
|
|
|
|
if ( filesystem == "ext2" ) return "#9DB8D2" ;
|
|
|
|
else if ( filesystem == "ext3" ) return "#7590AE" ;
|
|
|
|
|
|
|
|
//redbrown
|
|
|
|
else if ( filesystem == "linux-swap" ) return "#C1665A" ;
|
|
|
|
|
|
|
|
//greenisch stuff..
|
|
|
|
else if ( filesystem == "fat16" ) return "green" ;
|
|
|
|
else if ( filesystem == "fat32" ) return "#18D918" ;
|
|
|
|
else if ( filesystem == "ntfs" ) return "#42E5AC" ;
|
|
|
|
|
|
|
|
//purple something..
|
|
|
|
else if ( filesystem == "reiserfs" ) return "#ADA7C8" ;
|
2004-12-13 14:24:12 -07:00
|
|
|
|
|
|
|
else if ( filesystem == "xfs" ) return "#EED680" ;
|
|
|
|
|
2004-10-30 16:17:20 -06:00
|
|
|
//libparted can only detect these, i decided to "yellow them" :^)
|
|
|
|
else if ( filesystem == "HFS" ) return "yellow" ;
|
|
|
|
else if ( filesystem == "JFS" ) return "yellow" ;
|
|
|
|
else if ( filesystem == "UFS" ) return "yellow" ;
|
2004-12-13 14:24:12 -07:00
|
|
|
|
2004-10-30 16:17:20 -06:00
|
|
|
//darkgrey and ligthblue
|
2004-11-24 08:05:36 -07:00
|
|
|
else if ( filesystem == "---" ) return "darkgrey";
|
2004-10-30 16:17:20 -06:00
|
|
|
else if ( filesystem == "extended" ) return "#7DFCFE" ;
|
|
|
|
|
2004-12-13 14:24:12 -07:00
|
|
|
//unknown filesystem ( damaged, unknown or simply no filesystem )
|
2004-10-30 16:17:20 -06:00
|
|
|
else return "black";
|
|
|
|
}
|
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
|
|
|
|
}//GParted
|
|
|
|
|
|
|
|
#endif //UTILS
|