Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

# -*- coding: UTF-8 -*- 

# Copyright 2014-2015 Luc Saffre 

# License: BSD (see file COPYING for details) 

 

"""Adds actions for editing printable documents on a server with 

:doc:`/admin/webdav`. 

 

When this plugin is installed, you can still easily disable it by 

setting :attr:`use_java <lino.core.site.Site.use_java>` to `False` in 

your :xfile:`settings.py`. 

 

When this plugin is enabled, then you must also add the `.jar` files 

required by :ref:`davlink` into your media directory, in a 

subdirectory named "davlink".  TODO: move :ref:`davlink` to a `static` 

directory in the Lino repository. 

 

""" 

 

import os 

from lino.api import ad 

import jinja2 

 

 

class Plugin(ad.Plugin): 

    "See :doc:`/dev/plugins`." 

 

    site_js_snippets = ['davlink/davlink.js'] 

 

    media_name = 'davlink' 

 

    def get_body_lines(self, site, request): 

        if not site.use_java: 

            return 

        # jar = self.build_media_url('DavLink.jar') 

        # jar = request.build_absolute_uri(jar) 

        jnlp = site.build_media_url(*self.jnlp_file_parts()) 

        # jnlp = request.build_absolute_uri(jnlp) 

        # yield '<applet code="davlink.DavLink"' 

        yield '<applet name="DavLink" code="davlink.DavLink"' 

        # yield '        archive="%s"' % jar 

        yield '        width="1" height="1">' 

        # yield '<param name="separate_jvm" value="true">' # 20130913 

        # yield '<param name="permissions" value="all-permissions">' 

        yield '<param name="jnlp_href" value="%s">' % jnlp 

        yield '</applet>' 

 

    def write_jnlp_file(self, f): 

        context = dict( 

            site=self.site, 

            davlink=self, 

        ) 

        env = jinja2.Environment(loader=jinja2.FileSystemLoader( 

            os.path.dirname(__file__))) 

        tpl = env.get_template('template.jnlp') 

        f.write(tpl.render(**context)) 

 

    def on_ui_init(self, kernel): 

        fn = os.path.join(*self.jnlp_file_parts()) 

        kernel.make_cache_file(fn, self.write_jnlp_file) 

 

    def jnlp_file_parts(self): 

        return ('cache', self.media_name + '.jnlp')