Merge lp:~kriomant/do-plugins/transmission into lp:do-plugins

Proposed by kriomant
Status: Merged
Merged at revision: 754
Proposed branch: lp:~kriomant/do-plugins/transmission
Merge into: lp:do-plugins
Diff against target: 2699 lines (+2488/-0) (has conflicts)
30 files modified
.bzrignore (+9/-0)
DoPlugins.mds (+4/-0)
Makefile.am (+1/-0)
Transmission/Makefile.am (+40/-0)
Transmission/Resources/Transmission.addin.xml.in (+37/-0)
Transmission/Transmission.mdp (+64/-0)
Transmission/gtk-gui/Transmission.TransmissionConfig.cs (+161/-0)
Transmission/gtk-gui/generated.cs (+82/-0)
Transmission/gtk-gui/gui.stetic (+196/-0)
Transmission/src/Config/TransmissionConfig.cs (+91/-0)
Transmission/src/ITorrentEntry.cs (+16/-0)
Transmission/src/JsonCollectionImporter.cs (+117/-0)
Transmission/src/TorrentAbstractLimitSpeedAction.cs (+80/-0)
Transmission/src/TorrentDirectoryItem.cs (+64/-0)
Transmission/src/TorrentFileItem.cs (+97/-0)
Transmission/src/TorrentFileSetPriorityAction.cs (+108/-0)
Transmission/src/TorrentItem.cs (+72/-0)
Transmission/src/TorrentItemSource.cs (+130/-0)
Transmission/src/TorrentLimitDownloadSpeedAction.cs (+47/-0)
Transmission/src/TorrentLimitUploadSpeedAction.cs (+47/-0)
Transmission/src/TorrentMarkForDownloadAction.cs (+62/-0)
Transmission/src/TorrentOperateAction.cs (+37/-0)
Transmission/src/TorrentStartAction.cs (+42/-0)
Transmission/src/TorrentStopAction.cs (+42/-0)
Transmission/src/TorrentUnmarkForDownloadAction.cs (+62/-0)
Transmission/src/TorrentVerifyAction.cs (+42/-0)
Transmission/src/TransmissionAPI.cs (+575/-0)
Transmission/src/TransmissionPlugin.cs (+50/-0)
Transmission/src/Utils.cs (+111/-0)
configure.ac (+2/-0)
Text conflict in .bzrignore
To merge this branch: bzr merge lp:~kriomant/do-plugins/transmission
Reviewer Review Type Date Requested Status
Chris Halse Rogers Needs Fixing
Review via email: mp+30966@code.launchpad.net

Description of the change

Transmission plug-in.

Allows to control Transmission torrent client using XML-RPC API. Supports starting and stopping torrent downloads, choosing files to download, setting speed limits.

To post a comment you must log in.
Revision history for this message
Chris Halse Rogers (raof) wrote :

Oh, wow. Sorry for missing this for so long!

This looks good. I've only got two minor niggles, and one larger one. The two minor ones are: you should have copyright headers on the files you've created, and I'd generally use a lot more automatic properties rather than explicit private _foo variables.

The major one is that it bundles a binary copy of Jayrock.Json. We generally try to minimise the binaries we bundle in the source tree; most distributions will not accept packages with binaries bundled like this.

Given the terrible length of time that this has been waiting for a review, I'm happy to make these changes myself if you don't want to. I would like your email address, though, so that I can credit you in the Authors file properly.

review: Needs Fixing
Revision history for this message
kriomant (kriomant) wrote :

On 11 Dec 2011 10:16, "Chris Halse Rogers" <email address hidden> wrote:
>
> Review: Needs Fixing
>
> Oh, wow. Sorry for missing this for so long!

I thought development is completely stalled.

> This looks good. I've only got two minor niggles, and one larger one.
 The two minor ones are: you should have copyright headers on the files
you've created, and I'd generally use a lot more automatic properties
rather than explicit private _foo variables.
>
> The major one is that it bundles a binary copy of Jayrock.Json. We
generally try to minimise the binaries we bundle in the source tree; most
distributions will not accept packages with binaries bundled like this.

How will you solve this? I haven't found JSON library for Mono in standard
Ubuntu distribution. Will you include source code of Jayrock?

> Given the terrible length of time that this has been waiting for a
review, I'm happy to make these changes myself if you don't want to. I
would like your email address, though, so that I can credit you in the
Authors file properly.

It would be good.
My address is "Mikhail Trishchenkov <email address hidden>"

One more question: should I write wiki page?

> --
> https://code.launchpad.net/~kriomant/do-plugins/transmission/+merge/30966
> You are the owner of lp:~kriomant/do-plugins/transmission.

Revision history for this message
Chris Halse Rogers (raof) wrote :

I wouldn't bother writing a wiki page; I plan to take the wiki down, as it's become a hive of spam and villany and I don't have time to curate it properly.

I'll transfer the documentation into a local format, so it can be installed alongside the plugins. Once I've got that set up, you might want to add documentation there.

As for the JSON library, I'll see if Hyena.Json does what needs to be done here. If not, I'll grab the Jayrock source code and package it.

Revision history for this message
kriomant (kriomant) wrote :

Is there any progress?

Revision history for this message
Chris Halse Rogers (raof) wrote :

On Tue, 2012-01-10 at 17:33 +0000, kriomant wrote:
> Is there any progress?

Not on this, sorry. I'm slowly working my way through the blocker bugs
for the next core release. I hope to have that done this week or early
next week.

After I've done that I'll be able to work on plugins stuff, of which
this will be the first priority.

Revision history for this message
kriomant (kriomant) wrote :

Bump

Revision history for this message
kriomant (kriomant) wrote :

I have an impression that "this week" have already passed...

Revision history for this message
Chris Halse Rogers (raof) wrote :

