mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/external] Added icon support, fixed stuff.
This commit is contained in:
2
apps/external/Makefile
vendored
2
apps/external/Makefile
vendored
@@ -5,6 +5,8 @@ app_external_src = $(addprefix apps/external/,\
|
||||
archive.cpp \
|
||||
)
|
||||
|
||||
$(eval $(call depends_on_image,apps/home/controller.cpp,apps/external/external_icon.png))
|
||||
|
||||
else
|
||||
|
||||
apps += External::App
|
||||
|
||||
13
apps/external/archive.cpp
vendored
13
apps/external/archive.cpp
vendored
@@ -40,6 +40,9 @@ bool isExamModeAndFileNotExecutable(const TarHeader* tar) {
|
||||
}
|
||||
|
||||
bool fileAtIndex(size_t index, File &entry) {
|
||||
if (index == -1)
|
||||
return false;
|
||||
|
||||
const TarHeader* tar = reinterpret_cast<const TarHeader*>(0x90200000);
|
||||
unsigned size = 0;
|
||||
|
||||
@@ -123,7 +126,10 @@ bool executableAtIndex(size_t index, File &entry) {
|
||||
for (count = 0; fileAtIndex(count, dummy); count++) {
|
||||
if (dummy.isExecutable) {
|
||||
if (final_count == index) {
|
||||
entry = dummy;
|
||||
entry.name = dummy.name;
|
||||
entry.data = dummy.data;
|
||||
entry.dataLength = dummy.dataLength;
|
||||
entry.isExecutable = dummy.isExecutable;
|
||||
return true;
|
||||
}
|
||||
final_count++;
|
||||
@@ -176,7 +182,10 @@ uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) {
|
||||
}
|
||||
|
||||
int indexFromName(const char *name) {
|
||||
return 1;
|
||||
if (strcmp(name, "Built-in") == 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t numberOfFiles() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "app_cell.h"
|
||||
#include <assert.h>
|
||||
#include <apps/i18n.h>
|
||||
#include <escher/palette.h>
|
||||
|
||||
namespace Home {
|
||||
|
||||
@@ -31,15 +33,19 @@ void AppCell::layoutSubviews(bool force) {
|
||||
m_nameView.setFrame(KDRect((bounds().width()-nameSize.width())/2-k_nameWidthMargin, bounds().height()-nameSize.height() - 2*k_nameHeightMargin, nameSize.width()+2*k_nameWidthMargin, nameSize.height()+2*k_nameHeightMargin), force);
|
||||
}
|
||||
|
||||
void AppCell::setExtAppDescriptor(const char* name) {
|
||||
// m_iconView.setImage(descriptor->icon());
|
||||
void AppCell::setExtAppDescriptor(const char* name, const Image* icon) {
|
||||
m_iconView.setImage(icon);
|
||||
m_nameView.setText(name);
|
||||
m_nameView.setTextColor(Palette::AccentText);
|
||||
m_nameView.setMessage(I18n::Message::Default);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void AppCell::setAppDescriptor(::App::Descriptor * descriptor) {
|
||||
m_iconView.setImage(descriptor->icon());
|
||||
m_nameView.setMessage(descriptor->name());
|
||||
m_nameView.setTextColor(Palette::PrimaryText);
|
||||
m_nameView.setText(nullptr);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
void setVisible(bool visible);
|
||||
void reloadCell() override;
|
||||
void setAppDescriptor(::App::Descriptor * appDescriptor);
|
||||
void setExtAppDescriptor(const char* name);
|
||||
void setExtAppDescriptor(const char* name, const Image* icon);
|
||||
private:
|
||||
static constexpr KDCoordinate k_iconMargin = 22;
|
||||
static constexpr KDCoordinate k_iconWidth = 55;
|
||||
|
||||
@@ -7,7 +7,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
#ifdef HOME_DISPLAY_EXTERNALS
|
||||
#include "../external/external_icon.h"
|
||||
#include "../external/archive.h"
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
namespace Home {
|
||||
@@ -68,38 +70,41 @@ bool Controller::handleEvent(Ion::Events::Event event) {
|
||||
|
||||
#ifdef HOME_DISPLAY_EXTERNALS
|
||||
if (index >= container->numberOfApps()) {
|
||||
External::Archive::File executable;
|
||||
if (External::Archive::executableAtIndex(index - container->numberOfApps(), executable)) {
|
||||
uint32_t res = External::Archive::executeFile(executable.name, ((App *)m_app)->heap(), ((App *)m_app)->heapSize());
|
||||
((App*)m_app)->redraw();
|
||||
switch(res) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Container::activeApp()->displayWarning(I18n::Message::ExternalAppApiMismatch);
|
||||
break;
|
||||
case 2:
|
||||
Container::activeApp()->displayWarning(I18n::Message::StorageMemoryFull1);
|
||||
break;
|
||||
default:
|
||||
Container::activeApp()->displayWarning(I18n::Message::ExternalAppExecError);
|
||||
break;
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSymNoText || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSym) {
|
||||
App::app()->displayWarning(I18n::Message::ForbidenAppInExamMode1, I18n::Message::ForbidenAppInExamMode2);
|
||||
} else {
|
||||
External::Archive::File executable;
|
||||
if (External::Archive::executableAtIndex(index - container->numberOfApps(), executable)) {
|
||||
uint32_t res = External::Archive::executeFile(executable.name, ((App *)m_app)->heap(), ((App *)m_app)->heapSize());
|
||||
((App*)m_app)->redraw();
|
||||
switch(res) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Container::activeApp()->displayWarning(I18n::Message::ExternalAppApiMismatch);
|
||||
break;
|
||||
case 2:
|
||||
Container::activeApp()->displayWarning(I18n::Message::StorageMemoryFull1);
|
||||
break;
|
||||
default:
|
||||
Container::activeApp()->displayWarning(I18n::Message::ExternalAppExecError);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
#endif
|
||||
|
||||
::App::Snapshot * selectedSnapshot = container->appSnapshotAtIndex(index);
|
||||
if (((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSymNoText) && selectedSnapshot->descriptor()->examinationLevel() < 2) ||
|
||||
((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Standard || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSym) && selectedSnapshot->descriptor()->examinationLevel() < 1)) {
|
||||
App::app()->displayWarning(I18n::Message::ForbidenAppInExamMode1, I18n::Message::ForbidenAppInExamMode2);
|
||||
} else {
|
||||
bool switched = container->switchTo(selectedSnapshot);
|
||||
assert(switched);
|
||||
(void) switched; // Silence compilation warning about unused variable.
|
||||
}
|
||||
::App::Snapshot * selectedSnapshot = container->appSnapshotAtIndex(index);
|
||||
if (((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSymNoText) && selectedSnapshot->descriptor()->examinationLevel() < 2) ||
|
||||
((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Standard || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSym) && selectedSnapshot->descriptor()->examinationLevel() < 1)) {
|
||||
App::app()->displayWarning(I18n::Message::ForbidenAppInExamMode1, I18n::Message::ForbidenAppInExamMode2);
|
||||
} else {
|
||||
bool switched = container->switchTo(selectedSnapshot);
|
||||
assert(switched);
|
||||
(void) switched; // Silence compilation warning about unused variable.
|
||||
}
|
||||
#ifdef HOME_DISPLAY_EXTERNALS
|
||||
}
|
||||
#endif
|
||||
@@ -175,7 +180,25 @@ void Controller::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
|
||||
|
||||
|
||||
if (External::Archive::executableAtIndex(appIndex - container->numberOfApps(), app_file)) {
|
||||
appCell->setExtAppDescriptor(app_file.name);
|
||||
char temp_name_buffer[100];
|
||||
strlcpy(temp_name_buffer, app_file.name, 94);
|
||||
strlcat(temp_name_buffer, ".icon", 99);
|
||||
|
||||
int img_index = External::Archive::indexFromName(temp_name_buffer);
|
||||
|
||||
if (img_index != -1) {
|
||||
External::Archive::File image_file;
|
||||
if (External::Archive::fileAtIndex(img_index, image_file)) {
|
||||
const Image* img = new Image(55, 56, image_file.data, image_file.dataLength);
|
||||
appCell->setExtAppDescriptor(app_file.name, img);
|
||||
|
||||
} else {
|
||||
appCell->setExtAppDescriptor(app_file.name, ImageStore::ExternalIcon);
|
||||
}
|
||||
} else {
|
||||
appCell->setExtAppDescriptor(app_file.name, ImageStore::ExternalIcon);
|
||||
}
|
||||
|
||||
appCell->setVisible(true);
|
||||
} else {
|
||||
appCell->setVisible(false);
|
||||
@@ -201,7 +224,6 @@ int Controller::numberOfIcons() const {
|
||||
}
|
||||
|
||||
void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) {
|
||||
AppsContainer * container = AppsContainer::sharedAppsContainer();
|
||||
if (withinTemporarySelection) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <escher/message_text_view.h>
|
||||
#include <assert.h>
|
||||
#include <apps/i18n.h>
|
||||
|
||||
MessageTextView::MessageTextView(const KDFont * font, I18n::Message message, float horizontalAlignment, float verticalAlignment,
|
||||
KDColor textColor, KDColor backgroundColor) :
|
||||
@@ -9,9 +10,12 @@ MessageTextView::MessageTextView(const KDFont * font, I18n::Message message, flo
|
||||
}
|
||||
|
||||
const char * MessageTextView::text() const {
|
||||
if (m_text)
|
||||
if (m_message != I18n::Message::Default && m_text == nullptr)
|
||||
return I18n::translate(m_message);
|
||||
if (m_text != nullptr && m_message == I18n::Message::Default)
|
||||
return m_text;
|
||||
return I18n::translate(m_message);
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MessageTextView::setText(const char * text) {
|
||||
|
||||
Reference in New Issue
Block a user