Beispiel #1
0
 def dropEvent(self, e):
     logger.debug(msg("Drag drop event"))
     file_url = QUrl(e.mimeData().text())
     if file_url.isValid() and file_url.isLocalFile():
         fname = file_url.toLocalFile()
         if fname in self.watcher.files():
             logger.debug(msg("already watching file", fname))
         else:
             self.watch_file(file_url.toLocalFile())
def resolve_path(path, collection_path, search_paths):
    """Try to resolve the SVG and image path.

    This is the procedure to check it by order:
        * It might be a full local path, check if it exists
        * It might be a url (either local file system or http(s))
        * Check in the 'svg' collection path
        * Check in the 'image' collection path
        * Check in the search_paths

    :param path: The original path.
    :type path: str

    :param collection_path: The downloaded collection path in local.
    :type collection_path: str

    :param search_paths: List of paths to search the image/svg path
    :type search_paths: str
    """
    # It might be a full path
    if QFile(path).exists():
        return QFileInfo(path).canonicalFilePath()

    # It might be a url
    if '://' in path:
        url = QUrl(path)
        if url.isValid() and url.scheme() != '':
            if url.scheme().lower() == 'file':
                # It's a url to local file
                path = url.toLocalFile()
                if QFile(path).exists():
                    return QFileInfo(path).canonicalFilePath()
            else:
                # URL to pointing to online resource
                return path

    # Check in the svg collection path
    file_name = path_leaf(path)
    svg_collection_path = os.path.join(collection_path, 'svg', file_name)
    if QFile(svg_collection_path).exists():
        return QFileInfo(svg_collection_path).canonicalFilePath()

    # Check in the image collection path
    image_collection_path = os.path.join(collection_path, 'image', file_name)
    if QFile(image_collection_path).exists():
        return QFileInfo(image_collection_path).canonicalFilePath()

    # Still not found, check in the search_paths
    for search_path in search_paths:
        local_path = os.path.join(search_path, path)
        if QFile(local_path).exists():
            return QFileInfo(local_path).canonicalFilePath()

    # Can't find any, just return the original path
    return path
Beispiel #3
0
    def update_content(self, item):
        if not item.data:
            self.clear()
            return

        html = ""
        for k in sorted(item.data):
            v = item.data[k]
            html += '<strong>%s</strong>: ' % k
            if isinstance(v, basestring):
                url = QUrl(v)
                if url.isValid() and url.scheme():
                    v = '<a href="%s">%s</a>' % (v, v)
            html += '%s<br>' % v
        self.setHtml(html)
Beispiel #4
0
    def update_content(self, item):
        if not item.data:
            self.clear()
            return

        html = ""
        self.setStyleSheet("background-color:%s;" % GRAY_WHITE.name())
        for k in sorted(item.data):
            v = item.data[k]
            html += '<strong>%s</strong>: ' % k
            if isinstance(v, basestring):
                url = QUrl(v)
                if url.isValid() and url.scheme():
                    v = '<a href="%s">%s</a>' % (v, v)
            html += '%s<br>' % v
        self.setHtml(html)
Beispiel #5
0
    def update_content(self, item):
        if not item.data:
            self.clear()
            return

        html = u""
        for k in sorted(item.data):
            v = item.data[k]
            if v is not None:
                html += '<strong>%s</strong>: ' % k
                if isinstance(v, basestring):
                    url = QUrl(v)
                    if url.isValid() and url.scheme():
                        v = '<a href="%s">%s</a>' % (v, v)
                # I thought these values were always supposed to be ascii,
                # but apparently not:
                # https://bugzilla.mozilla.org/show_bug.cgi?id=1507293
                html += '%s<br>' % str(v).decode('ascii', 'ignore')
        self.setHtml(html)
Beispiel #6
0
    def update_content(self, item):
        if not item.data:
            self.clear()
            return

        html = u""
        for k in sorted(item.data):
            v = item.data[k]
            if v is not None:
                html += '<strong>%s</strong>: ' % k
                if isinstance(v, basestring):
                    url = QUrl(v)
                    if url.isValid() and url.scheme():
                        v = '<a href="%s">%s</a>' % (v, v)
                # I thought these values were always supposed to be ascii,
                # but apparently not:
                # https://bugzilla.mozilla.org/show_bug.cgi?id=1507293
                html += '%s<br>' % str(v).decode('ascii', 'ignore')
        self.setHtml(html)
Beispiel #7
0
def cmis_base_url():
    """
    Constructs the base URL from the CMIS Atom service end point.
    :return: Returns the base URL of the CMIS server or an empty string if
    the URL cannot be constructed or if the CMIS service has not been defined.
    :rtype: str
    """
    atom_pub_url = cmis_atom_pub_url()
    if not atom_pub_url:
        return ''

    url = QUrl(atom_pub_url)
    if not url.isValid():
        return ''

    if url.port() == -1:
        port = ''
    else:
        port = ':{0}'.format(url.port())

    return '{0}://{1}{2}'.format(url.scheme(), url.host(), port)
Beispiel #8
0
 def dragEnterEvent(self, e):
     file_url = QUrl(e.mimeData().text())
     if file_url.isValid() and file_url.isLocalFile():
         e.acceptProposedAction()
     else:
         e.ignore()