proxy support

This commit is contained in:
Marcos Pinto 2007-06-16 10:56:09 +00:00
parent 8873ac3cce
commit 71ed6b6f67
7 changed files with 276 additions and 80 deletions

View File

@ -315,40 +315,86 @@
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkAlignment" id="alignment18">
<widget class="GtkSpinButton" id="spin_max_upload">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="right_padding">10</property>
<child>
<widget class="GtkLabel" id="label55">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Rate (KB/s):</property>
</widget>
</child>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload rate for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment14">
<widget class="GtkSpinButton" id="spin_max_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip" translatable="yes">The maximum download rate for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_num_upload">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum number of upload slots. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 1000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_num_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 1000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="right_padding">10</property>
<child>
<widget class="GtkLabel" id="label52">
<widget class="GtkLabel" id="label54">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Download Rate (KB/s):</property>
<property name="label" translatable="yes">Maximum Connections:</property>
</widget>
</child>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@ -372,84 +418,38 @@
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment4">
<widget class="GtkAlignment" id="alignment14">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="right_padding">10</property>
<child>
<widget class="GtkLabel" id="label54">
<widget class="GtkLabel" id="label52">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Connections:</property>
<property name="label" translatable="yes">Maximum Download Rate (KB/s):</property>
</widget>
</child>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_num_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 1000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_num_upload">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum number of upload slots. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 1000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip" translatable="yes">The maximum download rate for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_upload">
<widget class="GtkAlignment" id="alignment18">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload rate for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="right_padding">10</property>
<child>
<widget class="GtkLabel" id="label55">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Rate (KB/s):</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
@ -955,7 +955,159 @@ Full Stream</property>
</packing>
</child>
<child>
<placeholder/>
<widget class="GtkFrame" id="frame14">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<child>
<widget class="GtkAlignment" id="alignment14">
<property name="visible">True</property>
<property name="top_padding">2</property>
<property name="bottom_padding">2</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkVBox" id="vbox10">
<property name="visible">True</property>
<child>
<widget class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Type: </property>
</widget>
</child>
<child>
<widget class="GtkComboBox" id="combo_proxy_type">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="items" translatable="yes">None
Socksv4
Socksv5
Socksv5 W/Auth
HTTP
HTTP W/ Auth</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Server: </property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="txt_proxy_hostname">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="width_chars">17</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Port: </property>
</widget>
<packing>
<property name="position">4</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_proxy_port">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="width_chars">4</property>
<property name="adjustment">8080 0 10000 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="position">5</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox10">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Username: </property>
</widget>
</child>
<child>
<widget class="GtkEntry" id="txt_proxy_username">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Password: </property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="txt_proxy_password">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="visibility">False</property>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label46">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Proxy&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="padding">2</property>
<property name="position">5</property>
</packing>
</child>
</widget>
</child>

View File

@ -125,3 +125,6 @@ class EncState:
class EncLevel:
plaintext, rc4, both = range(3)
class ProxyType:
none, socks4, socks5, socks5_pw, http, http_pw = range(6)

View File

@ -746,6 +746,7 @@ class Manager:
def get_queue_index(self, unique_ID):
return self.state.queue.index(unique_ID)
def apply_prefs(self):
print "Applying preferences"
@ -781,9 +782,6 @@ class Manager:
pieces=256, author="Deluge"):
return deluge_core.create_torrent(filename, source_directory, trackers, comments, pieces, author)
def pe_settings(self, out_enc_policy, in_enc_policy, allowed_enc_level, prefer_rc4):
return deluge_core.pe_settings(out_enc_policy, in_enc_policy, allowed_enc_level, prefer_rc4)
# Creates/resets the IP filter list
def reset_ip_filter(self):
return deluge_core.reset_IP_filter()
@ -791,3 +789,10 @@ class Manager:
# Adds an IP range (as two dotted quad strings) to the filter
def add_range_to_ip_filter(self, start, end):
return deluge_core.add_range_to_IP_filter(start, end)
def proxy_settings(self, server, login, paswd, portnum, proxytype):
return deluge_core.proxy_settings(server, login, paswd, portnum, proxytype)
def pe_settings(self, out_enc_policy, in_enc_policy, allowed_enc_level, prefer_rc4):
return deluge_core.pe_settings(out_enc_policy, in_enc_policy, allowed_enc_level, prefer_rc4)

