NotificationController.m (1480B)
1 // 2 // NotificationController.m 3 // uimac 4 // 5 // Created by Alan Schmitt on 02/02/06. 6 // Copyright 2006, see file COPYING for details. All rights reserved. 7 // 8 9 #import "NotificationController.h" 10 11 #define NOTIFY_UPDATE @"Scan finished" 12 #define NOTIFY_SYNC @"Synchronization finished" 13 14 /* Show a simple notification */ 15 static void simpleNotify(NSString *name, NSString *descFmt, NSString *profile); 16 17 @implementation NotificationController 18 19 - (void)awakeFromNib 20 { 21 [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; 22 } 23 24 - (void)updateFinishedFor: (NSString *)profile 25 { 26 simpleNotify(NOTIFY_UPDATE, 27 @"Profile '%@' is finished scanning for updates", 28 profile); 29 } 30 31 - (void)syncFinishedFor: (NSString *)profile { 32 simpleNotify(NOTIFY_SYNC, 33 @"Profile '%@' is finished synchronizing", 34 profile); 35 } 36 37 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{ 38 return YES; 39 } 40 41 @end 42 43 static void simpleNotify(NSString *name, NSString *descFmt, NSString *profile) 44 { 45 NSUserNotification *notification = [[NSUserNotification alloc] init]; 46 notification.title = name; 47 notification.informativeText = [NSString stringWithFormat:descFmt, profile]; 48 notification.soundName = NSUserNotificationDefaultSoundName; 49 [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; 50 }