2012-05-07 20:18:01 +00:00
|
|
|
//
|
|
|
|
// MPAppDelegate.m
|
|
|
|
// MasterPassword
|
|
|
|
//
|
|
|
|
// Created by Maarten Billemont on 24/11/11.
|
|
|
|
// Copyright (c) 2011 Lyndir. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MPAppDelegate_Shared.h"
|
2012-08-18 13:37:24 +00:00
|
|
|
#import "MPAppDelegate_Store.h"
|
2012-05-07 20:18:01 +00:00
|
|
|
|
2013-01-31 05:42:32 +00:00
|
|
|
@implementation MPAppDelegate_Shared {
|
|
|
|
NSManagedObjectID *_activeUserOID;
|
|
|
|
}
|
2012-05-11 20:45:05 +00:00
|
|
|
|
|
|
|
+ (MPAppDelegate_Shared *)get {
|
2012-06-08 21:46:13 +00:00
|
|
|
|
2012-05-11 15:04:51 +00:00
|
|
|
#if TARGET_OS_IPHONE
|
2012-05-11 20:45:05 +00:00
|
|
|
return (MPAppDelegate_Shared *)[UIApplication sharedApplication].delegate;
|
2012-05-07 20:18:01 +00:00
|
|
|
#elif defined (__MAC_OS_X_VERSION_MIN_REQUIRED)
|
2012-05-11 20:45:05 +00:00
|
|
|
return (MPAppDelegate_Shared *)[NSApplication sharedApplication].delegate;
|
2012-05-07 20:18:01 +00:00
|
|
|
#else
|
|
|
|
#error Unsupported OS.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-18 02:00:15 +00:00
|
|
|
- (MPUserEntity *)activeUserForThread {
|
2012-08-18 13:37:24 +00:00
|
|
|
|
2013-04-28 04:33:28 +00:00
|
|
|
return [self activeUserInContext:[MPAppDelegate_Shared managedObjectContextForThreadIfReady]];
|
2013-01-31 05:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (MPUserEntity *)activeUserInContext:(NSManagedObjectContext *)moc {
|
|
|
|
|
|
|
|
if (!_activeUserOID || !moc)
|
2012-08-19 07:34:49 +00:00
|
|
|
return nil;
|
|
|
|
|
2013-01-31 05:42:32 +00:00
|
|
|
NSError *error;
|
|
|
|
MPUserEntity *activeUser = (MPUserEntity *)[moc existingObjectWithID:_activeUserOID error:&error];
|
|
|
|
if (!activeUser)
|
2013-04-20 18:11:19 +00:00
|
|
|
err(@"Failed to retrieve active user: %@", error);
|
2013-01-31 05:42:32 +00:00
|
|
|
|
|
|
|
return activeUser;
|
2012-08-18 13:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setActiveUser:(MPUserEntity *)activeUser {
|
|
|
|
|
2013-01-31 05:42:32 +00:00
|
|
|
_activeUserOID = activeUser.objectID;
|
2012-08-18 13:37:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 20:18:01 +00:00
|
|
|
@end
|