summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/local/bin/tails-documentation
diff options
context:
space:
mode:
Diffstat (limited to 'config/chroot_local-includes/usr/local/bin/tails-documentation')
-rwxr-xr-xconfig/chroot_local-includes/usr/local/bin/tails-documentation131
1 files changed, 106 insertions, 25 deletions
diff --git a/config/chroot_local-includes/usr/local/bin/tails-documentation b/config/chroot_local-includes/usr/local/bin/tails-documentation
index 6a99cb6..2e2082e 100755
--- a/config/chroot_local-includes/usr/local/bin/tails-documentation
+++ b/config/chroot_local-includes/usr/local/bin/tails-documentation
@@ -1,25 +1,106 @@
-#! /bin/sh
-
-if [ $# -ge 1 ]; then
- PAGE="$1"
-else
- PAGE='index'
-fi
-
-WIKI_ROOT='/usr/share/doc/tails/website'
-LANG_CODE="`echo ${LANG} | head -c 2`"
-
-if [ -r "${WIKI_ROOT}/${PAGE}.${LANG_CODE}.html" ]; then
- FILE="${PAGE}.${LANG_CODE}.html"
-elif [ -r "${WIKI_ROOT}/${PAGE}.en.html" ]; then
- FILE="${PAGE}.en.html"
-else
- FILE="${PAGE}.html"
-fi
-
-if [ -n "${2}" ]; then
- FILE="${FILE}#${2}"
-fi
-
-export TOR_BROWSER_SKIP_OFFLINE_WARNING=yes
-exec /usr/local/bin/tor-browser "file://${WIKI_ROOT}/${FILE}"
+#!/usr/bin/env python3
+
+import gettext
+import gi
+import locale
+import os
+import os.path
+import sys
+import tailsgreeter.gui
+
+gi.require_version('Gdk', '3.0')
+from gi.repository import Gdk # NOQA: E402
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk # NOQA: E402
+gi.require_version('WebKit2', '4.0')
+from gi.repository import WebKit2 # NOQA: E402
+
+# We'll only use a single translation, "Tails documentation", which
+# already is translated for the launcher. For this reason, this script
+# is not managed by `refresh-translations`.
+gettext.textdomain('tails')
+
+# The browser from the Greeter is good as-is, but a button for
+# navigating backwards in the history would be nice.
+class DocumentationWindow(tailsgreeter.gui.GreeterHelpWindow):
+ def _build_ui(self):
+ super()._build_ui()
+ # The super class' headerbar is not exposed as an instance
+ # variable, but we need it!
+ headerbar = next(child for child in self.get_children() \
+ if isinstance(child, Gtk.HeaderBar))
+ back_button = Gtk.Button.new_from_icon_name('back', Gtk.IconSize.BUTTON)
+ back_button.connect("clicked", lambda x: self.webview.go_back())
+ headerbar.pack_start(back_button)
+ back_button.show()
+ self.webview.connect(
+ "load-changed",
+ lambda webview, e: back_button.set_visible(webview.can_go_back())
+ )
+ self.find_entry = Gtk.Entry()
+ self.find_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY,
+ "search")
+ self.find_entry.connect("activate", self.find_forward)
+ self.find_entry.connect("changed", self.find_forward)
+ self.find_entry.connect("key-press-event", self.cb_find_entry_key_press)
+ headerbar.pack_end(self.find_entry)
+ self.find_entry.show()
+ accelgroup = Gtk.AccelGroup.new()
+ self.add_accel_group(accelgroup)
+ accelgroup.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK, 0,
+ lambda *args: self.find_entry.grab_focus())
+
+ def cb_load_started(self, webview, ressource, request):
+ super().cb_load_started(webview, ressource, request)
+ if not request.get_uri().startswith("file://"):
+ # An external link was clicked, let's abort following it
+ # in our WebKit browser; any configured external protocol
+ # handler will still open the link's uri.
+ webview.stop_loading()
+
+ def find_forward(self, entry, user_data=None):
+ find_controller = self.webview.get_find_controller()
+ find_options = WebKit2.FindOptions.CASE_INSENSITIVE | \
+ WebKit2.FindOptions.WRAP_AROUND
+ find_controller.search(self.find_entry.get_text(), find_options, 32)
+
+ def find_previous(self):
+ find_controller = self.webview.get_find_controller()
+ find_controller.search_previous()
+
+ def find_finish(self):
+ find_controller = self.webview.get_find_controller()
+ find_controller.search_finish()
+ self.find_entry.set_text('')
+ self.webview.grab_focus()
+
+ def cb_find_entry_key_press(self, entry, event, user_data=None):
+ if event.keyval == Gdk.KEY_Return and event.state & Gdk.ModifierType.SHIFT_MASK:
+ self.find_previous()
+ if event.keyval == Gdk.KEY_Escape:
+ self.find_finish()
+
+# Main
+
+try:
+ page = sys.argv[1]
+except IndexError:
+ page = 'getting_started'
+wiki_path = '/usr/share/doc/tails/website'
+lang_code = os.getenv('LANG', 'en')[0:2]
+trials = [
+ os.path.join(wiki_path, page + code + ".html")
+ for code in ['.' + lang_code, '.en', '']
+]
+try:
+ uri = 'file://' + next(trial for trial in trials if os.path.isfile(trial))
+except StopIteration:
+ sys.exit('error: could not find the requested documentation page')
+if '..' in uri.split(os.sep):
+ sys.exit('error: cannot escape from {}'.format(wiki_path))
+
+helpwindow = DocumentationWindow(uri)
+helpwindow.connect("delete-event", Gtk.main_quit)
+helpwindow.window.set_title(gettext.gettext('Tails documentation'))
+helpwindow.show()
+Gtk.main()