diff --git a/romfs/kbd_layout.png b/romfs/kbd_layout.png deleted file mode 100644 index 08644a8..0000000 Binary files a/romfs/kbd_layout.png and /dev/null differ diff --git a/romfs/kbd_press_overlay.png b/romfs/kbd_press_overlay.png deleted file mode 100644 index 6cd73dc..0000000 Binary files a/romfs/kbd_press_overlay.png and /dev/null differ diff --git a/romfs/kbd_text_bg.png b/romfs/kbd_text_bg.png deleted file mode 100644 index 0904265..0000000 Binary files a/romfs/kbd_text_bg.png and /dev/null differ diff --git a/romfs/kbd_text_fg.png b/romfs/kbd_text_fg.png deleted file mode 100644 index 1da3316..0000000 Binary files a/romfs/kbd_text_fg.png and /dev/null differ diff --git a/source/core/screen.c b/source/core/screen.c index ac837c1..6d6f17e 100644 --- a/source/core/screen.c +++ b/source/core/screen.c @@ -244,10 +244,6 @@ void screen_init() { screen_load_texture_file(TEXTURE_WIFI_1, "wifi1.png", true); screen_load_texture_file(TEXTURE_WIFI_2, "wifi2.png", true); screen_load_texture_file(TEXTURE_WIFI_3, "wifi3.png", true); - screen_load_texture_file(TEXTURE_KBD_LAYOUT, "kbd_layout.png", true); - screen_load_texture_file(TEXTURE_KBD_PRESS_OVERLAY, "kbd_press_overlay.png", true); - screen_load_texture_file(TEXTURE_KBD_TEXT_BG, "kbd_text_bg.png", true); - screen_load_texture_file(TEXTURE_KBD_TEXT_FG, "kbd_text_fg.png", true); } void screen_exit() { diff --git a/source/core/screen.h b/source/core/screen.h index 37fd94c..651a255 100644 --- a/source/core/screen.h +++ b/source/core/screen.h @@ -39,12 +39,8 @@ #define TEXTURE_WIFI_1 28 #define TEXTURE_WIFI_2 29 #define TEXTURE_WIFI_3 30 -#define TEXTURE_KBD_LAYOUT 31 -#define TEXTURE_KBD_PRESS_OVERLAY 32 -#define TEXTURE_KBD_TEXT_BG 33 -#define TEXTURE_KBD_TEXT_FG 34 -#define TEXTURE_AUTO_START 33 +#define TEXTURE_AUTO_START 31 #define NUM_COLORS 9 diff --git a/source/ui/kbd.c b/source/ui/kbd.c deleted file mode 100644 index 661c42a..0000000 --- a/source/ui/kbd.c +++ /dev/null @@ -1,376 +0,0 @@ -#include -#include -#include - -#include <3ds.h> - -#include "error.h" -#include "ui.h" -#include "../core/screen.h" - -#define MAX_INPUT_SIZE 1024 - -typedef struct { - char input[MAX_INPUT_SIZE]; - size_t inputPos; - - bool shift; - bool capsLock; - - float scrollPos; - u32 lastTouchY; - - bool keyboardTouched; - u64 nextRepeatTime; - - void* data; - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2); - void (*finished)(void* data, char* input); - void (*canceled)(void* data); -} kbd_data; - -typedef struct { - char normal; - char special; - - void (*press)(ui_view* view, kbd_data* data); - - u32 x; - u32 y; - u32 width; - u32 height; -} LayoutKey; - -static void kbd_backspace(ui_view* view, kbd_data* data) { - if(data->inputPos > 0) { - data->input[--data->inputPos] = '\0'; - } -} - -static void kbd_capslock(ui_view* view, kbd_data* data) { - data->capsLock = !data->capsLock; -} - -static void kbd_shift(ui_view* view, kbd_data* data) { - data->shift = !data->shift; -} - -static void kbd_cancel(ui_view* view, kbd_data* data) { - ui_pop(); - - if(data->canceled != NULL) { - data->canceled(data->data); - } - - free(data); - ui_destroy(view); -} - -static void kbd_finish(ui_view* view, kbd_data* data) { - ui_pop(); - - if(data->finished != NULL) { - data->finished(data->data, data->input); - } - - free(data); - ui_destroy(view); -} - -#define NUM_KEYS 56 - -static LayoutKey layout[NUM_KEYS] = { - // Row 1 - {'`', '~', NULL, 1, 1, 21, 21}, - {'1', '!', NULL, 22, 1, 21, 21}, - {'2', '@', NULL, 43, 1, 21, 21}, - {'3', '#', NULL, 64, 1, 21, 21}, - {'4', '$', NULL, 85, 1, 21, 21}, - {'5', '%', NULL, 106, 1, 21, 21}, - {'6', '^', NULL, 127, 1, 21, 21}, - {'7', '&', NULL, 148, 1, 21, 21}, - {'8', '*', NULL, 169, 1, 21, 21}, - {'9', '(', NULL, 190, 1, 21, 21}, - {'0', ')', NULL, 211, 1, 21, 21}, - {'-', '_', NULL, 232, 1, 21, 21}, - {'=', '+', NULL, 253, 1, 21, 21}, - {'\0', '\0', kbd_backspace, 274, 1, 42, 21}, - - // Row 2 - {'\t', '\t', NULL, 1, 22, 31, 21}, - {'q', 'Q', NULL, 32, 22, 21, 21}, - {'w', 'W', NULL, 53, 22, 21, 21}, - {'e', 'E', NULL, 74, 22, 21, 21}, - {'r', 'R', NULL, 95, 22, 21, 21}, - {'t', 'T', NULL, 116, 22, 21, 21}, - {'y', 'Y', NULL, 137, 22, 21, 21}, - {'u', 'U', NULL, 158, 22, 21, 21}, - {'i', 'I', NULL, 179, 22, 21, 21}, - {'o', 'O', NULL, 200, 22, 21, 21}, - {'p', 'P', NULL, 221, 22, 21, 21}, - {'[', '{', NULL, 242, 22, 21, 21}, - {']', '}', NULL, 263, 22, 21, 21}, - {'\\', '|', NULL, 284, 22, 32, 21}, - - // Row 3 - {'\0', '\0', kbd_capslock, 1, 43, 36, 21}, - {'a', 'A', NULL, 37, 43, 21, 21}, - {'s', 'S', NULL, 58, 43, 21, 21}, - {'d', 'D', NULL, 79, 43, 21, 21}, - {'f', 'F', NULL, 100, 43, 21, 21}, - {'g', 'G', NULL, 121, 43, 21, 21}, - {'h', 'H', NULL, 142, 43, 21, 21}, - {'j', 'J', NULL, 163, 43, 21, 21}, - {'k', 'K', NULL, 184, 43, 21, 21}, - {'l', 'L', NULL, 205, 43, 21, 21}, - {';', ':', NULL, 226, 43, 21, 21}, - {'\'', '"', NULL, 247, 43, 21, 21}, - {'\n', '\n', NULL, 268, 43, 48, 21}, - - // Row 4 - {'\0', '\0', kbd_shift, 1, 64, 47, 21}, - {'z', 'Z', NULL, 48, 64, 21, 21}, - {'x', 'X', NULL, 69, 64, 21, 21}, - {'c', 'C', NULL, 90, 64, 21, 21}, - {'v', 'V', NULL, 111, 64, 21, 21}, - {'b', 'B', NULL, 132, 64, 21, 21}, - {'n', 'N', NULL, 153, 64, 21, 21}, - {'m', 'M', NULL, 174, 64, 21, 21}, - {',', '<', NULL, 195, 64, 21, 21}, - {'.', '>', NULL, 216, 64, 21, 21}, - {'/', '?', NULL, 237, 64, 21, 21}, - {'\0', '\0', kbd_shift, 258, 64, 58, 21}, - - // Row 5 - {'\0', '\0', kbd_cancel, 1, 85, 94, 21}, - {' ', ' ', NULL, 95, 85, 127, 21}, - {'\0', '\0', kbd_finish, 222, 85, 94, 21}, -}; - -static void kbd_update(ui_view* view, void* data, float bx1, float by1, float bx2, float by2) { - kbd_data* kbdData = (kbd_data*) data; - - if(hidKeysDown() & KEY_A) { - kbd_finish(view, kbdData); - return; - } - - if(hidKeysDown() & KEY_B) { - kbd_cancel(view, kbdData); - return; - } - - u32 kbdTextWidth = 0; - u32 kbdTextHeight = 0; - screen_get_texture_size(&kbdTextWidth, &kbdTextHeight, TEXTURE_KBD_TEXT_BG); - - float kbdTextX = bx1 + (bx2 - bx1 - kbdTextWidth) / 2; - - float inputHeight = 0; - screen_get_string_size_wrap(NULL, &inputHeight, kbdData->input, 0.5f, 0.5f, kbdTextX + kbdTextWidth); - - if(hidKeysHeld() & KEY_TOUCH) { - touchPosition pos; - hidTouchRead(&pos); - - u32 kbdWidth = 0; - u32 kbdHeight = 0; - screen_get_texture_size(&kbdWidth, &kbdHeight, TEXTURE_KBD_LAYOUT); - - float kbdX = bx1 + (bx2 - bx1 - kbdWidth) / 2; - float kbdY = by2 - kbdHeight - 2; - - if(pos.px >= kbdX && pos.py >= kbdY && pos.px < kbdX + kbdWidth && pos.py < kbdY + kbdHeight) { - if((hidKeysDown() & KEY_TOUCH) || (kbdData->keyboardTouched && osGetTime() >= kbdData->nextRepeatTime)) { - kbdData->keyboardTouched = true; - kbdData->nextRepeatTime = osGetTime() + ((hidKeysDown() & KEY_TOUCH) ? 500 : 100); - - for(u32 i = 0; i < NUM_KEYS; i++) { - LayoutKey key = layout[i]; - if(pos.px >= kbdX + key.x && pos.py >= kbdY + key.y && pos.px < kbdX + key.x + key.width && pos.py < kbdY + key.y + key.height) { - if(key.press != NULL) { - key.press(view, kbdData); - } else if(kbdData->inputPos < MAX_INPUT_SIZE) { - kbdData->input[kbdData->inputPos++] = (kbdData->shift || kbdData->capsLock) ? key.special : key.normal; - - if(key.normal != key.special) { - kbdData->shift = false; - } - - screen_get_string_size_wrap(NULL, &inputHeight, kbdData->input, 0.5f, 0.5f, kbdTextX + kbdTextWidth); - - if(inputHeight > kbdTextHeight && kbdData->scrollPos < inputHeight - kbdTextHeight) { - kbdData->scrollPos = inputHeight - kbdTextHeight; - } - } - - break; - } - } - } - } else { - kbdData->keyboardTouched = false; - } - - if(!(hidKeysDown() & KEY_TOUCH)) { - float kbdTextX = bx1 + (bx2 - bx1 - kbdTextWidth) / 2; - float kbdTextY = by1 + 2; - - if(pos.px >= kbdTextX && pos.py >= kbdTextY && pos.px < kbdTextX + kbdTextWidth && pos.py < kbdTextY + kbdTextHeight) { - kbdData->scrollPos += -((int) pos.py - (int) kbdData->lastTouchY); - } - } - - kbdData->lastTouchY = pos.py; - } else { - kbdData->keyboardTouched = false; - } - - if(kbdData->scrollPos > inputHeight - kbdTextHeight) { - kbdData->scrollPos = inputHeight - kbdTextHeight; - } - - if(kbdData->scrollPos < 0) { - kbdData->scrollPos = 0; - } -} - -static void kbd_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { - kbd_data* kbdData = (kbd_data*) data; - - if(kbdData->drawTop != NULL) { - kbdData->drawTop(view, kbdData->data, x1, y1, x2, y2); - } -} - -static void kbd_draw_bottom(ui_view* view, void* data, float x1, float y1, float x2, float y2) { - kbd_data* kbdData = (kbd_data*) data; - - touchPosition pos; - hidTouchRead(&pos); - - u32 kbdTextWidth = 0; - u32 kbdTextHeight = 0; - screen_get_texture_size(&kbdTextWidth, &kbdTextHeight, TEXTURE_KBD_TEXT_BG); - - float kbdTextX = x1 + (x2 - x1 - kbdTextWidth) / 2; - float kbdTextY = y1 + 2; - screen_draw_texture(TEXTURE_KBD_TEXT_BG, kbdTextX, kbdTextY, kbdTextWidth, kbdTextHeight); - - screen_set_scissor(true, (u32) (kbdTextX + 1), (u32) (kbdTextY + 1), kbdTextWidth - 1, kbdTextHeight - 1); - screen_draw_string_wrap(kbdData->input, kbdTextX + 1, kbdTextY + 1 - kbdData->scrollPos, 0.5f, 0.5f, COLOR_TEXT, false, kbdTextX + kbdTextWidth); - screen_set_scissor(false, 0, 0, 0, 0); - - u32 kbdTextFgWidth = 0; - u32 kbdTextFgHeight = 0; - screen_get_texture_size(&kbdTextFgWidth, &kbdTextFgHeight, TEXTURE_KBD_TEXT_FG); - - float kbdTextFgX = kbdTextX + (((int) kbdTextWidth - (int) kbdTextFgWidth) / 2); - float kbdTextFgY = kbdTextY + (((int) kbdTextHeight - (int) kbdTextFgHeight) / 2); - screen_draw_texture(TEXTURE_KBD_TEXT_FG, kbdTextFgX, kbdTextFgY, kbdTextFgWidth, kbdTextFgHeight); - - float inputHeight = 0; - screen_get_string_size_wrap(NULL, &inputHeight, kbdData->input, 0.5f, 0.5f, kbdTextX + kbdTextWidth); - - if(inputHeight > kbdTextHeight) { - u32 scrollBarWidth = 0; - screen_get_texture_size(&scrollBarWidth, NULL, TEXTURE_SCROLL_BAR); - - float scrollBarHeight = (kbdTextHeight / inputHeight) * kbdTextHeight; - - float scrollBarX = kbdTextX + kbdTextWidth - scrollBarWidth; - float scrollBarY = kbdTextY + (kbdData->scrollPos / inputHeight) * kbdTextHeight; - - screen_draw_texture(TEXTURE_SCROLL_BAR, scrollBarX, scrollBarY, scrollBarWidth, scrollBarHeight); - } - - u32 kbdWidth = 0; - u32 kbdHeight = 0; - screen_get_texture_size(&kbdWidth, &kbdHeight, TEXTURE_KBD_LAYOUT); - - float kbdX = x1 + (x2 - x1 - kbdWidth) / 2; - float kbdY = y2 - kbdHeight - 2; - screen_draw_texture(TEXTURE_KBD_LAYOUT, kbdX, kbdY, kbdWidth, kbdHeight); - - for(u32 i = 0; i < NUM_KEYS; i++) { - LayoutKey key = layout[i]; - - char text[16]; - if(key.press == kbd_backspace) { - snprintf(text, sizeof(text), "Del"); - } else if(key.press == kbd_capslock) { - snprintf(text, sizeof(text), "Caps"); - } else if(key.press == kbd_shift) { - snprintf(text, sizeof(text), "Shift"); - } else if(key.press == kbd_cancel) { - snprintf(text, sizeof(text), "Cancel (B)"); - } else if(key.press == kbd_finish) { - snprintf(text, sizeof(text), "Finish (A)"); - } else if(key.normal == '\t') { - snprintf(text, sizeof(text), "Tab"); - } else if(key.normal == '\n') { - snprintf(text, sizeof(text), "Enter"); - } else if(key.normal == ' ') { - snprintf(text, sizeof(text), "Space"); - } else { - snprintf(text, sizeof(text), "%c", (kbdData->shift || kbdData->capsLock) ? key.special : key.normal); - } - - float textWidth = 0; - float textHeight = 0; - screen_get_string_size(&textWidth, &textHeight, text, 0.5f, 0.5f); - - float textX = kbdX + key.x + (key.width - textWidth) / 2; - float textY = kbdY + key.y + (key.height - textHeight) / 2; - screen_draw_string(text, textX, textY, 0.5f, 0.5f, COLOR_TEXT, true); - - if((key.press == kbd_capslock && kbdData->capsLock) - || (key.press == kbd_shift && kbdData->shift) - || ((hidKeysHeld() & KEY_TOUCH) && pos.px >= kbdX + key.x && pos.py >= kbdY + key.y && pos.px < kbdX + key.x + key.width && pos.py < kbdY + key.y + key.height)) { - screen_draw_texture(TEXTURE_KBD_PRESS_OVERLAY, kbdX + key.x, kbdY + key.y, key.width, key.height); - } - } -} - -ui_view* kbd_display(const char* name, const char* initialInput, void* data, void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), - void (*finished)(void* data, char* input), - void (*canceled)(void* data)) { - kbd_data* kbdData = (kbd_data*) calloc(1, sizeof(kbd_data)); - if(kbdData == NULL) { - error_display(NULL, NULL, "Failed to allocate info data."); - return NULL; - } - - memset(kbdData->input, '\0', MAX_INPUT_SIZE); - kbdData->inputPos = 0; - - if(initialInput != NULL) { - strncpy(kbdData->input, initialInput, MAX_INPUT_SIZE); - kbdData->inputPos = strlen(kbdData->input); - } - - kbdData->shift = false; - kbdData->capsLock = false; - - kbdData->scrollPos = 0; - kbdData->lastTouchY = 0; - - kbdData->keyboardTouched = false; - kbdData->nextRepeatTime = 0; - - kbdData->data = data; - kbdData->drawTop = drawTop; - kbdData->finished = finished; - kbdData->canceled = canceled; - - ui_view* view = ui_create(); - view->name = name; - view->info = ""; - view->data = kbdData; - view->update = kbd_update; - view->drawTop = kbd_draw_top; - view->drawBottom = kbd_draw_bottom; - ui_push(view); - - return view; -} \ No newline at end of file diff --git a/source/ui/kbd.h b/source/ui/kbd.h deleted file mode 100644 index 8e9c6fa..0000000 --- a/source/ui/kbd.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -typedef struct ui_view_s ui_view; - -ui_view* kbd_display(const char* name, const char* initialInput, void* data, void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), - void (*finished)(void* data, char* input), - void (*canceled)(void* data)); \ No newline at end of file diff --git a/source/ui/section/action/installcdn.c b/source/ui/section/action/installcdn.c index aed4f6c..7bd36f3 100644 --- a/source/ui/section/action/installcdn.c +++ b/source/ui/section/action/installcdn.c @@ -8,7 +8,6 @@ #include "../task/task.h" #include "../../error.h" #include "../../info.h" -#include "../../kbd.h" #include "../../list.h" #include "../../prompt.h" #include "../../ui.h" @@ -353,13 +352,16 @@ void action_install_cdn_noprompt(volatile bool* done, ticket_info* info, bool fi action_install_cdn_internal(done, info, finishedPrompt, NULL); } -static void action_install_cdn_kbd_finished(void* data, char* input) { - action_install_cdn_internal(NULL, (ticket_info*) data, true, input); -} - static void action_install_cdn_onresponse(ui_view* view, void* data, bool response) { if(response) { - kbd_display("Enter Version (leave empty for default)", NULL, data, NULL, action_install_cdn_kbd_finished, NULL); + SwkbdState swkbd; + swkbdInit(&swkbd, SWKBD_TYPE_NUMPAD, 1, -1); + swkbdSetHintText(&swkbd, "Enter version (empty for default)"); + + char textBuf[16]; + swkbdInputText(&swkbd, textBuf, sizeof(textBuf)); + + action_install_cdn_internal(NULL, (ticket_info*) data, true, textBuf); } } diff --git a/source/ui/section/action/newfolder.c b/source/ui/section/action/newfolder.c index 7a01118..aaadb13 100644 --- a/source/ui/section/action/newfolder.c +++ b/source/ui/section/action/newfolder.c @@ -8,7 +8,6 @@ #include "../task/task.h" #include "../../error.h" #include "../../info.h" -#include "../../kbd.h" #include "../../list.h" #include "../../prompt.h" #include "../../ui.h" @@ -16,61 +15,40 @@ #include "../../../core/screen.h" #include "../../../core/util.h" -typedef struct { - linked_list* items; - file_info* parentDir; -} new_folder_data; +void action_new_folder(linked_list* items, list_item* selected) { + SwkbdState swkbd; + swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, -1); + swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY, 0, 0); + swkbdSetHintText(&swkbd, "Enter folder name"); -static void action_new_folder_kbd_finished(void* data, char* input) { - new_folder_data* newFolderData = (new_folder_data*) data; + char textBuf[FILE_NAME_MAX]; + if(swkbdInputText(&swkbd, textBuf, sizeof(textBuf)) == SWKBD_BUTTON_CONFIRM) { + Result res = 0; - if(strlen(input) == 0) { - error_display(NULL, NULL, "No name specified."); - } + file_info* parentDir = (file_info*) selected->data; - Result res = 0; + char path[FILE_PATH_MAX] = {'\0'}; + snprintf(path, FILE_PATH_MAX, "%s%s", parentDir->path, textBuf); - char path[FILE_PATH_MAX] = {'\0'}; - snprintf(path, FILE_PATH_MAX, "%s%s", newFolderData->parentDir->path, input); + FS_Path* fsPath = util_make_path_utf8(path); + if(fsPath != NULL) { + res = FSUSER_CreateDirectory(parentDir->archive, *fsPath, 0); - FS_Path* fsPath = util_make_path_utf8(path); - if(fsPath != NULL) { - res = FSUSER_CreateDirectory(newFolderData->parentDir->archive, *fsPath, 0); - - util_free_path_utf8(fsPath); - } else { - res = R_FBI_OUT_OF_MEMORY; - } - - if(R_SUCCEEDED(res)) { - list_item* folderItem = NULL; - if(R_SUCCEEDED(task_create_file_item(&folderItem, newFolderData->parentDir->archive, path))) { - linked_list_add(newFolderData->items, folderItem); - linked_list_sort(newFolderData->items, util_compare_file_infos); + util_free_path_utf8(fsPath); + } else { + res = R_FBI_OUT_OF_MEMORY; } - prompt_display("Success", "Folder created.", COLOR_TEXT, false, NULL, NULL, NULL); - } else { - error_display_res(NULL, NULL, res, "Failed to create folder."); + if(R_SUCCEEDED(res)) { + list_item* folderItem = NULL; + if(R_SUCCEEDED(task_create_file_item(&folderItem, parentDir->archive, path))) { + linked_list_add(items, folderItem); + linked_list_sort(items, util_compare_file_infos); + } + + prompt_display("Success", "Folder created.", COLOR_TEXT, false, NULL, NULL, NULL); + } else { + error_display_res(NULL, NULL, res, "Failed to create folder."); + } } - - free(data); -} - -static void action_new_folder_kbd_canceled(void* data) { - free(data); -} - -void action_new_folder(linked_list* items, list_item* selected) { - new_folder_data* data = (new_folder_data*) calloc(1, sizeof(new_folder_data)); - if(data == NULL) { - error_display(NULL, NULL, "Failed to allocate new folder data."); - - return; - } - - data->items = items; - data->parentDir = (file_info*) selected->data; - - kbd_display("Enter Name", NULL, data, NULL, action_new_folder_kbd_finished, action_new_folder_kbd_canceled); } \ No newline at end of file diff --git a/source/ui/section/action/rename.c b/source/ui/section/action/rename.c index e2e23f1..cd62f1f 100644 --- a/source/ui/section/action/rename.c +++ b/source/ui/section/action/rename.c @@ -8,7 +8,6 @@ #include "../task/task.h" #include "../../error.h" #include "../../info.h" -#include "../../kbd.h" #include "../../list.h" #include "../../prompt.h" #include "../../ui.h" @@ -16,80 +15,58 @@ #include "../../../core/screen.h" #include "../../../core/util.h" -typedef struct { - linked_list* items; - list_item* target; -} rename_data; +void action_rename(linked_list* items, list_item* selected) { + file_info* targetInfo = (file_info*) selected->data; -static void action_rename_kbd_finished(void* data, char* input) { - rename_data* renameData = (rename_data*) data; + SwkbdState swkbd; + swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, -1); + swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY, 0, 0); + swkbdSetInitialText(&swkbd, targetInfo->name); + swkbdSetHintText(&swkbd, "Enter new name"); - if(strlen(input) == 0) { - error_display(NULL, NULL, "No name specified."); - } + char textBuf[FILE_NAME_MAX]; + if(swkbdInputText(&swkbd, textBuf, sizeof(textBuf)) == SWKBD_BUTTON_CONFIRM) { + Result res = 0; - file_info* targetInfo = (file_info*) renameData->target->data; + char parentPath[FILE_PATH_MAX] = {'\0'}; + util_get_parent_path(parentPath, targetInfo->path, FILE_PATH_MAX); - Result res = 0; + char dstPath[FILE_PATH_MAX] = {'\0'}; + snprintf(dstPath, FILE_PATH_MAX, "%s%s", parentPath, textBuf); - char parentPath[FILE_PATH_MAX] = {'\0'}; - util_get_parent_path(parentPath, targetInfo->path, FILE_PATH_MAX); + FS_Path* srcFsPath = util_make_path_utf8(targetInfo->path); + if(srcFsPath != NULL) { + FS_Path* dstFsPath = util_make_path_utf8(dstPath); + if(dstFsPath != NULL) { + if(targetInfo->isDirectory) { + res = FSUSER_RenameDirectory(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); + } else { + res = FSUSER_RenameFile(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); + } - char dstPath[FILE_PATH_MAX] = {'\0'}; - snprintf(dstPath, FILE_PATH_MAX, "%s%s", parentPath, input); - - FS_Path* srcFsPath = util_make_path_utf8(targetInfo->path); - if(srcFsPath != NULL) { - FS_Path* dstFsPath = util_make_path_utf8(dstPath); - if(dstFsPath != NULL) { - if(targetInfo->isDirectory) { - res = FSUSER_RenameDirectory(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); + util_free_path_utf8(dstFsPath); } else { - res = FSUSER_RenameFile(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); + res = R_FBI_OUT_OF_MEMORY; } - util_free_path_utf8(dstFsPath); + util_free_path_utf8(srcFsPath); } else { res = R_FBI_OUT_OF_MEMORY; } - util_free_path_utf8(srcFsPath); - } else { - res = R_FBI_OUT_OF_MEMORY; - } + if(R_SUCCEEDED(res)) { + if(strncmp(selected->name, "", LIST_ITEM_NAME_MAX) != 0 && strncmp(selected->name, "", LIST_ITEM_NAME_MAX) != 0) { + strncpy(selected->name, textBuf, LIST_ITEM_NAME_MAX); + } - if(R_SUCCEEDED(res)) { - if(strncmp(renameData->target->name, "", LIST_ITEM_NAME_MAX) != 0 && strncmp(renameData->target->name, "", LIST_ITEM_NAME_MAX) != 0) { - strncpy(renameData->target->name, input, LIST_ITEM_NAME_MAX); + strncpy(targetInfo->name, textBuf, FILE_NAME_MAX); + strncpy(targetInfo->path, dstPath, FILE_PATH_MAX); + + linked_list_sort(items, util_compare_file_infos); + + prompt_display("Success", "Renamed.", COLOR_TEXT, false, NULL, NULL, NULL); + } else { + error_display_res(NULL, NULL, res, "Failed to perform rename."); } - - strncpy(targetInfo->name, input, FILE_NAME_MAX); - strncpy(targetInfo->path, dstPath, FILE_PATH_MAX); - - linked_list_sort(renameData->items, util_compare_file_infos); - - prompt_display("Success", "Renamed.", COLOR_TEXT, false, NULL, NULL, NULL); - } else { - error_display_res(NULL, NULL, res, "Failed to perform rename."); } - - free(data); -} - -static void action_rename_kbd_canceled(void* data) { - free(data); -} - -void action_rename(linked_list* items, list_item* selected) { - rename_data* data = (rename_data*) calloc(1, sizeof(rename_data)); - if(data == NULL) { - error_display(NULL, NULL, "Failed to allocate rename data."); - - return; - } - - data->items = items; - data->target = selected; - - kbd_display("Enter New Name", ((file_info*) selected->data)->name, data, NULL, action_rename_kbd_finished, action_rename_kbd_canceled); } \ No newline at end of file diff --git a/source/ui/section/qrinstall.c b/source/ui/section/qrinstall.c index 1b301b2..5fa3229 100644 --- a/source/ui/section/qrinstall.c +++ b/source/ui/section/qrinstall.c @@ -9,7 +9,6 @@ #include "task/task.h" #include "../error.h" #include "../info.h" -#include "../kbd.h" #include "../prompt.h" #include "../ui.h" #include "../../core/screen.h" @@ -360,16 +359,14 @@ static void qrinstall_wait_draw_top(ui_view* view, void* data, float x1, float y } } -static void qrinstall_process_urls(void* data, char* input) { - qr_install_data* qrInstallData = (qr_install_data*) data; - - qrInstallData->installInfo.total = 0; +static void qrinstall_process_urls(qr_install_data* data, char* input) { + data->installInfo.total = 0; size_t payloadLen = strlen(input); if(payloadLen > 0) { char* currStart = input; - while(qrInstallData->installInfo.total < URLS_MAX && currStart - input < payloadLen) { + while(data->installInfo.total < URLS_MAX && currStart - input < payloadLen) { char* currEnd = strchr(currStart, '\n'); if(currEnd == NULL) { currEnd = input + payloadLen; @@ -382,30 +379,30 @@ static void qrinstall_process_urls(void* data, char* input) { len = URL_MAX - 7; } - strncpy(qrInstallData->urls[qrInstallData->installInfo.total], "http://", 7); - strncpy(&qrInstallData->urls[qrInstallData->installInfo.total][7], currStart, len); + strncpy(data->urls[data->installInfo.total], "http://", 7); + strncpy(&data->urls[data->installInfo.total][7], currStart, len); } else { if(len > URL_MAX) { len = URL_MAX; } - strncpy(qrInstallData->urls[qrInstallData->installInfo.total], currStart, len); + strncpy(data->urls[data->installInfo.total], currStart, len); } - qrInstallData->installInfo.total++; + data->installInfo.total++; currStart = currEnd + 1; } - if(qrInstallData->installInfo.total > 0) { - if(!qrInstallData->captureInfo.finished) { - svcSignalEvent(qrInstallData->captureInfo.cancelEvent); - while(!qrInstallData->captureInfo.finished) { + if(data->installInfo.total > 0) { + if(!data->captureInfo.finished) { + svcSignalEvent(data->captureInfo.cancelEvent); + while(!data->captureInfo.finished) { svcSleepThread(1000000); } } - qrInstallData->capturing = false; - memset(qrInstallData->captureInfo.buffer, 0, IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(u16)); + data->capturing = false; + memset(data->captureInfo.buffer, 0, IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(u16)); prompt_display("Confirmation", "Install from the provided URL(s)?", COLOR_TEXT, true, data, NULL, qrinstall_confirm_onresponse); } @@ -453,8 +450,17 @@ static void qrinstall_wait_update(ui_view* view, void* data, float* progress, ch } if(hidKeysDown() & KEY_X) { - kbd_display("Enter URL(s)", NULL, data, NULL, qrinstall_process_urls, NULL); - return; + SwkbdState swkbd; + swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, -1); + swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY, 0, 0); + swkbdSetFeatures(&swkbd, SWKBD_MULTILINE); + swkbdSetHintText(&swkbd, "Enter URL(s)"); + + char textBuf[1024]; + if(swkbdInputText(&swkbd, textBuf, sizeof(textBuf)) == SWKBD_BUTTON_CONFIRM) { + qrinstall_process_urls(qrInstallData, textBuf); + return; + } } if(qrInstallData->tex != 0) { @@ -490,7 +496,7 @@ static void qrinstall_wait_update(ui_view* view, void* data, float* progress, ch quirc_decode_error_t err = quirc_decode(&qrCode, &qrData); if(err == 0) { - qrinstall_process_urls(data, (char*) qrData.payload); + qrinstall_process_urls(qrInstallData, (char*) qrData.payload); return; } }