Skip to content

Commit

Permalink
update for new libget version
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Nov 25, 2023
1 parent 0be24ae commit 41e7cdc
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 123 deletions.
54 changes: 29 additions & 25 deletions console/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,30 @@ void Menu::display()
int start = (this->position / PAGE_SIZE) * PAGE_SIZE; //

// go through this page of apps until the end of the page, or longer than the packages list
for (int x = start; x < start + PAGE_SIZE && x < get->packages.size(); x++)
for (int x = start; x < start + PAGE_SIZE && x < get->getPackages().size(); x++)
{
int curPosition = (x % PAGE_SIZE) * 3 + 2;

Package* cur = get->packages[x];
auto cur = get->list()[x];
std::stringstream line;
line << cur->title << " (" << cur->version << ")";
line << cur.getTitle() << " (" << cur.getVersion() << ")";
console->drawString(15, curPosition, line.str().c_str());

int r = (cur->status == UPDATE || cur->status == LOCAL) ? 0xFF : 0x00;
int g = (cur->status == UPDATE) ? 0xF7 : 0xFF;
int b = (cur->status == INSTALLED || cur->status == LOCAL) ? 0xFF : 0x00;
console->drawColorString(5, curPosition, cur->statusString(), r, g, b);
auto status = cur.getStatus();

int r = (status == UPDATE || status == LOCAL) ? 0xFF : 0x00;
int g = (status == UPDATE) ? 0xF7 : 0xFF;
int b = (status == INSTALLED || status == LOCAL) ? 0xFF : 0x00;
console->drawColorString(5, curPosition, cur.statusString(), r, g, b);

std::stringstream line2;
line2 << cur->short_desc << " [" << cur->author << "]";
line2 << cur.getShortDescription() << " [" << cur.getAuthor() << "]";

console->drawColorString(16, curPosition + 1, line2.str().c_str(), 0xcc, 0xcc, 0xcc);
}

std::stringstream footer;
footer << "Page " << this->position / PAGE_SIZE + 1 << " of " << (get->packages.size()-1) / PAGE_SIZE + 1;
footer << "Page " << this->position / PAGE_SIZE + 1 << " of " << (get->getPackages().size()-1) / PAGE_SIZE + 1;
console->drawString(34, 40, footer.str().c_str());
console->drawColorString(15, 42, "Use left/right and up/down to switch pages and apps", 0xcc, 0xcc, 0xcc);

Expand All @@ -98,28 +100,30 @@ void Menu::display()

