webui label config rework

This commit is contained in:
Martijn Voncken 2008-11-08 10:09:15 +00:00
parent 944be0876b
commit 05a982fd4b
15 changed files with 206 additions and 434 deletions

View File

@ -53,14 +53,10 @@ LABEL = "label"
CONFIG_DEFAULTS = { CONFIG_DEFAULTS = {
"torrent_labels":{}, #torrent_id:label_id "torrent_labels":{}, #torrent_id:label_id
"labels":{}, #label_id:{name:value} "labels":{}, #label_id:{name:value}
"hide_zero_hits":False, "auto_add_trackers":[]
"gtk_alfa":False,
"show_states":True,
"show_trackers":True,
"show_labels":True
} }
CORE_OPTIONS = ["hide_zero_hits", "gtk_alfa", "show_states", "show_trackers", "show_labels","auto_add","auto_add_trackers"] CORE_OPTIONS = ["auto_add_trackers"]
OPTIONS_DEFAULTS = { OPTIONS_DEFAULTS = {
"apply_max":False, "apply_max":False,
@ -77,8 +73,7 @@ OPTIONS_DEFAULTS = {
"apply_move_completed":False, "apply_move_completed":False,
"move_completed":False, "move_completed":False,
"move_completed_path":"", "move_completed_path":"",
"auto_add":False, "auto_add":False
"auto_add_trackers":[],
} }
NO_LABEL = "No Label" NO_LABEL = "No Label"
@ -296,11 +291,11 @@ class Core(CorePluginBase):
self.config.save() self.config.save()
def export_get_global_options(self): def export_get_config(self):
"see : label_set_global_options" "see : label_set_config"
return dict ( (k,self.config[k] ) for k in CORE_OPTIONS) return dict ( (k,self.config[k] ) for k in CORE_OPTIONS)
def export_set_global_options(self, options): def export_set_config(self, options):
"""global_options:""" """global_options:"""
for key in CORE_OPTIONS: for key in CORE_OPTIONS:
if options.has_key(key): if options.has_key(key):

View File

@ -68,7 +68,7 @@ class LabelConfig(object):
return pkg_resources.resource_filename("label", os.path.join("data", filename)) return pkg_resources.resource_filename("label", os.path.join("data", filename))
def load_settings(self ,widget = None , data = None): def load_settings(self ,widget = None , data = None):
aclient.label_get_global_options(self.cb_global_options) aclient.label_get_config(self.cb_global_options)
def cb_global_options(self, options): def cb_global_options(self, options):
log.debug("options=%s" % options) log.debug("options=%s" % options)
@ -80,5 +80,5 @@ class LabelConfig(object):
def on_apply_prefs(self): def on_apply_prefs(self):
options = {} options = {}
#update options dict here. #update options dict here.
aclient.label_set_global_options(None, options) aclient.label_set_config(None, options)

View File

@ -0,0 +1,19 @@
$def with (labels)
<table style="padding-left:20px;">
$for label in labels:
<tr>
<td><a href="$base/label/options/$label"
title="$_('Options')"
>$label</a></td>
</td>
<td><a href="$base/label/remove/$label"><img
src="$base/static/images/tango/list-remove.png"
title="$_('Remove')"
></a></td>
</tr>
</table>
<h2>Options</h2>
<ul>
<li><a href="$base/label/add">$_("Add label")</a></li>
</ul>

View File

@ -0,0 +1,10 @@
$def with (label_id)
$:render.basic_header(_("Label Options"))
<h2>$label_id Options.</h2>
<div class="panel">
<form method="POST" action='$base/label/options/$label_id'>
label= $label_id
</form>
</div>
$:render.footer()

View File

@ -1,53 +0,0 @@
$def with (filter_items)
<form method="GET" id="category_form">
<input type="hidden" name="sort" value="$get('sort')">
<input type="hidden" name="order" value="$get('order')">
<input type="hidden" name="filter_cat" value="keyword">
<div id="organize_block">
<div id="organize_state">
<div class="title">$_('Keyword')</div>
<input type="text" name="filter_value" id="filter_value"
$if get('filter_cat') == "keyword":
value="$get('filter_value')"
style="width:100px;padding:0px" title="$_('Filter on a keyword')"/>
$if get('filter_cat') == "keyword":
$if get('filter_value'):
<img src="$base/static/images/tango/edit-clear.png" alt="$_('Clear')"
onclick="el('keyword').value='';el('category_form').submit();"
>
</form>
<br /><br />
<!--
$filter_items
-->
$for cat in ["state", "tracker", "label"]:
<div class="title">$cat</div>
<ul>
$for value, count in filter_items[cat]:
<li
$if cat == get('filter_cat'):
$if value == get('filter_value'):
class="selected"
$# I hate this, special case for All
$# templetor sucks with multiple conditions in 1 if-statement, i need to find a better way,
$if cat == "state":
$if value == "All":
$if not get('filter_value'):
$if not get('filter_cat'):
class="selected"
>
<a href="$self_url(filter_cat=cat, filter_value=value)">
$if cat == "state":
<img src="/pixmaps/$(value.lower())"></img>
$value ($count)</a>
</li>
</ul>
</div>
</div>

View File

@ -0,0 +1,142 @@
#
# webui.py
#
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
#
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
# Copyright (C) 2007, 2008 Andrew Resch ('andar') <andrewresch@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
import os
from deluge.common import fspeed
from deluge.log import LOG as log
from deluge.ui.client import sclient, aclient
from deluge.plugins.webuipluginbase import WebUIPluginBase
from deluge import component
api = component.get("WebPluginApi")
forms = api.forms
#pages:
class options:
@api.deco.deluge_page
def GET(self, label_id):
return api.render.label.options(label_id)
class add:
@api.deco.deluge_page
def GET(self, label_id):
return api.render.label.options(label_id)
class remove:
@api.deco.deluge_page
def GET(self, label_id):
return api.render.label.options(label_id)
class WebUI(WebUIPluginBase):
include_javascript = ["/label/data/label.js"]
urls = [
('/label/options/(.*)', options),
('/label/add', add),
('/label/remove/(.*)', remove)
]
def enable(self):
api.config_page_manager.register('plugins', 'label' ,ConfigForm)
def disable(self):
api.config_page_manager.deregister('label')
#options:
"""
todo (see gtkui)
sensitive_groups = [
("apply_max", ["max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"]),
("apply_queue", ["is_auto_managed", "stop_at_ratio"]),
("stop_at_ratio", ["remove_at_ratio", "stop_ratio"]), #nested
("apply_move_completed", ["move_completed"]),
("move_completed", ["move_completed_path"]), #nested
("auto_add", ["auto_add_trackers"])
]
"""
class OptionsForm(forms.Form):
#maximum:
apply_max = forms.CheckBox(_("apply_max"))
max_download_speed = forms.DelugeInt(_("max_download_speed"))
max_upload_speed = forms.DelugeInt(_("max_upload_speed"))
max_upload_slots = forms.DelugeInt(_("max_upload_slots"))
max_connections = forms.DelugeInt(_("max_connections"))
#queue:
apply_queue = forms.CheckBox(_("apply_queue"))
is_auto_managed = forms.CheckBox(_("is_auto_managed"))
stop_at_ratio = forms.CheckBox(_("stop_at_ratio"))
stop_ratio = forms.DelugeInt(_("stop_ratio"))
remove_at_ratio = forms.CheckBox(_("remove_at_ratio"))
#location:
apply_move_completed = forms.CheckBox(_("apply_move_completed"))
move_completed = forms.CheckBox(_("move_completed"))
move_completed_path = forms.CharField(label=_("move_completed_path"))
#tracker:
auto_add_trackers = forms.CharField(label=_("auto_add_trackers"), widget=forms.Textarea)
auto_add = forms.CheckBox(_("auto_add"))
#config:
class ConfigForm(forms.Form):
"""
custom config page
too complex for the default config framework
"""
#meta:
title = _("Label")
info = _("Work in progress..")
#load/save:
def initial_data(self):
return sclient.label_get_config()
def save(self, data):
cfg = dict(data)
sclient.label_set_config(cfg)
def pre_html(self):
""" custom config html/template"""
labels = sclient.label_get_labels()
return api.render.label.config(labels)
#django newforms magic: define config fields:
#test = forms.CharField(label=_("Test config value"))

View File

@ -1,64 +0,0 @@
#
# blocklist/webui.py
#
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# 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 os
from deluge.log import LOG as log
from deluge.ui.client import sclient
from deluge import component
import ui
import config
import pages
from deluge.plugins.webuipluginbase import WebUIPluginBase
#TODO: use more additions to WebUIPluginBase, thish whould be and example -lougin.
class WebUI(WebUIPluginBase):
include_javascript = ["/label/data/test1.js"]
def enable(self):
log.debug("**HERE**")
pages.register()
config.register()
def disable(self):
log.debug("**HERE**")
pages.deregister()
config.deregister()

View File

@ -1,151 +0,0 @@
#
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# 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 os
from deluge.log import LOG as log
from deluge.ui.client import sclient
from deluge import component
api = component.get("WebPluginApi")
forms = api.forms
class LabelUpdateCfgForm(forms.Form):
"""
a config form based on django forms.
see webui.lib.newforms_plus, config_forms, etc.
"""
#meta:
title = _("Labels")
def get_selected(self):
selected = api.web.input(label = None).label
labels = sclient.label_get_labels()
if not selected:
if labels:
selected = labels[0]
return selected
def pre_html(self):
selected = self.get_selected()
html = _("Select Label") + ":"
for label in sclient.label_get_labels():
html += """
<a href="/config/label_update?label=%(label)s">%(label)s</a> &nbsp;""" % {"label":label}
html += "<h2>%s</h2>" % selected
return html
#load/save:
def initial_data(self):
label_id = self.get_selected()
return sclient.label_get_options(label_id)
def save(self, data):
label_id = self.get_selected()
apply = data.apply
delete = data.delete
if delete:
sclient.label_remove(label_id)
raise Exception("DELETED")
else:
del data["apply"]
del data["delete"]
sclient.label_set_options(label_id, dict(data), apply)
#input fields :
apply_max = forms.CheckBox(_("Apply Maximum settings on add"))
max_connections = forms.DelugeInt(_("Maximum Connections"))
max_download_speed = forms.DelugeFloat(_("Maximum Download Speed (Kib/s)"))
max_upload_speed = forms.DelugeFloat(_("Maximum Upload Speed (Kib/s)"))
max_upload_slots = forms.DelugeInt(_("Maximum Upload Slots"))
move_completed_to = forms.ServerFolder(_("Move completed to"), required=False)
apply = forms.CheckBox(_("Apply"))
delete = forms.CheckBox(_("Delete"))
class LabelAddCfgForm(forms.Form):
"""
a config form based on django forms.
see webui.lib.newforms_plus, config_forms, etc.
"""
#meta:
title = _("Add Label")
#load/save:
def initial_data(self):
return { }
def save(self, data):
sclient.label_add(data.label)
label = forms.CharField(_("Label"))
class LabelCfgForm(forms.Form):
"""
global settings.
"""
#meta:
title = _("General")
#load/save:
def initial_data(self):
return sclient.label_get_global_options()
def save(self, data):
return sclient.label_set_global_options(dict(data))
hide_zero_hits = forms.CheckBox(_("Hide filter items with 0 hits"))
#gtk_alfa = forms.CheckBox(_("gtk_alfa"))
def register():
api.config_page_manager.register('label','label_general',LabelCfgForm)
api.config_page_manager.register('label','label_update',LabelUpdateCfgForm)
api.config_page_manager.register('label','label_add',LabelAddCfgForm)
def deregister():
api.config_page_manager.deregister('label_general')
api.config_page_manager.deregister('label_update')
api.config_page_manager.deregister('label_add')

View File

@ -1,79 +0,0 @@
#
#
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# 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 os
from deluge.log import LOG as log
from deluge.ui.client import sclient
from deluge import component
api = component.get("WebPluginApi")
template_dir = os.path.join(os.path.dirname(__file__),"template")
class torrent_label:
@api.deco.deluge_page
@api.deco.torrent_list
def GET(self, torrent_list):
torrent_str = ",".join([t.id for t in torrent_list])
labels = sclient.label_get_labels()
return api.render.torrent_label(torrent_str , torrent_list , labels)
@api.deco.check_session
@api.deco.torrent_ids
def POST(self, torrent_ids):
label =api.web.input(label = None).label
for id in torrent_ids:
sclient.label_set_torrent(id , label)
api.utils.do_redirect()
def register():
api.render.register_template_path(template_dir)
api.page_manager.register_page('/torrent/label/(.*)', torrent_label)
api.menu_manager.register_toolbar_item("label",_("Label"), "label.png" ,2,
"GET","/torrent/label/", True)
def deregister():
api.render.deregister_template_path(template_dir)
api.page_manager.deregister_page('/torrent/label/(.*)')
api.menu_manager.deregister_toolbar_item("label")

View File

@ -1,53 +0,0 @@
#
# blocklist/ui.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
# Copyright (C) 2008 Mark Stahler ('kramed') <markstahler@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# 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 gettext
import locale
import pkg_resources
import deluge.component
from deluge.ui.client import aclient as client
from deluge.log import LOG as log
class UI:
def __init__(self, plugin_api, plugin_name):
self.plugin = plugin_api
def enable(self):
pass
def disable(self):
pass

View File

@ -58,7 +58,7 @@ setup(
license=__license__, license=__license__,
long_description=__long_description__, long_description=__long_description__,
packages=[__plugin_name__.lower(), "label.gtkui", "label.webui"], packages=[__plugin_name__.lower(), "label.gtkui"],
package_data = __pkg_data__, package_data = __pkg_data__,
entry_points=""" entry_points="""

View File

@ -16,3 +16,8 @@ print_totals(sclient.stats_get_totals())
print "==session totals==" print "==session totals=="
print_totals(sclient.stats_get_session_totals()) print_totals(sclient.stats_get_session_totals())

View File

@ -0,0 +1,20 @@
$def with (title)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Deluge:$title</title>
<link rel="icon" href="$base/static/images/deluge-icon.png" type="image/png" />
<link rel="shortcut icon" href="$base/static/images/deluge-icon.png" type="image/png" />
<link rel="stylesheet" type="text/css" href="$base/template_style.css" />
<script language="javascript" src="$base/static/deluge.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-core.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-more.js"></script>
<script language="javascript" src="$base/static/mooui.js"></script>
<script language="javascript" src="$base/gettext.js"></script>
$for js in include_javascript:
<script language="javascript" src="$base$js"></script>
</head>
<body>
<div id="page">

View File

@ -1,24 +1,5 @@
$def with (title, active_tab="NONE") $def with (title, active_tab="NONE")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> $:render.basic_header(title)
<html>
<head>
<title>Deluge:$title</title>
<link rel="icon" href="$base/static/images/deluge-icon.png" type="image/png" />
<link rel="shortcut icon" href="$base/static/images/deluge-icon.png" type="image/png" />
<link rel="stylesheet" type="text/css" href="$base/template_style.css" />
<script language="javascript" src="$base/static/deluge.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-core.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-more.js"></script>
<script language="javascript" src="$base/static/mooui.js"></script>
<script language="javascript" src="$base/gettext.js"></script>
$for js in include_javascript:
<script language="javascript" src="$base$js"></script>
</head>
<body>
<div id="page">
<table width="100%"><tr> <table width="100%"><tr>
<td> <td>