HaikuDepot: Add download progress package state.

- Add accessors for storing/retrieving current download progress.
- Adjust PackageListView to be able to create a progress state from
  the download percentage.
This commit is contained in:
Rene Gollent
2013-09-29 17:25:33 -04:00
parent 493d13f0b4
commit 647fb4ed35
3 changed files with 44 additions and 10 deletions
+27 -4
View File
@@ -446,7 +446,8 @@ PackageInfo::PackageInfo()
fChangelog(),
fUserRatings(),
fScreenshots(),
fState(NONE)
fState(NONE),
fDownloadProgress(0.0)
{
}
@@ -466,7 +467,8 @@ PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title,
fCategories(),
fUserRatings(),
fScreenshots(),
fState(NONE)
fState(NONE),
fDownloadProgress(0.0)
{
}
@@ -483,7 +485,8 @@ PackageInfo::PackageInfo(const PackageInfo& other)
fCategories(other.fCategories),
fUserRatings(other.fUserRatings),
fScreenshots(other.fScreenshots),
fState(other.fState)
fState(other.fState),
fDownloadProgress(other.fDownloadProgress)
{
}
@@ -502,6 +505,7 @@ PackageInfo::operator=(const PackageInfo& other)
fUserRatings = other.fUserRatings;
fScreenshots = other.fScreenshots;
fState = other.fState;
fDownloadProgress = other.fDownloadProgress;
return *this;
}
@@ -519,7 +523,8 @@ PackageInfo::operator==(const PackageInfo& other) const
&& fCategories == other.fCategories
&& fUserRatings == other.fUserRatings
&& fScreenshots == other.fScreenshots
&& fState == other.fState;
&& fState == other.fState
&& fDownloadProgress == other.fDownloadProgress;
}
@@ -542,11 +547,29 @@ PackageInfo::SetState(PackageState state)
{
if (fState != state) {
fState = state;
if (fState != DOWNLOADING)
fDownloadProgress = 0.0;
_NotifyListeners(PKG_CHANGED_STATE);
}
}
float
PackageInfo::DownloadProgress() const
{
return fDownloadProgress;
}
void
PackageInfo::SetDownloadProgress(float progress)
{
fState = DOWNLOADING;
fDownloadProgress = progress;
_NotifyListeners(PKG_CHANGED_STATE);
}
bool
PackageInfo::AddUserRating(const UserRating& rating)
{
+7 -2
View File
@@ -188,8 +188,9 @@ typedef List<PackageInfoListenerRef, false, 2> PackageListenerList;
enum PackageState {
NONE = 0,
INSTALLED = 1,
ACTIVATED = 2,
UNINSTALLED = 3,
DOWNLOADING = 2,
ACTIVATED = 3,
UNINSTALLED = 4,
};
@@ -228,6 +229,9 @@ public:
{ return fState; }
void SetState(PackageState state);
float DownloadProgress() const;
void SetDownloadProgress(float progress);
bool AddCategory(const CategoryRef& category);
const CategoryList& Categories() const
{ return fCategories; }
@@ -261,6 +265,7 @@ private:
UserRatingList fUserRatings;
BitmapList fScreenshots;
PackageState fState;
float fDownloadProgress;
PackageListenerList fListeners;
};
+10 -4
View File
@@ -26,9 +26,9 @@ static const char* skPackageStateInactive = B_TRANSLATE_MARK("Inactive");
inline BString
package_state_to_string(PackageState state)
package_state_to_string(PackageInfoRef ref)
{
switch (state) {
switch (ref->State()) {
case NONE:
return B_TRANSLATE(skPackageStateAvailable);
case INSTALLED:
@@ -37,6 +37,12 @@ package_state_to_string(PackageState state)
return B_TRANSLATE(skPackageStateActive);
case UNINSTALLED:
return B_TRANSLATE(skPackageStateUninstalled);
case DOWNLOADING:
{
BString data;
data.SetToFormat("%3.2f%%", ref->DownloadProgress() * 100.0);
return data;
}
}
return B_TRANSLATE("Unknown");
@@ -473,7 +479,7 @@ PackageRow::PackageRow(const PackageInfoRef& packageRef,
// Status
// TODO: Fetch info about installed/deactivated/uninstalled/...
SetField(new BStringField(package_state_to_string(package.State())),
SetField(new BStringField(package_state_to_string(fPackage)),
kStatusColumn);
package.AddListener(fPackageListener);
@@ -493,7 +499,7 @@ PackageRow::UpdateState()
if (fPackage.Get() == NULL)
return;
SetField(new BStringField(package_state_to_string(fPackage->State())),
SetField(new BStringField(package_state_to_string(fPackage)),
kStatusColumn);
}