From a8e3418a4cac2812c2fe1234ef0c95b88100c9d5 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 18 Dec 2013 08:38:03 -0500 Subject: [PATCH] Use the UIxMailSizeFormatter in messages listing --- UI/MailPartViewers/UIxMailSizeFormatter.m | 23 +++++++++++-------- UI/MailerUI/UIxMailListActions.h | 2 ++ UI/MailerUI/UIxMailListActions.m | 18 ++++----------- .../MailPartViewers/UIxMailPartLinkViewer.wox | 2 +- UI/WebServerResources/generic.css | 4 ++++ 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/UI/MailPartViewers/UIxMailSizeFormatter.m b/UI/MailPartViewers/UIxMailSizeFormatter.m index c4fdbe09e..2e5b133de 100644 --- a/UI/MailPartViewers/UIxMailSizeFormatter.m +++ b/UI/MailPartViewers/UIxMailSizeFormatter.m @@ -25,7 +25,8 @@ @implementation UIxMailSizeFormatter -+ (id)sharedMailSizeFormatter { ++ (id) sharedMailSizeFormatter +{ static UIxMailSizeFormatter *fmt = nil; // THREAD if (fmt == nil) fmt = [[self alloc] init]; return fmt; @@ -33,20 +34,24 @@ /* formatting */ -- (NSString *)stringForSize:(unsigned int)size { +- (NSString *) stringForSize: (unsigned int) size +{ char buf[128]; - - if (size < 1024) - sprintf(buf, "%d", size); - else if (size < 1024 * 1024) - sprintf(buf, "%.1fK", ((double)size / 1024)); + + if (size > 1024*1024) + sprintf(buf, "%.1f MiB", ((double)size / 1024 / 1024)); + else if (size > 1024*100) + sprintf(buf, "%d KiB", (size / 1024)); + else if (size > 1024) + sprintf(buf, "%.1f KiB", ((double)size / 1024)); else - sprintf(buf, "%.1fM", ((double)size / 1024 / 1024)); + sprintf(buf, "%d B", size); return [NSString stringWithCString:buf]; } -- (NSString *)stringForObjectValue:(id)_object { +- (NSString *) stringForObjectValue: (id) _object +{ return [self stringForSize:[_object unsignedIntValue]]; } diff --git a/UI/MailerUI/UIxMailListActions.h b/UI/MailerUI/UIxMailListActions.h index bd80c7357..26a917778 100644 --- a/UI/MailerUI/UIxMailListActions.h +++ b/UI/MailerUI/UIxMailListActions.h @@ -27,6 +27,7 @@ @class NSDictionary; @class EOQualifier; @class SOGoDateFormatter; +@class UIxMailSizeFormatter; @interface UIxMailListActions : WODirectAction { @@ -35,6 +36,7 @@ id message; SOGoDateFormatter *dateFormatter; NSTimeZone *userTimeZone; + UIxMailSizeFormatter *sizeFormatter; BOOL sortByThread; int folderType; int specificMessageNumber; diff --git a/UI/MailerUI/UIxMailListActions.m b/UI/MailerUI/UIxMailListActions.m index 90acfd53e..33585e932 100644 --- a/UI/MailerUI/UIxMailListActions.m +++ b/UI/MailerUI/UIxMailListActions.m @@ -60,6 +60,7 @@ #import #import +#import #import "WOContext+UIxMailer.h" #import "UIxMailFormatter.h" @@ -120,20 +121,9 @@ return [dateFormatter formattedDateAndTime: messageDate]; } -- (NSString *) messageSize +- (UIxMailSizeFormatter *) sizeFormatter { - NSString *rc; - int size; - - size = [[message valueForKey: @"size"] intValue]; - if (size > 1024*1024) - rc = [NSString stringWithFormat: @"%.1f MB", (float) size/1024/1024]; - else if (size > 1024*100) - rc = [NSString stringWithFormat: @"%d KB", size/1024]; - else - rc = [NSString stringWithFormat: @"%.1f KB", (float) size/1024]; - - return rc; + return [UIxMailSizeFormatter sharedMailSizeFormatter]; } // @@ -806,7 +796,7 @@ [msg addObject: msgDate]; // Size - [msg addObject: [self messageSize]]; + [msg addObject: [[self sizeFormatter] stringForObjectValue: [message objectForKey: @"size"]]]; // rowClasses [msg addObject: [self messageRowStyleClass]]; diff --git a/UI/Templates/MailPartViewers/UIxMailPartLinkViewer.wox b/UI/Templates/MailPartViewers/UIxMailPartLinkViewer.wox index 1e7368086..e566552c9 100644 --- a/UI/Templates/MailPartViewers/UIxMailPartLinkViewer.wox +++ b/UI/Templates/MailPartViewers/UIxMailPartLinkViewer.wox @@ -14,7 +14,7 @@
() + /> ()