fixing imports and indents to comply with python style guide - first attempt, this might break things

This commit is contained in:
Marcos Pinto 2007-07-11 04:22:44 +00:00
parent 6fd53ec356
commit d27137b4e2
11 changed files with 2829 additions and 2804 deletions

View File

@ -0,0 +1 @@

View File

@ -14,9 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -28,8 +28,12 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import sys, os, os.path, webbrowser
import xdg, xdg.BaseDirectory
import sys
import os
import os.path
import webbrowser
import xdg
import xdg.BaseDirectory
import gettext
@ -48,83 +52,83 @@ PIXMAP_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'pixmaps')
PLUGIN_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'plugins')
def estimate_eta(state):
try:
return ftime(get_eta(state["total_size"], state["total_done"], state["download_rate"]))
except ZeroDivisionError:
return _("Infinity")
try:
return ftime(get_eta(state["total_size"], state["total_done"], state["download_rate"]))
except ZeroDivisionError:
return _("Infinity")
def get_eta(size, done, speed):
if (size - done) == 0:
raise ZeroDivisionError
return (size - done) / speed
if (size - done) == 0:
raise ZeroDivisionError
return (size - done) / speed
# Returns formatted string describing filesize
# fsize_b should be in bytes
# Returned value will be in either KB, MB, or GB
def fsize(fsize_b):
fsize_kb = float (fsize_b / 1024.0)
if fsize_kb < 1000:
return _("%.1f KiB")%fsize_kb
fsize_mb = float (fsize_kb / 1024.0)
if fsize_mb < 1000:
return _("%.1f MiB")%fsize_mb
fsize_gb = float (fsize_mb / 1024.0)
return _("%.1f GiB")%fsize_gb
fsize_kb = float (fsize_b / 1024.0)
if fsize_kb < 1000:
return _("%.1f KiB")%fsize_kb
fsize_mb = float (fsize_kb / 1024.0)
if fsize_mb < 1000:
return _("%.1f MiB")%fsize_mb
fsize_gb = float (fsize_mb / 1024.0)
return _("%.1f GiB")%fsize_gb
# Returns a formatted string representing a percentage
def fpcnt(dec):
return '%.2f%%'%(dec * 100)
return '%.2f%%'%(dec * 100)
# Returns a formatted string representing transfer speed
def fspeed(bps):
return '%s/s'%(fsize(bps))
return '%s/s'%(fsize(bps))
def fseed(state):
return str(str(state['num_seeds']) + " (" + str(state['total_seeds']) + ")")
return str(str(state['num_seeds']) + " (" + str(state['total_seeds']) + ")")
def fpeer(state):
return str(str(state['num_peers']) + " (" + str(state['total_peers']) + ")")
return str(str(state['num_peers']) + " (" + str(state['total_peers']) + ")")
def ftime(seconds):
if seconds < 60:
return '%ds'%(seconds)
minutes = int(seconds/60)
seconds = seconds % 60
if minutes < 60:
return '%dm %ds'%(minutes, seconds)
hours = int(minutes/60)
minutes = minutes % 60
if hours < 24:
return '%dh %dm'%(hours, minutes)
days = int(hours/24)
hours = hours % 24
if days < 7:
return '%dd %dh'%(days, hours)
weeks = int(days/7)
days = days % 7
if weeks < 10:
return '%dw %dd'%(weeks, days)
return 'unknown'
if seconds < 60:
return '%ds'%(seconds)
minutes = int(seconds/60)
seconds = seconds % 60
if minutes < 60:
return '%dm %ds'%(minutes, seconds)
hours = int(minutes/60)
minutes = minutes % 60
if hours < 24:
return '%dh %dm'%(hours, minutes)
days = int(hours/24)
hours = hours % 24
if days < 7:
return '%dd %dh'%(days, hours)
weeks = int(days/7)
days = days % 7
if weeks < 10:
return '%dw %dd'%(weeks, days)
return 'unknown'
def get_glade_file(fname):
return os.path.join(GLADE_DIR, fname)
return os.path.join(GLADE_DIR, fname)
def get_pixmap(fname):
return os.path.join(PIXMAP_DIR, fname)
return os.path.join(PIXMAP_DIR, fname)
def open_url_in_browser(dialog, link):
try:
webbrowser.open(link)
except webbrowser.Error:
print _("Error: no webbrowser found")
try:
webbrowser.open(link)
except webbrowser.Error:
print _("Error: no webbrowser found")
# Encryption States
class EncState:
forced, enabled, disabled = range(3)
forced, enabled, disabled = range(3)
class EncLevel:
plaintext, rc4, both = range(3)
plaintext, rc4, both = range(3)
class ProxyType:
none, socks4, socks5, socks5_pw, http, http_pw = range(6)
none, socks4, socks5, socks5_pw, http, http_pw = range(6)

File diff suppressed because it is too large Load Diff

View File

