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).
This commit is contained in:
@@ -1 +1 @@
|
|||||||
#include <../private/package/FetchFileJob.h>
|
#include <../../../private/package/FetchFileJob.h>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||||
* Copyright 2013, Rene Gollent <[email protected]>
|
* Copyright 2013, Rene Gollent <[email protected]>
|
||||||
|
* Copyright 2015, Axel Dörfler <[email protected]>
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
|
#ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
|
||||||
@@ -32,6 +33,8 @@ public:
|
|||||||
float DownloadProgress() const;
|
float DownloadProgress() const;
|
||||||
const char* DownloadURL() const;
|
const char* DownloadURL() const;
|
||||||
const char* DownloadFileName() const;
|
const char* DownloadFileName() const;
|
||||||
|
off_t DownloadBytes() const;
|
||||||
|
off_t DownloadTotalBytes() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual status_t Execute();
|
virtual status_t Execute();
|
||||||
@@ -39,18 +42,20 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// libcurl callbacks
|
// libcurl callbacks
|
||||||
static int _ProgressCallback(void *clientp,
|
static int _TransferCallback(void* _job,
|
||||||
double dltotal, double dlnow,
|
off_t downloadTotal, off_t downloaded,
|
||||||
double ultotal, double ulnow);
|
off_t uploadTotal, off_t uploaded);
|
||||||
|
|
||||||
static size_t _WriteCallback(void *buffer, size_t size,
|
static size_t _WriteCallback(void* buffer, size_t size,
|
||||||
size_t nmemb, void *userp);
|
size_t nmemb, void* userp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fFileURL;
|
BString fFileURL;
|
||||||
BEntry fTargetEntry;
|
BEntry fTargetEntry;
|
||||||
BFile fTargetFile;
|
BFile fTargetFile;
|
||||||
float fDownloadProgress;
|
float fDownloadProgress;
|
||||||
|
off_t fBytes;
|
||||||
|
off_t fTotalBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -319,7 +319,8 @@ public:
|
|||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageDownloadActive(
|
virtual void ProgressPackageDownloadActive(
|
||||||
const char* packageName,
|
const char* packageName,
|
||||||
float completionPercentage);
|
float completionPercentage,
|
||||||
|
off_t bytes, off_t totalBytes);
|
||||||
virtual void ProgressPackageDownloadComplete(
|
virtual void ProgressPackageDownloadComplete(
|
||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageChecksumStarted(
|
virtual void ProgressPackageChecksumStarted(
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -313,14 +313,14 @@ struct DeskbarLink {
|
|||||||
link(link)
|
link(link)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeskbarLink(const DeskbarLink& other)
|
DeskbarLink(const DeskbarLink& other)
|
||||||
:
|
:
|
||||||
path(other.path),
|
path(other.path),
|
||||||
link(other.link)
|
link(other.link)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeskbarLink& operator=(const DeskbarLink& other)
|
DeskbarLink& operator=(const DeskbarLink& other)
|
||||||
{
|
{
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
@@ -329,17 +329,17 @@ struct DeskbarLink {
|
|||||||
link = other.link;
|
link = other.link;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const DeskbarLink& other)
|
bool operator==(const DeskbarLink& other)
|
||||||
{
|
{
|
||||||
return path == other.path && link == other.link;
|
return path == other.path && link == other.link;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const DeskbarLink& other)
|
bool operator!=(const DeskbarLink& other)
|
||||||
{
|
{
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
BString path;
|
BString path;
|
||||||
BString link;
|
BString link;
|
||||||
};
|
};
|
||||||
@@ -367,24 +367,24 @@ public:
|
|||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
|
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
|
||||||
BPackageEntryAttribute* attribute)
|
BPackageEntryAttribute* attribute)
|
||||||
{
|
{
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandleEntryDone(BPackageEntry* entry)
|
virtual status_t HandleEntryDone(BPackageEntry* entry)
|
||||||
{
|
{
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandlePackageAttribute(
|
virtual status_t HandlePackageAttribute(
|
||||||
const BPackageInfoAttributeValue& value)
|
const BPackageInfoAttributeValue& value)
|
||||||
{
|
{
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void HandleErrorOccurred()
|
virtual void HandleErrorOccurred()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ public:
|
|||||||
int32 lastPathSeparator = target.FindLast('/');
|
int32 lastPathSeparator = target.FindLast('/');
|
||||||
if (lastPathSeparator > 0 && lastPathSeparator + 1 < target.Length())
|
if (lastPathSeparator > 0 && lastPathSeparator + 1 < target.Length())
|
||||||
target.Remove(0, lastPathSeparator + 1);
|
target.Remove(0, lastPathSeparator + 1);
|
||||||
|
|
||||||
fLabel.ReplaceAll("%DeskbarLink%", target);
|
fLabel.ReplaceAll("%DeskbarLink%", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = path.Append(fDeskbarLink.path);
|
status = path.Append(fDeskbarLink.path);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = path.GetParent(&path);
|
status = path.GetParent(&path);
|
||||||
@@ -457,14 +457,14 @@ public:
|
|||||||
printf("trying to launch: %s\n", path.Path());
|
printf("trying to launch: %s\n", path.Path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = get_ref_for_path(path.Path(), &ref);
|
status = get_ref_for_path(path.Path(), &ref);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = be_roster->Launch(&ref);
|
status = be_roster->Launch(&ref);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,7 +494,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
packagePath.Append(package->FileName());
|
packagePath.Append(package->FileName());
|
||||||
|
|
||||||
BNoErrorOutput errorOutput;
|
BNoErrorOutput errorOutput;
|
||||||
BPackageReader reader(&errorOutput);
|
BPackageReader reader(&errorOutput);
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ public:
|
|||||||
packagePath.Path(), strerror(status));
|
packagePath.Path(), strerror(status));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan package contents for Deskbar links
|
// Scan package contents for Deskbar links
|
||||||
DeskbarLinkFinder contentHandler(foundLinks);
|
DeskbarLinkFinder contentHandler(foundLinks);
|
||||||
status = reader.ParseContent(&contentHandler);
|
status = reader.ParseContent(&contentHandler);
|
||||||
@@ -515,7 +515,7 @@ public:
|
|||||||
packagePath.Path(), strerror(status));
|
packagePath.Path(), strerror(status));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundLinks.CountItems() > 0;
|
return foundLinks.CountItems() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +567,7 @@ PackageManager::GetPackageActions(PackageInfoRef package, Model* model)
|
|||||||
if (state == ACTIVATED || state == INSTALLED) {
|
if (state == ACTIVATED || state == INSTALLED) {
|
||||||
actionList.Add(PackageActionRef(new UninstallPackageAction(
|
actionList.Add(PackageActionRef(new UninstallPackageAction(
|
||||||
package, model), true));
|
package, model), true));
|
||||||
|
|
||||||
// Add OpenPackageActions for each deskbar link found in the
|
// Add OpenPackageActions for each deskbar link found in the
|
||||||
// package
|
// package
|
||||||
DeskbarLinkList foundLinks;
|
DeskbarLinkList foundLinks;
|
||||||
@@ -721,13 +721,13 @@ PackageManager::Warn(status_t error, const char* format, ...)
|
|||||||
void
|
void
|
||||||
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
||||||
{
|
{
|
||||||
ProgressPackageDownloadActive(packageName, 0.0f);
|
ProgressPackageDownloadActive(packageName, 0.0f, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||||
float completionPercentage)
|
float completionPercentage, off_t bytes, off_t totalBytes)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fPackageProgressListeners.CountItems(); i++) {
|
for (int32 i = 0; i < fPackageProgressListeners.CountItems(); i++) {
|
||||||
fPackageProgressListeners.ItemAt(i)->DownloadProgressChanged(
|
fPackageProgressListeners.ItemAt(i)->DownloadProgressChanged(
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ private:
|
|||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageDownloadActive(
|
virtual void ProgressPackageDownloadActive(
|
||||||
const char* packageName,
|
const char* packageName,
|
||||||
float completionPercentage);
|
float completionPercentage,
|
||||||
|
off_t bytes, off_t totalBytes);
|
||||||
|
|
||||||
virtual void ProgressPackageDownloadComplete(
|
virtual void ProgressPackageDownloadComplete(
|
||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageChecksumStarted(
|
virtual void ProgressPackageChecksumStarted(
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
* Axel Dörfler <axeld@pinc-software.de>
|
||||||
* Rene Gollent <rene@gollent.com>
|
* Rene Gollent <rene@gollent.com>
|
||||||
|
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
|||||||
|
|
||||||
void
|
void
|
||||||
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||||
float completionPercentage)
|
float completionPercentage, off_t bytes, off_t totalBytes)
|
||||||
{
|
{
|
||||||
if (!fInteractive)
|
if (!fInteractive)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -46,7 +46,8 @@ private:
|
|||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageDownloadActive(
|
virtual void ProgressPackageDownloadActive(
|
||||||
const char* packageName,
|
const char* packageName,
|
||||||
float completionPercentage);
|
float completionPercentage,
|
||||||
|
off_t bytes, off_t totalBytes);
|
||||||
virtual void ProgressPackageDownloadComplete(
|
virtual void ProgressPackageDownloadComplete(
|
||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageChecksumStarted(
|
virtual void ProgressPackageChecksumStarted(
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Oliver Tappe <zooey@hirschkaefer.de>
|
* Axel Dörfler <axeld@pinc-software.de>
|
||||||
* Rene Gollent <rene@gollent.com>
|
* Rene Gollent <rene@gollent.com>
|
||||||
|
* Oliver Tappe <zooey@hirschkaefer.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +63,20 @@ FetchFileJob::DownloadFileName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
off_t
|
||||||
|
FetchFileJob::DownloadBytes() const
|
||||||
|
{
|
||||||
|
return fBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
off_t
|
||||||
|
FetchFileJob::DownloadTotalBytes() const
|
||||||
|
{
|
||||||
|
return fTotalBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
FetchFileJob::Execute()
|
FetchFileJob::Execute()
|
||||||
{
|
{
|
||||||
@@ -77,8 +92,8 @@ FetchFileJob::Execute()
|
|||||||
|
|
||||||
result = curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0);
|
result = curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0);
|
||||||
|
|
||||||
result = curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION,
|
result = curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION,
|
||||||
&_ProgressCallback);
|
&_TransferCallback);
|
||||||
if (result != CURLE_OK)
|
if (result != CURLE_OK)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@@ -117,12 +132,14 @@ FetchFileJob::Execute()
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
FetchFileJob::_ProgressCallback(void *userp, double dltotal, double dlnow,
|
FetchFileJob::_TransferCallback(void* _job, off_t downloadTotal,
|
||||||
double ultotal, double ulnow)
|
off_t downloaded, off_t uploadTotal, off_t uploaded)
|
||||||
{
|
{
|
||||||
FetchFileJob* job = reinterpret_cast<FetchFileJob*>(userp);
|
FetchFileJob* job = reinterpret_cast<FetchFileJob*>(_job);
|
||||||
if (dltotal != 0) {
|
if (downloadTotal != 0) {
|
||||||
job->fDownloadProgress = dlnow / dltotal;
|
job->fBytes = downloaded;
|
||||||
|
job->fTotalBytes = downloadTotal;
|
||||||
|
job->fDownloadProgress = downloaded / downloadTotal;
|
||||||
job->NotifyStateListeners();
|
job->NotifyStateListeners();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -383,7 +383,8 @@ BPackageManager::JobProgress(BJob* job)
|
|||||||
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
|
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
|
||||||
FetchFileJob* fetchJob = (FetchFileJob*)job;
|
FetchFileJob* fetchJob = (FetchFileJob*)job;
|
||||||
fUserInteractionHandler->ProgressPackageDownloadActive(
|
fUserInteractionHandler->ProgressPackageDownloadActive(
|
||||||
fetchJob->DownloadFileName(), fetchJob->DownloadProgress());
|
fetchJob->DownloadFileName(), fetchJob->DownloadProgress(),
|
||||||
|
fetchJob->DownloadBytes(), fetchJob->DownloadTotalBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1105,7 +1106,8 @@ BPackageManager::UserInteractionHandler::ProgressPackageDownloadStarted(
|
|||||||
|
|
||||||
void
|
void
|
||||||
BPackageManager::UserInteractionHandler::ProgressPackageDownloadActive(
|
BPackageManager::UserInteractionHandler::ProgressPackageDownloadActive(
|
||||||
const char* packageName, float completionPercentage)
|
const char* packageName, float completionPercentage, off_t bytes,
|
||||||
|
off_t totalBytes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
|||||||
|
|
||||||
void
|
void
|
||||||
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||||
float completionPercentage)
|
float completionPercentage, off_t bytes, off_t totalBytes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ private:
|
|||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageDownloadActive(
|
virtual void ProgressPackageDownloadActive(
|
||||||
const char* packageName,
|
const char* packageName,
|
||||||
float completionPercentage);
|
float completionPercentage,
|
||||||
|
off_t bytes, off_t totalBytes);
|
||||||
virtual void ProgressPackageDownloadComplete(
|
virtual void ProgressPackageDownloadComplete(
|
||||||
const char* packageName);
|
const char* packageName);
|
||||||
virtual void ProgressPackageChecksumStarted(
|
virtual void ProgressPackageChecksumStarted(
|
||||||
|
|||||||
Reference in New Issue
Block a user