bool QNetworkReplyProto::isOpen() const { QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject()); if (item) return item->isOpen(); return false; }
// Finished uploading an image void ShareOnline::Imgur::uploadFinished() { // The sending network reply QNetworkReply *reply = (QNetworkReply*)(sender()); // The reply is not open when operation was aborted if(!reply->isOpen()) { emit imgurImageUrl(""); emit finished(); return; } // Read output from finished network reply QString resp = reply->readAll(); // Delete sender object reply->deleteLater(); // If there has been an error... if(resp.contains("success=\"0\"")) { if(debug) { QString errorMsg = resp.split("<error>").at(1).split("</error>").at(0); LOG << CURDATE << QString("ERROR! An error occured. Error message: %1").arg(errorMsg).toStdString() << NL; } emit finished(); return; } // If data doesn't contain a valid link, something went wrong if(!resp.contains("<link>") || !resp.contains("<deletehash>")) { if(debug) LOG << CURDATE << QString("ERROR! Invalid return data received: %1").arg(resp).toStdString() << NL; emit finished(); return; } // Read out the link QString imgLink = resp.split("<link>").at(1).split("</link>").at(0); QString delHash = resp.split("<deletehash>").at(1).split("</deletehash>").at(0); // and tell the user emit imgurImageUrl(imgLink); emit imgurDeleteHash(delHash); emit finished(); }
// creates a total download progress for multiple QNetworkReplies void SettingsDialog::downloadProgress(qint64 received, qint64 total) { // Don't show progress for non-docset pages if (total == -1 || received < 10240) return; QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); if (!reply || !reply->isOpen()) return; if (reply->property(DownloadTypeProperty).toInt() == DownloadDocset) { const QString docsetName = reply->property(DocsetNameProperty).toString(); QTemporaryFile *tmpFile = m_tmpFiles[docsetName]; if (!tmpFile) { tmpFile = new QTemporaryFile(this); tmpFile->open(); m_tmpFiles.insert(docsetName, tmpFile); } tmpFile->write(reply->read(received)); } // Try to get the item associated to the request QListWidgetItem *item = ui->availableDocsetList->item(reply->property(ListItemIndexProperty).toInt()); if (item) item->setData(ProgressItemDelegate::ValueRole, percent(received, total)); qint64 previousReceived = 0; const QVariant previousReceivedVariant = reply->property(DownloadPreviousReceived); if (!previousReceivedVariant.isValid()) m_combinedTotal += total; else previousReceived = previousReceivedVariant.toLongLong(); m_combinedReceived += received - previousReceived; reply->setProperty(DownloadPreviousReceived, received); displayProgress(); }