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:
Marcus Müller 2014-01-31 12:08:13 +00:00
parent b7fe9517ff
commit 08346adf1d
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>
* Headers/Foundation/NSUserNotification.h:

View file

@ -33,8 +33,10 @@
#import "Foundation/NSUserNotification.h"
#import "Foundation/NSArray.h"
#import "Foundation/NSBundle.h"
#import "Foundation/NSCalendar.h"
#import "Foundation/NSDate.h"
#import "Foundation/NSString.h"
#import "Foundation/NSTimeZone.h"
@interface NSUserNotification ()
@property (readwrite) NSDate *actualDeliveryDate;
@ -68,12 +70,19 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%s:%p> { title: \"%@\" "
"informativeText: \"%@\" "
"actionButtonTitle: \"%@\" }",
object_getClassName(self), self,
self.title, self.informativeText,
self.actionButtonTitle];
NSMutableString *d = [NSMutableString stringWithCapacity:80];
[d appendFormat:@"<%s:%p< {", object_getClassName(self), self];
[d appendFormat:@" title: \"%@\"", self.title];
[d appendFormat:@" informativeText: \"%@\"", self.informativeText];
[d appendFormat:@" 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
@ -86,6 +95,7 @@
+ (Class) defaultUserNotificationCenterClass;
+ (void) setDefaultUserNotificationCenter: (NSUserNotificationCenter *)unc;
- (NSUserNotification *) deliveredNotificationWithUniqueId: (id)uniqueId;
- (NSDate *) nextDeliveryDateForNotification: (NSUserNotification *)un;
@end
@implementation NSUserNotificationCenter
@ -137,7 +147,8 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
- (id) init
{
if (nil != (self = self = [super init]))
self = [super init];
if (self)
{
_scheduledNotifications = [[NSMutableArray alloc] init];
_deliveredNotifications = [[NSMutableArray alloc] init];
@ -178,7 +189,29 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
- (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
@ -191,7 +224,9 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
actualDeliveryDate = [NSDate date];
un.actualDeliveryDate = actualDeliveryDate;
[_deliveredNotifications addObject: un];
un.presented = YES;
un.deliveryDate = [self nextDeliveryDateForNotification: un];
if (un.deliveryDate)
[self scheduleNotification: un];
if (self.delegate && [self.delegate respondsToSelector:
@selector(userNotificationCenter:didDeliverNotification:)])
@ -200,6 +235,7 @@ static NSUserNotificationCenter *defaultUserNotificationCenter = nil;
}
}
- (void) _removeDeliveredNotification: (NSUserNotification *)un
{
}