if (this->screen == INSTALL_SCREEN)
{
if (this->position < 0 || this->position > get->packages.size())
if (this->position < 0 || this->position > get->getPackages().size())
{
// invalid selection, go back a screen
this->screen--;
return;
}

// currently selected package
Package* cur = get->packages[this->position];
auto cur = get->list()[this->position];

console->drawString(5, 3, cur.getTitle().c_str());
console->drawString(6, 5, cur.getVersion().c_str());
console->drawString(6, 6, cur.getAuthor().c_str());

console->drawString(5, 3, cur->title.c_str());
console->drawString(6, 5, cur->version.c_str());
console->drawString(6, 6, cur->author.c_str());
auto status = cur.getStatus();

int r = (cur->status == UPDATE || cur->status == LOCAL) ? 0xFF : 0x00;
int g = (cur->status == UPDATE) ? 0xF7 : 0xFF;
int b = (cur->status == INSTALLED || cur->status == LOCAL) ? 0xFF : 0x00;
console->drawColorString(5, 8, cur->statusString(), r, g, b);
int r = (status == UPDATE || status == LOCAL) ? 0xFF : 0x00;
int g = (status == UPDATE) ? 0xF7 : 0xFF;
int b = (status == INSTALLED || status == LOCAL) ? 0xFF : 0x00;
console->drawColorString(5, 8, cur.statusString(), r, g, b);

console->drawColorString(5, 12, "Press [A] to install this package", 0xff, 0xff, 0x00);

if (cur->status != GET && cur->status != LOCAL)
if (status != GET && status != LOCAL)
console->drawColorString(5, 14, "Press [X] to remove this package", 0xff, 0xff, 0x00);

console->drawString(5, 16, "Press [B] to go back");
Expand All @@ -128,9 +132,9 @@ void Menu::display()
if (this->screen == INSTALLING || this->screen == REMOVING)
{
// currently selected package
Package* cur = get->packages[this->position];
auto cur = get->list()[this->position];

console->drawString(5, 4, cur->title.c_str());
console->drawString(5, 4, cur.getTitle().c_str());

if (this->screen == INSTALLING)
console->drawColorString(5, 5, "Downloading package...", 0xff, 0xff, 0x00);
Expand Down Expand Up @@ -165,8 +169,8 @@ void Menu::initGet()
// this is a blocking load
this->get = new Get(DEFAULT_GET_HOME, DEFAULT_REPO);

if (get->packages.size() > 0)
this->repoUrl = get->packages[0]->repoUrl->c_str();
if (get->getRepos().size() > 0)
this->repoUrl = get->getRepos()[0]->getUrl().c_str();
else
this->repoUrl = "No packages found on any repos!";
}
Expand All @@ -181,10 +185,10 @@ void Menu::moveCursor(int diff)
if (position < 0)
{
// went back too far, wrap around to last package
position = get->packages.size() - 1;
position = get->getPackages().size() - 1;
}

else if (position >= get->packages.size())
else if (position >= get->getPackages().size())
{
// too far forward, wrap around to first package
position = 0;
Expand Down
2 changes: 1 addition & 1 deletion console/console_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int console_main(RootDisplay* rootDisplay, InputEvents* input)
// if we're on the install screen, perform an install
if (menu->screen == INSTALLING || menu->screen == REMOVING)
{
Package* target = menu->get->packages[menu->position];
auto target = menu->get->list()[menu->position];

// install package
bool succeeded = false;
Expand Down
6 changes: 3 additions & 3 deletions gui/AboutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ void AboutScreen::back()
void AboutScreen::launchFeedback()
{
// find the package corresponding to us
for (auto& package : this->get->packages)
for (auto& package : this->get->getPackages())
{
if (package->pkg_name == APP_SHORTNAME)
if (package->getPackageName() == APP_SHORTNAME)
{
RootDisplay::switchSubscreen(new Feedback(package));
RootDisplay::switchSubscreen(new Feedback(*package));
break;
}
}
Expand Down
31 changes: 18 additions & 13 deletions gui/AppCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
CST_Color AppCard::gray = { 80, 80, 80, 0xff };
CST_Color AppCard::black = { 0, 0, 0, 0xff };

AppCard::AppCard(Package* package, AppList* list)
: package(package)
AppCard::AppCard(Package& package, AppList* list)
: package(new Package(package))
, list(list)
, icon(package->getIconUrl().c_str(), [list, package] {
, icon(package.getIconUrl().c_str(), [list, package] {
// if the icon fails to load, and we're offline, try to use one from the cache
auto iconSavePath = std::string(list->get->pkg_path) + "/" + package->pkg_name + "/icon.png";
auto iconSavePath = std::string(list->get->mPkg_path) + "/" + package.getPackageName() + "/icon.png";

// check if the package is installed, and if the icon file exists using stat
struct stat buffer;
if (package->status != GET && stat(iconSavePath.c_str(), &buffer) == 0) {
if (package.getStatus() != GET && stat(iconSavePath.c_str(), &buffer) == 0) {
// file exists, return the path to the icon
auto img = new ImageElement(iconSavePath.c_str());
img->setScaleMode(SCALE_PROPORTIONAL_WITH_BG);
Expand All @@ -25,11 +25,11 @@ AppCard::AppCard(Package* package, AppList* list)

return new ImageElement(RAMFS "res/default.png");
}, !list)
, version(("v" + package->version).c_str(), TEXT_SIZE, &gray)
, status(package->statusString(), TEXT_SIZE, &gray)
, appname(package->title.c_str(), TEXT_SIZE + 3, &black)
, author(package->author.c_str(), TEXT_SIZE, &gray)
, statusicon((RAMFS "res/" + std::string(package->statusString()) + ".png").c_str())
, version(("v" + package.getVersion()).c_str(), TEXT_SIZE, &gray)
, status(package.statusString(), TEXT_SIZE, &gray)
, appname(package.getTitle().c_str(), TEXT_SIZE + 3, &black)
, author(package.getAuthor().c_str(), TEXT_SIZE, &gray)
, statusicon((RAMFS "res/" + std::string(package.statusString()) + ".png").c_str())
{
// fixed width+height of one app card
this->width = 256; // + 9px margins
Expand Down Expand Up @@ -92,7 +92,7 @@ void AppCard::handleIconLoad()
if (iconFetch)
return;

// printf("Y position: %d, %d, %d, %d - %s\n", list->y, this->y, this->height, SCREEN_HEIGHT, package->title.c_str());
// printf("Y position: %d, %d, %d, %d - %s\n", list->y, this->y, this->height, SCREEN_HEIGHT, package.getTitle().c_str());

// don't try to load the icon if the card is not visible ("on screen, within height (one card)")
CST_Rect rect = { this->xOff + this->x, this->yOff + this->y - this->height, this->width, this->height };
Expand All @@ -103,7 +103,7 @@ void AppCard::handleIconLoad()
// so the download can be started
icon.fetch();

// printf("Fetching icon for %s\n", package->title.c_str());
// printf("Fetching icon for %s\n", package.getTitle().c_str());

iconFetch = true;
}
Expand All @@ -128,7 +128,7 @@ void AppCard::displaySubscreen()
return;

// received a click on this app, add a subscreen under the parent
AppDetails *appDetails = new AppDetails(this->package, list, this);
AppDetails *appDetails = new AppDetails(*package, list, this);

if (!list->touchMode)
appDetails->highlighted = 0; // show cursor if we're not in touch mode
Expand All @@ -148,3 +148,8 @@ bool AppCard::process(InputEvents* event)

return super::process(event);
}

AppCard::~AppCard()
{
delete package;
}
3 changes: 2 additions & 1 deletion gui/AppCard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class AppList;
class AppCard : public Element
{
public:
AppCard(Package* package, AppList* list = nullptr);
AppCard(Package& package, AppList* list = nullptr);
~AppCard();
void update();
bool process(InputEvents* event);
void render(Element* parent);
Expand Down
Loading

0 comments on commit 41e7cdc

Please sign in to comment.