Add reading informations about disks and partitions from libparted.new_installer
parent
11ce97387a
commit
c7004b3c59
@ -1,68 +1,90 @@
|
|||||||
project(qtermwidget)
|
###| CMAKE qtermwidget/lib |###
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
#| 2.6 is out, but most distros only have 2.4
|
||||||
|
cmake_minimum_required ( VERSION 2.6 )
|
||||||
|
|
||||||
set(QT_MIN_VERSION 4.6.0)
|
if(COMMAND cmake_policy)
|
||||||
|
cmake_policy (SET CMP0003 NEW)
|
||||||
|
endif(COMMAND cmake_policy)
|
||||||
|
|
||||||
find_package(Qt4 REQUIRED)
|
#| Project
|
||||||
|
project ( qtermwidget )
|
||||||
|
|
||||||
include(${QT_USE_FILE})
|
#| Sources
|
||||||
|
set ( SRCS
|
||||||
include_directories(
|
TerminalCharacterDecoder.cpp
|
||||||
${QT_INCLUDES}
|
KeyboardTranslator.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
Screen.cpp History.cpp BlockArray.cpp konsole_wcwidth.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
ScreenWindow.cpp
|
||||||
.
|
Emulation.cpp
|
||||||
|
Vt102Emulation.cpp TerminalDisplay.cpp Filter.cpp
|
||||||
|
Pty.cpp kpty.cpp k3process.cpp k3processcontroller.cpp
|
||||||
|
Session.cpp ShellCommand.cpp
|
||||||
|
qtermwidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
link_directories(
|
#| Headers
|
||||||
.
|
#| Only the Headers that need to be moc'd go here
|
||||||
|
set ( HDRS
|
||||||
|
ScreenWindow.h
|
||||||
|
Emulation.h
|
||||||
|
Vt102Emulation.h TerminalDisplay.h Filter.h
|
||||||
|
Pty.h k3process.h k3processcontroller.h
|
||||||
|
Session.h
|
||||||
|
qtermwidget.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set( qtermwidget_SRCS
|
#| Library Output
|
||||||
qtermwidget.cpp
|
#| CMake supports out-of-source builds, so the binary dir is not
|
||||||
BlockArray.cpp
|
#| necessarily the same as the source directory
|
||||||
Emulation.cpp
|
set ( LIBRARY_OUTPUT_PATH
|
||||||
Filter.cpp
|
${PROJECT_SOURCE_DIR}/../.
|
||||||
History.cpp
|
|
||||||
k3processcontroller.cpp
|
|
||||||
k3process.cpp
|
|
||||||
KeyboardTranslator.cpp
|
|
||||||
konsole_wcwidth.cpp
|
|
||||||
kpty.cpp
|
|
||||||
Pty.cpp
|
|
||||||
Screen.cpp
|
|
||||||
ScreenWindow.cpp
|
|
||||||
Session.cpp
|
|
||||||
ShellCommand.cpp
|
|
||||||
TerminalCharacterDecoder.cpp
|
|
||||||
TerminalDisplay.cpp
|
|
||||||
Vt102Emulation.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set( qtermwidget_HDRS
|
#| Library Versioning
|
||||||
qtermwidget.h
|
#| Libraries are not versioned by default
|
||||||
Emulation.h
|
set ( qtermwidget_VERSION_MAJOR "0" )
|
||||||
Filter.h
|
set ( qtermwidget_VERSION_MINOR "1" )
|
||||||
k3processcontroller.h
|
set ( qtermwidget_VERSION_PATCH "0" )
|
||||||
k3process.h
|
set ( qtermwidget_VERSION
|
||||||
Pty.h
|
"${qtermwidget_VERSION_MAJOR}.${qtermwidget_VERSION_MINOR}.${qtermwidget_VERSION_PATCH}"
|
||||||
ScreenWindow.h
|
|
||||||
Session.h
|
|
||||||
TerminalDisplay.h
|
|
||||||
Vt102Emulation.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions( -DQT_GUI_LIB -DQT_CORE_LIB -DHAVE_POSIX_OPENPT )
|
#| Qt4 Required Options
|
||||||
|
add_definitions ( -Wall )
|
||||||
|
find_package ( Qt4 REQUIRED ) # Finds Qt4 on the system
|
||||||
|
include ( ${QT_USE_FILE} ) # Includes Qt4 headers and libraries (the above command is needed first)
|
||||||
|
QT4_WRAP_CPP ( MOC_SRCS ${HDRS} ) # Moc's the headers
|
||||||
|
#include ( ${CMAKE_BINARY_DIR} ) # For including the heades generated by ui files
|
||||||
|
|
||||||
|
#| qtermwidget specific
|
||||||
|
include_directories ( ${PROJECT_SOURCE_DIR} ) # You mark some of the headers as global, so I just add the source directory to the includes
|
||||||
|
|
||||||
|
#| Defines
|
||||||
|
add_definitions ( -DHAVE_POSIX_OPENPT )
|
||||||
|
#add_definitions( -DHAVE_GETPT )
|
||||||
|
|
||||||
qt4_wrap_cpp( qtermwidget_MOC_SRCS
|
#| Create the Library
|
||||||
${qtermwidget_HDRS}
|
add_library( qtermwidget STATIC ${SRCS} ${MOC_SRCS} )
|
||||||
|
#add_library ( qtermwidget SHARED ${SRCS} ${MOC_SRCS} )
|
||||||
|
|
||||||
|
#| Set Build Type
|
||||||
|
set ( CMAKE_BUILD_TYPE
|
||||||
|
#"release"
|
||||||
|
"relwithdebinfo" # Default
|
||||||
|
#"debug"
|
||||||
|
#"debugfull"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library (qtermwidget STATIC
|
#| Library Properties
|
||||||
${qtermwidget_SRCS}
|
set_target_properties ( qtermwidget PROPERTIES
|
||||||
${qtermwidget_MOC_SRCS}
|
#OUTPUT_NAME "alternateName"
|
||||||
${QT_QTCORE_LIBRARY}
|
#PREFIX "lib"
|
||||||
${QT_QTGUI_LIBRARY}
|
SOVERSION ${qtermwidget_VERSION_MAJOR}
|
||||||
|
#SUFFIX "so"
|
||||||
|
VERSION ${qtermwidget_VERSION}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#| Link Qt4 Libraries
|
||||||
|
target_link_libraries ( qtermwidget ${QT_LIBRARIES} )
|
||||||
|
|
||||||
|
@ -0,0 +1,141 @@
|
|||||||
|
#include "libparted.h"
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
LibParted::LibParted(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
// ped_exception_set_handler( )
|
||||||
|
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
LibParted::~LibParted()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LibParted::getVersion()
|
||||||
|
{
|
||||||
|
return QString( ped_get_version() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibParted::Init()
|
||||||
|
{
|
||||||
|
ped_device_probe_all();
|
||||||
|
|
||||||
|
PedDevice* dsk = NULL;
|
||||||
|
|
||||||
|
while ( (dsk = ped_device_get_next(dsk)) != NULL )
|
||||||
|
{
|
||||||
|
m_DeviceList[ QString(dsk->path) ] = dsk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList LibParted::getDevices()
|
||||||
|
{
|
||||||
|
QStringList res;
|
||||||
|
|
||||||
|
Devices::const_iterator i = m_DeviceList.begin();
|
||||||
|
while ( i != m_DeviceList.constEnd() )
|
||||||
|
{
|
||||||
|
res << i.key();
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceInfo LibParted::getDeviceInfo(const QString& path) throw(LibPartedError)
|
||||||
|
{
|
||||||
|
if ( m_DeviceList.find(path) == m_DeviceList.end() )
|
||||||
|
throw LibPartedError();
|
||||||
|
|
||||||
|
return convertPedDevice(m_DeviceList[path]);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<PartitionInfo> LibParted::getPartitionList(const QString& path) throw(LibPartedError)
|
||||||
|
{
|
||||||
|
QList<PartitionInfo> PartInfo;
|
||||||
|
|
||||||
|
if ( m_DeviceList.find(path) == m_DeviceList.end() )
|
||||||
|
throw LibPartedError();
|
||||||
|
|
||||||
|
PedDevice* dev = m_DeviceList[path];
|
||||||
|
|
||||||
|
PedDisk* disk = NULL;
|
||||||
|
disk = ped_disk_new( dev );
|
||||||
|
if (!disk)
|
||||||
|
throw LibPartedError();
|
||||||
|
|
||||||
|
bool has_extended = ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED);
|
||||||
|
bool has_name = ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_PARTITION_NAME);
|
||||||
|
|
||||||
|
PedPartition* part = NULL;
|
||||||
|
|
||||||
|
while ( part = ped_disk_next_partition (disk, part) )
|
||||||
|
{
|
||||||
|
PartitionInfo part_inf;
|
||||||
|
|
||||||
|
if (part->type & PED_PARTITION_METADATA)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( part->num >= 0)
|
||||||
|
part_inf.num = part->num;
|
||||||
|
|
||||||
|
part_inf.begin = part->geom.start;
|
||||||
|
part_inf.end = (part->geom.end + 1) * dev->sector_size - 1;
|
||||||
|
part_inf.size = part->geom.length;
|
||||||
|
|
||||||
|
if (!(part->type & PED_PARTITION_FREESPACE))
|
||||||
|
{
|
||||||
|
if (has_extended)
|
||||||
|
{
|
||||||
|
char* type = const_cast<char*>( ped_partition_type_get_name(part->type) );
|
||||||
|
part_inf.type = QString(type);
|
||||||
|
//free(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
part_inf.fs = part->fs_type ? QString(part->fs_type->name) : "";
|
||||||
|
|
||||||
|
if (has_name)
|
||||||
|
{
|
||||||
|
char* name = const_cast<char*>( ped_partition_get_name(part) );
|
||||||
|
part_inf.name = QString(name);
|
||||||
|
}
|
||||||
|
//part_inf. = QString(name);
|
||||||
|
//free(name);
|
||||||
|
|
||||||
|
//char *flags = const_cast<char*>( partition_print_flags(part) );
|
||||||
|
//Flags = QString(flags);
|
||||||
|
//free(flags);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
part_inf.type = "Free space";
|
||||||
|
}
|
||||||
|
|
||||||
|
PartInfo << part_inf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PartInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceInfo LibParted::convertPedDevice(const PedDevice* dev)
|
||||||
|
{
|
||||||
|
DeviceInfo part_dev;
|
||||||
|
|
||||||
|
const char *const transport[] = {"unknown", "scsi", "ide", "dac960",
|
||||||
|
"cpqarray", "file", "ataraid", "i2o",
|
||||||
|
"ubd", "dasd", "viodasd", "sx8", "dm",
|
||||||
|
"xvd", "sd/mmc", "virtblk"};
|
||||||
|
|
||||||
|
part_dev.model = QString(dev->model);
|
||||||
|
part_dev.transport = QString("%1").arg(transport[dev->type]);
|
||||||
|
|
||||||
|
part_dev.size = dev->length * dev->sector_size;
|
||||||
|
part_dev.sec_ph = dev->phys_sector_size;
|
||||||
|
part_dev.sec_log = dev->sector_size;
|
||||||
|
|
||||||
|
return part_dev;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
#include <parted/parted.h>
|
||||||
|
|
||||||
|
class DeviceInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString model;
|
||||||
|
QString transport;
|
||||||
|
long size;
|
||||||
|
long sec_ph;
|
||||||
|
long sec_log;
|
||||||
|
DeviceInfo(): size(0), sec_ph(0), sec_log(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PartitionInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int num;
|
||||||
|
long begin;
|
||||||
|
long end;
|
||||||
|
long size;
|
||||||
|
QString type;
|
||||||
|
QString fs;
|
||||||
|
QString name;
|
||||||
|
long flags;
|
||||||
|
PartitionInfo(): num(0), begin(0), end(0), size(0), flags(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QMap<int, PedPartition*> Partitions;
|
||||||
|
typedef QMap<QString, PedDevice*> Devices;
|
||||||
|
|
||||||
|
class LibPartedError
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LibPartedError() {}
|
||||||
|
virtual ~LibPartedError() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class LibParted : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LibParted(QObject *parent = 0);
|
||||||
|
~LibParted();
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString getVersion();
|
||||||
|
void Init();
|
||||||
|
QStringList getDevices();
|
||||||
|
DeviceInfo getDeviceInfo(const QString& path) throw(LibPartedError);
|
||||||
|
QList<PartitionInfo> getPartitionList(const QString& path) throw(LibPartedError);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceInfo convertPedDevice(const PedDevice* dev);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Devices m_DeviceList;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in new issue