View File

@ -115,6 +115,7 @@ typedef torrents_t::iterator torrents_t_iterator;
long M_unique_counter = 0;
session_settings *M_settings = NULL;
pe_settings *M_pe_settings = NULL;
proxy_settings *M_proxy_settings = NULL;
session *M_ses = NULL;
PyObject *M_constants = NULL;
ip_filter *M_the_filter = NULL;
@ -1305,6 +1306,25 @@ static PyObject *torrent_set_ratio(PyObject *self, PyObject *args)
Py_INCREF(Py_None); return Py_None;
}
static PyObject *torrent_proxy_settings(PyObject *self, PyObject *args)
{
M_proxy_settings = new proxy_settings();
char *server, *login, *pasw;
int portnum;
libtorrent::proxy_settings::proxy_type proxytype;
PyArg_ParseTuple(args, "sssii", &server, &login, &pasw, &portnum, &proxytype);
M_proxy_settings->type = proxytype;
M_proxy_settings->username = login;
M_proxy_settings->password = pasw;
M_proxy_settings->hostname = server;
M_proxy_settings->port = portnum;
Py_INCREF(Py_None); return Py_None;
}
//====================
// Python Module data
@ -1348,6 +1368,7 @@ static PyMethodDef deluge_core_methods[] =
{"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."},
{"use_utpex", torrent_use_utpex, METH_VARARGS, "."},
{"set_ratio", torrent_set_ratio, METH_VARARGS, "."},
{"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."},
{NULL}
};

View File

