コード例 #1
0
MsgPartNetworkReply::MsgPartNetworkReply(MsgPartNetAccessManager *parent, const QPersistentModelIndex &part, bool requireFormatting):
    QNetworkReply(parent), part(part), formattedBufferContent(0), requireFormatting(requireFormatting)
{
    QUrl url;
    url.setScheme(QLatin1String("trojita-imap"));
    url.setHost(QLatin1String("msg"));
    url.setPath(part.data(Imap::Mailbox::RolePartPathToPart).toString());
    setUrl(url);

    setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
    Q_ASSERT(part.isValid());
    const Mailbox::Model *model = 0;
    Mailbox::Model::realTreeItem(part, &model);
    Q_ASSERT(model);

    connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotModelDataChanged(QModelIndex,QModelIndex)));

    //TODO: fileDownloadProgress signal in model signal the process of the current download.
    //      This reply might not be the current download, but now we assume that because the only use case here
    //      is just see the download progress of attachments that is usually the only downloading event.
    //      Should match message UID and partId and then emit downloadProgress.
    connect(model, SIGNAL(fileDownloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));

    Mailbox::TreeItemPart *partPtr = dynamic_cast<Mailbox::TreeItemPart *>(static_cast<Mailbox::TreeItem *>(part.internalPointer()));
    Q_ASSERT(partPtr);

    // We have to ask for contents before we check whether it's already fetched
    partPtr->fetch(const_cast<Mailbox::Model *>(model));
    // The part data might be already unavailable or already fetched
    QTimer::singleShot(0, this, SLOT(slotMyDataChanged()));

    buffer.setBuffer(partPtr->dataPtr());
    buffer.open(QIODevice::ReadOnly);
}
コード例 #2
0
ファイル: utils.cpp プロジェクト: mkiol/Ubi
void Utils::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
    //qDebug() << "progres: " << 100*bytesReceived/cur_size << "%";

    float progress = (float)bytesReceived/cur_size;

    emit fileDownloadProgress(cur_filename,progress);
}
コード例 #3
0
qint64 QGitHubReleaseAPIPrivate::downloadFile(const QUrl &u, QIODevice *of, bool generic) const {

	m_readBytes = Q_INT64_C(-1);

	if(of) {

		QEventLoop wait;
		FileDownloader dl(u, m_userAgent, m_eTag);

		m_dlOutputFile = of;

		dl.setCacheLoadControlAttribute(QNetworkRequest::PreferCache);
		dl.setGeneric(generic);

		QObject::connect(&dl, SIGNAL(canceled()), &wait, SLOT(quit()));
		QObject::connect(&dl, SIGNAL(error(QString)), &wait, SLOT(quit()));
		QObject::connect(&dl, SIGNAL(downloaded(FileDownloader)), &wait, SLOT(quit()));
		QObject::connect(&dl, SIGNAL(replyChanged(QNetworkReply*)),
						 this, SLOT(updateReply(QNetworkReply*)));
		QObject::connect(&dl, SIGNAL(canceled()), this, SLOT(fdCanceled()));
		QObject::connect(&dl, SIGNAL(error(QString)), this, SLOT(fileDownloadError(QString)));
		QObject::connect(&dl, SIGNAL(progress(qint64,qint64)),
						 this, SLOT(fileDownloadProgress(qint64,qint64)));

		m_readReply = dl.start(QGitHubReleaseAPI::RAW);

		QObject::connect(m_readReply, SIGNAL(readyRead()), this, SLOT(readChunk()));
		wait.exec();

		m_dlOutputFile = 0L;
	}

	m_readReply = 0L;

	return m_readBytes;
}