mirror of
https://github.com/transmission/transmission
synced 2025-03-09 21:54:09 +00:00
preliminary support for setting speed limits through the action menu
This commit is contained in:
parent
2a8f9eb1f9
commit
f0f61ddd2b
8 changed files with 107 additions and 20 deletions
10
macosx/English.lproj/MainMenu.nib/classes.nib
generated
10
macosx/English.lproj/MainMenu.nib/classes.nib
generated
|
@ -179,9 +179,17 @@
|
|||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {checkFile = id; setQuickLimit = id; setQuickLimitMode = id; };
|
||||
CLASS = TorrentTableView;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {fContextNoRow = NSMenu; fContextRow = NSMenu; fController = Controller; };
|
||||
OUTLETS = {
|
||||
fActionMenu = NSMenu;
|
||||
fContextNoRow = NSMenu;
|
||||
fContextRow = NSMenu;
|
||||
fController = Controller;
|
||||
fDownloadMenu = NSMenu;
|
||||
fUploadMenu = NSMenu;
|
||||
};
|
||||
SUPERCLASS = NSTableView;
|
||||
}
|
||||
);
|
||||
|
|
10
macosx/English.lproj/MainMenu.nib/info.nib
generated
10
macosx/English.lproj/MainMenu.nib/info.nib
generated
|
@ -7,13 +7,15 @@
|
|||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>1041</key>
|
||||
<string>308 271 208 149 0 0 1152 842 </string>
|
||||
<string>480 344 208 149 0 0 1680 1028 </string>
|
||||
<key>1480</key>
|
||||
<string>366 546 420 63 0 0 1152 842 </string>
|
||||
<key>1603</key>
|
||||
<string>337 544 477 67 0 0 1152 842 </string>
|
||||
<key>1936</key>
|
||||
<string>785 583 166 80 0 0 1680 1028 </string>
|
||||
<key>29</key>
|
||||
<string>149 756 451 44 0 0 1152 842 </string>
|
||||
<string>261 932 451 44 0 0 1680 1028 </string>
|
||||
<key>456</key>
|
||||
<string>396 374 240 225 0 0 1152 842 </string>
|
||||
<key>581</key>
|
||||
|
@ -31,10 +33,12 @@
|
|||
<integer>3</integer>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>1936</integer>
|
||||
<integer>21</integer>
|
||||
<integer>29</integer>
|
||||
<integer>1041</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8R218</string>
|
||||
<string>8R4031</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
BIN
macosx/English.lproj/MainMenu.nib/keyedobjects.nib
generated
BIN
macosx/English.lproj/MainMenu.nib/keyedobjects.nib
generated
Binary file not shown.
|
@ -106,7 +106,12 @@
|
|||
[self updateInfoForTorrents: [NSArray array]];
|
||||
|
||||
//allow for update notifications
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil];
|
||||
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
||||
[nc addObserver: self selector: @selector(updateInfoStats)
|
||||
name: @"UpdateStats" object: nil];
|
||||
|
||||
[nc addObserver: self selector: @selector(updateInfoSettings)
|
||||
name: @"UpdateSettings" object: nil];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
|
|
@ -62,7 +62,7 @@ typedef enum
|
|||
tr_file_stat_t * fileStat;
|
||||
NSArray * fFileList, * fFlatFileList;
|
||||
|
||||
NSMenu * fTorrentMenu;
|
||||
NSMenu * fFileMenu;
|
||||
|
||||
float fRatioLimit;
|
||||
int fRatioSetting;
|
||||
|
@ -213,7 +213,7 @@ typedef enum
|
|||
- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
|
||||
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet;
|
||||
|
||||
- (NSMenu *) torrentMenu;
|
||||
- (NSMenu *) fileMenu;
|
||||
|
||||
- (NSDate *) dateAdded;
|
||||
- (NSDate *) dateCompleted;
|
||||
|
|
|
@ -165,7 +165,7 @@ static int static_lastid = 0;
|
|||
[fFileList release];
|
||||
[fFlatFileList release];
|
||||
|
||||
[fTorrentMenu release];
|
||||
[fFileMenu release];
|
||||
|
||||
[fQuickPauseDict release];
|
||||
|
||||
|
@ -563,6 +563,7 @@ static int static_lastid = 0;
|
|||
return 0;
|
||||
}
|
||||
|
||||
#warning use enum value
|
||||
- (int) speedMode: (BOOL) upload
|
||||
{
|
||||
return tr_torrentGetSpeedMode(fHandle, upload ? TR_UP : TR_DOWN);
|
||||
|
@ -1314,14 +1315,14 @@ static int static_lastid = 0;
|
|||
return priorities;
|
||||
}
|
||||
|
||||
- (NSMenu *) torrentMenu
|
||||
- (NSMenu *) fileMenu
|
||||
{
|
||||
if (!fTorrentMenu)
|
||||
if (!fFileMenu)
|
||||
{
|
||||
fTorrentMenu = [[NSMenu alloc] initWithTitle: [@"TorrentMenu:" stringByAppendingString: [self name]]];
|
||||
[fTorrentMenu setAutoenablesItems: NO];
|
||||
fFileMenu = [[NSMenu alloc] initWithTitle: [@"TorrentMenu:" stringByAppendingString: [self name]]];
|
||||
[fFileMenu setAutoenablesItems: NO];
|
||||
}
|
||||
return fTorrentMenu;
|
||||
return fFileMenu;
|
||||
}
|
||||
|
||||
- (NSDate *) dateAdded
|
||||
|
|
|
@ -51,14 +51,18 @@
|
|||
NSMutableArray * fKeyStrokes;
|
||||
|
||||
NSDictionary * fSmallStatusAttributes;
|
||||
|
||||
|
||||
IBOutlet NSMenu * fActionMenu, * fUploadMenu, * fDownloadMenu;
|
||||
Torrent * fMenuTorrent;
|
||||
NSEvent * fMenuEvent;
|
||||
}
|
||||
|
||||
- (void) setTorrents: (NSArray *) torrents;
|
||||
|
||||
- (void) displayTorrentMenuForEvent: (NSEvent *) event;
|
||||
|
||||
- (void) setQuickLimitMode: (id) sender;
|
||||
- (void) setQuickLimit: (id) sender;
|
||||
|
||||
- (void) checkFile: (id) sender;
|
||||
|
||||
@end
|
||||
|
|
|
@ -34,6 +34,12 @@
|
|||
|
||||
#define ACTION_BUTTON_TO_TOP 47.0
|
||||
|
||||
#define ACTION_MENU_GLOBAL_TAG 101
|
||||
#define ACTION_MENU_UNLIMITED_TAG 102
|
||||
#define ACTION_MENU_LIMIT_TAG 103
|
||||
|
||||
#define ACTION_MENU_FILE_TAG 201
|
||||
|
||||
@interface TorrentTableView (Private)
|
||||
|
||||
- (NSRect) pauseRectForRow: (int) row;
|
||||
|
@ -304,9 +310,25 @@
|
|||
if (row < 0)
|
||||
return;
|
||||
|
||||
//get file menu
|
||||
fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
|
||||
NSMenu * torrentMenu = [fMenuTorrent torrentMenu];
|
||||
[torrentMenu setDelegate: self];
|
||||
NSMenu * fileMenu = [fMenuTorrent fileMenu];
|
||||
[fileMenu setDelegate: self];
|
||||
|
||||
//remove old file menu
|
||||
NSMenuItem * oldFileMenuItem;
|
||||
if ((oldFileMenuItem = [fActionMenu itemWithTag: ACTION_MENU_FILE_TAG]))
|
||||
[fActionMenu removeItem: oldFileMenuItem];
|
||||
|
||||
//set file menu
|
||||
#warning localize
|
||||
NSMenuItem * fileMenuItem = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Files",
|
||||
"torrent action context menu -> files menu") action: NULL keyEquivalent: @""];
|
||||
[fileMenuItem setTag: ACTION_MENU_FILE_TAG];
|
||||
[fileMenuItem setSubmenu: fileMenu];
|
||||
[fActionMenu addItem: fileMenuItem];
|
||||
|
||||
[fileMenuItem release];
|
||||
|
||||
NSRect rect = [self actionRectForRow: row];
|
||||
NSPoint location = rect.origin;
|
||||
|
@ -317,7 +339,7 @@
|
|||
modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
|
||||
context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
|
||||
|
||||
[NSMenu popUpContextMenu: torrentMenu withEvent: newEvent forView: self];
|
||||
[NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
|
||||
|
||||
[fMenuTorrent release];
|
||||
fMenuTorrent = nil;
|
||||
|
@ -326,17 +348,39 @@
|
|||
- (void) menuNeedsUpdate: (NSMenu *) menu
|
||||
{
|
||||
//this method seems to be called when it shouldn't be
|
||||
if (!fMenuTorrent)
|
||||
if (!fMenuTorrent || ![menu supermenu])
|
||||
return;
|
||||
|
||||
BOOL create = [menu numberOfItems] <= 0, folder;
|
||||
|
||||
NSMenu * supermenu = [menu supermenu];
|
||||
NSArray * items;
|
||||
if (supermenu)
|
||||
NSDictionary * folderDict;
|
||||
#warning move to submethod
|
||||
if (menu == fUploadMenu || menu == fDownloadMenu)
|
||||
{
|
||||
BOOL upload = menu == fUploadMenu;
|
||||
tr_speedlimit_t mode = [fMenuTorrent speedMode: upload];
|
||||
|
||||
NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
|
||||
[item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
|
||||
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
|
||||
"torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
|
||||
|
||||
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
|
||||
[item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
|
||||
|
||||
item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
|
||||
[item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
|
||||
|
||||
return;
|
||||
}
|
||||
else if ((folderDict = [[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject]))
|
||||
items = [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject] objectForKey: @"Children"];
|
||||
else
|
||||
items = [fMenuTorrent fileList];
|
||||
|
||||
#warning move rest to submethod
|
||||
NSEnumerator * enumerator = [items objectEnumerator];
|
||||
NSDictionary * dict;
|
||||
NSMenuItem * item;
|
||||
|
@ -388,6 +432,27 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) setQuickLimitMode: (id) sender
|
||||
{
|
||||
int tag = [sender tag];
|
||||
tr_speedlimit_t mode;
|
||||
if (tag == ACTION_MENU_UNLIMITED_TAG)
|
||||
mode = TR_SPEEDLIMIT_UNLIMITED;
|
||||
else if (tag == ACTION_MENU_LIMIT_TAG)
|
||||
mode = TR_SPEEDLIMIT_SINGLE;
|
||||
else
|
||||
mode = TR_SPEEDLIMIT_GLOBAL;
|
||||
|
||||
[fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
|
||||
}
|
||||
|
||||
- (void) setQuickLimit: (id) sender
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void) checkFile: (id) sender
|
||||
{
|
||||
#warning get working
|
||||
|
|
Loading…
Add table
Reference in a new issue