@ -52,6 +52,7 @@ class PreferencesDlg:
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state", int, default=common.EncState.enabled))
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state", int, default=common.EncState.enabled))
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type", int, default=common.EncLevel.both))
self.glade.get_widget("combo_proxy_type").set_active(self.preferences.get("proxy_type", int, default=common.ProxyType.none))
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4", bool, default=True))
self.glade.get_widget("chk_upnp").set_active(self.preferences.get("use_upnp", bool, default=True))
self.glade.get_widget("chk_natpmp").set_active(self.preferences.get("use_natpmp", bool, default=True))
@ -60,6 +61,9 @@ class PreferencesDlg:
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray", bool, default=False))
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray", bool, default=False))
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd", default=""))
self.glade.get_widget("txt_proxy_hostname").set_text(self.preferences.get("proxy_hostname", default=""))
self.glade.get_widget("txt_proxy_username").set_text(self.preferences.get("proxy_username", default=""))
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password", default=""))
if(self.preferences.get("use_default_dir", bool, False)):
self.glade.get_widget("radio_save_all_to").set_active(True)
else:
@ -74,6 +78,7 @@ class PreferencesDlg:
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads", int, default=-1))
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_rate", int, default=-1))
self.glade.get_widget("spin_num_download").set_value(self.preferences.get("max_number_downloads", int, default=-1))
self.glade.get_widget("spin_proxy_port").set_value(self.preferences.get("proxy_port", int, default=8080))
self.glade.get_widget("spin_torrents").set_value(self.preferences.get("max_number_torrents", int, default=-1))
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom", bool, default=False))
self.glade.get_widget("chk_autoseed").set_active(self.preferences.get("auto_end_seeding", bool, default=False))
@ -92,6 +97,7 @@ class PreferencesDlg:
self.preferences.set("encin_state", self.glade.get_widget("combo_encin").get_active())
self.preferences.set("encout_state", self.glade.get_widget("combo_encout").get_active())
self.preferences.set("enclevel_type", self.glade.get_widget("combo_enclevel").get_active())
self.preferences.set("proxy_type", self.glade.get_widget("combo_proxy_type").get_active())
self.preferences.set("pref_rc4", self.glade.get_widget("chk_pref_rc4").get_active())
self.preferences.set("use_upnp", self.glade.get_widget("chk_upnp").get_active())
self.preferences.set("use_natpmp", self.glade.get_widget("chk_natpmp").get_active())
@ -100,6 +106,9 @@ class PreferencesDlg:
self.preferences.set("close_to_tray", self.glade.get_widget("chk_min_on_close").get_active())
self.preferences.set("lock_tray", self.glade.get_widget("chk_lock_tray").get_active())
self.preferences.set("tray_passwd", self.glade.get_widget("txt_tray_passwd").get_text())
self.preferences.set("proxy_username", self.glade.get_widget("txt_proxy_username").get_text())
self.preferences.set("proxy_password", self.glade.get_widget("txt_proxy_password").get_text())
self.preferences.set("proxy_hostname", self.glade.get_widget("txt_proxy_hostname").get_text())
self.preferences.set("use_default_dir", self.glade.get_widget("radio_save_all_to").get_active())
self.preferences.set("default_download_path", self.glade.get_widget("download_path_button").get_filename())
self.preferences.set("auto_end_seeding", self.glade.get_widget("chk_autoseed").get_active())
@ -109,6 +118,7 @@ class PreferencesDlg:
self.preferences.set("max_upload_rate", self.glade.get_widget("spin_max_upload").get_value())
self.preferences.set("max_number_uploads", self.glade.get_widget("spin_num_upload").get_value())
self.preferences.set("max_download_rate", self.glade.get_widget("spin_max_download").get_value())
self.preferences.set("proxy_port", self.glade.get_widget("spin_proxy_port").get_value())
self.preferences.set("max_number_downloads", self.glade.get_widget("spin_num_download").get_value())
self.preferences.set("max_number_torrents", self.glade.get_widget("spin_torrents").get_value())
self.preferences.set("queue_seeds_to_bottom", self.glade.get_widget("chk_seedbottom").get_active())

View File

@ -108,8 +108,6 @@ class DelugeGTK:
self.apply_prefs()
self.load_window_geometry()
self.manager.pe_settings(self.config.get("encout_state", int, default=common.EncState.enabled), self.config.get("encin_state", int, default=common.EncState.enabled), self.config.get("enclevel_type", int, default=common.EncLevel.both), self.config.get("pref_rc4", bool, default=True))
# Load plugins after GTK is initialised
self.update_queue.append(self.load_plugins)
@ -611,6 +609,8 @@ class DelugeGTK:
# Apply the preferences in the core
self.manager.apply_prefs()
self.manager.pe_settings(self.config.get("encout_state", int, default=common.EncState.enabled), self.config.get("encin_state", int, default=common.EncState.enabled), self.config.get("enclevel_type", int, default=common.EncLevel.both), self.config.get("pref_rc4", bool, default=True))
self.manager.proxy_settings(self.config.get("proxy_hostname"), self.config.get("proxy_username"), self.config.get("proxy_password"), self.config.get("proxy_port"), self.config.get("proxy_type", int, default=common.ProxyType.none))
def get_message_from_state(self, torrent_state):
state = torrent_state['state']

View File

@ -62,6 +62,11 @@ DEFAULT_PREFS = {
"max_upload_rate_bps" : -1.0,
"max_uploads" : 2,
"pref_rc4" : True,
"proxy_type" : common.ProxyType.none,
"proxy_hostname" : "",
"proxy_username" : "",
"proxy_password" : "",
"proxy_port": 8080,
"queue_seeds_to_bottom" : False,
"show_dl" : True,
"show_eta" : True,