From ed40cc0ac6768004aeaa075b5205729ed6980c21 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Fri, 22 May 2026 15:05:57 +0900 Subject: [PATCH] WIP --- src/gd_v_express.erl | 96 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/src/gd_v_express.erl b/src/gd_v_express.erl index 2efd23e..7ec4799 100644 --- a/src/gd_v_express.erl +++ b/src/gd_v_express.erl @@ -72,6 +72,7 @@ sign = none :: none | wx:wx_object(), size = none :: none | wx:wx_object(), cost = none :: none | wx:wx_object(), + quote = none :: none | pos_integer(), ul = none :: none | wx:wx_object()}). %-record(mochila, @@ -200,7 +201,7 @@ init({Prefs, {Selected, Keys}}) -> CostT = wxStaticText:new(CostBox, ?wxID_ANY, "[N/A]"), _ = wxStaticBoxSizer:add(CostSz, CostT, zxw:flags({wide,5})), _ = wxStaticBoxSizer:add(UploadSz, CostSz, zxw:flags({wide,5})), - UploadB = #w{wx = UploadW} = make_button(UploadBox, ul, J("Upload")), + UploadB = #w{wx = UploadW} = make_button(UploadBox, ul, J("Check Quote")), _ = wxButton:disable(UploadW), _ = wxStaticBoxSizer:add(UploadSz, UploadW, zxw:flags({base,5})), @@ -227,6 +228,7 @@ init({Prefs, {Selected, Keys}}) -> end, ok = gd_v:safe_size(Frame, NewPrefs), + ok = wxTextCtrl:connect(DestT, command_text_updated), ok = wxPanel:dragAcceptFiles(Panel, true), ok = wxPanel:connect(Panel, drop_files), ok = wxFrame:connect(Frame, command_button_clicked), @@ -299,6 +301,9 @@ handle_event(#wx{event = #wxCommand{type = command_choice_selected}}, State) -> handle_event(#wx{event = #wxCommand{type = command_listbox_doubleclicked}}, State) -> NewState = do_dl(State), {noreply, NewState}; +handle_event(#wx{event = #wxCommand{type = command_text_updated}}, State) -> + NewState = do_check_ul_button(State), + {noreply, NewState}; handle_event(#wx{event = #wxDropFiles{files = Files}}, State) -> NewState = do_drop(Files, State), {noreply, NewState}; @@ -437,19 +442,106 @@ do_dl(State) -> State. -do_drop([Path], State) -> +do_check_ul_button(State = #s{ul = #w{wx = UL_B}}) -> + _ = wxButton:enable(UL_B, [{enable, should_enable_quote(State)}]), + State. + + +do_drop([Path], State = #s{path = PathP, ul = #w{wx = UL_B}}) -> ok = tell(info, "Path: ~ts", [Path]), + ok = + case filelib:is_file(Path) of + true -> + ok = wxFilePickerCtrl:setPath(PathP, Path), + _ = wxButton:enable(UL_B, [{enable, should_enable_quote(State)}]), + ok; + false -> + tell(warning, "Thank you, Mario! But our file is in a different path.") + end, State; do_drop(Paths, State) -> ok = tell(info, "Paths: ~tp", [Paths]), + ok = tell(info, "THIS IS A NO NO"), State. +should_enable_quote(#s{dest = DestT, path = PathP}) -> + DestKey = wxTextCtrl:getValue(DestT), + Path = wxFilePickerCtrl:getPath(PathP), + length(DestKey) > 0 andalso length(Path) > 0. + +do_ul(State = #s{quote = none, rider = none}) -> + check_quote(State); do_ul(State) -> ok = tell(info, "Would do_ul."), State. +check_quote(State = #s{dest = DestT}) -> + Dest = wxTextCtrl:getValue(DestT), + case gmser_api_encoder:safe_decode(account_pubkey, list_to_binary(Dest)) of + {ok, PubKey} -> + check_quote2(State, PubKey); + {error, Reason} -> + tell(warning, "Destination Key decode failed with: ~p", [Reason]), + State + end. + +check_quote2(State = #s{path = PathP}, PubKey) -> + Path = wxFilePickerCtrl:getPath(PathP), + case filelib:is_file(Path) of + true -> + check_quote3(State, PubKey, Path); + false -> + tell(info, "File path isn't a file"), + State + end. + +check_quote3(State = #s{ttl = TTL_T}, PubKey, Path) -> + TTL_S = wxTextCtrl:getValue(TTL_T), + case string_to_int(TTL_S) of + {ok, TTL} -> + check_quote4(State, PubKey, Path, TTL); + error -> + tell(info, "TTL isn't an integer"), + State + end. + +check_quote4(State = #s{sign = SigC}, PubKey, Path, TTL) -> + SigYN = wxCheckBox:is_checked(SigC), + check_quote5(State, PubKey, Path, TTL, SigYN). + +check_quote5(State, PubKey, Path, TTL, SigYN) -> + Tar = tar_path(), + case erl_tar:create(TarPath, Path, [compressed, dereference]) of + ok -> + check_quote6(State, PubKey, TTL, SigYN, Tar); + {error, Reason} -> + tell(warning, "Tar operation failed with: ~p", [Reason]), + State + end. + +check_quote6(State, PubKey, TTL, SigYN, Tar) -> + + +tar_path() -> + TarFile = integer_to_list(erlang:system_time(seconds)) ++ "tar.gz", + filename:join(zx_lib:path(tmp, "otpr", "gajudesk"), TarFile). + +check_quote6(State, PubKey, Path, TTL, SigYN, Tar) -> + +% PID = spawn_link(gd_n_rider, init, [PubKey, {"localhost", 7777}]), + + + +string_to_int(S) -> + try + {ok, list_to_integer(S)} + catch + error:bad_arg -> error + end. + + do_close(#s{frame = Frame, prefs = Prefs}) -> Geometry = case wxTopLevelWindow:isMaximized(Frame) of