feature: supporting applications by author

This commit is contained in:
Joshua Peisach 2024-05-29 14:51:04 -04:00
parent ac5f1a1788
commit 0ce64f2318
No known key found for this signature in database
GPG Key ID: 41C3D4189AFEDB5A
3 changed files with 63 additions and 5 deletions

View File

@ -49,9 +49,11 @@ static int device_active = -1;
static int device_prefered = -1;
static app_filter current_filter = APP_FILTER_ALL;
static app_sort current_sort = APP_SORT_NAME;
static bool cmp_author = false;
static bool cmp_descending = false;
static bool cmp_release_date = false;
// app sorting: comparison function
static int cmp_app_entry (const void *p1, const void *p2) {
const app_entry *a1;
const app_entry *a2;
@ -89,6 +91,12 @@ static int cmp_app_entry (const void *p1, const void *p2) {
return -1;
}
if (cmp_author) {
if(a1->meta->coder && a2->meta->coder) {
return strcasecmp (a1->meta->coder, a2->meta->coder);
}
}
if (!a1->meta->name && !a2->meta->name)
return strcasecmp (a1->dirname, a2->dirname);
@ -143,15 +151,26 @@ app_sort app_entry_get_sort(void) {
}
void app_entry_set_sort(app_sort sort) {
// TODO: Cleanup here - if we are comparing one thing we shouldn't need to modify fields that are most of the time set to false anyways
switch (sort) {
case APP_SORT_DATE:
cmp_author = false;
cmp_descending = true;
cmp_release_date = true;
current_filter = APP_FILTER_DATEONLY;
current_sort = APP_SORT_DATE;
break;
case APP_SORT_AUTHOR:
cmp_author = true;
cmp_descending = false;
cmp_release_date = false;
current_filter = APP_FILTER_ALL;
current_sort = APP_SORT_AUTHOR;
break;
default:
cmp_author = false;
cmp_descending = false;
cmp_release_date = false;
current_filter = APP_FILTER_ALL;

View File

@ -37,7 +37,8 @@ typedef enum {
typedef enum {
APP_SORT_NAME = 0,
APP_SORT_DATE
APP_SORT_DATE,
APP_SORT_AUTHOR
} app_sort;
extern const char *app_path;

View File

@ -39,6 +39,7 @@ static const char *caption_device_names[DEVICE_COUNT];
static const char *caption_sort_by;
static const char *caption_sort_name;
static const char *caption_sort_date;
static const char *caption_sort_author;
static const char *l_version;
static const char *l_coder;
@ -72,6 +73,7 @@ void dialogs_theme_reinit (void) {
caption_sort_by = _("Sort applications by:");
caption_sort_name = _("Name");
caption_sort_date = _("Date");
caption_sort_author = _("Author");
string_about_pre =
"Credits\n\n"
@ -198,7 +200,8 @@ view * dialog_app (const app_entry *entry, const view *sub_view) {
else
desc = app_entry_desc_default;
v = view_new (11, sub_view, (view_width - theme_gfx[THEME_DIALOG]->w) / 2,
// TODO: Better ways of handling when we need to add more widgets
v = view_new (12, sub_view, (view_width - theme_gfx[THEME_DIALOG]->w) / 2,
44, TEX_LAYER_DIALOGS, PADS_B);
widget_image(&v->widgets[0], 0, 0, 0, theme_gfx[THEME_DIALOG],
@ -477,7 +480,7 @@ dialog_options_result show_options_dialog(const view *sub_view) {
app_entry_poll_status(true);
v = view_new (12, sub_view, (view_width - theme_gfx[THEME_DIALOG]->w) / 2,
v = view_new (13, sub_view, (view_width - theme_gfx[THEME_DIALOG]->w) / 2,
44, TEX_LAYER_DIALOGS, PADS_B);
widget_image (&v->widgets[0], 0, 0, 0, theme_gfx[THEME_DIALOG],
@ -495,8 +498,9 @@ dialog_options_result show_options_dialog(const view *sub_view) {
widget_button (&v->widgets[6], 52, 128, 1, BTN_SMALL, NULL);
widget_button (&v->widgets[7], 268, 128, 1, BTN_SMALL, NULL);
widget_button (&v->widgets[8], 52, 216, 1, BTN_SMALL, NULL);
widget_button (&v->widgets[9], 268, 216, 1, BTN_SMALL, NULL);
widget_button (&v->widgets[8], 52, 216, 1, BTN_TINY, NULL);
widget_button (&v->widgets[9], 186, 216, 1, BTN_TINY, NULL);
widget_button (&v->widgets[12], 320, 216, 1, BTN_TINY, NULL);
widget_button (&v->widgets[10], 32,
theme_gfx[THEME_DIALOG]->h -
@ -528,17 +532,34 @@ dialog_options_result show_options_dialog(const view *sub_view) {
widget_set_flag (&v->widgets[DLG_DEV_FIRST + i], WF_ENABLED, status[i]);
}
// TODO: set all captions to desel by default?
if (ret.sort == APP_SORT_DATE) {
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON_DESEL,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON_DESEL,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON,
caption_sort_date);
} else if (ret.sort == APP_SORT_AUTHOR) {
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON_DESEL,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON_DESEL,
caption_sort_date);
} else {
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON_DESEL,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON_DESEL,
caption_sort_date);
@ -590,6 +611,9 @@ dialog_options_result show_options_dialog(const view *sub_view) {
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON_DESEL,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON_DESEL,
caption_sort_date);
@ -598,9 +622,23 @@ dialog_options_result show_options_dialog(const view *sub_view) {
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON_DESEL,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON_DESEL,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON,
caption_sort_date);
} else if (v->focus == 12) {
ret.sort = APP_SORT_AUTHOR;
widget_button_set_caption(&v->widgets[8],
FONT_BUTTON_DESEL,
caption_sort_name);
widget_button_set_caption(&v->widgets[12],
FONT_BUTTON,
caption_sort_author);
widget_button_set_caption(&v->widgets[9],
FONT_BUTTON_DESEL,
caption_sort_date);
} else if ((v->focus == 10) || (v->focus == 11)) {
break;
}