From 90c7bc237c9cf964c16f0cb48c308a92a8193a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 2 Sep 2022 02:11:49 +0200 Subject: Use global Window object. This makes it easier to control initialization and maintain RAII. --- c/data.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'c/data.cpp') diff --git a/c/data.cpp b/c/data.cpp index d9df68c..1274321 100644 --- a/c/data.cpp +++ b/c/data.cpp @@ -8,6 +8,7 @@ #include "resource.h" #include "data.h" #include "episodelistview.h" +#include "main.h" #include "util.h" #include "win.h" @@ -89,7 +90,7 @@ enum Signal : unsigned char void WaitFor(void (*f)(unsigned char*)) { - extern HWND g_hWnd; + extern Window* g_window; static unsigned char sig = READY; static UINT_PTR iTimer = 0; @@ -98,12 +99,11 @@ void WaitFor(void (*f)(unsigned char*)) static int i = 0; if (sig & DONE) { - extern EpisodeListView* g_elv; KillTimer(nullptr, iTimer); i = 0; sig = READY; /* Reset signals. */ - g_elv->Update(); /* Reset status bar. */ - EnableMenuItem(GetMenu(g_hWnd), IDM_FILE_FETCH_CANCEL, MF_GRAYED); + g_window->elv.Update(); /* Reset status bar. */ + EnableMenuItem(GetMenu(g_window->hWnd), IDM_FILE_FETCH_CANCEL, MF_GRAYED); } else { /* Animate ellipsis in status bar. */ static const wchar_t* text[] = {L".", L"..", L"...", L""}; @@ -118,7 +118,7 @@ void WaitFor(void (*f)(unsigned char*)) while (!(sig & READY)) Sleep(100); sig = 0; - EnableMenuItem(GetMenu(g_hWnd), IDM_FILE_FETCH_CANCEL, MF_ENABLED); + EnableMenuItem(GetMenu(g_window->hWnd), IDM_FILE_FETCH_CANCEL, MF_ENABLED); try { f(&sig); sig |= DONE; @@ -132,7 +132,7 @@ void WaitFor(void (*f)(unsigned char*)) /* Null indicates that any active task should be cancelled. */ if (!f) { sig |= ABORT; - EnableMenuItem(GetMenu(g_hWnd), IDM_FILE_FETCH_CANCEL, MF_GRAYED); + EnableMenuItem(GetMenu(g_window->hWnd), IDM_FILE_FETCH_CANCEL, MF_GRAYED); return; } @@ -180,8 +180,7 @@ void FetchData(unsigned char* sig) throw std::runtime_error("could not find remote episode information"); for (int i = 0; i < nodes->nodeNr; i++) { - extern FileView g_fvElv; - extern FileView g_fvDlv; + extern Window* g_window; if (*sig & ABORT) return; @@ -190,8 +189,8 @@ void FetchData(unsigned char* sig) if (xmlChildElementCount(node) != 8) throw std::runtime_error("unexpected remote data format"); - ElvDataA& e = g_fvElv.At(i); - DlvDataA& d = g_fvDlv.At(i); + ElvDataA& e = g_window->fvElv.At(i); + DlvDataA& d = g_window->fvDlv.At(i); /* Each datum is contained within a specific cell in * the row. The child element count above ensures that @@ -223,8 +222,7 @@ void FetchData(unsigned char* sig) void FetchScreenwriters(unsigned char* sig) { - extern FileView g_fvDlv; - extern CfgA& g_cfg; + extern Window* g_window; /* Screenwriters are expensive to fetch, so we try to avoid * fetching screenwriters for episodes that already have a @@ -233,12 +231,12 @@ void FetchScreenwriters(unsigned char* sig) * already tried to fetch screenwriters. We keep track of * these states using the iLast variable. */ static int iLast = -1; - int iMax = g_cfg.cEp-1; + int iMax = g_window->cfg.cEp-1; /* Find the last episode that has a screenwriter. */ if (iLast == -1) - for (size_t i = 0; i < g_fvDlv.c; i++) - if (const DlvDataA& d = g_fvDlv[i]; !d.date[0]) { + for (size_t i = 0; i < g_window->fvDlv.c; i++) + if (const DlvDataA& d = g_window->fvDlv[i]; !d.date[0]) { iMax = i-1; break; } else if (d.screenwriter[0]) @@ -262,7 +260,7 @@ void FetchScreenwriters(unsigned char* sig) Status(msg); /* Retrieve URL for episode's wiki page. */ - DlvDataA& d = g_fvDlv[iLast]; + DlvDataA& d = g_window->fvDlv[iLast]; Wcscpy(Buf(url)+Len(prefix), d.wiki); /* Retrieve screenwriter from HTML. */ -- cgit v1.2.3