Extend Package delegate callbacks.
This makes it easier to report the status in the launcher, at least.
This commit is contained in:
@@ -77,6 +77,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void availablePackagesChanged() {}
|
virtual void availablePackagesChanged() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* More general purpose notification when install is queued / cancelled / started
|
||||||
|
* stopped. Reason value is only in certain cases.
|
||||||
|
*/
|
||||||
|
virtual void installStatusChanged(InstallRef aInstall, StatusCode aReason) {};
|
||||||
|
|
||||||
virtual void dataForThumbnail(const std::string& aThumbnailUrl,
|
virtual void dataForThumbnail(const std::string& aThumbnailUrl,
|
||||||
size_t lenth, const uint8_t* bytes) {}
|
size_t lenth, const uint8_t* bytes) {}
|
||||||
};
|
};
|
||||||
|
|||||||
+31
-26
@@ -75,45 +75,49 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fireStatusChange(InstallRef install, Delegate::StatusCode status)
|
||||||
|
{
|
||||||
|
for (auto d : delegates) {
|
||||||
|
d->installStatusChanged(install, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void fireStartInstall(InstallRef install)
|
void fireStartInstall(InstallRef install)
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
for (auto d : delegates) {
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
d->startInstall(install);
|
||||||
(*it)->startInstall(install);
|
d->installStatusChanged(install, Delegate::STATUS_IN_PROGRESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fireInstallProgress(InstallRef install,
|
void fireInstallProgress(InstallRef install,
|
||||||
unsigned int aBytes, unsigned int aTotal)
|
unsigned int aBytes, unsigned int aTotal)
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
for (auto d : delegates) {
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
d->installProgress(install, aBytes, aTotal);
|
||||||
(*it)->installProgress(install, aBytes, aTotal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fireFinishInstall(InstallRef install, Delegate::StatusCode status)
|
void fireFinishInstall(InstallRef install, Delegate::StatusCode status)
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
for (auto d : delegates) {
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
d->finishInstall(install, status);
|
||||||
(*it)->finishInstall(install, status);
|
d->installStatusChanged(install, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fireRefreshStatus(CatalogRef catalog, Delegate::StatusCode status)
|
void fireRefreshStatus(CatalogRef catalog, Delegate::StatusCode status)
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
for (auto d : delegates) {
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
d->catalogRefreshed(catalog, status);
|
||||||
(*it)->catalogRefreshed(catalog, status);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void firePackagesChanged()
|
void firePackagesChanged()
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
for (auto d : delegates) {
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
d->availablePackagesChanged();
|
||||||
(*it)->availablePackagesChanged();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void thumbnailDownloadComplete(HTTP::Request_ptr request,
|
void thumbnailDownloadComplete(HTTP::Request_ptr request,
|
||||||
@@ -130,10 +134,9 @@ public:
|
|||||||
|
|
||||||
void fireDataForThumbnail(const std::string& aUrl, const std::string& bytes)
|
void fireDataForThumbnail(const std::string& aUrl, const std::string& bytes)
|
||||||
{
|
{
|
||||||
DelegateVec::const_iterator it;
|
|
||||||
const uint8_t* data = reinterpret_cast<const uint8_t*>(bytes.data());
|
const uint8_t* data = reinterpret_cast<const uint8_t*>(bytes.data());
|
||||||
for (it = delegates.begin(); it != delegates.end(); ++it) {
|
for (auto d : delegates) {
|
||||||
(*it)->dataForThumbnail(aUrl, bytes.size(), data);
|
d->dataForThumbnail(aUrl, bytes.size(), data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,8 +160,9 @@ public:
|
|||||||
|
|
||||||
void fireFinishUninstall(PackageRef pkg)
|
void fireFinishUninstall(PackageRef pkg)
|
||||||
{
|
{
|
||||||
std::for_each(delegates.begin(), delegates.end(),
|
for (auto d : delegates) {
|
||||||
[pkg](Delegate* d) {d->finishUninstall(pkg);});
|
d->finishUninstall(pkg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DelegateVec delegates;
|
DelegateVec delegates;
|
||||||
@@ -446,7 +450,7 @@ void Root::scheduleToUpdate(InstallRef aInstall)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PackageList deps = aInstall->package()->dependencies();
|
PackageList deps = aInstall->package()->dependencies();
|
||||||
BOOST_FOREACH(Package* dep, deps) {
|
for (Package* dep : deps) {
|
||||||
// will internally schedule for update if required
|
// will internally schedule for update if required
|
||||||
// hence be careful, this method is re-entered in here!
|
// hence be careful, this method is re-entered in here!
|
||||||
dep->install();
|
dep->install();
|
||||||
@@ -455,6 +459,7 @@ void Root::scheduleToUpdate(InstallRef aInstall)
|
|||||||
bool wasEmpty = d->updateDeque.empty();
|
bool wasEmpty = d->updateDeque.empty();
|
||||||
d->updateDeque.push_back(aInstall);
|
d->updateDeque.push_back(aInstall);
|
||||||
|
|
||||||
|
d->fireStatusChange(aInstall, Delegate::STATUS_IN_PROGRESS);
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
aInstall->startUpdate();
|
aInstall->startUpdate();
|
||||||
}
|
}
|
||||||
@@ -462,8 +467,7 @@ void Root::scheduleToUpdate(InstallRef aInstall)
|
|||||||
|
|
||||||
bool Root::isInstallQueued(InstallRef aInstall) const
|
bool Root::isInstallQueued(InstallRef aInstall) const
|
||||||
{
|
{
|
||||||
RootPrivate::UpdateDeque::const_iterator it =
|
auto it = std::find(d->updateDeque.begin(), d->updateDeque.end(), aInstall);
|
||||||
std::find(d->updateDeque.begin(), d->updateDeque.end(), aInstall);
|
|
||||||
return (it != d->updateDeque.end());
|
return (it != d->updateDeque.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,11 +509,12 @@ void Root::finishInstall(InstallRef aInstall, Delegate::StatusCode aReason)
|
|||||||
|
|
||||||
void Root::cancelDownload(InstallRef aInstall)
|
void Root::cancelDownload(InstallRef aInstall)
|
||||||
{
|
{
|
||||||
RootPrivate::UpdateDeque::iterator it =
|
auto it = std::find(d->updateDeque.begin(), d->updateDeque.end(), aInstall);
|
||||||
std::find(d->updateDeque.begin(), d->updateDeque.end(), aInstall);
|
|
||||||
if (it != d->updateDeque.end()) {
|
if (it != d->updateDeque.end()) {
|
||||||
bool startNext = (aInstall == d->updateDeque.front());
|
bool startNext = (aInstall == d->updateDeque.front());
|
||||||
d->updateDeque.erase(it);
|
d->updateDeque.erase(it);
|
||||||
|
d->fireStatusChange(aInstall, Delegate::USER_CANCELLED);
|
||||||
|
|
||||||
if (startNext) {
|
if (startNext) {
|
||||||
if (!d->updateDeque.empty()) {
|
if (!d->updateDeque.empty()) {
|
||||||
d->updateDeque.front()->startUpdate();
|
d->updateDeque.front()->startUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user