411516 Format dates and times according to the user's preferences. r=smorgan

This commit is contained in:
mark%moxienet.com 2008-01-22 19:38:48 +00:00
Родитель 3ac8b1f7c3
Коммит f351bf68ae
14 изменённых файлов: 121 добавлений и 164 удалений

Просмотреть файл

@ -130,10 +130,3 @@ typedef enum ECookiePolicyPopupIndex
- (IBAction)filterChanged:(id)sender;
@end
// custom formatter for cookies list to handle session cookie expiration sanely
@interface CookieDateFormatter : NSDateFormatter
{
CFDateFormatterRef mLocaleFormatter; // strong
}
@end

Просмотреть файл

@ -44,6 +44,9 @@
#import "ExtendedTableView.h"
#import "KeychainDenyList.h"
@interface CookieDateFormatter : NSDateFormatter
@end
// prefs for keychain password autofill
static const char* const kUseKeychainPref = "chimera.store_passwords_with_keychain";
@ -216,17 +219,12 @@ const int kSortReverse = 1;
// build cookie list
[self loadCookies];
CookieDateFormatter* cookieDateFormatter =
[[CookieDateFormatter alloc] initWithDateFormat:@"%b %d, %Y"
allowNaturalLanguage:NO];
// Once we are 10.4+, the above and all the CF stuff in CookieDateFormatter
// can be replaced with the following:
//CookieDateFormatter* cookieDateFormatter = [[CookieDateFormatter alloc] init];
//[cookieDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
//[cookieDateFormatter setDateStyle:NSDateFormatterMediumStyle];
//[cookieDateFormatter setTimeStyle:NSDateFormatterNoStyle];
[[[mCookiesTable tableColumnWithIdentifier:@"expiresDate"] dataCell] setFormatter:cookieDateFormatter];
[cookieDateFormatter release];
CookieDateFormatter* dateFormatter = [[CookieDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[[[mCookiesTable tableColumnWithIdentifier:@"expiresDate"] dataCell] setFormatter:dateFormatter];
[dateFormatter release];
[self initializeTable:mCookiesTable
withInitialSortKey:@"domain"
@ -1072,43 +1070,15 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
@implementation CookieDateFormatter
- (id)initWithDateFormat:(NSString*)format allowNaturalLanguage:(BOOL)flag;
{
if ((self = [super initWithDateFormat:format allowNaturalLanguage:flag])) {
CFLocaleRef userLocale = CFLocaleCopyCurrent();
if (userLocale) {
mLocaleFormatter = CFDateFormatterCreate(NULL,
userLocale,
kCFDateFormatterMediumStyle,
kCFDateFormatterNoStyle);
CFRelease(userLocale);
}
- (NSString*)stringForObjectValue:(id)object {
if ([object isKindOfClass:[NSDate class]] &&
[(NSDate*)object timeIntervalSince1970] == 0) {
return NSLocalizedStringFromTableInBundle(@"CookieExpiresOnQuit",
nil,
[NSBundle bundleForClass:[self class]],
nil);
}
return self;
}
- (void)dealloc
{
if (mLocaleFormatter)
CFRelease(mLocaleFormatter);
[super dealloc];
}
- (NSString*)stringForObjectValue:(id)anObject
{
if ([(NSDate*)anObject timeIntervalSince1970] == 0)
return NSLocalizedStringFromTableInBundle(@"CookieExpiresOnQuit", nil,
[NSBundle bundleForClass:[self class]], nil);
if (mLocaleFormatter) {
NSString* dateString = (NSString*)CFDateFormatterCreateStringWithDate(NULL,
mLocaleFormatter,
(CFDateRef)anObject);
if (dateString)
return [dateString autorelease];
}
// If all else fails, fall back on the standard date formatter
return [super stringForObjectValue:anObject];
return [super stringForObjectValue:object];
}
@end

Просмотреть файл

@ -1,14 +1,14 @@
{
IBClasses = (
{
ACTIONS = {
IBClasses = (
{
ACTIONS = {
clearVisitCount = id;
dockMenuCheckboxClicked = id;
tabGroupCheckboxClicked = id;
};
CLASS = BookmarkInfoController;
LANGUAGE = ObjC;
OUTLETS = {
OUTLETS = {
mBookmarkDescField = NSTextField;
mBookmarkLocationField = NSTextField;
mBookmarkNameField = NSTextField;
@ -27,7 +27,11 @@
};
SUPERCLASS = NSWindowController;
},
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
{
CLASS = FirstResponder;
LANGUAGE = ObjC;
SUPERCLASS = NSObject;
}
);
IBVersion = 1;
}

Просмотреть файл

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
@ -7,17 +7,17 @@
<key>IBEditorPositions</key>
<dict>
<key>513</key>
<string>664 539 400 292 0 0 1680 1028 </string>
<string>520 457 400 292 0 0 1440 878 </string>
<key>514</key>
<string>664 534 400 302 0 0 1680 1028 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
<string>489.0</string>
<key>IBLockedObjects</key>
<array>
<integer>130</integer>
</array>
<key>IBSystem Version</key>
<string>8P2137</string>
<string>9B18</string>
</dict>
</plist>

Двоичные данные
camino/resources/localized/English.lproj/BookmarkInfoPanel.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -1,9 +1,6 @@
"IssuedByHeaderFormat" = "Issued by: %@";
"ExpiresHeaderFormat" = "Expires: %@";
"ShortExpireDateFormat" = "%Y-%m-%d"; /* Year-month-day */
"ExpireDateFormat" = "%A, %B %d, %Y %H:%M:%S %Z"; /* Day, Month nn, Year h:m:s timezone */
"CertDetailsGroupHeader" = "Details";
"CertTrustGroupHeader" = "Trust Settings";

Просмотреть файл

@ -357,7 +357,6 @@
"Reveal in Bookmark Manager" = "Reveal in Bookmark Manager";
/* Page Info */
"PageInfoDateFormat" = "%x";
"WebSiteVerified" = "Website identity verified";
"WebSiteVerifiedMixed" = "Website identity verified, but not all content is secure";
"WebSiteNotVerified" = "Website identity not verified";

Просмотреть файл

@ -61,7 +61,7 @@ enum EBookmarkInfoViewType {
- (void)updateLastVisitField;
- (void)dockMenuChanged:(NSNotification *)aNote;
@end;
@end
@implementation BookmarkInfoController
@ -372,10 +372,12 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
lastVisitString = NSLocalizedString(@"BookmarkVisitedNever", nil);
}
else {
lastVisitString =
[lastVisit descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat]
timeZone:nil
locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
lastVisitString = [dateFormatter stringFromDate:lastVisit];
[dateFormatter release];
}
[mLastVisitField setStringValue:lastVisitString];

Просмотреть файл

@ -174,16 +174,16 @@ static PageInfoWindowController* gSingletonPageInfoController;
[mPageLocationField setStringValue:[inBrowserView currentURI]];
NSDate* lastModDate = [inBrowserView pageLastModifiedDate];
if (lastModDate)
{
NSString* dateFormat = NSLocalizedString(@"PageInfoDateFormat", @"");
NSDictionary* curCalendarLocale = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
NSString* dateString = [lastModDate descriptionWithCalendarFormat:dateFormat
timeZone:nil
locale:curCalendarLocale];
[mPageModDateField setStringValue:dateString];
NSString* dateString = @"";
if (lastModDate) {
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
dateString = [dateFormatter stringFromDate:lastModDate];
[dateFormatter release];
}
[mPageModDateField setStringValue:dateString];
}
- (void)updateSecurityInfoFromBrowserView:(CHBrowserView*)inBrowserView

Просмотреть файл

@ -74,9 +74,9 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
// Custom formatter for relative date formatting
@interface RelativeDateFormatter : NSDateFormatter
{
CFDateFormatterRef mTimeFormatter; // strong
CFDateFormatterRef mDateTimeFormatter; // strong
NSDateFormatter* mWeekdayFormatter; // strong
NSDateFormatter* mTimeFormatter; // strong
NSDateFormatter* mDateTimeFormatter; // strong
NSDateFormatter* mWeekdayFormatter; // strong
}
@end
@ -742,37 +742,31 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
#pragma mark -
// TODO: Once we are 10.4+ the CFDateFormatters can be replaced with
// NSDateFormatters using NSDateFormatterBehavior10_4 behavior.
@implementation RelativeDateFormatter
- (id)init
{
if ((self = [super init])) {
CFLocaleRef userLocale = CFLocaleCopyCurrent();
if (userLocale) {
mTimeFormatter = CFDateFormatterCreate(NULL,
userLocale,
kCFDateFormatterNoStyle,
kCFDateFormatterShortStyle);
mDateTimeFormatter = CFDateFormatterCreate(NULL,
userLocale,
kCFDateFormatterMediumStyle,
kCFDateFormatterShortStyle);
mWeekdayFormatter = [[NSDateFormatter alloc] initWithDateFormat:@"%a"
allowNaturalLanguage:NO];
CFRelease(userLocale);
}
mTimeFormatter = [[NSDateFormatter alloc] init];
[mTimeFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[mTimeFormatter setDateStyle:NSDateFormatterNoStyle];
[mTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
mDateTimeFormatter = [[NSDateFormatter alloc] init];
[mDateTimeFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[mDateTimeFormatter setDateStyle:NSDateFormatterMediumStyle];
[mDateTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
mWeekdayFormatter = [[NSDateFormatter alloc] initWithDateFormat:@"%A"
allowNaturalLanguage:NO];
}
return self;
}
- (void)dealloc
{
if (mTimeFormatter)
CFRelease(mTimeFormatter);
if (mDateTimeFormatter)
CFRelease(mDateTimeFormatter);
[mTimeFormatter release];
[mDateTimeFormatter release];
[mWeekdayFormatter release];
[super dealloc];
}
@ -782,12 +776,13 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
if (!anObject)
return @"";
if (mTimeFormatter && mDateTimeFormatter) {
if (mTimeFormatter && mDateTimeFormatter &&
[anObject isKindOfClass:[NSDate class]]) {
int day = [[anObject dateWithCalendarFormat:nil timeZone:nil] dayOfCommonEra];
int today = [[NSCalendarDate calendarDate] dayOfCommonEra];
NSString* dayPrefix = nil;
CFDateFormatterRef dateFormatter;
NSDateFormatter* dateFormatter;
if (day == today) {
dayPrefix = NSLocalizedString(@"Today", nil);
dateFormatter = mTimeFormatter;
@ -803,15 +798,13 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
else if (day > (today - 7)) {
// show the shortened weekday for recent dates
dayPrefix = [mWeekdayFormatter stringForObjectValue:anObject];
dateFormatter = mDateTimeFormatter;
dateFormatter = mTimeFormatter;
}
else {
dateFormatter = mDateTimeFormatter;
}
NSString* result = [(NSString*)CFDateFormatterCreateStringWithDate(NULL,
dateFormatter,
(CFDateRef)anObject) autorelease];
NSString* result = [dateFormatter stringFromDate:(NSDate*)anObject];
if (dayPrefix)
result = [NSString stringWithFormat:@"%@ %@", dayPrefix, result];

Просмотреть файл

@ -291,7 +291,7 @@ static BrowserSecurityUIProvider* gBrowserSecurityUIProvider;
[mTitleField setStringValue:title];
NSString* msgFormat = NSLocalizedStringFromTable(@"ExpiredCertMessageFormat", @"CertificateDialogs", @"");
NSString* msg = [NSString stringWithFormat:msgFormat, [inCert commonName], [inCert longExpiresString]];
NSString* msg = [NSString stringWithFormat:msgFormat, [inCert commonName], [inCert expiresString]];
[mMessageField setStringValue:msg];
[mCertificateView setDetailsInitiallyExpanded:NO];

Просмотреть файл

@ -113,12 +113,10 @@ extern NSString* const CertificateChangedNotificationName;
- (BOOL)isUntrustedRootCACert;
- (NSDate*)expiresDate;
- (NSString*)shortExpiresString;
- (NSString*)longExpiresString;
- (NSString*)expiresString;
- (NSDate*)validFromDate;
- (NSString*)shortValidFromString;
- (NSString*)longValidFromString;
- (NSString*)validFromString;
- (BOOL)isExpired;
- (BOOL)isNotYetValid;

Просмотреть файл

@ -63,7 +63,7 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
@interface CertificateItem(Private)
- (NSString*)stringForDate:(NSDate*)inDate withFormat:(NSString*)inFormat;
- (NSString*)stringForDate:(NSDate*)inDate;
- (PRUint32)validityForUsage:(PRUint32)inUsage;
- (PRUint32)generalValidity; // whether it's verified for at least one usage
@ -401,14 +401,9 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
return nil;
}
- (NSString*)shortExpiresString
- (NSString*)expiresString
{
return [self stringForDate:[self expiresDate] withFormat:NSLocalizedStringFromTable(@"ShortExpireDateFormat", @"CertificateDialogs", @"")];
}
- (NSString*)longExpiresString
{
return [self stringForDate:[self expiresDate] withFormat:NSLocalizedStringFromTable(@"ExpireDateFormat", @"CertificateDialogs", @"")];
return [self stringForDate:[self expiresDate]];
}
- (NSDate*)validFromDate
@ -423,14 +418,9 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
return nil;
}
- (NSString*)shortValidFromString
- (NSString*)validFromString
{
return [self stringForDate:[self validFromDate] withFormat:NSLocalizedStringFromTable(@"ShortExpireDateFormat", @"CertificateDialogs", @"")];
}
- (NSString*)longValidFromString
{
return [self stringForDate:[self validFromDate] withFormat:NSLocalizedStringFromTable(@"ExpireDateFormat", @"CertificateDialogs", @"")];
return [self stringForDate:[self validFromDate]];
}
- (BOOL)isExpired
@ -489,12 +479,19 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
return nil;
}
- (NSString*)stringForDate:(NSDate*)inDate withFormat:(NSString*)inFormat
- (NSString*)stringForDate:(NSDate*)inDate
{
if (!inDate) return @"";
if (!inDate) {
return @"";
}
NSDictionary* curCalendarLocale = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
return [inDate descriptionWithCalendarFormat:inFormat timeZone:nil locale:curCalendarLocale];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
NSString* string = [dateFormatter stringFromDate:inDate];
[dateFormatter release];
return string;
}
- (PRUint32)validityForUsage:(PRUint32)inUsage

Просмотреть файл

@ -629,8 +629,12 @@ const float kGapUnderCheckboxLine = 3.0f;
// validity
[mDetailsItemsView addSubview:[self headerWithKey:@"Validity"]];
[mDetailsItemsView addSubview:[self lineWithLabelKey:@"NotBeforeLocalTime" data:[mCertItem longValidFromString] ignoreBlankLines:NO]];
[mDetailsItemsView addSubview:[self lineWithLabelKey:@"NotAfterLocalTime" data:[mCertItem longExpiresString] ignoreBlankLines:NO]];
[mDetailsItemsView addSubview:[self lineWithLabelKey:@"NotBeforeLocalTime"
data:[mCertItem validFromString]
ignoreBlankLines:NO]];
[mDetailsItemsView addSubview:[self lineWithLabelKey:@"NotAfterLocalTime"
data:[mCertItem expiresString]
ignoreBlankLines:NO]];
// signature
[mDetailsItemsView addSubview:[self lineWithLabelKey:@"SigAlgorithm" data:[mCertItem signatureAlgorithm] ignoreBlankLines:NO]];
@ -759,7 +763,7 @@ const float kGapUnderCheckboxLine = 3.0f;
// expiry info
NSRect expiryRect = NSMakeRect(headerFieldsLeftEdge, headerFieldYOffset, headerFieldWith, 100.0f);
formatString = NSLocalizedStringFromTable(@"ExpiresHeaderFormat", @"CertificateDialogs", @"");
NSString* expiryString = [NSString stringWithFormat:formatString, [mCertItem longExpiresString]];
NSString* expiryString = [NSString stringWithFormat:formatString, [mCertItem expiresString]];
NSTextField* expiryField = [self textFieldWithInitialFrame:[headerContainer subviewRectFromTopRelativeRect:expiryRect] stringValue:expiryString autoSizing:NO small:YES bold:NO];
[headerContainer addSubview:expiryField];
headerFieldYOffset += NSHeight([expiryField frame]) + kCertHeaderFieldVerticalGap;