From 71ed6b6f6739bfe74defe0fadd6821c157950ba2 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sat, 16 Jun 2007 10:56:09 +0000 Subject: [PATCH] proxy support --- glade/preferences_dialog.glade | 302 +++++++++++++++++++++++++-------- src/common.py | 3 + src/core.py | 11 +- src/deluge_core.cpp | 21 +++ src/dialogs.py | 10 ++ src/interface.py | 4 +- src/pref.py | 5 + 7 files changed, 276 insertions(+), 80 deletions(-) diff --git a/glade/preferences_dialog.glade b/glade/preferences_dialog.glade index c80dee3cc..4b5d2e6b2 100644 --- a/glade/preferences_dialog.glade +++ b/glade/preferences_dialog.glade @@ -315,40 +315,86 @@ 4 2 - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 10 - - - True - 0 - Maximum Upload Rate (KB/s): - - + True + The maximum upload rate for all torrents. Set -1 for unlimited. + 1 + -1 -1 9000 1 10 10 + 1 + 1 + 2 3 4 GTK_FILL - + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + The maximum download rate for all torrents. Set -1 for unlimited. + 1 + -1 -1 9000 1 10 10 + 1 + + + 1 + 2 + 2 + 3 + GTK_FILL + + + + + True + True + The maximum number of upload slots. Set -1 for unlimited. + 1 + -1 -1 1000 1 10 10 + 1 + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + True + The maximum number of connections allowed. Set -1 for unlimited. + 1 + -1 -1 1000 1 10 10 + 1 + + + 1 + 2 + GTK_FILL + + + + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 10 - + True 0 - Maximum Download Rate (KB/s): + Maximum Connections: - 2 - 3 GTK_FILL @@ -372,84 +418,38 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 10 - + True 0 - Maximum Connections: + Maximum Download Rate (KB/s): - GTK_FILL - - - - - True - True - The maximum number of connections allowed. Set -1 for unlimited. - 1 - -1 -1 1000 1 10 10 - 1 - - - 1 - 2 - GTK_FILL - - - - - True - True - The maximum number of upload slots. Set -1 for unlimited. - 1 - -1 -1 1000 1 10 10 - 1 - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - The maximum download rate for all torrents. Set -1 for unlimited. - 1 - -1 -1 9000 1 10 10 - 1 - - - 1 - 2 2 3 GTK_FILL - + True - True - The maximum upload rate for all torrents. Set -1 for unlimited. - 1 - -1 -1 9000 1 10 10 - 1 + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 10 + + + True + 0 + Maximum Upload Rate (KB/s): + + - 1 - 2 3 4 GTK_FILL @@ -955,7 +955,159 @@ Full Stream - + + True + 0 + + + True + 2 + 2 + 12 + + + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Type: + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + None +Socksv4 +Socksv5 +Socksv5 W/Auth +HTTP +HTTP W/ Auth + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Server: + + + 2 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 17 + + + False + False + 3 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Port: + + + 4 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 4 + 8080 0 10000 1 10 10 + True + + + 5 + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Username: + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Password: + + + 2 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + + + 3 + + + + + 1 + + + + + + + + + True + <b>Proxy</b> + True + + + label_item + + + + + False + 2 + 5 + diff --git a/src/common.py b/src/common.py index 022a3706f..a0996539d 100644 --- a/src/common.py +++ b/src/common.py @@ -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) diff --git a/src/core.py b/src/core.py index 2075e6661..605f433fd 100644 --- a/src/core.py +++ b/src/core.py @@ -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) + diff --git a/src/deluge_core.cpp b/src/deluge_core.cpp index 60f02b3eb..3070304ce 100644 --- a/src/deluge_core.cpp +++ b/src/deluge_core.cpp @@ -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} }; diff --git a/src/dialogs.py b/src/dialogs.py index 4a657e2fc..e8a8af3e1 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -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()) diff --git a/src/interface.py b/src/interface.py index 264451d07..0c032953b 100644 --- a/src/interface.py +++ b/src/interface.py @@ -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'] diff --git a/src/pref.py b/src/pref.py index 8787a2d73..a4e71d9c4 100644 --- a/src/pref.py +++ b/src/pref.py @@ -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,