Show plugin information in the preferences page

This commit is contained in:
Andrew Resch 2008-11-13 22:39:57 +00:00
commit 1725ab7569
2 changed files with 748 additions and 686 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,19 +2,19 @@
# preferences.py # preferences.py
# #
# Copyright (C) 2007, 2008 Andrew Resch ('andar') <andrewresch@gmail.com> # Copyright (C) 2007, 2008 Andrew Resch ('andar') <andrewresch@gmail.com>
# #
# Deluge is free software. # Deluge is free software.
# #
# You may redistribute it and/or modify it under the terms of the # You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software # GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) # Foundation; either version 3 of the License, or (at your option)
# any later version. # any later version.
# #
# deluge is distributed in the hope that it will be useful, # deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. # See the GNU General Public License for more details.
# #
# 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 deluge. If not, write to: # along with deluge. If not, write to:
# The Free Software Foundation, Inc., # The Free Software Foundation, Inc.,
@ -64,7 +64,7 @@ class Preferences(component.Component):
self.treeview.append_column(column) self.treeview.append_column(column)
# Add the default categories # Add the default categories
i = 0 i = 0
for category in ["Downloads", "Network", "Bandwidth", "Interface", for category in ["Downloads", "Network", "Bandwidth", "Interface",
"Other", "Daemon", "Queue", "Proxy", "Notification", "Plugins"]: "Other", "Daemon", "Queue", "Proxy", "Notification", "Plugins"]:
self.liststore.append([i, category]) self.liststore.append([i, category])
i += 1 i += 1
@ -80,15 +80,15 @@ class Preferences(component.Component):
gtk.TreeViewColumn(_("Enabled"), render, active=1)) gtk.TreeViewColumn(_("Enabled"), render, active=1))
self.plugin_listview.append_column( self.plugin_listview.append_column(
gtk.TreeViewColumn(_("Plugin"), gtk.CellRendererText(), text=0)) gtk.TreeViewColumn(_("Plugin"), gtk.CellRendererText(), text=0))
# Connect to the 'changed' event of TreeViewSelection to get selection # Connect to the 'changed' event of TreeViewSelection to get selection
# changes. # changes.
self.treeview.get_selection().connect("changed", self.treeview.get_selection().connect("changed",
self.on_selection_changed) self.on_selection_changed)
self.plugin_listview.get_selection().connect("changed", self.plugin_listview.get_selection().connect("changed",
self.on_plugin_selection_changed) self.on_plugin_selection_changed)
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_pref_dialog_delete_event": self.on_pref_dialog_delete_event, "on_pref_dialog_delete_event": self.on_pref_dialog_delete_event,
"on_button_ok_clicked": self.on_button_ok_clicked, "on_button_ok_clicked": self.on_button_ok_clicked,
@ -100,10 +100,10 @@ class Preferences(component.Component):
"on_button_rescan_plugins_clicked": self._on_button_rescan_plugins_clicked "on_button_rescan_plugins_clicked": self._on_button_rescan_plugins_clicked
}) })
# These get updated by requests done to the core # These get updated by requests done to the core
self.all_plugins = [] self.all_plugins = []
self.enabled_plugins = [] self.enabled_plugins = []
def __del__(self): def __del__(self):
del self.gtkui_config del self.gtkui_config
@ -128,9 +128,9 @@ class Preferences(component.Component):
vbox.pack_start(align, False, False, 0) vbox.pack_start(align, False, False, 0)
scrolled = gtk.ScrolledWindow() scrolled = gtk.ScrolledWindow()
viewport = gtk.Viewport() viewport = gtk.Viewport()
viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.set_shadow_type(gtk.SHADOW_NONE)
viewport.add(vbox) viewport.add(vbox)
scrolled.add(viewport) scrolled.add(viewport)
scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled.show_all() scrolled.show_all()
# Add this page to the notebook # Add this page to the notebook
@ -142,7 +142,7 @@ class Preferences(component.Component):
"""Removes a page from the notebook""" """Removes a page from the notebook"""
self.page_num_to_remove = None self.page_num_to_remove = None
self.iter_to_remove = None self.iter_to_remove = None
def check_row(model, path, iter, user_data): def check_row(model, path, iter, user_data):
row_name = model.get_value(iter, 1) row_name = model.get_value(iter, 1)
if row_name == user_data: if row_name == user_data:
@ -157,19 +157,19 @@ class Preferences(component.Component):
self.notebook.remove_page(self.page_num_to_remove) self.notebook.remove_page(self.page_num_to_remove)
if self.iter_to_remove != None: if self.iter_to_remove != None:
self.liststore.remove(self.iter_to_remove) self.liststore.remove(self.iter_to_remove)
def _on_get_config(self, config): def _on_get_config(self, config):
self.core_config = config self.core_config = config
def _on_get_available_plugins(self, plugins): def _on_get_available_plugins(self, plugins):
self.all_plugins = plugins self.all_plugins = plugins
def _on_get_enabled_plugins(self, plugins): def _on_get_enabled_plugins(self, plugins):
self.enabled_plugins = plugins self.enabled_plugins = plugins
def _on_get_listen_port(self, port): def _on_get_listen_port(self, port):
self.active_port = port self.active_port = port
def show(self, page=None): def show(self, page=None):
"""Page should be the string in the left list.. ie, 'Network' or 'Bandwidth'""" """Page should be the string in the left list.. ie, 'Network' or 'Bandwidth'"""
if page != None: if page != None:
@ -177,7 +177,7 @@ class Preferences(component.Component):
if page == string: if page == string:
self.treeview.get_selection().select_path(index) self.treeview.get_selection().select_path(index)
break break
# Update the preferences dialog to reflect current config settings # Update the preferences dialog to reflect current config settings
self.core_config = {} self.core_config = {}
try: try:
@ -211,7 +211,7 @@ class Preferences(component.Component):
"radio_full_allocation": \ "radio_full_allocation": \
("not_active", self.core_config["compact_allocation"]), ("not_active", self.core_config["compact_allocation"]),
"chk_prioritize_first_last_pieces": \ "chk_prioritize_first_last_pieces": \
("active", ("active",
self.core_config["prioritize_first_last_pieces"]), self.core_config["prioritize_first_last_pieces"]),
"spin_port_min": ("value", self.core_config["listen_ports"][0]), "spin_port_min": ("value", self.core_config["listen_ports"][0]),
"spin_port_max": ("value", self.core_config["listen_ports"][1]), "spin_port_max": ("value", self.core_config["listen_ports"][1]),
@ -276,7 +276,7 @@ class Preferences(component.Component):
"txt_proxy_username": ("text", self.core_config["proxy_username"]), "txt_proxy_username": ("text", self.core_config["proxy_username"]),
"txt_proxy_password": ("text", self.core_config["proxy_password"]), "txt_proxy_password": ("text", self.core_config["proxy_password"]),
} }
# Change a few widgets if we're connected to a remote host # Change a few widgets if we're connected to a remote host
if not client.is_localhost(): if not client.is_localhost():
self.glade.get_widget("entry_download_path").show() self.glade.get_widget("entry_download_path").show()
@ -288,7 +288,7 @@ class Preferences(component.Component):
self.glade.get_widget("move_completed_path_button").hide() self.glade.get_widget("move_completed_path_button").hide()
core_widgets.pop("move_completed_path_button") core_widgets.pop("move_completed_path_button")
core_widgets["entry_move_completed_path"] = ("text", self.core_config["move_completed_path"]) core_widgets["entry_move_completed_path"] = ("text", self.core_config["move_completed_path"])
self.glade.get_widget("entry_torrents_path").show() self.glade.get_widget("entry_torrents_path").show()
self.glade.get_widget("torrent_files_button").hide() self.glade.get_widget("torrent_files_button").hide()
core_widgets.pop("torrent_files_button") core_widgets.pop("torrent_files_button")
@ -306,7 +306,7 @@ class Preferences(component.Component):
self.glade.get_widget("entry_torrents_path").hide() self.glade.get_widget("entry_torrents_path").hide()
self.glade.get_widget("torrent_files_button").show() self.glade.get_widget("torrent_files_button").show()
self.glade.get_widget("entry_autoadd").hide() self.glade.get_widget("entry_autoadd").hide()
self.glade.get_widget("folder_autoadd").show() self.glade.get_widget("folder_autoadd").show()
# Update the widgets accordingly # Update the widgets accordingly
for key in core_widgets.keys(): for key in core_widgets.keys():
@ -317,7 +317,7 @@ class Preferences(component.Component):
for child in widget.get_children(): for child in widget.get_children():
child.set_sensitive(True) child.set_sensitive(True)
widget.set_sensitive(True) widget.set_sensitive(True)
if modifier == "filename": if modifier == "filename":
if value: if value:
try: try:
@ -423,7 +423,7 @@ class Preferences(component.Component):
self.gtkui_config["lock_tray"]) self.gtkui_config["lock_tray"])
self.glade.get_widget("chk_classic_mode").set_active( self.glade.get_widget("chk_classic_mode").set_active(
self.gtkui_config["classic_mode"]) self.gtkui_config["classic_mode"])
## Other tab ## ## Other tab ##
self.glade.get_widget("chk_show_new_releases").set_active( self.glade.get_widget("chk_show_new_releases").set_active(
self.gtkui_config["show_new_releases"]) self.gtkui_config["show_new_releases"])
@ -468,22 +468,22 @@ class Preferences(component.Component):
row = self.plugin_liststore.append() row = self.plugin_liststore.append()
self.plugin_liststore.set_value(row, 0, plugin) self.plugin_liststore.set_value(row, 0, plugin)
self.plugin_liststore.set_value(row, 1, enabled) self.plugin_liststore.set_value(row, 1, enabled)
component.get("PluginManager").run_on_show_prefs() component.get("PluginManager").run_on_show_prefs()
# Now show the dialog # Now show the dialog
self.pref_dialog.show() self.pref_dialog.show()
def set_config(self): def set_config(self):
"""Sets all altered config values in the core""" """Sets all altered config values in the core"""
try: try:
from hashlib import sha1 as sha_hash from hashlib import sha1 as sha_hash
except ImportError: except ImportError:
from sha import new as sha_hash from sha import new as sha_hash
# Get the values from the dialog # Get the values from the dialog
new_core_config = {} new_core_config = {}
new_gtkui_config = {} new_gtkui_config = {}
## Downloads tab ## ## Downloads tab ##
new_gtkui_config["interactive_add"] = \ new_gtkui_config["interactive_add"] = \
self.glade.get_widget("chk_show_dialog").get_active() self.glade.get_widget("chk_show_dialog").get_active()
@ -507,7 +507,7 @@ class Preferences(component.Component):
self.glade.get_widget("entry_move_completed_path").get_text() self.glade.get_widget("entry_move_completed_path").get_text()
new_core_config["torrentfiles_location"] = \ new_core_config["torrentfiles_location"] = \
self.glade.get_widget("entry_torrents_path").get_text() self.glade.get_widget("entry_torrents_path").get_text()
new_core_config["autoadd_enable"] = \ new_core_config["autoadd_enable"] = \
self.glade.get_widget("chk_autoadd").get_active() self.glade.get_widget("chk_autoadd").get_active()
if client.is_localhost(): if client.is_localhost():
@ -516,7 +516,7 @@ class Preferences(component.Component):
else: else:
new_core_config["autoadd_location"] = \ new_core_config["autoadd_location"] = \
self.glade.get_widget("entry_autoadd").get_text() self.glade.get_widget("entry_autoadd").get_text()
new_core_config["compact_allocation"] = \ new_core_config["compact_allocation"] = \
self.glade.get_widget("radio_compact_allocation").get_active() self.glade.get_widget("radio_compact_allocation").get_active()
new_core_config["prioritize_first_last_pieces"] = \ new_core_config["prioritize_first_last_pieces"] = \
@ -536,12 +536,12 @@ class Preferences(component.Component):
outgoing_ports.append( outgoing_ports.append(
self.glade.get_widget("spin_outgoing_port_min").get_value_as_int()) self.glade.get_widget("spin_outgoing_port_min").get_value_as_int())
outgoing_ports.append( outgoing_ports.append(
self.glade.get_widget("spin_outgoing_port_max").get_value_as_int()) self.glade.get_widget("spin_outgoing_port_max").get_value_as_int())
new_core_config["outgoing_ports"] = outgoing_ports new_core_config["outgoing_ports"] = outgoing_ports
new_core_config["random_outgoing_ports"] = \ new_core_config["random_outgoing_ports"] = \
self.glade.get_widget("chk_random_outgoing_ports").get_active() self.glade.get_widget("chk_random_outgoing_ports").get_active()
new_core_config["peer_tos"] = self.glade.get_widget("entry_peer_tos").get_text() new_core_config["peer_tos"] = self.glade.get_widget("entry_peer_tos").get_text()
new_core_config["dht"] = self.glade.get_widget("chk_dht").get_active() new_core_config["dht"] = self.glade.get_widget("chk_dht").get_active()
new_core_config["upnp"] = self.glade.get_widget("chk_upnp").get_active() new_core_config["upnp"] = self.glade.get_widget("chk_upnp").get_active()
new_core_config["natpmp"] = \ new_core_config["natpmp"] = \
@ -558,7 +558,7 @@ class Preferences(component.Component):
self.glade.get_widget("combo_enclevel").get_active() self.glade.get_widget("combo_enclevel").get_active()
new_core_config["enc_prefer_rc4"] = \ new_core_config["enc_prefer_rc4"] = \
self.glade.get_widget("chk_pref_rc4").get_active() self.glade.get_widget("chk_pref_rc4").get_active()
## Bandwidth tab ## ## Bandwidth tab ##
new_core_config["max_connections_global"] = \ new_core_config["max_connections_global"] = \
self.glade.get_widget( self.glade.get_widget(
@ -589,7 +589,7 @@ class Preferences(component.Component):
"spin_max_download_per_torrent").get_value() "spin_max_download_per_torrent").get_value()
new_core_config["ignore_limits_on_local_network"] = \ new_core_config["ignore_limits_on_local_network"] = \
self.glade.get_widget("chk_ignore_limits_on_local_network").get_active() self.glade.get_widget("chk_ignore_limits_on_local_network").get_active()
## Interface tab ## ## Interface tab ##
new_gtkui_config["enable_system_tray"] = \ new_gtkui_config["enable_system_tray"] = \
self.glade.get_widget("chk_use_tray").get_active() self.glade.get_widget("chk_use_tray").get_active()
@ -631,8 +631,8 @@ class Preferences(component.Component):
new_gtkui_config["ntf_security"] = 'SSL' new_gtkui_config["ntf_security"] = 'SSL'
elif self.glade.get_widget("rad_ntf_tls").get_active(): elif self.glade.get_widget("rad_ntf_tls").get_active():
new_gtkui_config["ntf_security"] = 'TLS' new_gtkui_config["ntf_security"] = 'TLS'
## Other tab ## ## Other tab ##
new_gtkui_config["show_new_releases"] = \ new_gtkui_config["show_new_releases"] = \
self.glade.get_widget("chk_show_new_releases").get_active() self.glade.get_widget("chk_show_new_releases").get_active()
new_core_config["send_info"] = \ new_core_config["send_info"] = \
@ -681,16 +681,16 @@ class Preferences(component.Component):
self.glade.get_widget("spin_seed_time_ratio_limit").get_value() self.glade.get_widget("spin_seed_time_ratio_limit").get_value()
new_core_config["seed_time_limit"] = \ new_core_config["seed_time_limit"] = \
self.glade.get_widget("spin_seed_time_limit").get_value() self.glade.get_widget("spin_seed_time_limit").get_value()
# Run plugin hook to apply preferences # Run plugin hook to apply preferences
component.get("PluginManager").run_on_apply_prefs() component.get("PluginManager").run_on_apply_prefs()
# GtkUI # GtkUI
for key in new_gtkui_config.keys(): for key in new_gtkui_config.keys():
# The values do not match so this needs to be updated # The values do not match so this needs to be updated
if self.gtkui_config[key] != new_gtkui_config[key]: if self.gtkui_config[key] != new_gtkui_config[key]:
self.gtkui_config[key] = new_gtkui_config[key] self.gtkui_config[key] = new_gtkui_config[key]
# Core # Core
if client.get_core_uri() != None: if client.get_core_uri() != None:
# Only do this if we're connected to a daemon # Only do this if we're connected to a daemon
@ -705,17 +705,17 @@ class Preferences(component.Component):
client.force_call(True) client.force_call(True)
# Update the configuration # Update the configuration
self.core_config.update(config_to_set) self.core_config.update(config_to_set)
# Re-show the dialog to make sure everything has been updated # Re-show the dialog to make sure everything has been updated
self.show() self.show()
def hide(self): def hide(self):
self.pref_dialog.hide() self.pref_dialog.hide()
def on_pref_dialog_delete_event(self, widget, event): def on_pref_dialog_delete_event(self, widget, event):
self.hide() self.hide()
return True return True
def on_toggle(self, widget): def on_toggle(self, widget):
"""Handles widget sensitivity based on radio/check button values.""" """Handles widget sensitivity based on radio/check button values."""
try: try:
@ -771,7 +771,7 @@ class Preferences(component.Component):
log.debug("on_button_cancel_clicked") log.debug("on_button_cancel_clicked")
self.hide() self.hide()
return True return True
def on_selection_changed(self, treeselection): def on_selection_changed(self, treeselection):
# Show the correct notebook page based on what row is selected. # Show the correct notebook page based on what row is selected.
(model, row) = treeselection.get_selected() (model, row) = treeselection.get_selected()
@ -787,7 +787,7 @@ class Preferences(component.Component):
"http://deluge-torrent.org/test-port.php?port=%s" % port) "http://deluge-torrent.org/test-port.php?port=%s" % port)
client.get_listen_port(on_get_listen_port) client.get_listen_port(on_get_listen_port)
client.force_call() client.force_call()
def on_plugin_toggled(self, renderer, path): def on_plugin_toggled(self, renderer, path):
log.debug("on_plugin_toggled") log.debug("on_plugin_toggled")
row = self.plugin_liststore.get_iter_from_string(path) row = self.plugin_liststore.get_iter_from_string(path)
@ -800,9 +800,17 @@ class Preferences(component.Component):
else: else:
client.disable_plugin(name) client.disable_plugin(name)
component.get("PluginManager").disable_plugin(name) component.get("PluginManager").disable_plugin(name)
def on_plugin_selection_changed(self, treeselection): def on_plugin_selection_changed(self, treeselection):
log.debug("on_plugin_selection_changed") log.debug("on_plugin_selection_changed")
(model, itr) = treeselection.get_selected()
name = model[itr][0]
plugin_info = component.get("PluginManager").get_plugin_info(name)
self.glade.get_widget("label_plugin_author").set_text(plugin_info["Author"])
self.glade.get_widget("label_plugin_version").set_text(plugin_info["Version"])
self.glade.get_widget("label_plugin_email").set_text(plugin_info["Author-email"])
self.glade.get_widget("label_plugin_homepage").set_text(plugin_info["Home-page"])
self.glade.get_widget("label_plugin_details").set_text(plugin_info["Description"])
def _on_button_plugin_install_clicked(self, widget): def _on_button_plugin_install_clicked(self, widget):
log.debug("_on_button_plugin_install_clicked") log.debug("_on_button_plugin_install_clicked")
@ -834,11 +842,11 @@ class Preferences(component.Component):
import os.path import os.path
filename = os.path.split(filepath)[1] filename = os.path.split(filepath)[1]
shutil.copyfile( shutil.copyfile(
filepath, filepath,
os.path.join(self.gtkui_config["config_location"], "plugins", filename)) os.path.join(self.gtkui_config["config_location"], "plugins", filename))
component.get("PluginManager").scan_for_plugins() component.get("PluginManager").scan_for_plugins()
if not client.is_localhost(): if not client.is_localhost():
# We need to send this plugin to the daemon # We need to send this plugin to the daemon
client.upload_plugin( client.upload_plugin(
@ -849,9 +857,8 @@ class Preferences(component.Component):
chooser.destroy() chooser.destroy()
# We need to re-show the preferences dialog to show the new plugins # We need to re-show the preferences dialog to show the new plugins
self.show() self.show()
def _on_button_rescan_plugins_clicked(self, widget): def _on_button_rescan_plugins_clicked(self, widget):
component.get("PluginManager").scan_for_plugins() component.get("PluginManager").scan_for_plugins()
client.rescan_plugins() client.rescan_plugins()
self.show() self.show()