Permalink
Browse files

Integration of client lookup and deregistering into Sample Desktop

  • Loading branch information...
1 parent 5faa09f commit 9bbfdfe40fca1700a134f3da87b00c84f8e38cde Marcus S. Zarra committed Jun 19, 2010
@@ -1,3 +1,6 @@
+#define zsSchemaIdentifier @"ZSyncSchemaIdentifier"
+#define ZSDaemonHandler [[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"ZSyncInstaller" ofType:@"bundle"]] principalClass]
+
@interface ZSyncDaemon : NSObject
{
@@ -263,7 +263,14 @@ + (void)startDaemon;
+ (NSManagedObjectContext*)managedObjectContext:(NSError**)error
{
- NSString *path = [[self myBundle] pathForResource:@"ZSyncModel" ofType:@"mom"];
+ NSBundle *appBundle = [NSBundle bundleWithPath:[self applicationPath]];
+ if (!appBundle) {
+ NSString *errorDesc = [NSString stringWithFormat:@"ZSyncDaemon is not installed: %@", [self applicationPath]];
+ NSDictionary *dictionary = [NSDictionary dictionaryWithObject:errorDesc forKey:NSLocalizedDescriptionKey];
+ *error = [NSError errorWithDomain:@"ZSync" code:1129 userInfo:dictionary];
+ return nil;
+ }
+ NSString *path = [appBundle pathForResource:@"ZSyncModel" ofType:@"mom"];
NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]];
if (!model) {
@@ -340,8 +347,6 @@ + (NSArray*)devicesRegisteredForSchema:(NSString*)schema error:(NSError**)error;
[deviceArray addObject:dict];
[dict release], dict = nil;
}
-
- [moc release], moc = nil;
return deviceArray;
}
@@ -1,6 +1,9 @@
@interface AppDelegate : NSObject <NSPersistentStoreCoordinatorSyncing>
{
+ NSPanel *clientSheet;
+ NSArray *clientList;
+ NSArrayController *clientListController;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
@@ -12,6 +15,10 @@
@property (nonatomic, retain) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet NSPanel *syncPanel;
+@property (nonatomic, retain) IBOutlet NSArrayController *clientListController;
+@property (nonatomic, retain) IBOutlet NSPanel *clientSheet;
+
+@property (nonatomic, retain) NSArray *clientList;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@@ -23,5 +30,8 @@
- (IBAction)addData:(id)sender;
- (IBAction)changeData:(id)sender;
- (IBAction)performSync:(id)sender;
+- (IBAction)showClients:(id)sender;
+- (IBAction)closeClients:(id)sender;
+- (IBAction)deregisterClient:(id)sender;
@end
@@ -10,9 +10,6 @@ - (IBAction)performSync:(id)sender;
@implementation AppDelegate
-@synthesize window;
-@synthesize syncPanel;
-
- (NSString*)applicationSupportDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
@@ -69,10 +66,9 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
- (void)validateZSync;
{
- Class zsync = [[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"ZSyncInstaller" ofType:@"bundle"]] principalClass];
NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleDesktop" ofType:@"zsyncPlugin"];
NSError *error = nil;
- ZAssert([zsync installPluginAtPath:path intoDaemonWithError:&error], @"Error installing plugin: %@", [error userInfo]);
+ ZAssert([ZSDaemonHandler installPluginAtPath:path intoDaemonWithError:&error], @"Error installing plugin: %@", [error userInfo]);
DLog(@"validation complete");
}
@@ -347,6 +343,33 @@ - (IBAction)saveAction:(id)sender
ZAssert([[self managedObjectContext] save:&error], @"Error saving context: %@", [error localizedDescription]);
}
+- (IBAction)showClients:(id)sender;
+{
+ NSBundle *pluginBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"SampleDesktop" ofType:@"zsyncPlugin"]];
+ NSString *schema = [[pluginBundle infoDictionary] objectForKey:zsSchemaIdentifier];
+ NSError *error = nil;
+ [self setClientList:[ZSDaemonHandler devicesRegisteredForSchema:schema error:&error]];
+ ZAssert(!error, @"Error fetching registered clients: %@\n%@", [error localizedDescription], [error userInfo]);
+
+ [NSApp beginSheet:[self clientSheet] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:nil];
+}
+
+- (IBAction)closeClients:(id)sender;
+{
+ [NSApp endSheet:[self clientSheet]];
+ [[self clientSheet] orderOut:nil];
+}
+
+- (IBAction)deregisterClient:(id)sender;
+{
+ id selectedDict = [[[self clientListController] selectedObjects] lastObject];
+ if (!selectedDict) return;
+
+ NSString *uuid = [selectedDict objectForKey:@"uuid"];
+ NSError *error = nil;
+ ZAssert([ZSDaemonHandler deregisterDeviceForUUID:uuid error:&error], @"Error deregistering device: %@\n%@", [error localizedDescription], [error userInfo]);
+}
+
#pragma mark -
#pragma mark NSPersistentStoreCoordinatorSyncing
@@ -365,4 +388,10 @@ - (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator d
DLog(@"sync complete");
}
+@synthesize clientSheet;
+@synthesize clientList;
+@synthesize clientListController;
+@synthesize window;
+@synthesize syncPanel;
+
@end
@@ -50,8 +50,8 @@
PBXTargetDataSource_PrimaryAttribute,
);
};
- PBXPerProjectTemplateStateSaveDate = 298588859;
- PBXWorkspaceStateSaveDate = 298588859;
+ PBXPerProjectTemplateStateSaveDate = 298599608;
+ PBXWorkspaceStateSaveDate = 298599608;
};
sourceControlManager = B6457E2A10B058B000A96714 /* Source Control */;
userBuildSettings = {
@@ -18,5 +18,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
+ <key>ZSyncSchemaIdentifier</key>
+ <string>com.zarrastudios.zsync.SampleSchema</string>
</dict>
</plist>
Oops, something went wrong.

0 comments on commit 9bbfdfe

Please sign in to comment.