summaryrefslogtreecommitdiffstats
path: root/deluge/plugins/Toggle
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/plugins/Toggle')
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/__init__.py41
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/common.py23
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/core.py50
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/data/toggle.js27
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/gtkui.py56
-rw-r--r--deluge/plugins/Toggle/deluge_toggle/webui.py34
-rw-r--r--deluge/plugins/Toggle/setup.py47
7 files changed, 278 insertions, 0 deletions
diff --git a/deluge/plugins/Toggle/deluge_toggle/__init__.py b/deluge/plugins/Toggle/deluge_toggle/__init__.py
new file mode 100644
index 0000000..e63e4aa
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/__init__.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from __future__ import unicode_literals
+
+from deluge.plugins.init import PluginInitBase
+
+
+class CorePlugin(PluginInitBase):
+ def __init__(self, plugin_name):
+ from .core import Core as _pluginCls
+
+ self._plugin_cls = _pluginCls
+ super(CorePlugin, self).__init__(plugin_name)
+
+
+class GtkUIPlugin(PluginInitBase):
+ def __init__(self, plugin_name):
+ from .gtkui import GtkUI as _pluginCls
+
+ self._plugin_cls = _pluginCls
+ super(GtkUIPlugin, self).__init__(plugin_name)
+
+
+class WebUIPlugin(PluginInitBase):
+ def __init__(self, plugin_name):
+ from .webui import WebUI as _pluginCls
+
+ self._plugin_cls = _pluginCls
+ super(WebUIPlugin, self).__init__(plugin_name)
diff --git a/deluge/plugins/Toggle/deluge_toggle/common.py b/deluge/plugins/Toggle/deluge_toggle/common.py
new file mode 100644
index 0000000..4c9db09
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/common.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# 2009 Damien Churchill <damoxc@gmail.com>
+# 2010 Pedro Algarvio <pedro@algarvio.me>
+# 2017 Calum Lind <calumlind+deluge@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from __future__ import unicode_literals
+
+import os.path
+
+from pkg_resources import resource_filename
+
+
+def get_resource(filename):
+ return resource_filename(__package__, os.path.join('data', filename))
diff --git a/deluge/plugins/Toggle/deluge_toggle/core.py b/deluge/plugins/Toggle/deluge_toggle/core.py
new file mode 100644
index 0000000..dad52ce
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/core.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from __future__ import unicode_literals
+
+import logging
+
+import deluge.component as component
+from deluge.core.rpcserver import export
+from deluge.plugins.pluginbase import CorePluginBase
+
+log = logging.getLogger(__name__)
+
+DEFAULT_PREFS = {}
+
+
+class Core(CorePluginBase):
+ def enable(self):
+ self.core = component.get('Core')
+
+ def disable(self):
+ pass
+
+ def update(self):
+ pass
+
+ @export
+ def get_status(self):
+ return self.core.session.is_paused()
+
+ @export
+ def toggle(self):
+ if self.core.session.is_paused():
+ self.core.resume_session()
+ paused = False
+ else:
+ self.core.pause_session()
+ paused = True
+ return paused
diff --git a/deluge/plugins/Toggle/deluge_toggle/data/toggle.js b/deluge/plugins/Toggle/deluge_toggle/data/toggle.js
new file mode 100644
index 0000000..8e9a045
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/data/toggle.js
@@ -0,0 +1,27 @@
+/**
+ * Script: toggle.js
+ * The client-side javascript code for the Toggle plugin.
+ *
+ * Copyright (C) John Garland 2010 <johnnybg+deluge@gmail.com>
+ *
+ * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+ * the additional special exception to link portions of this program with the OpenSSL library.
+ * See LICENSE for more details.
+ */
+
+TogglePlugin = Ext.extend(Deluge.Plugin, {
+ constructor: function(config) {
+ config = Ext.apply(
+ {
+ name: 'Toggle',
+ },
+ config
+ );
+ TogglePlugin.superclass.constructor.call(this, config);
+ },
+
+ onDisable: function() {},
+
+ onEnable: function() {},
+});
+new TogglePlugin();
diff --git a/deluge/plugins/Toggle/deluge_toggle/gtkui.py b/deluge/plugins/Toggle/deluge_toggle/gtkui.py
new file mode 100644
index 0000000..c54bca4
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/gtkui.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from __future__ import unicode_literals
+
+import logging
+
+import deluge.component as component
+from deluge.plugins.pluginbase import Gtk3PluginBase
+from deluge.ui.client import client
+
+log = logging.getLogger(__name__)
+
+
+class GtkUI(Gtk3PluginBase):
+ def enable(self):
+ self.core = client.toggle
+ self.plugin = component.get('PluginManager')
+ self.separator = self.plugin.add_toolbar_separator()
+ self.button = self.plugin.add_toolbar_button(
+ self._on_button_clicked,
+ label='Pause Session',
+ stock='gtk-media-pause',
+ tooltip='Pause the session',
+ )
+
+ def disable(self):
+ component.get('PluginManager').remove_toolbar_button(self.button)
+ component.get('PluginManager').remove_toolbar_button(self.separator)
+
+ def update(self):
+ def _on_get_status(paused):
+ if paused:
+ self.button.set_label('Resume Session')
+ self.button.set_tooltip_text('Resume the session')
+ self.button.set_stock_id('gtk-media-play')
+ else:
+ self.button.set_label('Pause Session')
+ self.button.set_tooltip_text('Pause the session')
+ self.button.set_stock_id('gtk-media-pause')
+
+ self.core.get_status().addCallback(_on_get_status)
+
+ def _on_button_clicked(self, widget):
+ self.core.toggle()
diff --git a/deluge/plugins/Toggle/deluge_toggle/webui.py b/deluge/plugins/Toggle/deluge_toggle/webui.py
new file mode 100644
index 0000000..8f0fc8c
--- /dev/null
+++ b/deluge/plugins/Toggle/deluge_toggle/webui.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from __future__ import unicode_literals
+
+import logging
+
+from deluge.plugins.pluginbase import WebPluginBase
+
+from .common import get_resource
+
+log = logging.getLogger(__name__)
+
+
+class WebUI(WebPluginBase):
+
+ scripts = [get_resource('toggle.js')]
+
+ def enable(self):
+ pass
+
+ def disable(self):
+ pass
diff --git a/deluge/plugins/Toggle/setup.py b/deluge/plugins/Toggle/setup.py
new file mode 100644
index 0000000..acc6e6c
--- /dev/null
+++ b/deluge/plugins/Toggle/setup.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
+#
+# Basic plugin template created by:
+# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
+# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+
+from setuptools import find_packages, setup
+
+__plugin_name__ = 'Toggle'
+__author__ = 'John Garland'
+__author_email__ = 'johnnybg+deluge@gmail.com'
+__version__ = '0.4'
+__url__ = 'http://deluge-torrent.org'
+__license__ = 'GPLv3'
+__description__ = 'Toggles the session'
+__long_description__ = """"""
+__pkg_data__ = {'deluge_' + __plugin_name__.lower(): ['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=find_packages(),
+ package_data=__pkg_data__,
+ entry_points="""
+ [deluge.plugin.core]
+ %s = deluge_%s:CorePlugin
+ [deluge.plugin.gtk3ui]
+ %s = deluge_%s:GtkUIPlugin
+ [deluge.plugin.web]
+ %s = deluge_%s:WebUIPlugin
+ """
+ % ((__plugin_name__, __plugin_name__.lower()) * 3),
+)