First version of directory browser.
This commit is contained in:
parent
0acbd77ada
commit
c8d3fc57c2
55
qutebrowser/browser/dirbrowser.py
Normal file
55
qutebrowser/browser/dirbrowser.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2015 Antoni Boucher (antoyo) <bouanto@zoho.com>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""The directory browser page."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from qutebrowser.utils import jinja
|
||||||
|
|
||||||
|
|
||||||
|
def dirbrowser(url):
|
||||||
|
"""Get the directory browser web page.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The directory path.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The HTML of the web page.
|
||||||
|
"""
|
||||||
|
title = "Browse directory: {}".format(url)
|
||||||
|
template = jinja.env.get_template('dirbrowser.html')
|
||||||
|
# pylint: disable=no-member
|
||||||
|
# https://bitbucket.org/logilab/pylint/issue/490/
|
||||||
|
|
||||||
|
def is_file(file):
|
||||||
|
return os.path.isfile(os.path.join(url, file))
|
||||||
|
|
||||||
|
def is_dir(file):
|
||||||
|
return os.path.isdir(os.path.join(url, file))
|
||||||
|
|
||||||
|
parent = os.path.dirname(url)
|
||||||
|
all_files = os.listdir(url)
|
||||||
|
files = sorted([(file, os.path.join(url, file)) for file in all_files if
|
||||||
|
is_file(file)])
|
||||||
|
directories = sorted([(file, os.path.join(url, file)) for file in
|
||||||
|
all_files if is_dir(file)])
|
||||||
|
html = template.render(title=title, url=url, icon='', parent=parent,
|
||||||
|
files=files, directories=directories)
|
||||||
|
return html
|
@ -31,6 +31,7 @@ from PyQt5.QtWebKitWidgets import QWebPage
|
|||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.browser import http, tabhistory
|
from qutebrowser.browser import http, tabhistory
|
||||||
|
from qutebrowser.browser.dirbrowser import dirbrowser
|
||||||
from qutebrowser.browser.network import networkmanager
|
from qutebrowser.browser.network import networkmanager
|
||||||
from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils,
|
from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils,
|
||||||
objreg, debug)
|
objreg, debug)
|
||||||
@ -158,6 +159,12 @@ class BrowserPage(QWebPage):
|
|||||||
if QUrl(elem.attribute('src')) == info.url:
|
if QUrl(elem.attribute('src')) == info.url:
|
||||||
elem.setAttribute('style', 'display: none')
|
elem.setAttribute('style', 'display: none')
|
||||||
return False
|
return False
|
||||||
|
elif (error_str.endswith('Path is a directory') and
|
||||||
|
info.url.scheme() == 'file'):
|
||||||
|
html = dirbrowser(info.url.url()[7:])
|
||||||
|
errpage.content = html.encode('utf-8')
|
||||||
|
errpage.encoding = 'utf-8'
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self._ignore_load_started = True
|
self._ignore_load_started = True
|
||||||
self.error_occurred = True
|
self.error_occurred = True
|
||||||
|
43
qutebrowser/html/dirbrowser.html
Normal file
43
qutebrowser/html/dirbrowser.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block style %}
|
||||||
|
{{ super() }}
|
||||||
|
#dirbrowserContainer {
|
||||||
|
background: #fff;
|
||||||
|
min-width: 35em;
|
||||||
|
max-width: 35em;
|
||||||
|
position: absolute;
|
||||||
|
top: 2em;
|
||||||
|
left: 1em;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px solid #eee;
|
||||||
|
-webkit-border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dirbrowserTitleText {
|
||||||
|
font-size: 118%;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div id="dirbrowserContainer">
|
||||||
|
<div id="dirbrowserTitle">
|
||||||
|
<p id="dirbrowserTitleText">Browse directory: {{url}}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% if parent %}
|
||||||
|
<li><a href="{{parent}}">..</a></li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for item in directories %}
|
||||||
|
<li><a href="file://{{item.1}}">{{item.0}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for item in files %}
|
||||||
|
<li><a href="file://{{item.1}}">{{item.0}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user