Improve Blocklist preferences page

This commit is contained in:
Andrew Resch 2008-07-29 08:00:50 +00:00
commit dd4fc26877
3 changed files with 292 additions and 185 deletions

View file

@ -52,7 +52,11 @@ DEFAULT_PREFS = {
"check_after_days": 2, "check_after_days": 2,
"listtype": "gzmule", "listtype": "gzmule",
"timeout": 180, "timeout": 180,
"try_times": 3 "try_times": 3,
"file_type": "",
"file_url": "",
"file_date": "",
"file_size": 0,
} }
FORMATS = { FORMATS = {
@ -93,14 +97,14 @@ class Core(CorePluginBase):
pass pass
## Exported RPC methods ### ## Exported RPC methods ###
def export_download(self): def export_download(self, _import=False):
"""Download the blocklist specified in the config as url""" """Download the blocklist specified in the config as url"""
self.download_blocklist() self.download_blocklist(_import)
def export_import(self, download=False): def export_import(self, download=False, force=False):
"""Import the blocklist from the blocklist.cache, if load is True, then """Import the blocklist from the blocklist.cache, if load is True, then
it will download the blocklist file if needed.""" it will download the blocklist file if needed."""
threading.Thread(target=self.import_blocklist, kwargs={"download": download}).start() threading.Thread(target=self.import_blocklist, kwargs={"download": download, "force": force}).start()
def export_get_config(self): def export_get_config(self):
"""Returns the config dictionary""" """Returns the config dictionary"""
@ -123,6 +127,10 @@ class Core(CorePluginBase):
status["num_blocked"] = self.num_blocked status["num_blocked"] = self.num_blocked
status["file_progress"] = self.file_progress status["file_progress"] = self.file_progress
status["file_type"] = self.config["file_type"]
status["file_url"] = self.config["file_url"]
status["file_size"] = self.config["file_size"]
status["file_date"] = self.config["file_date"]
return status return status
@ -134,13 +142,13 @@ class Core(CorePluginBase):
if load: if load:
self.export_import() self.export_import()
def import_blocklist(self, download=False): def import_blocklist(self, download=False, force=False):
"""Imports the downloaded blocklist into the session""" """Imports the downloaded blocklist into the session"""
if self.is_downloading: if self.is_downloading:
return return
if download: if download:
if self.need_new_blocklist(): if force or self.need_new_blocklist():
self.download_blocklist(True) self.download_blocklist(True)
return return
@ -191,7 +199,10 @@ class Core(CorePluginBase):
return False return False
def on_retrieve_data(count, block_size, total_blocks): def on_retrieve_data(count, block_size, total_blocks):
self.file_progress = float(count * block_size) / total_blocks fp = float(count * block_size) / total_blocks
if fp > 1.0:
fp = 1.0
self.file_progress = fp
import socket import socket
socket.setdefaulttimeout(self.config["timeout"]) socket.setdefaulttimeout(self.config["timeout"])
@ -208,6 +219,13 @@ class Core(CorePluginBase):
continue continue
else: else:
log.debug("Blocklist successfully downloaded..") log.debug("Blocklist successfully downloaded..")
# Set information about the file
self.config["file_type"] = self.config["listtype"]
self.config["file_url"] = self.config["url"]
list_stats = os.stat(deluge.configmanager.get_config_dir("blocklist.cache"))
self.config["file_date"] = datetime.datetime.fromtimestamp(list_stats.st_mtime).ctime()
self.config["file_size"] = list_size = list_stats.st_size
gobject.idle_add(_call_callback, callback, load) gobject.idle_add(_call_callback, callback, load)
return return

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Fri Jul 18 11:06:25 2008 --> <!--Generated with glade3 3.4.5 on Tue Jul 29 00:52:51 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<child> <child>
@ -75,8 +75,6 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
@ -97,7 +95,6 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
@ -117,47 +114,19 @@
<child> <child>
<widget class="GtkTable" id="table1"> <widget class="GtkTable" id="table1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">3</property> <property name="n_rows">1</property>
<property name="n_columns">3</property> <property name="n_columns">3</property>
<property name="column_spacing">5</property> <property name="column_spacing">5</property>
<property name="row_spacing">5</property> <property name="row_spacing">5</property>
<child> <child>
<placeholder/> <widget class="GtkLabel" id="label8">
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Check for new list every:</property> <property name="label" translatable="yes">Days</property>
</widget> </widget>
<packing> <packing>
<property name="x_options">GTK_FILL</property> <property name="left_attach">2</property>
<property name="y_options"></property> <property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Timeout to download new list:</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max attempts to download list:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
@ -176,59 +145,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="spin_timeout"> <widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">180 0 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_attempts">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">3 1 100 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Days</property> <property name="label" translatable="yes">Check for new list every:</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Seconds</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
@ -270,7 +192,6 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
@ -283,21 +204,20 @@
<child> <child>
<widget class="GtkAlignment" id="alignment3"> <widget class="GtkAlignment" id="alignment3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property>
<property name="xscale">0</property>
<property name="left_padding">12</property> <property name="left_padding">12</property>
<child> <child>
<widget class="GtkVBox" id="vbox3"> <widget class="GtkVBox" id="vbox3">
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<widget class="GtkHButtonBox" id="hbuttonbox1"> <widget class="GtkButton" id="button_check_download">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<child>
<widget class="GtkButton" id="button_download">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Download the blocklist file if necessary and import the file.</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<signal name="clicked" handler="on_button_download_clicked"/> <signal name="clicked" handler="on_button_check_download_clicked"/>
<child> <child>
<widget class="GtkHBox" id="hbox3"> <widget class="GtkHBox" id="hbox3">
<property name="visible">True</property> <property name="visible">True</property>
@ -305,6 +225,7 @@
<child> <child>
<widget class="GtkImage" id="image_download"> <widget class="GtkImage" id="image_download">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -314,7 +235,7 @@
<child> <child>
<widget class="GtkLabel" id="label12"> <widget class="GtkLabel" id="label12">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Download List</property> <property name="label" translatable="yes">Check Download and Import</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -331,12 +252,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkButton" id="button_import"> <widget class="GtkButton" id="button_force_download">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Download a new blocklist file and import it.</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<signal name="clicked" handler="on_button_import_clicked"/> <signal name="clicked" handler="on_button_force_download_clicked"/>
<child> <child>
<widget class="GtkHBox" id="hbox4"> <widget class="GtkHBox" id="hbox4">
<property name="visible">True</property> <property name="visible">True</property>
@ -344,6 +266,7 @@
<child> <child>
<widget class="GtkImage" id="image_import"> <widget class="GtkImage" id="image_import">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -353,7 +276,7 @@
<child> <child>
<widget class="GtkLabel" id="label7"> <widget class="GtkLabel" id="label7">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Import List</property> <property name="label" translatable="yes">Force Download and Import</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -371,12 +294,6 @@
</packing> </packing>
</child> </child>
</widget> </widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child> </child>
</widget> </widget>
</child> </child>
@ -393,11 +310,154 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkFrame" id="frame4">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<child>
<widget class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="top_padding">5</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<child>
<widget class="GtkProgressBar" id="progressbar">
<property name="visible">True</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
<child>
<widget class="GtkTable" id="table_info">
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">5</property>
<child>
<widget class="GtkLabel" id="label_url">
<property name="visible">True</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_type">
<property name="visible">True</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_modified">
<property name="visible">True</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_filesize">
<property name="visible">True</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">URL:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label16">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Type:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label15">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Date:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">File Size:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Info&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</widget> </widget>
</child> </child>
</widget> </widget>

View file

@ -36,6 +36,7 @@ import gtk
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.ui.client import aclient as client from deluge.ui.client import aclient as client
import deluge.component as component import deluge.component as component
import deluge.common
import ui import ui
from core import FORMATS from core import FORMATS
@ -75,13 +76,42 @@ class GtkUI(ui.UI):
def update(self): def update(self):
def _on_get_status(status): def _on_get_status(status):
if status["state"] == "Downloading": if status["state"] == "Downloading":
self.table_info.hide()
self.glade.get_widget("button_check_download").set_sensitive(False)
self.glade.get_widget("button_force_download").set_sensitive(False)
self.status_item.set_text( self.status_item.set_text(
"Downloading %.2f%%" % (status["file_progress"] * 100)) "Downloading %.2f%%" % (status["file_progress"] * 100))
self.progress_bar.set_text("Downloading %.2f%%" % (status["file_progress"] * 100))
self.progress_bar.set_fraction(status["file_progress"])
self.progress_bar.show()
elif status["state"] == "Importing": elif status["state"] == "Importing":
self.table_info.hide()
self.glade.get_widget("button_check_download").set_sensitive(False)
self.glade.get_widget("button_force_download").set_sensitive(False)
self.status_item.set_text( self.status_item.set_text(
"Importing " + str(status["num_blocked"])) "Importing " + str(status["num_blocked"]))
self.progress_bar.set_text("Importing %s" % (status["num_blocked"]))
self.progress_bar.pulse()
self.progress_bar.show()
elif status["state"] == "Idle": elif status["state"] == "Idle":
self.progress_bar.hide()
self.glade.get_widget("button_check_download").set_sensitive(True)
self.glade.get_widget("button_force_download").set_sensitive(True)
self.table_info.show()
self.status_item.set_text(str(status["num_blocked"])) self.status_item.set_text(str(status["num_blocked"]))
self.glade.get_widget("label_filesize").set_text(
deluge.common.fsize(status["file_size"]))
self.glade.get_widget("label_modified").set_text(
str(status["file_date"]))
self.glade.get_widget("label_type").set_text(
FORMATS[status["file_type"]][0])
self.glade.get_widget("label_url").set_text(
status["file_url"])
client.blocklist_get_status(_on_get_status) client.blocklist_get_status(_on_get_status)
@ -98,12 +128,6 @@ class GtkUI(ui.UI):
self.glade.get_widget("spin_check_days").set_value( self.glade.get_widget("spin_check_days").set_value(
config["check_after_days"]) config["check_after_days"])
self.glade.get_widget("spin_timeout").set_value(
config["timeout"])
self.glade.get_widget("spin_attempts").set_value(
config["try_times"])
self.glade.get_widget("chk_import_on_start").set_active( self.glade.get_widget("chk_import_on_start").set_active(
config["load_on_start"]) config["load_on_start"])
@ -115,16 +139,14 @@ class GtkUI(ui.UI):
get_model()[self.glade.get_widget("combobox_types").get_active()][1] get_model()[self.glade.get_widget("combobox_types").get_active()][1]
config["url"] = self.glade.get_widget("entry_url").get_text() config["url"] = self.glade.get_widget("entry_url").get_text()
config["check_after_days"] = self.glade.get_widget("spin_check_days").get_value_as_int() config["check_after_days"] = self.glade.get_widget("spin_check_days").get_value_as_int()
config["timeout"] = self.glade.get_widget("spin_timeout").get_value_as_int()
config["try_times"] = self.glade.get_widget("spin_attempts").get_value_as_int()
config["load_on_start"] = self.glade.get_widget("chk_import_on_start").get_active() config["load_on_start"] = self.glade.get_widget("chk_import_on_start").get_active()
client.blocklist_set_config(None, config) client.blocklist_set_config(None, config)
def _on_button_download_clicked(self, widget): def _on_button_check_download_clicked(self, widget):
client.blocklist_download(None) client.blocklist_import(None, True, False)
def _on_button_import_clicked(self, widget): def _on_button_force_download_clicked(self, widget):
client.blocklist_import(None) client.blocklist_import(None, True, True)
def _on_status_item_clicked(self, widget, event): def _on_status_item_clicked(self, widget, event):
component.get("Preferences").show("Blocklist") component.get("Preferences").show("Blocklist")
@ -134,9 +156,16 @@ class GtkUI(ui.UI):
# Load the preferences page # Load the preferences page
self.glade = gtk.glade.XML(self.get_resource("blocklist_pref.glade")) self.glade = gtk.glade.XML(self.get_resource("blocklist_pref.glade"))
self.progress_bar = self.glade.get_widget("progressbar")
self.table_info = self.glade.get_widget("table_info")
# Hide the progress bar initially
self.progress_bar.hide()
self.table_info.show()
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_button_download_clicked": self._on_button_download_clicked, "on_button_check_download_clicked": self._on_button_check_download_clicked,
"on_button_import_clicked": self._on_button_import_clicked "on_button_force_download_clicked": self._on_button_force_download_clicked
}) })
# Setup types combobox # Setup types combobox