diff --git a/plinth/frontpage.py b/plinth/frontpage.py index d000253a4..f620be3ce 100644 --- a/plinth/frontpage.py +++ b/plinth/frontpage.py @@ -27,12 +27,14 @@ def get_shortcuts(): return sorted(shortcuts.values(), key=lambda x: x['label']) -def add_shortcut(app, label, url, icon): +def add_shortcut(app, label, url, icon, details=None): """Add shortcut to front page.""" shortcuts[app] = { + 'app': app, 'label': label, 'url': url, 'icon': icon, + 'details': details, } diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index 70d42580c..5a8cf27e0 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -21,8 +21,10 @@ Plinth module for minetest. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.utils import format_lazy from plinth.views import ServiceView @@ -58,13 +60,34 @@ def init(): global service service = service_module.Service( managed_services[0], title, ports=['minetest-plinth'], - is_external=True) + is_external=True, enable=enable, disable=disable) + + if service.is_enabled(): + add_shortcut() def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('minetest', title, '?selected=minetest', + 'glyphicon-th-large', description) + + +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Disable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('minetest') class MinetestServiceView(ServiceView): diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index 00214c835..1ac8a940d 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -21,8 +21,10 @@ Plinth module to configure Mumble server from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.views import ServiceView @@ -56,7 +58,11 @@ def init(): global service service = service_module.Service( - managed_services[0], title, ports=['mumble-plinth'], is_external=True) + managed_services[0], title, ports=['mumble-plinth'], is_external=True, + enable=enable, disable=disable) + + if service.is_enabled(): + add_shortcut() class MumbleServiceView(ServiceView): @@ -69,6 +75,24 @@ def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('mumble', title, '?selected=mumble', + 'glyphicon-headphones', description) + + +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Disable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('mumble') def diagnose(): diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index 984c7cceb..621cd87e1 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _ from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.utils import format_lazy from plinth.views import ServiceView @@ -66,7 +67,11 @@ def init(): global service service = service_module.Service( - managed_services[0], title, ports=['privoxy'], is_external=False) + managed_services[0], title, ports=['privoxy'], is_external=False, + enable=enable, disable=disable) + + if service.is_enabled(): + add_shortcut() def setup(helper, old_version=None): @@ -74,6 +79,24 @@ def setup(helper, old_version=None): helper.call('pre', actions.superuser_run, 'privoxy', ['pre-install']) helper.install(managed_packages) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('privoxy', title, '?selected=privoxy', + 'glyphicon-cloud-upload', description) + + +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Disable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('privoxy') class PrivoxyServiceView(ServiceView): diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py index 865c38672..b4ecab192 100644 --- a/plinth/modules/quassel/__init__.py +++ b/plinth/modules/quassel/__init__.py @@ -21,8 +21,10 @@ Plinth module for Quassel. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.utils import format_lazy from plinth.views import ServiceView @@ -64,7 +66,11 @@ def init(): global service service = service_module.Service( - managed_services[0], title, ports=['quassel-plinth'], is_external=True) + managed_services[0], title, ports=['quassel-plinth'], is_external=True, + enable=enable, disable=disable) + + if service.is_enabled(): + add_shortcut() class QuasselServiceView(ServiceView): @@ -77,6 +83,24 @@ def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('quassel', title, '?selected=quassel', + 'glyphicon-retweet', description) + + +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Disable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('quassel') def diagnose(): diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py index dbe495004..463d2fc23 100644 --- a/plinth/modules/radicale/__init__.py +++ b/plinth/modules/radicale/__init__.py @@ -25,6 +25,7 @@ from django.utils.translation import ugettext_lazy as _ from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.utils import format_lazy @@ -63,22 +64,33 @@ def init(): managed_services[0], title, ports=['http', 'https'], is_external=True, enable=enable, disable=disable) + if service.is_enabled(): + add_shortcut() + def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) helper.call('post', actions.superuser_run, 'radicale', ['setup']) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('radicale', title, '?selected=radicale', + 'glyphicon-calendar', description) def enable(): """Enable the module.""" actions.superuser_run('radicale', ['enable']) + add_shortcut() def disable(): """Disable the module.""" actions.superuser_run('radicale', ['disable']) + frontpage.remove_shortcut('radicale') def load_augeas(): diff --git a/plinth/modules/repro/__init__.py b/plinth/modules/repro/__init__.py index d20d7cc6e..bd38b2ad2 100644 --- a/plinth/modules/repro/__init__.py +++ b/plinth/modules/repro/__init__.py @@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _ from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.views import ServiceView @@ -69,7 +70,10 @@ def init(): global service service = service_module.Service( managed_services[0], title, ports=['sip-plinth', 'sip-tls-plinth'], - is_external=True) + is_external=True, enable=enable, disable=disable) + + if service.is_enabled(): + add_shortcut() class ReproServiceView(ServiceView): @@ -83,6 +87,24 @@ def setup(helper, old_version=None): helper.install(managed_packages) helper.call('post', actions.superuser_run, 'repro', ['setup']) helper.call('post', service.notify_enabled, None, True) + helper.call('post', add_shortcut) + + +def add_shortcut(): + frontpage.add_shortcut('repro', title, '?selected=repro', + 'glyphicon-phone-alt', description) + + +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Disable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('repro') def diagnose(): diff --git a/plinth/templates/index.html b/plinth/templates/index.html index 120911db9..d434e9421 100644 --- a/plinth/templates/index.html +++ b/plinth/templates/index.html @@ -22,17 +22,23 @@ {% block content %} +
{% if shortcuts %} {% for shortcut in shortcuts %}
{% endfor %} @@ -50,6 +56,22 @@ {% endif %} +
+ +
+ {% if details %} +
+
+

{{ details_label }}

+
+ + {% for paragraph in details %} +
+ {{ paragraph|safe }} +
+ {% endfor %} +
+ {% endif %} {% endblock %} diff --git a/plinth/views.py b/plinth/views.py index 0e5d2f6cb..f79c3f88d 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -35,9 +35,20 @@ import plinth @public def index(request): """Serve the main index page.""" + shortcuts = frontpage.get_shortcuts() + selection = request.GET.get('selected') + + details, details_label = None, None + if selection in frontpage.shortcuts: + details = frontpage.shortcuts[selection]['details'] + details_label = frontpage.shortcuts[selection]['label'] + return TemplateResponse(request, 'index.html', {'title': _('FreedomBox'), - 'shortcuts': frontpage.get_shortcuts()}) + 'shortcuts': shortcuts, + 'selected_app': selection, + 'details': details, + 'details_label': details_label}) class ServiceView(FormView):