remembers configuration in the UI and fixes a cancellation bug - tarka
This commit is contained in:
parent
3091a6943f
commit
8649b4b973
|
@ -30,11 +30,11 @@ from text import TextReader, GZMuleReader, PGZip
|
||||||
from ui import GTKConfig, GTKProgress
|
from ui import GTKConfig, GTKProgress
|
||||||
|
|
||||||
# List of formats supported. This is used to generate the UI list and
|
# List of formats supported. This is used to generate the UI list and
|
||||||
# specify the reader class
|
# specify the reader class. The last entry is for storage by the UI.
|
||||||
readers = {'p2bgz':("PeerGuardian P2B (GZip)", PGReader),
|
readers = {'p2bgz':["PeerGuardian P2B (GZip)", PGReader, None],
|
||||||
'pgtext':("PeerGuardian Text (Uncompressed)", TextReader),
|
'pgtext':["PeerGuardian Text (Uncompressed)", TextReader, None],
|
||||||
'gzmule':("Emule IP list (GZip)", GZMuleReader),
|
'gzmule':["Emule IP list (GZip)", GZMuleReader, None],
|
||||||
'spzip':("SafePeer Text (Zipped)", PGZip)}
|
'spzip':["SafePeer Text (Zipped)", PGZip, None]}
|
||||||
|
|
||||||
class BlocklistImport:
|
class BlocklistImport:
|
||||||
|
|
||||||
|
@ -44,9 +44,10 @@ class BlocklistImport:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.core = core
|
self.core = core
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
|
self.cancelled = False
|
||||||
|
|
||||||
self.gtkconf = GTKConfig(self)
|
self.gtkconf = GTKConfig(self)
|
||||||
self.gtkprog = GTKProgress(self)
|
self.gtkprog = GTKProgress(self)
|
||||||
self.cancelled = False
|
|
||||||
self.nimported = 0
|
self.nimported = 0
|
||||||
|
|
||||||
self.blockfile = deluge.common.CONFIG_DIR + "/blocklist.cache"
|
self.blockfile = deluge.common.CONFIG_DIR + "/blocklist.cache"
|
||||||
|
@ -74,9 +75,9 @@ class BlocklistImport:
|
||||||
print "Fetching",self.config.get('url')
|
print "Fetching",self.config.get('url')
|
||||||
self.gtkprog.start_download()
|
self.gtkprog.start_download()
|
||||||
try:
|
try:
|
||||||
filename, headers = urllib.urlretrieve(self.config.get('url'),
|
filename, headers = urllib.urlretrieve(self.config.get('url'),
|
||||||
filename=self.blockfile,
|
filename=self.blockfile,
|
||||||
reporthook=self._download_update)
|
reporthook=self._download_update)
|
||||||
except IOError, (errno, strerr):
|
except IOError, (errno, strerr):
|
||||||
err = ui.GTKError("Couldn't download URL: %s"%strerr)
|
err = ui.GTKError("Couldn't download URL: %s"%strerr)
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
|
@ -89,7 +90,7 @@ class BlocklistImport:
|
||||||
print "importing with",ltype
|
print "importing with",ltype
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reader = readers[ltype][1](self.blockfile)
|
reader = readers[ltype][1](self.blockfile)
|
||||||
except IOError, (errno, strerr):
|
except IOError, (errno, strerr):
|
||||||
err = ui.GTKError("Couldn't open blocklist file: %s"%strerr)
|
err = ui.GTKError("Couldn't open blocklist file: %s"%strerr)
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
|
@ -118,12 +119,15 @@ class BlocklistImport:
|
||||||
reader.close()
|
reader.close()
|
||||||
self.nimported = curr
|
self.nimported = curr
|
||||||
self.gtkprog.end_import()
|
self.gtkprog.end_import()
|
||||||
print "Import complete"
|
print "Import finished"
|
||||||
|
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
|
self.cancelled = False
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
self.gtkconf.start()
|
self.gtkconf.start(self.config.get('listtype'),
|
||||||
|
self.config.get('url'),
|
||||||
|
self.config.get('load_on_start'))
|
||||||
|
|
||||||
def setconfig(self, url, load_on_start, listtype):
|
def setconfig(self, url, load_on_start, listtype):
|
||||||
self.config.set('url', url)
|
self.config.set('url', url)
|
||||||
|
|
|
@ -13,6 +13,8 @@ class GTKConfig(gtk.Dialog):
|
||||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
||||||
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
||||||
|
|
||||||
|
self.plugin = plugin
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
self.set_border_width(12)
|
self.set_border_width(12)
|
||||||
self.vbox.set_spacing(6)
|
self.vbox.set_spacing(6)
|
||||||
|
@ -25,7 +27,8 @@ class GTKConfig(gtk.Dialog):
|
||||||
ls = gtk.ListStore(gobject.TYPE_STRING, # Long name
|
ls = gtk.ListStore(gobject.TYPE_STRING, # Long name
|
||||||
gobject.TYPE_STRING) # Short name
|
gobject.TYPE_STRING) # Short name
|
||||||
for k in BlocklistImport.readers.keys():
|
for k in BlocklistImport.readers.keys():
|
||||||
ls.append([BlocklistImport.readers[k][0], k])
|
i = ls.append([BlocklistImport.readers[k][0], k])
|
||||||
|
BlocklistImport.readers[k][2] = ls.get_path(i)
|
||||||
|
|
||||||
cell = gtk.CellRendererText()
|
cell = gtk.CellRendererText()
|
||||||
cell.set_property('xpad', 5) # padding for status text
|
cell.set_property('xpad', 5) # padding for status text
|
||||||
|
@ -51,8 +54,6 @@ class GTKConfig(gtk.Dialog):
|
||||||
|
|
||||||
self.hide_all()
|
self.hide_all()
|
||||||
|
|
||||||
self.plugin = plugin
|
|
||||||
|
|
||||||
|
|
||||||
def ok(self, dialog, response):
|
def ok(self, dialog, response):
|
||||||
self.hide_all()
|
self.hide_all()
|
||||||
|
@ -72,7 +73,18 @@ class GTKConfig(gtk.Dialog):
|
||||||
def cancel(self, dialog):
|
def cancel(self, dialog):
|
||||||
self.hide_all()
|
self.hide_all()
|
||||||
|
|
||||||
def start(self):
|
def start(self, ltype, url, load):
|
||||||
|
if ltype:
|
||||||
|
path = BlocklistImport.readers[ltype][2]
|
||||||
|
i = self.listtype.get_model().get_iter(path)
|
||||||
|
self.listtype.set_active_iter(i)
|
||||||
|
|
||||||
|
if url:
|
||||||
|
self.url.set_text(url)
|
||||||
|
|
||||||
|
if load:
|
||||||
|
self.load_on_start.set_active(load)
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,6 +113,7 @@ class GTKProgress(gtk.Dialog):
|
||||||
|
|
||||||
def start_download(self):
|
def start_download(self):
|
||||||
self.progress.set_text("Downloading")
|
self.progress.set_text("Downloading")
|
||||||
|
self.progress.set_fraction(0.0)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def download_prog(self, fract):
|
def download_prog(self, fract):
|
||||||
|
@ -111,6 +124,7 @@ class GTKProgress(gtk.Dialog):
|
||||||
|
|
||||||
def start_import(self):
|
def start_import(self):
|
||||||
self.progress.set_text("Importing")
|
self.progress.set_text("Importing")
|
||||||
|
self.progress.set_fraction(0.0)
|
||||||
self.progress.set_pulse_step(0.0075)
|
self.progress.set_pulse_step(0.0075)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue