* extract a Support.cpp/h with utility functions

* fix the problem with duplicated parent partition entries, we need to recurse
  into child rows when findig a particular BRow, or else RowAt() or CountRows()
  will only return the top level list entries
* disabled the bitmap column for now, to get a better overview of "level"
* display the device path also for partitions, not just devices


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22889 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-11-10 23:48:53 +00:00
parent c98d35dc33
commit 0be6cbd37d
6 changed files with 118 additions and 74 deletions
+1
View File
@@ -10,6 +10,7 @@ Preference DriveSetup :
DriveSetup.cpp
MainWindow.cpp
PartitionList.cpp
Support.cpp
:
be
;
+1 -52
View File
@@ -9,6 +9,7 @@
*/
#include "MainWindow.h"
#include "PartitionList.h"
#include "Support.h"
#include <Application.h>
@@ -37,58 +38,6 @@ private:
PartitionListView* fPartitionList;
};
const char*
SizeAsString(off_t size, char *string)
{
double kb = size / 1024.0;
if (kb < 1.0) {
sprintf(string, "%Ld B", size);
return string;
}
float mb = kb / 1024.0;
if (mb < 1.0) {
sprintf(string, "%3.1f KB", kb);
return string;
}
float gb = mb / 1024.0;
if (gb < 1.0) {
sprintf(string, "%3.1f MB", mb);
return string;
}
float tb = gb / 1024.0;
if (tb < 1.0) {
sprintf(string, "%3.1f GB", gb);
return string;
}
sprintf(string, "%.1f TB", tb);
return string;
}
static void
dump_partition_info(BPartition* partition)
{
char size[1024];
printf("\tOffset(): %Ld\n", partition->Offset());
printf("\tSize(): %s\n", SizeAsString(partition->Size(),size));
printf("\tContentSize(): %s\n", SizeAsString(partition->ContentSize(), size));
printf("\tBlockSize(): %ld\n", partition->BlockSize());
printf("\tIndex(): %ld\n", partition->Index());
printf("\tStatus(): %ld\n\n", partition->Status());
printf("\tContainsFileSystem(): %s\n", partition->ContainsFileSystem() ? "true" : "false");
printf("\tContainsPartitioningSystem(): %s\n\n", partition->ContainsPartitioningSystem() ? "true" : "false");
printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %lx\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name());
printf("\tContentName(): %s\n", partition->ContentName());
printf("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %lx\n\n", partition->ID());
}
enum {
MSG_MOUNT_ALL = 'mnta',
+23 -20
View File
@@ -6,15 +6,12 @@
* Ithamar R. Adema <[email protected]>
*/
#include "PartitionList.h"
#include "Support.h"
#include <ColumnTypes.h>
#include <Path.h>
extern const char*
SizeAsString(off_t size, char* string); //FIXME: from MainWindow.cpp
PartitionListRow::PartitionListRow(BPartition* partition)
: Inherited()
, fPartitionID(partition->ID())
@@ -24,12 +21,12 @@ PartitionListRow::PartitionListRow(BPartition* partition)
partition->GetPath(&path);
SetField(new BBitmapField(NULL), 0);
// SetField(new BBitmapField(NULL), 0);
if (partition->IsDevice()) // Only show device path for actual devices (so only for /dev/disk/..../raw entries)
// if (partition->IsDevice()) // Only show device path for actual devices (so only for /dev/disk/..../raw entries)
SetField(new BStringField(path.Path()), 1);
else
SetField(new BStringField(""), 1);
// else
// SetField(new BStringField("n/a"), 1);
// if (partition->ContainsPartitioningSystem()) {
// SetField(new BStringField(partition->ContentType()), 2);
@@ -51,14 +48,14 @@ PartitionListRow::PartitionListRow(BPartition* partition)
SetField(new BStringField(""), 4);
}
SetField(new BStringField(SizeAsString(partition->Size(), size)), 5);
SetField(new BStringField(string_for_size(partition->Size(), size)), 5);
}
PartitionListView::PartitionListView(const BRect& frame)
: Inherited(frame, "storagelist", B_FOLLOW_ALL, 0, B_NO_BORDER, true)
{
AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), 0);
// AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), 0);
AddColumn(new BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
@@ -68,12 +65,18 @@ PartitionListView::PartitionListView(const BRect& frame)
PartitionListRow*
PartitionListView::FindRow(partition_id id)
PartitionListView::FindRow(partition_id id, PartitionListRow* parent)
{
for (int32 i = 0; i < CountRows(); i++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(i));
for (int32 i = 0; i < CountRows(parent); i++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(i, parent));
if (item != NULL && item->ID() == id)
return item;
if (CountRows(item) > 0) {
// recurse into child rows
item = FindRow(id, item);
if (item)
return item;
}
}
return NULL;
@@ -83,28 +86,28 @@ PartitionListView::FindRow(partition_id id)
PartitionListRow*
PartitionListView::AddPartition(BPartition* partition)
{
PartitionListRow* parent = NULL;
PartitionListRow* partitionrow = NULL;
PartitionListRow* partitionrow = FindRow(partition->ID());
// Forget about it if this partition is already in the listview
if ((partitionrow = FindRow(partition->ID())) != NULL)
if (partitionrow != NULL) {
return partitionrow;
}
// Create the row for this partition
partitionrow = new PartitionListRow(partition);
// If this partition has a parent...
if (partition->Parent() != NULL) {
printf("partition has parent\n");
// check if it is in the listview
parent = FindRow(partition->Parent()->ID());
PartitionListRow* parent = FindRow(partition->Parent()->ID());
// If parent of this partition is not yet in the list
if (parent == NULL) //add it
if (parent == NULL) {
// add it
parent = AddPartition(partition->Parent());
}
// Now it is ok to add this partition under its parent
AddRow(partitionrow, parent);
} else {
printf("partition has NO parent\n");
// If this partition has no parent, add it in the 'root'
AddRow(partitionrow);
}
+4 -2
View File
@@ -22,7 +22,8 @@ class PartitionListRow : public BRow {
public:
PartitionListRow(BPartition* partition);
partition_id ID() { return fPartitionID; }
partition_id ID() const
{ return fPartitionID; }
private:
partition_id fPartitionID;
};
@@ -33,7 +34,8 @@ class PartitionListView : public BColumnListView {
public:
PartitionListView(const BRect& frame);
PartitionListRow* FindRow(partition_id id);
PartitionListRow* FindRow(partition_id id,
PartitionListRow* parent = NULL);
PartitionListRow* AddPartition(BPartition* partition);
};
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Erik Jaesler <[email protected]>
* Ithamar R. Adema <[email protected]>
* Stephan Aßmus <[email protected]>
*/
#include "Support.h"
#include <Partition.h>
const char*
string_for_size(off_t size, char *string)
{
double kb = size / 1024.0;
if (kb < 1.0) {
sprintf(string, "%Ld B", size);
return string;
}
float mb = kb / 1024.0;
if (mb < 1.0) {
sprintf(string, "%3.1f KB", kb);
return string;
}
float gb = mb / 1024.0;
if (gb < 1.0) {
sprintf(string, "%3.1f MB", mb);
return string;
}
float tb = gb / 1024.0;
if (tb < 1.0) {
sprintf(string, "%3.1f GB", gb);
return string;
}
sprintf(string, "%.1f TB", tb);
return string;
}
void
dump_partition_info(const BPartition* partition)
{
char size[1024];
printf("\tOffset(): %Ld\n", partition->Offset());
printf("\tSize(): %s\n", string_for_size(partition->Size(),size));
printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(),
size));
printf("\tBlockSize(): %ld\n", partition->BlockSize());
printf("\tIndex(): %ld\n", partition->Index());
printf("\tStatus(): %ld\n\n", partition->Status());
printf("\tContainsFileSystem(): %s\n",
partition->ContainsFileSystem() ? "true" : "false");
printf("\tContainsPartitioningSystem(): %s\n\n",
partition->ContainsPartitioningSystem() ? "true" : "false");
printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %lx\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name());
printf("\tContentName(): %s\n", partition->ContentName());
printf("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %lx\n\n", partition->ID());
}
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef SUPPORT_H
#define SUPPORT_H
#include <SupportDefs.h>
class BPartition;
const char* string_for_size(off_t size, char *string);
void dump_partition_info(const BPartition* partition);
#endif // SUPPORT_H