mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-10 15:44:45 +00:00
Disable view of parent source if it is a parent directory.
This commit is contained in:
parent
042a77d79e
commit
37b09d7e15
2 changed files with 18 additions and 10 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
Fixes:
|
Fixes:
|
||||||
- checking: Do not remove CGI parameters when joining URLs.
|
- checking: Do not remove CGI parameters when joining URLs.
|
||||||
- gui: Remove old context menu action to view URL properties.
|
- gui: Remove old context menu action to view URL properties.
|
||||||
|
- gui: Disable viewing of parent URL source if its a local directory.
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
- gui: Use Alt-key shortcuts for menu entries.
|
- gui: Use Alt-key shortcuts for menu entries.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
import os
|
||||||
|
import urlparse
|
||||||
|
from linkcheck.checker.fileurl import get_os_filename
|
||||||
|
|
||||||
class ContextMenu (QtGui.QMenu):
|
class ContextMenu (QtGui.QMenu):
|
||||||
"""Show context menu."""
|
"""Show context menu."""
|
||||||
|
|
@ -29,22 +32,26 @@ class ContextMenu (QtGui.QMenu):
|
||||||
def enableFromItem (self, item):
|
def enableFromItem (self, item):
|
||||||
"""Enable context menu actions depending on the item content."""
|
"""Enable context menu actions depending on the item content."""
|
||||||
parent = self.parentWidget()
|
parent = self.parentWidget()
|
||||||
|
# data is an instance of CompactUrlData
|
||||||
data = item.url_data
|
data = item.url_data
|
||||||
# enable view online actions
|
# enable view online actions
|
||||||
parent.actionViewOnline.setEnabled(bool(data.url))
|
parent.actionViewOnline.setEnabled(bool(data.url))
|
||||||
parent.actionViewParentOnline.setEnabled(bool(data.parent_url))
|
parent.actionViewParentOnline.setEnabled(bool(data.parent_url))
|
||||||
# enable view source actions
|
# enable view source actions
|
||||||
enable_parent_url_source = self.can_view_source(data.parent_url)
|
enable_parent_url_source = self.can_view_parent_source(data)
|
||||||
parent.actionViewParentSource.setEnabled(enable_parent_url_source)
|
parent.actionViewParentSource.setEnabled(enable_parent_url_source)
|
||||||
|
|
||||||
def can_view_source (self, url, result=None):
|
def can_view_parent_source (self, url_data):
|
||||||
"""Determine if URL source could be retrieved."""
|
"""Determine if parent URL source can be retrieved."""
|
||||||
if not url:
|
if not url_data.valid:
|
||||||
return False
|
return False
|
||||||
if result and result.startswith(u"Error"):
|
parent = url_data.parent_url
|
||||||
|
if not parent:
|
||||||
return False
|
return False
|
||||||
return (url.startswith(u"http:") or
|
if parent.startswith(u"file:"):
|
||||||
url.startswith(u"https:") or
|
urlparts = urlparse.urlsplit(parent)
|
||||||
url.startswith(u"ftp:") or
|
return not os.path.isdir(get_os_filename(urlparts[2]))
|
||||||
url.startswith(u"ftps:") or
|
return (parent.startswith(u"http:") or
|
||||||
url.startswith(u"file:"))
|
parent.startswith(u"https:") or
|
||||||
|
parent.startswith(u"ftp:") or
|
||||||
|
parent.startswith(u"ftps:"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue