+class MyDelegate : public pkg::Delegate
+{
+public:
+ virtual void catalogRefreshed(pkg::CatalogRef aCatalog, StatusCode aReason)
+ {
+ if (aReason == STATUS_REFRESHED) {
+ if (aCatalog.ptr() == NULL) {
+ cout << "refreshed all catalogs" << endl;
+ } else {
+ cout << "refreshed catalog " << aCatalog->url() << endl;
+ }
+ } else if (aReason == STATUS_IN_PROGRESS) {
+ cout << "started refresh of " << aCatalog->url() << endl;
+ } else {
+ cerr << "failed refresh of " << aCatalog->url() << ":" << aReason << endl;
+ }
+ }
+
+ virtual void startInstall(pkg::InstallRef aInstall)
+ {
+ _lastPercent = 999;
+ cout << "starting install of " << aInstall->package()->name() << endl;
+ }
+
+ virtual void installProgress(pkg::InstallRef aInstall, unsigned int bytes, unsigned int total)
+ {
+ unsigned int percent = (bytes * 100) / total;
+ if (percent == _lastPercent) {
+ return;
+ }
+
+ _lastPercent = percent;
+ cout << percent << "%" << endl;
+ }
+
+ virtual void finishInstall(pkg::InstallRef aInstall, StatusCode aReason)
+ {
+ if (aReason == STATUS_SUCCESS) {
+ cout << "done install of " << aInstall->package()->name() << endl;
+ } else {
+ cerr << "failed install of " << aInstall->package()->name() << endl;
+ }
+ }
+
+private:
+ unsigned int _lastPercent;
+
+};
+
+void printRating(pkg::Package* pkg, const std::string& aRating, const std::string& aLabel)
+{
+ SGPropertyNode* ratings = pkg->properties()->getChild("rating");
+ cout << "\t" << aLabel << ":" << ratings->getIntValue(aRating) << endl;
+}
+
+void printPackageInfo(pkg::Package* pkg)
+{
+ cout << "Package:" << pkg->catalog()->id() << "." << pkg->id() << endl;
+ cout << "Revision:" << pkg->revision() << endl;
+ cout << "Name:" << pkg->name() << endl;
+ cout << "Description:" << pkg->description() << endl;
+ cout << "Long description:\n" << pkg->getLocalisedProp("long-description") << endl << endl;
+
+ if (pkg->properties()->hasChild("author")) {
+ cout << "Authors:" << endl;
+ BOOST_FOREACH(SGPropertyNode* author, pkg->properties()->getChildren("author")) {
+ if (author->hasChild("name")) {
+ cout << "\t" << author->getStringValue("name") << endl;
+
+ } else {
+ // simple author structure
+ cout << "\t" << author->getStringValue() << endl;
+ }
+
+
+ }
+
+ cout << endl;
+ }
+
+ cout << "Ratings:" << endl;
+ printRating(pkg, "fdm", "Flight-model ");
+ printRating(pkg, "cockpit", "Cockpit ");
+ printRating(pkg, "model", "3D model ");
+ printRating(pkg, "systems", "Aircraft systems");
+}
+