From a11668762f199ac4778bde5e399bbefcd56ac239 Mon Sep 17 00:00:00 2001 From: Daniel C Date: Fri, 24 Jan 2025 21:22:16 -0500 Subject: [PATCH] Delete libui from desktop variant --- .github/workflows/unit.yml | 5 - desktop/Makefile | 4 +- desktop/backend.c | 2 - desktop/file_table.c | 79 -------- desktop/main.c | 59 +++++- desktop/ui.c | 380 ------------------------------------- desktop/unix.c | 27 ++- desktop/wifi.c | 0 desktop/win.c | 20 ++ 9 files changed, 105 insertions(+), 471 deletions(-) delete mode 100644 desktop/file_table.c delete mode 100644 desktop/ui.c delete mode 100644 desktop/wifi.c diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index ca5c0b7..acf264d 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -15,11 +15,6 @@ jobs: submodules: recursive - name: Install deps run: sudo apt install liblua5.3-dev libusb-1.0-0-dev - - name: Quick install libui-dev - run: | - sudo mkdir /usr/local/lib/x86_64-linux-gnu - sudo wget https://github.com/petabyt/libui-cross/releases/download/2/libui.so -O /usr/lib/libui.so - sudo wget https://raw.githubusercontent.com/libui-ng/libui-ng/master/ui.h -O /usr/local/include/ui.h - name: Checkout submodules run: git submodule update --init --recursive - name: Get latest vcam diff --git a/desktop/Makefile b/desktop/Makefile index 2db16ac..23bc3b1 100644 --- a/desktop/Makefile +++ b/desktop/Makefile @@ -4,8 +4,8 @@ include cross.mk FUDGE = ../lib CAMLIB_CORE := transport.o operations.o packet.o enums.o data.o enum_dump.o lib.o canon.o liveview.o bind.o ml.o conv.o generic.o canon_adv.o stuff.o -OBJ := main.o ui.o jank.o os.o backend.o -FUDGE_CORE := fuji.o tester.o data.o net.o discovery.o exif.o uilua.o fuji_usb.o object.o fuji_lua.o lua_runtime.o +OBJ := main.o jank.o backend.o +FUDGE_CORE := fuji.o tester.o data.o net.o discovery.o exif.o fuji_usb.o object.o fuji_lua.o lua_runtime.o ifeq ($(TARGET),l) CAMLIB_CORE += libusb.o diff --git a/desktop/backend.c b/desktop/backend.c index 255d313..3de24d1 100644 --- a/desktop/backend.c +++ b/desktop/backend.c @@ -23,9 +23,7 @@ struct PtpRuntime *luaptp_get_runtime(lua_State *L) { return ptp_get(); } -int luaopen_libuilua(lua_State *L); int cam_lua_setup(lua_State *L) { - luaL_requiref(L, "ui", luaopen_libuilua, 1); return 0; } diff --git a/desktop/file_table.c b/desktop/file_table.c deleted file mode 100644 index 6079fd6..0000000 --- a/desktop/file_table.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include - -struct MyTableModelHandler { - uiTableModelHandler mh; - struct PtpRuntime *r; - struct PtpObjectCache *oc; -}; - -static inline struct MyTableModelHandler *my_handler(uiTableModelHandler *mh) { - return (struct MyTableModelHandler *)mh; -} - -static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m) { - return 3; -} - -static uiTableValueType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column) -{ - switch (column) { - case 0: - return uiTableValueTypeString; - case 1: - return uiTableValueTypeString; - default: - return uiTableValueTypeString; - } -} - -static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m) { - return ptp_object_service_length( - my_handler(mh)->r, - my_handler(mh)->oc - ); -} - -static uiTableValue *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column) -{ - struct MyTableModelHandler *h = my_handler(mh); - - if (column == 0) { - struct PtpObjectInfo *oi = ptp_object_service_get_index(h->r, h->oc, row); - return uiNewTableValueString(oi->filename); - } - - return uiNewTableValueString("TODO"); -} - -static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column, const uiTableValue *val) { - // This list is not editable -} - -uiControl *create_files_tab(struct PtpRuntime *r, struct PtpObjectCache *oc) { - struct MyTableModelHandler *mh = (struct MyTableModelHandler *)malloc(sizeof(struct MyTableModelHandler)); - mh->mh.NumColumns = modelNumColumns; - mh->mh.ColumnType = modelColumnType; - mh->mh.NumRows = modelNumRows; - mh->mh.CellValue = modelCellValue; - mh->mh.SetCellValue = modelSetCellValue; - mh->r = r; - mh->oc = oc; - - uiTableModel *m = uiNewTableModel((uiTableModelHandler *)mh); - - uiTableParams p = { - .Model = m, - .RowBackgroundColorModelColumn = 3, - }; - - uiTable *t = uiNewTable(&p); - - uiTableAppendTextColumn(t, "Filename", 0, uiTableModelColumnNeverEditable, NULL); - uiTableAppendTextColumn(t, "Last Modified", 1, uiTableModelColumnNeverEditable, NULL); - - return uiControl(t); -} diff --git a/desktop/main.c b/desktop/main.c index c9669b4..476763b 100644 --- a/desktop/main.c +++ b/desktop/main.c @@ -71,6 +71,63 @@ int fuji_discovery_check_cancel(void *arg) { return 0; } +void app_send_cam_name(const char *name) { + +} + +void fuji_discovery_update_progress(void *arg, enum DiscoverUpdateMessages progress) { +} + +void app_downloading_file(const struct PtpObjectInfo *oi) { + // ... +} + +void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) { + // ... +} + +void app_increment_progress_bar(int read) { + // ... +} + +void app_report_download_speed(long time, size_t size) { + // ... +} + +void app_log_clear(void) { + // ... +} + +void app_print(char *fmt, ...) { + char buffer[512]; + va_list args; + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); +} + +void tester_log(char *fmt, ...) { + char buffer[512]; + va_list args; + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); + printf("LOG: %s\n", buffer); +} + +void tester_fail(char *fmt, ...) { + char buffer[512]; + va_list args; + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); + printf("FAIL: %s\n", buffer); +} + +void app_update_connected_status(int connected) { + +} + static int help(void) { printf("Fudge 0.1.0\n"); printf("Compilation date: " __DATE__ "\n"); @@ -116,5 +173,5 @@ int main(int argc, char **argv) { } } - return fudge_main_ui(); + return 0; } diff --git a/desktop/ui.c b/desktop/ui.c deleted file mode 100644 index fca94e1..0000000 --- a/desktop/ui.c +++ /dev/null @@ -1,380 +0,0 @@ -// 2024 Fudge desktop frontend -#include -#include -#include -#include -#include -#include -#include -#include "safety.h" -#include -#include -#include "desktop.h" - -void uiToast(const char *format, ...) {} - -struct App { - int is_opened; - uiWindow *main_win; - uiMultilineEntry *main_log; - uiMultilineEntry *script_box; - uiMultilineEntry *connect_entry; - uiLabel *bottom_status; - uiTab *right_tab; -}app = {0}; - -void app_send_cam_name(const char *name) { - if (!app.is_opened) { - return; - } - - if (name) { - char buffer[64]; - sprintf(buffer, "Fudge - Connected to %s", name); - uiWindowSetTitle(app.main_win, buffer); - sprintf(buffer, "Connected to %s", name); - uiLabelSetText(app.bottom_status, buffer); - } else { - uiWindowSetTitle(app.main_win, "Fudge"); - uiLabelSetText(app.bottom_status, "Not connected to any camera"); - } -} - -void fuji_discovery_update_progress(void *arg, int progress) { - if (!app.is_opened) return; -} - -void app_downloading_file(const struct PtpObjectInfo *oi) { - if (!app.is_opened) return; - // ... -} - -void app_downloaded_file(const struct PtpObjectInfo *oi, const char *path) { - if (!app.is_opened) return; - // ... -} - -void app_increment_progress_bar(int read) { - if (!app.is_opened) return; - // ... -} - -void app_report_download_speed(long time, size_t size) { - if (!app.is_opened) return; - // ... -} - -void tester_log(char *fmt, ...) { - char buffer[512]; - va_list args; - va_start(args, fmt); - vsnprintf(buffer, sizeof(buffer), fmt, args); - va_end(args); - printf("LOG: %s\n", buffer); -} - -void tester_fail(char *fmt, ...) { - char buffer[512]; - va_list args; - va_start(args, fmt); - vsnprintf(buffer, sizeof(buffer), fmt, args); - va_end(args); - printf("FAIL: %s\n", buffer); -} - -static void clear_thread(void *arg) { - uiMultilineEntrySetText(app.main_log, ""); -} - -static void print_thread(void *buffer) { - uiMultilineEntryAppend(app.main_log, (const char *)buffer); - free(buffer); - uiMultilineEntryAppend(app.main_log, "\n"); -} - -void app_print(char *fmt, ...) { - char buffer[512]; - va_list args; - va_start(args, fmt); - vsnprintf(buffer, sizeof(buffer), fmt, args); - va_end(args); - if (app.is_opened) { - uiQueueMain(print_thread, (void *)strdup(buffer)); - } else { - puts(buffer); - } -} - -void app_log_clear(void) { - uiQueueMain(clear_thread, NULL); -} - -static char *read_file(const char *filename) { - FILE* file = fopen(filename, "rb"); - if (!file) return NULL; - - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - char* buffer = (char*)malloc(file_size + 1); - if (!buffer) return NULL; - - fread(buffer, 1, file_size, file); - buffer[file_size] = '\0'; - - fclose(file); - return buffer; -} - -static int onClosing(uiWindow *w, void *data) { - fudge_disconnect_all(); - uiQuit(); - return 1; -} - -static int onShouldQuit(void *data) -{ - uiWindow *mainwin = uiWindow(data); - uiControlDestroy(uiControl(mainwin)); - return 1; -} - -static uiControl *files_tab(void) { - return uiControl(uiNewLabel("TODO...")); -} - -static uiControl *general_tab(void) { - uiBox *box = uiNewVerticalBox(); - uiBoxAppend(box, uiControl(uiNewLabel("Hello")), 0); - - { - uiGroup *g = uiNewGroup("Camera Settings"); - uiButton *btn = uiNewButton("Backup settings"); - uiGroupSetChild(g, uiControl(btn)); - uiBoxAppend(box, uiControl(g), 0); - } - - return uiControl(box); -} - -static void usb_connect(uiButton *btn, void *data) { - pthread_t thread; - pthread_create(&thread, 0, fudge_usb_connect_thread, NULL); -} - -static void usb_connect_menu(uiMenuItem *i, uiWindow *w, void *data) { - pthread_t thread; - pthread_create(&thread, 0, fudge_usb_connect_thread, NULL); -} - -static void script_run(uiMenuItem *sender, uiWindow *window, void *senderData) { - char *file = uiMultilineEntryText(app.script_box); - if (cam_run_lua_script_async(file) < 0) { - uiToast(cam_lua_get_error()); - } - - uiFreeText(file); -} - -void app_update_connected_status_(void *arg) { - uiTab *tab = app.right_tab; - if ((uintptr_t)arg) { - uiTabInsertAt(tab, "General", 0, general_tab()); - uiTabSetSelected(tab, 0); - } else { - uiTabSetSelected(tab, 1); - uiTabDelete(tab, 0); - app_send_cam_name(NULL); - } -} -void app_update_connected_status(int connected) { - uiQueueMain(app_update_connected_status_, (void *)(uintptr_t)connected); -} - -uiControl *editor_tab(void) { - char *file = read_file("../android/app/src/main/assets/script.lua"); - if (file == NULL) file = "null"; - app.script_box = uiNewNonWrappingMultilineEntry(); - uiMultilineEntrySetText(app.script_box, file); - return uiControl(app.script_box); -} - -uiControl *connect_tab(void) { - uiMultilineEntry *entry = uiNewMultilineEntry(); - uiMultilineEntrySetReadOnly(entry, 1); - - app.connect_entry = entry; - - return (uiControl *)entry; -} - -uiControl *create_discovery_ui(void) { - uiGroup *discovery = uiNewGroup("Searching for a camera..."); - uiBox *inner = uiNewVerticalBox(); - - uiBoxAppend(inner, uiControl(uiNewLabel("- PC AutoSave")), 0); - uiBoxAppend(inner, uiControl(uiNewLabel("- Wireless Tether")), 0); - - uiProgressBar *bar = uiNewProgressBar(); - uiProgressBarSetValue(bar, -1); - uiBoxAppend(inner, uiControl(bar), 0); - - uiGroupSetChild(discovery, uiControl(inner)); - return uiControl(discovery); -} - -uiControl *about_tab(void) { - uiBox *box = uiNewVerticalBox(); - uiBoxSetPadded(box, 1); - -#if 0 - { - uiGroup *g = uiNewGroup("Fudge"); - uiMultilineEntry *text = uiNewMultilineEntry(); - uiMultilineEntrySetReadOnly(text, 1); - uiMultilineEntrySetText(text, - "Connect to a camera to get started.\n" - "For questions, feature requests, or bug reports, shoot me an email or file an issue on the Github page.\n" - "- brikbusters@gmail.com\n" - "- https://github.com/petabyt/fudge\n" - ); - uiGroupSetChild(g, uiControl(text)); - uiBoxAppend(box, uiControl(g), 1); - } - - { - uiGroup *g = uiNewGroup("Credits"); - uiMultilineEntry *text = uiNewMultilineEntry(); - uiMultilineEntrySetReadOnly(text, 1); - uiMultilineEntrySetText(text, - "Created by Daniel Cook (danielc.dev)\n" - "Libraries:\n" - "- https://github.com/libui-ng/libui-ng (MIT License)\n" - "- https://github.com/petabyt/libwpd\n" - "- https://github.com/petabyt/camlib\n" - "- Lua 5.3 (MIT License)\n" - ); - uiGroupSetChild(g, uiControl(text)); - uiBoxAppend(box, uiControl(g), 1); - } -#endif - - return uiControl(box); -} - -static uiControl *fudge_screen(void) { - uiBox *box = uiNewHorizontalBox(); - uiBoxSetPadded(box, 1); - - uiBox *left = uiNewVerticalBox(); - uiBoxSetPadded(left, 1); - - //uiGroup *connectivity = uiNewGroup("Connect"); - { - uiBox *hbox = uiNewVerticalBox(); - uiBoxSetPadded(hbox, 1); - uiBoxAppend(hbox, uiControl(uiNewLabel("Connect to a camera to get started.")), 1); - uiButton *btn = uiNewButton("Connect to Camera"); - uiControlSetTooltip(uiControl(btn), "Find a camera over USB or WiFi and connect"); - uiButtonOnClicked(btn, usb_connect, NULL); - uiBoxAppend(hbox, uiControl(btn), 1); -// uiBoxAppend(hbox, uiControl(uiNewButton("WiFi")), 1); - uiBoxAppend(hbox, uiControl(uiNewButton("Search for camera")), 1); - //uiGroupSetChild(connectivity, uiControl(hbox)); - uiBoxAppend(left, uiControl(hbox), 0); - } - //uiBoxAppend(left, uiControl(connectivity), 0); - - app.main_log = uiNewMultilineEntry(); - uiMultilineEntrySetReadOnly(app.main_log, 1); - uiBoxAppend(left, uiControl(app.main_log), 1); - - uiBoxAppend(box, uiControl(left), 1); - - { - uiBox *vbox = uiNewVerticalBox(); - uiTab *tab = uiNewTab(); - app.right_tab = tab; - //uiTabAppend(tab, "Files", files_tab()); - //uiTabAppend(tab, "Lua Editor", editor_tab()); - //uiTabAppend(tab, "Recipes", files_tab()); - uiTabAppend(tab, "About", about_tab()); - uiBoxAppend(vbox, uiControl(tab), 1); - uiLabel *lbl = uiNewLabel("Not connected to any camera"); - app.bottom_status = lbl; - uiBoxAppend(vbox, uiControl(lbl), 0); - uiBoxAppend(box, uiControl(vbox), 1); - } - - return (uiControl *)box; -} - -int multiple_cameras_menu(void) { - - uiWindow *w = uiNewWindow("Dialog", 500, 100, 0); - uiWindowSetMargined(w, 1); - - uiBox *screen = uiNewVerticalBox(); - - uiBoxAppend(screen, uiControl(uiNewLabel("Choose a camera to connect to")), 1); - - uiButton *btn = uiNewButton("Fujfilm X-T4"); - uiBoxAppend(screen, uiControl(btn), 1); - - btn = uiNewButton("Fujifilm X-A2"); - uiBoxAppend(screen, uiControl(btn), 1); - - btn = uiNewButton("Cancel"); - uiBoxAppend(screen, uiControl(btn), 1); - - uiWindowSetChild(w, uiControl(screen)); - uiControlShow(uiControl(w)); - - return 0; -} - -int fudge_main_ui(void) { - app.is_opened = 1; - uiInitOptions options; - const char *err; - uiTab *tab; - - memset(&options, 0, sizeof (uiInitOptions)); - err = uiInit(&options); - if (err != NULL) { - fprintf(stderr, "error initializing libui: %s", err); - uiFreeInitError(err); - return 1; - } - - { - uiMenuItem *item; - uiMenu *menu = uiNewMenu("Script"); - item = uiMenuAppendItem(menu, "Run"); - uiMenuItemOnClicked(item, script_run, NULL); - item = uiMenuAppendItem(menu, "Open"); - item = uiMenuAppendItem(menu, "Save"); - item = uiMenuAppendPreferencesItem(menu); - item = uiMenuAppendQuitItem(menu); - menu = uiNewMenu("About"); - - menu = uiNewMenu("Connect"); - item = uiMenuAppendItem(menu, "USB"); - uiMenuItemOnClicked(item, usb_connect_menu, NULL); - item = uiMenuAppendItem(menu, "WiFi"); - } - - app.main_win = uiNewWindow("Fudge", 1000, 500, 1); - uiWindowOnClosing(app.main_win, onClosing, NULL); - uiOnShouldQuit(onShouldQuit, app.main_win); - uiWindowSetMargined(app.main_win, 1); - - uiWindowSetChild(app.main_win, fudge_screen()); - uiControlShow(uiControl(app.main_win)); - - app_print("Fudge desktop pre-release"); - - uiMain(); - return 0; -} diff --git a/desktop/unix.c b/desktop/unix.c index 15dbf7b..61c9c7f 100644 --- a/desktop/unix.c +++ b/desktop/unix.c @@ -1,5 +1,28 @@ -#include "desktop.h" +#include +#include +#include + +void app_get_file_path(char buffer[256], const char *filename) { + snprintf(buffer, 256, "%s", filename); +} + +void app_get_tether_file_path(char buffer[256]) { + snprintf(buffer, 256, "TETHER.JPG"); +} + +int app_get_os_network_handle(struct NetworkHandle *h) { + return 0; +} + +int app_get_wifi_network_handle(struct NetworkHandle *h) { + return -1; +} + +int app_bind_socket_to_network(int fd, struct NetworkHandle *h) { + return 0; +} + void network_init(void) { - // Check WiFi on Linux + // Linux doesn't need anything to init network } diff --git a/desktop/wifi.c b/desktop/wifi.c deleted file mode 100644 index e69de29..0000000 diff --git a/desktop/win.c b/desktop/win.c index 4d83dcb..df2625c 100644 --- a/desktop/win.c +++ b/desktop/win.c @@ -11,6 +11,26 @@ // Windows does not have kill! void kill(int pid) {} +void app_get_file_path(char buffer[256], const char *filename) { + snprintf(buffer, 256, "%s", filename); +} + +void app_get_tether_file_path(char buffer[256]) { + snprintf(buffer, 256, "TETHER.JPG"); +} + +int app_get_os_network_handle(struct NetworkHandle *h) { + return 0; +} + +int app_get_wifi_network_handle(struct NetworkHandle *h) { + return -1; +} + +int app_bind_socket_to_network(int fd, struct NetworkHandle *h) { + return 0; +} + void network_init() { // Windows wants to init every thread for socket stuff WSADATA wsaData = {0};