xref: /haiku/src/apps/drivesetup/Support.cpp (revision e0ef64750f3169cd634bb2f7a001e22488b05231)
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  {
104  	SetBarColor((rgb_color){ 0, 80, 255, 255 });
105  	char minString[64];
106  	char maxString[64];
107  	snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %ld MB"),
108  		fStartOffset);
109  	snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %ld MB"),
110  		fEndOffset);
111  	SetLimitLabels(minString, maxString);
112  }
113  
114  
115  SizeSlider::~SizeSlider()
116  {
117  }
118  
119  
120  const char*
121  SizeSlider::UpdateText() const
122  {
123  	// TODO: Perhaps replace with string_for_size, but it looks like
124  	// Value() and fStartOffset are always in MiB.
125  	snprintf(fStatusLabel, sizeof(fStatusLabel), B_TRANSLATE("%ld MiB"),
126  		Value() - fStartOffset);
127  
128  	return fStatusLabel;
129  }
130  
131  
132  int32
133  SizeSlider::Size()
134  {
135  	return Value() - fStartOffset;
136  }
137  
138  
139  int32
140  SizeSlider::Offset()
141  {
142  	// TODO: This should be the changed offset once a double
143  	// headed slider is implemented.
144  	return fStartOffset;
145  }
146