+#pragma mark Callbacks
+
+- (void)loginItemsChanged {
+ NSURL *appURL = [[NSBundle mainBundle] bundleURL];
+ LSSharedFileListItemRef appItem = NULL;
+ NSArray *snapshot = (__bridge_transfer NSArray *)(LSSharedFileListCopySnapshot(loginItems, NULL));
+ for (id itemObject in snapshot) {
+ LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef)itemObject;
+ UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
+ CFURLRef currentItemURL = NULL;
+ LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, NULL);
+ if (currentItemURL && CFEqual(currentItemURL, (__bridge CFTypeRef)(appURL))) {
+ CFRelease(currentItemURL);
+ appItem = item;
+ break;
+ }
+ if (currentItemURL)
+ CFRelease(currentItemURL);
+ }
+
+ if (appItem && (!openAtLogin || !openAtLoginEnabled))
+ self.openAtLogin = YES;
+ else if (!appItem && (openAtLogin || !openAtLoginEnabled))
+ self.openAtLogin = NO;
+}
+
+void LSSharedFileListChanged(LSSharedFileListRef inList, void *context) {
+ pithos_macosAppDelegate *self = (__bridge id)context;
+ [self loginItemsChanged];
+}
+
+#pragma mark -
+#pragma mark Properties
+
+- (PithosBrowserController *)pithosBrowserController {
+ if (!pithosBrowserController) {
+ pithosBrowserController = [[PithosBrowserController alloc] init];
+ }
+ return pithosBrowserController;
+}
+
+- (PithosPreferencesController *)pithosPreferencesController {
+ if (!pithosPreferencesController) {
+ pithosPreferencesController = [[PithosPreferencesController alloc] init];
+ }
+ return pithosPreferencesController;
+}
+
+- (void)setOpenAtLogin:(BOOL)anOpenAtLogin {
+ if (!openAtLoginEnabled) {
+ openAtLogin = anOpenAtLogin;
+ } else if (anOpenAtLogin != openAtLogin) {
+ NSURL *appURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
+ LSSharedFileListItemRef appItem = NULL;
+ NSArray *snapshot = (__bridge_transfer NSArray *)(LSSharedFileListCopySnapshot(loginItems, NULL));
+ for (id itemObject in snapshot) {
+ LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef)itemObject;
+ UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
+ CFURLRef currentItemURL = NULL;
+ LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, NULL);
+ if (currentItemURL && CFEqual(currentItemURL, (__bridge CFTypeRef)(appURL))) {
+ CFRelease(currentItemURL);
+ appItem = item;
+ break;
+ }
+ if (currentItemURL)
+ CFRelease(currentItemURL);
+ }
+
+ if (anOpenAtLogin) {
+ if (!appItem)
+ LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, (__bridge CFURLRef)appURL, NULL, NULL);
+ openAtLogin = YES;
+ } else {
+ if (appItem)
+ LSSharedFileListItemRemove(loginItems, appItem);
+ openAtLogin = NO;
+ }
+ }
+}
+
+#pragma mark -