2009-11-05 18:08:32 +00:00
|
|
|
/* Copyright (C) 2004 Bart
|
2010-01-02 22:04:30 +00:00
|
|
|
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
|
2004-10-06 15:32:40 +00: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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTILS
|
|
|
|
#define UTILS
|
|
|
|
|
2005-12-07 11:21:27 +00:00
|
|
|
#include "../include/i18n.h"
|
|
|
|
|
2004-10-06 15:32:40 +00:00
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
|
2005-12-13 21:30:13 +00:00
|
|
|
#include <iostream>
|
2008-04-07 15:26:19 +00:00
|
|
|
#include <ctime>
|
2009-03-12 19:37:12 +00:00
|
|
|
#include <vector>
|
2004-10-06 15:32:40 +00:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef long long Sector;
|
2010-03-16 16:18:04 +00:00
|
|
|
typedef long long Byte_Value;
|
2004-10-06 15:32:40 +00:00
|
|
|
|
2010-03-16 16:18:04 +00:00
|
|
|
//Size units defined in bytes
|
2010-04-26 19:40:38 +00:00
|
|
|
const Byte_Value KIBIBYTE=1024;
|
|
|
|
const Byte_Value MEBIBYTE=(KIBIBYTE * KIBIBYTE);
|
|
|
|
const Byte_Value GIBIBYTE=(MEBIBYTE * KIBIBYTE);
|
|
|
|
const Byte_Value TEBIBYTE=(GIBIBYTE * KIBIBYTE);
|
2010-03-16 16:18:04 +00:00
|
|
|
|
2005-12-07 11:21:27 +00:00
|
|
|
enum FILESYSTEM
|
|
|
|
{
|
|
|
|
FS_UNALLOCATED = 0,
|
|
|
|
FS_UNKNOWN = 1,
|
|
|
|
FS_UNFORMATTED = 2,
|
|
|
|
FS_EXTENDED = 3,
|
2005-12-15 15:10:34 +00:00
|
|
|
|
2005-12-07 11:21:27 +00:00
|
|
|
FS_EXT2 = 4,
|
|
|
|
FS_EXT3 = 5,
|
2008-12-18 22:13:43 +00:00
|
|
|
FS_EXT4 = 6,
|
|
|
|
FS_LINUX_SWAP = 7,
|
|
|
|
FS_FAT16 = 8,
|
|
|
|
FS_FAT32 = 9,
|
|
|
|
FS_NTFS = 10,
|
|
|
|
FS_REISERFS = 11,
|
|
|
|
FS_REISER4 = 12,
|
|
|
|
FS_XFS = 13,
|
|
|
|
FS_JFS = 14,
|
|
|
|
FS_HFS = 15,
|
|
|
|
FS_HFSPLUS = 16,
|
|
|
|
FS_UFS = 17,
|
2005-12-15 15:10:34 +00:00
|
|
|
|
2008-12-18 22:13:43 +00:00
|
|
|
FS_USED = 18,
|
|
|
|
FS_UNUSED = 19,
|
2008-12-07 18:43:35 +00:00
|
|
|
|
2009-02-23 20:22:30 +00:00
|
|
|
FS_BTRFS = 20, /* FIXME: Move this higher up list when full support added */
|
|
|
|
FS_LVM2 = 21,
|
|
|
|
FS_LUKS = 22
|
2006-03-31 10:49:27 +00:00
|
|
|
} ;
|
2004-10-06 15:32:40 +00:00
|
|
|
|
2006-01-22 00:07:27 +00:00
|
|
|
enum SIZE_UNIT
|
|
|
|
{
|
|
|
|
UNIT_SECTOR = 0,
|
|
|
|
UNIT_BYTE = 1,
|
|
|
|
|
|
|
|
UNIT_KIB = 2,
|
|
|
|
UNIT_MIB = 3,
|
|
|
|
UNIT_GIB = 4,
|
2006-03-31 10:49:27 +00:00
|
|
|
UNIT_TIB = 5
|
|
|
|
} ;
|
2006-01-22 00:07:27 +00:00
|
|
|
|
2008-11-18 23:58:17 +00:00
|
|
|
//struct to store file system information
|
2004-10-06 15:32:40 +00:00
|
|
|
struct FS
|
|
|
|
{
|
2005-11-27 00:57:11 +00:00
|
|
|
enum Support
|
|
|
|
{
|
|
|
|
NONE = 0,
|
2006-05-23 21:17:34 +00:00
|
|
|
GPARTED = 1,
|
|
|
|
LIBPARTED = 2,
|
|
|
|
EXTERNAL = 3
|
2005-11-27 00:57:11 +00:00
|
|
|
};
|
|
|
|
|
2005-12-07 11:21:27 +00:00
|
|
|
FILESYSTEM filesystem ;
|
2005-11-27 00:57:11 +00:00
|
|
|
Support read ; //can we get the amount of used sectors?
|
2008-11-08 23:55:17 +00:00
|
|
|
Support read_label ;
|
|
|
|
Support write_label ;
|
2005-11-27 00:57:11 +00:00
|
|
|
Support create ;
|
|
|
|
Support grow ;
|
|
|
|
Support shrink ;
|
|
|
|
Support move ; //startpoint and endpoint
|
|
|
|
Support check ; //some checktool available?
|
|
|
|
Support copy ;
|
2006-02-17 21:18:07 +00:00
|
|
|
|
2010-03-16 17:24:08 +00:00
|
|
|
Byte_Value MIN ;
|
2010-03-16 19:25:58 +00:00
|
|
|
Byte_Value MAX ;
|
2004-11-17 13:00:25 +00:00
|
|
|
|
2006-01-22 00:07:27 +00:00
|
|
|
FS()
|
2004-12-09 22:56:33 +00:00
|
|
|
{
|
2008-11-08 23:55:17 +00:00
|
|
|
read = read_label = write_label = create = grow = shrink = move = check = copy = NONE;
|
2005-08-31 02:30:25 +00:00
|
|
|
MIN = MAX = 0 ;
|
2004-12-09 22:56:33 +00:00
|
|
|
}
|
2006-03-31 10:49:27 +00:00
|
|
|
} ;
|
2004-11-17 13:00:25 +00:00
|
|
|
|
2004-10-06 15:32:40 +00:00
|
|
|
|
2005-12-13 21:30:13 +00:00
|
|
|
class Utils
|
2004-10-06 15:32:40 +00:00
|
|
|
{
|
2005-12-13 21:30:13 +00:00
|
|
|
public:
|
2006-03-28 12:40:29 +00:00
|
|
|
static Sector round( double double_value ) ;
|
2005-12-14 14:47:58 +00:00
|
|
|
static Gtk::Label * mk_label( const Glib::ustring & text,
|
|
|
|
bool use_markup = true,
|
2006-03-28 12:40:29 +00:00
|
|
|
Gtk::AlignmentEnum x_align = Gtk::ALIGN_LEFT,
|
|
|
|
Gtk::AlignmentEnum y_align = Gtk::ALIGN_CENTER,
|
2005-12-14 14:47:58 +00:00
|
|
|
bool wrap = false,
|
2008-12-03 18:18:04 +00:00
|
|
|
bool selectable = false,
|
2005-12-14 14:47:58 +00:00
|
|
|
const Glib::ustring & text_color = "black" ) ;
|
2010-01-02 22:04:30 +00:00
|
|
|
static Glib::ustring num_to_str( Sector number ) ;
|
2006-03-28 12:40:29 +00:00
|
|
|
static Glib::ustring get_color( FILESYSTEM filesystem ) ;
|
2005-12-15 15:10:34 +00:00
|
|
|
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ;
|
2006-03-28 12:40:29 +00:00
|
|
|
static Glib::ustring get_filesystem_string( FILESYSTEM filesystem ) ;
|
2008-11-14 19:45:14 +00:00
|
|
|
static Glib::ustring get_filesystem_software( FILESYSTEM filesystem ) ;
|
2010-03-23 19:06:26 +00:00
|
|
|
static Glib::ustring format_size( Sector sectors, Byte_Value sector_size ) ;
|
2006-08-22 19:29:59 +00:00
|
|
|
static Glib::ustring format_time( std::time_t seconds ) ;
|
2010-03-23 18:14:53 +00:00
|
|
|
static double sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT size_unit ) ;
|
2006-04-02 13:04:24 +00:00
|
|
|
static int execute_command( const Glib::ustring & command ) ;
|
2006-02-15 16:05:26 +00:00
|
|
|
static int execute_command( const Glib::ustring & command,
|
|
|
|
Glib::ustring & output,
|
|
|
|
Glib::ustring & error,
|
|
|
|
bool use_C_locale = false ) ;
|
2008-04-07 19:41:18 +00:00
|
|
|
static Glib::ustring regexp_label( const Glib::ustring & text,
|
|
|
|
const Glib::ustring & regular_sub_expression ) ;
|
2008-11-11 00:14:57 +00:00
|
|
|
static Glib::ustring fat_compliant_label( const Glib::ustring & label ) ;
|
2008-04-07 19:41:18 +00:00
|
|
|
static Glib::ustring create_mtoolsrc_file( char file_name[],
|
|
|
|
const char drive_letter, const Glib::ustring & device_path ) ;
|
|
|
|
static Glib::ustring delete_mtoolsrc_file( const char file_name[] ) ;
|
|
|
|
static Glib::ustring trim( const Glib::ustring & src, const Glib::ustring & c = " \t\r\n" ) ;
|
2008-09-04 16:36:14 +00:00
|
|
|
static Glib::ustring cleanup_cursor( const Glib::ustring & text ) ;
|
2008-10-16 19:58:14 +00:00
|
|
|
static Glib::ustring get_lang() ;
|
2009-03-12 19:37:12 +00:00
|
|
|
static void tokenize( const Glib::ustring& str,
|
|
|
|
std::vector<Glib::ustring>& tokens,
|
|
|
|
const Glib::ustring& delimiters ) ;
|
2011-01-28 18:09:21 +00:00
|
|
|
static int convert_to_int(const Glib::ustring & src);
|
2005-12-13 21:30:13 +00:00
|
|
|
};
|
2008-09-04 16:36:14 +00:00
|
|
|
|
2004-10-06 15:32:40 +00:00
|
|
|
|
|
|
|
}//GParted
|
|
|
|
|
|
|
|
#endif //UTILS
|