The longest week ever has ended!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2010-06-29 08:19:20 +0000
+++ .bzrignore 2010-07-26 16:47:47 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1Makefile.in2Makefile.in
2Makefile3Makefile
3*.pc4*.pc
@@ -23,3 +24,11 @@
23*.addin.xml24*.addin.xml
24*.gmo25*.gmo
25m4/intltool.m426m4/intltool.m4
27=======
28Emesene.addin.xml
29Transmission/Makefile
30Transmission/Makefile.in
31Transmission/Transmission.pidb
32Transmission/bin
33Transmission/Resources/Transmission.addin.xml
34>>>>>>> MERGE-SOURCE
2635
=== modified file 'DoPlugins.mds'
--- DoPlugins.mds 2009-11-08 23:58:01 +0000
+++ DoPlugins.mds 2010-07-26 16:47:47 +0000
@@ -78,6 +78,7 @@
78 <Entry build="True" name="Baconator" configuration="Debug" />78 <Entry build="True" name="Baconator" configuration="Debug" />
79 <Entry build="True" name="Chromium" configuration="Debug" />79 <Entry build="True" name="Chromium" configuration="Debug" />
80 <Entry build="True" name="GNOME-Calculator" configuration="Debug" />80 <Entry build="True" name="GNOME-Calculator" configuration="Debug" />
81 <Entry build="True" name="Transmission" configuration="Debug" />
81 </Configuration>82 </Configuration>
82 <Configuration name="Release" ctype="CombineConfiguration">83 <Configuration name="Release" ctype="CombineConfiguration">
83 <Entry build="True" name="Rhythmbox" configuration="Release" />84 <Entry build="True" name="Rhythmbox" configuration="Release" />
@@ -157,6 +158,7 @@
157 <Entry build="True" name="Baconator" configuration="Release" />158 <Entry build="True" name="Baconator" configuration="Release" />
158 <Entry build="True" name="Chromium" configuration="Release" />159 <Entry build="True" name="Chromium" configuration="Release" />
159 <Entry build="True" name="GNOME-Calculator" configuration="Release" />160 <Entry build="True" name="GNOME-Calculator" configuration="Release" />
161 <Entry build="True" name="Transmission" configuration="Release" />
160 </Configuration>162 </Configuration>
161 </Configurations>163 </Configurations>
162 <StartMode startupentry="Rhythmbox" single="True">164 <StartMode startupentry="Rhythmbox" single="True">
@@ -237,6 +239,7 @@
237 <Execute type="None" entry="Baconator" />239 <Execute type="None" entry="Baconator" />
238 <Execute type="None" entry="Chromium" />240 <Execute type="None" entry="Chromium" />
239 <Execute type="None" entry="GNOME-Calculator" />241 <Execute type="None" entry="GNOME-Calculator" />
242 <Execute type="None" entry="Transmission" />
240 </StartMode>243 </StartMode>
241 <MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />244 <MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />
242 <Entries>245 <Entries>
@@ -317,5 +320,6 @@
317 <Entry filename="Baconator/Baconator.mdp" />320 <Entry filename="Baconator/Baconator.mdp" />
318 <Entry filename="Chromium/Chromium.mdp" />321 <Entry filename="Chromium/Chromium.mdp" />
319 <Entry filename="GNOME-Calculator/GNOME-Calculator.mdp" />322 <Entry filename="GNOME-Calculator/GNOME-Calculator.mdp" />
323 <Entry filename="Transmission/Transmission.mdp" />
320 </Entries>324 </Entries>
321</Combine>325</Combine>
322\ No newline at end of file326\ No newline at end of file
323327
=== modified file 'Makefile.am'
--- Makefile.am 2009-11-08 23:58:01 +0000
+++ Makefile.am 2010-07-26 16:47:47 +0000
@@ -70,6 +70,7 @@
70 TinyUrl \70 TinyUrl \
71 Tracker \71 Tracker \
72 Translate \72 Translate \
73 Transmission \
73 Tomboy \74 Tomboy \
74 Vinagre \75 Vinagre \
75 VirtualBox \76 VirtualBox \
7677
=== added directory 'Transmission'
=== added file 'Transmission/Makefile.am'
--- Transmission/Makefile.am 1970-01-01 00:00:00 +0000
+++ Transmission/Makefile.am 2010-07-26 16:47:47 +0000
@@ -0,0 +1,40 @@
1include $(top_srcdir)/build.rules.mk
2
3ASSEMBLY=Transmission
4
5FILES = \
6 gtk-gui/Transmission.TransmissionConfig.cs \
7 gtk-gui/generated.cs \
8 src/Config/TransmissionConfig.cs \
9 src/ITorrentEntry.cs \
10 src/JsonCollectionImporter.cs \
11 src/Utils.cs \
12 src/TorrentDirectoryItem.cs \
13 src/TorrentFileItem.cs \
14 src/TorrentFileSetPriorityAction.cs \
15 src/TorrentItem.cs \
16 src/TorrentItemSource.cs \
17 src/TorrentAbstractLimitSpeedAction.cs \
18 src/TorrentLimitDownloadSpeedAction.cs \
19 src/TorrentLimitUploadSpeedAction.cs \
20 src/TorrentMarkForDownloadAction.cs \
21 src/TorrentStartAction.cs \
22 src/TorrentStopAction.cs \
23 src/TorrentUnmarkForDownloadAction.cs \
24 src/TorrentVerifyAction.cs \
25 src/TorrentOperateAction.cs \
26 src/TransmissionAPI.cs \
27 src/TransmissionPlugin.cs
28
29RESOURCES = \
30 Resources/Transmission.addin.xml \
31 gtk-gui/gui.stetic \
32 Resources/icons/transmission.png
33
34REFERENCES = \
35 System \
36 System.Core \
37 lib/Jayrock.Json.dll \
38 $(DO_PLATFORM_LINUX_LIBS) \
39 $(DO_UNIVERSE_LIBS) \
40 $(GTK_SHARP_20_LIBS)
041
=== added directory 'Transmission/Resources'
=== added file 'Transmission/Resources/Transmission.addin.xml.in'
--- Transmission/Resources/Transmission.addin.xml.in 1970-01-01 00:00:00 +0000
+++ Transmission/Resources/Transmission.addin.xml.in 2010-07-26 16:47:47 +0000
@@ -0,0 +1,37 @@
1<Addin
2 id="Transmission"
3 namespace="Do"
4 version="0.1"
5 name="Transmission"
6 description="Control Transmission torrent client."
7 author="Mikhail Trishchenkov"
8 category="Community"
9 defaultEnabled="true"
10 url="http://do.davebsd.com/wiki/Transmission_Plugin"
11 >
12
13 <Runtime>
14 <Import assembly="Transmission.dll"/>
15 </Runtime>
16
17 <!--Localizer type="Gettext" catalog="gnome-do-plugins" location="@expanded_datadir@/locale" /-->
18
19 <Dependencies>
20 <Addin id="Universe" version="1.0" />
21 </Dependencies>
22
23 <Extension path="/Do/ItemSource">
24 <ItemSource type="Transmission.TorrentItemSource" />
25 </Extension>
26 <Extension path="/Do/Action">
27 <Action type="Transmission.TorrentStopAction" />
28 <Action type="Transmission.TorrentStartAction" />
29 <Action type="Transmission.TorrentVerifyAction" />
30 <Action type="Transmission.TorrentLimitDownloadSpeedAction" />
31 <Action type="Transmission.TorrentLimitUploadSpeedAction" />
32 <Action type="Transmission.TorrentFileSetPriorityAction" />
33 <Action type="Transmission.TorrentMarkForDownloadAction" />
34 <Action type="Transmission.TorrentUnmarkForDownloadAction" />
35 <Action type="Transmission.TorrentOperateAction" />
36 </Extension>
37</Addin>
038
=== added directory 'Transmission/Resources/icons'
=== added file 'Transmission/Resources/icons/transmission.png'
1Binary files Transmission/Resources/icons/transmission.png 1970-01-01 00:00:00 +0000 and Transmission/Resources/icons/transmission.png 2010-07-26 16:47:47 +0000 differ39Binary files Transmission/Resources/icons/transmission.png 1970-01-01 00:00:00 +0000 and Transmission/Resources/icons/transmission.png 2010-07-26 16:47:47 +0000 differ
=== added file 'Transmission/Transmission.mdp'
--- Transmission/Transmission.mdp 1970-01-01 00:00:00 +0000
+++ Transmission/Transmission.mdp 2010-07-26 16:47:47 +0000
@@ -0,0 +1,64 @@
1<Project name="Transmission" fileversion="2.0" DefaultNamespace="Transmission" language="C#" targetFramework="3.5" ctype="DotNetProject">
2 <Configurations active="Debug">
3 <Configuration name="Debug" ctype="DotNetProjectConfiguration">
4 <Output directory="bin/Debug" assembly="Transmission" />
5 <Build debugmode="True" target="Library" />
6 <Execution consolepause="True" runwithwarnings="True" runtime="MsNet" />
7 <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
8 </Configuration>
9 <Configuration name="Release" ctype="DotNetProjectConfiguration">
10 <Output directory="bin/Release" assembly="Transmission" />
11 <Build debugmode="False" target="Library" />
12 <Execution consolepause="True" runwithwarnings="True" runtime="MsNet" />
13 <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
14 </Configuration>
15 </Configurations>
16 <Contents>
17 <File subtype="Directory" buildaction="Compile" name="src" />
18 <File subtype="Directory" buildaction="Compile" name="Resources" />
19 <File subtype="Code" buildaction="Nothing" name="Resources/Transmission.addin.xml" />
20 <File subtype="Code" buildaction="EmbedAsResource" name="gtk-gui/gui.stetic" />
21 <File subtype="Code" buildaction="Compile" name="gtk-gui/generated.cs" />
22 <File subtype="Code" buildaction="Compile" name="gtk-gui/Transmission.TransmissionConfig.cs" />
23 <File subtype="Code" buildaction="Compile" name="src/Config/TransmissionConfig.cs" />
24 <File subtype="Directory" buildaction="Compile" name="Resources/icons" />
25 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-add.png" />
26 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-remove.png" />
27 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-revisions.png" />
28 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-share.png" />
29 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-start.png" />
30 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-stop.png" />
31 <File subtype="Code" buildaction="Nothing" name="Resources/icons/transmission-web.png" />
32 <File subtype="Code" buildaction="Compile" name="src/ITorrentEntry.cs" />
33 <File subtype="Code" buildaction="Compile" name="src/JsonCollectionImporter.cs" />
34 <File subtype="Code" buildaction="Compile" name="src/TorrentDirectoryItem.cs" />
35 <File subtype="Code" buildaction="Compile" name="src/TorrentFileItem.cs" />
36 <File subtype="Code" buildaction="Compile" name="src/TorrentFileSetPriorityAction.cs" />
37 <File subtype="Code" buildaction="Compile" name="src/TorrentItem.cs" />
38 <File subtype="Code" buildaction="Compile" name="src/TorrentItemSource.cs" />
39 <File subtype="Code" buildaction="Compile" name="src/TorrentAbstractLimitSpeedAction.cs" />
40 <File subtype="Code" buildaction="Compile" name="src/TorrentLimitDownloadSpeedAction.cs" />
41 <File subtype="Code" buildaction="Compile" name="src/TorrentMarkForDownloadAction.cs" />
42 <File subtype="Code" buildaction="Compile" name="src/TorrentStartAction.cs" />
43 <File subtype="Code" buildaction="Compile" name="src/TorrentStopAction.cs" />
44 <File subtype="Code" buildaction="Compile" name="src/TorrentUnmarkForDownloadAction.cs" />
45 <File subtype="Code" buildaction="Compile" name="src/TorrentVerifyAction.cs" />
46 <File subtype="Code" buildaction="Compile" name="src/TransmissionAPI.cs" />
47 <File subtype="Code" buildaction="Compile" name="src/TransmissionPlugin.cs" />
48 <File subtype="Code" buildaction="Compile" name="src/Utils.cs" />
49 <File subtype="Code" buildaction="Compile" name="src/TorrentLimitUploadSpeedAction.cs" />
50 <File subtype="Code" buildaction="Compile" name="src/TorrentOperateAction.cs" />
51 </Contents>
52 <References>
53 <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
54 <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
55 <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
56 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
57 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
58 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.9.0.0, Culture=neutral" />
59 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.9.0.0, Culture=neutral" />
60 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform.Linux, Version=0.9.0.0, Culture=neutral" />
61 <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="lib/Jayrock.Json.dll" />
62 </References>
63 <GtkDesignInfo gettextClass="Mono.Addins.AddinManager.CurrentLocalizer" />
64</Project>
0\ No newline at end of file65\ No newline at end of file
166
=== added directory 'Transmission/gtk-gui'
=== added file 'Transmission/gtk-gui/Transmission.TransmissionConfig.cs'
--- Transmission/gtk-gui/Transmission.TransmissionConfig.cs 1970-01-01 00:00:00 +0000
+++ Transmission/gtk-gui/Transmission.TransmissionConfig.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,161 @@
1// ------------------------------------------------------------------------------
2// <autogenerated>
3// This code was generated by a tool.
4//
5//
6// Changes to this file may cause incorrect behavior and will be lost if
7// the code is regenerated.
8// </autogenerated>
9// ------------------------------------------------------------------------------
10
11namespace Transmission {
12
13
14 public partial class TransmissionConfig {
15
16 private Gtk.Alignment alignment108;
17
18 private Gtk.Table table1;
19
20 private Gtk.HBox hbox1;
21
22 private Gtk.Entry address_entry;
23
24 private Gtk.Label remote_port_label;
25
26 private Gtk.Entry port_entry;
27
28 private Gtk.Label label1;
29
30 private Gtk.Label label2;
31
32 private Gtk.Label label3;
33
34 private Gtk.Entry password_entry;
35
36 private Gtk.Entry user_name_entry;
37
38 protected virtual void Build() {
39 Stetic.Gui.Initialize(this);
40 // Widget Transmission.TransmissionConfig
41 Stetic.BinContainer.Attach(this);
42 this.Name = "Transmission.TransmissionConfig";
43 // Container child Transmission.TransmissionConfig.Gtk.Container+ContainerChild
44 this.alignment108 = new Gtk.Alignment(0.5F, 0F, 1F, 0F);
45 this.alignment108.Name = "alignment108";
46 // Container child alignment108.Gtk.Container+ContainerChild
47 this.table1 = new Gtk.Table(((uint)(3)), ((uint)(2)), false);
48 this.table1.Name = "table1";
49 this.table1.RowSpacing = ((uint)(6));
50 this.table1.ColumnSpacing = ((uint)(6));
51 // Container child table1.Gtk.Table+TableChild
52 this.hbox1 = new Gtk.HBox();
53 this.hbox1.Name = "hbox1";
54 this.hbox1.Spacing = 6;
55 // Container child hbox1.Gtk.Box+BoxChild
56 this.address_entry = new Gtk.Entry();
57 this.address_entry.CanFocus = true;
58 this.address_entry.Name = "address_entry";
59 this.address_entry.IsEditable = true;
60 this.address_entry.InvisibleChar = '●';
61 this.hbox1.Add(this.address_entry);
62 Gtk.Box.BoxChild w1 = ((Gtk.Box.BoxChild)(this.hbox1[this.address_entry]));
63 w1.Position = 0;
64 // Container child hbox1.Gtk.Box+BoxChild
65 this.remote_port_label = new Gtk.Label();
66 this.remote_port_label.Name = "remote_port_label";
67 this.remote_port_label.LabelProp = Mono.Addins.AddinManager.CurrentLocalizer.GetString("Port");
68 this.hbox1.Add(this.remote_port_label);
69 Gtk.Box.BoxChild w2 = ((Gtk.Box.BoxChild)(this.hbox1[this.remote_port_label]));
70 w2.Position = 1;
71 w2.Expand = false;
72 w2.Fill = false;
73 // Container child hbox1.Gtk.Box+BoxChild
74 this.port_entry = new Gtk.Entry();
75 this.port_entry.CanFocus = true;
76 this.port_entry.Name = "port_entry";
77 this.port_entry.IsEditable = true;
78 this.port_entry.WidthChars = 5;
79 this.port_entry.MaxLength = 5;
80 this.port_entry.InvisibleChar = '●';
81 this.hbox1.Add(this.port_entry);
82 Gtk.Box.BoxChild w3 = ((Gtk.Box.BoxChild)(this.hbox1[this.port_entry]));
83 w3.Position = 2;
84 w3.Expand = false;
85 this.table1.Add(this.hbox1);
86 Gtk.Table.TableChild w4 = ((Gtk.Table.TableChild)(this.table1[this.hbox1]));
87 w4.LeftAttach = ((uint)(1));
88 w4.RightAttach = ((uint)(2));
89 w4.YOptions = ((Gtk.AttachOptions)(4));
90 // Container child table1.Gtk.Table+TableChild
91 this.label1 = new Gtk.Label();
92 this.label1.Name = "label1";
93 this.label1.Xalign = 0F;
94 this.label1.LabelProp = Mono.Addins.AddinManager.CurrentLocalizer.GetString("_Address");
95 this.label1.UseUnderline = true;
96 this.table1.Add(this.label1);
97 Gtk.Table.TableChild w5 = ((Gtk.Table.TableChild)(this.table1[this.label1]));
98 w5.XOptions = ((Gtk.AttachOptions)(4));
99 w5.YOptions = ((Gtk.AttachOptions)(4));
100 // Container child table1.Gtk.Table+TableChild
101 this.label2 = new Gtk.Label();
102 this.label2.Name = "label2";
103 this.label2.Xalign = 0F;
104 this.label2.LabelProp = Mono.Addins.AddinManager.CurrentLocalizer.GetString("_Password");
105 this.label2.UseUnderline = true;
106 this.table1.Add(this.label2);
107 Gtk.Table.TableChild w6 = ((Gtk.Table.TableChild)(this.table1[this.label2]));
108 w6.TopAttach = ((uint)(2));
109 w6.BottomAttach = ((uint)(3));
110 w6.XOptions = ((Gtk.AttachOptions)(4));
111 w6.YOptions = ((Gtk.AttachOptions)(4));
112 // Container child table1.Gtk.Table+TableChild
113 this.label3 = new Gtk.Label();
114 this.label3.Name = "label3";
115 this.label3.Xalign = 0F;
116 this.label3.LabelProp = Mono.Addins.AddinManager.CurrentLocalizer.GetString("_Login");
117 this.label3.UseUnderline = true;
118 this.table1.Add(this.label3);
119 Gtk.Table.TableChild w7 = ((Gtk.Table.TableChild)(this.table1[this.label3]));
120 w7.TopAttach = ((uint)(1));
121 w7.BottomAttach = ((uint)(2));
122 w7.XOptions = ((Gtk.AttachOptions)(4));
123 w7.YOptions = ((Gtk.AttachOptions)(4));
124 // Container child table1.Gtk.Table+TableChild
125 this.password_entry = new Gtk.Entry();
126 this.password_entry.CanFocus = true;
127 this.password_entry.Name = "password_entry";
128 this.password_entry.IsEditable = true;
129 this.password_entry.Visibility = false;
130 this.password_entry.InvisibleChar = '●';
131 this.table1.Add(this.password_entry);
132 Gtk.Table.TableChild w8 = ((Gtk.Table.TableChild)(this.table1[this.password_entry]));
133 w8.TopAttach = ((uint)(2));
134 w8.BottomAttach = ((uint)(3));
135 w8.LeftAttach = ((uint)(1));
136 w8.RightAttach = ((uint)(2));
137 w8.YOptions = ((Gtk.AttachOptions)(4));
138 // Container child table1.Gtk.Table+TableChild
139 this.user_name_entry = new Gtk.Entry();
140 this.user_name_entry.CanFocus = true;
141 this.user_name_entry.Name = "user_name_entry";
142 this.user_name_entry.IsEditable = true;
143 this.user_name_entry.InvisibleChar = '●';
144 this.table1.Add(this.user_name_entry);
145 Gtk.Table.TableChild w9 = ((Gtk.Table.TableChild)(this.table1[this.user_name_entry]));
146 w9.TopAttach = ((uint)(1));
147 w9.BottomAttach = ((uint)(2));
148 w9.LeftAttach = ((uint)(1));
149 w9.RightAttach = ((uint)(2));
150 w9.YOptions = ((Gtk.AttachOptions)(4));
151 this.alignment108.Add(this.table1);
152 this.Add(this.alignment108);
153 if ((this.Child != null)) {
154 this.Child.ShowAll();
155 }
156 this.Hide();
157 this.user_name_entry.Changed += new System.EventHandler(this.OnUserNameEntryChanged);
158 this.password_entry.Changed += new System.EventHandler(this.OnPasswordEntryChanged);
159 }
160 }
161}
0162
=== added file 'Transmission/gtk-gui/generated.cs'
--- Transmission/gtk-gui/generated.cs 1970-01-01 00:00:00 +0000
+++ Transmission/gtk-gui/generated.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,82 @@
1// ------------------------------------------------------------------------------
2// <autogenerated>
3// This code was generated by a tool.
4//
5//
6// Changes to this file may cause incorrect behavior and will be lost if
7// the code is regenerated.
8// </autogenerated>
9// ------------------------------------------------------------------------------
10
11namespace Stetic {
12
13
14 internal class Gui {
15
16 private static bool initialized;
17
18 internal static void Initialize(Gtk.Widget iconRenderer) {
19 if ((Stetic.Gui.initialized == false)) {
20 Stetic.Gui.initialized = true;
21 }
22 }
23 }
24
25 internal class BinContainer {
26
27 private Gtk.Widget child;
28
29 private Gtk.UIManager uimanager;
30
31 public static BinContainer Attach(Gtk.Bin bin) {
32 BinContainer bc = new BinContainer();
33 bin.SizeRequested += new Gtk.SizeRequestedHandler(bc.OnSizeRequested);
34 bin.SizeAllocated += new Gtk.SizeAllocatedHandler(bc.OnSizeAllocated);
35 bin.Added += new Gtk.AddedHandler(bc.OnAdded);
36 return bc;
37 }
38
39 private void OnSizeRequested(object sender, Gtk.SizeRequestedArgs args) {
40 if ((this.child != null)) {
41 args.Requisition = this.child.SizeRequest();
42 }
43 }
44
45 private void OnSizeAllocated(object sender, Gtk.SizeAllocatedArgs args) {
46 if ((this.child != null)) {
47 this.child.Allocation = args.Allocation;
48 }
49 }
50
51 private void OnAdded(object sender, Gtk.AddedArgs args) {
52 this.child = args.Widget;
53 }
54
55 public void SetUiManager(Gtk.UIManager uim) {
56 this.uimanager = uim;
57 this.child.Realized += new System.EventHandler(this.OnRealized);
58 }
59
60 private void OnRealized(object sender, System.EventArgs args) {
61 if ((this.uimanager != null)) {
62 Gtk.Widget w;
63 w = this.child.Toplevel;
64 if (((w != null) && typeof(Gtk.Window).IsInstanceOfType(w))) {
65 ((Gtk.Window)(w)).AddAccelGroup(this.uimanager.AccelGroup);
66 this.uimanager = null;
67 }
68 }
69 }
70 }
71
72 internal class ActionGroups {
73
74 public static Gtk.ActionGroup GetActionGroup(System.Type type) {
75 return Stetic.ActionGroups.GetActionGroup(type.FullName);
76 }
77
78 public static Gtk.ActionGroup GetActionGroup(string name) {
79 return null;
80 }
81 }
82}
083
=== added file 'Transmission/gtk-gui/gui.stetic'
--- Transmission/gtk-gui/gui.stetic 1970-01-01 00:00:00 +0000
+++ Transmission/gtk-gui/gui.stetic 2010-07-26 16:47:47 +0000
@@ -0,0 +1,196 @@
1<?xml version="1.0" encoding="utf-8"?>
2<stetic-interface>
3 <configuration>
4 <images-root-path>..</images-root-path>
5 <target-gtk-version>2.12</target-gtk-version>
6 </configuration>
7 <import>
8 <widget-library name="Do.Platform.Linux, Version=0.9.0.0, Culture=neutral" />
9 <widget-library name="../bin/Debug/Transmission.dll" internal="true" />
10 </import>
11 <widget class="Gtk.Bin" id="Transmission.TransmissionConfig" design-size="444 300">
12 <property name="MemberName" />
13 <property name="Visible">False</property>
14 <child>
15 <widget class="Gtk.Alignment" id="alignment108">
16 <property name="MemberName" />
17 <property name="Yscale">0</property>
18 <property name="Yalign">0</property>
19 <child>
20 <widget class="Gtk.Table" id="table1">
21 <property name="MemberName" />
22 <property name="NRows">3</property>
23 <property name="NColumns">2</property>
24 <property name="RowSpacing">6</property>
25 <property name="ColumnSpacing">6</property>
26 <child>
27 <widget class="Gtk.HBox" id="hbox1">
28 <property name="MemberName" />
29 <property name="Spacing">6</property>
30 <child>
31 <widget class="Gtk.Entry" id="address_entry">
32 <property name="MemberName" />
33 <property name="CanFocus">True</property>
34 <property name="IsEditable">True</property>
35 <property name="InvisibleChar">●</property>
36 </widget>
37 <packing>
38 <property name="Position">0</property>
39 <property name="AutoSize">True</property>
40 </packing>
41 </child>
42 <child>
43 <widget class="Gtk.Label" id="remote_port_label">
44 <property name="MemberName">remote_port_label</property>
45 <property name="LabelProp" translatable="yes">Port</property>
46 </widget>
47 <packing>
48 <property name="Position">1</property>
49 <property name="AutoSize">True</property>
50 <property name="Expand">False</property>
51 <property name="Fill">False</property>
52 </packing>
53 </child>
54 <child>
55 <widget class="Gtk.Entry" id="port_entry">
56 <property name="MemberName">port_entry</property>
57 <property name="CanFocus">True</property>
58 <property name="IsEditable">True</property>
59 <property name="WidthChars">5</property>
60 <property name="MaxLength">5</property>
61 <property name="InvisibleChar">●</property>
62 </widget>
63 <packing>
64 <property name="Position">2</property>
65 <property name="AutoSize">False</property>
66 <property name="Expand">False</property>
67 </packing>
68 </child>
69 </widget>
70 <packing>
71 <property name="LeftAttach">1</property>
72 <property name="RightAttach">2</property>
73 <property name="AutoSize">True</property>
74 <property name="YOptions">Fill</property>
75 <property name="XExpand">True</property>
76 <property name="XFill">True</property>
77 <property name="XShrink">False</property>
78 <property name="YExpand">False</property>
79 <property name="YFill">True</property>
80 <property name="YShrink">False</property>
81 </packing>
82 </child>
83 <child>
84 <widget class="Gtk.Label" id="label1">
85 <property name="MemberName" />
86 <property name="Xalign">0</property>
87 <property name="LabelProp" translatable="yes">_Address</property>
88 <property name="UseUnderline">True</property>
89 </widget>
90 <packing>
91 <property name="AutoSize">True</property>
92 <property name="XOptions">Fill</property>
93 <property name="YOptions">Fill</property>
94 <property name="XExpand">False</property>
95 <property name="XFill">True</property>
96 <property name="XShrink">False</property>
97 <property name="YExpand">False</property>
98 <property name="YFill">True</property>
99 <property name="YShrink">False</property>
100 </packing>
101 </child>
102 <child>
103 <widget class="Gtk.Label" id="label2">
104 <property name="MemberName" />
105 <property name="Xalign">0</property>
106 <property name="LabelProp" translatable="yes">_Password</property>
107 <property name="UseUnderline">True</property>
108 </widget>
109 <packing>
110 <property name="TopAttach">2</property>
111 <property name="BottomAttach">3</property>
112 <property name="AutoSize">True</property>
113 <property name="XOptions">Fill</property>
114 <property name="YOptions">Fill</property>
115 <property name="XExpand">False</property>
116 <property name="XFill">True</property>
117 <property name="XShrink">False</property>
118 <property name="YExpand">False</property>
119 <property name="YFill">True</property>
120 <property name="YShrink">False</property>
121 </packing>
122 </child>
123 <child>
124 <widget class="Gtk.Label" id="label3">
125 <property name="MemberName" />
126 <property name="Xalign">0</property>
127 <property name="LabelProp" translatable="yes">_Login</property>
128 <property name="UseUnderline">True</property>
129 </widget>
130 <packing>
131 <property name="TopAttach">1</property>
132 <property name="BottomAttach">2</property>
133 <property name="AutoSize">True</property>
134 <property name="XOptions">Fill</property>
135 <property name="YOptions">Fill</property>
136 <property name="XExpand">False</property>
137 <property name="XFill">True</property>
138 <property name="XShrink">False</property>
139 <property name="YExpand">False</property>
140 <property name="YFill">True</property>
141 <property name="YShrink">False</property>
142 </packing>
143 </child>
144 <child>
145 <widget class="Gtk.Entry" id="password_entry">
146 <property name="MemberName" />
147 <property name="CanFocus">True</property>
148 <property name="IsEditable">True</property>
149 <property name="Visibility">False</property>
150 <property name="InvisibleChar">●</property>
151 <signal name="Changed" handler="OnPasswordEntryChanged" />
152 </widget>
153 <packing>
154 <property name="TopAttach">2</property>
155 <property name="BottomAttach">3</property>
156 <property name="LeftAttach">1</property>
157 <property name="RightAttach">2</property>
158 <property name="AutoSize">True</property>
159 <property name="YOptions">Fill</property>
160 <property name="XExpand">True</property>
161 <property name="XFill">True</property>
162 <property name="XShrink">False</property>
163 <property name="YExpand">False</property>
164 <property name="YFill">True</property>
165 <property name="YShrink">False</property>
166 </packing>
167 </child>
168 <child>
169 <widget class="Gtk.Entry" id="user_name_entry">
170 <property name="MemberName" />
171 <property name="CanFocus">True</property>
172 <property name="IsEditable">True</property>
173 <property name="InvisibleChar">●</property>
174 <signal name="Changed" handler="OnUserNameEntryChanged" />
175 </widget>
176 <packing>
177 <property name="TopAttach">1</property>
178 <property name="BottomAttach">2</property>
179 <property name="LeftAttach">1</property>
180 <property name="RightAttach">2</property>
181 <property name="AutoSize">True</property>
182 <property name="YOptions">Fill</property>
183 <property name="XExpand">True</property>
184 <property name="XFill">True</property>
185 <property name="XShrink">False</property>
186 <property name="YExpand">False</property>
187 <property name="YFill">True</property>
188 <property name="YShrink">False</property>
189 </packing>
190 </child>
191 </widget>
192 </child>
193 </widget>
194 </child>
195 </widget>
196</stetic-interface>
0\ No newline at end of file197\ No newline at end of file
1198
=== added directory 'Transmission/lib'
=== added file 'Transmission/lib/Jayrock.Json.dll'
2Binary files Transmission/lib/Jayrock.Json.dll 1970-01-01 00:00:00 +0000 and Transmission/lib/Jayrock.Json.dll 2010-07-26 16:47:47 +0000 differ199Binary files Transmission/lib/Jayrock.Json.dll 1970-01-01 00:00:00 +0000 and Transmission/lib/Jayrock.Json.dll 2010-07-26 16:47:47 +0000 differ
=== added file 'Transmission/lib/Jayrock.Json.pdb'
3Binary files Transmission/lib/Jayrock.Json.pdb 1970-01-01 00:00:00 +0000 and Transmission/lib/Jayrock.Json.pdb 2010-07-26 16:47:47 +0000 differ200Binary files Transmission/lib/Jayrock.Json.pdb 1970-01-01 00:00:00 +0000 and Transmission/lib/Jayrock.Json.pdb 2010-07-26 16:47:47 +0000 differ
=== added directory 'Transmission/src'
=== added directory 'Transmission/src/Config'
=== added file 'Transmission/src/Config/TransmissionConfig.cs'
--- Transmission/src/Config/TransmissionConfig.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/Config/TransmissionConfig.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,91 @@
1using System;
2using System.IO;
3using System.Text;
4
5using Mono.Addins;
6
7using Gtk;
8
9using Do.Platform;
10
11namespace Transmission
12{
13
14 [System.ComponentModel.Category("File")]
15 [System.ComponentModel.ToolboxItem(true)]
16 public partial class TransmissionConfig : Gtk.Bin
17 {
18 public static string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
19 public static string settings_path = System.IO.Path.Combine (home_path, ".config/transmission/settings.json");
20
21 static IPreferences prefs;
22
23 public TransmissionConfig()
24 {
25 Build();
26 RefreshView();
27 }
28
29 private void RefreshView()
30 {
31 address_entry.Text = Address;
32 port_entry.Text = Port.ToString();
33 user_name_entry.Text = UserName;
34 password_entry.Text = Password;
35 }
36
37 static TransmissionConfig()
38 {
39 prefs = Services.Preferences.Get<TransmissionConfig>();
40 }
41
42 public static string Address
43 {
44 get { return prefs.Get<string>("Address", "127.0.0.1"); }
45 set { prefs.Set<string> ("Address", value); }
46 }
47
48 public static int Port
49 {
50 get { return prefs.Get<int>("Port", TransmissionAPI.DEFAULT_PORT); }
51 set { prefs.Set<int> ("Port", value); }
52 }
53
54 public static string UserName
55 {
56 get { return prefs.Get<string>("UserName", ""); }
57 set { prefs.Set<string> ("UserName", value); }
58 }
59
60 public static string Password
61 {
62 get { return prefs.Get<string>("Password", ""); }
63 set { prefs.Set<string> ("Password", value); }
64 }
65
66 protected virtual void OnAddressEntryChanged (object sender, System.EventArgs e)
67 {
68 Address = address_entry.Text;
69 TransmissionPlugin.ResetConnection();
70 }
71
72 protected virtual void OnUserNameEntryChanged (object sender, System.EventArgs e)
73 {
74 UserName = user_name_entry.Text;
75 TransmissionPlugin.ResetConnection();
76 }
77
78 protected virtual void OnPasswordEntryChanged (object sender, System.EventArgs e)
79 {
80 Password = password_entry.Text;
81 TransmissionPlugin.ResetConnection();
82 }
83
84 protected virtual void OnPortEntryChanged (object sender, System.EventArgs e)
85 {
86 Port = int.Parse(port_entry.Text);
87 TransmissionPlugin.ResetConnection();
88 }
89
90 }
91}
092
=== added file 'Transmission/src/ITorrentEntry.cs'
--- Transmission/src/ITorrentEntry.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/ITorrentEntry.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,16 @@
1using System.Collections.Generic;
2
3namespace Transmission {
4
5 public interface ITorrentEntry {
6 // Owner torrent.
7 TorrentItem Torrent { get; }
8
9 // Path on FS.
10 string Path { get; }
11
12 // Get all files under this entry (recursively).
13 // For files return file itself.
14 IEnumerable<TorrentFileItem> GetFiles();
15 }
16}
017
=== added file 'Transmission/src/JsonCollectionImporter.cs'
--- Transmission/src/JsonCollectionImporter.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/JsonCollectionImporter.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,117 @@
1namespace Transmission
2{
3 #region Imports
4
5 using System;
6 using System.Collections.Generic;
7 using System.Diagnostics;
8 using Jayrock.Json;
9 using Jayrock.Json.Conversion;
10 using Jayrock.Json.Conversion.Converters;
11
12 #endregion
13
14 /// <summary>
15 /// An abstract base class for importer implementations that can import
16 /// a concrete collection instance from a JSON array.
17 /// </summary>
18
19
20 public abstract class CollectionImporterBase : ImporterBase
21 {
22 private readonly Type _elementType;
23
24
25 public CollectionImporterBase(Type outputType, Type elementType) :
26 base(outputType)
27 {
28 if (elementType == null) throw new ArgumentNullException("elementType");
29
30 _elementType = elementType;
31 }
32
33
34 public Type ElementType
35 {
36 get { return _elementType; }
37 }
38
39
40 protected override object ImportFromArray(ImportContext context, JsonReader reader)
41 {
42 if (context == null) throw new ArgumentNullException("context");
43 if (reader == null) throw new ArgumentNullException("reader");
44
45
46 object collection = CreateCollection();
47
48
49 reader.ReadToken(JsonTokenClass.Array);
50
51
52 ImportElements(collection, context, reader);
53
54
55 if (reader.TokenClass != JsonTokenClass.EndArray)
56 throw new Exception("Implementation error.");
57
58
59 reader.Read();
60 return collection;
61 }
62
63
64 protected abstract object CreateCollection();
65 protected abstract void ImportElements(object collection, ImportContext context, JsonReader reader);
66 }
67
68
69 /// <summary>
70 /// An importer for importing a collection of elements from a JSON array.
71 /// </summary>
72
73
74 public class CollectionImporter<Collection, Element> : CollectionImporterBase
75 where Collection : ICollection<Element>, new()
76 {
77 public CollectionImporter() :
78 base(typeof(Collection), typeof(Element)) { }
79
80
81 protected override object CreateCollection()
82 {
83 return new Collection();
84 }
85
86
87 protected override void ImportElements(object collection, ImportContext context, JsonReader reader)
88 {
89 if (collection == null) throw new ArgumentNullException("collection");
90 if (context == null) throw new ArgumentNullException("context");
91 if (reader == null) throw new ArgumentNullException("reader");
92
93
94 ImportElements((ICollection<Element>) collection, context, reader);
95 }
96
97
98 private static void ImportElements(ICollection<Element> collection, ImportContext context, JsonReader reader)
99 {
100 Debug.Assert(collection != null);
101 Debug.Assert(context != null);
102 Debug.Assert(reader != null);
103
104
105 while (reader.TokenClass != JsonTokenClass.EndArray)
106 collection.Add((Element) context.Import(typeof(Element), reader));
107 }
108 }
109
110 /// <summary>
111 /// Imports <see cref="List{T}"/> from a JSON array.
112 /// </summary>
113
114 public class ListImporter<T> : CollectionImporter<List<T>, T>
115 where T : new() { }
116
117}
0\ No newline at end of file118\ No newline at end of file
1119
=== added file 'Transmission/src/TorrentAbstractLimitSpeedAction.cs'
--- Transmission/src/TorrentAbstractLimitSpeedAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentAbstractLimitSpeedAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,80 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5using System.Text.RegularExpressions;
6
7using Mono.Addins;
8
9using Do.Platform;
10using Do.Universe;
11
12namespace Transmission {
13
14 public abstract class TorrentAbstractLimitSpeedAction: Act {
15
16 public override IEnumerable<Type> SupportedItemTypes {
17 get { yield return typeof (TorrentItem); }
18 }
19
20 public override IEnumerable<Type> SupportedModifierItemTypes {
21 get {
22 yield return typeof (ITextItem);
23 yield return typeof (PredefinedSpeed);
24 }
25 }
26
27 public override bool ModifierItemsOptional {
28 get { return false; }
29 }
30
31 protected abstract PredefinedSpeed GetCurrentSpeedItem(TorrentItem torrent);
32
33 public override IEnumerable<Item> DynamicModifierItemsForItem(Item item) {
34 TorrentItem torrent = (TorrentItem)item;
35
36 yield return new PredefinedSpeed(0, "Unlimited", "Turn download speed limit off");
37 yield return GetCurrentSpeedItem(torrent);
38 foreach (PredefinedSpeed speed in Utils.PredefinedSpeedItems)
39 yield return speed;
40 }
41
42 protected abstract void SetSpeedLimit(TransmissionAPI api, IEnumerable<TorrentItem> torrents, int speed);
43
44 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
45 int? speed = null;
46
47 // Get speed item, it can be either ITextItem or PredefinedSpeed.
48 Item modItem = modItems.First();
49 if (modItem is PredefinedSpeed) {
50 speed = ((PredefinedSpeed)modItem).Value;
51 } else {
52 string speed_str = ((ITextItem)modItem).Text;
53
54 try {
55 // Try to parse entered speed value.
56 speed = Utils.ParseSpeed(speed_str);
57
58 } catch (ArgumentException) {
59 Log<TransmissionPlugin>.Debug("Invalid speed string: {0}", speed_str);
60
61 // Show notification about invalid speed value with some hints on
62 // accepted formats.
63 string message = AddinManager.CurrentLocalizer.GetString(
64 "Can't recognize \"{0}\" as speed\nUse values like: 100k, 50 kb, 20m, 10 mib"
65 );
66 Services.Notifications.Notify("Transmission", string.Format(message, speed_str), "transmission");
67 }
68 }
69
70 // If speed is recognized successfully, set speed limit and update item.
71 if (speed.HasValue) {
72 TransmissionAPI api = TransmissionPlugin.getTransmission();
73 IEnumerable<TorrentItem> torrents = items.Cast<TorrentItem>();
74 SetSpeedLimit(api, torrents, speed.Value);
75 }
76
77 yield break;
78 }
79 }
80}
081
=== added file 'Transmission/src/TorrentDirectoryItem.cs'
--- Transmission/src/TorrentDirectoryItem.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentDirectoryItem.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,64 @@
1
2using System;
3using System.Collections.Generic;
4
5using Do.Universe;
6
7namespace 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}
065
=== added file 'Transmission/src/TorrentFileItem.cs'
--- Transmission/src/TorrentFileItem.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentFileItem.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,97 @@
1
2using System;
3using System.Collections.Generic;
4
5using Do.Universe;
6
7namespace Transmission {
8
9 public class TorrentFileItem: Item, ITorrentEntry {
10
11 // Owner torrent.
12 private TorrentItem _torrent;
13 // Position of this file within torrents file list.
14 private int _index;
15
16 private TorrentDirectoryItem _parent;
17 private string _name;
18 private long _size, _downloaded;
19 private bool _wanted;
20 private TransmissionAPI.FilePriority _priority;
21
22 public TorrentFileItem(
23 TorrentItem torrent, int index, TorrentDirectoryItem parent,
24 string name, TransmissionAPI.TorrentFileInfo info
25 ) {
26 _torrent = torrent;
27 _index = index;
28
29 _parent = parent;
30 _name = name;
31 _size = info.Length;
32 _downloaded = info.BytesCompleted;
33
34 _wanted = info.Wanted;
35 _priority = info.Priority;
36 }
37
38 public TorrentItem Torrent {
39 get { return _torrent; }
40 }
41
42 public int Index {
43 get { return _index; }
44 }
45
46 public TransmissionAPI.FilePriority Priority {
47 get { return _priority; }
48 }
49
50 public IEnumerable<TorrentFileItem> GetFiles() {
51 yield return this;
52 }
53
54 public override string Name {
55 get { return _name; }
56 }
57
58 public override string Description {
59 get {
60 // I don't use special percentage format string, because it rounds
61 // value and I don't want to get "100%" until file is really downloaded.
62 // High precision isn't needed, because info is mostly out-of-date.
63
64 if (_downloaded == _size)
65 return string.Format("Complete, {0}", Utils.FormatSize(_size));
66
67 else if (_wanted)
68 return string.Format("{0} of {1} complete ({2:0}%)",
69 Utils.FormatSize(_downloaded), Utils.FormatSize(_size),
70 Math.Floor(100.0 * _downloaded / _size)
71 );
72
73 else if (_downloaded != 0)
74 return string.Format("Skipped, {0} of {1} complete ({2:0}%)",
75 Utils.FormatSize(_downloaded),Utils.FormatSize(_size),
76 Math.Floor(100.0 * _downloaded / _size)
77 );
78
79 else
80 return string.Format("Skipped, {0}", Utils.FormatSize(_size));
81 }
82 }
83
84 public override string Icon {
85 get { return "document"; }
86 }
87
88 public string Path {
89 get { return _parent.Path + '/' + _name; }
90 }
91
92 public string Uri {
93 get { return "file://" + Path; }
94 }
95 }
96
97}
098
=== added file 'Transmission/src/TorrentFileSetPriorityAction.cs'
--- Transmission/src/TorrentFileSetPriorityAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentFileSetPriorityAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,108 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Platform;
9using Do.Universe;
10
11namespace Transmission {
12
13 public class PriorityItem: Item {
14 private TransmissionAPI.FilePriority _value;
15 private string _name;
16 private string _icon;
17
18 public PriorityItem(TransmissionAPI.FilePriority value, string name, string icon) {
19 _value = value;
20 _name = name;
21 _icon = icon;
22 }
23
24 public override string Name {
25 get { return _name; }
26 }
27
28 public override string Description {
29 get { return ""; }
30 }
31
32 public override string Icon {
33 get { return _icon; }
34 }
35
36 public TransmissionAPI.FilePriority Value {
37 get { return _value; }
38 }
39 }
40
41 public class TorrentFileSetPriorityAction: Act {
42
43 public TorrentFileSetPriorityAction() {
44 }
45
46 public override string Name {
47 get { return AddinManager.CurrentLocalizer.GetString ("Set priority"); }
48 }
49
50 public override string Description {
51 get { return AddinManager.CurrentLocalizer.GetString ("Set download priority"); }
52 }
53
54 public override string Icon {
55 get { return "object-flip-vertical"; }
56 }
57
58 public override IEnumerable<Type> SupportedItemTypes {
59 get {
60 yield return typeof (ITorrentEntry);
61 }
62 }
63
64 public override IEnumerable<Type> SupportedModifierItemTypes {
65 get {
66 yield return typeof (PriorityItem);
67 }
68 }
69
70 public override bool ModifierItemsOptional {
71 get { return false; }
72 }
73
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");
78 }
79
80 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
81 TransmissionAPI.FilePriority priority = (modItems.First() as PriorityItem).Value;
82
83 TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(null, priority);
84
85 // Group torrent entries by torrent.
86 var files_by_torrent = items
87 .Cast<ITorrentEntry>()
88 .GroupBy(
89 item => item.Torrent,
90 (torrent, entries) => new {
91 Torrent = torrent,
92 Files = entries.SelectMany(entry => entry.GetFiles())
93 }
94 );
95
96 TransmissionAPI api = TransmissionPlugin.getTransmission();
97
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);
103 }
104
105 yield break;
106 }
107 }
108}
0109
=== added file 'Transmission/src/TorrentItem.cs'
--- Transmission/src/TorrentItem.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentItem.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,72 @@
1
2using System;
3using System.Collections.Generic;
4
5using Do.Universe;
6
7namespace Transmission {
8
9 public class TorrentItem: Item {
10
11 private string _name;
12 private string _comment;
13 private string _hash_string;
14 private long _size;
15 private TransmissionAPI.TorrentStatus _status;
16 private int _download_speed_limit, _upload_speed_limit;
17 private TorrentDirectoryItem _root;
18
19 public TorrentItem(TransmissionAPI.TorrentInfo info) {
20 _hash_string = info.HashString;
21 _name = info.Name;
22 _comment = info.Comment;
23 _status = info.Status;
24 _size = info.TotalSize;
25 _download_speed_limit = info.DownloadLimit;
26 _upload_speed_limit = info.UploadLimit;
27 _root = new TorrentDirectoryItem(this, null, info.DownloadDir);
28 }
29
30 public override string Name {
31 get { return _name; }
32 }
33
34 public override string Description {
35 get {
36 string status_text = "";
37 switch (_status) {
38 case TransmissionAPI.TorrentStatus.CheckWait: status_text = "Waiting for check"; break;
39 case TransmissionAPI.TorrentStatus.Check: status_text = "Checking"; break;
40 case TransmissionAPI.TorrentStatus.Download: status_text = "Downloading"; break;
41 case TransmissionAPI.TorrentStatus.Seed: status_text = "Seeding"; break;
42 case TransmissionAPI.TorrentStatus.Stopped: status_text = "Stopped"; break;
43 }
44
45 return string.Format("{0}, {1}", Utils.FormatSize(_size), status_text);
46 }
47 }
48
49 public override string Icon {
50 get { return "transmission"; }
51 }
52
53 public string HashString {
54 get { return _hash_string; }
55 }
56
57 public TorrentDirectoryItem Root {
58 get { return _root; }
59 }
60
61 public int DownloadSpeedLimit {
62 get { return _download_speed_limit; }
63 set { _download_speed_limit = value; }
64 }
65
66 public int UploadSpeedLimit {
67 get { return _upload_speed_limit; }
68 set { _upload_speed_limit = value; }
69 }
70 }
71
72}
073
=== added file 'Transmission/src/TorrentItemSource.cs'
--- Transmission/src/TorrentItemSource.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentItemSource.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,130 @@
1
2using System;
3using System.Collections.Generic;
4
5using Mono.Addins;
6
7using Do.Universe;
8using Do.Platform;
9using Do.Platform.Linux;
10
11namespace Transmission {
12
13 public class TorrentItemSource: ItemSource, IConfigurable {
14
15 private List<Item> _torrents = new List<Item>();
16
17 public TorrentItemSource() {
18 }
19
20 public override string Name {
21 get { return "Torrents"; }
22 }
23
24 public override string Description {
25 get { return "Transmission torrent client downloads"; }
26 }
27
28 public override string Icon {
29 get { return "transmission"; }
30 }
31
32 public override void UpdateItems () {
33 Log<TorrentItemSource>.Debug("Updating torrents list");
34
35 // Clear current torrents list.
36 _torrents.Clear();
37
38 TransmissionAPI api = TransmissionPlugin.getTransmission();
39
40 foreach (TransmissionAPI.TorrentInfo t in api.GetAllTorrents()) {
41 Log<TorrentItemSource>.Debug("Torrent: {0}", t.Name);
42
43 TorrentItem torrent = new TorrentItem(t);
44
45 // Transmission returns files as flat list with full names, this map
46 // is used to organize files into hierarchy.
47 // It maps directory path to directory item.
48 Dictionary<string, TorrentDirectoryItem> dirs = new Dictionary<string, TorrentDirectoryItem>();
49 dirs.Add("", torrent.Root);
50
51 int index = 0; // File index within list.
52 foreach (TransmissionAPI.TorrentFileInfo f in t.files) {
53 // Split path and name.
54 int sep_pos = f.Name.LastIndexOf('/');
55
56 string name = f.Name.Substring(sep_pos+1);
57 string path = f.Name.Substring(0, sep_pos == -1 ? 0 : sep_pos);
58 Log<TorrentItemSource>.Debug("File {0} in dir {1}", name, path);
59 TorrentDirectoryItem dir = FindOrCreateDirectory(path, dirs);
60
61 dir.Files.Add(new TorrentFileItem(torrent, index, dir, name, f));
62
63 ++index;
64 }
65
66 _torrents.Add(torrent);
67 }
68 }
69
70 private TorrentDirectoryItem FindOrCreateDirectory(
71 string path,
72 Dictionary<string, TorrentDirectoryItem> dirs
73 ) {
74 TorrentDirectoryItem dir;
75 dirs.TryGetValue(path, out dir);
76
77 if (dir != null) {
78 // Found already added directory.
79 return dir;
80
81 } else {
82 // Directory doesn't exist, find or add parent one, then add this one.
83 int sep_pos = path.LastIndexOf('/');
84
85 string parent_path = path.Substring(0, sep_pos == -1 ? 0 : sep_pos);
86 TorrentDirectoryItem parent = FindOrCreateDirectory(parent_path, dirs);
87
88 string name = path.Substring(sep_pos+1);
89 dir = new TorrentDirectoryItem(parent.Torrent, parent, name);
90
91 parent.Files.Add(dir);
92 dirs.Add(path, dir);
93
94 return dir;
95 }
96 }
97
98 public override IEnumerable<Item> Items {
99 get { return _torrents; }
100 }
101
102 public override IEnumerable<Item> ChildrenOfItem(Item item) {
103 if (item is TorrentItem) {
104 foreach (Item entry in ((TorrentItem)item).Root.Files)
105 yield return entry;
106
107 } else if (item is TorrentDirectoryItem) {
108 foreach (Item entry in ((TorrentDirectoryItem)item).Files)
109 yield return entry;
110
111 } else {
112 yield break;
113
114 }
115 }
116
117 public override IEnumerable<Type> SupportedItemTypes {
118 get {
119 yield return typeof(TorrentItem);
120 yield return typeof(TorrentDirectoryItem);
121 yield return typeof(TorrentFileItem);
122 }
123 }
124
125 public Gtk.Bin GetConfiguration() {
126 return new TransmissionConfig();
127 }
128
129 }
130}
0131
=== added file 'Transmission/src/TorrentLimitDownloadSpeedAction.cs'
--- Transmission/src/TorrentLimitDownloadSpeedAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentLimitDownloadSpeedAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,47 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5using System.Text.RegularExpressions;
6
7using Mono.Addins;
8
9using Do.Platform;
10using Do.Universe;
11
12namespace Transmission {
13
14 public class TorrentLimitDownloadSpeedAction: TorrentAbstractLimitSpeedAction {
15
16 public override string Name {
17 get { return AddinManager.CurrentLocalizer.GetString("Limit download speed"); }
18 }
19
20 public override string Description {
21 get { return AddinManager.CurrentLocalizer.GetString("Set download speed limit"); }
22 }
23
24 public override string Icon {
25 get { return "top"; }
26 }
27
28 protected override PredefinedSpeed GetCurrentSpeedItem(TorrentItem torrent) {
29 int currentSpeed = torrent.DownloadSpeedLimit;
30 return new PredefinedSpeed(
31 currentSpeed,
32 string.Format("Saved: {0}", Utils.FormatSpeed(currentSpeed)),
33 "Use limit from torrent settings"
34 );
35 }
36
37 protected override void SetSpeedLimit(TransmissionAPI api, IEnumerable<TorrentItem> torrents, int speed) {
38 bool limit_speed = (speed != 0);
39 int? limit = (speed == 0 ? (int?)null : speed);
40 api.SetTorrents(torrents.Select(t => t.HashString), null, limit_speed, limit, null, null);
41
42 foreach (TorrentItem torrent in torrents)
43 torrent.DownloadSpeedLimit = speed;
44 }
45
46 }
47}
048
=== added file 'Transmission/src/TorrentLimitUploadSpeedAction.cs'
--- Transmission/src/TorrentLimitUploadSpeedAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentLimitUploadSpeedAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,47 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5using System.Text.RegularExpressions;
6
7using Mono.Addins;
8
9using Do.Platform;
10using Do.Universe;
11
12namespace Transmission {
13
14 public class TorrentLimitUploadSpeedAction: TorrentAbstractLimitSpeedAction {
15
16 public override string Name {
17 get { return AddinManager.CurrentLocalizer.GetString ("Limit upload speed"); }
18 }
19
20 public override string Description {
21 get { return AddinManager.CurrentLocalizer.GetString ("Set upload speed limit"); }
22 }
23
24 public override string Icon {
25 get { return "top"; }
26 }
27
28 protected override PredefinedSpeed GetCurrentSpeedItem(TorrentItem torrent) {
29 int currentSpeed = torrent.UploadSpeedLimit;
30 return new PredefinedSpeed(
31 currentSpeed,
32 string.Format("Saved: {0}", Utils.FormatSpeed(currentSpeed)),
33 "Use limit from torrent settings"
34 );
35 }
36
37 protected override void SetSpeedLimit(TransmissionAPI api, IEnumerable<TorrentItem> torrents, int speed) {
38 bool limit_speed = (speed != 0);
39 int? limit = (speed == 0 ? (int?)null : speed);
40 api.SetTorrents(torrents.Select(t => t.HashString), null, null, null, limit_speed, limit);
41
42 foreach (TorrentItem torrent in torrents)
43 torrent.UploadSpeedLimit = speed;
44 }
45
46 }
47}
048
=== added file 'Transmission/src/TorrentMarkForDownloadAction.cs'
--- Transmission/src/TorrentMarkForDownloadAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentMarkForDownloadAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,62 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Platform;
9using Do.Universe;
10
11namespace Transmission {
12
13 public class TorrentMarkForDownloadAction: Act {
14
15 public TorrentMarkForDownloadAction() {
16 }
17
18 public override string Name {
19 get { return AddinManager.CurrentLocalizer.GetString ("Mark for download"); }
20 }
21
22 public override string Description {
23 get { return AddinManager.CurrentLocalizer.GetString ("Mark file as needed to be downloaded"); }
24 }
25
26 public override string Icon {
27 get { return "add"; }
28 }
29
30 public override IEnumerable<Type> SupportedItemTypes {
31 get {
32 yield return typeof (ITorrentEntry);
33 }
34 }
35
36 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
37 TransmissionAPI api = TransmissionPlugin.getTransmission();
38
39 // Operation is common for all files.
40 TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(true, null);
41
42 // Group selected items by owner torrent.
43 var files_by_torrent = items
44 .Cast<ITorrentEntry>()
45 .GroupBy(
46 item => item.Torrent,
47 (torrent, entries) => new {
48 Torrent = torrent,
49 Files = entries.SelectMany(entry => entry.GetFiles())
50 }
51 );
52
53 // Perform action for each torrent separately.
54 foreach (var group in files_by_torrent) {
55 var operations = group.Files.ToDictionary(f => f.Index, f => operation);
56 api.SetTorrent(group.Torrent.HashString, null, null, null, null, null, operations);
57 }
58
59 yield break;
60 }
61 }
62}
063
=== added file 'Transmission/src/TorrentOperateAction.cs'
--- Transmission/src/TorrentOperateAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentOperateAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,37 @@
1using System;
2using System.Linq;
3using System.Collections.Generic;
4
5using Mono.Addins;
6
7using Do.Universe;
8using Do.Platform;
9
10namespace Transmission {
11
12 public class TorrentOperateAction: Act {
13
14 public override string Name {
15 get { return AddinManager.CurrentLocalizer.GetString ("Operate on files"); }
16 }
17
18 public override string Description {
19 get { return AddinManager.CurrentLocalizer.GetString ("Operate on downloaded file"); }
20 }
21
22 public override string Icon {
23 get { return "file"; }
24 }
25
26 public override IEnumerable<Type> SupportedItemTypes {
27 get { yield return typeof (ITorrentEntry); }
28 }
29
30 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
31 foreach (Item item in items) {
32 ITorrentEntry entry = (ITorrentEntry)item;
33 yield return Services.UniverseFactory.NewFileItem(entry.Path) as Item;
34 }
35 }
36 }
37}
038
=== added file 'Transmission/src/TorrentStartAction.cs'
--- Transmission/src/TorrentStartAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentStartAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,42 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Universe;
9
10namespace Transmission {
11
12 public class TorrentStartAction: Act {
13
14 public TorrentStartAction() {
15 }
16
17 public override string Name {
18 get { return AddinManager.CurrentLocalizer.GetString ("Start"); }
19 }
20
21 public override string Description {
22 get { return AddinManager.CurrentLocalizer.GetString ("Start downloading torrent"); }
23 }
24
25 public override string Icon {
26 get { return "gtk-media-play"; }
27 }
28
29 public override IEnumerable<Type> SupportedItemTypes {
30 get { yield return typeof (TorrentItem); }
31 }
32
33 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
34 TransmissionAPI api = TransmissionPlugin.getTransmission();
35
36 var hashes = items.Cast<TorrentItem>().Select(t => t.HashString);
37 api.StartTorrents(hashes);
38
39 return null;
40 }
41 }
42}
043
=== added file 'Transmission/src/TorrentStopAction.cs'
--- Transmission/src/TorrentStopAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentStopAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,42 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Universe;
9
10namespace Transmission {
11
12 public class TorrentStopAction: Act {
13
14 public TorrentStopAction() {
15 }
16
17 public override string Name {
18 get { return AddinManager.CurrentLocalizer.GetString ("Stop"); }
19 }
20
21 public override string Description {
22 get { return AddinManager.CurrentLocalizer.GetString ("Stop downloading torrent"); }
23 }
24
25 public override string Icon {
26 get { return "gtk-media-pause"; }
27 }
28
29 public override IEnumerable<Type> SupportedItemTypes {
30 get { yield return typeof (TorrentItem); }
31 }
32
33 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
34 TransmissionAPI api = TransmissionPlugin.getTransmission();
35
36 var hashes = items.Cast<TorrentItem>().Select(t => t.HashString);
37 api.StopTorrents(hashes);
38
39 return null;
40 }
41 }
42}
043
=== added file 'Transmission/src/TorrentUnmarkForDownloadAction.cs'
--- Transmission/src/TorrentUnmarkForDownloadAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentUnmarkForDownloadAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,62 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Platform;
9using Do.Universe;
10
11namespace Transmission {
12
13 public class TorrentUnmarkForDownloadAction: Act {
14
15 public TorrentUnmarkForDownloadAction() {
16 }
17
18 public override string Name {
19 get { return AddinManager.CurrentLocalizer.GetString ("Unmark for download"); }
20 }
21
22 public override string Description {
23 get { return AddinManager.CurrentLocalizer.GetString ("Unmark file as needed to be downloaded"); }
24 }
25
26 public override string Icon {
27 get { return "remove"; }
28 }
29
30 public override IEnumerable<Type> SupportedItemTypes {
31 get {
32 yield return typeof (ITorrentEntry);
33 }
34 }
35
36 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
37 TransmissionAPI api = TransmissionPlugin.getTransmission();
38
39 // Operation is common for all files.
40 TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(false, null);
41
42 // Group selected items by owner torrent.
43 var files_by_torrent = items
44 .Cast<ITorrentEntry>()
45 .GroupBy(
46 item => item.Torrent,
47 (torrent, entries) => new {
48 Torrent = torrent,
49 Files = entries.SelectMany(entry => entry.GetFiles())
50 }
51 );
52
53 // Perform action for each torrent separately.
54 foreach (var group in files_by_torrent) {
55 var operations = group.Files.ToDictionary(f => f.Index, f => operation);
56 api.SetTorrent(group.Torrent.HashString, null, null, null, null, null, operations);
57 }
58
59 yield break;
60 }
61 }
62}
063
=== added file 'Transmission/src/TorrentVerifyAction.cs'
--- Transmission/src/TorrentVerifyAction.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TorrentVerifyAction.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,42 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5
6using Mono.Addins;
7
8using Do.Universe;
9
10namespace Transmission {
11
12 public class TorrentVerifyAction: Act {
13
14 public TorrentVerifyAction() {
15 }
16
17 public override string Name {
18 get { return AddinManager.CurrentLocalizer.GetString ("Verify"); }
19 }
20
21 public override string Description {
22 get { return AddinManager.CurrentLocalizer.GetString ("Verify torrent"); }
23 }
24
25 public override string Icon {
26 get { return "dialog-question"; }
27 }
28
29 public override IEnumerable<Type> SupportedItemTypes {
30 get { yield return typeof (TorrentItem); }
31 }
32
33 public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems) {
34 TransmissionAPI api = TransmissionPlugin.getTransmission();
35
36 var hashes = items.Cast<TorrentItem>().Select(t => t.HashString);
37 api.VerifyTorrents(hashes);
38
39 return null;
40 }
41 }
42}
043
=== added file 'Transmission/src/TransmissionAPI.cs'
--- Transmission/src/TransmissionAPI.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TransmissionAPI.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,575 @@
1
2using System;
3using System.IO;
4using System.Collections;
5using System.Collections.Generic;
6using System.Net;
7using System.Text;
8using Jayrock.Json;
9
10namespace Transmission {
11
12 /// <summary>
13 /// Transmission API client.
14 /// Compatible with RPC version 5 to 10 (release version 1.60 to 2.10).
15 /// </summary>
16 public class TransmissionAPI {
17
18 /// <summary>
19 /// File loading priority.
20 /// </summary>
21 public enum FilePriority {
22 Low, Normal, High
23 };
24
25 /// <summary>
26 /// Operation on individual file from torrent.
27 /// </summary>
28 /// <remarks>
29 /// All fields are nullable, <c>null</c> means "don't change current value".
30 /// </remarks>
31 public struct FileOperation {
32 public FileOperation(bool? download, FilePriority? priority) {
33 this.download = download;
34 this.priority = priority;
35 }
36
37 /// <summary>Whether it is needed to download this file</summary>
38 public bool? download;
39
40 /// <summary>Priority relative to other files of the same torrent</summary>
41 public FilePriority? priority;
42 };
43
44 /// <summary>
45 /// Error communicating to Transmission.
46 /// </summary>
47 public class TransmissionAPIError: Exception {
48 public TransmissionAPIError(string message): base(message) {}
49 public TransmissionAPIError(string message, Exception reason): base(message, reason) {}
50 };
51
52 /// <summary>
53 /// Error returned by Transmission.
54 /// </summary>
55 public class TransmissionError: Exception {
56 public TransmissionError(string message): base(message) {
57 }
58 };
59
60 public const int DEFAULT_PORT = 9091;
61 public const string DEFAULT_PATH = "/transmission/rpc";
62 public const string SESSION_HEADER = "X-Transmission-Session-Id";
63
64 private string _url, _username, _password;
65 private string _session_id = "";
66
67 private delegate void ResultReader(JsonReader json);
68
69 /// <summary>Response handler which does nothing</summary>
70 /// <remarks>Prefer using <see cref="Call(string, IDictionary<string, object>)"/> instead</remarks>
71 private void NullHandler(JsonReader json) {}
72
73 /// <summary>
74 /// Create API client.
75 /// </summary>
76 /// <param name="url">Transmission API-RPC URL</param>
77 /// <param name="username">Username for authentication</param>
78 /// <param name="password">Password for authentication</param>
79 /// <remarks>Pass <c>null</c> for both <paramref="username"/> and <paramref="username"/> is
80 /// authentication isn't needed.</remarks>
81 public TransmissionAPI(string url, string username, string password) {
82 _url = url;
83 _username = username;
84 _password = password;
85 }
86
87 /// <summary>Compose request JSON string</summary>
88 protected string ComposeRequest(string method, IDictionary<string, object> arguments) {
89 StringWriter sw = new StringWriter();
90
91 using (JsonWriter json = new JsonTextWriter(sw)) {
92 json.WriteStartObject();
93
94 json.WriteMember("method");
95 json.WriteString(method);
96
97 json.WriteMember("arguments");
98 json.WriteStartObject();
99 foreach (KeyValuePair<string, object> pair in arguments) {
100 string name = pair.Key;
101 object value = pair.Value;
102
103 json.WriteMember(name);
104 Jayrock.Json.Conversion.JsonConvert.Export(value, json);
105 }
106 json.WriteEndObject();
107
108 json.WriteEndObject();
109 }
110
111 return sw.ToString();
112 }
113
114 /// <summary></summary>
115 /// <param name="payload">HTTP POST request content</param>
116 /// <returns>HTTP response content</returns>
117 /// <exception cref="System.Net.WebException"/>
118 protected string PerformRequest(byte[] payload) {
119 // Prepare request.
120 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
121 request.Method = "POST";
122 request.ContentType = "application/x-www-form-urlencoded";
123 request.Headers[SESSION_HEADER] = _session_id;
124 request.ContentLength = payload.Length;
125
126 // Authenticate if credentials are given.
127 if (_username != null && _password != null) {
128 string auth = Convert.ToBase64String(Encoding.Default.GetBytes(_username + ":" + _password));
129 request.Headers["Authorization"] = "Basic " + auth;
130 }
131
132 // Perform request.
133 using (Stream stream = request.GetRequestStream()) {
134 stream.Write(payload, 0, payload.Length);
135 }
136
137 // Get response.
138 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
139 return new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8).ReadToEnd();
140 }
141
142 /// <summary>
143 /// Call Transmission API method.
144 /// </summary>
145 /// <param name="method">API method name</param>
146 /// <param name="arguments">Arguments passed to API method</param>
147 /// <param name="handler">Function called with value returned by method</param>
148 /// <exception cref="TransmissionError" />
149 /// <exception cref="TransmissionAPIError" />
150 private void Call(string method, IDictionary<string, object> arguments, ResultReader handler) {
151 // Compose request and encode it to UTF-8.
152 string req = ComposeRequest(method, arguments);
153 byte[] reqb = System.Text.Encoding.UTF8.GetBytes(req);
154
155 try {
156
157 string resp = null;
158 try {
159 resp = PerformRequest(reqb);
160
161 } catch (System.Net.WebException err) {
162 HttpWebResponse response = (HttpWebResponse)err.Response;
163
164 // Transmission 1.53 and 1.6 introduced X-Transmission-Session-Id header
165 // in order to protect from CSRF attacks. If you make request without
166 // this header (or your session expire) you'll get 409 response with
167 // this header set. Just copy header to your request and try again.
168 if (
169 err.Status == WebExceptionStatus.ProtocolError &&
170 response.StatusCode == HttpStatusCode.Conflict
171 ) {
172 _session_id = response.Headers[SESSION_HEADER];
173 resp = PerformRequest(reqb);
174
175 } else {
176 throw;
177 }
178 }
179
180 JsonReader json_reader = new JsonTextReader(new StringReader(resp));
181
182 json_reader.ReadToken(JsonTokenClass.Object);
183 while (json_reader.TokenClass == JsonTokenClass.Member) {
184 switch (json_reader.ReadMember()) {
185 case "result":
186 string result = json_reader.ReadString();
187 if (result != "success")
188 throw new TransmissionError(result);
189 break;
190 case "tag":
191 json_reader.ReadNumber();
192 break;
193 case "arguments":
194 json_reader.ReadToken(JsonTokenClass.Object);
195 handler(json_reader);
196 json_reader.ReadToken(JsonTokenClass.EndObject);
197 break;
198 default:
199 json_reader.Skip();
200 break;
201 }
202 }
203 json_reader.ReadToken(JsonTokenClass.EndObject);
204 json_reader.ReadToken(JsonTokenClass.EOF);
205
206 } catch (System.Net.WebException err) {
207 throw new TransmissionAPIError("Cannot access Transmission RPC service", err);
208 }
209 }
210
211 /// <summary>Call API method and ignore return value</summary>
212 /// <remarks>This is equivalent to <c>Call(method, arguments, NullHandler)</c>.</remarks>
213 private void Call(string method, IDictionary<string, object> arguments) {
214 Call(method, arguments, NullHandler);
215 }
216
217 /// <summary>
218 /// Start torrents.
219 /// </summary>
220 /// <param name="torrent_hashes">Sequence of torrent's hashes</param>
221 /// <exception cref="TransmissionAPIError" />
222 /// <exception cref="TransmissionError" />
223 public void StartTorrents(IEnumerable<string> torrent_hashes) {
224 Dictionary<string, object> arguments = new Dictionary<string, object>();
225 arguments.Add("ids", torrent_hashes);
226 Call("torrent-start", arguments);
227 }
228
229 /// <summary>
230 /// Start all torrents.
231 /// </summary>
232 /// <exception cref="TransmissionAPIError" />
233 /// <exception cref="TransmissionError" />
234 public void StartAllTorrents() {
235 Call("torrent-start", new Dictionary<string, object>());
236 }
237
238 /// <summary>
239 /// Stop torrents.
240 /// </summary>
241 /// <param name="torrent_hashes">Sequence of torrent's hashes</param>
242 /// <exception cref="TransmissionAPIError" />
243 /// <exception cref="TransmissionError" />
244 public void StopTorrents(IEnumerable<string> torrent_hashes) {
245 Dictionary<string, object> arguments = new Dictionary<string, object>();
246 arguments.Add("ids", torrent_hashes);
247 Call("torrent-stop", arguments);
248 }
249
250 /// <summary>
251 /// Stop all torrents.
252 /// </summary>
253 /// <exception cref="TransmissionAPIError" />
254 /// <exception cref="TransmissionError" />
255 public void StopAllTorrents() {
256 Call("torrent-stop", new Dictionary<string, object>());
257 }
258
259 /// <summary>
260 /// Start torrents verification.
261 /// </summary>
262 /// <param name="torrent_hashes">Sequence of torrent's hashes to verify</param>
263 /// <exception cref="TransmissionAPIError" />
264 /// <exception cref="TransmissionError" />
265 public void VerifyTorrents(IEnumerable<string> torrent_hashes) {
266 Dictionary<string, object> arguments = new Dictionary<string, object>();
267 arguments.Add("ids", torrent_hashes);
268 Call("torrent-verify", arguments);
269 }
270
271 /// <summary>
272 /// Start torrents verification for all torrents.
273 /// </summary>
274 /// <exception cref="TransmissionAPIError" />
275 /// <exception cref="TransmissionError" />
276 public void VerifyAllTorrents() {
277 Call("torrent-verify", new Dictionary<string, object>());
278 }
279
280 /// <summary>
281 /// Set torrents' properties.
282 ///
283 /// Not all torrent properties can be changed using this method, because some of them
284 /// are meaningless for torrent group, e.g. file priorities. Use <c>SetTorrent</c> method
285 /// to set such properties.
286 /// </summary>
287 /// <param name="torrent_hashes">Sequence of torrents hashed to modify</param>
288 /// <param name="peer_limit">Maximum number of used peers, if it is <c>null</c> then value won't be changed.</param>
289 /// <param name="limit_download">
290 /// Downloading speed limit switch, if it is <c>true</c>, downloading speed will be limited,
291 /// if it is <c>false</c>, downloading speed isn't limited, if it is <c>null</c>, limit switch won't be changed.
292 /// A <see cref="System.Nullable"/>
293 /// </param>
294 /// <param name="download_speed_limit">
295 /// A <see cref="System.Nullable"/>
296 /// </param>
297 /// <param name="limit_upload">
298 /// A <see cref="System.Nullable"/>
299 /// </param>
300 /// <param name="upload_speed_limit">
301 /// A <see cref="System.Nullable"/>
302 /// </param>
303 public void SetTorrents(IEnumerable<string> torrent_hashes, int? peer_limit, bool? limit_download, int? download_speed_limit, bool? limit_upload, int? upload_speed_limit) {
304 Dictionary<string, object> arguments = new Dictionary<string, object>();
305
306 arguments.Add("ids", torrent_hashes);
307
308 if (peer_limit != null)
309 arguments.Add("peer-limit", peer_limit);
310
311 if (limit_download.HasValue) {
312 if (limit_download.Value) {
313 arguments.Add("downloadLimited", true);
314 if (download_speed_limit.HasValue)
315 arguments.Add("downloadLimit", download_speed_limit.Value);
316 } else {
317 arguments.Add("downloadLimited", false);
318 }
319 }
320
321 if (limit_upload.HasValue) {
322 if (limit_upload.Value) {
323 arguments.Add("uploadLimited", true);
324 if (upload_speed_limit.HasValue)
325 arguments.Add("uploadLimit", upload_speed_limit.Value);
326 } else {
327 arguments.Add("uploadLimited", false);
328 }
329 }
330
331 Call("torrent-set", arguments);
332 }
333
334 public void SetTorrent(string torrent_hash, int? peer_limit, bool? limit_download, int? download_speed_limit, bool? limit_upload, int? upload_speed_limit, IDictionary<int, FileOperation> files) {
335 Dictionary<string, object> arguments = new Dictionary<string, object>();
336
337 arguments.Add("ids", new string[] { torrent_hash });
338
339 if (peer_limit != null)
340 arguments.Add("peer-limit", peer_limit);
341
342 if (limit_download.HasValue) {
343 if (limit_download.Value) {
344 arguments.Add("downloadLimited", true);
345 if (download_speed_limit.HasValue)
346 arguments.Add("downloadLimit", download_speed_limit.Value);
347 } else {
348 arguments.Add("downloadLimited", false);
349 }
350 }
351
352 if (limit_upload.HasValue) {
353 if (limit_upload.Value) {
354 arguments.Add("uploadLimited", true);
355 if (upload_speed_limit.HasValue)
356 arguments.Add("uploadLimit", upload_speed_limit.Value);
357 } else {
358 arguments.Add("uploadLimited", false);
359 }
360 }
361
362 List<int> wanted_files = new List<int>();
363 List<int> unwanted_files = new List<int>();
364 List<int> low_priority_files = new List<int>();
365 List<int> normal_priority_files = new List<int>();
366 List<int> high_priority_files = new List<int>();
367 foreach (KeyValuePair<int, FileOperation> op in files) {
368 int index = op.Key;
369 FileOperation file = op.Value;
370
371 if (file.download.HasValue) {
372 if (file.download.Value) wanted_files.Add(index);
373 else unwanted_files.Add(index);
374 }
375
376 if (file.priority.HasValue) {
377 switch (file.priority.Value) {
378 case FilePriority.Low: low_priority_files.Add(index); break;
379 case FilePriority.Normal: normal_priority_files.Add(index); break;
380 case FilePriority.High: high_priority_files.Add(index); break;
381 }
382 }
383 }
384 if (wanted_files.Count > 0) arguments.Add("files-wanted", wanted_files);
385 if (unwanted_files.Count > 0) arguments.Add("files-unwanted", unwanted_files);
386 if (low_priority_files.Count > 0) arguments.Add("priority-low", low_priority_files);
387 if (normal_priority_files.Count > 0) arguments.Add("priority-normal", normal_priority_files);
388 if (high_priority_files.Count > 0) arguments.Add("priority-high", high_priority_files);
389
390 Call("torrent-set", arguments);
391 }
392
393 /// <summary>
394 /// Torrent status.
395 /// </summary>
396 public enum TorrentStatus {
397 CheckWait = 1, Check = 2, Download = 4, Seed = 8, Stopped = 16
398 };
399
400 public class TorrentInfo {
401 public int Id; // Torrent's unique ID within Transmission.
402 public string Comment;
403 public string HashString;
404 public string Name;
405 public string DownloadDir;
406 public IList<TorrentFileInfo> files;
407 public TorrentStatus Status;
408 public long TotalSize;
409
410 public int DownloadLimit;
411 public bool DownloadLimited;
412 public int UploadLimit;
413 public bool UploadLimited;
414 };
415
416 public class TorrentFileInfo {
417 public string Name;
418 public long Length;
419 public long BytesCompleted;
420 public bool Wanted;
421 public FilePriority Priority;
422 };
423
424 /// <summary>Get information about all torrents.</summary>
425 /// <remarks>This is equivalent to <c>GetTorrents(null)</c>.</remarks>
426 public IEnumerable<TorrentInfo> GetAllTorrents() {
427 return GetTorrents(null);
428 }
429
430 public IEnumerable<TorrentInfo> GetTorrents(IEnumerable<string> torrent_hashes) {
431 Dictionary<string, object> arguments = new Dictionary<string, object>();
432 if (torrent_hashes != null) arguments.Add("ids", torrent_hashes);
433 arguments.Add("fields", new string[] {"comment", "downloadDir", "files", "hashString", "id", "name", "priorities", "status", "totalSize", "wanted", "downloadLimited", "downloadLimit", "uploadLimited", "uploadLimit"});
434
435 List<TorrentInfo> torrents = new List<TorrentInfo>();
436
437 Jayrock.Json.Conversion.ImportContext jsonctx = new Jayrock.Json.Conversion.ImportContext();
438 jsonctx.Register(new ListImporter<int>());
439 jsonctx.Register(new ListImporter<TorrentFileInfo>());
440
441 Call("torrent-get", arguments, delegate(JsonReader json) {
442 while (json.TokenClass == JsonTokenClass.Member) {
443 switch (json.ReadMember()) {
444 case "torrents":
445 json.ReadToken(JsonTokenClass.Array);
446 while (json.TokenClass != JsonTokenClass.EndArray) {
447
448 json.ReadToken(JsonTokenClass.Object);
449
450 TorrentInfo torrent = new TorrentInfo();
451 IList<TorrentFileInfo> files = null;
452 IList<int> wanted = null;
453 IList<int> priorities = null;
454
455 while (json.TokenClass == JsonTokenClass.Member) {
456 switch (json.ReadMember()) {
457 case "comment": torrent.Comment = json.ReadString(); break;
458 case "hashString": torrent.HashString = json.ReadString(); break;
459 case "name": torrent.Name = json.ReadString(); break;
460 case "id": torrent.Id = json.ReadNumber().ToInt32(); break;
461 case "downloadDir": torrent.DownloadDir = json.ReadString(); break;
462 case "status": torrent.Status = (TorrentStatus)json.ReadNumber().ToInt32(); break;
463 case "totalSize": torrent.TotalSize = json.ReadNumber().ToInt64(); break;
464 case "wanted": wanted = (IList<int>)jsonctx.Import(typeof(List<int>), json); break;
465 case "priorities": priorities = (IList<int>)jsonctx.Import(typeof(List<int>), json); break;
466 case "files": files = jsonctx.Import(typeof(List<TorrentFileInfo>), json) as IList<TorrentFileInfo>; break;
467 case "downloadLimited": torrent.DownloadLimited = json.ReadBoolean(); break;
468 case "downloadLimit": torrent.DownloadLimit = json.ReadNumber().ToInt32(); break;
469 case "uploadLimited": torrent.UploadLimited = json.ReadBoolean(); break;
470 case "uploadLimit": torrent.UploadLimit = json.ReadNumber().ToInt32(); break;
471 }
472 }
473
474 for (int i = 0; i < files.Count; ++i) {
475 files[i].Wanted = wanted[i] == 1;
476
477 int prio = priorities[i];
478 if (prio < -1 || prio > 1)
479 throw new TransmissionAPIError(string.Format("Invalid priority value: {0}", prio));
480 files[i].Priority = (FilePriority)(prio+1);
481 }
482 torrent.files = files;
483 torrents.Add(torrent);
484
485 json.ReadToken(JsonTokenClass.EndObject);
486 }
487 json.ReadToken(JsonTokenClass.EndArray);
488 break;
489 default:
490 json.Skip();
491 break;
492 }
493 }
494 });
495
496 return torrents;
497 }
498
499 // Transmission RPC allows to use .torrent file content instead of it's filename, but
500 // this isn't supported.
501 public void AddTorrent(string filename, string download_to, bool paused, int? peer_limit) {
502 Dictionary<string, object> arguments = new Dictionary<string, object>();
503 arguments.Add("filename", filename);
504 arguments.Add("download-dir", download_to);
505 arguments.Add("paused", paused);
506 if (peer_limit.HasValue) arguments.Add("peer-limit", peer_limit.Value);
507 Call("torrent-add", arguments);
508 }
509
510 /// <summary>
511 /// Remove torrents.
512 /// </summary>
513 /// <param name="hashes">Sequence of torrent hashes to remove.</param>
514 /// <param name="delete_files">Whether downloaded files should be deleted or not.</param>
515 public void RemoveTorrent(IEnumerable<string> hashes, bool delete_files) {
516 Dictionary<string, object> arguments = new Dictionary<string, object>();
517 arguments.Add("ids", hashes);
518 arguments.Add("delete-load-data", delete_files);
519 Call("torrent-remove", arguments);
520 }
521
522 /// <summary>
523 /// Set session parameters.
524 /// </summary>
525 /// <param name="download_dir">
526 /// Path to directory to download torrent contents to.
527 /// Pass <c>null</c> to keep old value.
528 /// </param>
529 /// <param name="peer_limit">
530 /// Global limit on number of connected peers. Pass <c>null</c> to keep old value.
531 /// </param>
532 /// <param name="limit_download">
533 /// Global limit on number of connected peers. Pass <c>null</c> to keep old value.
534 /// </param>
535 public void SetSession(
536 string download_dir, int? peer_limit,
537 bool? limit_download, int? download_speed_limit, bool? limit_upload, int? upload_speed_limit
538 ) {
539 Dictionary<string, object> arguments = new Dictionary<string, object>();
540
541 if (download_dir != null)
542 arguments.Add("download-dir", download_dir);
543
544 if (peer_limit.HasValue)
545 arguments.Add("peer-limit", peer_limit.Value);
546
547 if (limit_download.HasValue) {
548 if (limit_download.Value) {
549 arguments.Add("downloadLimited", true);
550 if (download_speed_limit.HasValue)
551 arguments.Add("downloadLimit", download_speed_limit.Value);
552 } else {
553 arguments.Add("downloadLimited", false);
554 }
555 }
556
557 if (limit_upload.HasValue) {
558 if (limit_upload.Value) {
559 arguments.Add("uploadLimited", true);
560 if (upload_speed_limit.HasValue)
561 arguments.Add("uploadLimit", upload_speed_limit.Value);
562 } else {
563 arguments.Add("uploadLimited", false);
564 }
565 }
566
567 Call("session-set", arguments);
568 }
569
570 public void GetSession() {
571 Call("session-get", new Dictionary<string, object>());
572 }
573
574 }
575}
0576
=== added file 'Transmission/src/TransmissionPlugin.cs'
--- Transmission/src/TransmissionPlugin.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/TransmissionPlugin.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,50 @@
1using System;
2using System.Collections.Generic;
3
4using Do.Platform;
5
6namespace Transmission {
7
8 public class ConnectionParameters {
9 public ConnectionParameters(string url, string username, string password) {
10 this.url = url;
11 this.username = username;
12 this.password = password;
13 }
14
15 public string url;
16 public string username;
17 public string password;
18 };
19
20 public class TransmissionPlugin {
21 private static TransmissionAPI transmission;
22
23 public static TransmissionAPI getTransmission() {
24 if (transmission == null) {
25 ConnectionParameters p = getTransmissionConnectionParameters();
26 Log<TransmissionPlugin>.Info("Using Transmission on {0}", p.url);
27 Log<TransmissionPlugin>.Debug("Using name, password: {0}:{1}", p.username, p.password);
28 transmission = new TransmissionAPI(p.url, p.username, p.password);
29 }
30 return transmission;
31 }
32
33 public static void ResetConnection() {
34 transmission = null;
35 }
36
37 public static ConnectionParameters getTransmissionConnectionParameters() {
38 string host = TransmissionConfig.Address;
39 int port = TransmissionConfig.Port;
40 string username = TransmissionConfig.UserName;
41 string password = TransmissionConfig.Password;
42
43 string url = string.Format("http://{0}:{1}/transmission/rpc", host, port);
44 return new ConnectionParameters(url, username, password);
45 }
46
47 };
48
49}
50
051
=== added file 'Transmission/src/Utils.cs'
--- Transmission/src/Utils.cs 1970-01-01 00:00:00 +0000
+++ Transmission/src/Utils.cs 2010-07-26 16:47:47 +0000
@@ -0,0 +1,111 @@
1
2using System;
3using System.Linq;
4using System.Collections.Generic;
5using System.Text.RegularExpressions;
6
7using Do.Platform;
8using Do.Universe;
9
10namespace Transmission {
11
12 class Utils {
13
14 public static int ParseSpeed(string speed) {
15 Regex regex = new Regex(
16 @"^(\d+)\s*(b|[km]i?b?)$",
17 RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace
18 );
19 Match match = regex.Match(speed);
20
21 if (match.Success) {
22 int number = int.Parse(match.Groups[1].Value);
23 string unit = match.Groups[2].Value.ToLower();
24 int scale = 1;
25
26 if (unit == "" || unit[0] == 'k') scale = 1;
27 else if (unit[0] == 'm') scale = 1024;
28
29 return number * scale;
30
31 } else {
32 throw new ArgumentException("Invalid speed string");
33 }
34 }
35
36 public static string FormatAmount(float amount, string baseFormat, float[] scales, string[] formats) {
37 if (scales.Length != formats.Length)
38 throw new ArgumentException("'scales' and 'formats' arguments must have equal length");
39
40 // The typical scales count is three to five, so don't use binary search,
41 // but just plain reverse loop.
42 for (int i = scales.Length-1; i >= 0; --i) {
43 if (amount >= scales[i])
44 return string.Format(formats[i], amount / scales[i]);
45 }
46
47 return string.Format(baseFormat, amount);
48 }
49
50 // Format speed in KiB/sec into human-readable representation.
51 public static string FormatSpeed(int speed_kbytes_sec) {
52 return FormatAmount(speed_kbytes_sec, "{0} KiB/sec",
53 new float[] { 1024, 1024*1024},
54 new string[] {"{0:#.#} MiB/sec", "{0:#.#} GiB/sec"}
55 );
56 }
57
58 // Format size in bytes into human-readable representation.
59 public static string FormatSize(long size_bytes) {
60 return FormatAmount(size_bytes, "{0} B",
61 new float[] { 1024, 1024*1024, 1024*1024*1024},
62 new string[] {"{0:#.#} KiB", "{0:#.#} MiB", "{0:#.##} GiB"}
63 );
64 }
65
66 public readonly static IEnumerable<PredefinedSpeed> PredefinedSpeedItems = new List<PredefinedSpeed>() {
67 new PredefinedSpeed( 10, "10 KiB/sec", ""),
68 new PredefinedSpeed( 20, "20 KiB/sec", ""),
69 new PredefinedSpeed( 50, "50 KiB/sec", ""),
70 new PredefinedSpeed( 100, "100 KiB/sec", ""),
71 new PredefinedSpeed( 200, "200 KiB/sec", ""),
72 new PredefinedSpeed( 500, "500 KiB/sec", ""),
73 new PredefinedSpeed( 1 * 1024, "1 MiB/sec", ""),
74 new PredefinedSpeed( 2 * 1024, "2 MiB/sec", ""),
75 new PredefinedSpeed( 5 * 1024, "5 MiB/sec", ""),
76 new PredefinedSpeed( 10 * 1024, "10 MiB/sec", ""),
77 new PredefinedSpeed( 20 * 1024, "20 MiB/sec", ""),
78 new PredefinedSpeed( 50 * 1024, "50 MiB/sec", ""),
79 new PredefinedSpeed(100 * 1024, "100 MiB/sec", ""),
80 };
81
82 }
83
84 public class PredefinedSpeed: Item {
85 private string _name, _desc;
86 private int _value;
87
88 public PredefinedSpeed(int value, string name, string desc) {
89 _value = value;
90 _name = name;
91 _desc = desc;
92 }
93
94 public override string Name {
95 get { return _name; }
96 }
97
98 public override string Description {
99 get { return _desc; }
100 }
101
102 public override string Icon {
103 get { return "top"; }
104 }
105
106 public int Value {
107 get { return _value; }
108 }
109 }
110
111}
0112
=== modified file 'configure.ac'
--- configure.ac 2010-03-08 02:43:56 +0000
+++ configure.ac 2010-07-26 16:47:47 +0000
@@ -383,6 +383,8 @@
383Tracker/Resources/TrackerSearch.addin.xml383Tracker/Resources/TrackerSearch.addin.xml
384Translate/Makefile384Translate/Makefile
385Translate/Resources/Translate.addin.xml385Translate/Resources/Translate.addin.xml
386Transmission/Makefile
387Transmission/Resources/Transmission.addin.xml
386Tomboy/Makefile388Tomboy/Makefile
387Tomboy/Resources/Tomboy.addin.xml389Tomboy/Resources/Tomboy.addin.xml
388Vinagre/Makefile390Vinagre/Makefile

Subscribers

People subscribed via source and target branches