@ -113,8 +113,8 @@ 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;
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;
@ -158,7 +158,7 @@ long get_torrent_index(torrent_handle &handle)
for (unsigned long i = 0; i < M_torrents->size(); i++)
if ((*M_torrents)[i].handle == handle)
{
// printf("Found: %li\r\n", i);
// printf("Found: %li\r\n", i);
return i;
}
@ -210,7 +210,7 @@ boost::filesystem::path const& save_path)
torrent_t new_torrent;
torrent_handle h = M_ses->add_torrent(t, save_path, resume_data, compact_mode, 16 * 1024);
// h.set_max_connections(60); // at some point we should use this
// h.set_max_connections(60); // at some point we should use this
h.set_max_uploads(-1);
h.set_ratio(preferred_ratio);
new_torrent.handle = h;
@ -436,7 +436,7 @@ static PyObject *torrent_set_download_rate_limit(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &arg))
return NULL;
// printf("Capping download to %d bytes per second\r\n", (int)arg);
// printf("Capping download to %d bytes per second\r\n", (int)arg);
M_ses->set_download_rate_limit(arg);
Py_INCREF(Py_None); return Py_None;
@ -449,7 +449,7 @@ static PyObject *torrent_set_upload_rate_limit(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &arg))
return NULL;
// printf("Capping upload to %d bytes per second\r\n", (int)arg);
// printf("Capping upload to %d bytes per second\r\n", (int)arg);
M_ses->set_upload_rate_limit(arg);
Py_INCREF(Py_None); return Py_None;
@ -501,7 +501,7 @@ static PyObject *torrent_set_max_connections(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &max_conn))
return NULL;
// printf("Setting max connections: %d\r\n", max_conn);
// printf("Setting max connections: %d\r\n", max_conn);
M_ses->set_max_connections(max_conn);
Py_INCREF(Py_None); return Py_None;
@ -629,14 +629,14 @@ static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
for (unsigned long i = 0; i < peers.size(); i++) {
connected_peers = s.num_peers - s.num_seeds;
connected_peers = s.num_peers - s.num_seeds;
connected_seeds = s.num_seeds;
connected_seeds = s.num_seeds;
total_seeds = s.num_complete != -1? s.num_complete : connected_seeds;
total_seeds = s.num_complete != -1? s.num_complete : connected_seeds;
total_peers = s.num_incomplete != -1? s.num_incomplete : connected_peers;
}
total_peers = s.num_incomplete != -1? s.num_incomplete : connected_peers;
}
return Py_BuildValue("{s:s,s:i,s:i,s:l,s:l,s:f,s:f,s:f,s:L,s:L,s:b,s:s,s:s,s:f,s:L,s:L,s:l,s:i,s:i,s:L,s:L,s:i,s:l,s:l,s:b,s:b,s:L,s:L,s:L}",
"name", t.handle.get_torrent_info().name().c_str(),
@ -661,11 +661,11 @@ static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
"total_size", i.total_size(),
"piece_length", i.piece_length(),
"num_pieces", i.num_pieces(),
"total_peers", total_peers,
"total_seeds", total_seeds,
"total_peers", total_peers,
"total_seeds", total_seeds,
"is_paused", t.handle.is_paused(),
"is_seed", t.handle.is_seed(),
"total_done", s.total_done,
"total_done", s.total_done,
"total_wanted", s.total_wanted,
"total_wanted_done", s.total_wanted_done);
};
@ -1033,7 +1033,7 @@ static PyObject *torrent_start_DHT(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &DHT_path))
return NULL;
// printf("Loading DHT state from %s\r\n", DHT_path);
// printf("Loading DHT state from %s\r\n", DHT_path);
boost::filesystem::path tempPath(DHT_path, empty_name_check);
boost::filesystem::ifstream DHT_state_file(tempPath, std::ios_base::binary);
@ -1045,10 +1045,10 @@ static PyObject *torrent_start_DHT(PyObject *self, PyObject *args)
DHT_state = bdecode(std::istream_iterator<char>(DHT_state_file),
std::istream_iterator<char>());
M_ses->start_dht(DHT_state);
// printf("DHT state recovered.\r\n");
// printf("DHT state recovered.\r\n");
// // Print out the state data from the FILE (not the session!)
// printf("Number of DHT peers in recovered state: %ld\r\n", count_DHT_peers(DHT_state));
// // Print out the state data from the FILE (not the session!)
// printf("Number of DHT peers in recovered state: %ld\r\n", count_DHT_peers(DHT_state));
}
catch (std::exception&)
@ -1074,7 +1074,7 @@ static PyObject *torrent_stop_DHT(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &DHT_path))
return NULL;
// printf("Saving DHT state to %s\r\n", DHT_path);
// printf("Saving DHT state to %s\r\n", DHT_path);
boost::filesystem::path tempPath = boost::filesystem::path(DHT_path, empty_name_check);
@ -1082,7 +1082,7 @@ static PyObject *torrent_stop_DHT(PyObject *self, PyObject *args)
{
entry DHT_state = M_ses->dht_state();
// printf("Number of DHT peers in state, saving: %ld\r\n", count_DHT_peers(DHT_state));
// printf("Number of DHT peers in state, saving: %ld\r\n", count_DHT_peers(DHT_state));
boost::filesystem::ofstream out(tempPath, std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
@ -1105,7 +1105,7 @@ static PyObject *torrent_get_DHT_info(PyObject *self, PyObject *args)
return Py_BuildValue("l", python_long(count_DHT_peers(DHT_state)));
/*
// DHT_state.print(cout);
// DHT_state.print(cout);
entry *nodes = DHT_state.find_key("nodes");
if (!nodes)
return Py_BuildValue("l", -1); // No nodes - we are just starting up...
@ -1190,8 +1190,8 @@ static PyObject *torrent_create_torrent(PyObject *self, PyObject *args)
return Py_BuildValue("l", 1);
} catch (std::exception& e)
{
// std::cerr << e.what() << "\n";
// return Py_BuildValue("l", 0);
// std::cerr << e.what() << "\n";
// return Py_BuildValue("l", 0);
RAISE_PTR(DelugeError, e.what());
return Py_BuildValue("l", 0);
}
@ -1231,15 +1231,15 @@ static PyObject *torrent_add_range_to_IP_filter(PyObject *self, PyObject *args)
static PyObject *torrent_use_upnp(PyObject *self, PyObject *args)
{
python_long action;
PyArg_ParseTuple(args, "i", &action);
python_long action;
PyArg_ParseTuple(args, "i", &action);
if (action){
M_ses->start_upnp();
}
else{
M_ses->stop_upnp();
}
if (action){
M_ses->start_upnp();
}
else{
M_ses->stop_upnp();
}
Py_INCREF(Py_None); return Py_None;
@ -1247,49 +1247,49 @@ static PyObject *torrent_use_upnp(PyObject *self, PyObject *args)
static PyObject *torrent_use_natpmp(PyObject *self, PyObject *args)
{
python_long action;
python_long action;
PyArg_ParseTuple(args, "i", &action);
PyArg_ParseTuple(args, "i", &action);
if (action){
M_ses->start_natpmp();
}
else{
M_ses->stop_natpmp();
}
if (action){
M_ses->start_natpmp();
}
else{
M_ses->stop_natpmp();
}
Py_INCREF(Py_None); return Py_None;
}
static PyObject *torrent_use_utpex(PyObject *self, PyObject *args)
{
python_long action;
python_long action;
PyArg_ParseTuple(args, "i", &action);
PyArg_ParseTuple(args, "i", &action);
if (action){
M_ses->add_extension(&libtorrent::create_ut_pex_plugin);
}
if (action){
M_ses->add_extension(&libtorrent::create_ut_pex_plugin);
}
Py_INCREF(Py_None); return Py_None;
}
static PyObject *torrent_pe_settings(PyObject *self, PyObject *args)
{
M_pe_settings = new pe_settings();
libtorrent::pe_settings::enc_policy out, in, prefer;
libtorrent::pe_settings::enc_level level;
M_pe_settings = new pe_settings();
libtorrent::pe_settings::enc_policy out, in, prefer;
libtorrent::pe_settings::enc_level level;
PyArg_ParseTuple(args, "iiii", &out, &in, &level, &prefer);
PyArg_ParseTuple(args, "iiii", &out, &in, &level, &prefer);
M_pe_settings->out_enc_policy = out;
M_pe_settings->in_enc_policy = in;
M_pe_settings->allowed_enc_level = level;
M_pe_settings->prefer_rc4 = prefer;
M_pe_settings->out_enc_policy = out;
M_pe_settings->in_enc_policy = in;
M_pe_settings->allowed_enc_level = level;
M_pe_settings->prefer_rc4 = prefer;
M_ses->set_pe_settings(*M_pe_settings);
M_ses->set_pe_settings(*M_pe_settings);
return Py_None;
return Py_None;
}
static PyObject *torrent_set_ratio(PyObject *self, PyObject *args)
@ -1310,57 +1310,57 @@ static PyObject *torrent_set_ratio(PyObject *self, PyObject *args)
static PyObject *torrent_proxy_settings(PyObject *self, PyObject *args)
{
M_proxy_settings = new proxy_settings();
M_proxy_settings = new proxy_settings();
char *server, *login, *pasw;
int portnum;
libtorrent::proxy_settings::proxy_type proxytype;
bool peerproxy, trackerproxy, dhtproxy;
char *server, *login, *pasw;
int portnum;
libtorrent::proxy_settings::proxy_type proxytype;
bool peerproxy, trackerproxy, dhtproxy;
PyArg_ParseTuple(args, "sssiibbb", &server, &login, &pasw, &portnum, &proxytype, &peerproxy, &trackerproxy, &dhtproxy);
PyArg_ParseTuple(args, "sssiibbb", &server, &login, &pasw, &portnum, &proxytype, &peerproxy, &trackerproxy, &dhtproxy);
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;
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;
if (peerproxy) {
M_ses->set_peer_proxy(*M_proxy_settings);
}
if (peerproxy) {
M_ses->set_peer_proxy(*M_proxy_settings);
}
if (trackerproxy) {
M_ses->set_tracker_proxy(*M_proxy_settings);
}
if (trackerproxy) {
M_ses->set_tracker_proxy(*M_proxy_settings);
}
if (dhtproxy) {
M_ses->set_dht_proxy(*M_proxy_settings);
}
if (dhtproxy) {
M_ses->set_dht_proxy(*M_proxy_settings);
}
return Py_None;
return Py_None;
}
static PyObject *torrent_get_trackers(PyObject *self, PyObject *args)
{
python_long unique_ID;
if (!PyArg_ParseTuple(args, "i", &unique_ID))
return NULL;
python_long unique_ID;
if (!PyArg_ParseTuple(args, "i", &unique_ID))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
torrent_handle& h = M_torrents->at(index).handle;
std::string trackerslist;
if (h.is_valid() && h.has_metadata())
{
for (std::vector<announce_entry>::const_iterator i = h.trackers().begin();
i != h.trackers().end(); ++i)
{
trackerslist = trackerslist + i->url +"\n";
}
}
return Py_BuildValue("s",trackerslist.c_str());
torrent_handle& h = M_torrents->at(index).handle;
std::string trackerslist;
if (h.is_valid() && h.has_metadata())
{
for (std::vector<announce_entry>::const_iterator i = h.trackers().begin();
i != h.trackers().end(); ++i)
{
trackerslist = trackerslist + i->url +"\n";
}
}
return Py_BuildValue("s",trackerslist.c_str());
}
static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args)

View File

@ -13,9 +13,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -36,54 +36,54 @@ old_peer_info_timestamp = None
# Availability - how many complete copies are among our peers
def calc_availability(peer_info):
if len(peer_info) == 0:
return 0
if len(peer_info) == 0:
return 0
num_pieces = len(peer_info[0].pieces)
num_pieces = len(peer_info[0].pieces)
freqs = [0]*num_pieces
freqs = [0]*num_pieces
for peer in peer_info:
for piece in num_pieces:
freqs[piece] = freqs[piece] + peer['pieces'][piece]
for peer in peer_info:
for piece in num_pieces:
freqs[piece] = freqs[piece] + peer['pieces'][piece]
minimum = min(freqs)
# frac = freqs.count(minimum + 1) # Does this mean something?
minimum = min(freqs)
# frac = freqs.count(minimum + 1) # Does this mean something?
return minimum
return minimum
# Swarm speed - try to guess the speed of the entire swarm
# We return #pieces / second. The calling function should convert pieces to KB, if it wants
# Note that we return the delta from the last call. If the client calls too soon, this may
# be too unreliable. But the client can smooth things out, if desired
def calc_swarm_speed(peer_info):
if old_peer_info is not None:
new_pieces = 0
peers_known = 0
if old_peer_info is not None:
new_pieces = 0
peers_known = 0
# List new peers
new_peer_IPs = {} # ip->peerinfo dict (from the core)
for peer in peer_info:
new_peer_IPs[peer['ip']] = peer
# List new peers
new_peer_IPs = {} # ip->peerinfo dict (from the core)
for peer in peer_info:
new_peer_IPs[peer['ip']] = peer
for new_IP in new_peer_IPs.keys():
if new_IP in old_peer_IPs.keys():
# We know this peer from before, see what changed
peers_known = peers_known + 1
delta = sum(new_peer_IPs[new_IP].pieces) - sum(old_peer_IPs[new_IP].pieces)
for new_IP in new_peer_IPs.keys():
if new_IP in old_peer_IPs.keys():
# We know this peer from before, see what changed
peers_known = peers_known + 1
delta = sum(new_peer_IPs[new_IP].pieces) - sum(old_peer_IPs[new_IP].pieces)
if delta >= 0:
new_pieces = new_pieces + delta
else:
print "Deluge.stat.calc_swarm_speed: Bad Delta: ", delta, old_peer_IPs[new_IP].pieces, new_peer_IPs[new_IP].pieces
if delta >= 0:
new_pieces = new_pieces + delta
else:
print "Deluge.stat.calc_swarm_speed: Bad Delta: ", delta, old_peer_IPs[new_IP].pieces, new_peer_IPs[new_IP].pieces
# Calculate final value
time_delta = time.time() - old_peer_info_timestamp
ret = float(new_pieces)/( float(peers_known) * time_delta )
# Calculate final value
time_delta = time.time() - old_peer_info_timestamp
ret = float(new_pieces)/( float(peers_known) * time_delta )
# Save info
old_peer_info = peer_info
old_peer_info_timestamp = time.time()
old_peer_IPs = new_peer_IPs
# Save info
old_peer_info = peer_info
old_peer_info_timestamp = time.time()
old_peer_IPs = new_peer_IPs
return ret
return ret

View File

@ -14,9 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -40,96 +40,96 @@ import gtk.glade
# This is a dummy tray object to allow Deluge to run on PyGTK < 2.9
class StupidTray:
def __init__(self):
pass
def set_visible(self, value):
pass
def set_tooltip(self, value):
pass
def __init__(self):
pass
def set_visible(self, value):
pass
def set_tooltip(self, value):
pass
## Cell data functions to pass to add_func_column()
def cell_data_speed(column, cell, model, iter, data):
speed = int(model.get_value(iter, data))
speed_str = common.fspeed(speed)
cell.set_property('text', speed_str)
speed = int(model.get_value(iter, data))
speed_str = common.fspeed(speed)
cell.set_property('text', speed_str)
## Functions to create columns
def add_func_column(view, header, func, data, sortid=None):
column = gtk.TreeViewColumn(header)
render = gtk.CellRendererText()
column.pack_start(render, True)
column.set_cell_data_func(render, func, data)
if sortid is not None:
column.set_clickable(True)
column.set_sort_column_id(sortid)
else:
try:
if len(data) == 1:
column.set_clickable(True)
column.set_sort_column_id(data[0])
except TypeError:
column.set_clickable(True)
column.set_sort_column_id(data)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
column = gtk.TreeViewColumn(header)
render = gtk.CellRendererText()
column.pack_start(render, True)
column.set_cell_data_func(render, func, data)
if sortid is not None:
column.set_clickable(True)
column.set_sort_column_id(sortid)
else:
try:
if len(data) == 1:
column.set_clickable(True)
column.set_sort_column_id(data[0])
except TypeError:
column.set_clickable(True)
column.set_sort_column_id(data)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
def add_text_column(view, header, cid):
render = gtk.CellRendererText()
column = gtk.TreeViewColumn(header, render, text=cid)
column.set_clickable(True)
column.set_sort_column_id(cid)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
render = gtk.CellRendererText()
column = gtk.TreeViewColumn(header, render, text=cid)
column.set_clickable(True)
column.set_sort_column_id(cid)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
def add_progress_column(view, header, pid, mid):
render = gtk.CellRendererProgress()
column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
column.set_clickable(True)
column.set_sort_column_id(pid)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
render = gtk.CellRendererProgress()
column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
column.set_clickable(True)
column.set_sort_column_id(pid)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
return column
def add_toggle_column(view, header, cid, toggled_signal=None):
render = gtk.CellRendererToggle()
render.set_property('activatable', True)
column = gtk.TreeViewColumn(header, render, active=cid)
column.set_clickable(True)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
if toggled_signal is not None:
render.connect("toggled", toggled_signal)
return column
render = gtk.CellRendererToggle()
render.set_property('activatable', True)
column = gtk.TreeViewColumn(header, render, active=cid)
column.set_clickable(True)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
view.append_column(column)
if toggled_signal is not None:
render.connect("toggled", toggled_signal)
return column
def add_texticon_column(view, header, icon_col, text_col):
column = gtk.TreeViewColumn(header)
column.set_clickable(True)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
render = gtk.CellRendererPixbuf()
column.pack_start(render, expand=False)
column.add_attribute(render, 'pixbuf', icon_col)
render = gtk.CellRendererText()
column.pack_start(render, expand=True)
column.add_attribute(render, 'text', text_col)
view.append_column(column)
return column
column = gtk.TreeViewColumn(header)
column.set_clickable(True)
column.set_resizable(True)
column.set_expand(False)
column.set_min_width(10)
column.set_reorderable(True)
render = gtk.CellRendererPixbuf()
column.pack_start(render, expand=False)
column.add_attribute(render, 'pixbuf', icon_col)
render = gtk.CellRendererText()
column.pack_start(render, expand=True)
column.add_attribute(render, 'text', text_col)
view.append_column(column)
return column

View File

@ -14,9 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -28,285 +28,289 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import common, dgtk, pref
import gtk, gtk.glade
import os, os.path
import common
import dgtk
import pref
import gtk
import gtk.glade
import os
import os.path
PREFS_FILENAME = "prefs.state"
class PreferencesDlg:
def __init__(self, parent, preferences):
self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge')
self.dialog = self.glade.get_widget("pref_dialog")
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
self.glade.signal_autoconnect({
'on_chk_use_tray_toggled': self.tray_toggle,
'on_btn_testport_clicked': self.TestPort,
})
self.parent = parent
self.preferences = preferences
def __init__(self, parent, preferences):
self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge')
self.dialog = self.glade.get_widget("pref_dialog")
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
self.glade.signal_autoconnect({
'on_chk_use_tray_toggled': self.tray_toggle,
'on_btn_testport_clicked': self.TestPort,
})
self.parent = parent
self.preferences = preferences
def show(self):
# Load settings into dialog
try:
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state"))
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state"))
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type"))
self.glade.get_widget("combo_proxy_type").set_active(self.preferences.get("proxy_type"))
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4"))
self.glade.get_widget("chk_peer_proxy").set_active(self.preferences.get("peer_proxy"))
self.glade.get_widget("chk_tracker_proxy").set_active(self.preferences.get("tracker_proxy"))
self.glade.get_widget("chk_dht_proxy").set_active(self.preferences.get("dht_proxy"))
self.glade.get_widget("chk_upnp").set_active(self.preferences.get("use_upnp"))
self.glade.get_widget("chk_natpmp").set_active(self.preferences.get("use_natpmp"))
self.glade.get_widget("chk_utpex").set_active(self.preferences.get("use_utpex"))
self.glade.get_widget("chk_use_tray").set_active(self.preferences.get("enable_system_tray"))
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray"))
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray"))
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd"))
self.glade.get_widget("txt_proxy_hostname").set_text(self.preferences.get("proxy_hostname"))
self.glade.get_widget("txt_proxy_username").set_text(self.preferences.get("proxy_username"))
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password"))
if(self.preferences.get("use_default_dir")):
self.glade.get_widget("radio_save_all_to").set_active(True)
else:
self.glade.get_widget("radio_ask_save").set_active(True)
def show(self):
# Load settings into dialog
try:
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state"))
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state"))
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type"))
self.glade.get_widget("combo_proxy_type").set_active(self.preferences.get("proxy_type"))
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4"))
self.glade.get_widget("chk_peer_proxy").set_active(self.preferences.get("peer_proxy"))
self.glade.get_widget("chk_tracker_proxy").set_active(self.preferences.get("tracker_proxy"))
self.glade.get_widget("chk_dht_proxy").set_active(self.preferences.get("dht_proxy"))
self.glade.get_widget("chk_upnp").set_active(self.preferences.get("use_upnp"))
self.glade.get_widget("chk_natpmp").set_active(self.preferences.get("use_natpmp"))
self.glade.get_widget("chk_utpex").set_active(self.preferences.get("use_utpex"))
self.glade.get_widget("chk_use_tray").set_active(self.preferences.get("enable_system_tray"))
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray"))
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray"))
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd"))
self.glade.get_widget("txt_proxy_hostname").set_text(self.preferences.get("proxy_hostname"))
self.glade.get_widget("txt_proxy_username").set_text(self.preferences.get("proxy_username"))
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password"))
if(self.preferences.get("use_default_dir")):
self.glade.get_widget("radio_save_all_to").set_active(True)
else:
self.glade.get_widget("radio_ask_save").set_active(True)
self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path"))
self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage"))
self.glade.get_widget("active_port_label").set_text(str(self.parent.manager.get_state()['port']))
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on")[0])
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on")[1])
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_speed"))
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads"))
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_speed"))
self.glade.get_widget("spin_max_connections").set_value(self.preferences.get("max_connections"))
self.glade.get_widget("spin_proxy_port").set_value(self.preferences.get("proxy_port"))
self.glade.get_widget("spin_torrents").set_value(float(self.preferences.get("max_active_torrents")))
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom"))
self.glade.get_widget("chk_autoseed").set_active(self.preferences.get("auto_end_seeding"))
self.glade.get_widget("ratio_spinner").set_value(self.preferences.get("auto_seed_ratio"))
self.glade.get_widget("chk_dht").set_active(self.preferences.get("enable_dht"))
self.glade.get_widget("spin_gui").set_value(self.preferences.get("gui_update_interval"))
self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path"))
self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage"))
self.glade.get_widget("active_port_label").set_text(str(self.parent.manager.get_state()['port']))
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on")[0])
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on")[1])
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_speed"))
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads"))
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_speed"))
self.glade.get_widget("spin_max_connections").set_value(self.preferences.get("max_connections"))
self.glade.get_widget("spin_proxy_port").set_value(self.preferences.get("proxy_port"))
self.glade.get_widget("spin_torrents").set_value(float(self.preferences.get("max_active_torrents")))
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom"))
self.glade.get_widget("chk_autoseed").set_active(self.preferences.get("auto_end_seeding"))
self.glade.get_widget("ratio_spinner").set_value(self.preferences.get("auto_seed_ratio"))
self.glade.get_widget("chk_dht").set_active(self.preferences.get("enable_dht"))
self.glade.get_widget("spin_gui").set_value(self.preferences.get("gui_update_interval"))
except KeyError:
pass
# Now, show the dialog
self.dialog.show()
r = self.dialog.run()
self.dialog.hide()
# Now, get the settings from the dialog
if r == 1:
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("peer_proxy", self.glade.get_widget("chk_peer_proxy").get_active())
self.preferences.set("tracker_proxy", self.glade.get_widget("chk_tracker_proxy").get_active())
self.preferences.set("dht_proxy", self.glade.get_widget("chk_dht_proxy").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())
self.preferences.set("use_utpex", self.glade.get_widget("chk_utpex").get_active())
self.preferences.set("enable_system_tray", self.glade.get_widget("chk_use_tray").get_active())
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())
self.preferences.set("auto_seed_ratio", self.glade.get_widget("ratio_spinner").get_value())
self.preferences.set("use_compact_storage", self.glade.get_widget("chk_compact").get_active())
self.preferences.set("listen_on", [self.glade.get_widget("spin_port_min").get_value(), self.glade.get_widget("spin_port_max").get_value()])
self.preferences.set("max_upload_speed", 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_speed", 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_connections", int(self.glade.get_widget("spin_max_connections").get_value()))
self.preferences.set("max_active_torrents", int(self.glade.get_widget("spin_torrents").get_value()))
self.preferences.set("queue_seeds_to_bottom", self.glade.get_widget("chk_seedbottom").get_active())
self.preferences.set("enable_dht", self.glade.get_widget("chk_dht").get_active())
self.preferences.set("gui_update_interval", self.glade.get_widget("spin_gui").get_value())
except KeyError:
pass
# Now, show the dialog
self.dialog.show()
r = self.dialog.run()
self.dialog.hide()
# Now, get the settings from the dialog
if r == 1:
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("peer_proxy", self.glade.get_widget("chk_peer_proxy").get_active())
self.preferences.set("tracker_proxy", self.glade.get_widget("chk_tracker_proxy").get_active())
self.preferences.set("dht_proxy", self.glade.get_widget("chk_dht_proxy").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())
self.preferences.set("use_utpex", self.glade.get_widget("chk_utpex").get_active())
self.preferences.set("enable_system_tray", self.glade.get_widget("chk_use_tray").get_active())
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())
self.preferences.set("auto_seed_ratio", self.glade.get_widget("ratio_spinner").get_value())
self.preferences.set("use_compact_storage", self.glade.get_widget("chk_compact").get_active())
self.preferences.set("listen_on", [self.glade.get_widget("spin_port_min").get_value(), self.glade.get_widget("spin_port_max").get_value()])
self.preferences.set("max_upload_speed", 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_speed", 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_connections", int(self.glade.get_widget("spin_max_connections").get_value()))
self.preferences.set("max_active_torrents", int(self.glade.get_widget("spin_torrents").get_value()))
self.preferences.set("queue_seeds_to_bottom", self.glade.get_widget("chk_seedbottom").get_active())
self.preferences.set("enable_dht", self.glade.get_widget("chk_dht").get_active())
self.preferences.set("gui_update_interval", self.glade.get_widget("spin_gui").get_value())
return r
return r
def TestPort(self, widget):
activep = str(self.parent.manager.get_state()['port'])
common.open_url_in_browser(self.dialog,'http://www.deluge-torrent.org/test-port.php?port=%s' %activep)
def TestPort(self, widget):
activep = str(self.parent.manager.get_state()['port'])
common.open_url_in_browser(self.dialog,'http://www.deluge-torrent.org/test-port.php?port=%s' %activep)
def tray_toggle(self, widget):
is_active = widget.get_active()
def tray_toggle(self, widget):
is_active = widget.get_active()
self.glade.get_widget("chk_min_on_close").set_sensitive(is_active)
self.glade.get_widget("chk_lock_tray").set_sensitive(is_active)
self.glade.get_widget("txt_tray_passwd").set_sensitive(is_active)
self.glade.get_widget("chk_min_on_close").set_sensitive(is_active)
self.glade.get_widget("chk_lock_tray").set_sensitive(is_active)
self.glade.get_widget("txt_tray_passwd").set_sensitive(is_active)
class PluginDlg:
def __init__(self, parent, plugins):
self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge')
self.dialog = self.glade.get_widget("plugin_dialog")
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
self.view = self.glade.get_widget("plugin_view")
self.store = gtk.ListStore(str, bool)
self.view.set_model(self.store)
try:
self.view.get_selection().set_select_function(self.plugin_clicked, full=True)
except TypeError:
self.view.get_selection().set_select_function(self.old_clicked)
name_col = dgtk.add_text_column(self.view, _("Plugin"), 0)
name_col.set_expand(True)
dgtk.add_toggle_column(self.view, _("Enabled"), 1, toggled_signal=self.plugin_toggled)
self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref})
self.parent = parent
self.plugins = plugins
def __init__(self, parent, plugins):
self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge')
self.dialog = self.glade.get_widget("plugin_dialog")
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
self.view = self.glade.get_widget("plugin_view")
self.store = gtk.ListStore(str, bool)
self.view.set_model(self.store)
try:
self.view.get_selection().set_select_function(self.plugin_clicked, full=True)
except TypeError:
self.view.get_selection().set_select_function(self.old_clicked)
name_col = dgtk.add_text_column(self.view, _("Plugin"), 0)
name_col.set_expand(True)
dgtk.add_toggle_column(self.view, _("Enabled"), 1, toggled_signal=self.plugin_toggled)
self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref})
self.parent = parent
self.plugins = plugins
def show(self):
self.store.clear()
for plugin in self.plugins.get_available_plugins():
#print plugin
if plugin in self.plugins.get_enabled_plugins():
self.store.append( (plugin, True) )
else:
self.store.append( (plugin, False) )
self.glade.get_widget("plugin_text").get_buffer().set_text("")
self.glade.get_widget("plugin_conf").set_sensitive(False)
self.dialog.show()
self.dialog.run()
self.dialog.hide()
def show(self):
self.store.clear()
for plugin in self.plugins.get_available_plugins():
#print plugin
if plugin in self.plugins.get_enabled_plugins():
self.store.append( (plugin, True) )
else:
self.store.append( (plugin, False) )
self.glade.get_widget("plugin_text").get_buffer().set_text("")
self.glade.get_widget("plugin_conf").set_sensitive(False)
self.dialog.show()
self.dialog.run()
self.dialog.hide()
def old_clicked(self, path):
return self.plugin_clicked(self.view.get_selection(), self.store, path, False)
def old_clicked(self, path):
return self.plugin_clicked(self.view.get_selection(), self.store, path, False)
def plugin_clicked(self, selection, model, path, is_selected):
if is_selected:
return True
name = model.get_value(model.get_iter(path), 0)
plugin = self.plugins.get_plugin(name)
author = plugin.plugin_author
version = plugin.plugin_version
description = plugin.plugin_description
if name in self.plugins.get_enabled_plugins():
config = self.plugins.configurable_plugin(name)
self.glade.get_widget("plugin_conf").set_sensitive(config)
else:
self.glade.get_widget("plugin_conf").set_sensitive(False)
self.glade.get_widget("plugin_text").get_buffer(
).set_text("%s\nBy: %s\nVersion: %s\n\n%s"%
(name, author, version, description))
return True
def plugin_clicked(self, selection, model, path, is_selected):
if is_selected:
return True
name = model.get_value(model.get_iter(path), 0)
plugin = self.plugins.get_plugin(name)
author = plugin.plugin_author
version = plugin.plugin_version
description = plugin.plugin_description
if name in self.plugins.get_enabled_plugins():
config = self.plugins.configurable_plugin(name)
self.glade.get_widget("plugin_conf").set_sensitive(config)
else:
self.glade.get_widget("plugin_conf").set_sensitive(False)
self.glade.get_widget("plugin_text").get_buffer(
).set_text("%s\nBy: %s\nVersion: %s\n\n%s"%
(name, author, version, description))
return True
def plugin_toggled(self, renderer, path):
plugin_iter = self.store.get_iter_from_string(path)
plugin_name = self.store.get_value(plugin_iter, 0)
plugin_value = not self.store.get_value(plugin_iter, 1)
self.store.set_value(plugin_iter, 1, plugin_value)
if plugin_value:
config = self.plugins.configurable_plugin(plugin_name)
self.glade.get_widget("plugin_conf").set_sensitive(config)
self.plugins.enable_plugin(plugin_name)
else:
self.plugins.disable_plugin(plugin_name)
self.glade.get_widget("plugin_conf").set_sensitive(False)
def plugin_toggled(self, renderer, path):
plugin_iter = self.store.get_iter_from_string(path)
plugin_name = self.store.get_value(plugin_iter, 0)
plugin_value = not self.store.get_value(plugin_iter, 1)
self.store.set_value(plugin_iter, 1, plugin_value)
if plugin_value:
config = self.plugins.configurable_plugin(plugin_name)
self.glade.get_widget("plugin_conf").set_sensitive(config)
self.plugins.enable_plugin(plugin_name)
else:
self.plugins.disable_plugin(plugin_name)
self.glade.get_widget("plugin_conf").set_sensitive(False)
def plugin_pref(self, widget=None):
(model, plugin_iter) = self.view.get_selection().get_selected()
plugin_name = self.store.get_value(plugin_iter, 0)
self.plugins.configure_plugin(plugin_name)
def plugin_pref(self, widget=None):
(model, plugin_iter) = self.view.get_selection().get_selected()
plugin_name = self.store.get_value(plugin_iter, 0)
self.plugins.configure_plugin(plugin_name)
def show_about_dialog(parent=None):
gtk.about_dialog_set_url_hook(common.open_url_in_browser)
abt = gtk.glade.XML(common.get_glade_file("aboutdialog.glade")).get_widget("aboutdialog")
abt.set_name(common.PROGRAM_NAME)
abt.set_version(common.PROGRAM_VERSION)
abt.set_authors(["Zach Tibbitts", "Alon Zakai", "Marcos Pinto", "Andrew Resch"])
abt.set_artists(["Andrew Wedderburn"])
abt.set_translator_credits(_("translator-credits"))
abt.set_website("http://deluge-torrent.org")
abt.set_website_label("http://deluge-torrent.org")
abt.set_icon_from_file(common.get_pixmap("deluge32.png"))
abt.set_logo(gtk.gdk.pixbuf_new_from_file(
common.get_pixmap("deluge-about.png")))
abt.show_all()
abt.run()
abt.hide_all()
gtk.about_dialog_set_url_hook(common.open_url_in_browser)
abt = gtk.glade.XML(common.get_glade_file("aboutdialog.glade")).get_widget("aboutdialog")
abt.set_name(common.PROGRAM_NAME)
abt.set_version(common.PROGRAM_VERSION)
abt.set_authors(["Zach Tibbitts", "Alon Zakai", "Marcos Pinto", "Andrew Resch"])
abt.set_artists(["Andrew Wedderburn"])
abt.set_translator_credits(_("translator-credits"))
abt.set_website("http://deluge-torrent.org")
abt.set_website_label("http://deluge-torrent.org")
abt.set_icon_from_file(common.get_pixmap("deluge32.png"))
abt.set_logo(gtk.gdk.pixbuf_new_from_file(
common.get_pixmap("deluge-about.png")))
abt.show_all()
abt.run()
abt.hide_all()
def show_popup_warning(window, message):
warner = gtk.MessageDialog(parent = window,
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
buttons= gtk.BUTTONS_OK,
message_format=message,
type = gtk.MESSAGE_WARNING)
warner.run()
warner.destroy()
warner = gtk.MessageDialog(parent = window,
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
buttons= gtk.BUTTONS_OK,
message_format=message,
type = gtk.MESSAGE_WARNING)
warner.run()
warner.destroy()
def show_popup_question(window, message):
asker = gtk.MessageDialog(parent = window,
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
buttons = gtk.BUTTONS_YES_NO,
message_format=message,
type=gtk.MESSAGE_QUESTION)
result = asker.run()
asker.destroy()
if result == gtk.RESPONSE_YES:
return True
elif result == gtk.RESPONSE_NO:
return False
elif result == gtk.RESPONSE_DELETE_EVENT:
return False
else:
return False
asker = gtk.MessageDialog(parent = window,
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
buttons = gtk.BUTTONS_YES_NO,
message_format=message,
type=gtk.MESSAGE_QUESTION)
result = asker.run()
asker.destroy()
if result == gtk.RESPONSE_YES:
return True
elif result == gtk.RESPONSE_NO:
return False
elif result == gtk.RESPONSE_DELETE_EVENT:
return False
else:
return False
## Browse for .torrent files
def show_file_open_dialog(parent=None, title=None):
if title is None:
title = _("Choose a .torrent file")
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
if title is None:
title = _("Choose a .torrent file")
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
f0 = gtk.FileFilter()
f0.set_name(_("Torrent files"))
f0.add_pattern("*." + "torrent")
chooser.add_filter(f0)
f1 = gtk.FileFilter()
f1.set_name(_("All files"))
f1.add_pattern("*")
loadpref = pref.Preferences()
chooser.set_current_folder(loadpref.get("default_load_path"))
chooser.add_filter(f1)
chooser.set_select_multiple(True)
f0 = gtk.FileFilter()
f0.set_name(_("Torrent files"))
f0.add_pattern("*." + "torrent")
chooser.add_filter(f0)
f1 = gtk.FileFilter()
f1.set_name(_("All files"))
f1.add_pattern("*")
loadpref = pref.Preferences()
chooser.set_current_folder(loadpref.get("default_load_path"))
chooser.add_filter(f1)
chooser.set_select_multiple(True)
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
chooser.set_property("skip-taskbar-hint", True)
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
chooser.set_property("skip-taskbar-hint", True)
response = chooser.run()
if response == gtk.RESPONSE_OK:
result = chooser.get_filenames()
loadpref.set("default_load_path", chooser.get_current_folder())
else:
result = None
chooser.destroy()
return result
response = chooser.run()
if response == gtk.RESPONSE_OK:
result = chooser.get_filenames()
loadpref.set("default_load_path", chooser.get_current_folder())
else:
result = None
chooser.destroy()
return result
def show_directory_chooser_dialog(parent=None, title=None):
if title is None:
title = _("Choose a download directory")
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
chooser.set_property("skip-taskbar-hint", True)
if chooser.run() == gtk.RESPONSE_OK:
result = chooser.get_filename()
else:
result = None
chooser.destroy()
return result
if title is None:
title = _("Choose a download directory")
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
chooser.set_property("skip-taskbar-hint", True)
if chooser.run() == gtk.RESPONSE_OK:
result = chooser.get_filename()
else:
result = None
chooser.destroy()
return result

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -34,42 +34,43 @@
# 0.80.0. I finally found a solution by reading the source code from the
# Listen project.
try:
import dbus, dbus.service
dbus_version = getattr(dbus, 'version', (0,0,0))
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
dbus.SessionBus()
import dbus.glib
elif dbus_version >= (0,80,0):
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
dbus.SessionBus()
else:
pass
import dbus
import dbus.service
dbus_version = getattr(dbus, 'version', (0,0,0))
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
dbus.SessionBus()
import dbus.glib
elif dbus_version >= (0,80,0):
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
dbus.SessionBus()
else:
pass
except: dbus_imported = False
else: dbus_imported = True
if dbus_imported:
class Manager(dbus.service.Object):
def __init__(self, interface, object_path='/org/deluge_torrent/DelugeObject'):
self.interface = interface
self.bus = dbus.SessionBus()
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus)
dbus.service.Object.__init__(self, bus_name, object_path)
class Manager(dbus.service.Object):
def __init__(self, interface, object_path='/org/deluge_torrent/DelugeObject'):
self.interface = interface
self.bus = dbus.SessionBus()
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus)
dbus.service.Object.__init__(self, bus_name, object_path)
## external_add_torrent should only be called from outside the class
@dbus.service.method('org.deluge_torrent.Deluge')
def external_add_torrent(self, torrent_file):
self.interface.external_add_torrent(torrent_file)
@dbus.service.method('org.deluge_torrent.Deluge')
def external_add_url(self, url):
self.interface.external_add_url(url)
## external_add_torrent should only be called from outside the class
@dbus.service.method('org.deluge_torrent.Deluge')
def external_add_torrent(self, torrent_file):
self.interface.external_add_torrent(torrent_file)
@dbus.service.method('org.deluge_torrent.Deluge')
def external_add_url(self, url):
self.interface.external_add_url(url)
else:
# This is a fallback class in case dbus is not available
class Manager:
def __init__(self, interface, object_path=None):
self.interface = interface
# This is a fallback class in case dbus is not available
class Manager:
def __init__(self, interface, object_path=None):
self.interface = interface
def external_add_torrent(self, torrent_file):
print "I can't do anything with this."
def external_add_url(self, url):
print "I can't do anything with this."
def external_add_torrent(self, torrent_file):
print "I can't do anything with this."
def external_add_url(self, url):
print "I can't do anything with this."

View File

@ -16,9 +16,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -30,85 +30,87 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import os, sys, imp
import os
import sys
import imp
class PluginManager:
def __init__(self, deluge_core, deluge_interface):
self.plugin_dirs = []
self.available_plugins = {}
self.enabled_plugins = {}
self.core = deluge_core
self.interface = deluge_interface
def __init__(self, deluge_core, deluge_interface):
self.plugin_dirs = []
self.available_plugins = {}
self.enabled_plugins = {}
self.core = deluge_core
self.interface = deluge_interface
def add_plugin_dir(self, directory):
self.plugin_dirs.append(directory)
sys.path.append(directory)
def add_plugin_dir(self, directory):
self.plugin_dirs.append(directory)
sys.path.append(directory)
# Scans all defined plugin dirs for Deluge plugins. The resulting
# module object is store with the defined name.
def scan_for_plugins(self):
for folder in self.plugin_dirs:
print "Scanning plugin dir",folder
for modname in os.listdir(folder):
path = folder+'/'+modname
if '__init__.py' in os.listdir(path):
# Import the found module. Note that the last
# parameter is important otherwise only the base
# modules (ie. 'plugins') is imported. This appears
# to be by design.
print "Loading module",modname
mod = __import__(modname, globals(), locals(), [''])
if 'deluge_init' in dir(mod):
print "Initialising plugin",modname
mod.deluge_init(path)
self.available_plugins[mod.plugin_name] = mod
# Scans all defined plugin dirs for Deluge plugins. The resulting
# module object is store with the defined name.
def scan_for_plugins(self):
for folder in self.plugin_dirs:
print "Scanning plugin dir",folder
for modname in os.listdir(folder):
path = folder+'/'+modname
if '__init__.py' in os.listdir(path):
# Import the found module. Note that the last
# parameter is important otherwise only the base
# modules (ie. 'plugins') is imported. This appears
# to be by design.
print "Loading module",modname
mod = __import__(modname, globals(), locals(), [''])
if 'deluge_init' in dir(mod):
print "Initialising plugin",modname
mod.deluge_init(path)
self.available_plugins[mod.plugin_name] = mod
def get_available_plugins(self):
return self.available_plugins.keys()
def get_available_plugins(self):
return self.available_plugins.keys()
def get_plugin(self, name):
return self.available_plugins[name]
def get_plugin(self, name):
return self.available_plugins[name]
def enable_plugin(self, name):
plugin = self.available_plugins[name]
self.enabled_plugins[name] = plugin.enable(self.core, self.interface)
def enable_plugin(self, name):
plugin = self.available_plugins[name]
self.enabled_plugins[name] = plugin.enable(self.core, self.interface)
def get_enabled_plugins(self):
return self.enabled_plugins.keys()
def get_enabled_plugins(self):
return self.enabled_plugins.keys()
def disable_plugin(self, name):
plugin = self.enabled_plugins[name]
if 'unload' in dir(plugin):
plugin.unload()
self.enabled_plugins.pop(name)
def disable_plugin(self, name):
plugin = self.enabled_plugins[name]
if 'unload' in dir(plugin):
plugin.unload()
self.enabled_plugins.pop(name)
def configurable_plugin(self, name):
if name in self.enabled_plugins:
return 'configure' in dir(self.enabled_plugins[name])
else:
return False
def configurable_plugin(self, name):
if name in self.enabled_plugins:
return 'configure' in dir(self.enabled_plugins[name])
else:
return False
def configure_plugin(self, name):
self.enabled_plugins[name].configure()
def configure_plugin(self, name):
self.enabled_plugins[name].configure()
def update_active_plugins(self):
for name in self.enabled_plugins.keys():
plugin = self.enabled_plugins[name]
if 'update' in dir(plugin):
plugin.update()
def update_active_plugins(self):
for name in self.enabled_plugins.keys():
plugin = self.enabled_plugins[name]
if 'update' in dir(plugin):
plugin.update()
def shutdown_all_plugins(self):
for name in self.enabled_plugins.keys():
self.disable_plugin(name)
self.enabled_plugins.clear()
def shutdown_all_plugins(self):
for name in self.enabled_plugins.keys():
self.disable_plugin(name)
self.enabled_plugins.clear()
## Few lines of code to test functionality
if __name__ == "__main__":
p = PluginManager()
p.add_plugin_dir("plugins/")
p.scan_for_plugins()
for x in p.plugins:
print x
for y in p.plugins[x]:
print "\t", y
p = PluginManager()
p.add_plugin_dir("plugins/")
p.scan_for_plugins()
for x in p.plugins:
print x
for y in p.plugins[x]:
print "\t", y

View File

@ -14,9 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
@ -38,141 +38,141 @@ import common
import os.path
DEFAULT_PREFS = {
"auto_end_seeding" : False,
"auto_seed_ratio" : 0,
"close_to_tray" : False,
"default_download_path" : "",
"default_load_path" : os.path.expanduser("~/"),
"enable_dht" : True,
"enable_system_tray" : True,
"enabled_plugins" : "",
"encin_state" : common.EncState.enabled,
"encout_state" : common.EncState.enabled,
"enclevel_type" : common.EncLevel.both,
"end_seed_ratio" : 0.0,
"gui_update_interval" : 1.0,
"listen_on" : [6881,6889],
"lock_tray" : False,
"max_active_torrents" : -1,
"max_connections" : 400,
"max_download_speed" : -1,
"max_download_speed_bps": -1,
"max_number_downloads" : -1,
"max_number_uploads" : -1,
"max_upload_speed" : -1,
"max_upload_speed_bps" : -1,
"max_uploads" : 2,
"pref_rc4" : True,
"proxy_type" : common.ProxyType.none,
"peer_proxy" : False,
"tracker_proxy" : False,
"dht_proxy" : False,
"proxy_hostname" : "",
"proxy_username" : "",
"proxy_password" : "",
"proxy_port": 8080,
"queue_seeds_to_bottom" : False,
"show_dl" : True,
"show_eta" : True,
"show_infopane" : True,
"show_peers" : True,
"show_seeders" : True,
"show_share" : True,
"show_size" : True,
"show_status" : True,
"show_toolbar" : True,
"show_ul" : True,
"tray_downloadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
"tray_passwd" : "",
"tray_uploadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
"use_compact_storage" : True,
"use_default_dir" : False,
"use_natpmp" : False,
"use_upnp" : False,
"use_utpex" : True,
"window_height" : 480,
"window_maximized" : False,
"window_pane_position" : -1,
"window_width" : 640,
"window_x_pos" : 0,
"window_y_pos" : 0,
"auto_end_seeding" : False,
"auto_seed_ratio" : 0,
"close_to_tray" : False,
"default_download_path" : "",
"default_load_path" : os.path.expanduser("~/"),
"enable_dht" : True,
"enable_system_tray" : True,
"enabled_plugins" : "",
"encin_state" : common.EncState.enabled,
"encout_state" : common.EncState.enabled,
"enclevel_type" : common.EncLevel.both,
"end_seed_ratio" : 0.0,
"gui_update_interval" : 1.0,
"listen_on" : [6881,6889],
"lock_tray" : False,
"max_active_torrents" : -1,
"max_connections" : 400,
"max_download_speed" : -1,
"max_download_speed_bps": -1,
"max_number_downloads" : -1,
"max_number_uploads" : -1,
"max_upload_speed" : -1,
"max_upload_speed_bps" : -1,
"max_uploads" : 2,
"pref_rc4" : True,
"proxy_type" : common.ProxyType.none,
"peer_proxy" : False,
"tracker_proxy" : False,
"dht_proxy" : False,
"proxy_hostname" : "",
"proxy_username" : "",
"proxy_password" : "",
"proxy_port": 8080,
"queue_seeds_to_bottom" : False,
"show_dl" : True,
"show_eta" : True,
"show_infopane" : True,
"show_peers" : True,
"show_seeders" : True,
"show_share" : True,
"show_size" : True,
"show_status" : True,
"show_toolbar" : True,
"show_ul" : True,
"tray_downloadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
"tray_passwd" : "",
"tray_uploadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
"use_compact_storage" : True,
"use_default_dir" : False,
"use_natpmp" : False,
"use_upnp" : False,
"use_utpex" : True,
"window_height" : 480,
"window_maximized" : False,
"window_pane_position" : -1,
"window_width" : 640,
"window_x_pos" : 0,
"window_y_pos" : 0,
}
class Preferences:
def __init__(self, filename=None, global_defaults=True, defaults=None):
self.mapping = {}
if defaults is not None:
for key in defaults.keys():
self.mapping.setdefault(key, defaults[key])
def __init__(self, filename=None, global_defaults=True, defaults=None):
self.mapping = {}
if defaults is not None:
for key in defaults.keys():
self.mapping.setdefault(key, defaults[key])
if global_defaults is True:
self.mapping = DEFAULT_PREFS
if global_defaults is True:
self.mapping = DEFAULT_PREFS
self.config_file = filename
if self.config_file is not None:
self.load(self.config_file)
self.config_file = filename
if self.config_file is not None:
self.load(self.config_file)
# Allows you to access an item in a Preferences objecy by calling
# instance[key] rather than instance.get(key). However, this will
# return the value as the type it is currently in memory, so it is
# advisable to use get() if you need the value converted.
def __getitem__(self, key):
return self.mapping[key]
# Allows you to access an item in a Preferences objecy by calling
# instance[key] rather than instance.get(key). However, this will
# return the value as the type it is currently in memory, so it is
# advisable to use get() if you need the value converted.
def __getitem__(self, key):
return self.mapping[key]
def __setitem__(self, key, value):
self.mapping[key] = value
def __setitem__(self, key, value):
self.mapping[key] = value
def __delitem__(self, key):
del self.mapping[key]
def __delitem__(self, key):
del self.mapping[key]
def __len__(self):
return len(self.mapping)
def __len__(self):
return len(self.mapping)
def has_key(self, key): return self.mapping.has_key(key)
def items(self): return self.mapping.items()
def keys(self): return self.mapping.keys()
def values(self): return self.mapping.values()
def has_key(self, key): return self.mapping.has_key(key)
def items(self): return self.mapping.items()
def keys(self): return self.mapping.keys()
def values(self): return self.mapping.values()
def save(self, filename=None):
if filename is None:
filename = self.config_file
try:
pkl_file = open(filename, 'wb')
pickle.dump(self.mapping, pkl_file)
pkl_file.close()
except IOError:
pass
def save(self, filename=None):
if filename is None:
filename = self.config_file
try:
pkl_file = open(filename, 'wb')
pickle.dump(self.mapping, pkl_file)
pkl_file.close()
except IOError:
pass
def load(self, filename=None):
if filename is None:
filename = self.config_file
try:
pkl_file = open(filename, 'rb')
self.dump = pickle.load(pkl_file)
self.mapping.update(self.dump)
pkl_file.close()
except IOError:
pass
except EOFError:
pkl_file.close()
pass
def load(self, filename=None):
if filename is None:
filename = self.config_file
try:
pkl_file = open(filename, 'rb')
self.dump = pickle.load(pkl_file)
self.mapping.update(self.dump)
pkl_file.close()
except IOError:
pass
except EOFError:
pkl_file.close()
pass
def set(self, key, value):
self.mapping[key] = value
def set(self, key, value):
self.mapping[key] = value
def get(self, key):
try:
value = self.mapping[key]
return value
except KeyError:
return None
def get(self, key):
try:
value = self.mapping[key]
return value
except KeyError:
return None
def remove(self, key):
self.mapping.pop(key)
def remove(self, key):
self.mapping.pop(key)
def clear(self):
self.mapping.clear()
def clear(self):
self.mapping.clear()
def printout(self):
for key in self.mapping.keys():
print key, ':', self.mapping[key]
def printout(self):
for key in self.mapping.keys():
print key, ':', self.mapping[key]