Themeplaza browser (#140)

* builds at least

* meh, multithreading will come later. or never

* movement added, and correct grid mode

* switching splash/themes when in browser mode

* closer to the actual themeplaza menu

* bring back downloading from qr

* show a download screen when downloading from browser

* fix selecting with touchscreen in browser mode

* update readme for jansson

* fix quitting with start in browser mode

* add jump menu for browser mode

* rotate is broken, add working touchscreen page changing

* allow quitting preview mode with B in browser mode

* proper way to have portlibs

* add searching

* show error when search has no results

* always free entries and icon ids
This commit is contained in:
LiquidFenrir
2018-04-01 02:31:46 +02:00
committed by Alex Taber
parent 5090da114f
commit a2b5788fe8
18 changed files with 1212 additions and 350 deletions

View File

@@ -30,12 +30,12 @@
#include "unicode.h"
#include "draw.h"
void delete_entry(Entry_s entry)
void delete_entry(Entry_s * entry, bool is_file)
{
if(entry.is_zip)
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, entry.path));
if(is_file)
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
else
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, entry.path));
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
}
u32 load_data(char * filename, Entry_s entry, char ** buf)
@@ -114,15 +114,19 @@ static int compare_entries(const void * a, const void * b)
static void sort_list(Entry_List_s * list)
{
qsort(list->entries, list->entries_count, sizeof(Entry_s), compare_entries); //alphabet sort
if(list->entries != NULL)
qsort(list->entries, list->entries_count, sizeof(Entry_s), compare_entries); //alphabet sort
}
Result load_entries(const char * loading_path, Entry_List_s * list, EntryMode mode)
Result load_entries(const char * loading_path, Entry_List_s * list)
{
Handle dir_handle;
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, loading_path));
if(R_FAILED(res))
{
DEBUG("Failed to open folder: %s\n", loading_path);
return res;
}
u32 entries_read = 1;
@@ -133,7 +137,7 @@ Result load_entries(const char * loading_path, Entry_List_s * list, EntryMode mo
if(R_FAILED(res) || entries_read == 0)
break;
if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP"))
if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP"))
continue;
list->entries_count++;
@@ -143,6 +147,7 @@ Result load_entries(const char * loading_path, Entry_List_s * list, EntryMode mo
free(list->entries);
list->entries = NULL;
res = -1;
DEBUG("break\n");
break;
}
else
@@ -155,14 +160,12 @@ Result load_entries(const char * loading_path, Entry_List_s * list, EntryMode mo
strucat(current_entry->path, dir_entry.name);
current_entry->is_zip = !strcmp(dir_entry.shortExt, "ZIP");
parse_smdh(current_entry, dir_entry.name);
}
FSDIR_Close(dir_handle);
sort_list(list);
list->mode = mode;
return res;
}
@@ -176,7 +179,7 @@ void load_icons_first(Entry_List_s * list, bool silent)
int starti = 0, endi = 0;
if(list->entries_count <= ENTRIES_PER_SCREEN*ICONS_OFFSET_AMOUNT)
if(list->entries_count <= list->entries_loaded*ICONS_OFFSET_AMOUNT)
{
DEBUG("small load\n");
// if the list is one that doesnt need swapping, load everything at once
@@ -186,14 +189,15 @@ void load_icons_first(Entry_List_s * list, bool silent)
{
DEBUG("extended load\n");
// otherwise, load around to prepare for swapping
starti = list->scroll - ENTRIES_PER_SCREEN*ICONS_VISIBLE;
endi = starti + ENTRIES_PER_SCREEN*ICONS_OFFSET_AMOUNT;
starti = list->scroll - list->entries_loaded*ICONS_VISIBLE;
endi = starti + list->entries_loaded*ICONS_OFFSET_AMOUNT;
}
ssize_t * icon_ids = (ssize_t *)list->icons_ids;
list->icons_ids = calloc(endi-starti, sizeof(ssize_t));
ssize_t * icons_ids = list->icons_ids;
ssize_t id = list->texture_id_offset;
memset(icon_ids, 0, ENTRIES_PER_SCREEN*ICONS_OFFSET_AMOUNT*sizeof(ssize_t));
for(int i = starti; i < endi; i++, id++)
{
int offset = i;
@@ -204,7 +208,8 @@ void load_icons_first(Entry_List_s * list, bool silent)
Entry_s current_entry = list->entries[offset];
load_smdh_icon(current_entry, id);
icon_ids[i-starti] = id;
icons_ids[i-starti] = id;
}
}
@@ -229,21 +234,21 @@ void handle_scrolling(Entry_List_s * list)
{
// Scroll the menu up or down if the selected theme is out of its bounds
//----------------------------------------------------------------
if(list->entries_count > ENTRIES_PER_SCREEN)
if(list->entries_count > list->entries_loaded)
{
for(int i = 0; i < list->entries_count; i++)
{
int change = 0;
if(list->entries_count > ENTRIES_PER_SCREEN*2 && list->previous_scroll < ENTRIES_PER_SCREEN && list->selected_entry >= list->entries_count - ENTRIES_PER_SCREEN)
if(list->entries_count > list->entries_loaded*2 && list->previous_scroll < list->entries_loaded && list->selected_entry >= list->entries_count - list->entries_loaded)
{
list->scroll = list->entries_count - ENTRIES_PER_SCREEN;
list->scroll = list->entries_count - list->entries_loaded;
}
else if(list->entries_count > ENTRIES_PER_SCREEN*2 && list->selected_entry < ENTRIES_PER_SCREEN && list->previous_selected >= list->entries_count - ENTRIES_PER_SCREEN)
else if(list->entries_count > list->entries_loaded*2 && list->selected_entry < list->entries_loaded && list->previous_selected >= list->entries_count - list->entries_loaded)
{
list->scroll = 0;
}
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+ENTRIES_PER_SCREEN)
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+list->entries_loaded)
{
change = 1;
}
@@ -251,21 +256,21 @@ void handle_scrolling(Entry_List_s * list)
{
change = -1;
}
else if(list->selected_entry == list->previous_selected+ENTRIES_PER_SCREEN || list->selected_entry >= list->scroll + ENTRIES_PER_SCREEN)
else if(list->selected_entry == list->previous_selected+list->entries_loaded || list->selected_entry >= list->scroll + list->entries_loaded)
{
change = ENTRIES_PER_SCREEN;
change = list->entries_loaded;
}
else if(list->selected_entry == list->previous_selected-ENTRIES_PER_SCREEN || list->selected_entry < list->scroll)
else if(list->selected_entry == list->previous_selected-list->entries_loaded || list->selected_entry < list->scroll)
{
change = -ENTRIES_PER_SCREEN;
change = -list->entries_loaded;
}
list->scroll += change;
if(list->scroll < 0)
list->scroll = 0;
else if(list->scroll > list->entries_count - ENTRIES_PER_SCREEN)
list->scroll = list->entries_count - ENTRIES_PER_SCREEN;
else if(list->scroll > list->entries_count - list->entries_loaded)
list->scroll = list->entries_count - list->entries_loaded;
if(!change)
list->previous_selected = list->selected_entry;
@@ -283,13 +288,13 @@ static void load_icons(Entry_List_s * current_list)
handle_scrolling(current_list);
if(current_list->entries_count <= ENTRIES_PER_SCREEN*ICONS_OFFSET_AMOUNT || current_list->previous_scroll == current_list->scroll)
if(current_list->entries_count <= current_list->entries_loaded*ICONS_OFFSET_AMOUNT || current_list->previous_scroll == current_list->scroll)
return; // return if the list is one that doesnt need swapping, or if nothing changed
#define SIGN(x) (x > 0 ? 1 : ((x < 0) ? -1 : 0))
int delta = current_list->scroll - current_list->previous_scroll;
if(abs(delta) >= current_list->entries_count - ENTRIES_PER_SCREEN*(ICONS_OFFSET_AMOUNT-1))
if(abs(delta) >= current_list->entries_count - current_list->entries_loaded*(ICONS_OFFSET_AMOUNT-1))
delta = -SIGN(delta) * (current_list->entries_count - abs(delta));
int starti = current_list->scroll;
@@ -306,26 +311,26 @@ static void load_icons(Entry_List_s * current_list)
ssize_t * ids = calloc(abs(delta), sizeof(ssize_t));
#define FIRST(arr) arr[0]
#define LAST(arr) arr[ENTRIES_PER_SCREEN*ICONS_OFFSET_AMOUNT - 1]
#define LAST(arr) arr[current_list->entries_loaded*ICONS_OFFSET_AMOUNT - 1]
ssize_t * icons_ids = (ssize_t *)current_list->icons_ids;
ssize_t * icons_ids = current_list->icons_ids;
for(int i = starti; i != endi; i++, ctr++)
{
ssize_t id = 0;
int offset = i;
rotate(icons_ids, ICONS_OFFSET_AMOUNT*ENTRIES_PER_SCREEN, -1*SIGN(delta));
rotate(icons_ids, ICONS_OFFSET_AMOUNT*current_list->entries_loaded, -1*SIGN(delta));
if(delta > 0)
{
id = LAST(icons_ids);
offset += ENTRIES_PER_SCREEN*ICONS_UNDER - delta;
offset += current_list->entries_loaded*ICONS_UNDER - delta;
}
else
{
id = FIRST(icons_ids);
offset -= ENTRIES_PER_SCREEN*ICONS_VISIBLE;
offset -= current_list->entries_loaded*ICONS_VISIBLE;
i -= 2; //i-- twice to counter the i++, needed only for this case
}
@@ -344,7 +349,11 @@ static void load_icons(Entry_List_s * current_list)
svcSleepThread(1e6);
for(int i = 0; i < abs(delta); i++)
load_smdh_icon(*entries[i], ids[i]);
{
Entry_s current_entry = *entries[i];
ssize_t id = ids[i];
load_smdh_icon(current_entry, id);
}
free(entries);
free(ids);