From ccb7d14a8b1ad6d80308c14a3f0b209d66c3c88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 24 Aug 2022 03:01:10 +0200 Subject: Add FetchScreenwriters. Improve thread communication. --- c/main.cpp | 55 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) (limited to 'c/main.cpp') diff --git a/c/main.cpp b/c/main.cpp index 771b323..8916860 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -77,8 +76,6 @@ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK HandleMsg(HWND, UINT, WPARAM, LPARAM); /* Process main menu commands. */ static void HandleMainMenu(HWND, WORD); -/* Wait for thread. */ -void WaitFor(void (*f)(bool*)); /* Handle messages to Help > About dialog. */ static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); /* Try to style application according to current Windows theme. */ @@ -353,7 +350,7 @@ LRESULT CALLBACK HandleMsg(const HWND hWnd, const UINT uMsg, const WPARAM wParam const wchar_t** const vTip = group == IDG_MENU? vTipMenu: vTipCtx; tip = vTip[ID_INDEX(command)]; } - SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), reinterpret_cast(tip)); + Status(tip, 0); return 0; } @@ -390,12 +387,12 @@ void HandleMainMenu(const HWND hWnd, const WORD command) case IDM_FILE_FETCH_DATA: { - WaitFor(WaitFetchData); + WaitFor(FetchData); break; } case IDM_FILE_FETCH_SCREENWRITERS: - //WaitFor("episode_data","update_screenwriters"); + WaitFor(FetchScreenwriters); break; case IDM_FILE_ABOUT: @@ -442,52 +439,6 @@ void HandleMainMenu(const HWND hWnd, const WORD command) } } -void WaitFor(void (*f)(bool*)) -{ - static bool bActive = false; - static bool bDone = false; - static UINT_PTR iTimer; - - /* Ensure that only a single thread is waited on. */ - if (bActive) { - if (EBMessageBox(L"Another task is active. " - L"Do you want to cancel the existing task and start a new one?", - L"Error", MB_YESNO|MB_ICONWARNING) == IDYES) { - KillTimer(nullptr, iTimer); - bActive = false; - g_elv->Update(); - } else - return; - } - - /* The timer procedure animates an ellipsis in the status bar - * while the thread is running. */ - static auto proc = [](HWND, UINT, UINT_PTR, DWORD) -> void - { - static int i = 0; - static const wchar_t* text[] = {L".", L"..", L"...", L""}; - - if (bDone) { - KillTimer(nullptr, iTimer); - i = 0; - bActive = 0; - g_elv->Update(); - } else { - i = (i+1)%(sizeof(text)/sizeof(*text)); - SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), - reinterpret_cast(text[i])); - } - }; - - /* The waited-on function signals its completion by setting a - * shared boolean value to true. */ - bDone = false; - bActive = true; - std::thread(f, &bDone).detach(); - SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), reinterpret_cast(L".")); - Prefer(iTimer = SetTimer(nullptr, -1, 500, proc)); -} - INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM) { switch (uMsg) { -- cgit v1.2.3