示例#1
0
    def action(self):
        """Save the entered text to the BookmarkDB."""
        index = self.parent().selectionModel().currentIndex()
        text = u'{}'.format(index.data(common.DescriptionRole))
        if text.lower() == self.text().lower():
            self.hide()
            return

        if not index.data(common.ParentPathRole):
            self.hide()
            return

        p = index.data(QtCore.Qt.StatusTipRole)
        if common.is_collapsed(p):
            k = common.proxy_path(index)
        else:
            k = p

        db = bookmark_db.get_db(
            index.data(common.ParentPathRole)[0],
            index.data(common.ParentPathRole)[1],
            index.data(common.ParentPathRole)[2]
        )
        db.setValue(k, u'description', self.text())

        source_index = index.model().mapToSource(index)
        data = source_index.model().model_data()[source_index.row()]
        data[common.DescriptionRole] = self.text()
        self.parent().update(source_index)
        self.hide()
示例#2
0
    def dropEvent(self, event):
        """Event responsible for adding the dropped file to the favourites."""
        self.indicatorwidget.hide()

        if event.source() == self:
            return  # Won't allow dropping an item from itself

        mime = event.mimeData()
        if not mime.hasUrls():
            return

        event.accept()
        favourites = settings.local_settings.favourites()

        for url in mime.urls():
            file_info = QtCore.QFileInfo(url.toLocalFile())
            path = file_info.filePath().lower()

            if file_info.suffix().lower() == u'favourites':
                common.import_favourites(source=path)
            else:
                k = common.proxy_path(path).lower()
            favourites.append(k)
        settings.local_settings.setValue(u'favourites',
                                         sorted(list(set(favourites))))
        self.favouritesChanged.emit()
示例#3
0
    def refresh(self):
        """Populates the list from the database."""
        if not self.parent():
            return
        if not self.index.isValid():
            return
        if not self.index.data(common.FileInfoLoaded):
            return

        db = bookmark_db.get_db(
            self.index.data(common.ParentPathRole)[0],
            self.index.data(common.ParentPathRole)[1],
            self.index.data(common.ParentPathRole)[2])
        if self.index.data(common.TypeRole) == common.FileItem:
            k = self.index.data(QtCore.Qt.StatusTipRole)
        elif self.index.data(common.TypeRole) == common.SequenceItem:
            k = common.proxy_path(self.index)

        v = db.value(k, u'notes')
        if not v:
            return

        try:
            v = base64.b64decode(v)
            d = json.loads(v)
        except:
            log.error(u'Error decoding notes from JSON')
            return

        if not v:
            return

        self.clear()

        keys = sorted(d.keys())
        try:
            for k in keys:
                self.add_item(text=d[k][u'text'], checked=d[k][u'checked'])
        except:
            log.error(u'Error adding notes')
            common_ui.ErrorBox(u'Error refreshing the data', u'').open()
            raise
示例#4
0
    def _entry_iterator(self, path):
        """We're using the saved keys to find and return the DirEntries
        corresponding to the saved favourites.

        """
        favourites = settings.local_settings.favourites()

        d = []

        for k in favourites:
            file_info = QtCore.QFileInfo(k)
            for entry in _scandir.scandir(file_info.path()):
                path = entry.path.replace(u'\\', u'/').lower()
                if path == k:
                    d.append(entry)
                    continue
                _k = common.proxy_path(path)
                if k.lower() == _k.lower():
                    d.append(entry)
        for entry in d:
            yield entry
示例#5
0
    def save_settings(self):
        """Saves the current list of todo items to the assets configuration file."""
        if not self.index.isValid():
            return

        data = {}
        for n in xrange(len(self.todoeditors_widget.items)):
            item = self.todoeditors_widget.items[n]
            editor = item.findChild(TodoItemEditor)
            checkbox = item.findChild(CheckBoxButton)
            if not editor.document().toPlainText():
                continue
            data[n] = {
                u'checked': not checkbox.checked,
                u'text': editor.document().toHtml(),
            }

        k = common.proxy_path(self.index)
        db = bookmark_db.get_db(
            self.index.data(common.ParentPathRole)[0],
            self.index.data(common.ParentPathRole)[1],
            self.index.data(common.ParentPathRole)[2])

        try:
            v = json.dumps(data, ensure_ascii=False, encoding='utf-8')
            v = base64.b64encode(v.encode('utf-8'))
        except:
            s = u'Error saving notes.'
            log.error(s)
            common_ui.ErrorBox(u'Error saving notes.', s).open()
            raise

        db.setValue(k, u'notes', v)
        todo_count = len([k for k in data if not data[k][u'checked']])
        self.index.model().setData(self.index,
                                   todo_count,
                                   role=common.TodoCountRole)
