From 0e96185a936d794a80f1117415880312b42e80a0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 25 Apr 2008 22:23:31 +0000 Subject: [PATCH] the torrent url sheet will now disable the open button when there is no text; cleanup to the sleep code --- macosx/Controller.h | 1 + macosx/Controller.m | 39 ++++++++++++++----------------- macosx/English.lproj/MainMenu.xib | 38 ++++++++++++++++++++++++------ macosx/GroupsWindowController.m | 2 +- macosx/Torrent.m | 1 + 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index 5ef6d304d..8b968a302 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -99,6 +99,7 @@ typedef enum IBOutlet NSWindow * fURLSheetWindow; IBOutlet NSTextField * fURLSheetTextField; + IBOutlet NSButton * fURLSheetOpenButton; io_connect_t fRootPort; NSTimer * fTimer; diff --git a/macosx/Controller.m b/macosx/Controller.m index 446315385..2cccd652b 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -337,7 +337,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi //register for sleep notifications IONotificationPortRef notify; io_object_t iterator; - if ((fRootPort = IORegisterForSystemPower(self, & notify, sleepCallBack, & iterator)) != 0) + if ((fRootPort = IORegisterForSystemPower(self, & notify, sleepCallBack, &iterator))) CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopCommonModes); else NSLog(@"Could not IORegisterForSystemPower"); @@ -952,13 +952,17 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi [NSApp endSheet: fURLSheetWindow returnCode: 0]; } +- (void) controlTextDidChange: (NSNotification *) notification +{ + [fURLSheetOpenButton setEnabled: ![[fURLSheetTextField stringValue] isEqual: @""]]; +} + - (void) urlSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo { [fURLSheetTextField selectText: self]; if (returnCode != 1) return; - #warning disable OK button when blank NSString * urlString = [fURLSheetTextField stringValue]; if (![urlString isEqualToString: @""]) { @@ -2380,7 +2384,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi fSoundPlaying = NO; } --(void) watcher: (id) watcher receivedNotification: (NSString *) notification forPath: (NSString *) path +- (void) watcher: (id) watcher receivedNotification: (NSString *) notification forPath: (NSString *) path { if ([notification isEqualToString: UKFileWatcherWriteNotification]) { @@ -3676,31 +3680,25 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi { NSEnumerator * enumerator; Torrent * torrent; - BOOL allowSleep; switch (messageType) { case kIOMessageSystemWillSleep: - //close all connections before going to sleep and remember we should resume when we wake up - [fTorrents makeObjectsPerformSelector: @selector(sleep)]; - - //wait for running transfers to stop (5 second timeout) - NSDate * start = [NSDate date]; - BOOL timeUp = NO; - + //if there are any running transfers, wait 15 seconds for them to stop enumerator = [fTorrents objectEnumerator]; - while (!timeUp && (torrent = [enumerator nextObject])) - while ([torrent isActive] && !(timeUp = [start timeIntervalSinceNow] < -5.0)) + while ((torrent = [enumerator nextObject])) + if ([torrent isActive]) { - usleep(100000); - [torrent update]; + //stop all transfers (since some are active) before going to sleep and remember to resume when we wake up + [fTorrents makeObjectsPerformSelector: @selector(sleep)]; + sleep(15); + break; } IOAllowPowerChange(fRootPort, (long) messageArgument); break; case kIOMessageCanSystemSleep: - allowSleep = YES; if ([fDefaults boolForKey: @"SleepPrevent"]) { //prevent idle sleep unless no torrents are active @@ -3708,15 +3706,12 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi while ((torrent = [enumerator nextObject])) if ([torrent isActive] && ![torrent isStalled] && ![torrent isError]) { - allowSleep = NO; - break; + IOCancelPowerChange(fRootPort, (long) messageArgument); + return; } } - if (allowSleep) - IOAllowPowerChange(fRootPort, (long) messageArgument); - else - IOCancelPowerChange(fRootPort, (long) messageArgument); + IOAllowPowerChange(fRootPort, (long) messageArgument); break; case kIOMessageSystemHasPoweredOn: diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index b5aecb7c1..da038ef92 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -3,14 +3,15 @@ 1050 9C7010 - 648 + 652 949.26 352.00 YES - - + + + YES @@ -3941,7 +3942,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA {3.40282e+38, 3.40282e+38} {400, 177} - + 256 YES @@ -3974,7 +3975,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA YES - 67239424 + 604110336 134217728 Open @@ -4026,7 +4027,8 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - {{1, 9}, {400, 177}} + {400, 177} + {{0, 0}, {1680, 1028}} {400, 199} @@ -6237,6 +6239,22 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 3154 + + + fURLSheetOpenButton + + + + 3156 + + + + delegate + + + + 3157 + @@ -8525,7 +8543,9 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 1815.ImportedFromIB2 1846.IBPluginDependency 1846.ImportedFromIB2 + 1848.IBEditorWindowLastContentRect 1848.IBPluginDependency + 1848.IBWindowTemplateEditedContentRect 1848.ImportedFromIB2 1848.windowTemplate.hasMaxSize 1848.windowTemplate.hasMinSize @@ -9092,7 +9112,9 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA com.apple.InterfaceBuilder.CocoaPlugin + {{0, 818}, {400, 177}} com.apple.InterfaceBuilder.CocoaPlugin + {{0, 818}, {400, 177}} @@ -9445,7 +9467,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - 3154 + 3157 @@ -9624,6 +9646,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA fTotalDLImageView fTotalTorrentsField fTotalULField + fURLSheetOpenButton fURLSheetTextField fURLSheetWindow fUpdater @@ -9670,6 +9693,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA NSImageView NSTextField NSTextField + NSButton NSTextField NSWindow SUUpdater diff --git a/macosx/GroupsWindowController.m b/macosx/GroupsWindowController.m index ab7dea73f..49c4bdaa9 100644 --- a/macosx/GroupsWindowController.m +++ b/macosx/GroupsWindowController.m @@ -140,7 +140,7 @@ GroupsWindowController * fGroupsWindowInstance = nil; return NSDragOperationNone; } -- (BOOL) tableView: (NSTableView *) t acceptDrop: (id ) info row: (int) newRow +- (BOOL) tableView: (NSTableView *) tableView acceptDrop: (id ) info row: (int) newRow dropOperation: (NSTableViewDropOperation) operation { NSPasteboard * pasteboard = [info draggingPasteboard]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 16df32cf1..7c8f9dd1d 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1633,6 +1633,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * fFinishedSeeding = NO; fWaitToStart = waitToStart && [waitToStart boolValue]; + fResumeOnWake = NO; fOrderValue = orderValue ? [orderValue intValue] : tr_torrentCount(lib) - 1; fGroupValue = groupValue ? [groupValue intValue] : -1; -- 2.40.0