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