xref: /haiku/src/apps/drivesetup/Support.cpp (revision 526e86ac79f9899c43e2def55f82754a5c449f8a)
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 <Partition.h>
18 #include <String.h>
19 
20 
21 #undef B_TRANSLATE_CONTEXT
22 #define B_TRANSLATE_CONTEXT "Support"
23 
24 
25 void
26 dump_partition_info(const BPartition* partition)
27 {
28 	char size[1024];
29 	printf("\tOffset(): %Ld\n", partition->Offset());
30 	printf("\tSize(): %s\n", string_for_size(partition->Size(), size,
31 		sizeof(size)));
32 	printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(),
33 		size, sizeof(size)));
34 	printf("\tBlockSize(): %ld\n", partition->BlockSize());
35 	printf("\tIndex(): %ld\n", partition->Index());
36 	printf("\tStatus(): %ld\n\n", partition->Status());
37 	printf("\tContainsFileSystem(): %s\n",
38 		partition->ContainsFileSystem() ? "true" : "false");
39 	printf("\tContainsPartitioningSystem(): %s\n\n",
40 		partition->ContainsPartitioningSystem() ? "true" : "false");
41 	printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
42 	printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
43 	printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
44 	printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
45 	printf("\tFlags(): %lx\n\n", partition->Flags());
46 	printf("\tName(): %s\n", partition->Name());
47 	printf("\tContentName(): %s\n", partition->ContentName());
48 	printf("\tType(): %s\n", partition->Type());
49 	printf("\tContentType(): %s\n", partition->ContentType());
50 	printf("\tID(): %lx\n\n", partition->ID());
51 }
52 
53 
54 bool
55 is_valid_partitionable_space(size_t size)
56 {
57 	// TODO: remove this again, the DiskDeviceAPI should
58 	// not even show these spaces to begin with
59 	return size >= 8 * 1024 * 1024;
60 }
61 
62 
63 // #pragma mark - SpaceIDMap
64 
65 
66 SpaceIDMap::SpaceIDMap()
67 	:
68 	HashMap<HashString, partition_id>(),
69 	fNextSpaceID(-2)
70 {
71 }
72 
73 
74 SpaceIDMap::~SpaceIDMap()
75 {
76 }
77 
78 
79 partition_id
80 SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset)
81 {
82 	BString key;
83 	key << parentID << ':' << (uint64)spaceOffset;
84 
85 	if (ContainsKey(key.String()))
86 		return Get(key.String());
87 
88 	partition_id newID = fNextSpaceID--;
89 	Put(key.String(), newID);
90 
91 	return newID;
92 }
93 
94 
95 SizeSlider::SizeSlider(const char* name, const char* label,
96 		BMessage* message, int32 minValue, int32 maxValue)
97 	:
98 	BSlider(name, label, message, minValue, maxValue,
99 	B_HORIZONTAL, B_TRIANGLE_THUMB),
100 	fStartOffset(minValue),
101 	fEndOffset(maxValue)
102 {
103 	SetBarColor((rgb_color){ 0, 80, 255, 255 });
104 	char minString[64];
105 	char maxString[64];
106 	snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %ld MB"),
107 		fStartOffset);
108 	snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %ld MB"),
109 		fEndOffset);
110 	SetLimitLabels(minString, maxString);
111 }
112 
113 
114 SizeSlider::~SizeSlider()
115 {
116 }
117 
118 
119 const char*
120 SizeSlider::UpdateText() const
121 {
122 	// TODO: Perhaps replace with string_for_size, but it looks like
123 	// Value() and fStartOffset are always in MiB.
124 	snprintf(fStatusLabel, sizeof(fStatusLabel), B_TRANSLATE("%ld MiB"),
125 		Value() - fStartOffset);
126 
127 	return fStatusLabel;
128 }
129 
130 
131 int32
132 SizeSlider::Size()
133 {
134 	return Value() - fStartOffset;
135 }
136 
137 
138 int32
139 SizeSlider::Offset()
140 {
141 	// TODO: This should be the changed offset once a double
142 	// headed slider is implemented.
143 	return fStartOffset;
144 }
145