Пример #1
0
 def _getHashes(self, index):
     mimeData = unwrapMime(self.libraryModel.mimeData([index]))
     item = mimeData['items'][0]
     try:
         return [item['hash']]
     except KeyError:
         if 'album' in item:
             return self.libraryModel.albumHashes(index)
     return []
Пример #2
0
    def _playlistDragDropHandle(self, event, isDropped):
        from txplayagui.client import moveTrack, libraryInsert

        mimeData = event.mimeData()

        # get row
        rowPosition = event.pos().y() - self.playlistTable.rowHeight(0)
        rowTarget = self.playlistTable.rowAt(rowPosition)

        if rowTarget == -1:
            # new row
            rowTarget = self.playlistModel.rowCount()

        if mimeData.hasUrls():
            urls = mimeData.urls()
            if len(urls) > 0:
                url = urls[0]
                if url.isLocalFile():
                    if not isDropped:
                        event.acceptProposedAction()
                        return

                    # file dropped
                    filepath = url.toLocalFile()

                    from txplayagui.client import insert
                    _ = insert(filepath, rowTarget)
                    return

        # no urls or not local file
        if not mimeData.hasText():
            return

        try:
            data = unwrapMime(mimeData)
        except ValueError:
            # invalid data passed
            return

        # check for proper flag
        source = data.get('source')
        if source not in ('playlist', 'library'):
            return

        if not isDropped:
            # drag entered
            event.acceptProposedAction()
            return

        if source == 'playlist':
            rowSource = data['row']
            moveTrack(rowSource, rowTarget)

        elif source == 'library':
            hashes = [item['hash'] for item in data['items']]
            libraryInsert(hashes, position=rowTarget)
Пример #3
0
    def onTreeViewDoubleClicked(self, index):
        mimeData = unwrapMime(self.libraryModel.mimeData([index]))[0]
        if 'hash' in mimeData:
            hashes = [mimeData['hash']]

        elif 'album' in mimeData:
            hashes = self.libraryModel.albumHashes(index)
        else:
            # artist clicked
            return

        self.itemsActivated.emit(hashes)