open external urls in browser

This commit is contained in:
j 2015-11-19 15:11:18 +01:00
parent a400afc923
commit 13e360ac97
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@
import os
from os.path import dirname, abspath
import subprocess
import webbrowser
import gi
gi.require_version('WebKit2', '4.0')
@ -21,6 +22,14 @@ def on_key_press_event(widget, event):
if event.state & Gdk.ModifierType.CONTROL_MASK and event.keyval == 113:
Gtk.main_quit()
def on_decide_policy(view, decision, dtype):
uri = decision.get_request().get_uri()
if uri.startswith("http") and not '127.0.0.1' in uri:
decision.ignore()
webbrowser.open_new(uri)
return True
return False
wnd = Gtk.Window()
wnd.set_icon_from_file(icon)
@ -35,6 +44,8 @@ wnd.connect('key_press_event', on_key_press_event)
wnd.add(web)
wnd.show_all()
web.connect("decide-policy", on_decide_policy)
url = 'file://' + base + '/openmedialibrary/static/html/load.html'
web.load_uri(url)

View File

@ -531,6 +531,9 @@ class File(db.Model):
j = self.item.json()
current_path = self.fullpath()
if not os.path.exists(current_path):
logger.debug('file is missing. %s', current_path)
return
author = '; '.join([ox.canonical_name(a) for a in j.get('author', [])])
if not author:
author = 'Unknown Author'