Commits

Simon H. committed 439a88e

qtlib: new method openlocalurl for opening a local url

It allows to explore something located on a network share.
Additionally the path is converted to unicode if necessary.

Comments (0)

Files changed (1)

tortoisehg/hgqt/qtlib.py

             chm = os.path.join(paths.bin_path, 'doc', 'TortoiseHg.chm')
             if os.path.exists(chm):
                 fullurl = (r'mk:@MSITStore:%s::/' % chm) + url
-                QDesktopServices.openUrl(QUrl.fromLocalFile(fullurl))
+                openlocalurl(fullurl)
                 return
         QDesktopServices.openUrl(QUrl(fullurl))
 
+def startswith(strQstring, startstr):
+    '''calls startsWith of QString or startswith for others
+
+    takes st, unicode or QString as strQstring'''
+
+     if isinstance(strQstring, QString):
+        return strQstring.startsWith(startstr)
+    else:
+        return strQstring.startswith(startstr)
+
+def openlocalurl(path):
+    '''open the given path with the default application
+
+    takes str, unicode or QString as argument'''
+
+    if isinstance(path, str):
+        path = hglib.tounicode(path)
+    if os.name == 'nt' and startswith(path, '\\\\'):
+        # network share, special handling because of qt bug 13359
+        # see http://bugreports.qt.nokia.com/browse/QTBUG-13359
+        qurl = QUrl().setUrl(QDir.toNativeSeparators(path))
+    else:
+        qurl = QUrl.fromLocalFile(path)
+    return QDesktopServices.openUrl(qurl)
+
 def editfiles(repo, files, lineno=None, search=None, parent=None):
     if len(files) == 1:
         path = repo.wjoin(files[0])