this, SLOT(requestFinished()));
// start timer for the download estimation
+ m_totalTime = 0;
m_downloadTime.start();
speedCheckTimer->start();
}
m_file.close();
m_status = Finished;
+ m_totalTime = m_downloadTime.elapsed() / 1000.0;
emit statusChanged();
emit finished();
m_reply->deleteLater();
return QString(QLatin1String("%1 %2")).arg(speedInt).arg(unit);
}
-QString DownloadItem::formattedTime(double timeRemaining) {
+QString DownloadItem::formattedTime(double timeRemaining, bool remaining) {
QString timeRemainingString = tr("seconds");
if (timeRemaining > 60) {
timeRemaining = timeRemaining / 60;
timeRemainingString = tr("minutes");
}
timeRemaining = floor(timeRemaining);
- return tr("%4 %5 remaining")
+ QString msg = remaining ? tr("%4 %5 remaining") : "%4 %5";
+ return msg
.arg(timeRemaining)
.arg(timeRemainingString);
}
qint64 bytesTotal() const;
qint64 bytesReceived() const;
double remainingTime() const;
+ double totalTime() { return m_totalTime; }
double currentSpeed() const;
int currentPercent() const { return percent; }
Video* getVideo() const { return video; }
DownloadItemStatus status() const { return m_status; }
static QString formattedFilesize(qint64 size);
static QString formattedSpeed(double speed);
- static QString formattedTime(double time);
+ static QString formattedTime(double time, bool remaining = true);
QString errorMessage() const;
public slots:
bool m_finishedDownloading;
QTime m_lastProgressTime;
int percent;
+ double m_totalTime;
QUrl m_url;
static DownloadManager *downloadManagerInstance = 0;
DownloadManager::DownloadManager(QWidget *parent) :
- QObject(parent),
- downloadModel(new DownloadModel(this, this))
+ QObject(parent),
+ downloadModel(new DownloadModel(this, this))
{ }
DownloadManager* DownloadManager::instance() {
msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::NAME));
msgBox.setInformativeText(
- tr("It can only download videos shorter than %1 minutes so you can test the download functionality.")
- .arg(4));
+ tr("It can only download videos shorter than %1 minutes so you can test the download functionality.")
+ .arg(4));
msgBox.setModal(true);
// make it a "sheet" on the Mac
msgBox.setWindowModality(Qt::WindowModal);
void DownloadManager::itemFinished() {
if (activeItems() == 0) emit finished();
+#ifdef Q_WS_MAC
+ if (mac::canNotify()) {
+ DownloadItem *item = static_cast<DownloadItem*>(sender());
+ if (!item) {
+ qDebug() << "Cannot get item in" << __FUNCTION__;
+ return;
+ }
+ Video *video = item->getVideo();
+ if (!video) return;
+ QString stats = tr("%1 downloaded in %2").arg(
+ DownloadItem::formattedFilesize(item->bytesTotal()),
+ DownloadItem::formattedTime(item->totalTime(), false));
+ mac::notify(tr("Download finished"), video->title(), stats);
+ }
+#endif
}
void DownloadManager::updateStatusMessage() {