fixing imports and indents to comply with python style guide - first attempt, this might break things
This commit is contained in:
parent
6fd53ec356
commit
d27137b4e2
|
@ -0,0 +1 @@
|
||||||
|
|
120
src/common.py
120
src/common.py
|
@ -14,9 +14,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import sys, os, os.path, webbrowser
|
import sys
|
||||||
import xdg, xdg.BaseDirectory
|
import os
|
||||||
|
import os.path
|
||||||
|
import webbrowser
|
||||||
|
import xdg
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
|
||||||
import gettext
|
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')
|
PLUGIN_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'plugins')
|
||||||
|
|
||||||
def estimate_eta(state):
|
def estimate_eta(state):
|
||||||
try:
|
try:
|
||||||
return ftime(get_eta(state["total_size"], state["total_done"], state["download_rate"]))
|
return ftime(get_eta(state["total_size"], state["total_done"], state["download_rate"]))
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
return _("Infinity")
|
return _("Infinity")
|
||||||
|
|
||||||
def get_eta(size, done, speed):
|
def get_eta(size, done, speed):
|
||||||
if (size - done) == 0:
|
if (size - done) == 0:
|
||||||
raise ZeroDivisionError
|
raise ZeroDivisionError
|
||||||
return (size - done) / speed
|
return (size - done) / speed
|
||||||
|
|
||||||
# Returns formatted string describing filesize
|
# Returns formatted string describing filesize
|
||||||
# fsize_b should be in bytes
|
# fsize_b should be in bytes
|
||||||
# Returned value will be in either KB, MB, or GB
|
# Returned value will be in either KB, MB, or GB
|
||||||
def fsize(fsize_b):
|
def fsize(fsize_b):
|
||||||
fsize_kb = float (fsize_b / 1024.0)
|
fsize_kb = float (fsize_b / 1024.0)
|
||||||
if fsize_kb < 1000:
|
if fsize_kb < 1000:
|
||||||
return _("%.1f KiB")%fsize_kb
|
return _("%.1f KiB")%fsize_kb
|
||||||
fsize_mb = float (fsize_kb / 1024.0)
|
fsize_mb = float (fsize_kb / 1024.0)
|
||||||
if fsize_mb < 1000:
|
if fsize_mb < 1000:
|
||||||
return _("%.1f MiB")%fsize_mb
|
return _("%.1f MiB")%fsize_mb
|
||||||
fsize_gb = float (fsize_mb / 1024.0)
|
fsize_gb = float (fsize_mb / 1024.0)
|
||||||
return _("%.1f GiB")%fsize_gb
|
return _("%.1f GiB")%fsize_gb
|
||||||
|
|
||||||
# Returns a formatted string representing a percentage
|
# Returns a formatted string representing a percentage
|
||||||
def fpcnt(dec):
|
def fpcnt(dec):
|
||||||
return '%.2f%%'%(dec * 100)
|
return '%.2f%%'%(dec * 100)
|
||||||
|
|
||||||
# Returns a formatted string representing transfer speed
|
# Returns a formatted string representing transfer speed
|
||||||
def fspeed(bps):
|
def fspeed(bps):
|
||||||
return '%s/s'%(fsize(bps))
|
return '%s/s'%(fsize(bps))
|
||||||
|
|
||||||
def fseed(state):
|
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):
|
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):
|
def ftime(seconds):
|
||||||
if seconds < 60:
|
if seconds < 60:
|
||||||
return '%ds'%(seconds)
|
return '%ds'%(seconds)
|
||||||
minutes = int(seconds/60)
|
minutes = int(seconds/60)
|
||||||
seconds = seconds % 60
|
seconds = seconds % 60
|
||||||
if minutes < 60:
|
if minutes < 60:
|
||||||
return '%dm %ds'%(minutes, seconds)
|
return '%dm %ds'%(minutes, seconds)
|
||||||
hours = int(minutes/60)
|
hours = int(minutes/60)
|
||||||
minutes = minutes % 60
|
minutes = minutes % 60
|
||||||
if hours < 24:
|
if hours < 24:
|
||||||
return '%dh %dm'%(hours, minutes)
|
return '%dh %dm'%(hours, minutes)
|
||||||
days = int(hours/24)
|
days = int(hours/24)
|
||||||
hours = hours % 24
|
hours = hours % 24
|
||||||
if days < 7:
|
if days < 7:
|
||||||
return '%dd %dh'%(days, hours)
|
return '%dd %dh'%(days, hours)
|
||||||
weeks = int(days/7)
|
weeks = int(days/7)
|
||||||
days = days % 7
|
days = days % 7
|
||||||
if weeks < 10:
|
if weeks < 10:
|
||||||
return '%dw %dd'%(weeks, days)
|
return '%dw %dd'%(weeks, days)
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
|
|
||||||
def get_glade_file(fname):
|
def get_glade_file(fname):
|
||||||
return os.path.join(GLADE_DIR, fname)
|
return os.path.join(GLADE_DIR, fname)
|
||||||
|
|
||||||
def get_pixmap(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):
|
def open_url_in_browser(dialog, link):
|
||||||
try:
|
try:
|
||||||
webbrowser.open(link)
|
webbrowser.open(link)
|
||||||
except webbrowser.Error:
|
except webbrowser.Error:
|
||||||
print _("Error: no webbrowser found")
|
print _("Error: no webbrowser found")
|
||||||
|
|
||||||
# Encryption States
|
# Encryption States
|
||||||
class EncState:
|
class EncState:
|
||||||
forced, enabled, disabled = range(3)
|
forced, enabled, disabled = range(3)
|
||||||
|
|
||||||
class EncLevel:
|
class EncLevel:
|
||||||
plaintext, rc4, both = range(3)
|
plaintext, rc4, both = range(3)
|
||||||
|
|
||||||
class ProxyType:
|
class ProxyType:
|
||||||
none, socks4, socks5, socks5_pw, http, http_pw = range(6)
|
none, socks4, socks5, socks5_pw, http, http_pw = range(6)
|
||||||
|
|
1423
src/core.py
1423
src/core.py
File diff suppressed because it is too large
Load Diff
|
@ -113,8 +113,8 @@ typedef torrents_t::iterator torrents_t_iterator;
|
||||||
|
|
||||||
long M_unique_counter = 0;
|
long M_unique_counter = 0;
|
||||||
session_settings *M_settings = NULL;
|
session_settings *M_settings = NULL;
|
||||||
pe_settings *M_pe_settings = NULL;
|
pe_settings *M_pe_settings = NULL;
|
||||||
proxy_settings *M_proxy_settings = NULL;
|
proxy_settings *M_proxy_settings = NULL;
|
||||||
session *M_ses = NULL;
|
session *M_ses = NULL;
|
||||||
PyObject *M_constants = NULL;
|
PyObject *M_constants = NULL;
|
||||||
ip_filter *M_the_filter = 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++)
|
for (unsigned long i = 0; i < M_torrents->size(); i++)
|
||||||
if ((*M_torrents)[i].handle == handle)
|
if ((*M_torrents)[i].handle == handle)
|
||||||
{
|
{
|
||||||
// printf("Found: %li\r\n", i);
|
// printf("Found: %li\r\n", i);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ boost::filesystem::path const& save_path)
|
||||||
torrent_t new_torrent;
|
torrent_t new_torrent;
|
||||||
|
|
||||||
torrent_handle h = M_ses->add_torrent(t, save_path, resume_data, compact_mode, 16 * 1024);
|
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_max_uploads(-1);
|
||||||
h.set_ratio(preferred_ratio);
|
h.set_ratio(preferred_ratio);
|
||||||
new_torrent.handle = h;
|
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))
|
if (!PyArg_ParseTuple(args, "i", &arg))
|
||||||
return NULL;
|
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);
|
M_ses->set_download_rate_limit(arg);
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
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))
|
if (!PyArg_ParseTuple(args, "i", &arg))
|
||||||
return NULL;
|
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);
|
M_ses->set_upload_rate_limit(arg);
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
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))
|
if (!PyArg_ParseTuple(args, "i", &max_conn))
|
||||||
return NULL;
|
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);
|
M_ses->set_max_connections(max_conn);
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
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++) {
|
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}",
|
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(),
|
"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(),
|
"total_size", i.total_size(),
|
||||||
"piece_length", i.piece_length(),
|
"piece_length", i.piece_length(),
|
||||||
"num_pieces", i.num_pieces(),
|
"num_pieces", i.num_pieces(),
|
||||||
"total_peers", total_peers,
|
"total_peers", total_peers,
|
||||||
"total_seeds", total_seeds,
|
"total_seeds", total_seeds,
|
||||||
"is_paused", t.handle.is_paused(),
|
"is_paused", t.handle.is_paused(),
|
||||||
"is_seed", t.handle.is_seed(),
|
"is_seed", t.handle.is_seed(),
|
||||||
"total_done", s.total_done,
|
"total_done", s.total_done,
|
||||||
"total_wanted", s.total_wanted,
|
"total_wanted", s.total_wanted,
|
||||||
"total_wanted_done", s.total_wanted_done);
|
"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))
|
if (!PyArg_ParseTuple(args, "s", &DHT_path))
|
||||||
return NULL;
|
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::path tempPath(DHT_path, empty_name_check);
|
||||||
boost::filesystem::ifstream DHT_state_file(tempPath, std::ios_base::binary);
|
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),
|
DHT_state = bdecode(std::istream_iterator<char>(DHT_state_file),
|
||||||
std::istream_iterator<char>());
|
std::istream_iterator<char>());
|
||||||
M_ses->start_dht(DHT_state);
|
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!)
|
// // 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));
|
// printf("Number of DHT peers in recovered state: %ld\r\n", count_DHT_peers(DHT_state));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
|
@ -1074,7 +1074,7 @@ static PyObject *torrent_stop_DHT(PyObject *self, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "s", &DHT_path))
|
if (!PyArg_ParseTuple(args, "s", &DHT_path))
|
||||||
return NULL;
|
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);
|
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();
|
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);
|
boost::filesystem::ofstream out(tempPath, std::ios_base::binary);
|
||||||
out.unsetf(std::ios_base::skipws);
|
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)));
|
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");
|
entry *nodes = DHT_state.find_key("nodes");
|
||||||
if (!nodes)
|
if (!nodes)
|
||||||
return Py_BuildValue("l", -1); // No nodes - we are just starting up...
|
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);
|
return Py_BuildValue("l", 1);
|
||||||
} catch (std::exception& e)
|
} catch (std::exception& e)
|
||||||
{
|
{
|
||||||
// std::cerr << e.what() << "\n";
|
// std::cerr << e.what() << "\n";
|
||||||
// return Py_BuildValue("l", 0);
|
// return Py_BuildValue("l", 0);
|
||||||
RAISE_PTR(DelugeError, e.what());
|
RAISE_PTR(DelugeError, e.what());
|
||||||
return Py_BuildValue("l", 0);
|
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)
|
static PyObject *torrent_use_upnp(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
python_long action;
|
python_long action;
|
||||||
PyArg_ParseTuple(args, "i", &action);
|
PyArg_ParseTuple(args, "i", &action);
|
||||||
|
|
||||||
if (action){
|
if (action){
|
||||||
M_ses->start_upnp();
|
M_ses->start_upnp();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
M_ses->stop_upnp();
|
M_ses->stop_upnp();
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
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)
|
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){
|
if (action){
|
||||||
M_ses->start_natpmp();
|
M_ses->start_natpmp();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
M_ses->stop_natpmp();
|
M_ses->stop_natpmp();
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
Py_INCREF(Py_None); return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *torrent_use_utpex(PyObject *self, PyObject *args)
|
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){
|
if (action){
|
||||||
M_ses->add_extension(&libtorrent::create_ut_pex_plugin);
|
M_ses->add_extension(&libtorrent::create_ut_pex_plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None); return Py_None;
|
Py_INCREF(Py_None); return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *torrent_pe_settings(PyObject *self, PyObject *args)
|
static PyObject *torrent_pe_settings(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
M_pe_settings = new pe_settings();
|
M_pe_settings = new pe_settings();
|
||||||
libtorrent::pe_settings::enc_policy out, in, prefer;
|
libtorrent::pe_settings::enc_policy out, in, prefer;
|
||||||
libtorrent::pe_settings::enc_level level;
|
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->out_enc_policy = out;
|
||||||
M_pe_settings->in_enc_policy = in;
|
M_pe_settings->in_enc_policy = in;
|
||||||
M_pe_settings->allowed_enc_level = level;
|
M_pe_settings->allowed_enc_level = level;
|
||||||
M_pe_settings->prefer_rc4 = prefer;
|
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)
|
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)
|
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;
|
char *server, *login, *pasw;
|
||||||
int portnum;
|
int portnum;
|
||||||
libtorrent::proxy_settings::proxy_type proxytype;
|
libtorrent::proxy_settings::proxy_type proxytype;
|
||||||
bool peerproxy, trackerproxy, dhtproxy;
|
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->type = proxytype;
|
||||||
M_proxy_settings->username = login;
|
M_proxy_settings->username = login;
|
||||||
M_proxy_settings->password = pasw;
|
M_proxy_settings->password = pasw;
|
||||||
M_proxy_settings->hostname = server;
|
M_proxy_settings->hostname = server;
|
||||||
M_proxy_settings->port = portnum;
|
M_proxy_settings->port = portnum;
|
||||||
|
|
||||||
if (peerproxy) {
|
if (peerproxy) {
|
||||||
M_ses->set_peer_proxy(*M_proxy_settings);
|
M_ses->set_peer_proxy(*M_proxy_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackerproxy) {
|
if (trackerproxy) {
|
||||||
M_ses->set_tracker_proxy(*M_proxy_settings);
|
M_ses->set_tracker_proxy(*M_proxy_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dhtproxy) {
|
if (dhtproxy) {
|
||||||
M_ses->set_dht_proxy(*M_proxy_settings);
|
M_ses->set_dht_proxy(*M_proxy_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *torrent_get_trackers(PyObject *self, PyObject *args)
|
static PyObject *torrent_get_trackers(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
python_long unique_ID;
|
python_long unique_ID;
|
||||||
if (!PyArg_ParseTuple(args, "i", &unique_ID))
|
if (!PyArg_ParseTuple(args, "i", &unique_ID))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
long index = get_index_from_unique_ID(unique_ID);
|
long index = get_index_from_unique_ID(unique_ID);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
torrent_handle& h = M_torrents->at(index).handle;
|
torrent_handle& h = M_torrents->at(index).handle;
|
||||||
std::string trackerslist;
|
std::string trackerslist;
|
||||||
if (h.is_valid() && h.has_metadata())
|
if (h.is_valid() && h.has_metadata())
|
||||||
{
|
{
|
||||||
for (std::vector<announce_entry>::const_iterator i = h.trackers().begin();
|
for (std::vector<announce_entry>::const_iterator i = h.trackers().begin();
|
||||||
i != h.trackers().end(); ++i)
|
i != h.trackers().end(); ++i)
|
||||||
{
|
{
|
||||||
trackerslist = trackerslist + i->url +"\n";
|
trackerslist = trackerslist + i->url +"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Py_BuildValue("s",trackerslist.c_str());
|
return Py_BuildValue("s",trackerslist.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args)
|
static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args)
|
||||||
|
@ -1376,10 +1376,10 @@ static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args)
|
||||||
torrent_handle& h = M_torrents->at(index).handle;
|
torrent_handle& h = M_torrents->at(index).handle;
|
||||||
|
|
||||||
std::vector<libtorrent::announce_entry> trackerlist;
|
std::vector<libtorrent::announce_entry> trackerlist;
|
||||||
|
|
||||||
std::istringstream trackers(tracker);
|
std::istringstream trackers(tracker);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
while (std::getline(trackers, line)) {
|
while (std::getline(trackers, line)) {
|
||||||
libtorrent::announce_entry a_entry(line);
|
libtorrent::announce_entry a_entry(line);
|
||||||
trackerlist.push_back(a_entry);
|
trackerlist.push_back(a_entry);
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# Availability - how many complete copies are among our peers
|
||||||
def calc_availability(peer_info):
|
def calc_availability(peer_info):
|
||||||
if len(peer_info) == 0:
|
if len(peer_info) == 0:
|
||||||
return 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 peer in peer_info:
|
||||||
for piece in num_pieces:
|
for piece in num_pieces:
|
||||||
freqs[piece] = freqs[piece] + peer['pieces'][piece]
|
freqs[piece] = freqs[piece] + peer['pieces'][piece]
|
||||||
|
|
||||||
minimum = min(freqs)
|
minimum = min(freqs)
|
||||||
# frac = freqs.count(minimum + 1) # Does this mean something?
|
# frac = freqs.count(minimum + 1) # Does this mean something?
|
||||||
|
|
||||||
return minimum
|
return minimum
|
||||||
|
|
||||||
# Swarm speed - try to guess the speed of the entire swarm
|
# 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
|
# 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
|
# 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
|
# be too unreliable. But the client can smooth things out, if desired
|
||||||
def calc_swarm_speed(peer_info):
|
def calc_swarm_speed(peer_info):
|
||||||
if old_peer_info is not None:
|
if old_peer_info is not None:
|
||||||
new_pieces = 0
|
new_pieces = 0
|
||||||
peers_known = 0
|
peers_known = 0
|
||||||
|
|
||||||
# List new peers
|
# List new peers
|
||||||
new_peer_IPs = {} # ip->peerinfo dict (from the core)
|
new_peer_IPs = {} # ip->peerinfo dict (from the core)
|
||||||
for peer in peer_info:
|
for peer in peer_info:
|
||||||
new_peer_IPs[peer['ip']] = peer
|
new_peer_IPs[peer['ip']] = peer
|
||||||
|
|
||||||
for new_IP in new_peer_IPs.keys():
|
for new_IP in new_peer_IPs.keys():
|
||||||
if new_IP in old_peer_IPs.keys():
|
if new_IP in old_peer_IPs.keys():
|
||||||
# We know this peer from before, see what changed
|
# We know this peer from before, see what changed
|
||||||
peers_known = peers_known + 1
|
peers_known = peers_known + 1
|
||||||
delta = sum(new_peer_IPs[new_IP].pieces) - sum(old_peer_IPs[new_IP].pieces)
|
delta = sum(new_peer_IPs[new_IP].pieces) - sum(old_peer_IPs[new_IP].pieces)
|
||||||
|
|
||||||
if delta >= 0:
|
if delta >= 0:
|
||||||
new_pieces = new_pieces + delta
|
new_pieces = new_pieces + delta
|
||||||
else:
|
else:
|
||||||
print "Deluge.stat.calc_swarm_speed: Bad Delta: ", delta, old_peer_IPs[new_IP].pieces, new_peer_IPs[new_IP].pieces
|
print "Deluge.stat.calc_swarm_speed: Bad Delta: ", delta, old_peer_IPs[new_IP].pieces, new_peer_IPs[new_IP].pieces
|
||||||
|
|
||||||
# Calculate final value
|
# Calculate final value
|
||||||
time_delta = time.time() - old_peer_info_timestamp
|
time_delta = time.time() - old_peer_info_timestamp
|
||||||
ret = float(new_pieces)/( float(peers_known) * time_delta )
|
ret = float(new_pieces)/( float(peers_known) * time_delta )
|
||||||
|
|
||||||
# Save info
|
# Save info
|
||||||
old_peer_info = peer_info
|
old_peer_info = peer_info
|
||||||
old_peer_info_timestamp = time.time()
|
old_peer_info_timestamp = time.time()
|
||||||
old_peer_IPs = new_peer_IPs
|
old_peer_IPs = new_peer_IPs
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
160
src/dgtk.py
160
src/dgtk.py
|
@ -14,9 +14,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# This is a dummy tray object to allow Deluge to run on PyGTK < 2.9
|
||||||
class StupidTray:
|
class StupidTray:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def set_visible(self, value):
|
def set_visible(self, value):
|
||||||
pass
|
pass
|
||||||
def set_tooltip(self, value):
|
def set_tooltip(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## Cell data functions to pass to add_func_column()
|
## Cell data functions to pass to add_func_column()
|
||||||
|
|
||||||
def cell_data_speed(column, cell, model, iter, data):
|
def cell_data_speed(column, cell, model, iter, data):
|
||||||
speed = int(model.get_value(iter, data))
|
speed = int(model.get_value(iter, data))
|
||||||
speed_str = common.fspeed(speed)
|
speed_str = common.fspeed(speed)
|
||||||
cell.set_property('text', speed_str)
|
cell.set_property('text', speed_str)
|
||||||
|
|
||||||
## Functions to create columns
|
## Functions to create columns
|
||||||
|
|
||||||
def add_func_column(view, header, func, data, sortid=None):
|
def add_func_column(view, header, func, data, sortid=None):
|
||||||
column = gtk.TreeViewColumn(header)
|
column = gtk.TreeViewColumn(header)
|
||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column.pack_start(render, True)
|
column.pack_start(render, True)
|
||||||
column.set_cell_data_func(render, func, data)
|
column.set_cell_data_func(render, func, data)
|
||||||
if sortid is not None:
|
if sortid is not None:
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_sort_column_id(sortid)
|
column.set_sort_column_id(sortid)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if len(data) == 1:
|
if len(data) == 1:
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_sort_column_id(data[0])
|
column.set_sort_column_id(data[0])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_sort_column_id(data)
|
column.set_sort_column_id(data)
|
||||||
column.set_resizable(True)
|
column.set_resizable(True)
|
||||||
column.set_expand(False)
|
column.set_expand(False)
|
||||||
column.set_min_width(10)
|
column.set_min_width(10)
|
||||||
column.set_reorderable(True)
|
column.set_reorderable(True)
|
||||||
view.append_column(column)
|
view.append_column(column)
|
||||||
return column
|
return column
|
||||||
|
|
||||||
|
|
||||||
def add_text_column(view, header, cid):
|
def add_text_column(view, header, cid):
|
||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column = gtk.TreeViewColumn(header, render, text=cid)
|
column = gtk.TreeViewColumn(header, render, text=cid)
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_sort_column_id(cid)
|
column.set_sort_column_id(cid)
|
||||||
column.set_resizable(True)
|
column.set_resizable(True)
|
||||||
column.set_expand(False)
|
column.set_expand(False)
|
||||||
column.set_min_width(10)
|
column.set_min_width(10)
|
||||||
column.set_reorderable(True)
|
column.set_reorderable(True)
|
||||||
view.append_column(column)
|
view.append_column(column)
|
||||||
return column
|
return column
|
||||||
|
|
||||||
def add_progress_column(view, header, pid, mid):
|
def add_progress_column(view, header, pid, mid):
|
||||||
render = gtk.CellRendererProgress()
|
render = gtk.CellRendererProgress()
|
||||||
column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
|
column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_sort_column_id(pid)
|
column.set_sort_column_id(pid)
|
||||||
column.set_resizable(True)
|
column.set_resizable(True)
|
||||||
column.set_expand(False)
|
column.set_expand(False)
|
||||||
column.set_min_width(10)
|
column.set_min_width(10)
|
||||||
column.set_reorderable(True)
|
column.set_reorderable(True)
|
||||||
view.append_column(column)
|
view.append_column(column)
|
||||||
return column
|
return column
|
||||||
|
|
||||||
def add_toggle_column(view, header, cid, toggled_signal=None):
|
def add_toggle_column(view, header, cid, toggled_signal=None):
|
||||||
render = gtk.CellRendererToggle()
|
render = gtk.CellRendererToggle()
|
||||||
render.set_property('activatable', True)
|
render.set_property('activatable', True)
|
||||||
column = gtk.TreeViewColumn(header, render, active=cid)
|
column = gtk.TreeViewColumn(header, render, active=cid)
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_resizable(True)
|
column.set_resizable(True)
|
||||||
column.set_expand(False)
|
column.set_expand(False)
|
||||||
column.set_min_width(10)
|
column.set_min_width(10)
|
||||||
column.set_reorderable(True)
|
column.set_reorderable(True)
|
||||||
view.append_column(column)
|
view.append_column(column)
|
||||||
if toggled_signal is not None:
|
if toggled_signal is not None:
|
||||||
render.connect("toggled", toggled_signal)
|
render.connect("toggled", toggled_signal)
|
||||||
return column
|
return column
|
||||||
|
|
||||||
def add_texticon_column(view, header, icon_col, text_col):
|
def add_texticon_column(view, header, icon_col, text_col):
|
||||||
column = gtk.TreeViewColumn(header)
|
column = gtk.TreeViewColumn(header)
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
column.set_resizable(True)
|
column.set_resizable(True)
|
||||||
column.set_expand(False)
|
column.set_expand(False)
|
||||||
column.set_min_width(10)
|
column.set_min_width(10)
|
||||||
column.set_reorderable(True)
|
column.set_reorderable(True)
|
||||||
render = gtk.CellRendererPixbuf()
|
render = gtk.CellRendererPixbuf()
|
||||||
column.pack_start(render, expand=False)
|
column.pack_start(render, expand=False)
|
||||||
column.add_attribute(render, 'pixbuf', icon_col)
|
column.add_attribute(render, 'pixbuf', icon_col)
|
||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column.pack_start(render, expand=True)
|
column.pack_start(render, expand=True)
|
||||||
column.add_attribute(render, 'text', text_col)
|
column.add_attribute(render, 'text', text_col)
|
||||||
view.append_column(column)
|
view.append_column(column)
|
||||||
return column
|
return column
|
||||||
|
|
522
src/dialogs.py
522
src/dialogs.py
|
@ -14,9 +14,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import common, dgtk, pref
|
import common
|
||||||
import gtk, gtk.glade
|
import dgtk
|
||||||
import os, os.path
|
import pref
|
||||||
|
import gtk
|
||||||
|
import gtk.glade
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
PREFS_FILENAME = "prefs.state"
|
PREFS_FILENAME = "prefs.state"
|
||||||
|
|
||||||
class PreferencesDlg:
|
class PreferencesDlg:
|
||||||
def __init__(self, parent, preferences):
|
def __init__(self, parent, preferences):
|
||||||
self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge')
|
self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge')
|
||||||
self.dialog = self.glade.get_widget("pref_dialog")
|
self.dialog = self.glade.get_widget("pref_dialog")
|
||||||
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
||||||
self.glade.signal_autoconnect({
|
self.glade.signal_autoconnect({
|
||||||
'on_chk_use_tray_toggled': self.tray_toggle,
|
'on_chk_use_tray_toggled': self.tray_toggle,
|
||||||
'on_btn_testport_clicked': self.TestPort,
|
'on_btn_testport_clicked': self.TestPort,
|
||||||
})
|
})
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.preferences = preferences
|
self.preferences = preferences
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
# Load settings into dialog
|
# Load settings into dialog
|
||||||
try:
|
try:
|
||||||
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state"))
|
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_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_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("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_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_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_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_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_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_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_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_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_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("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_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_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_username").set_text(self.preferences.get("proxy_username"))
|
||||||
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password"))
|
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password"))
|
||||||
if(self.preferences.get("use_default_dir")):
|
if(self.preferences.get("use_default_dir")):
|
||||||
self.glade.get_widget("radio_save_all_to").set_active(True)
|
self.glade.get_widget("radio_save_all_to").set_active(True)
|
||||||
else:
|
else:
|
||||||
self.glade.get_widget("radio_ask_save").set_active(True)
|
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("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("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("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_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_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_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_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_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_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_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("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_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("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("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("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("spin_gui").set_value(self.preferences.get("gui_update_interval"))
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
# Now, show the dialog
|
# Now, show the dialog
|
||||||
self.dialog.show()
|
self.dialog.show()
|
||||||
r = self.dialog.run()
|
r = self.dialog.run()
|
||||||
self.dialog.hide()
|
self.dialog.hide()
|
||||||
# Now, get the settings from the dialog
|
# Now, get the settings from the dialog
|
||||||
if r == 1:
|
if r == 1:
|
||||||
self.preferences.set("encin_state", self.glade.get_widget("combo_encin").get_active())
|
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("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("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("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("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("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("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("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_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_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("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("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("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("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("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_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_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("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("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("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_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("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("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("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_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_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("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("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_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("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("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("enable_dht", self.glade.get_widget("chk_dht").get_active())
|
||||||
self.preferences.set("gui_update_interval", self.glade.get_widget("spin_gui").get_value())
|
self.preferences.set("gui_update_interval", self.glade.get_widget("spin_gui").get_value())
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def TestPort(self, widget):
|
def TestPort(self, widget):
|
||||||
activep = str(self.parent.manager.get_state()['port'])
|
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)
|
common.open_url_in_browser(self.dialog,'http://www.deluge-torrent.org/test-port.php?port=%s' %activep)
|
||||||
|
|
||||||
|
|
||||||
def tray_toggle(self, widget):
|
def tray_toggle(self, widget):
|
||||||
is_active = widget.get_active()
|
is_active = widget.get_active()
|
||||||
|
|
||||||
self.glade.get_widget("chk_min_on_close").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("chk_lock_tray").set_sensitive(is_active)
|
||||||
self.glade.get_widget("txt_tray_passwd").set_sensitive(is_active)
|
self.glade.get_widget("txt_tray_passwd").set_sensitive(is_active)
|
||||||
|
|
||||||
|
|
||||||
class PluginDlg:
|
class PluginDlg:
|
||||||
def __init__(self, parent, plugins):
|
def __init__(self, parent, plugins):
|
||||||
self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge')
|
self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge')
|
||||||
self.dialog = self.glade.get_widget("plugin_dialog")
|
self.dialog = self.glade.get_widget("plugin_dialog")
|
||||||
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
||||||
self.view = self.glade.get_widget("plugin_view")
|
self.view = self.glade.get_widget("plugin_view")
|
||||||
self.store = gtk.ListStore(str, bool)
|
self.store = gtk.ListStore(str, bool)
|
||||||
self.view.set_model(self.store)
|
self.view.set_model(self.store)
|
||||||
try:
|
try:
|
||||||
self.view.get_selection().set_select_function(self.plugin_clicked, full=True)
|
self.view.get_selection().set_select_function(self.plugin_clicked, full=True)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.view.get_selection().set_select_function(self.old_clicked)
|
self.view.get_selection().set_select_function(self.old_clicked)
|
||||||
name_col = dgtk.add_text_column(self.view, _("Plugin"), 0)
|
name_col = dgtk.add_text_column(self.view, _("Plugin"), 0)
|
||||||
name_col.set_expand(True)
|
name_col.set_expand(True)
|
||||||
dgtk.add_toggle_column(self.view, _("Enabled"), 1, toggled_signal=self.plugin_toggled)
|
dgtk.add_toggle_column(self.view, _("Enabled"), 1, toggled_signal=self.plugin_toggled)
|
||||||
self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref})
|
self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref})
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.plugins = plugins
|
self.plugins = plugins
|
||||||
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
self.store.clear()
|
self.store.clear()
|
||||||
for plugin in self.plugins.get_available_plugins():
|
for plugin in self.plugins.get_available_plugins():
|
||||||
#print plugin
|
#print plugin
|
||||||
if plugin in self.plugins.get_enabled_plugins():
|
if plugin in self.plugins.get_enabled_plugins():
|
||||||
self.store.append( (plugin, True) )
|
self.store.append( (plugin, True) )
|
||||||
else:
|
else:
|
||||||
self.store.append( (plugin, False) )
|
self.store.append( (plugin, False) )
|
||||||
self.glade.get_widget("plugin_text").get_buffer().set_text("")
|
self.glade.get_widget("plugin_text").get_buffer().set_text("")
|
||||||
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
||||||
self.dialog.show()
|
self.dialog.show()
|
||||||
self.dialog.run()
|
self.dialog.run()
|
||||||
self.dialog.hide()
|
self.dialog.hide()
|
||||||
|
|
||||||
def old_clicked(self, path):
|
def old_clicked(self, path):
|
||||||
return self.plugin_clicked(self.view.get_selection(), self.store, path, False)
|
return self.plugin_clicked(self.view.get_selection(), self.store, path, False)
|
||||||
|
|
||||||
def plugin_clicked(self, selection, model, path, is_selected):
|
def plugin_clicked(self, selection, model, path, is_selected):
|
||||||
if is_selected:
|
if is_selected:
|
||||||
return True
|
return True
|
||||||
name = model.get_value(model.get_iter(path), 0)
|
name = model.get_value(model.get_iter(path), 0)
|
||||||
plugin = self.plugins.get_plugin(name)
|
plugin = self.plugins.get_plugin(name)
|
||||||
author = plugin.plugin_author
|
author = plugin.plugin_author
|
||||||
version = plugin.plugin_version
|
version = plugin.plugin_version
|
||||||
description = plugin.plugin_description
|
description = plugin.plugin_description
|
||||||
if name in self.plugins.get_enabled_plugins():
|
if name in self.plugins.get_enabled_plugins():
|
||||||
config = self.plugins.configurable_plugin(name)
|
config = self.plugins.configurable_plugin(name)
|
||||||
self.glade.get_widget("plugin_conf").set_sensitive(config)
|
self.glade.get_widget("plugin_conf").set_sensitive(config)
|
||||||
else:
|
else:
|
||||||
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
||||||
self.glade.get_widget("plugin_text").get_buffer(
|
self.glade.get_widget("plugin_text").get_buffer(
|
||||||
).set_text("%s\nBy: %s\nVersion: %s\n\n%s"%
|
).set_text("%s\nBy: %s\nVersion: %s\n\n%s"%
|
||||||
(name, author, version, description))
|
(name, author, version, description))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def plugin_toggled(self, renderer, path):
|
def plugin_toggled(self, renderer, path):
|
||||||
plugin_iter = self.store.get_iter_from_string(path)
|
plugin_iter = self.store.get_iter_from_string(path)
|
||||||
plugin_name = self.store.get_value(plugin_iter, 0)
|
plugin_name = self.store.get_value(plugin_iter, 0)
|
||||||
plugin_value = not self.store.get_value(plugin_iter, 1)
|
plugin_value = not self.store.get_value(plugin_iter, 1)
|
||||||
self.store.set_value(plugin_iter, 1, plugin_value)
|
self.store.set_value(plugin_iter, 1, plugin_value)
|
||||||
if plugin_value:
|
if plugin_value:
|
||||||
config = self.plugins.configurable_plugin(plugin_name)
|
config = self.plugins.configurable_plugin(plugin_name)
|
||||||
self.glade.get_widget("plugin_conf").set_sensitive(config)
|
self.glade.get_widget("plugin_conf").set_sensitive(config)
|
||||||
self.plugins.enable_plugin(plugin_name)
|
self.plugins.enable_plugin(plugin_name)
|
||||||
else:
|
else:
|
||||||
self.plugins.disable_plugin(plugin_name)
|
self.plugins.disable_plugin(plugin_name)
|
||||||
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
self.glade.get_widget("plugin_conf").set_sensitive(False)
|
||||||
|
|
||||||
def plugin_pref(self, widget=None):
|
def plugin_pref(self, widget=None):
|
||||||
(model, plugin_iter) = self.view.get_selection().get_selected()
|
(model, plugin_iter) = self.view.get_selection().get_selected()
|
||||||
plugin_name = self.store.get_value(plugin_iter, 0)
|
plugin_name = self.store.get_value(plugin_iter, 0)
|
||||||
self.plugins.configure_plugin(plugin_name)
|
self.plugins.configure_plugin(plugin_name)
|
||||||
|
|
||||||
|
|
||||||
def show_about_dialog(parent=None):
|
def show_about_dialog(parent=None):
|
||||||
gtk.about_dialog_set_url_hook(common.open_url_in_browser)
|
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 = gtk.glade.XML(common.get_glade_file("aboutdialog.glade")).get_widget("aboutdialog")
|
||||||
abt.set_name(common.PROGRAM_NAME)
|
abt.set_name(common.PROGRAM_NAME)
|
||||||
abt.set_version(common.PROGRAM_VERSION)
|
abt.set_version(common.PROGRAM_VERSION)
|
||||||
abt.set_authors(["Zach Tibbitts", "Alon Zakai", "Marcos Pinto", "Andrew Resch"])
|
abt.set_authors(["Zach Tibbitts", "Alon Zakai", "Marcos Pinto", "Andrew Resch"])
|
||||||
abt.set_artists(["Andrew Wedderburn"])
|
abt.set_artists(["Andrew Wedderburn"])
|
||||||
abt.set_translator_credits(_("translator-credits"))
|
abt.set_translator_credits(_("translator-credits"))
|
||||||
abt.set_website("http://deluge-torrent.org")
|
abt.set_website("http://deluge-torrent.org")
|
||||||
abt.set_website_label("http://deluge-torrent.org")
|
abt.set_website_label("http://deluge-torrent.org")
|
||||||
abt.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
abt.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
||||||
abt.set_logo(gtk.gdk.pixbuf_new_from_file(
|
abt.set_logo(gtk.gdk.pixbuf_new_from_file(
|
||||||
common.get_pixmap("deluge-about.png")))
|
common.get_pixmap("deluge-about.png")))
|
||||||
abt.show_all()
|
abt.show_all()
|
||||||
abt.run()
|
abt.run()
|
||||||
abt.hide_all()
|
abt.hide_all()
|
||||||
|
|
||||||
def show_popup_warning(window, message):
|
def show_popup_warning(window, message):
|
||||||
warner = gtk.MessageDialog(parent = window,
|
warner = gtk.MessageDialog(parent = window,
|
||||||
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
buttons= gtk.BUTTONS_OK,
|
buttons= gtk.BUTTONS_OK,
|
||||||
message_format=message,
|
message_format=message,
|
||||||
type = gtk.MESSAGE_WARNING)
|
type = gtk.MESSAGE_WARNING)
|
||||||
warner.run()
|
warner.run()
|
||||||
warner.destroy()
|
warner.destroy()
|
||||||
|
|
||||||
def show_popup_question(window, message):
|
def show_popup_question(window, message):
|
||||||
asker = gtk.MessageDialog(parent = window,
|
asker = gtk.MessageDialog(parent = window,
|
||||||
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
buttons = gtk.BUTTONS_YES_NO,
|
buttons = gtk.BUTTONS_YES_NO,
|
||||||
message_format=message,
|
message_format=message,
|
||||||
type=gtk.MESSAGE_QUESTION)
|
type=gtk.MESSAGE_QUESTION)
|
||||||
result = asker.run()
|
result = asker.run()
|
||||||
asker.destroy()
|
asker.destroy()
|
||||||
if result == gtk.RESPONSE_YES:
|
if result == gtk.RESPONSE_YES:
|
||||||
return True
|
return True
|
||||||
elif result == gtk.RESPONSE_NO:
|
elif result == gtk.RESPONSE_NO:
|
||||||
return False
|
return False
|
||||||
elif result == gtk.RESPONSE_DELETE_EVENT:
|
elif result == gtk.RESPONSE_DELETE_EVENT:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
## Browse for .torrent files
|
## Browse for .torrent files
|
||||||
def show_file_open_dialog(parent=None, title=None):
|
def show_file_open_dialog(parent=None, title=None):
|
||||||
if title is None:
|
if title is None:
|
||||||
title = _("Choose a .torrent file")
|
title = _("Choose a .torrent file")
|
||||||
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_OPEN,
|
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||||
|
|
||||||
f0 = gtk.FileFilter()
|
f0 = gtk.FileFilter()
|
||||||
f0.set_name(_("Torrent files"))
|
f0.set_name(_("Torrent files"))
|
||||||
f0.add_pattern("*." + "torrent")
|
f0.add_pattern("*." + "torrent")
|
||||||
chooser.add_filter(f0)
|
chooser.add_filter(f0)
|
||||||
f1 = gtk.FileFilter()
|
f1 = gtk.FileFilter()
|
||||||
f1.set_name(_("All files"))
|
f1.set_name(_("All files"))
|
||||||
f1.add_pattern("*")
|
f1.add_pattern("*")
|
||||||
loadpref = pref.Preferences()
|
loadpref = pref.Preferences()
|
||||||
chooser.set_current_folder(loadpref.get("default_load_path"))
|
chooser.set_current_folder(loadpref.get("default_load_path"))
|
||||||
chooser.add_filter(f1)
|
chooser.add_filter(f1)
|
||||||
chooser.set_select_multiple(True)
|
chooser.set_select_multiple(True)
|
||||||
|
|
||||||
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
||||||
chooser.set_property("skip-taskbar-hint", True)
|
chooser.set_property("skip-taskbar-hint", True)
|
||||||
|
|
||||||
response = chooser.run()
|
response = chooser.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
result = chooser.get_filenames()
|
result = chooser.get_filenames()
|
||||||
loadpref.set("default_load_path", chooser.get_current_folder())
|
loadpref.set("default_load_path", chooser.get_current_folder())
|
||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
chooser.destroy()
|
chooser.destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def show_directory_chooser_dialog(parent=None, title=None):
|
def show_directory_chooser_dialog(parent=None, title=None):
|
||||||
if title is None:
|
if title is None:
|
||||||
title = _("Choose a download directory")
|
title = _("Choose a download directory")
|
||||||
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
|
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_icon_from_file(common.get_pixmap("deluge32.png"))
|
||||||
chooser.set_property("skip-taskbar-hint", True)
|
chooser.set_property("skip-taskbar-hint", True)
|
||||||
if chooser.run() == gtk.RESPONSE_OK:
|
if chooser.run() == gtk.RESPONSE_OK:
|
||||||
result = chooser.get_filename()
|
result = chooser.get_filename()
|
||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
chooser.destroy()
|
chooser.destroy()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
2628
src/interface.py
2628
src/interface.py
File diff suppressed because it is too large
Load Diff
|
@ -14,9 +14,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# 0.80.0. I finally found a solution by reading the source code from the
|
||||||
# Listen project.
|
# Listen project.
|
||||||
try:
|
try:
|
||||||
import dbus, dbus.service
|
import dbus
|
||||||
dbus_version = getattr(dbus, 'version', (0,0,0))
|
import dbus.service
|
||||||
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
dbus_version = getattr(dbus, 'version', (0,0,0))
|
||||||
dbus.SessionBus()
|
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
||||||
import dbus.glib
|
dbus.SessionBus()
|
||||||
elif dbus_version >= (0,80,0):
|
import dbus.glib
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
elif dbus_version >= (0,80,0):
|
||||||
DBusGMainLoop(set_as_default=True)
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
dbus.SessionBus()
|
DBusGMainLoop(set_as_default=True)
|
||||||
else:
|
dbus.SessionBus()
|
||||||
pass
|
else:
|
||||||
|
pass
|
||||||
except: dbus_imported = False
|
except: dbus_imported = False
|
||||||
else: dbus_imported = True
|
else: dbus_imported = True
|
||||||
|
|
||||||
if dbus_imported:
|
if dbus_imported:
|
||||||
class Manager(dbus.service.Object):
|
class Manager(dbus.service.Object):
|
||||||
def __init__(self, interface, object_path='/org/deluge_torrent/DelugeObject'):
|
def __init__(self, interface, object_path='/org/deluge_torrent/DelugeObject'):
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.bus = dbus.SessionBus()
|
self.bus = dbus.SessionBus()
|
||||||
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus)
|
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus)
|
||||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||||
|
|
||||||
## external_add_torrent should only be called from outside the class
|
## external_add_torrent should only be called from outside the class
|
||||||
@dbus.service.method('org.deluge_torrent.Deluge')
|
@dbus.service.method('org.deluge_torrent.Deluge')
|
||||||
def external_add_torrent(self, torrent_file):
|
def external_add_torrent(self, torrent_file):
|
||||||
self.interface.external_add_torrent(torrent_file)
|
self.interface.external_add_torrent(torrent_file)
|
||||||
@dbus.service.method('org.deluge_torrent.Deluge')
|
@dbus.service.method('org.deluge_torrent.Deluge')
|
||||||
def external_add_url(self, url):
|
def external_add_url(self, url):
|
||||||
self.interface.external_add_url(url)
|
self.interface.external_add_url(url)
|
||||||
else:
|
else:
|
||||||
# This is a fallback class in case dbus is not available
|
# This is a fallback class in case dbus is not available
|
||||||
class Manager:
|
class Manager:
|
||||||
def __init__(self, interface, object_path=None):
|
def __init__(self, interface, object_path=None):
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
|
|
||||||
def external_add_torrent(self, torrent_file):
|
def external_add_torrent(self, torrent_file):
|
||||||
print "I can't do anything with this."
|
print "I can't do anything with this."
|
||||||
def external_add_url(self, url):
|
def external_add_url(self, url):
|
||||||
print "I can't do anything with this."
|
print "I can't do anything with this."
|
||||||
|
|
156
src/plugins.py
156
src/plugins.py
|
@ -16,9 +16,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# 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
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# 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:
|
class PluginManager:
|
||||||
def __init__(self, deluge_core, deluge_interface):
|
def __init__(self, deluge_core, deluge_interface):
|
||||||
self.plugin_dirs = []
|
self.plugin_dirs = []
|
||||||
self.available_plugins = {}
|
self.available_plugins = {}
|
||||||
self.enabled_plugins = {}
|
self.enabled_plugins = {}
|
||||||
self.core = deluge_core
|
self.core = deluge_core
|
||||||
self.interface = deluge_interface
|
self.interface = deluge_interface
|
||||||
|
|
||||||
def add_plugin_dir(self, directory):
|
def add_plugin_dir(self, directory):
|
||||||
self.plugin_dirs.append(directory)
|
self.plugin_dirs.append(directory)
|
||||||
sys.path.append(directory)
|
sys.path.append(directory)
|
||||||
|
|
||||||
# Scans all defined plugin dirs for Deluge plugins. The resulting
|
# Scans all defined plugin dirs for Deluge plugins. The resulting
|
||||||
# module object is store with the defined name.
|
# module object is store with the defined name.
|
||||||
def scan_for_plugins(self):
|
def scan_for_plugins(self):
|
||||||
for folder in self.plugin_dirs:
|
for folder in self.plugin_dirs:
|
||||||
print "Scanning plugin dir",folder
|
print "Scanning plugin dir",folder
|
||||||
for modname in os.listdir(folder):
|
for modname in os.listdir(folder):
|
||||||
path = folder+'/'+modname
|
path = folder+'/'+modname
|
||||||
if '__init__.py' in os.listdir(path):
|
if '__init__.py' in os.listdir(path):
|
||||||
# Import the found module. Note that the last
|
# Import the found module. Note that the last
|
||||||
# parameter is important otherwise only the base
|
# parameter is important otherwise only the base
|
||||||
# modules (ie. 'plugins') is imported. This appears
|
# modules (ie. 'plugins') is imported. This appears
|
||||||
# to be by design.
|
# to be by design.
|
||||||
print "Loading module",modname
|
print "Loading module",modname
|
||||||
mod = __import__(modname, globals(), locals(), [''])
|
mod = __import__(modname, globals(), locals(), [''])
|
||||||
if 'deluge_init' in dir(mod):
|
if 'deluge_init' in dir(mod):
|
||||||
print "Initialising plugin",modname
|
print "Initialising plugin",modname
|
||||||
mod.deluge_init(path)
|
mod.deluge_init(path)
|
||||||
self.available_plugins[mod.plugin_name] = mod
|
self.available_plugins[mod.plugin_name] = mod
|
||||||
|
|
||||||
def get_available_plugins(self):
|
def get_available_plugins(self):
|
||||||
return self.available_plugins.keys()
|
return self.available_plugins.keys()
|
||||||
|
|
||||||
def get_plugin(self, name):
|
def get_plugin(self, name):
|
||||||
return self.available_plugins[name]
|
return self.available_plugins[name]
|
||||||
|
|
||||||
def enable_plugin(self, name):
|
def enable_plugin(self, name):
|
||||||
plugin = self.available_plugins[name]
|
plugin = self.available_plugins[name]
|
||||||
self.enabled_plugins[name] = plugin.enable(self.core, self.interface)
|
self.enabled_plugins[name] = plugin.enable(self.core, self.interface)
|
||||||
|
|
||||||
def get_enabled_plugins(self):
|
def get_enabled_plugins(self):
|
||||||
return self.enabled_plugins.keys()
|
return self.enabled_plugins.keys()
|
||||||
|
|
||||||
def disable_plugin(self, name):
|
def disable_plugin(self, name):
|
||||||
plugin = self.enabled_plugins[name]
|
plugin = self.enabled_plugins[name]
|
||||||
if 'unload' in dir(plugin):
|
if 'unload' in dir(plugin):
|
||||||
plugin.unload()
|
plugin.unload()
|
||||||
self.enabled_plugins.pop(name)
|
self.enabled_plugins.pop(name)
|
||||||
|
|
||||||
def configurable_plugin(self, name):
|
def configurable_plugin(self, name):
|
||||||
if name in self.enabled_plugins:
|
if name in self.enabled_plugins:
|
||||||
return 'configure' in dir(self.enabled_plugins[name])
|
return 'configure' in dir(self.enabled_plugins[name])
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def configure_plugin(self, name):
|
def configure_plugin(self, name):
|
||||||
self.enabled_plugins[name].configure()
|
self.enabled_plugins[name].configure()
|
||||||
|
|
||||||
def update_active_plugins(self):
|
def update_active_plugins(self):
|
||||||
for name in self.enabled_plugins.keys():
|
for name in self.enabled_plugins.keys():
|
||||||
plugin = self.enabled_plugins[name]
|
plugin = self.enabled_plugins[name]
|
||||||
if 'update' in dir(plugin):
|
if 'update' in dir(plugin):
|
||||||
plugin.update()
|
plugin.update()
|
||||||
|
|
||||||
def shutdown_all_plugins(self):
|
def shutdown_all_plugins(self):
|
||||||
for name in self.enabled_plugins.keys():
|
for name in self.enabled_plugins.keys():
|
||||||
self.disable_plugin(name)
|
self.disable_plugin(name)
|
||||||
self.enabled_plugins.clear()
|
self.enabled_plugins.clear()
|
||||||
|
|
||||||
|
|
||||||
## Few lines of code to test functionality
|
## Few lines of code to test functionality
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = PluginManager()
|
p = PluginManager()
|
||||||
p.add_plugin_dir("plugins/")
|
p.add_plugin_dir("plugins/")
|
||||||
p.scan_for_plugins()
|
p.scan_for_plugins()
|
||||||
for x in p.plugins:
|
for x in p.plugins:
|
||||||
print x
|
print x
|
||||||
for y in p.plugins[x]:
|
for y in p.plugins[x]:
|
||||||
print "\t", y
|
print "\t", y
|
||||||
|
|
276
src/pref.py
276
src/pref.py
|
@ -14,9 +14,9 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, write to:
|
# along with this program. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# In addition, as a special exception, the copyright holders give
|
# In addition, as a special exception, the copyright holders give
|
||||||
# permission to link the code of portions of this program with the OpenSSL
|
# permission to link the code of portions of this program with the OpenSSL
|
||||||
|
@ -38,141 +38,141 @@ import common
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
"auto_end_seeding" : False,
|
"auto_end_seeding" : False,
|
||||||
"auto_seed_ratio" : 0,
|
"auto_seed_ratio" : 0,
|
||||||
"close_to_tray" : False,
|
"close_to_tray" : False,
|
||||||
"default_download_path" : "",
|
"default_download_path" : "",
|
||||||
"default_load_path" : os.path.expanduser("~/"),
|
"default_load_path" : os.path.expanduser("~/"),
|
||||||
"enable_dht" : True,
|
"enable_dht" : True,
|
||||||
"enable_system_tray" : True,
|
"enable_system_tray" : True,
|
||||||
"enabled_plugins" : "",
|
"enabled_plugins" : "",
|
||||||
"encin_state" : common.EncState.enabled,
|
"encin_state" : common.EncState.enabled,
|
||||||
"encout_state" : common.EncState.enabled,
|
"encout_state" : common.EncState.enabled,
|
||||||
"enclevel_type" : common.EncLevel.both,
|
"enclevel_type" : common.EncLevel.both,
|
||||||
"end_seed_ratio" : 0.0,
|
"end_seed_ratio" : 0.0,
|
||||||
"gui_update_interval" : 1.0,
|
"gui_update_interval" : 1.0,
|
||||||
"listen_on" : [6881,6889],
|
"listen_on" : [6881,6889],
|
||||||
"lock_tray" : False,
|
"lock_tray" : False,
|
||||||
"max_active_torrents" : -1,
|
"max_active_torrents" : -1,
|
||||||
"max_connections" : 400,
|
"max_connections" : 400,
|
||||||
"max_download_speed" : -1,
|
"max_download_speed" : -1,
|
||||||
"max_download_speed_bps": -1,
|
"max_download_speed_bps": -1,
|
||||||
"max_number_downloads" : -1,
|
"max_number_downloads" : -1,
|
||||||
"max_number_uploads" : -1,
|
"max_number_uploads" : -1,
|
||||||
"max_upload_speed" : -1,
|
"max_upload_speed" : -1,
|
||||||
"max_upload_speed_bps" : -1,
|
"max_upload_speed_bps" : -1,
|
||||||
"max_uploads" : 2,
|
"max_uploads" : 2,
|
||||||
"pref_rc4" : True,
|
"pref_rc4" : True,
|
||||||
"proxy_type" : common.ProxyType.none,
|
"proxy_type" : common.ProxyType.none,
|
||||||
"peer_proxy" : False,
|
"peer_proxy" : False,
|
||||||
"tracker_proxy" : False,
|
"tracker_proxy" : False,
|
||||||
"dht_proxy" : False,
|
"dht_proxy" : False,
|
||||||
"proxy_hostname" : "",
|
"proxy_hostname" : "",
|
||||||
"proxy_username" : "",
|
"proxy_username" : "",
|
||||||
"proxy_password" : "",
|
"proxy_password" : "",
|
||||||
"proxy_port": 8080,
|
"proxy_port": 8080,
|
||||||
"queue_seeds_to_bottom" : False,
|
"queue_seeds_to_bottom" : False,
|
||||||
"show_dl" : True,
|
"show_dl" : True,
|
||||||
"show_eta" : True,
|
"show_eta" : True,
|
||||||
"show_infopane" : True,
|
"show_infopane" : True,
|
||||||
"show_peers" : True,
|
"show_peers" : True,
|
||||||
"show_seeders" : True,
|
"show_seeders" : True,
|
||||||
"show_share" : True,
|
"show_share" : True,
|
||||||
"show_size" : True,
|
"show_size" : True,
|
||||||
"show_status" : True,
|
"show_status" : True,
|
||||||
"show_toolbar" : True,
|
"show_toolbar" : True,
|
||||||
"show_ul" : True,
|
"show_ul" : True,
|
||||||
"tray_downloadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
|
"tray_downloadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
|
||||||
"tray_passwd" : "",
|
"tray_passwd" : "",
|
||||||
"tray_uploadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
|
"tray_uploadspeedlist" : [5.0, 10.0, 30.0, 80.0, 300.0],
|
||||||
"use_compact_storage" : True,
|
"use_compact_storage" : True,
|
||||||
"use_default_dir" : False,
|
"use_default_dir" : False,
|
||||||
"use_natpmp" : False,
|
"use_natpmp" : False,
|
||||||
"use_upnp" : False,
|
"use_upnp" : False,
|
||||||
"use_utpex" : True,
|
"use_utpex" : True,
|
||||||
"window_height" : 480,
|
"window_height" : 480,
|
||||||
"window_maximized" : False,
|
"window_maximized" : False,
|
||||||
"window_pane_position" : -1,
|
"window_pane_position" : -1,
|
||||||
"window_width" : 640,
|
"window_width" : 640,
|
||||||
"window_x_pos" : 0,
|
"window_x_pos" : 0,
|
||||||
"window_y_pos" : 0,
|
"window_y_pos" : 0,
|
||||||
}
|
}
|
||||||
class Preferences:
|
class Preferences:
|
||||||
def __init__(self, filename=None, global_defaults=True, defaults=None):
|
def __init__(self, filename=None, global_defaults=True, defaults=None):
|
||||||
self.mapping = {}
|
self.mapping = {}
|
||||||
if defaults is not None:
|
if defaults is not None:
|
||||||
for key in defaults.keys():
|
for key in defaults.keys():
|
||||||
self.mapping.setdefault(key, defaults[key])
|
self.mapping.setdefault(key, defaults[key])
|
||||||
|
|
||||||
if global_defaults is True:
|
if global_defaults is True:
|
||||||
self.mapping = DEFAULT_PREFS
|
self.mapping = DEFAULT_PREFS
|
||||||
|
|
||||||
self.config_file = filename
|
self.config_file = filename
|
||||||
if self.config_file is not None:
|
if self.config_file is not None:
|
||||||
self.load(self.config_file)
|
self.load(self.config_file)
|
||||||
|
|
||||||
# Allows you to access an item in a Preferences objecy by calling
|
# Allows you to access an item in a Preferences objecy by calling
|
||||||
# instance[key] rather than instance.get(key). However, this will
|
# instance[key] rather than instance.get(key). However, this will
|
||||||
# return the value as the type it is currently in memory, so it is
|
# return the value as the type it is currently in memory, so it is
|
||||||
# advisable to use get() if you need the value converted.
|
# advisable to use get() if you need the value converted.
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self.mapping[key]
|
return self.mapping[key]
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
self.mapping[key] = value
|
self.mapping[key] = value
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
del self.mapping[key]
|
del self.mapping[key]
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.mapping)
|
return len(self.mapping)
|
||||||
|
|
||||||
def has_key(self, key): return self.mapping.has_key(key)
|
def has_key(self, key): return self.mapping.has_key(key)
|
||||||
def items(self): return self.mapping.items()
|
def items(self): return self.mapping.items()
|
||||||
def keys(self): return self.mapping.keys()
|
def keys(self): return self.mapping.keys()
|
||||||
def values(self): return self.mapping.values()
|
def values(self): return self.mapping.values()
|
||||||
|
|
||||||
def save(self, filename=None):
|
def save(self, filename=None):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
filename = self.config_file
|
filename = self.config_file
|
||||||
try:
|
try:
|
||||||
pkl_file = open(filename, 'wb')
|
pkl_file = open(filename, 'wb')
|
||||||
pickle.dump(self.mapping, pkl_file)
|
pickle.dump(self.mapping, pkl_file)
|
||||||
pkl_file.close()
|
pkl_file.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def load(self, filename=None):
|
def load(self, filename=None):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
filename = self.config_file
|
filename = self.config_file
|
||||||
try:
|
try:
|
||||||
pkl_file = open(filename, 'rb')
|
pkl_file = open(filename, 'rb')
|
||||||
self.dump = pickle.load(pkl_file)
|
self.dump = pickle.load(pkl_file)
|
||||||
self.mapping.update(self.dump)
|
self.mapping.update(self.dump)
|
||||||
pkl_file.close()
|
pkl_file.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
except EOFError:
|
except EOFError:
|
||||||
pkl_file.close()
|
pkl_file.close()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
self.mapping[key] = value
|
self.mapping[key] = value
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
try:
|
try:
|
||||||
value = self.mapping[key]
|
value = self.mapping[key]
|
||||||
return value
|
return value
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def remove(self, key):
|
def remove(self, key):
|
||||||
self.mapping.pop(key)
|
self.mapping.pop(key)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.mapping.clear()
|
self.mapping.clear()
|
||||||
|
|
||||||
def printout(self):
|
def printout(self):
|
||||||
for key in self.mapping.keys():
|
for key in self.mapping.keys():
|
||||||
print key, ':', self.mapping[key]
|
print key, ':', self.mapping[key]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue