1 /* 2 * Copyright 2002-2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Erik Jaesler <ejakowatz@users.sourceforge.net> 7 * Ithamar R. Adema <ithamar@unet.nl> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Bryce Groff <bgroff@hawaii.edu> 10 */ 11 12 #include "Support.h" 13 14 #include <stdio.h> 15 16 #include <Catalog.h> 17 #include <Locale.h> 18 #include <Partition.h> 19 #include <String.h> 20 21 22 #undef B_TRANSLATE_CONTEXT 23 #define B_TRANSLATE_CONTEXT "Support" 24 25 26 void 27 dump_partition_info(const BPartition* partition) 28 { 29 char size[1024]; 30 printf("\tOffset(): %Ld\n", partition->Offset()); 31 printf("\tSize(): %s\n", string_for_size(partition->Size(), size, 32 sizeof(size))); 33 printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(), 34 size, sizeof(size))); 35 printf("\tBlockSize(): %ld\n", partition->BlockSize()); 36 printf("\tIndex(): %ld\n", partition->Index()); 37 printf("\tStatus(): %ld\n\n", partition->Status()); 38 printf("\tContainsFileSystem(): %s\n", 39 partition->ContainsFileSystem() ? "true" : "false"); 40 printf("\tContainsPartitioningSystem(): %s\n\n", 41 partition->ContainsPartitioningSystem() ? "true" : "false"); 42 printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false"); 43 printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false"); 44 printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false"); 45 printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); 46 printf("\tFlags(): %lx\n\n", partition->Flags()); 47 printf("\tName(): %s\n", partition->Name()); 48 printf("\tContentName(): %s\n", partition->ContentName()); 49 printf("\tType(): %s\n", partition->Type()); 50 printf("\tContentType(): %s\n", partition->ContentType()); 51 printf("\tID(): %lx\n\n", partition->ID()); 52 } 53 54 55 bool 56 is_valid_partitionable_space(size_t size) 57 { 58 // TODO: remove this again, the DiskDeviceAPI should 59 // not even show these spaces to begin with 60 return size >= 8 * 1024 * 1024; 61 } 62 63 64 // #pragma mark - SpaceIDMap 65 66 67 SpaceIDMap::SpaceIDMap() 68 : 69 HashMap<HashString, partition_id>(), 70 fNextSpaceID(-2) 71 { 72 } 73 74 75 SpaceIDMap::~SpaceIDMap() 76 { 77 } 78 79 80 partition_id 81 SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset) 82 { 83 BString key; 84 key << parentID << ':' << (uint64)spaceOffset; 85 86 if (ContainsKey(key.String())) 87 return Get(key.String()); 88 89 partition_id newID = fNextSpaceID--; 90 Put(key.String(), newID); 91 92 return newID; 93 } 94 95 96 SizeSlider::SizeSlider(const char* name, const char* label, 97 BMessage* message, int32 minValue, int32 maxValue) 98 : 99 BSlider(name, label, message, minValue, maxValue, 100 B_HORIZONTAL, B_TRIANGLE_THUMB), 101 fStartOffset(minValue), 102 fEndOffset(maxValue), 103 fMaxPartitionSize(maxValue) 104 { 105 rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); 106 UseFillColor(true, &fillColor); 107 char minString[64]; 108 char maxString[64]; 109 snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %ld MB"), 110 fStartOffset); 111 snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %ld MB"), 112 fEndOffset); 113 SetLimitLabels(minString, maxString); 114 } 115 116 117 SizeSlider::~SizeSlider() 118 { 119 } 120 121 122 const char* 123 SizeSlider::UpdateText() const 124 { 125 // TODO: Perhaps replace with string_for_size, but it looks like 126 // Value() and fStartOffset are always in MiB. 127 snprintf(fStatusLabel, sizeof(fStatusLabel), B_TRANSLATE("%ld MiB"), 128 Value() - fStartOffset); 129 130 return fStatusLabel; 131 } 132 133 134 int32 135 SizeSlider::Size() 136 { 137 return Value() - fStartOffset; 138 } 139 140 141 int32 142 SizeSlider::Offset() 143 { 144 // TODO: This should be the changed offset once a double 145 // headed slider is implemented. 146 return fStartOffset; 147 } 148 149 int32 150 SizeSlider::MaxPartitionSize() 151 { 152 return fMaxPartitionSize; 153 } 154