4
using System.Collections.Generic;
11
namespace Transmission {
13
public class PriorityItem: Item {
14
private TransmissionAPI.FilePriority _value;
18
public PriorityItem(TransmissionAPI.FilePriority value, string name, string icon) {
24
public override string Name {
28
public override string Description {
32
public override string Icon {
36
public TransmissionAPI.FilePriority Value {
37
get { return _value; }
41
public class TorrentFileSetPriorityAction: Act {
43
public TorrentFileSetPriorityAction() {
46
public override string Name {
47
get { return AddinManager.CurrentLocalizer.GetString ("Set priority"); }
50
public override string Description {
51
get { return AddinManager.CurrentLocalizer.GetString ("Set download priority"); }
54
public override string Icon {
55
get { return "object-flip-vertical"; }
58
public override IEnumerable<Type> SupportedItemTypes {
60
yield return typeof (ITorrentEntry);
64
public override IEnumerable<Type> SupportedModifierItemTypes {
66
yield return typeof (PriorityItem);
70
public override bool ModifierItemsOptional {
74
public override IEnumerable<Item> DynamicModifierItemsForItem(Item item) {
75
yield return new PriorityItem(TransmissionAPI.FilePriority.Low, "Low", "down");
76
yield return new PriorityItem(TransmissionAPI.FilePriority.Normal, "Normal", "forward");
77
yield return new PriorityItem(TransmissionAPI.FilePriority.High, "High", "up");
80
public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
81
TransmissionAPI.FilePriority priority = (modItems.First() as PriorityItem).Value;
83
TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(null, priority);
85
// Group torrent entries by torrent.
86
var files_by_torrent = items
87
.Cast<ITorrentEntry>()
90
(torrent, entries) => new {
92
Files = entries.SelectMany(entry => entry.GetFiles())
96
TransmissionAPI api = TransmissionPlugin.getTransmission();
98
// Expand entries for each torrent into set of torrent file entries.
99
// Perform action for each torrent separately.
100
foreach (var group in files_by_torrent) {
101
var operations = group.Files.ToDictionary(f => f.Index, f => operation);
102
api.SetTorrent(group.Torrent.HashString, null, null, null, null, null, operations);