~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to Transmission/src/Config/TransmissionConfig.cs

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

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
using System.Text;
 
4
 
 
5
using Mono.Addins;
 
6
 
 
7
using Gtk;
 
8
 
 
9
using Do.Platform;
 
10
 
 
11
namespace 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
}