From: Mitchell Livingston Date: Wed, 4 Jun 2008 04:48:17 +0000 (+0000) Subject: add ability to add and remove to the rpc access list X-Git-Tag: 1.22~153 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63c06c99b1165f22a02e20d025a487b76984f0c0;p=transmission add ability to add and remove to the rpc access list --- diff --git a/macosx/English.lproj/PrefsWindow.xib b/macosx/English.lproj/PrefsWindow.xib index ce9823e58..a12abe4bf 100644 --- a/macosx/English.lproj/PrefsWindow.xib +++ b/macosx/English.lproj/PrefsWindow.xib @@ -9,6 +9,7 @@ YES + YES @@ -1517,7 +1518,7 @@ NSResponder - + 256 YES @@ -2112,6 +2113,7 @@ AAABAAAAAQ {535, 226} + NSView NSResponder @@ -2804,7 +2806,7 @@ AAABAAAAAQ 256 - {{102, 210}, {96, 17}} + {{102, 238}, {96, 17}} YES @@ -2820,7 +2822,7 @@ AAABAAAAAQ 256 - {{204, 208}, {50, 22}} + {{204, 236}, {50, 22}} YES @@ -2886,7 +2888,7 @@ AAABAAAAAQ 256 - {{84, 234}, {367, 18}} + {{84, 262}, {367, 18}} YES @@ -2908,7 +2910,7 @@ AAABAAAAAQ 256 - {{103, 183}, {139, 18}} + {{103, 211}, {139, 18}} YES @@ -2930,7 +2932,7 @@ AAABAAAAAQ 256 - {{248, 182}, {152, 22}} + {{248, 210}, {152, 22}} YES @@ -2951,7 +2953,7 @@ AAABAAAAAQ 256 - {{102, 161}, {123, 17}} + {{102, 189}, {123, 17}} YES @@ -2966,7 +2968,7 @@ AAABAAAAAQ - 268 + 256 YES @@ -2977,27 +2979,27 @@ AAABAAAAAQ 256 - {327, 117} + {327, 116} YES - + 256 {327, 17} - + 256 - {{328, 0}, {16, 17}} + {{328, 1}, {16, 17}} YES IP - 2.570000e+02 + 2.460000e+02 4.000000e+01 1.000000e+03 @@ -3032,7 +3034,7 @@ AAABAAAAAQ Permission - 6.400000e+01 + 7.500000e+01 4.000000e+01 1.000000e+03 @@ -3108,14 +3110,14 @@ AAABAAAAAQ 1.700000e+01 - -557842432 + 448790528 4 15 0 - YES + NO - {{1, 17}, {327, 117}} + {{1, 18}, {327, 116}} @@ -3125,12 +3127,11 @@ AAABAAAAAQ 256 - {{328, 17}, {15, 117}} + {{328, 18}, {15, 116}} _doScroller: - 3.700000e+01 - 1.947368e-01 + 9.914530e-01 @@ -3142,14 +3143,14 @@ AAABAAAAAQ _doScroller: 9.971265e-01 - + 2304 YES - {{1, 0}, {327, 17}} + {{1, 1}, {327, 17}} @@ -3158,19 +3159,57 @@ AAABAAAAAQ - {{105, 18}, {344, 135}} + {{105, 46}, {344, 135}} 18 - + QSAAAEEgAABBmAAAQZgAAA + + + 292 + {{105, 19}, {67, 23}} + + YES + + -2080244224 + 0 + + + + YES + + 3.200000e+01 + + NSImage + NSAddTemplate + + + 0 + + + 3.200000e+01 + + NSImage + NSRemoveTemplate + + + 1 + YES + 0 + + + 2 + 6 + + - {535, 270} + {535, 298} NSView NSResponder @@ -4913,13 +4952,37 @@ AAABAAAAAQ 1532 + + + fRPCAddRemoveControl + + + + 1536 + + + + delegate + + + + 1537 + fRPCAccessTable - 1533 + 1538 + + + + addRemoveRPCIP: + + + + 1539 @@ -6727,6 +6790,7 @@ AAABAAAAAQ + Remote @@ -6856,11 +6920,6 @@ AAABAAAAAQ - - 1522 - - - 1523 @@ -6913,6 +6972,25 @@ AAABAAAAAQ + + 1522 + + + + + 1534 + + + YES + + + + + + 1535 + + + @@ -7036,6 +7114,10 @@ AAABAAAAAQ 153.editorWindowContentRectSynchronizationRect 1530.IBPluginDependency 1531.IBPluginDependency + 1534.IBPluginDependency + 1534.IBSegmentedControlTracker.RoundRobinState + 1534.IBSegmentedControlTracker.WasGrowing + 1535.IBPluginDependency 154.IBPluginDependency 154.ImportedFromIB2 155.IBPluginDependency @@ -7331,7 +7413,7 @@ AAABAAAAAQ com.apple.InterfaceBuilder.CocoaPlugin - {{404, 377}, {535, 270}} + {{404, 377}, {535, 298}} com.apple.InterfaceBuilder.CocoaPlugin {{281, 577}, {539, 315}} @@ -7367,6 +7449,10 @@ AAABAAAAAQ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7605,7 +7691,7 @@ AAABAAAAAQ - 1533 + 1539 @@ -7691,6 +7777,7 @@ AAABAAAAAQ YES YES + addRemoveRPCIP: applyRatioSetting: applySpeedSettings: folderSheetShow: @@ -7758,6 +7845,7 @@ AAABAAAAAQ id id id + id @@ -7784,6 +7872,7 @@ AAABAAAAAQ fQueueDownloadField fQueueSeedField fRPCAccessTable + fRPCAddRemoveControl fRPCPortField fRatioStopField fRemoteView @@ -7815,6 +7904,7 @@ AAABAAAAAQ NSTextField NSTextField NSTableView + NSSegmentedControl NSTextField NSTextField NSView diff --git a/macosx/PrefsController.h b/macosx/PrefsController.h index 3d544a336..20585820b 100644 --- a/macosx/PrefsController.h +++ b/macosx/PrefsController.h @@ -59,6 +59,7 @@ IBOutlet NSTextField * fRPCPortField; IBOutlet NSTableView * fRPCAccessTable; + IBOutlet NSSegmentedControl * fRPCAddRemoveControl; NSMutableArray * fRPCAccessArray; } @@ -117,12 +118,13 @@ - (void) setAutoSize: (id) sender; -- (void) helpForPeers: (id) sender; -- (void) helpForNetwork: (id) sender; - - (void) setRPCEnabled: (id) sender; - (void) setRPCPort: (id) sender; - (void) updateRPCAccessList; +- (void) addRemoveRPCIP: (id) sender; + +- (void) helpForPeers: (id) sender; +- (void) helpForNetwork: (id) sender; - (void) rpcUpdatePrefs; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 9846cc106..db5b4e6f2 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -34,6 +34,9 @@ #define RPC_ACCESS_ALLOW 0 #define RPC_ACCESS_BLOCK 1 +#define RPC_IP_ADD_TAG 0 +#define RPC_IP_REMOVE_TAG 1 + #define UPDATE_SECONDS 86400 #define TOOLBAR_GENERAL @"TOOLBAR_GENERAL" @@ -144,6 +147,13 @@ [self setPrefView: nil]; + if (![NSApp isOnLeopardOrBetter]) + { + [fRPCAddRemoveControl sizeToFit]; + [fRPCAddRemoveControl setLabel: @"+" forSegment: RPC_IP_ADD_TAG]; + [fRPCAddRemoveControl setLabel: @"-" forSegment: RPC_IP_REMOVE_TAG]; + } + //set download folder [fFolderPopUp selectItemAtIndex: [fDefaults boolForKey: @"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT]; @@ -651,24 +661,47 @@ - (void) updateRPCAccessList { - NSMutableString * string = [NSMutableString stringWithCapacity: 17 * [fRPCAccessArray count]]; + NSMutableArray * components = [NSMutableArray arrayWithCapacity: [fRPCAccessArray count]]; NSEnumerator * enumerator = [fRPCAccessArray objectEnumerator]; NSDictionary * dict; while ((dict = [enumerator nextObject])) - { - [string appendFormat: @"%c%@,", [[dict objectForKey: @"Allow"] boolValue] ? '+' : '-', [dict objectForKey: @"IP"]]; - } + [components addObject: [NSString stringWithFormat: @"%c%@", [[dict objectForKey: @"Allow"] boolValue] ? '+' : '-', + [dict objectForKey: @"IP"]]]; - //remove last comma - NSUInteger length = [string length]; - if (length > 0) - [string deleteCharactersInRange: NSMakeRange(length-1, 1)]; + NSString * string = [components componentsJoinedByString: @","];NSLog(string); #warning check for an error! tr_sessionSetRPCACL(fHandle, [string UTF8String], NULL); } +- (void) addRemoveRPCIP: (id) sender +{ + //don't allow add/remove when currently adding - it leads to weird results + if ([fRPCAccessTable editedRow] != -1) + return; + + if ([[sender cell] tagForSegment: [sender selectedSegment]] == RPC_IP_REMOVE_TAG) + { + [fRPCAccessArray removeObjectsAtIndexes: [fRPCAccessTable selectedRowIndexes]]; + [fRPCAccessTable deselectAll: self]; + [fRPCAccessTable reloadData]; + + [fDefaults setObject: fRPCAccessArray forKey: @"RPCAccessList"]; + [self updateRPCAccessList]; + } + else + { + [fRPCAccessArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"", @"IP", + [NSNumber numberWithBool: YES], @"Allow", nil]]; + [fRPCAccessTable reloadData]; + + int row = [fRPCAccessArray count] - 1; + [fRPCAccessTable selectRow: row byExtendingSelection: NO]; + [fRPCAccessTable editColumn: 0 row: row withEvent: nil select: YES]; + } +} + - (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView { return [fRPCAccessArray count]; @@ -703,35 +736,49 @@ { //verify ip NSArray * components = [object componentsSeparatedByString: @"."]; - if ([components count] != 4) - { - NSBeep(); - return; - } - - NSMutableArray * newComponents = [NSMutableArray arrayWithCapacity: 4]; + BOOL valid = [components count] == 4; - NSEnumerator * enumerator = [components objectEnumerator]; - NSString * component; - while ((component = [enumerator nextObject])) + NSMutableArray * newComponents; + if (valid) { - if ([component isEqualToString: @"*"]) - [newComponents addObject: component]; - else + newComponents = [NSMutableArray arrayWithCapacity: 4]; + + NSEnumerator * enumerator = [components objectEnumerator]; + NSString * component; + while ((component = [enumerator nextObject])) { - int value = [component intValue]; - if (value >= 0 && value < 256) - [newComponents addObject: [[NSNumber numberWithInt: value] stringValue]]; + if ([component isEqualToString: @"*"]) + [newComponents addObject: component]; else { - NSBeep(); - return; + int value = [component intValue]; + if (value >= 0 && value < 256) + [newComponents addObject: [[NSNumber numberWithInt: value] stringValue]]; + else + { + valid = NO; + break; + } } } } + if (!valid) + { + NSBeep(); + + if ([[oldDict objectForKey: @"IP"] isEqualToString: @""]) + { + [fRPCAccessArray removeObjectAtIndex: row]; + [fRPCAccessTable deselectAll: self]; + [fRPCAccessTable reloadData]; + } + + return; + } + newDict = [NSDictionary dictionaryWithObjectsAndKeys: [newComponents componentsJoinedByString: @"."], @"IP", - [oldDict objectForKey: @"Allow"], @"Allow", nil];NSLog([newDict description]); + [oldDict objectForKey: @"Allow"], @"Allow", nil]; } [fRPCAccessArray replaceObjectAtIndex: row withObject: newDict]; @@ -740,6 +787,11 @@ [self updateRPCAccessList]; } +- (void) tableViewSelectionDidChange: (NSNotification *) notification +{ + [fRPCAddRemoveControl setEnabled: [fRPCAccessTable numberOfSelectedRows] > 0 forSegment: RPC_IP_REMOVE_TAG]; +} + - (void) helpForPeers: (id) sender { [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PeersPrefs" diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index a70f19a6b..0cfae2f1a 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -777,7 +777,7 @@ [bitmap setColor: pieceColor atX: i y: 0]; } - [torrent setPreviousAmountFinished: piecePercent]; + [torrent setPreviousAmountFinished: piecePercent]; //holds onto piecePercent, so no need to release it here //actually draw image [bitmap drawInRect: barRect];