示例#6
0
    def process_data(self, ref):
        """Populates the item with the missing file information.

        Args:
            ref (weakref): An internal model data DataDict instance's weakref.

        Returns:
            bool: `True` if all went well, `False` otherwise.

        """
        def is_valid():
            return False if not ref() or self.interrupt or ref()[
                common.FileInfoLoaded] else True

        if not is_valid():
            return False

        try:
            pp = ref()[common.ParentPathRole]
            db = bookmark_db.get_db(pp[0], pp[1], pp[2])

            if not is_valid():
                return False

            collapsed = common.is_collapsed(ref()[QtCore.Qt.StatusTipRole])
            seq = ref()[common.SequenceRole]

            if not is_valid():
                return False
            proxy_k = common.proxy_path(ref())
            if collapsed:
                k = proxy_k
            else:
                if not is_valid():
                    return False
                k = ref()[QtCore.Qt.StatusTipRole]

            # Issues SQLite "BEGIN"
            with db.transactions():
                # Description
                v = db.value(k, u'description')
                if v:
                    if not is_valid():
                        return False
                    ref()[common.DescriptionRole] = v

                v = db.value(k, u'notes')
                count = 0
                if v:
                    try:
                        v = base64.b64decode(v)
                        v = json.loads(v)
                        count = [
                            k for k in v
                            if v[k][u'text'] and not v[k][u'checked']
                        ]
                        count = len(count)
                    except:
                        log.error(u'Could not read notes')

                if not is_valid():
                    return False
                ref()[common.TodoCountRole] = count

                # Item flags
                if not is_valid():
                    return False
                flags = ref(
                )[common.
                  FlagsRole] | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsDragEnabled

                v = db.value(k, u'flags')
                if v:
                    flags = flags | v
                v = db.value(proxy_k, u'flags')
                if v:
                    flags = flags | v

                if not is_valid():
                    return False
                ref()[common.FlagsRole] = flags

            # For sequences we will work out the name of the sequence based on
            # the frames.
            if not is_valid():
                return False
            if ref()[common.TypeRole] == common.SequenceItem:
                if not is_valid():
                    return False
                frs = ref()[common.FramesRole]
                intframes = [int(f) for f in frs]
                padding = len(frs[0])
                rangestring = common.get_ranges(intframes, padding)

                if not is_valid():
                    return False
                seq = ref()[common.SequenceRole]
                startpath = \
                    seq.group(1) + \
                    unicode(min(intframes)).zfill(padding) + \
                    seq.group(3) + \
                    u'.' + \
                    seq.group(4)
                endpath = \
                    seq.group(1) + \
                    unicode(max(intframes)).zfill(padding) + \
                    seq.group(3) + \
                    u'.' + \
                    seq.group(4)
                seqpath = \
                    seq.group(1) + \
                    u'[' + rangestring + u']' + \
                    seq.group(3) + \
                    u'.' + \
                    seq.group(4)
                seqname = seqpath.split(u'/')[-1]

                # Setting the path names
                if not is_valid():
                    return False
                ref()[common.StartpathRole] = startpath
                if not is_valid():
                    return False
                ref()[common.EndpathRole] = endpath
                if not is_valid():
                    return False
                ref()[QtCore.Qt.StatusTipRole] = seqpath
                if not is_valid():
                    return False
                ref()[QtCore.Qt.ToolTipRole] = seqpath
                if not ref():
                    return False
                ref()[QtCore.Qt.DisplayRole] = seqname
                if not is_valid():
                    return False
                ref()[QtCore.Qt.EditRole] = seqname
                if not is_valid():
                    return False
                # We saved the DirEntry instances previously in `__initdata__` but
                # only for the thread to extract the information from it.
                if not is_valid():
                    return False
                er = ref()[common.EntryRole]
                if er:
                    mtime = 0
                    for entry in er:
                        stat = entry.stat()
                        mtime = stat.st_mtime if stat.st_mtime > mtime else mtime
                        if not is_valid():
                            return False
                        ref()[common.SortBySizeRole] += stat.st_size
                    if not is_valid():
                        return False
                    ref()[common.SortByLastModifiedRole] = mtime
                    mtime = common.qlast_modified(mtime)

                    if not is_valid():
                        return False
                    info_string = \
                        unicode(len(intframes)) + u'f;' + \
                        mtime.toString(u'dd') + u'/' + \
                        mtime.toString(u'MM') + u'/' + \
                        mtime.toString(u'yyyy') + u' ' + \
                        mtime.toString(u'hh') + u':' + \
                        mtime.toString(u'mm') + u';' + \
                        common.byte_to_string(ref()[common.SortBySizeRole])
                    if not is_valid():
                        return False
                    ref()[common.FileDetailsRole] = info_string

            if not is_valid():
                return False
            if ref()[common.TypeRole] == common.FileItem:
                if not is_valid():
                    return False
                er = ref()[common.EntryRole]
                if er:
                    stat = er[0].stat()
                    mtime = stat.st_mtime
                    ref()[common.SortByLastModifiedRole] = mtime
                    mtime = common.qlast_modified(mtime)
                    ref()[common.SortBySizeRole] = stat.st_size
                    info_string = \
                        mtime.toString(u'dd') + u'/' + \
                        mtime.toString(u'MM') + u'/' + \
                        mtime.toString(u'yyyy') + u' ' + \
                        mtime.toString(u'hh') + u':' + \
                        mtime.toString(u'mm') + u';' + \
                        common.byte_to_string(ref()[common.SortBySizeRole])
                    if not is_valid():
                        return False
                    ref()[common.FileDetailsRole] = info_string
                if not is_valid():
                    return False

            # Finally, set flag to mark this loaded
            if not is_valid():
                return False
            return True
        except:
            log.error(u'Error processing file info.')
        finally:
            if ref():
                ref()[common.FileInfoLoaded] = True