+- (IBAction)showPithosAbout:(id)sender {
+ [NSApp orderFrontStandardAboutPanel:sender];
+ [NSApp activateIgnoringOtherApps:YES];
+}
+
+- (void)sync {
+ if (!activated || ![pithosAccounts count])
+ return;
+ NSUInteger syncIndex;
+ BOOL syncPithosAccountFound = [pithosAccounts containsObject:syncPithosAccount];
+ if (syncPithosAccountFound)
+ syncIndex = [pithosAccounts indexOfObject:syncPithosAccount];
+
+ PithosAccount *singleSyncPithosAccount = nil;
+ for (PithosAccount *pithosAccount in pithosAccounts) {
+ if (!singleSyncPithosAccount && pithosAccount.active && pithosAccount.syncActive && pithosAccount.syncDaemon) {
+ singleSyncPithosAccount = pithosAccount;
+ } else if (singleSyncPithosAccount && pithosAccount.active && pithosAccount.syncActive && pithosAccount.syncDaemon) {
+ singleSyncPithosAccount = nil;
+ break;
+ }
+ }
+
+ if (syncPithosAccount && syncPithosAccount.active && syncPithosAccount.syncActive && syncPithosAccount.syncDaemon) {
+ // An active syncDaemon was previously syncing
+ if (singleSyncPithosAccount && [singleSyncPithosAccount isEqualTo:syncPithosAccount]) {
+ // It's the only one, sync again
+ [syncPithosAccount.syncDaemon startDaemon];
+ [syncPithosAccount.syncDaemon sync];
+ return;
+ } else if ([syncPithosAccount.syncDaemon isSyncing]) {
+ // It's still syncing, mark it as late and return
+ [syncPithosAccount.syncDaemon syncLate];
+ return;
+ }
+ }
+ PithosAccount *newSyncPithosAccount = nil;
+ if (syncPithosAccountFound) {
+ for (PithosAccount *pithosAccount in [pithosAccounts objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(syncIndex + 1, [pithosAccounts count] - syncIndex - 1)]]) {
+ if (pithosAccount.active && pithosAccount.syncActive && pithosAccount.syncDaemon) {
+ newSyncPithosAccount = pithosAccount;
+ break;
+ }
+ }
+ if (!newSyncPithosAccount) {
+ for (PithosAccount *pithosAccount in [pithosAccounts objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, syncIndex)]]) {
+ if (pithosAccount.active && pithosAccount.syncActive && pithosAccount.syncDaemon) {
+ newSyncPithosAccount = pithosAccount;
+ break;
+ }
+ }
+ }
+ } else {
+ for (PithosAccount *pithosAccount in pithosAccounts) {
+ if (pithosAccount.active && pithosAccount.syncActive && pithosAccount.syncDaemon) {
+ newSyncPithosAccount = pithosAccount;
+ break;
+ }
+ }
+ }
+ if (newSyncPithosAccount) {
+ // A different syncDaemon is found, sync it
+ self.syncPithosAccount = newSyncPithosAccount;
+ [syncPithosAccount.syncDaemon startDaemon];
+ [syncPithosAccount.syncDaemon sync];
+ } else if (syncPithosAccountFound && syncPithosAccount && syncPithosAccount.active && syncPithosAccount.syncActive && syncPithosAccount.syncDaemon) {
+ [syncPithosAccount.syncDaemon startDaemon];
+ [syncPithosAccount.syncDaemon sync];
+ } else {
+ self.syncPithosAccount = nil;
+ }
+}
+
+- (void)savePithosAccounts:(id)sender {
+ [userDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:pithosAccounts] forKey:@"pithosAccounts"];
+ [userDefaults synchronize];
+}
+
+- (void)removedPithosAccount:(PithosAccount *)removedPithosAccount {
+ if ([self.currentPithosAccount isEqualTo:removedPithosAccount]) {
+ for (PithosAccount *pithosAccount in pithosAccounts) {
+ if (pithosAccount.active) {
+ self.currentPithosAccount = pithosAccount;
+ self.pithosBrowserController.pithosAccountManager = currentPithosAccount;
+ self.pithosBrowserController.pithos = currentPithosAccount.pithos;
+ break;
+ }
+ }
+ if ([self.currentPithosAccount isEqualTo:removedPithosAccount]) {
+ self.activated = NO;
+ [self.pithosBrowserController.window close];
+ [self.pithosBrowserController resetBrowser];
+ self.currentPithosAccount = [pithosAccounts objectAtIndex:0];
+ self.pithosBrowserController.pithosAccountManager = currentPithosAccount;
+ }
+ }
+ if ([self.syncPithosAccount isEqualTo:removedPithosAccount])
+ self.syncPithosAccount = nil;
+}
+
+- (void)checkForUpdates {
+ @synchronized(self) {
+ if (!checkForUpdatesNotRunning)
+ return;
+ self.checkForUpdatesNotRunning = NO;
+ }
+ ASIHTTPRequest *checkForUpdatesRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"https://code.grnet.gr/projects/pithos-macos/repository/revisions/master/raw/pithos-macos/pithos-macos-Info.plist"]];
+ checkForUpdatesRequest.delegate = self;
+ checkForUpdatesRequest.didFinishSelector = @selector(checkForUpdatesRequestFinished:);
+ checkForUpdatesRequest.didFailSelector = @selector(checkForUpdatesRequestFailed:);
+ checkForUpdatesRequest.timeOutSeconds = 60;
+ checkForUpdatesRequest.numberOfTimesToRetryOnTimeout = 10;
+ [checkForUpdatesRequest startAsynchronous];