diff --git a/deluge/plugins/init.py b/deluge/plugins/init.py index 3c9506fc7..29185d3e9 100644 --- a/deluge/plugins/init.py +++ b/deluge/plugins/init.py @@ -2,19 +2,19 @@ # init.py # # Copyright (C) 2007 Andrew Resch ('andar') -# +# # 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., @@ -36,18 +36,25 @@ from deluge.log import LOG as log class PluginBase: def __init__(self): self.plugin = None - + def enable(self): try: + log.debug(0) + if hasattr(self.plugin, "base_enable"): + log.debug(1) + self.plugin.base_enable() + log.debug(2) self.plugin.enable() except Exception, e: log.warning("Unable to enable plugin: %s", e) else: # If plugin was enabled, call it's update() right away self.update() - + def disable(self): try: + if hasattr(self.plugin, "base_disable"): + self.plugin.base_disable() self.plugin.disable() except Exception, e: log.warning("Unable to disable plugin: %s", e) @@ -55,4 +62,4 @@ class PluginBase: def update(self): if hasattr(self.plugin, "update"): self.plugin.update() - + diff --git a/deluge/plugins/label/label/data/test1.js b/deluge/plugins/label/label/data/test1.js new file mode 100644 index 000000000..435ca766b --- /dev/null +++ b/deluge/plugins/label/label/data/test1.js @@ -0,0 +1,2 @@ +/*testing include_javascript*/ +window.alert("test-plugin-javascript"); diff --git a/deluge/plugins/label/label/webui/__init__.py b/deluge/plugins/label/label/webui/__init__.py index 18fe85b0e..e330c5dc9 100644 --- a/deluge/plugins/label/label/webui/__init__.py +++ b/deluge/plugins/label/label/webui/__init__.py @@ -40,19 +40,20 @@ import ui import config import pages +from deluge.plugins.webuipluginbase import WebUIPluginBase -class WebUI(ui.UI): - def __init__(self, plugin_api, plugin_name): - log.debug("Calling UI init") - # Call UI constructor - ui.UI.__init__(self, plugin_api, plugin_name) - log.debug("Label WebUI plugin initalized..") + +#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() diff --git a/deluge/plugins/label/setup.py b/deluge/plugins/label/setup.py index b890cb18b..f0973fd8e 100644 --- a/deluge/plugins/label/setup.py +++ b/deluge/plugins/label/setup.py @@ -58,7 +58,7 @@ setup( license=__license__, long_description=__long_description__, - packages=[__plugin_name__.lower()], + packages=[__plugin_name__.lower(), "label.gtkui", "label.webui"], package_data = __pkg_data__, entry_points=""" diff --git a/deluge/plugins/webuipluginbase.py b/deluge/plugins/webuipluginbase.py index a61cf5fea..2e40a0f3d 100644 --- a/deluge/plugins/webuipluginbase.py +++ b/deluge/plugins/webuipluginbase.py @@ -45,23 +45,50 @@ class WebUIPluginBase: * templates: /template are added to api.render.plugin-name. * pages: urls attribute registers pages : urls = [(url, class), ..] """ - urls= [] + include_javascript = [] + ajax_javascript = [] + urls = [] + def __init__(self, plugin_api, plugin_name): log.debug("%s plugin : start initalize.." % plugin_name) + self.plugin = plugin_api self.plugin_name = plugin_name - clean_plugin_name = plugin_name.lower().replace(" ","_") + self.clean_plugin_name = plugin_name.lower().replace(" ","_") + + def base_enable(self): + """ + enable plugin. + """ for url , klass in self.urls: - api.page_manager.register_page(url, klass) + api.page_manager.register_page(url, klass) + + for js in self.include_javascript: + api.page_manager.include_javascript.append(js) class egg_data_static(api.egg_handler): #serves files in /data from egg - resource = clean_plugin_name + resource = self.clean_plugin_name base_path = "data" #use as : api.render.plugin-name.template-name[excluding.html](parameters) - setattr(api.render, clean_plugin_name, api.egg_render(clean_plugin_name, "template")) + setattr(api.render, self.clean_plugin_name, api.egg_render(self.clean_plugin_name, "template")) + + api.page_manager.register_page("/%s/data/(.*)" % self.clean_plugin_name , egg_data_static) + + log.debug("%s plugin : end base_enable().." % self.plugin_name) + + def base_disable(self): + """ + disable plugin. + """ + for url , klass in self.urls: + api.page_manager.deregister_page(url, klass) + + for js in self.include_javascript: + api.page_manager.include_javascript.remove(js) + + log.debug("%s plugin : end base_disable().." % self.plugin_name) + - api.page_manager.register_page("/%s/data/(.*)" % clean_plugin_name , egg_data_static) - log.debug("%s plugin : end initalize.." % plugin_name) diff --git a/deluge/tests/test_tracker_icons.py b/deluge/tests/test_tracker_icons.py index d3d2e2bee..c0d816657 100644 --- a/deluge/tests/test_tracker_icons.py +++ b/deluge/tests/test_tracker_icons.py @@ -2,7 +2,7 @@ import time import gobject import os -from deluge.tracker_icons import TrackerIcons +from deluge.ui.tracker_icons import TrackerIcons from deluge.common import get_default_config_dir def del_old(): diff --git a/deluge/ui/webui/components.py b/deluge/ui/webui/components.py index 68119a4cf..cd88633cf 100644 --- a/deluge/ui/webui/components.py +++ b/deluge/ui/webui/components.py @@ -112,6 +112,8 @@ class PageManager(component.Component): component.Component.__init__(self, "PageManager") self.page_classes = {} self.urls = [] + self.include_javascript = [] + self.ajax_javascript = [] def register_pages(self, url_list, class_list): self.urls += url_list @@ -200,14 +202,15 @@ class PluginApi(component.Component): self.utils = utils def register(): + __page_manager = PageManager() __plugin_manager = PluginManager() __menu_manager = MenuManager() - __page_manager = PageManager() __config_page_manager = ConfigPageManager() __plugin_api = PluginApi() - +if __name__ == "__main__": + register() diff --git a/deluge/ui/webui/render.py b/deluge/ui/webui/render.py index 7f4fb0a53..99207e44b 100644 --- a/deluge/ui/webui/render.py +++ b/deluge/ui/webui/render.py @@ -35,11 +35,14 @@ from utils import * import utils #/relative from deluge import common +from deluge import component from web import template, Storage import os - from deluge.configmanager import ConfigManager + config = ConfigManager("webui06.conf") +page_manager = component.get("PageManager") + class subclassed_render(object): """ @@ -212,7 +215,9 @@ template.Template.globals.update({ 'forms':web.Storage(), 'enumerate':enumerate, 'base':'', #updated when running within apache. - 'id_to_label':id_to_label + 'id_to_label':id_to_label, + 'include_javascript':page_manager.include_javascript, + 'ajax_javascript':page_manager.include_javascript }) #/template-defs diff --git a/deluge/ui/webui/templates/white/header.html b/deluge/ui/webui/templates/white/header.html index 5f8fac0eb..c8bac2f83 100644 --- a/deluge/ui/webui/templates/white/header.html +++ b/deluge/ui/webui/templates/white/header.html @@ -8,6 +8,8 @@ $def with (title, active_tab="NONE") + $for js in include_javascript: + diff --git a/deluge/ui/webui/templates/white/part_label_filters.html b/deluge/ui/webui/templates/white/part_label_filters.html index 06e69e7a3..779ea12b9 100644 --- a/deluge/ui/webui/templates/white/part_label_filters.html +++ b/deluge/ui/webui/templates/white/part_label_filters.html @@ -26,13 +26,15 @@ $if get_config("show_keyword_search"): $filter_items --> $for cat in filter_items.keys(): -
$id_to_label(cat)
+
$id_to_label(cat)