Changeset 498 for trunk/macosx/Controller.m
- Timestamp:
- Jul 1, 2006, 10:06:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.m
r497 r498 1033 1033 - (void) globalStartSettingChange: (NSNotification *) notification 1034 1034 { 1035 #warning redo 1035 [self attemptToStartMultipleAuto: fTorrents]; 1036 1037 [self updateUI: nil]; 1038 [self reloadInspector: nil]; 1039 } 1040 1041 - (void) torrentStartSettingChange: (NSNotification *) notification 1042 { 1043 [self attemptToStartMultipleAuto: [notification object]]; 1044 1045 [self updateUI: nil]; 1046 [self reloadInspector: nil]; 1047 [self updateTorrentHistory]; 1048 } 1049 1050 //will try to start, taking into consideration the start preference 1051 - (void) attemptToStartAuto: (Torrent *) torrent 1052 { 1053 [self attemptToStartMultipleAuto: [NSArray arrayWithObject: torrent]]; 1054 } 1055 1056 - (void) attemptToStartMultipleAuto: (NSArray *) torrents 1057 { 1036 1058 NSString * startSetting = [fDefaults stringForKey: @"StartSetting"]; 1037 1038 1059 if ([startSetting isEqualToString: @"Start"]) 1039 1060 { 1040 NSEnumerator * enumerator = [ fTorrents objectEnumerator];1061 NSEnumerator * enumerator = [torrents objectEnumerator]; 1041 1062 Torrent * torrent; 1042 1063 while ((torrent = [enumerator nextObject])) 1043 1064 if ([torrent waitingToStart]) 1044 1065 [torrent startTransfer]; 1045 } 1046 else if ([startSetting isEqualToString: @"Wait"]) 1047 { 1048 NSMutableArray * waitingTorrents = [[NSMutableArray alloc] initWithCapacity: [fTorrents count]]; 1049 1050 int amountToStart = [fDefaults integerForKey: @"WaitToStartNumber"]; 1051 1052 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1053 Torrent * torrent; 1054 while ((torrent = [enumerator nextObject])) 1066 1067 return; 1068 } 1069 else if (![startSetting isEqualToString: @"Wait"]) 1070 return; 1071 else; 1072 1073 //sort torrents by order value 1074 NSArray * sortedTorrents; 1075 if ([torrents count] > 1) 1076 { 1077 NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: 1078 @"orderValue" ascending: YES] autorelease]; 1079 NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil]; 1080 1081 sortedTorrents = [torrents sortedArrayUsingDescriptors: descriptors]; 1082 [descriptors release]; 1083 } 1084 else 1085 sortedTorrents = torrents; 1086 1087 int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"]; 1088 1089 Torrent * torrent; 1090 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1091 while ((torrent = [enumerator nextObject])) 1092 if ([torrent isActive] && ![torrent isSeeding]) 1055 1093 { 1056 if ([torrent isActive]) 1094 desiredActive--; 1095 if (desiredActive <= 0) 1096 break; 1097 } 1098 1099 enumerator = [sortedTorrents objectEnumerator]; 1100 while ((torrent = [enumerator nextObject])) 1101 { 1102 if ([torrent progress] >= 1.0) 1103 [torrent startTransfer]; 1104 else 1105 { 1106 if ([torrent waitingToStart] && desiredActive > 0) 1057 1107 { 1058 if (![torrent isSeeding]) 1059 { 1060 amountToStart--; 1061 if (amountToStart <= 0) 1062 break; 1063 } 1108 [torrent startTransfer]; 1109 desiredActive--; 1064 1110 } 1065 else if ([torrent waitingToStart])1066 [waitingTorrents addObject: torrent];1067 else;1068 1111 } 1069 1112 1070 int waitingCount = [waitingTorrents count]; 1071 if (amountToStart > 0 && waitingCount > 0) 1072 { 1073 if (amountToStart > waitingCount) 1074 amountToStart = waitingCount; 1075 1076 //sort torrents by order 1077 if (amountToStart < waitingCount) 1078 { 1079 NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: 1080 @"orderValue" ascending: YES] autorelease]; 1081 NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil]; 1082 1083 [waitingTorrents sortUsingDescriptors: descriptors]; 1084 [descriptors release]; 1085 } 1086 1087 int i; 1088 for (i = 0; i < amountToStart; i++) 1089 [[waitingTorrents objectAtIndex: i] startTransfer]; 1090 } 1091 1092 [waitingTorrents release]; 1093 } 1094 else; 1095 1096 [self updateUI: nil]; 1097 1098 //update info for changed start setting 1099 [self reloadInspector: nil]; 1100 } 1101 1102 - (void) torrentStartSettingChange: (NSNotification *) notification 1103 { 1104 //sort torrents by order value 1105 NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: 1106 @"orderValue" ascending: YES] autorelease]; 1107 NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil]; 1108 1109 NSArray * torrents = [[notification object] sortedArrayUsingDescriptors: descriptors]; 1110 [descriptors release]; 1111 1112 //attempt to start all torrents 1113 NSEnumerator * enumerator = [torrents objectEnumerator]; 1114 Torrent * torrent; 1115 1116 while ((torrent = [enumerator nextObject])) 1117 [self attemptToStartAuto: torrent]; 1118 1119 [self updateUI: nil]; 1120 [self reloadInspector: nil]; 1121 [self updateTorrentHistory]; 1122 } 1123 1124 //will try to start, taking into consideration the start preference 1125 - (void) attemptToStartAuto: (Torrent *) torrent 1126 { 1127 if ([torrent progress] >= 1.0) 1128 [torrent startTransfer]; 1129 else 1130 { 1131 if (![torrent waitingToStart]) 1132 return; 1133 1134 NSString * startSetting = [fDefaults stringForKey: @"StartSetting"]; 1135 if ([startSetting isEqualToString: @"Wait"]) 1136 { 1137 int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"]; 1138 1139 Torrent * tempTorrent; 1140 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1141 while ((tempTorrent = [enumerator nextObject])) 1142 if ([tempTorrent isActive] && ![tempTorrent isSeeding]) 1143 { 1144 desiredActive--; 1145 if (desiredActive <= 0) 1146 return; 1147 } 1148 1149 [torrent startTransfer]; 1150 } 1151 else if ([startSetting isEqualToString: @"Start"]) 1152 [torrent startTransfer]; 1153 else; 1154 } 1155 1156 [torrent update]; 1113 [torrent update]; 1114 } 1157 1115 } 1158 1116
Note: See TracChangeset
for help on using the changeset viewer.