From b6f5505092cea3f09aefff1716bc74d5d0451eb1 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Mon, 29 Aug 2011 19:58:50 +0300 Subject: [PATCH] Updated bytes transformers for showing human readable size. --- pithos-macos.xcodeproj/project.pbxproj | 8 +- pithos-macos/BytesExtendedSizeTransformer.h | 39 +++++ pithos-macos/BytesExtendedSizeTransformer.m | 94 +++++++++++ pithos-macos/BytesSizeTransformer.m | 32 +++- pithos-macos/PithosNodeInfoController.xib | 235 +++++++++++++++++---------- 5 files changed, 317 insertions(+), 91 deletions(-) create mode 100644 pithos-macos/BytesExtendedSizeTransformer.h create mode 100644 pithos-macos/BytesExtendedSizeTransformer.m diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index 5664ed4..b47c1b6 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ 6139837113EFEECC004CE444 /* FileSystemBrowserCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6139837013EFEECC004CE444 /* FileSystemBrowserCell.m */; }; 616FC0AF13F91BA400140A33 /* PithosNodeInfoController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 616FC0AE13F91BA400140A33 /* PithosNodeInfoController.xib */; }; 616FC0B313F97D0800140A33 /* PithosNodeInfoController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616FC0B213F97D0800140A33 /* PithosNodeInfoController.m */; }; + 617460F1140BE45C00D333A1 /* BytesExtendedSizeTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 617460F0140BE45C00D333A1 /* BytesExtendedSizeTransformer.m */; }; 6180C22B13FAEF4B00BCA40B /* BytesSizeTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6180C22A13FAEF4B00BCA40B /* BytesSizeTransformer.m */; }; 6180C22E13FBF1FD00BCA40B /* LastModifiedDateTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6180C22D13FBF1FD00BCA40B /* LastModifiedDateTransformer.m */; }; 619B85D513F8077800C9371F /* PithosPreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 619B85D313F8077100C9371F /* PithosPreferencesController.m */; }; @@ -124,9 +125,11 @@ 616FC0AE13F91BA400140A33 /* PithosNodeInfoController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PithosNodeInfoController.xib; sourceTree = ""; }; 616FC0B113F97D0800140A33 /* PithosNodeInfoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PithosNodeInfoController.h; sourceTree = ""; }; 616FC0B213F97D0800140A33 /* PithosNodeInfoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PithosNodeInfoController.m; sourceTree = ""; }; + 617460EF140BE45C00D333A1 /* BytesExtendedSizeTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BytesExtendedSizeTransformer.h; path = "pithos-macos/BytesExtendedSizeTransformer.h"; sourceTree = ""; }; + 617460F0140BE45C00D333A1 /* BytesExtendedSizeTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BytesExtendedSizeTransformer.m; path = "pithos-macos/BytesExtendedSizeTransformer.m"; sourceTree = ""; }; 6180C22913FAEF4B00BCA40B /* BytesSizeTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BytesSizeTransformer.h; path = "pithos-macos/BytesSizeTransformer.h"; sourceTree = ""; }; 6180C22A13FAEF4B00BCA40B /* BytesSizeTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BytesSizeTransformer.m; path = "pithos-macos/BytesSizeTransformer.m"; sourceTree = ""; }; - 6180C22C13FBF1FC00BCA40B /* LastModifiedDateTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; name = LastModifiedDateTransformer.h; path = "pithos-macos/LastModifiedDateTransformer.h"; sourceTree = ""; }; + 6180C22C13FBF1FC00BCA40B /* LastModifiedDateTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LastModifiedDateTransformer.h; path = "pithos-macos/LastModifiedDateTransformer.h"; sourceTree = ""; }; 6180C22D13FBF1FD00BCA40B /* LastModifiedDateTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LastModifiedDateTransformer.m; path = "pithos-macos/LastModifiedDateTransformer.m"; sourceTree = ""; }; 619B85D213F8076F00C9371F /* PithosPreferencesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PithosPreferencesController.h; sourceTree = ""; }; 619B85D313F8077100C9371F /* PithosPreferencesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PithosPreferencesController.m; sourceTree = ""; }; @@ -318,6 +321,8 @@ children = ( 6180C22913FAEF4B00BCA40B /* BytesSizeTransformer.h */, 6180C22A13FAEF4B00BCA40B /* BytesSizeTransformer.m */, + 617460EF140BE45C00D333A1 /* BytesExtendedSizeTransformer.h */, + 617460F0140BE45C00D333A1 /* BytesExtendedSizeTransformer.m */, 6180C22C13FBF1FC00BCA40B /* LastModifiedDateTransformer.h */, 6180C22D13FBF1FD00BCA40B /* LastModifiedDateTransformer.m */, ); @@ -422,6 +427,7 @@ 616FC0B313F97D0800140A33 /* PithosNodeInfoController.m in Sources */, 6180C22B13FAEF4B00BCA40B /* BytesSizeTransformer.m in Sources */, 6180C22E13FBF1FD00BCA40B /* LastModifiedDateTransformer.m in Sources */, + 617460F1140BE45C00D333A1 /* BytesExtendedSizeTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/pithos-macos/BytesExtendedSizeTransformer.h b/pithos-macos/BytesExtendedSizeTransformer.h new file mode 100644 index 0000000..23d20b5 --- /dev/null +++ b/pithos-macos/BytesExtendedSizeTransformer.h @@ -0,0 +1,39 @@ +// +// BytesExtendedSizeTransformer.h +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +@interface BytesExtendedSizeTransformer : NSValueTransformer +@end diff --git a/pithos-macos/BytesExtendedSizeTransformer.m b/pithos-macos/BytesExtendedSizeTransformer.m new file mode 100644 index 0000000..726e460 --- /dev/null +++ b/pithos-macos/BytesExtendedSizeTransformer.m @@ -0,0 +1,94 @@ +// +// BytesExtendedSizeTransformer.m +// pithos-macos +// +// Copyright 2011 GRNET S.A. All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and +// documentation are those of the authors and should not be +// interpreted as representing official policies, either expressed +// or implied, of GRNET S.A. + +#import "BytesExtendedSizeTransformer.h" + +@implementation BytesExtendedSizeTransformer + ++ (Class)transformedValueClass { + return [NSString class]; +} + ++ (BOOL)allowsReverseTransformation { + return NO; +} + +- (id)transformedValue:(id)value { + if (value == nil) + return nil; + NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setGroupingSeparator:@","]; + [numberFormatter setUsesGroupingSeparator:YES]; + [numberFormatter setGroupingSize:3]; + NSString *formattedBytes = [numberFormatter stringFromNumber:value]; + double bytes = [value unsignedIntegerValue] + 0.0; + if (bytes <= 999) { + return [NSString stringWithFormat:@"%@ bytes", formattedBytes]; + } else if (bytes <= 999000) { + return [NSString stringWithFormat:@"%d KB (%@ bytes)", (int)ceil(bytes / 1000), formattedBytes]; + } else if (bytes <= 999900000) { + double megabytes = floor(bytes / 1000000); + double hundredkilobytes = ceil((bytes - megabytes * 1000000) / 100000); + if (hundredkilobytes == 10) { + megabytes++; + hundredkilobytes = 0; + } + if (hundredkilobytes == 0) { + return [NSString stringWithFormat:@"%d MB (%@ bytes)", (int)megabytes, formattedBytes]; + } else { + return [NSString stringWithFormat:@"%d.%d MB (%@ bytes)", (int)megabytes, (int)hundredkilobytes, formattedBytes]; + } + } else { + double gigabytes = floor(bytes / 1000000000); + double hundredmegabytes = ceil((bytes - gigabytes * 1000000000) / 100000000); + if (hundredmegabytes == 10) { + gigabytes++; + hundredmegabytes = 0; + } + if (hundredmegabytes == 0) { + return [NSString stringWithFormat:@"%d GB (%@ bytes)", (int)gigabytes, formattedBytes]; + } else { + return [NSString stringWithFormat:@"%d.%d GB (%@ bytes)", (int)gigabytes, (int)hundredmegabytes, formattedBytes]; + } + } +} + ++ (void)initialize { + [[NSValueTransformer class] setValueTransformer:[self new] forName:@"BytesExtendedSizeTransformer"]; +} + +@end diff --git a/pithos-macos/BytesSizeTransformer.m b/pithos-macos/BytesSizeTransformer.m index a80e3de..026b643 100644 --- a/pithos-macos/BytesSizeTransformer.m +++ b/pithos-macos/BytesSizeTransformer.m @@ -50,8 +50,36 @@ - (id)transformedValue:(id)value { if (value == nil) return nil; - // XXX make it more readble using KB, MB, etc - return [NSString stringWithFormat:@"%lu B", [value unsignedIntegerValue]]; + double bytes = [value unsignedIntegerValue] + 0.0; + if (bytes <= 999) { + return [NSString stringWithFormat:@"%d B", (int)bytes]; + } else if (bytes <= 999000) { + return [NSString stringWithFormat:@"%d KB", (int)ceil(bytes / 1000)]; + } else if (bytes <= 999900000) { + double megabytes = floor(bytes / 1000000); + double hundredkilobytes = ceil((bytes - megabytes * 1000000) / 100000); + if (hundredkilobytes == 10) { + megabytes++; + hundredkilobytes = 0; + } + if (hundredkilobytes == 0) { + return [NSString stringWithFormat:@"%d MB", (int)megabytes]; + } else { + return [NSString stringWithFormat:@"%d.%d MB", (int)megabytes, (int)hundredkilobytes]; + } + } else { + double gigabytes = floor(bytes / 1000000000); + double hundredmegabytes = ceil((bytes - gigabytes * 1000000000) / 100000000); + if (hundredmegabytes == 10) { + gigabytes++; + hundredmegabytes = 0; + } + if (hundredmegabytes == 0) { + return [NSString stringWithFormat:@"%d GB", (int)gigabytes]; + } else { + return [NSString stringWithFormat:@"%d.%d GB", (int)gigabytes, (int)hundredmegabytes]; + } + } } + (void)initialize { diff --git a/pithos-macos/PithosNodeInfoController.xib b/pithos-macos/PithosNodeInfoController.xib index b440195..de2b7b0 100644 --- a/pithos-macos/PithosNodeInfoController.xib +++ b/pithos-macos/PithosNodeInfoController.xib @@ -84,6 +84,7 @@ {{10, 473}, {32, 32}} + YES @@ -105,6 +106,7 @@ 270 {{47, 490}, {135, 17}} + YES @@ -142,6 +144,7 @@ 268 {{47, 470}, {60, 17}} + YES @@ -163,6 +166,7 @@ 265 {{178, 490}, {80, 17}} + YES @@ -184,6 +188,7 @@ 268 {{109, 473}, {149, 14}} + YES @@ -201,6 +206,7 @@ 14 {{0, 459}, {265, 5}} + {0, 0} @@ -232,6 +238,7 @@ 268 {{7, 444}, {72, 14}} + YES @@ -250,6 +257,7 @@ 270 {{84, 392}, {174, 14}} + YES @@ -271,6 +279,7 @@ 270 {{84, 422}, {174, 14}} + YES @@ -288,6 +297,7 @@ 270 {{84, 407}, {174, 14}} + YES @@ -305,6 +315,7 @@ 270 {{84, 377}, {174, 14}} + YES @@ -322,6 +333,7 @@ 270 {{84, 362}, {174, 14}} + YES @@ -339,6 +351,7 @@ 270 {{84, 347}, {174, 14}} + YES @@ -356,6 +369,7 @@ 268 {{12, 392}, {72, 14}} + YES @@ -374,6 +388,7 @@ 268 {{12, 422}, {72, 14}} + YES @@ -392,6 +407,7 @@ 268 {{12, 407}, {72, 14}} + YES @@ -410,6 +426,7 @@ 268 {{12, 377}, {72, 14}} + YES @@ -428,6 +445,7 @@ 268 {{12, 362}, {72, 14}} + YES @@ -446,6 +464,7 @@ 268 {{12, 347}, {72, 14}} + YES @@ -464,6 +483,7 @@ 14 {{0, 334}, {265, 5}} + {0, 0} @@ -487,6 +507,7 @@ 268 {{7, 319}, {72, 14}} + YES @@ -515,6 +536,7 @@ 256 {243, 78} + YES @@ -522,6 +544,7 @@ 256 {243, 17} + @@ -530,6 +553,7 @@ -2147483392 {{224, 0}, {16, 17}} + @@ -626,6 +650,7 @@ {{1, 17}, {243, 78}} + @@ -636,6 +661,7 @@ -2147483392 {{224, 17}, {15, 102}} + _doScroller: @@ -647,6 +673,7 @@ -2147483392 {{1, 119}, {223, 15}} + 1 @@ -662,6 +689,7 @@ {{1, 0}, {243, 17}} + @@ -671,6 +699,7 @@ {{10, 215}, {245, 96}} + 562 @@ -685,6 +714,7 @@ 268 {{10, 195}, {18, 18}} + YES @@ -710,6 +740,7 @@ 268 {{27, 195}, {18, 18}} + YES @@ -735,6 +766,7 @@ 14 {{0, 185}, {265, 5}} + {0, 0} @@ -758,6 +790,7 @@ 268 {{7, 170}, {126, 14}} + YES @@ -786,6 +819,7 @@ 256 {243, 78} + YES @@ -793,6 +827,7 @@ 256 {243, 17} + @@ -801,6 +836,7 @@ -2147483392 {{224, 0}, {16, 17}} + @@ -879,6 +915,7 @@ {{1, 17}, {243, 78}} + @@ -889,6 +926,7 @@ -2147483392 {{224, 17}, {15, 102}} + _doScroller: @@ -899,6 +937,7 @@ -2147483392 {{1, 80}, {243, 15}} + 1 @@ -914,6 +953,7 @@ {{1, 0}, {243, 17}} + @@ -923,6 +963,7 @@ {{10, 27}, {245, 96}} + 562 @@ -937,6 +978,7 @@ 268 {{10, 7}, {18, 18}} + YES @@ -959,6 +1001,7 @@ 268 {{27, 7}, {18, 18}} + YES @@ -981,6 +1024,7 @@ 268 {{83, 129}, {61, 18}} + YES @@ -1009,6 +1053,7 @@ 270 {{84, 148}, {174, 14}} + YES @@ -1026,6 +1071,7 @@ 268 {{12, 148}, {72, 14}} + YES @@ -1042,6 +1088,7 @@ {{7, 11}, {265, 515}} + {{0, 0}, {1280, 778}} @@ -1093,22 +1140,6 @@ 105 - - value: self.node.icon - - - - - - value: self.node.icon - value - self.node.icon - 2 - - - 106 - - window @@ -1118,22 +1149,6 @@ - value: self.node.displayName - - - - - - value: self.node.displayName - value - self.node.displayName - 2 - - - 108 - - - content: arrangedObjects @@ -1182,15 +1197,63 @@ - value: self.node.pithosObject.bytes + contentDictionary: self.node.pithosObject.metadata + + + + + + contentDictionary: self.node.pithosObject.metadata + contentDictionary + self.node.pithosObject.metadata + 2 + + + 166 + + + + value: node.icon + + + + + + value: node.icon + value + node.icon + 2 + + + 169 + + + + value: node.displayName + + + + + + value: node.displayName + value + node.displayName + 2 + + + 170 + + + + value: node.pithosObject.bytes - value: self.node.pithosObject.bytes + value: node.pithosObject.bytes value - self.node.pithosObject.bytes + node.pithosObject.bytes NSValueTransformerName BytesSizeTransformer @@ -1198,143 +1261,127 @@ 2 - 156 + 171 - value: self.node.pithosContainer.name + value: node.pithosContainer.name - value: self.node.pithosContainer.name + value: node.pithosContainer.name value - self.node.pithosContainer.name + node.pithosContainer.name 2 - 159 + 172 - value: self.node.pithosObject.name + value: node.pithosObject.name - value: self.node.pithosObject.name + value: node.pithosObject.name value - self.node.pithosObject.name + node.pithosObject.name 2 - 160 + 173 - value: self.node.pithosObject.contentType + value: node.pithosObject.contentType - value: self.node.pithosObject.contentType + value: node.pithosObject.contentType value - self.node.pithosObject.contentType + node.pithosObject.contentType 2 - 161 + 174 - value: self.node.pithosObject.bytes - + value: node.pithosObject.lastModified + - + - value: self.node.pithosObject.bytes + value: node.pithosObject.lastModified value - self.node.pithosObject.bytes + node.pithosObject.lastModified NSValueTransformerName - BytesSizeTransformer + LastModifiedDateTransformer 2 - 163 + 176 - value: self.node.pithosObject.modifiedBy + value: node.pithosObject.modifiedBy - value: self.node.pithosObject.modifiedBy + value: node.pithosObject.modifiedBy value - self.node.pithosObject.modifiedBy + node.pithosObject.modifiedBy 2 - 164 + 177 - value: self.node.pithosObject.version + value: node.pithosObject.version - value: self.node.pithosObject.version + value: node.pithosObject.version value - self.node.pithosObject.version - 2 - - - 165 - - - - contentDictionary: self.node.pithosObject.metadata - - - - - - contentDictionary: self.node.pithosObject.metadata - contentDictionary - self.node.pithosObject.metadata + node.pithosObject.version 2 - 166 + 178 - value: self.node.pithosObject.lastModified - + value: node.pithosObject.bytes + - + - value: self.node.pithosObject.lastModified + value: node.pithosObject.bytes value - self.node.pithosObject.lastModified + node.pithosObject.bytes NSValueTransformerName - LastModifiedDateTransformer + BytesExtendedSizeTransformer 2 - 168 + 184 @@ -2154,9 +2201,21 @@ - 168 + 184 + + + + YES + + PithosNodeInfoController + NSWindowController + + IBProjectSource + ./Classes/PithosNodeInfoController.h + + + - 0 IBCocoaFramework -- 1.7.10.4