From 1aaa0c2142c6c843e93bd1ee8edd4c7ea6256559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 24 Jan 2015 14:26:26 +0100 Subject: [PATCH] Package Kit: FetchFileJob now contains package size. * So that you know how much already was, and still has to be downloaded. * Automatic whitespace cleanup. * The link in FetchFileJob.h did not fetch the correct header under Haiku anymore (since the addition of the private headers to the image). --- headers/build/private/package/FetchFileJob.h | 2 +- headers/private/package/FetchFileJob.h | 15 ++++--- .../private/package/manager/PackageManager.h | 5 ++- src/apps/haikudepot/model/PackageManager.cpp | 42 +++++++++---------- src/apps/haikudepot/model/PackageManager.h | 4 +- src/bin/pkgman/PackageManager.cpp | 7 ++-- src/bin/pkgman/PackageManager.h | 5 ++- src/kits/package/FetchFileJob.cpp | 35 ++++++++++++---- src/kits/package/manager/PackageManager.cpp | 8 ++-- src/servers/package/PackageManager.cpp | 2 +- src/servers/package/PackageManager.h | 3 +- 11 files changed, 79 insertions(+), 49 deletions(-) diff --git a/headers/build/private/package/FetchFileJob.h b/headers/build/private/package/FetchFileJob.h index aad2b1f2a4..e41921b277 100644 --- a/headers/build/private/package/FetchFileJob.h +++ b/headers/build/private/package/FetchFileJob.h @@ -1 +1 @@ -#include <../private/package/FetchFileJob.h> +#include <../../../private/package/FetchFileJob.h> diff --git a/headers/private/package/FetchFileJob.h b/headers/private/package/FetchFileJob.h index c62ef11fbc..9d8b52b155 100644 --- a/headers/private/package/FetchFileJob.h +++ b/headers/private/package/FetchFileJob.h @@ -1,6 +1,7 @@ /* * Copyright 2011, Oliver Tappe * Copyright 2013, Rene Gollent + * Copyright 2015, Axel Dörfler * 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 5bbd945b40..c280fe4ff9 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/apps/haikudepot/model/PackageManager.cpp b/src/apps/haikudepot/model/PackageManager.cpp index 8190d6ec47..e2f9e3bf45 100644 --- a/src/apps/haikudepot/model/PackageManager.cpp +++ b/src/apps/haikudepot/model/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: @@ -313,14 +313,14 @@ struct DeskbarLink { link(link) { } - + DeskbarLink(const DeskbarLink& other) : path(other.path), link(other.link) { } - + DeskbarLink& operator=(const DeskbarLink& other) { if (this == &other) @@ -329,17 +329,17 @@ struct DeskbarLink { link = other.link; return *this; } - + bool operator==(const DeskbarLink& other) { return path == other.path && link == other.link; } - + bool operator!=(const DeskbarLink& other) { return !(*this == other); } - + BString path; BString link; }; @@ -367,24 +367,24 @@ public: } return B_OK; } - + virtual status_t HandleEntryAttribute(BPackageEntry* entry, BPackageEntryAttribute* attribute) { return B_OK; } - + virtual status_t HandleEntryDone(BPackageEntry* entry) { return B_OK; } - + virtual status_t HandlePackageAttribute( const BPackageInfoAttributeValue& value) { return B_OK; } - + virtual void HandleErrorOccurred() { } @@ -419,7 +419,7 @@ public: int32 lastPathSeparator = target.FindLast('/'); if (lastPathSeparator > 0 && lastPathSeparator + 1 < target.Length()) target.Remove(0, lastPathSeparator + 1); - + fLabel.ReplaceAll("%DeskbarLink%", target); } @@ -448,7 +448,7 @@ public: } else { return B_ERROR; } - + status = path.Append(fDeskbarLink.path); if (status == B_OK) status = path.GetParent(&path); @@ -457,14 +457,14 @@ public: printf("trying to launch: %s\n", path.Path()); } } - + entry_ref ref; if (status == B_OK) status = get_ref_for_path(path.Path(), &ref); - + if (status == B_OK) status = be_roster->Launch(&ref); - + return status; } @@ -494,7 +494,7 @@ public: } packagePath.Append(package->FileName()); - + BNoErrorOutput errorOutput; BPackageReader reader(&errorOutput); @@ -505,7 +505,7 @@ public: packagePath.Path(), strerror(status)); return false; } - + // Scan package contents for Deskbar links DeskbarLinkFinder contentHandler(foundLinks); status = reader.ParseContent(&contentHandler); @@ -515,7 +515,7 @@ public: packagePath.Path(), strerror(status)); return false; } - + return foundLinks.CountItems() > 0; } @@ -567,7 +567,7 @@ PackageManager::GetPackageActions(PackageInfoRef package, Model* model) if (state == ACTIVATED || state == INSTALLED) { actionList.Add(PackageActionRef(new UninstallPackageAction( package, model), true)); - + // Add OpenPackageActions for each deskbar link found in the // package DeskbarLinkList foundLinks; @@ -721,13 +721,13 @@ PackageManager::Warn(status_t error, const char* format, ...) void PackageManager::ProgressPackageDownloadStarted(const char* packageName) { - ProgressPackageDownloadActive(packageName, 0.0f); + ProgressPackageDownloadActive(packageName, 0.0f, 0, 0); } void PackageManager::ProgressPackageDownloadActive(const char* packageName, - float completionPercentage) + float completionPercentage, off_t bytes, off_t totalBytes) { for (int32 i = 0; i < fPackageProgressListeners.CountItems(); i++) { fPackageProgressListeners.ItemAt(i)->DownloadProgressChanged( diff --git a/src/apps/haikudepot/model/PackageManager.h b/src/apps/haikudepot/model/PackageManager.h index f56a07105c..c5cb0b3f50 100644 --- a/src/apps/haikudepot/model/PackageManager.h +++ b/src/apps/haikudepot/model/PackageManager.h @@ -96,7 +96,9 @@ 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/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index d4d9cf2724..f8fd1ea6a4 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 + * Axel Dörfler * Rene Gollent + * Ingo Weinhold */ @@ -179,7 +180,7 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName) void PackageManager::ProgressPackageDownloadActive(const char* packageName, - float completionPercentage) + float completionPercentage, off_t bytes, off_t totalBytes) { if (!fInteractive) return; diff --git a/src/bin/pkgman/PackageManager.h b/src/bin/pkgman/PackageManager.h index eb64aa4561..475947b9f9 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 4a4959ab5c..ff1bad4748 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 + * Axel Dörfler * Rene Gollent + * Oliver Tappe */ @@ -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(userp); - if (dltotal != 0) { - job->fDownloadProgress = dlnow / dltotal; + FetchFileJob* job = reinterpret_cast(_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 0deae53e10..37d233963f 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(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) { } diff --git a/src/servers/package/PackageManager.cpp b/src/servers/package/PackageManager.cpp index 2c1eb8528f..8799aa203b 100644 --- a/src/servers/package/PackageManager.cpp +++ b/src/servers/package/PackageManager.cpp @@ -320,7 +320,7 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName) void PackageManager::ProgressPackageDownloadActive(const char* packageName, - float completionPercentage) + float completionPercentage, off_t bytes, off_t totalBytes) { } diff --git a/src/servers/package/PackageManager.h b/src/servers/package/PackageManager.h index 95106fb740..56f3a44206 100644 --- a/src/servers/package/PackageManager.h +++ b/src/servers/package/PackageManager.h @@ -65,7 +65,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(