X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fdownloaditem.cpp;h=fe8b3b654a8f0869016a670bbd58c2b8028f432b;hb=3c8c537559e6bef5f019196b0989e95863ddd3ee;hp=1f9ca8027791ffe2dfdc076ab4aedf58d2f1cb59;hpb=a3f14b781684abfbe76b349e68a3cdaaa454c09f;p=minitube diff --git a/src/downloaditem.cpp b/src/downloaditem.cpp index 1f9ca80..fe8b3b6 100644 --- a/src/downloaditem.cpp +++ b/src/downloaditem.cpp @@ -3,6 +3,11 @@ #include "video.h" #include +#include + +#ifdef APP_MAC +#include "macutils.h" +#endif namespace The { NetworkAccess* http(); @@ -26,8 +31,14 @@ DownloadItem::DownloadItem(Video *video, QUrl url, QString filename, QObject *pa } DownloadItem::~DownloadItem() { - if (m_reply) delete m_reply; - if (video) delete video; + if (m_reply) { + delete m_reply; + m_reply = 0; + } + if (video) { + delete video; + video = 0; + } } void DownloadItem::start() { @@ -85,8 +96,12 @@ void DownloadItem::open() { void DownloadItem::openFolder() { QFileInfo info(m_file); +#ifdef APP_MAC + mac::showInFinder(info.absoluteFilePath()); +#else QUrl url = QUrl::fromLocalFile(info.absolutePath()); QDesktopServices::openUrl(url); +#endif } void DownloadItem::tryAgain() { @@ -102,6 +117,7 @@ void DownloadItem::tryAgain() { } void DownloadItem::downloadReadyRead() { + if (!m_reply) return; if (!m_file.isOpen()) { if (!m_file.open(QIODevice::ReadWrite)) { @@ -131,13 +147,11 @@ void DownloadItem::downloadReadyRead() { void DownloadItem::error(QNetworkReply::NetworkError) { -#ifdef DOWNLOADMANAGER_DEBUG - qDebug() << "DownloadItem::" << __FUNCTION__ << m_reply->errorString() << m_url; -#endif - - qDebug() << m_reply->errorString(); + if (m_reply) { + qWarning() << m_reply->errorString() << m_reply->url().toEncoded(); + m_errorMessage = m_reply->errorString(); + } - m_errorMessage = m_reply->errorString(); m_reply = 0; m_status = Failed; @@ -149,6 +163,7 @@ QString DownloadItem::errorMessage() const { } void DownloadItem::metaDataChanged() { + if (!m_reply) return; QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader); if (locationHeader.isValid()) { m_url = locationHeader.toUrl(); @@ -179,6 +194,8 @@ int DownloadItem::initialBufferSize() { void DownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { + // qDebug() << bytesReceived << bytesTotal << m_downloadTime.elapsed(); + if (m_lastProgressTime.elapsed() < 150) return; m_lastProgressTime.start(); @@ -191,7 +208,7 @@ void DownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { int bufferSize = initialBufferSize(); if (bytesReceived > bufferSize && bytesReceived > neededBytes - && m_downloadTime.elapsed() > 1000 ) { + && (m_downloadTime.elapsed() > 1000)) { emit bufferProgress(100); m_status = Downloading; emit statusChanged(); @@ -277,6 +294,10 @@ void DownloadItem::requestFinished() { qDebug() << "Request finished but never started saving"; return; } + if (m_status == Starting) { + m_status = Downloading; + emit statusChanged(); + } m_file.close(); m_status = Finished; emit statusChanged();