Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=08f0861440ce84b44019c35974889f62345f7d55
commit 08f0861440ce84b44019c35974889f62345f7d55 Author: James Buren <[email protected]> Date: Tue Aug 28 01:48:25 2012 -0500 import initial draft of PartitionModule diff --git a/PartitionModule.cc b/PartitionModule.cc new file mode 100644 index 0000000..6bce8b9 --- /dev/null +++ b/PartitionModule.cc @@ -0,0 +1,147 @@ +#include "Utility.hh" +#include "UserInterface.hh" +#include "Device.hh" +#include "PartitionModule.hh" + +#ifdef NEWT +#include <newt.h> +#include <stdlib.h> +#include <sstream> + +using std::stringstream; + +class Item +{ + +public: + Item() { device = 0, partition = 0, space = false; } + ~Item() { } + static bool getItems(vector <Device *> &devices,vector <Item *> &items,newtComponent &listbox); + string text; + Device *device; + Partition *partition; + bool space; + +}; + +// FIXME: this function makes assumptions about text alignment padding. +static string formatPartitionText(Device *device,Partition *part) +{ + stringstream buf; + + buf << " "; + buf << "Partition"; + buf << " "; + buf.width(3); + buf << part->getNumber(); + buf.width(0); + buf << ": "; + buf.width(8); + buf << part->getPurpose(); + buf.width(0); + buf << " type ("; + buf << device->sectorsToSizeString(part->getSectors()); + buf << ")"; + + return buf.str(); +} + +bool Item::getItems(vector <Device *> &devices,vector <Item *> &items,newtComponent &listbox) +{ + devices = Device::probeAll(); + + if(devices.empty()) + return false; + + for( size_t i = 0 ; i < devices.size() ; ++i ) + { + Device *device = devices.at(i); + + if(device->isDisk()) + { + Item *item = new Item(); + + item->text = device->getPath() + ": " + device->getLabelType() + " label (" + device->getSizeString() + ")"; + + item->device = device; + + items.push_back(item); + + if(device->getLabelType() != "unknown") + { + for( size_t j = 0 ; j < device->getTableSize() ; ++j ) + { + Partition *part = device->getPartition(j); + + item = new Item(); + + item->text = formatPartitionText(device,part); + + item->partition = part; + + items.push_back(item); + } + + if(device->getUnusedSizeString() != "0.0BiB") + { + item = new Item(); + + item->text = " Free Space (" + device->getUnusedSizeString() + ")"; + + item->space = true; + + items.push_back(item); + } + } + + item = new Item(); + + items.push_back(item); + } + } + + if(items.empty()) + return false; + + return true; +} +#endif + +PartitionModule::PartitionModule() +{ +} + +PartitionModule::~PartitionModule() +{ +} + +int PartitionModule::run() +{ + const char *title = "Partition Setup"; + +#ifdef NEWT + vector <Item *> items; + vector <Device *> devices; + newtComponent i; + + if(!Item::getItems(devices,items,i)) + return 0; + + for( size_t n = 0 ; n < items.size() ; ++n ) + { + Item *item = items[n]; + + printf("%s\n",item->text.c_str()); + } + +#endif + + return 1; +} + +string PartitionModule::getName() +{ + return __FILE__; +} + +PartitionModule partition_module; diff --git a/PartitionModule.hh b/PartitionModule.hh new file mode 100644 index 0000000..c9e0f6a --- /dev/null +++ b/PartitionModule.hh @@ -0,0 +1,16 @@ +#pragma once + +#include "Module.hh" + +class PartitionModule : public Module +{ + +public: + PartitionModule(); + virtual ~PartitionModule(); + virtual int run(); + virtual string getName(); + +}; + +extern PartitionModule partition_module; \ No newline at end of file diff --git a/SConstruct b/SConstruct index 9d2ed73..22f524f 100644 --- a/SConstruct +++ b/SConstruct @@ -42,5 +42,6 @@ env.Program('fwsetup',[ 'DosPartitionTable.cc', 'Device.cc', 'UserInterface.cc', - 'Utility.cc' + 'Utility.cc', + 'PartitionModule.cc' ]) _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
