implemented deliveryRepeatInterval handling, minor fixes and code cleanup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37651 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
znek 2014-01-31 12:08:13 +00:00
parent fc5e7d24d4
commit 501a14af4b
2 changed files with 54 additions and 9 deletions

View file

@ -1,3 +1,12 @@
2014-01-31 Marcus Mueller <znek@mulle-kybernetik.com>
* Source/NSUserNotification.m:
Implemented repetitions, moved "presented" flagging to the appropriate
method (subclassers may have different opinions about presentation,
i.e. gnustep-gui might want to prevent presentation if application
is already frontmost [the OSX behavior]). Improved -description
(similar to OSX's output, eases cross-platform debugging).
2014-01-30 Marcus Mueller <znek@mulle-kybernetik.com> 2014-01-30 Marcus Mueller <znek@mulle-kybernetik.com>
* Headers/Foundation/NSUserNotification.h: * Headers/Foundation/NSUserNotification.h:

View file

@ -33,8 +33,10 @@
#import "Foundation/NSUserNotification.h" #import "Foundation/NSUserNotification.h"
#import "Foundation/NSArray.h" #import "Foundation/NSArray.h"
#import "Foundation/NSBundle.h" #import "Foundation/NSBundle.h"
#import "Foundation/NSCalendar.h"
#import "Foundation/NSDate.h" #import "Foundation/NSDate.h"
#import "Foundation/NSString.h" #import "Foundation/NSString.h"
#import "Foundation/NSTimeZone.h"
@interface NSUserNotification () @interface NSUserNotification ()
@property (readwrite) NSDate *actualDeliveryDate; @property (readwrite) NSDate *actualDeliveryDate;
@ -68,12 +70,19 @@
- (NSString *)description - (NSString *)description
{ {
return [NSString stringWithFormat:@"<%s:%p> { title: \"%@\" " NSMutableString *d = [NSMutableString stringWithCapacity:80];
"informativeText: \"%@\" " [d appendFormat:@"<%s:%p< {", object_getClassName(self), self];
"actionButtonTitle: \"%@\" }", [d appendFormat:@" title: \"%@\"", self.title];
object_getClassName(self), self, [d appendFormat:@" informativeText: \"%@\"", self.informativeText];
self.title, self.informativeText, [d appendFormat:@" actionButtonTitle: \"%@\"", self.actionButtonTitle];
self.actionButtonTitle]; if (self.actualDeliveryDate)
{
[d appendFormat:@" actualDeliveryDate: %@", self.actualDeliveryDate];
[d appendFormat:@" presented: %s", self.presented ? "YES" : "NO"];
}
[d appendFormat:@" next delivery date: %@", self.deliveryDate];
[d appendString:@" }"];
return d;
} }
@end @end
@ -86,6 +95,7 @@
+ (Class) defaultUserNotificationCenterClass; + (Class) defaultUserNotificationCenterClass;
+ (void) setDefaultUserNotificationCenter: (NSUserNotificationCenter *)unc; + (void) setDefaultUserNotificationCenter: (NSUserNotificationCenter *)unc;
- (NSUserNotification *) deliveredNotificationWithUniqueId: (id)uniqueId; - (NSUserNotification *) deliveredNotificationWithUniqueId: (id)uniqueId;
- (NSDate *) nextDeliveryDateForNotification: (NSUserNotification *)un;
@end @end
@implementation NSUserNotificationCenter @implementation NSUserNotificationCenter
@ -137,7 +147,8 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
- (id) init - (id) init
{ {
if (nil != (self = self = [super init])) self = [super init];
if (self)
{ {
_scheduledNotifications = [[NSMutableArray alloc] init]; _scheduledNotifications = [[NSMutableArray alloc] init];
_deliveredNotifications = [[NSMutableArray alloc] init]; _deliveredNotifications = [[NSMutableArray alloc] init];
@ -178,7 +189,29 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
- (void) _deliverNotification: (NSUserNotification *)un - (void) _deliverNotification: (NSUserNotification *)un
{ {
NSLog(@"%s -- needs implementation", __PRETTY_FUNCTION__); un.presented = YES;
NSLog(@"NOTE: %@", un);
}
- (NSDate *) nextDeliveryDateForNotification: (NSUserNotification *)un
{
NSDateComponents *repeatInterval = un.deliveryRepeatInterval;
if (!repeatInterval)
return nil;
NSCalendar *cal = [[repeatInterval calendar] copy];
if (!cal)
cal = [[NSCalendar currentCalendar] copy];
if ([repeatInterval timeZone])
[cal setTimeZone:[repeatInterval timeZone]];
if (![cal timeZone])
[cal setTimeZone:[NSTimeZone localTimeZone]];
NSDate *nextDeliveryDate = [cal dateByAddingComponents: repeatInterval
toDate: un.actualDeliveryDate
options: 0];
RELEASE(cal);
return nextDeliveryDate;
} }
- (void) deliverNotification: (NSUserNotification *)un - (void) deliverNotification: (NSUserNotification *)un
@ -191,7 +224,9 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
actualDeliveryDate = [NSDate date]; actualDeliveryDate = [NSDate date];
un.actualDeliveryDate = actualDeliveryDate; un.actualDeliveryDate = actualDeliveryDate;
[_deliveredNotifications addObject: un]; [_deliveredNotifications addObject: un];
un.presented = YES; un.deliveryDate = [self nextDeliveryDateForNotification: un];
if (un.deliveryDate)
[self scheduleNotification: un];
if (self.delegate && [self.delegate respondsToSelector: if (self.delegate && [self.delegate respondsToSelector:
@selector(userNotificationCenter:didDeliverNotification:)]) @selector(userNotificationCenter:didDeliverNotification:)])
@ -200,6 +235,7 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
} }
} }
- (void) _removeDeliveredNotification: (NSUserNotification *)un - (void) _removeDeliveredNotification: (NSUserNotification *)un
{ {
} }