2007-06-17 04:59:24 +00:00
|
|
|
##
|
|
|
|
# Copyright 2007 Steve 'Tarka' Smith (tarka@internode.on.net)
|
|
|
|
# Distributed under the same terms as Deluge
|
|
|
|
##
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-06-17 04:59:24 +00:00
|
|
|
import gobject, gtk
|
|
|
|
import BlocklistImport
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
class GTKConfig(gtk.Dialog):
|
|
|
|
def __init__(self, plugin):
|
|
|
|
gtk.Dialog.__init__(self, title="Blocklist Config",
|
2007-08-09 03:55:56 +00:00
|
|
|
parent=None,
|
2007-06-12 08:13:16 +00:00
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
2007-08-06 00:40:18 +00:00
|
|
|
self.set_property("skip-taskbar-hint", True)
|
|
|
|
self.set_property("skip-pager-hint", True)
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-06-26 04:31:55 +00:00
|
|
|
self.plugin = plugin
|
2007-06-12 08:13:16 +00:00
|
|
|
# Setup
|
|
|
|
self.set_border_width(12)
|
|
|
|
self.vbox.set_spacing(6)
|
|
|
|
|
|
|
|
# List source
|
|
|
|
label = gtk.Label()
|
2007-07-20 22:08:48 +00:00
|
|
|
label.set_markup('<b>' + _("Blocklist URL") + '</b>')
|
2007-06-12 08:13:16 +00:00
|
|
|
self.url = gtk.Entry()
|
2007-06-17 04:59:24 +00:00
|
|
|
|
|
|
|
ls = gtk.ListStore(gobject.TYPE_STRING, # Long name
|
|
|
|
gobject.TYPE_STRING) # Short name
|
|
|
|
for k in BlocklistImport.readers.keys():
|
2007-06-26 04:31:55 +00:00
|
|
|
i = ls.append([BlocklistImport.readers[k][0], k])
|
|
|
|
BlocklistImport.readers[k][2] = ls.get_path(i)
|
2007-06-17 04:59:24 +00:00
|
|
|
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
cell.set_property('xpad', 5) # padding for status text
|
|
|
|
|
|
|
|
self.listtype = gtk.ComboBox(model=ls)
|
|
|
|
self.listtype.pack_start(cell, False)
|
|
|
|
self.listtype.add_attribute(cell, 'text', 0)
|
2007-06-12 08:13:16 +00:00
|
|
|
self.listtype.set_active(0)
|
|
|
|
|
|
|
|
hbox = gtk.HBox(False, 6)
|
|
|
|
hbox.pack_start(label)
|
|
|
|
hbox.pack_start(self.url)
|
|
|
|
|
2007-06-17 04:59:24 +00:00
|
|
|
self.vbox.pack_start(self.listtype)
|
2007-06-12 08:13:16 +00:00
|
|
|
self.vbox.pack_start(hbox)
|
|
|
|
|
|
|
|
# Load on start
|
2007-07-20 22:08:48 +00:00
|
|
|
self.load_on_start = gtk.CheckButton(_("Download on start"))
|
2007-06-12 08:13:16 +00:00
|
|
|
self.vbox.pack_start(self.load_on_start)
|
|
|
|
|
|
|
|
self.connect('response', self.ok)
|
|
|
|
self.connect('close', self.cancel)
|
2007-12-15 18:14:20 +00:00
|
|
|
self.connect("delete_event", self.cancel)
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
self.hide_all()
|
|
|
|
|
|
|
|
|
|
|
|
def ok(self, dialog, response):
|
|
|
|
self.hide_all()
|
|
|
|
|
|
|
|
if response != gtk.RESPONSE_ACCEPT:
|
|
|
|
self.cancel(dialog)
|
|
|
|
return
|
2007-06-17 14:02:17 +00:00
|
|
|
|
2007-06-17 04:59:24 +00:00
|
|
|
ls = self.listtype.get_model()
|
|
|
|
ltype = ls[self.listtype.get_active()][1]
|
|
|
|
url = self.url.get_text()
|
|
|
|
los = self.load_on_start.get_active()
|
|
|
|
|
|
|
|
self.plugin.setconfig(url, los, ltype)
|
|
|
|
|
2007-06-17 14:02:17 +00:00
|
|
|
|
2007-12-15 18:14:20 +00:00
|
|
|
def cancel(self, dialog, signal=None):
|
2007-06-12 08:13:16 +00:00
|
|
|
self.hide_all()
|
2007-12-15 18:14:20 +00:00
|
|
|
if signal:
|
|
|
|
return True
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-08-06 00:40:18 +00:00
|
|
|
def start(self, ltype, url, load, window):
|
|
|
|
self.set_transient_for(window)
|
2007-06-26 04:31:55 +00:00
|
|
|
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)
|
|
|
|
|
2007-06-12 08:13:16 +00:00
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
|
|
|
|
class GTKProgress(gtk.Dialog):
|
|
|
|
def __init__(self, plugin):
|
2007-06-16 05:45:22 +00:00
|
|
|
gtk.Dialog.__init__(self, title="Loading Blocklist",
|
2007-08-09 03:55:56 +00:00
|
|
|
parent=None,
|
2007-06-12 08:13:16 +00:00
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
|
2007-06-17 14:02:17 +00:00
|
|
|
self.plugin = plugin
|
|
|
|
|
2007-06-12 08:13:16 +00:00
|
|
|
# Setup
|
|
|
|
self.set_border_width(12)
|
|
|
|
self.vbox.set_spacing(6)
|
|
|
|
|
|
|
|
label = gtk.Label()
|
2007-07-20 22:08:48 +00:00
|
|
|
label.set_markup('<b>' + _("Loading and installing blocklist") + '</b>')
|
2007-06-12 08:13:16 +00:00
|
|
|
self.vbox.pack_start(label)
|
|
|
|
|
|
|
|
self.progress = gtk.ProgressBar()
|
|
|
|
self.vbox.pack_start(self.progress)
|
|
|
|
|
2007-06-17 14:02:17 +00:00
|
|
|
self.connect('response', self.response)
|
2007-06-12 08:13:16 +00:00
|
|
|
self.connect('close', self.cancel)
|
2007-12-15 18:40:03 +00:00
|
|
|
self.connect("delete_event", self.cancel)
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
self.hide_all()
|
|
|
|
|
2007-06-16 05:45:22 +00:00
|
|
|
def start_download(self):
|
2007-07-20 22:08:48 +00:00
|
|
|
self.progress.set_text(_("Downloading"))
|
2007-06-26 04:31:55 +00:00
|
|
|
self.progress.set_fraction(0.0)
|
2007-06-16 05:45:22 +00:00
|
|
|
self.update()
|
|
|
|
|
2007-06-12 08:13:16 +00:00
|
|
|
def download_prog(self, fract):
|
|
|
|
if fract > 1.0:
|
|
|
|
fract = 1.0
|
|
|
|
self.progress.set_fraction(fract)
|
2007-06-16 05:45:22 +00:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def start_import(self):
|
2007-07-20 22:08:48 +00:00
|
|
|
self.progress.set_text(_("Importing"))
|
2007-06-26 04:31:55 +00:00
|
|
|
self.progress.set_fraction(0.0)
|
2007-06-16 05:45:22 +00:00
|
|
|
self.progress.set_pulse_step(0.0075)
|
|
|
|
self.update()
|
|
|
|
|
2007-06-24 10:32:51 +00:00
|
|
|
def import_prog(self, text=None):
|
|
|
|
if text:
|
|
|
|
self.progress.set_text(text)
|
2007-06-16 05:45:22 +00:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def end_import(self):
|
2007-07-20 22:08:48 +00:00
|
|
|
self.progress.set_text(_("Complete"))
|
2007-06-16 05:45:22 +00:00
|
|
|
self.progress.set_fraction(1.0)
|
|
|
|
self.update()
|
2007-06-12 08:13:16 +00:00
|
|
|
|
2007-06-17 14:02:17 +00:00
|
|
|
|
|
|
|
def response(self, dialog, response):
|
|
|
|
self.cancel(dialog)
|
|
|
|
|
2007-12-15 18:40:03 +00:00
|
|
|
def cancel(self, dialog, signal=None):
|
2007-06-17 14:02:17 +00:00
|
|
|
print "Cancelling"
|
|
|
|
self.plugin.cancelled = True
|
2007-06-12 08:13:16 +00:00
|
|
|
self.hide_all()
|
2007-12-15 18:40:03 +00:00
|
|
|
if signal:
|
|
|
|
return True
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.show_all()
|
2007-06-16 05:45:22 +00:00
|
|
|
self.update()
|
2007-06-12 08:13:16 +00:00
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self.hide_all()
|
2007-06-16 05:45:22 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
while gtk.events_pending():
|
|
|
|
not gtk.main_iteration(block=True)
|
2007-06-24 10:32:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GTKError(gtk.Dialog):
|
|
|
|
def __init__(self, message):
|
|
|
|
gtk.Dialog.__init__(self, title="Error",
|
2007-08-09 03:55:56 +00:00
|
|
|
parent=None,
|
2007-06-24 10:32:51 +00:00
|
|
|
buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
|
|
|
|
|
|
|
# Setup
|
|
|
|
self.set_border_width(12)
|
|
|
|
self.vbox.set_spacing(6)
|
|
|
|
|
|
|
|
# List source
|
|
|
|
label = gtk.Label()
|
|
|
|
label.set_text(message)
|
|
|
|
self.vbox.pack_start(label)
|
|
|
|
|
|
|
|
self.connect('response', self.ok)
|
|
|
|
self.connect('close', self.cancel)
|
2007-12-15 18:40:03 +00:00
|
|
|
self.connect("delete_event", self.cancel)
|
2007-06-24 10:32:51 +00:00
|
|
|
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
def ok(self, dialog, response):
|
|
|
|
self.hide_all()
|
|
|
|
|
2007-12-15 18:40:03 +00:00
|
|
|
def cancel(self, dialog, signal):
|
2007-06-24 10:32:51 +00:00
|
|
|
self.hide_all()
|
2007-12-15 18:40:03 +00:00
|
|
|
if signal:
|
|
|
|
return True
|