diff --git a/deluge/plugins/webui/create_dev_link.sh b/deluge/plugins/webui/create_dev_link.sh new file mode 100755 index 000000000..6d3af263f --- /dev/null +++ b/deluge/plugins/webui/create_dev_link.sh @@ -0,0 +1,7 @@ +#!/bin/bash +cd /home/damien/Projects/deluge/deluge/plugins/webui +mkdir temp +export PYTHONPATH=./temp +python setup.py build develop --install-dir ./temp +cp ./temp/WebUi.egg-link /home/damien/.config/deluge/plugins +rm -fr ./temp diff --git a/deluge/plugins/webui/setup.py b/deluge/plugins/webui/setup.py new file mode 100644 index 000000000..25cf05dc2 --- /dev/null +++ b/deluge/plugins/webui/setup.py @@ -0,0 +1,70 @@ +# +# setup.py +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# 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. +# + +from setuptools import setup + +__plugin_name__ = "WebUi" +__author__ = "Damien Churchill" +__author_email__ = "damoxc@gmail.com" +__version__ = "0.1" +__url__ = "http://deluge-torrent.org" +__license__ = "GPLv3" +__description__ = "Allows starting the web interface within the daemon." +__long_description__ = """""" +__pkg_data__ = {__plugin_name__.lower(): ["template/*", "data/*"]} + +setup( + name=__plugin_name__, + version=__version__, + description=__description__, + author=__author__, + author_email=__author_email__, + url=__url__, + license=__license__, + long_description=__long_description__ if __long_description__ else __description__, + + packages=[__plugin_name__.lower()], + package_data = __pkg_data__, + + entry_points=""" + [deluge.plugin.core] + %s = %s:CorePlugin + [deluge.plugin.gtkui] + %s = %s:GtkUIPlugin + """ % ((__plugin_name__, __plugin_name__.lower())*2) +) diff --git a/deluge/plugins/webui/webui/__init__.py b/deluge/plugins/webui/webui/__init__.py new file mode 100644 index 000000000..3cf56dd9d --- /dev/null +++ b/deluge/plugins/webui/webui/__init__.py @@ -0,0 +1,57 @@ +# +# __init__.py +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# 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. +# + +from deluge.plugins.init import PluginInitBase + +class CorePlugin(PluginInitBase): + def __init__(self, plugin_name): + from core import Core as _plugin_cls + self._plugin_cls = _plugin_cls + super(CorePlugin, self).__init__(plugin_name) + +class GtkUIPlugin(PluginInitBase): + def __init__(self, plugin_name): + from gtkui import GtkUI as _plugin_cls + self._plugin_cls = _plugin_cls + super(GtkUIPlugin, self).__init__(plugin_name) + +class WebUIPlugin(PluginInitBase): + def __init__(self, plugin_name): + from webui import WebUI as _plugin_cls + self._plugin_cls = _plugin_cls + super(WebUIPlugin, self).__init__(plugin_name) diff --git a/deluge/plugins/webui/webui/common.py b/deluge/plugins/webui/webui/common.py new file mode 100644 index 000000000..a85371ec6 --- /dev/null +++ b/deluge/plugins/webui/webui/common.py @@ -0,0 +1,41 @@ +# +# common.py +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# 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. +# + +def get_resource(filename): + import pkg_resources, os + return pkg_resources.resource_filename("webui", os.path.join("data", filename)) diff --git a/deluge/plugins/webui/webui/core.py b/deluge/plugins/webui/webui/core.py new file mode 100644 index 000000000..8311962a7 --- /dev/null +++ b/deluge/plugins/webui/webui/core.py @@ -0,0 +1,119 @@ +# +# core.py +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# 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 import common, component, configmanager +from deluge.log import LOG as log +from deluge.plugins.pluginbase import CorePluginBase +from deluge.core.rpcserver import export + +from deluge.ui.web import server + +DEFAULT_PREFS = { + "enabled": False, + "ssl": False, + "port": 8112 +} + +class Core(CorePluginBase): + + + def enable(self): + self.config = configmanager.ConfigManager("web_plugin.conf", DEFAULT_PREFS) + self.server = None + if self.config['enabled']: + self.start() + + def disable(self): + if self.server: + self.server.stop() + + def update(self): + pass + + def restart(self): + if self.server: + self.server.stop().addCallback(self.on_stop) + else: + self.start() + + def on_stop(self, *args): + self.start() + + @export + def start(self): + if not self.server: + self.server = server.DelugeWeb() + self.server.port = self.config["port"] + self.server.https = self.config["ssl"] + self.server.start(False) + + @export + def stop(self): + if self.server: + self.server.stop() + + @export + def set_config(self, config): + "sets the config dictionary" + + action = None + if "enabled" in config: + if config["enabled"] != self.config["enabled"]: + action = config["enabled"] and 'start' or 'stop' + + if "ssl" in config: + if not action: + action = 'restart' + + for key in config.keys(): + self.config[key] = config[key] + self.config.save() + + if action == 'start': + self.start() + elif action == 'stop': + self.stop() + elif action == 'restart': + self.restart() + + @export + def get_config(self): + "returns the config dictionary" + return self.config.config diff --git a/deluge/plugins/webui/webui/data/config.glade b/deluge/plugins/webui/webui/data/config.glade new file mode 100644 index 000000000..820053bc1 --- /dev/null +++ b/deluge/plugins/webui/webui/data/config.glade @@ -0,0 +1,109 @@ + + + + + + + + True + vertical + + + True + 0 + none + + + True + 10 + 12 + + + True + vertical + 5 + + + Enable web interface + True + True + False + True + + + False + False + 0 + + + + + Enable SSL + True + True + False + True + + + False + False + 1 + + + + + True + 5 + + + True + Listening port: + + + False + False + 0 + + + + + True + True + + 8112 0 99999 1 10 0 + True + + + 1 + + + + + False + False + 2 + + + + + + + + + True + <b>Settings</b> + True + + + label_item + + + + + 0 + + + + + + diff --git a/deluge/plugins/webui/webui/gtkui.py b/deluge/plugins/webui/webui/gtkui.py new file mode 100644 index 000000000..1be861c07 --- /dev/null +++ b/deluge/plugins/webui/webui/gtkui.py @@ -0,0 +1,79 @@ +# +# gtkui.py +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# 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 gtk + +from deluge.log import LOG as log +from deluge.ui.client import client +from deluge.plugins.pluginbase import GtkPluginBase +import deluge.component as component +import deluge.common + +from common import get_resource + +class GtkUI(GtkPluginBase): + def enable(self): + self.glade = gtk.glade.XML(get_resource("config.glade")) + + component.get("Preferences").add_page("WebUi", self.glade.get_widget("prefs_box")) + component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) + component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) + client.webui.get_config().addCallback(self.cb_get_config) + + def disable(self): + component.get("Preferences").remove_page("WebUi") + component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs) + component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs) + + def on_apply_prefs(self): + log.debug("applying prefs for WebUi") + config = { + "enabled": self.glade.get_widget("enabled_checkbutton").get_active(), + "ssl": self.glade.get_widget("ssl_checkbutton").get_active(), + "port": self.glade.get_widget("port_spinbutton").get_value_as_int() + } + client.webui.set_config(config) + + def on_show_prefs(self): + client.webui.get_config().addCallback(self.cb_get_config) + + def cb_get_config(self, config): + "callback for on show_prefs" + self.glade.get_widget("enabled_checkbutton").set_active(config["enabled"]) + self.glade.get_widget("ssl_checkbutton").set_active(config["ssl"]) + self.glade.get_widget("port_spinbutton").set_value(config["port"])