diff --git a/deluge/plugins/blocklist/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index f68bddeb0..d1757b9c3 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/blocklist/core.py @@ -33,12 +33,14 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. +import deluge.component from torrentblocklist import TorrentBlockList from deluge.log import LOG as log from deluge.plugins.corepluginbase import CorePluginBase class Core(CorePluginBase): def enable(self): + deluge.component.get("Core").session.set_max_connections(0) self.blocklist = TorrentBlockList(self.plugin) self.plugin.register_hook("post_session_load", self._post_session_load) log.debug('Blocklist: Plugin enabled..') @@ -57,7 +59,7 @@ class Core(CorePluginBase): ## Hooks for core ## def _post_session_load(self): log.info('Blocklist: Session load hook caught') - if self.blocklist.load_on_start == True or self.blocklist.load_on_start == 'True': + if self.blocklist.load_on_start == True: # Wait until an idle time to load block list import gobject gobject.idle_add(self.blocklist.import_list) @@ -86,6 +88,17 @@ class Core(CorePluginBase): def export_import_list(self): log.debug('Blocklist: Import started from GTK UI') self.blocklist.import_list() + + def export_download_list(self): + log.debug('Blocklist: Download started from GTK UI') + force_check = True + self.blocklist.check_update(force_check) + # Initialize download attempt + self.blocklist.attempt = 0 + + if self.blocklist.fetch == True: + self.blocklist.download() + def export_set_options(self, settings): log.debug("Blocklist: Set Options") diff --git a/deluge/plugins/blocklist/blocklist/data/blocklist16.png b/deluge/plugins/blocklist/blocklist/data/blocklist16.png new file mode 100644 index 000000000..58240de7d Binary files /dev/null and b/deluge/plugins/blocklist/blocklist/data/blocklist16.png differ diff --git a/deluge/plugins/blocklist/blocklist/data/blocklist_download24.png b/deluge/plugins/blocklist/blocklist/data/blocklist_download24.png new file mode 100644 index 000000000..de73891d9 Binary files /dev/null and b/deluge/plugins/blocklist/blocklist/data/blocklist_download24.png differ diff --git a/deluge/plugins/blocklist/blocklist/data/blocklist_import24.png b/deluge/plugins/blocklist/blocklist/data/blocklist_import24.png new file mode 100644 index 000000000..ed2c75b22 Binary files /dev/null and b/deluge/plugins/blocklist/blocklist/data/blocklist_import24.png differ diff --git a/deluge/plugins/blocklist/blocklist/gtkui.py b/deluge/plugins/blocklist/blocklist/gtkui.py index d52cab641..3e1fc214e 100644 --- a/deluge/plugins/blocklist/blocklist/gtkui.py +++ b/deluge/plugins/blocklist/blocklist/gtkui.py @@ -33,9 +33,9 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. -import pkg_resources # remove possibly, double check +import os +import pkg_resources # access plugin egg from deluge.log import LOG as log -import deluge.common # for pixmap import deluge.component # for systray import ui import gtk, gobject @@ -71,6 +71,10 @@ class GtkUI(ui.UI): def disable(self): deluge.component.get("StatusBar").remove_item(self.blocklist_status) self.plugin.deregister_hook("on_apply_prefs", self.apply_prefs) + + def get_pixmap(self, fname): + """Returns a pixmap file included with plugin""" + return pkg_resources.resource_filename("blocklist", os.path.join("data", fname)) def add_status_icon(self, ip_count): try: @@ -78,7 +82,7 @@ class GtkUI(ui.UI): except: pass # self, image=None, stock=None, text=None, callback=None - self.blocklist_status = deluge.component.get("StatusBar").add_item(deluge.common.get_pixmap("blocklist16.png"), None, str(ip_count) + " Blocked IP Ranges ", None) + self.blocklist_status = deluge.component.get("StatusBar").add_item(self.get_pixmap("blocklist16.png"), None, str(ip_count) + " Blocked IP Ranges ", None) def get_ip_count(self): ui.client.block_list_count_ips(self.add_status_icon) @@ -89,6 +93,11 @@ class GtkUI(ui.UI): log.debug('Blocklist: Import button') gobject.timeout_add(20000, self.get_ip_count) + def download_list(self, widget, data=None): + self.apply_prefs() + ui.client.block_list_download_list(None) + log.debug('Blocklist: Download button') + def unload_interface(self): self.plugin.remove_preferences_page("Blocklist") @@ -113,7 +122,7 @@ class GtkUI(ui.UI): alignment = gtk.Alignment(0.5, 0.5, 1, 1) alignment.set_padding(8, 5, 5, 5) - table = gtk.Table(7, 2, False) + table = gtk.Table(8, 2, False) table.set_col_spacings(8) table.set_row_spacings(10) @@ -198,22 +207,30 @@ class GtkUI(ui.UI): hbox2.pack_start(self.try_times) table.attach(hbox2, 0, 2, 4, 5) - + # sixth row self.load_on_start = gtk.CheckButton('Import blocklist on daemon startup') table.attach(self.load_on_start, 0, 2, 5, 6) - # DO I NEED THIS STILL I DONT KNOW THINK ABOUT IT AND ASK MYSELF AGAIN LATER K THX BYE + # download new list button + download_button = gtk.Button("_Download Blocklist", None, True) + download_button.connect("clicked", self.download_list, None) -# # import button (Check and possibly download) + pixbuf = gtk.gdk.pixbuf_new_from_file(self.get_pixmap("blocklist_download24.png")) + image = gtk.image_new_from_pixbuf(pixbuf) + download_button.set_image(image) + table.attach(download_button, 0, 2, 6, 7) + + # import button (Check and possibly download) import_button = gtk.Button("_Import Blocklist", None, True) import_button.connect("clicked", self.start_import, None) - pixbuf = gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("blocklist_import24.png")) + pixbuf = gtk.gdk.pixbuf_new_from_file(self.get_pixmap("blocklist_import24.png")) image = gtk.image_new_from_pixbuf(pixbuf) import_button.set_image(image) - table.attach(import_button, 0, 2, 6, 7) + table.attach(import_button, 0, 2, 7, 8) + # finish frame frame.set_label_widget(label) @@ -247,7 +264,7 @@ class GtkUI(ui.UI): } ui.client.block_list_set_options(None, settings_dict) # Needs to go in another thread or wait until window is closed - gobject.idle_add(self.call_critical_setting) + #gobject.idle_add(self.call_critical_setting) def call_critical_setting(self): ui.client.block_list_critical_setting(None) # This checks to see if url or listtype changed, if so download & import diff --git a/deluge/plugins/blocklist/blocklist/torrentblocklist.py b/deluge/plugins/blocklist/blocklist/torrentblocklist.py index 31532d1e7..757e7acda 100644 --- a/deluge/plugins/blocklist/blocklist/torrentblocklist.py +++ b/deluge/plugins/blocklist/blocklist/torrentblocklist.py @@ -49,7 +49,7 @@ from text import TextReader, GZMuleReader, PGZip BLOCKLIST_PREFS = { "url": "http://www.bluetack.co.uk/config/pipfilter.dat.gz", - "load_on_start": "True", + "load_on_start": True, "check_after_days": 2, "listtype": "gzmule", "timeout": 180, @@ -118,7 +118,6 @@ class TorrentBlockList: def __init__(self, coreplugin): self.plugin = coreplugin # reference from plugin core log.info('Blocklist: TorrentBlockList instantiated') - deluge.component.get("Core").session.set_max_connections(0) self.config = deluge.configmanager.ConfigManager("blocklist.conf", BLOCKLIST_PREFS) self.curr = 0 self.load_options() @@ -167,7 +166,7 @@ class TorrentBlockList: # Load newly set options to core plugin self.load_options() - def check_update(self): + def check_update(self, force_check=False): log.info('Blocklist: Checking for updates') try: @@ -193,7 +192,7 @@ class TorrentBlockList: check_newer = False # If the program decides it is time to get a new list - if check_newer == True: + if check_newer == True or force_check == True: log.debug('Blocklist: Attempting check') j = 0 # counter for loop @@ -300,6 +299,9 @@ class TorrentBlockList: # CHECKSUM log.info('Blocklist: List downloaded sucessfully') + break + + # Download completed def import_list(self): diff --git a/deluge/plugins/blocklist/setup.py b/deluge/plugins/blocklist/setup.py index 4d5f9dbfa..bebce4d0f 100644 --- a/deluge/plugins/blocklist/setup.py +++ b/deluge/plugins/blocklist/setup.py @@ -44,7 +44,7 @@ setup( description=__doc__, author=__author__, packages=["blocklist"], - package_data = {"blocklist": ["glade/*.glade"]}, + package_data = {"blocklist": ["data/*"]}, entry_points=""" [deluge.plugin.core] Blocklist = blocklist:CorePlugin