~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to Transmission/src/TorrentDirectoryItem.cs

  • Committer: Christopher James Halse Rogers
  • Date: 2013-05-02 07:23:58 UTC
  • mfrom: (684.1.9 do-plugins)
  • Revision ID: chris@ed-20130502072358-ddn5oxyjngeearme
Merge long-awaited Transmission control plugin

Ported to Json.NET, as this has packages in the Debian and Ubuntu archives.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
 
 
5
using Do.Universe;
 
6
 
 
7
namespace Transmission {
 
8
 
 
9
        public class TorrentDirectoryItem: Item, ITorrentEntry {
 
10
 
 
11
                private TorrentItem _torrent;
 
12
                private TorrentDirectoryItem _parent;
 
13
                private string _name;
 
14
                private IList<Item> _files;
 
15
 
 
16
                public TorrentDirectoryItem(TorrentItem torrent, TorrentDirectoryItem parent, string name) {
 
17
                        _torrent = torrent;
 
18
                        _parent = parent;
 
19
                        _name = name;
 
20
                        _files = new List<Item>();
 
21
                }
 
22
 
 
23
                public TorrentItem Torrent {
 
24
                        get { return _torrent; }
 
25
                }
 
26
 
 
27
                public IEnumerable<TorrentFileItem> GetFiles() {
 
28
                        foreach (ITorrentEntry entry in _files)
 
29
                                foreach (TorrentFileItem file in entry.GetFiles())
 
30
                                        yield return file;
 
31
                }
 
32
 
 
33
                public override string Name {
 
34
                        get { return _name; }
 
35
                }
 
36
 
 
37
                public override string Description {
 
38
                        get { return string.Empty; }
 
39
                }
 
40
 
 
41
                public override string Icon {
 
42
                        get { return "folder"; }
 
43
                }
 
44
 
 
45
                public IList<Item> Files {
 
46
                        get { return _files; }
 
47
                }
 
48
 
 
49
                public string Path {
 
50
                        get {
 
51
                                if (_parent != null) {
 
52
                                        return _parent.Path + '/' + _name;
 
53
                                } else {
 
54
                                        return _name;
 
55
                                }
 
56
                        }
 
57
                }
 
58
 
 
59
                public string Uri {
 
60
                        get { return "file://" + Path; }
 
61
                }
 
62
        }
 
63
 
 
64
}