added 1 changeset to branch 'refs/remotes/axeld-github/pkgman-progress' old head: 0000000000000000000000000000000000000000 new head: 31dd73a57a9c24058e04efcde210db30f623f7c6 overview: https://github.com/axeld/haiku/compare/31dd73a57a9c ---------------------------------------------------------------------------- 31dd73a57a9c: pgkman: added package size progress info. * So that you know how much already was, and still has to be downloaded. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: 31dd73a57a9c24058e04efcde210db30f623f7c6 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Sat Jan 24 13:26:26 2015 UTC ---------------------------------------------------------------------------- 6 files changed, 58 insertions(+), 27 deletions(-) headers/private/package/FetchFileJob.h | 15 ++++++--- headers/private/package/manager/PackageManager.h | 5 +-- src/bin/pkgman/PackageManager.cpp | 17 ++++++---- src/bin/pkgman/PackageManager.h | 5 +-- src/kits/package/FetchFileJob.cpp | 35 +++++++++++++++----- src/kits/package/manager/PackageManager.cpp | 8 +++-- ---------------------------------------------------------------------------- diff --git a/headers/private/package/FetchFileJob.h b/headers/private/package/FetchFileJob.h index c62ef11..9d8b52b 100644 --- a/headers/private/package/FetchFileJob.h +++ b/headers/private/package/FetchFileJob.h @@ -1,6 +1,7 @@ /* * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxx> * Copyright 2013, Rene Gollent <rene@xxxxxxxxxxx> + * Copyright 2015, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> * Distributed under the terms of the MIT License. */ #ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ @@ -32,6 +33,8 @@ public: float DownloadProgress() const; const char* DownloadURL() const; const char* DownloadFileName() const; + off_t DownloadBytes() const; + off_t DownloadTotalBytes() const; protected: virtual status_t Execute(); @@ -39,18 +42,20 @@ protected: private: // libcurl callbacks - static int _ProgressCallback(void *clientp, - double dltotal, double dlnow, - double ultotal, double ulnow); + static int _TransferCallback(void* _job, + off_t downloadTotal, off_t downloaded, + off_t uploadTotal, off_t uploaded); - static size_t _WriteCallback(void *buffer, size_t size, - size_t nmemb, void *userp); + static size_t _WriteCallback(void* buffer, size_t size, + size_t nmemb, void* userp); private: BString fFileURL; BEntry fTargetEntry; BFile fTargetFile; float fDownloadProgress; + off_t fBytes; + off_t fTotalBytes; }; diff --git a/headers/private/package/manager/PackageManager.h b/headers/private/package/manager/PackageManager.h index 5bbd945..c280fe4 100644 --- a/headers/private/package/manager/PackageManager.h +++ b/headers/private/package/manager/PackageManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2015, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -319,7 +319,8 @@ public: const char* packageName); virtual void ProgressPackageDownloadActive( const char* packageName, - float completionPercentage); + float completionPercentage, + off_t bytes, off_t totalBytes); virtual void ProgressPackageDownloadComplete( const char* packageName); virtual void ProgressPackageChecksumStarted( diff --git a/src/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index 1d6ef42..6d9311f 100644 --- a/src/bin/pkgman/PackageManager.cpp +++ b/src/bin/pkgman/PackageManager.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2015, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Ingo Weinhold <ingo_weinhold@xxxxxx> + * Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> * Rene Gollent <rene@xxxxxxxxxxx> + * Ingo Weinhold <ingo_weinhold@xxxxxx> */ @@ -176,7 +177,7 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName) void PackageManager::ProgressPackageDownloadActive(const char* packageName, - float completionPercentage) + float completionPercentage, off_t bytes, off_t totalBytes) { static const char* progressChars[] = { "\xE2\x96\x8F", @@ -189,7 +190,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName, "\xE2\x96\x88", }; - const int width = 70; + const int width = 65; int position; int ipart = (int)(completionPercentage * width); @@ -210,8 +211,12 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName, } } - // Also print the progress percentage - printf(" %3d%%", (int)(completionPercentage * 100)); + // Also print the progress percentage, and downloaded size + char byteBuffer[32]; + char totalBuffer[32]; + printf(" %3d%% (%s/%s)", (int)(completionPercentage * 100), + string_for_size(bytes, byteBuffer, sizeof(byteBuffer)), + string_for_size(totalBytes, totalBuffer, sizeof(totalBuffer))); fflush(stdout); } diff --git a/src/bin/pkgman/PackageManager.h b/src/bin/pkgman/PackageManager.h index eb64aa4..475947b 100644 --- a/src/bin/pkgman/PackageManager.h +++ b/src/bin/pkgman/PackageManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2015, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -46,7 +46,8 @@ private: const char* packageName); virtual void ProgressPackageDownloadActive( const char* packageName, - float completionPercentage); + float completionPercentage, + off_t bytes, off_t totalBytes); virtual void ProgressPackageDownloadComplete( const char* packageName); virtual void ProgressPackageChecksumStarted( diff --git a/src/kits/package/FetchFileJob.cpp b/src/kits/package/FetchFileJob.cpp index 4a4959a..ff1bad4 100644 --- a/src/kits/package/FetchFileJob.cpp +++ b/src/kits/package/FetchFileJob.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2011-2013, Haiku, Inc. All Rights Reserved. + * Copyright 2011-2015, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Oliver Tappe <zooey@xxxxxxxxxxxxxxx> + * Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> * Rene Gollent <rene@xxxxxxxxxxx> + * Oliver Tappe <zooey@xxxxxxxxxxxxxxx> */ @@ -62,6 +63,20 @@ FetchFileJob::DownloadFileName() const } +off_t +FetchFileJob::DownloadBytes() const +{ + return fBytes; +} + + +off_t +FetchFileJob::DownloadTotalBytes() const +{ + return fTotalBytes; +} + + status_t FetchFileJob::Execute() { @@ -77,8 +92,8 @@ FetchFileJob::Execute() result = curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0); - result = curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, - &_ProgressCallback); + result = curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, + &_TransferCallback); if (result != CURLE_OK) return B_BAD_VALUE; @@ -117,12 +132,14 @@ FetchFileJob::Execute() int -FetchFileJob::_ProgressCallback(void *userp, double dltotal, double dlnow, - double ultotal, double ulnow) +FetchFileJob::_TransferCallback(void* _job, off_t downloadTotal, + off_t downloaded, off_t uploadTotal, off_t uploaded) { - FetchFileJob* job = reinterpret_cast<FetchFileJob*>(userp); - if (dltotal != 0) { - job->fDownloadProgress = dlnow / dltotal; + FetchFileJob* job = reinterpret_cast<FetchFileJob*>(_job); + if (downloadTotal != 0) { + job->fBytes = downloaded; + job->fTotalBytes = downloadTotal; + job->fDownloadProgress = downloaded / downloadTotal; job->NotifyStateListeners(); } return 0; diff --git a/src/kits/package/manager/PackageManager.cpp b/src/kits/package/manager/PackageManager.cpp index 0deae53..37d2339 100644 --- a/src/kits/package/manager/PackageManager.cpp +++ b/src/kits/package/manager/PackageManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2015, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -383,7 +383,8 @@ BPackageManager::JobProgress(BJob* job) if (dynamic_cast<FetchFileJob*>(job) != NULL) { FetchFileJob* fetchJob = (FetchFileJob*)job; fUserInteractionHandler->ProgressPackageDownloadActive( - fetchJob->DownloadFileName(), fetchJob->DownloadProgress()); + fetchJob->DownloadFileName(), fetchJob->DownloadProgress(), + fetchJob->DownloadBytes(), fetchJob->DownloadTotalBytes()); } } @@ -1105,7 +1106,8 @@ BPackageManager::UserInteractionHandler::ProgressPackageDownloadStarted( void BPackageManager::UserInteractionHandler::ProgressPackageDownloadActive( - const char* packageName, float completionPercentage) + const char* packageName, float completionPercentage, off_t bytes, + off_t totalBytes) { }