Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 18 | */ |
Alexandre Lision | b9f3f94 | 2016-07-23 14:29:33 -0400 | [diff] [blame] | 19 | #import <SystemConfiguration/SystemConfiguration.h> |
| 20 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 21 | #import "AppDelegate.h" |
| 22 | |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 23 | #import <callmodel.h> |
Edric Milaret | 8131541 | 2015-05-13 15:14:56 -0400 | [diff] [blame] | 24 | #import <qapplication.h> |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 25 | #import <accountmodel.h> |
| 26 | #import <protocolmodel.h> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 27 | #import <media/recordingmodel.h> |
| 28 | #import <media/textrecording.h> |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 29 | #import <QItemSelectionModel> |
| 30 | #import <account.h> |
Kateryna Kostiuk | abf4e27 | 2017-04-18 14:18:00 -0400 | [diff] [blame] | 31 | #import <AvailableAccountModel.h> |
| 32 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 33 | |
Alexandre Lision | 3d4143a | 2015-06-10 14:27:49 -0400 | [diff] [blame] | 34 | #if ENABLE_SPARKLE |
| 35 | #import <Sparkle/Sparkle.h> |
| 36 | #endif |
| 37 | |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 38 | #import "Constants.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 39 | #import "RingWizardWC.h" |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 40 | #import "DialpadWC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 41 | |
Alexandre Lision | 3d4143a | 2015-06-10 14:27:49 -0400 | [diff] [blame] | 42 | #if ENABLE_SPARKLE |
| 43 | @interface AppDelegate() <SUUpdaterDelegate> |
| 44 | #else |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 45 | @interface AppDelegate() |
Alexandre Lision | 3d4143a | 2015-06-10 14:27:49 -0400 | [diff] [blame] | 46 | #endif |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 47 | |
| 48 | @property RingWindowController* ringWindowController; |
| 49 | @property RingWizardWC* wizard; |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 50 | @property DialpadWC* dialpad; |
Alexandre Lision | b9f3f94 | 2016-07-23 14:29:33 -0400 | [diff] [blame] | 51 | @property (nonatomic, strong) dispatch_queue_t scNetworkQueue; |
| 52 | @property (nonatomic, assign) SCNetworkReachabilityRef currentReachability; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 53 | |
| 54 | @end |
| 55 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 56 | @implementation AppDelegate |
| 57 | |
| 58 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 59 | [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"]; |
| 60 | |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 61 | [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; |
| 62 | |
Edric Milaret | 8131541 | 2015-05-13 15:14:56 -0400 | [diff] [blame] | 63 | NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager]; |
| 64 | [appleEventManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; |
| 65 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 66 | if([self checkForRingAccount]) { |
| 67 | [self showMainWindow]; |
| 68 | } else { |
| 69 | [self showWizard]; |
| 70 | } |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 71 | [self connect]; |
Alexandre Lision | b9f3f94 | 2016-07-23 14:29:33 -0400 | [diff] [blame] | 72 | |
| 73 | dispatch_queue_t queue = NULL; |
| 74 | queue = dispatch_queue_create("scNetworkReachability", DISPATCH_QUEUE_SERIAL); |
| 75 | [self setScNetworkQueue:queue]; |
| 76 | [self beginObservingReachabilityStatus]; |
| 77 | } |
| 78 | |
| 79 | - (void) beginObservingReachabilityStatus |
| 80 | { |
| 81 | SCNetworkReachabilityRef reachabilityRef = NULL; |
| 82 | |
| 83 | void (^callbackBlock)(SCNetworkReachabilityFlags) = ^(SCNetworkReachabilityFlags flags) { |
| 84 | BOOL reachable = (flags & kSCNetworkReachabilityFlagsReachable) != 0; |
| 85 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 86 | AccountModel::instance().slotConnectivityChanged(); |
| 87 | }]; |
| 88 | }; |
| 89 | |
| 90 | SCNetworkReachabilityContext context = { |
| 91 | .version = 0, |
| 92 | .info = (void *)CFBridgingRetain(callbackBlock), |
| 93 | .release = CFRelease |
| 94 | }; |
| 95 | |
| 96 | reachabilityRef = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "test"); |
| 97 | if (SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)){ |
| 98 | if (!SCNetworkReachabilitySetDispatchQueue(reachabilityRef, [self scNetworkQueue]) ){ |
| 99 | // Remove our callback if we can't use the queue |
| 100 | SCNetworkReachabilitySetCallback(reachabilityRef, NULL, NULL); |
| 101 | } |
| 102 | [self setCurrentReachability:reachabilityRef]; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | - (void) endObsvervingReachabilityStatusForHost:(NSString *)__unused host |
| 107 | { |
| 108 | // Un-set the dispatch queue |
| 109 | if (SCNetworkReachabilitySetDispatchQueue([self currentReachability], NULL) ){ |
| 110 | SCNetworkReachabilitySetCallback([self currentReachability], NULL, NULL); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static void ReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkConnectionFlags flags, void* info) |
| 115 | { |
| 116 | void (^callbackBlock)(SCNetworkReachabilityFlags) = (__bridge id)info; |
| 117 | callbackBlock(flags); |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | - (void) connect |
| 121 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 122 | QObject::connect(&CallModel::instance(), |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 123 | &CallModel::incomingCall, |
| 124 | [=](Call* call) { |
Kateryna Kostiuk | abf4e27 | 2017-04-18 14:18:00 -0400 | [diff] [blame] | 125 | // on incoming call set selected account match call destination account |
| 126 | if (call->account()) { |
| 127 | QModelIndex index = call->account()->index(); |
| 128 | index = AvailableAccountModel::instance().mapFromSource(index); |
| 129 | |
| 130 | AvailableAccountModel::instance().selectionModel()->setCurrentIndex(index, |
| 131 | QItemSelectionModel::ClearAndSelect); |
| 132 | } |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 133 | BOOL shouldComeToForeground = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::WindowBehaviour]; |
| 134 | BOOL shouldNotify = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::Notifications]; |
Alexandre Lision | 61d78a4 | 2015-10-06 11:22:47 -0400 | [diff] [blame] | 135 | if (shouldComeToForeground) { |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 136 | [NSApp activateIgnoringOtherApps:YES]; |
Alexandre Lision | 61d78a4 | 2015-10-06 11:22:47 -0400 | [diff] [blame] | 137 | if ([self.ringWindowController.window isMiniaturized]) { |
| 138 | [self.ringWindowController.window deminiaturize:self]; |
| 139 | } |
| 140 | } |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 141 | |
| 142 | if(shouldNotify) { |
| 143 | [self showIncomingNotification:call]; |
| 144 | } |
| 145 | }); |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 146 | |
| 147 | |
Alexandre Lision | 08e7214 | 2016-01-19 13:29:36 -0500 | [diff] [blame] | 148 | QObject::connect(&Media::RecordingModel::instance(), |
| 149 | &Media::RecordingModel::unreadMessagesCountChanged, |
| 150 | [=](int unreadCount) { |
| 151 | NSDockTile *tile = [[NSApplication sharedApplication] dockTile]; |
| 152 | NSString* label = unreadCount ? [NSString stringWithFormat:@"%d", unreadCount]: @""; |
| 153 | [tile setBadgeLabel:label]; |
Alexandre Lision | ef32456 | 2016-01-21 13:23:21 -0500 | [diff] [blame] | 154 | [NSApp requestUserAttention:NSCriticalRequest]; |
Alexandre Lision | 08e7214 | 2016-01-19 13:29:36 -0500 | [diff] [blame] | 155 | }); |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 156 | |
| 157 | QObject::connect(&Media::RecordingModel::instance(), |
| 158 | &Media::RecordingModel::newTextMessage, |
| 159 | [=](Media::TextRecording* t, ContactMethod* cm) { |
| 160 | |
| 161 | BOOL shouldNotify = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::Notifications]; |
| 162 | auto qIdx = t->instantTextMessagingModel()->index(t->instantTextMessagingModel()->rowCount()-1, 0); |
| 163 | |
| 164 | // Don't show a notification if we are sending the text OR window already has focus OR user disabled notifications |
| 165 | if(qvariant_cast<Media::Media::Direction>(qIdx.data((int)Media::TextRecording::Role::Direction)) == Media::Media::Direction::OUT |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 166 | || self.ringWindowController.window.isMainWindow || !shouldNotify) |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 167 | return; |
| 168 | |
| 169 | NSUserNotification* notification = [[NSUserNotification alloc] init]; |
| 170 | |
Alexandre Lision | c818011 | 2016-01-27 11:27:50 -0500 | [diff] [blame] | 171 | NSString* localizedTitle = [NSString stringWithFormat:NSLocalizedString(@"Message from %@", @"Message from {Name}"), qIdx.data((int)Media::TextRecording::Role::AuthorDisplayname).toString().toNSString()]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 172 | |
| 173 | [notification setTitle:localizedTitle]; |
| 174 | [notification setSoundName:NSUserNotificationDefaultSoundName]; |
| 175 | [notification setSubtitle:qIdx.data().toString().toNSString()]; |
| 176 | |
| 177 | [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; |
| 178 | }); |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | - (void) showIncomingNotification:(Call*) call{ |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 182 | NSUserNotification* notification = [[NSUserNotification alloc] init]; |
Alexandre Lision | c818011 | 2016-01-27 11:27:50 -0500 | [diff] [blame] | 183 | NSString* localizedTitle = [NSString stringWithFormat: |
| 184 | NSLocalizedString(@"Incoming call from %@", @"Incoming call from {Name}"), call->peerName().toNSString()]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 185 | [notification setTitle:localizedTitle]; |
| 186 | [notification setSoundName:NSUserNotificationDefaultSoundName]; |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 187 | |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 188 | // try to activate action button |
| 189 | @try { |
| 190 | [notification setValue:@YES forKey:@"_showsButtons"]; |
| 191 | } |
| 192 | @catch (NSException *exception) { |
| 193 | // private API _showsButtons has changed... |
| 194 | NSLog(@"Action button not activable on notification"); |
| 195 | } |
| 196 | [notification setActionButtonTitle:NSLocalizedString(@"Refuse", @"Button Action")]; |
| 197 | |
Alexandre Lision | e404149 | 2015-03-20 18:20:43 -0400 | [diff] [blame] | 198 | [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Alexandre Lision | 3460703 | 2016-02-08 16:16:49 -0500 | [diff] [blame] | 201 | - (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification |
| 202 | { |
| 203 | if(notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) { |
| 204 | CallModel::instance().selectedCall() << Call::Action::REFUSE; |
| 205 | } else { |
| 206 | [NSApp activateIgnoringOtherApps:YES]; |
| 207 | if ([self.ringWindowController.window isMiniaturized]) { |
| 208 | [self.ringWindowController.window deminiaturize:self]; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 213 | - (void) showWizard |
| 214 | { |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 215 | if(self.wizard == nil) { |
| 216 | self.wizard = [[RingWizardWC alloc] initWithWindowNibName:@"RingWizard"]; |
| 217 | } |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 218 | [self.wizard.window makeKeyAndOrderFront:self]; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | - (void) showMainWindow |
| 222 | { |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 223 | if(self.ringWindowController == nil) { |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 224 | self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow"]; |
Alexandre Lision | b3f7ed6 | 2015-08-17 11:53:13 -0400 | [diff] [blame] | 225 | } |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 226 | [self.ringWindowController.window makeKeyAndOrderFront:self]; |
| 227 | } |
| 228 | |
Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 229 | - (void) showDialpad |
| 230 | { |
| 231 | if (self.dialpad == nil) { |
| 232 | self.dialpad = [[DialpadWC alloc] initWithWindowNibName:@"Dialpad"]; |
| 233 | } |
| 234 | [self.dialpad.window makeKeyAndOrderFront:self]; |
| 235 | } |
| 236 | |
| 237 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 238 | - (BOOL) checkForRingAccount |
| 239 | { |
Alexandre Lision | a1f07bf | 2015-07-28 10:30:55 -0400 | [diff] [blame] | 240 | BOOL foundRingAcc = NO; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 241 | for (int i = 0 ; i < AccountModel::instance().rowCount() ; ++i) { |
| 242 | QModelIndex idx = AccountModel::instance().index(i); |
| 243 | Account* acc = AccountModel::instance().getAccountByModelIndex(idx); |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 244 | if(acc->protocol() == Account::Protocol::RING && !acc->isNew()) { |
Alexandre Lision | a1f07bf | 2015-07-28 10:30:55 -0400 | [diff] [blame] | 245 | if (acc->displayName().isEmpty()) |
| 246 | acc->setDisplayName(acc->alias()); |
| 247 | foundRingAcc = YES; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 248 | } |
| 249 | } |
Alexandre Lision | a1f07bf | 2015-07-28 10:30:55 -0400 | [diff] [blame] | 250 | return foundRingAcc; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Alexandre Lision | 18e1fcd | 2015-08-04 14:38:42 -0400 | [diff] [blame] | 253 | -(void)applicationWillFinishLaunching:(NSNotification *)aNotification |
| 254 | { |
| 255 | NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; |
| 256 | [appleEventManager setEventHandler:self |
| 257 | andSelector:@selector(handleGetURLEvent:withReplyEvent:) |
| 258 | forEventClass:kInternetEventClass andEventID:kAEGetURL]; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Recognized patterns: |
| 263 | * - ring:<hash> |
| 264 | * - ring://<hash> |
| 265 | */ |
| 266 | - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent |
| 267 | { |
| 268 | NSString* query = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; |
| 269 | NSURL* url = [[NSURL alloc] initWithString:query]; |
| 270 | NSString* ringID = [url host]; |
| 271 | if (!ringID) { |
| 272 | //not a valid NSURL, try to parse query directly |
| 273 | ringID = [query substringFromIndex:@"ring:".length]; |
| 274 | } |
| 275 | |
| 276 | // check for a valid ring hash |
| 277 | NSCharacterSet *hexSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789abcdefABCDEF"]; |
| 278 | BOOL valid = [[ringID stringByTrimmingCharactersInSet:hexSet] isEqualToString:@""]; |
| 279 | |
| 280 | if(valid && ringID.length == 40) { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 281 | Call* c = CallModel::instance().dialingCall(); |
Alexandre Lision | 18e1fcd | 2015-08-04 14:38:42 -0400 | [diff] [blame] | 282 | c->setDialNumber(QString::fromNSString([NSString stringWithFormat:@"ring:%@",ringID])); |
| 283 | c << Call::Action::ACCEPT; |
| 284 | } else { |
| 285 | NSAlert *alert = [[NSAlert alloc] init]; |
| 286 | [alert addButtonWithTitle:@"OK"]; |
| 287 | [alert setMessageText:@"Error"]; |
| 288 | [alert setInformativeText:@"ringID cannot be read from this URL."]; |
| 289 | [alert setAlertStyle:NSWarningAlertStyle]; |
| 290 | [alert runModal]; |
| 291 | } |
| 292 | } |
| 293 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 294 | - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag |
| 295 | { |
| 296 | if([self checkForRingAccount]) { |
| 297 | [self showMainWindow]; |
| 298 | } else { |
| 299 | [self showWizard]; |
| 300 | } |
| 301 | return YES; |
| 302 | } |
| 303 | |
Edric Milaret | 8131541 | 2015-05-13 15:14:56 -0400 | [diff] [blame] | 304 | - (void)handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent |
| 305 | { |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 306 | [self cleanExit]; |
Edric Milaret | 8131541 | 2015-05-13 15:14:56 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | -(void)applicationWillTerminate:(NSNotification *)notification |
| 310 | { |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 311 | [self cleanExit]; |
| 312 | } |
| 313 | |
| 314 | - (void) cleanExit |
| 315 | { |
| 316 | [self.wizard close]; |
| 317 | [self.ringWindowController close]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 318 | delete CallModel::instance().QObject::parent(); |
Edric Milaret | 8131541 | 2015-05-13 15:14:56 -0400 | [diff] [blame] | 319 | [[NSApplication sharedApplication] terminate:self]; |
| 320 | } |
| 321 | |
Alexandre Lision | 3d4143a | 2015-06-10 14:27:49 -0400 | [diff] [blame] | 322 | #if ENABLE_SPARKLE |
| 323 | |
Alexandre Lision | 76d5969 | 2016-01-20 18:06:05 -0500 | [diff] [blame] | 324 | #pragma mark - Sparkle delegate |
Alexandre Lision | 3d4143a | 2015-06-10 14:27:49 -0400 | [diff] [blame] | 325 | |
| 326 | - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update |
| 327 | { |
| 328 | [NSApp activateIgnoringOtherApps:YES]; |
| 329 | } |
| 330 | |
| 331 | - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle |
| 332 | { |
| 333 | return YES; |
| 334 | } |
| 335 | |
| 336 | - (BOOL)updaterShouldRelaunchApplication:(SUUpdater *)updater |
| 337 | { |
| 338 | return YES; |
| 339 | } |
| 340 | |
| 341 | - (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error |
| 342 | { |
| 343 | NSLog(@"Error:%@", error.localizedDescription); |
| 344 | } |
| 345 | |
| 346 | #endif |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 347 | @end |