]> granicus.if.org Git - transmission/commitdiff
More 10.8 better file size formatting.
authorMitchell Livingston <livings124@transmissionbt.com>
Wed, 25 Jul 2012 12:48:13 +0000 (12:48 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Wed, 25 Jul 2012 12:48:13 +0000 (12:48 +0000)
macosx/InfoWindowController.m
macosx/StatsWindowController.m

index bdf049dd2ebb77d2eb34dfea2f0afff25f57c2be..1868ab62613a7030de8638bc61666aa7e287289c 100644 (file)
@@ -31,6 +31,7 @@
 #import "InfoFileViewController.h"
 #import "InfoOptionsViewController.h"
 #import "InfoTabButtonCell.h"
+#import "NSApplicationAdditions.h"
 #import "NSStringAdditions.h"
 #import "Torrent.h"
 
@@ -448,8 +449,18 @@ typedef enum
                 [fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@", fileString,
                     [NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"),
                         [NSString stringForFileSize: size]]]];
-                [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes",
-                                                "Inspector -> selected torrents"), [NSString formattedUInteger: size]]];
+                
+                NSString * byteString;
+                if ([NSApp isOnMountainLionOrBetter])
+                {
+                    NSByteCountFormatter * formatter = [[NSByteCountFormatterMtLion alloc] init];
+                    [formatter setAllowedUnits: NSByteCountFormatterUseBytes];
+                    byteString = [formatter stringFromByteCount: size];
+                    [formatter release];
+                }
+                else
+                    byteString = [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "Inspector -> selected torrents"), [NSString formattedUInteger: size]];
+                [fBasicInfoField setToolTip: byteString];
             }
             else
             {
@@ -497,8 +508,18 @@ typedef enum
                 basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString];
             }
             [fBasicInfoField setStringValue: basicString];
-            [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "Inspector -> selected torrents"),
-                                            [NSString formattedUInteger: [torrent size]]]];
+            
+            NSString * byteString;
+            if ([NSApp isOnMountainLionOrBetter])
+            {
+                NSByteCountFormatter * formatter = [[NSByteCountFormatterMtLion alloc] init];
+                [formatter setAllowedUnits: NSByteCountFormatterUseBytes];
+                byteString = [formatter stringFromByteCount: [torrent size]];
+                [formatter release];
+            }
+            else
+                byteString = [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "Inspector -> selected torrents"), [NSString formattedUInteger: [torrent size]]];
+            [fBasicInfoField setToolTip: byteString];
         }
         else
         {
index 7c902cebbd52a56440def3b143831a842af30817..51a4d6877a0423c4adf69469bb06e3d6d8653110 100644 (file)
@@ -181,21 +181,24 @@ tr_session * fLib = NULL;
     tr_sessionGetCumulativeStats(fLib, &statsAll);
     tr_sessionGetStats(fLib, &statsSession);
     
+    NSByteCountFormatter * byteFormatter = nil;
+    if ([NSApp isOnMountainLionOrBetter])
+    {
+        byteFormatter = [[NSByteCountFormatterMtLion alloc] init];
+        [byteFormatter setAllowedUnits: NSByteCountFormatterUseBytes];
+    }
+    
     [fUploadedField setStringValue: [NSString stringForFileSize: statsSession.uploadedBytes]];
-    [fUploadedField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"),
-                                    [NSString formattedUInteger: statsSession.uploadedBytes]]];
-    [fUploadedAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"),
-                                        [NSString stringForFileSize: statsAll.uploadedBytes]]];
-    [fUploadedAllField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"),
-                                    [NSString formattedUInteger: statsAll.uploadedBytes]]];
+    [fUploadedField setToolTip: [NSApp isOnMountainLionOrBetter] ? [byteFormatter stringFromByteCount: statsSession.uploadedBytes] : [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"), [NSString formattedUInteger: statsSession.uploadedBytes]]];
+    [fUploadedAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [NSString stringForFileSize: statsAll.uploadedBytes]]];
+    [fUploadedAllField setToolTip: [NSApp isOnMountainLionOrBetter] ? [byteFormatter stringFromByteCount: statsAll.uploadedBytes] : [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"), [NSString formattedUInteger: statsAll.uploadedBytes]]];
     
     [fDownloadedField setStringValue: [NSString stringForFileSize: statsSession.downloadedBytes]];
-    [fDownloadedField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"),
-                                    [NSString formattedUInteger: statsSession.downloadedBytes]]];
-    [fDownloadedAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"),
-                                        [NSString stringForFileSize: statsAll.downloadedBytes]]];
-    [fDownloadedAllField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"),
-                                        [NSString formattedUInteger: statsAll.downloadedBytes]]];
+    [fDownloadedField setToolTip: [NSApp isOnMountainLionOrBetter] ? [byteFormatter stringFromByteCount: statsSession.downloadedBytes] : [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"), [NSString formattedUInteger: statsSession.downloadedBytes]]];
+    [fDownloadedAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [NSString stringForFileSize: statsAll.downloadedBytes]]];
+    [fDownloadedAllField setToolTip: [NSApp isOnMountainLionOrBetter] ? [byteFormatter stringFromByteCount: statsAll.downloadedBytes] : [NSString stringWithFormat: NSLocalizedString(@"%@ bytes", "stats -> bytes"), [NSString formattedUInteger: statsAll.downloadedBytes]]];
+    
+    [byteFormatter release];
     
     [fRatioField setStringValue: [NSString stringForRatio: statsSession.ratio]];
     
@@ -205,14 +208,12 @@ tr_session * fLib = NULL;
     [fRatioAllField setStringValue: totalRatioString];
     
     [fTimeField setStringValue: [NSString timeString: statsSession.secondsActive showSeconds: NO]];
-    [fTimeAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"),
-                                        [NSString timeString: statsAll.secondsActive showSeconds: NO]]];
+    [fTimeAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [NSString timeString: statsAll.secondsActive showSeconds: NO]]];
     
     if (statsAll.sessionCount == 1)
         [fNumOpenedField setStringValue: NSLocalizedString(@"1 time", "stats window -> times opened")];
     else
-        [fNumOpenedField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ times", "stats window -> times opened"),
-                                            [NSString formattedUInteger: statsAll.sessionCount]]];
+        [fNumOpenedField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ times", "stats window -> times opened"), [NSString formattedUInteger: statsAll.sessionCount]]];
 }
 
 - (void) performResetStats