1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

groups are now stored as objects instead of dictionaries

This commit is contained in:
Mitchell Livingston 2008-07-01 01:28:19 +00:00
parent d4345a40b8
commit 212ea5e119
6 changed files with 149 additions and 35 deletions

View file

@ -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 = "<group>"; };
A27477010CC38EE6003CC76D /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = macosx/es.lproj/Localizable.strings; sourceTree = "<group>"; };
A277DA090C693D9C00DA2CD4 /* ActionOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ActionOn.png; path = macosx/Images/ActionOn.png; sourceTree = "<group>"; };
A27F0F310E19AD9800B2DB97 /* TorrentGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TorrentGroup.h; path = macosx/TorrentGroup.h; sourceTree = "<group>"; };
A27F0F320E19AD9800B2DB97 /* TorrentGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TorrentGroup.m; path = macosx/TorrentGroup.m; sourceTree = "<group>"; };
A28AFE050DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = zh_TW; path = macosx/zh_TW.lproj/AddWindow.xib; sourceTree = "<group>"; };
A28AFE060DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = zh_TW; path = macosx/zh_TW.lproj/Creator.xib; sourceTree = "<group>"; };
A28AFE070DA1C47A00673957 /* zh_TW */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_TW; path = macosx/zh_TW.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -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;
};

View file

@ -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;

View file

@ -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--)
{

38
macosx/TorrentGroup.h Normal file
View file

@ -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 <Cocoa/Cocoa.h>
@interface TorrentGroup : NSObject
{
NSInteger fGroup;
NSMutableArray * fTorrents;
}
+ (id) groupForIndex: (int) group;
- (NSInteger) groupIndex;
- (NSMutableArray *) torrents;
@end

70
macosx/TorrentGroup.m Normal file
View file

@ -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

View file

@ -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];
}