示例#1
0
	void MediaModel::onTorrentRemoved(bt::TorrentInterface* tc)
	{
		int start = -1;
		int cnt = 0;
		for (QList<MediaFile::Ptr>::iterator i = items.begin();i != items.end();i++)
		{
			MediaFile::Ptr p = *i;
			if (p->torrent() == tc)
			{
				if (start == -1)
				{
					// start of the range
					start = i - items.begin();
					cnt = 1;
				}
				else
					cnt++; // Still in the middle of the media files of this torrent
			}
			else if (start != -1)
			{
				// We have found the end
				break;
			}
		}
		
		if (cnt > 0)
			removeRows(start,cnt,QModelIndex());
	}
示例#2
0
    void VideoChunkBar::drawBarContents(QPainter* p)
    {
        ChunkBar::drawBarContents(p);

        MediaFile::Ptr file = mfile.mediaFile();
        if (!file)
            return;

        bt::TorrentFileStream::Ptr stream = file->stream().toStrongRef();
        if (!stream)
            return;

        current_chunk = stream->currentChunk();
        qreal f = (qreal)current_chunk / bitset.getNumBits();
        int x = (int)(f * contentsRect().width());

        QStyleOptionSlider option;
        option.orientation = Qt::Horizontal;
        option.minimum = 0;
        option.maximum = bitset.getNumBits();
        option.tickPosition = QSlider::NoTicks;
        //option.sliderValue = current_chunk;
        option.sliderPosition = current_chunk;
        option.rect = QRect(x - 5, 0, 11, contentsRect().height());

        KApplication::style()->drawControl(QStyle::CE_ScrollBarSlider, &option, p, this);
    }
示例#3
0
    bool MediaViewFilter::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
    {
        if (show_incomplete)
            return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);

        MediaModel* model = (MediaModel*)sourceModel();
        MediaFileRef ref = model->fileForIndex(model->index(source_row));
        MediaFile::Ptr file = ref.mediaFile();
        if (file->fullyAvailable())
            return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
        else
            return false;
    }
示例#4
0
	QVariant MediaModel::data(const QModelIndex & index, int role) const
	{
		if (index.column() != 0 || index.row() < 0 || index.row() >= items.count())
			return QVariant();
		
		MediaFile::Ptr mf = items.at(index.row());
		switch (role)
		{
			case Qt::ToolTipRole:
				{
					QString preview = mf->previewAvailable() ? i18n("Available") : i18n("Pending");
					return i18n("<b>%1</b><br/>Preview: %2<br/>Downloaded: %3 %",
							mf->name(),preview,mf->downloadPercentage());
				}
				break;
			case Qt::DisplayRole:
				return mf->name();
			case Qt::DecorationRole:
				return KIcon(KMimeType::findByPath(mf->path())->iconName());
			case Qt::UserRole: // user role is for finding out if a torrent is complete
				return mf->fullyAvailable();
			case Qt::UserRole + 1:
				return QFileInfo(mf->path()).lastModified().toTime_t();
			default:
				return QVariant();
		}
		
		return QVariant();
	}
示例#5
0
    void VideoChunkBar::timeElapsed(qint64 time)
    {
        Q_UNUSED(time);
        MediaFile::Ptr file = mfile.mediaFile();
        if (!file)
            return;

        bt::TorrentFileStream::Ptr stream = file->stream().toStrongRef();
        if (!stream)
            return;

        if (current_chunk != stream->currentChunk() || stream->chunksBitSet() != bitset)
            updateChunkBar();
    }
示例#6
0
 void VideoChunkBar::updateBitSet()
 {
     MediaFile::Ptr file = mfile.mediaFile();
     if (file)
     {
         bt::TorrentFileStream::Ptr stream = file->stream().toStrongRef();
         if (stream)
             bitset = stream->chunksBitSet();
         else
             bitset.clear();
     }
     else
         bitset.clear();
 }
示例#7
0
    void VideoChunkBar::setMediaFile(const kt::MediaFileRef& mf)
    {
        mfile = mf;
        MediaFile::Ptr file = mfile.mediaFile();
        if (file && !file->fullyAvailable())
        {
            bt::TorrentFileStream::Ptr stream = file->stream().toStrongRef();
            if (stream)
                connect(stream.data(), SIGNAL(readyRead()), this, SLOT(updateChunkBar()));

            updateBitSet();
            updateChunkBar();
        }
    }
示例#8
0
		foreach (MediaFile::Ptr mf,items)
		{
			if (mf->path() == path)
				return MediaFileRef(mf);
		}