patch RC3: Index: ClockMenulet.h =================================================================== --- ClockMenulet.h (revisione 8428) +++ ClockMenulet.h (copia locale) @@ -23,6 +23,8 @@ #import <Foundation/NSObject.h> #import "../../EtoileMenulet.h" +#import <Foundation/NSCalendar.h> +#import <Foundation/NSDateFormatter.h> @class NSButton, NSTimer, NSWindow; @@ -31,8 +33,9 @@ NSTimer *timer; NSButton *view; NSWindow *calendarWindow; - - int hour, minute, day; + NSCalendar *gregorian; + NSDateFormatter *dateFormatter; + NSArray *shortDayName; } - (NSView *) menuletView; Index: ClockMenulet.m =================================================================== --- ClockMenulet.m (revisione 8428) +++ ClockMenulet.m (copia locale) @@ -27,38 +27,12 @@ #import <AppKit/NSButton.h> #import <AppKit/NSFont.h> #import <AppKit/NSWindow.h> - #import <Foundation/NSTimer.h> #import <Foundation/NSInvocation.h> -#import <Foundation/NSCalendarDate.h> #import <Foundation/NSString.h> #import <Foundation/NSBundle.h> #import <Foundation/NSUserDefaults.h> -static inline NSString * -ShortNameOfDay(int day) -{ - return [[[NSUserDefaults standardUserDefaults] - objectForKey: NSShortWeekDayNameArray] - objectAtIndex: day]; -} - -static inline NSString * -AMPMStringForHour(int hour) -{ - NSArray * AMPMArray = [[NSUserDefaults standardUserDefaults] - objectForKey: NSAMPMDesignation]; - - if (hour < 12) - { - return [AMPMArray objectAtIndex: 0]; - } - else - { - return [AMPMArray objectAtIndex: 1]; - } -} - @implementation ClockMenulet - (void) buttonAction: (id) sender @@ -93,6 +67,9 @@ - (void) dealloc { [timer invalidate]; + [gregorian release]; + [dateFormatter release]; + [shortDayName release]; TEST_RELEASE(view); DESTROY(calendarWindow); @@ -121,7 +98,10 @@ timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 invocation: inv repeats: YES]; - + gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"]; + shortDayName = [[NSArray alloc] initWithArray:[dateFormatter shortWeekdaySymbols]]; [self updateClock]; } @@ -130,47 +110,13 @@ - (void) updateClock { - NSCalendarDate * date; - int newHour, newMinute, newDay; - - date = [NSCalendarDate calendarDate]; - - // only redraw every minute - newHour = [date hourOfDay]; - newMinute = [date minuteOfHour]; - newDay = [date dayOfWeek]; - if (hour != newHour || minute != newMinute || day != newDay) - { - BOOL useAmPmTime = [[NSUserDefaults standardUserDefaults] - boolForKey: @"UseAMPMTimeIndication"]; - - hour = newHour; - minute = newMinute; - day = newDay; - - if (useAmPmTime) - { - int h = hour; - - if (h == 0) - { - h = 12; - } - else if (h > 12) - { - h -= 12; - } - - [view setTitle: [NSString stringWithFormat: - _(@"%@ %d:%02d %@"), ShortNameOfDay(day), h, minute, - AMPMStringForHour(hour)]]; - } - else - { - [view setTitle: [NSString stringWithFormat: _(@"%@ %d:%02d"), - ShortNameOfDay(day), hour, minute]]; - } - } + NSDate * date = [NSDate date]; + NSDateComponents *dateComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:date]; + + NSInteger weekDayNum = [dateComponents weekday]; + NSString *strDate = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle]; + NSString *dayNum = [dateFormatter stringFromDate:date]; + [view setTitle: [NSString stringWithFormat:@"%@ %@ %@", [shortDayName objectAtIndex:weekDayNum], [dayNum substringToIndex:2], strDate]]; } - (NSView *) menuletView
> From: thera...@sucs.org > Date: Wed, 5 Jun 2013 11:47:41 +0100 > To: etoile-dev@gna.org > Subject: Re: [Etoile-dev] EtoileMenuServer patch > > On 5 Jun 2013, at 11:41, Slex Sangiuliano <alex2...@hotmail.com> wrote: > > > + gregorian = [[NSCalendar alloc] > > initWithCalendarIdentifier:NSGregorianCalendar]; > > + dateFormatter = [[NSDateFormatter alloc] init]; > > + [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"]; > > + shortDayName = [dateFormatter shortWeekdaySymbols]; > > If this isn't using ARC, then you will need to put corresponding -release > messages in -dealloc. > > > + [gregorian release]; > > + [dateFormatter release]; > > Destroying them every second is probably not what you want to do... > > David > > > On 5 Jun 2013, at 11:41, Slex Sangiuliano <alex2...@hotmail.com> wrote: > > > + gregorian = [[NSCalendar alloc] > > initWithCalendarIdentifier:NSGregorianCalendar]; > > + dateFormatter = [[NSDateFormatter alloc] init]; > > + [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"]; > > + shortDayName = [dateFormatter shortWeekdaySymbols]; > > If this isn't using ARC, then you will need to put corresponding -release > messages in -dealloc. > > > + [gregorian release]; > > + [dateFormatter release]; > > Destroying them every second is probably not what you want to do... > > David > > > _______________________________________________ > Etoile-dev mailing list > Etoile-dev@gna.org > https://mail.gna.org/listinfo/etoile-dev
clock_menulaet_RC3.patch
Description: Binary data
_______________________________________________ Etoile-dev mailing list Etoile-dev@gna.org https://mail.gna.org/listinfo/etoile-dev