diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index f2626511a..aabefde54 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -144,6 +144,7 @@ A2725B6E0DE5C4F5003445E7 /* FileListNode.m in Sources */ = {isa = PBXBuildFile; fileRef = A2725B6D0DE5C4F5003445E7 /* FileListNode.m */; }; A2725D5D0DE7507C003445E7 /* TrackerTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2725D5C0DE7507C003445E7 /* TrackerTableView.m */; }; A277DA0B0C693D9C00DA2CD4 /* ActionOn.png in Resources */ = {isa = PBXBuildFile; fileRef = A277DA090C693D9C00DA2CD4 /* ActionOn.png */; }; + A27F0F330E19AD9800B2DB97 /* TorrentGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = A27F0F320E19AD9800B2DB97 /* TorrentGroup.m */; }; A28F4F770E085BDC003A3882 /* ColorTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = A28F4F760E085BDC003A3882 /* ColorTextField.m */; }; A292A6E80DFB45FC004B9C0A /* webseed.c in Sources */ = {isa = PBXBuildFile; fileRef = A292A6E50DFB45EC004B9C0A /* webseed.c */; }; A29576030D11D63C0093B167 /* Creator.xib in Resources */ = {isa = PBXBuildFile; fileRef = A29576010D11D63C0093B167 /* Creator.xib */; }; @@ -577,6 +578,8 @@ A27476FF0CC38EE6003CC76D /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = macosx/es.lproj/InfoPlist.strings; sourceTree = ""; }; A27477010CC38EE6003CC76D /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = macosx/es.lproj/Localizable.strings; sourceTree = ""; }; A277DA090C693D9C00DA2CD4 /* ActionOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ActionOn.png; path = macosx/Images/ActionOn.png; sourceTree = ""; }; + A27F0F310E19AD9800B2DB97 /* TorrentGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TorrentGroup.h; path = macosx/TorrentGroup.h; sourceTree = ""; }; + A27F0F320E19AD9800B2DB97 /* TorrentGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TorrentGroup.m; path = macosx/TorrentGroup.m; sourceTree = ""; }; A28AFE050DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = zh_TW; path = macosx/zh_TW.lproj/AddWindow.xib; sourceTree = ""; }; A28AFE060DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = zh_TW; path = macosx/zh_TW.lproj/Creator.xib; sourceTree = ""; }; A28AFE070DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_TW; path = macosx/zh_TW.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -889,6 +892,8 @@ 4DF0C5A90899190500DD8943 /* Controller.m */, 4DFBC2DD09C0970D00D5C571 /* Torrent.h */, 4DFBC2DE09C0970D00D5C571 /* Torrent.m */, + A27F0F310E19AD9800B2DB97 /* TorrentGroup.h */, + A27F0F320E19AD9800B2DB97 /* TorrentGroup.m */, 4D364D9E091FBB2C00377D12 /* TorrentTableView.h */, 4D364D9F091FBB2C00377D12 /* TorrentTableView.m */, 4DCCBB3D09C3D71100D3CABF /* TorrentCell.h */, @@ -1976,6 +1981,7 @@ A2725B6E0DE5C4F5003445E7 /* FileListNode.m in Sources */, A2725D5D0DE7507C003445E7 /* TrackerTableView.m in Sources */, A28F4F770E085BDC003A3882 /* ColorTextField.m in Sources */, + A27F0F330E19AD9800B2DB97 /* TorrentGroup.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/macosx/BlocklistDownloader.h b/macosx/BlocklistDownloader.h index b5036ef64..32a25fe35 100644 --- a/macosx/BlocklistDownloader.h +++ b/macosx/BlocklistDownloader.h @@ -42,7 +42,7 @@ long long fExpectedSize; } -+ (void) downloadWithPrefsController: (PrefsController *) prefsController; //only use when no other blocklist downloads ++ (void) downloadWithPrefsController: (PrefsController *) prefsController; //only use when no other blocklist is downloading - (void) cancelDownload: (id) sender; diff --git a/macosx/Controller.m b/macosx/Controller.m index ede019086..484146738 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -26,6 +26,7 @@ #import "Controller.h" #import "Torrent.h" +#import "TorrentGroup.h" #import "TorrentCell.h" #import "TorrentTableView.h" #import "CreatorWindowController.h" @@ -1888,9 +1889,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if ([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter]) { NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator]; - NSDictionary * dict; - while ((dict = [enumerator nextObject])) - [[dict objectForKey: @"Torrents"] sortUsingDescriptors: descriptors]; + TorrentGroup * group; + while ((group = [enumerator nextObject])) + [[group torrents] sortUsingDescriptors: descriptors]; } else [fDisplayedTorrents sortUsingDescriptors: descriptors]; @@ -1909,9 +1910,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy previousTorrents = [NSMutableArray array]; NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator]; - NSDictionary * dict; - while ((dict = [enumerator nextObject])) - [previousTorrents addObjectsFromArray: [dict objectForKey: @"Torrents"]]; + TorrentGroup * group; + while ((group = [enumerator nextObject])) + [previousTorrents addObjectsFromArray: [group torrents]]; } else previousTorrents = fDisplayedTorrents; @@ -2047,10 +2048,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy int groupValue = [torrent groupValue]; if (groupValue != oldGroupValue) { - groupTorrents = [NSMutableArray array]; - NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: groupValue], @"Group", - groupTorrents, @"Torrents", nil]; - [fDisplayedTorrents addObject: dict]; + TorrentGroup * group = [TorrentGroup groupForIndex: groupValue]; + [fDisplayedTorrents addObject: group]; + groupTorrents = [group torrents]; oldGroupValue = groupValue; } @@ -2070,13 +2070,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if (groupRows) { enumerator = [fDisplayedTorrents objectEnumerator]; - NSDictionary * dict; - while ((dict = [enumerator nextObject])) + TorrentGroup * group; + while ((group = [enumerator nextObject])) { - if ([fTableView isGroupCollapsed: [[dict objectForKey: @"Group"] intValue]]) - [fTableView collapseItem: dict]; + if ([fTableView isGroupCollapsed: [group groupIndex]]) + [fTableView collapseItem: group]; else - [fTableView expandItem: dict]; + [fTableView expandItem: group]; } } @@ -2576,7 +2576,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy - (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item { if (item) - return [[item objectForKey: @"Torrents"] count]; + return [[item torrents] count]; else return [fDisplayedTorrents count]; } @@ -2584,7 +2584,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy - (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item { if (item) - return [[item objectForKey: @"Torrents"] objectAtIndex: index]; + return [[item torrents] objectAtIndex: index]; else return [fDisplayedTorrents objectAtIndex: index]; } @@ -2603,13 +2603,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy NSString * ident = [tableColumn identifier]; if ([ident isEqualToString: @"Group"]) { - int group = [[item objectForKey: @"Group"] intValue]; + int group = [item groupIndex]; return group != -1 ? [[GroupsController groups] nameForIndex: group] : NSLocalizedString(@"No Group", "Group table row"); } else if ([ident isEqualToString: @"Color"]) { - int group = [[item objectForKey: @"Group"] intValue]; + int group = [item groupIndex]; return [[GroupsController groups] imageForIndex: group]; } else if ([ident isEqualToString: @"DL Image"]) @@ -2622,7 +2622,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if ([fDefaults boolForKey: @"DisplayGroupRowRatio"]) { uint64_t uploaded = 0, downloaded = 0; - NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator]; + NSEnumerator * enumerator = [[item torrents] objectEnumerator]; Torrent * torrent; while ((torrent = [enumerator nextObject])) { @@ -2637,7 +2637,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy BOOL upload = [ident isEqualToString: @"UL"]; float rate = 0.0; - NSEnumerator * enumerator = [[item objectForKey: @"Torrents"] objectEnumerator]; + NSEnumerator * enumerator = [[item torrents] objectEnumerator]; Torrent * torrent; while ((torrent = [enumerator nextObject])) rate += upload ? [torrent uploadRate] : [torrent downloadRate]; @@ -2687,8 +2687,8 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy { if ([item isKindOfClass: [Torrent class]]) { - NSDictionary * group = [fTableView parentForItem: item]; - index = [[group objectForKey: @"Torrents"] indexOfObject: item] + 1; + TorrentGroup * group = [fTableView parentForItem: item]; + index = [[group torrents] indexOfObject: item] + 1; item = group; } } @@ -2736,14 +2736,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if (item) { //change groups - int groupValue = [[item objectForKey: @"Group"] intValue]; + int groupValue = [item groupIndex]; NSEnumerator * enumerator = [movingTorrents objectEnumerator]; Torrent * torrent; while ((torrent = [enumerator nextObject])) { //have to reset objects here to avoid weird crash - [[[fTableView parentForItem: torrent] objectForKey: @"Torrent"] removeObject: torrent]; - [[item objectForKey: @"Torrent"] addObject: torrent]; + [[[fTableView parentForItem: torrent] torrents] removeObject: torrent]; + [[item torrents] addObject: torrent]; [torrent setGroupValue: groupValue]; } @@ -2755,7 +2755,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if (newRow != NSOutlineViewDropOnItemIndex) { //find torrent to place under - NSArray * groupTorrents = item ? [item objectForKey: @"Torrents"] : fDisplayedTorrents; + NSArray * groupTorrents = item ? [item torrents] : fDisplayedTorrents; Torrent * topTorrent = nil; for (i = newRow-1; i >= 0; i--) { diff --git a/macosx/TorrentGroup.h b/macosx/TorrentGroup.h new file mode 100644 index 000000000..3591e0b28 --- /dev/null +++ b/macosx/TorrentGroup.h @@ -0,0 +1,38 @@ +/****************************************************************************** + * $Id$ + * + * Copyright (c) 2008 Transmission authors and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *****************************************************************************/ + +#import + +@interface TorrentGroup : NSObject +{ + NSInteger fGroup; + NSMutableArray * fTorrents; +} + ++ (id) groupForIndex: (int) group; + +- (NSInteger) groupIndex; +- (NSMutableArray *) torrents; + +@end diff --git a/macosx/TorrentGroup.m b/macosx/TorrentGroup.m new file mode 100644 index 000000000..afdb9b1de --- /dev/null +++ b/macosx/TorrentGroup.m @@ -0,0 +1,70 @@ +/****************************************************************************** + * $Id$ + * + * Copyright (c) 2008 Transmission authors and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *****************************************************************************/ + +#import "TorrentGroup.h" + +@interface TorrentGroup (Private) + +- (id) initWithGroup: (int) group; + +@end + +@implementation TorrentGroup + ++ (id) groupForIndex: (int) group +{ + return [[[self alloc] initWithGroup: group] autorelease]; +} + +- (void) dealloc +{ + [fTorrents release]; + [super dealloc]; +} + +- (NSInteger) groupIndex +{ + return fGroup; +} + +- (NSMutableArray *) torrents +{ + return fTorrents; +} + +@end + +@implementation TorrentGroup (Private) + +- (id) initWithGroup: (int) group +{ + if ((self = [super init])) + { + fGroup = group; + fTorrents = [[NSMutableArray alloc] init]; + } + return self; +} + +@end diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 5e5c39682..a77cfa9fb 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -25,6 +25,7 @@ #import "TorrentTableView.h" #import "TorrentCell.h" #import "Torrent.h" +#import "TorrentGroup.h" #import "FileListNode.h" #import "QuickLookController.h" #import "NSApplicationAdditions.h" @@ -234,7 +235,7 @@ : NSLocalizedString(@"Upload speed", "Torrent table -> group row -> tooltip"); else if (ident) { - int count = [[item objectForKey: @"Torrents"] count]; + int count = [[item torrents] count]; if (count == 1) return NSLocalizedString(@"1 transfer", "Torrent table -> group row -> tooltip"); else @@ -354,7 +355,7 @@ - (void) outlineViewItemDidExpand: (NSNotification *) notification { - int value = [[[[notification userInfo] objectForKey: @"NSObject"] objectForKey: @"Group"] intValue]; + int value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex]; if (value < 0) value = MAX_GROUP; @@ -367,7 +368,7 @@ - (void) outlineViewItemDidCollapse: (NSNotification *) notification { - int value = [[[[notification userInfo] objectForKey: @"NSObject"] objectForKey: @"Group"] intValue]; + int value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex]; if (value < 0) value = MAX_GROUP; @@ -448,15 +449,14 @@ } else { - NSNumber * group = [item objectForKey: @"Group"]; - int i; + int i, group = [item groupIndex]; for (i = 0; i < [self numberOfRows]; i++) { if ([indexSet containsIndex: i]) continue; id tableItem = [self itemAtRow: i]; - if (![tableItem isKindOfClass: [Torrent class]] && [group isEqualToNumber: [tableItem objectForKey: @"Group"]]) + if (![tableItem isKindOfClass: [Torrent class]] && group == [tableItem groupIndex]) { [indexSet addIndex: i]; break; @@ -493,7 +493,7 @@ [torrents addObject: item]; else { - NSArray * groupTorrents = [item objectForKey: @"Torrents"]; + NSArray * groupTorrents = [item torrents]; [torrents addObjectsFromArray: groupTorrents]; i += [groupTorrents count]; }