aboutsummaryrefslogtreecommitdiff
path: root/c/data.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-09-02 02:11:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-09-02 02:14:11 +0200
commit90c7bc237c9cf964c16f0cb48c308a92a8193a5c (patch)
tree53f165056dffa061a9dfe39b76913edab87056f4 /c/data.cpp
parentbb9280267bfb78a8d69adea02f5ed7894833b19d (diff)
downloadEpisodeBrowser-90c7bc237c9cf964c16f0cb48c308a92a8193a5c.tar.gz
Use global Window object.
This makes it easier to control initialization and maintain RAII.
Diffstat (limited to 'c/data.cpp')
-rw-r--r--c/data.cpp30
1 files changed, 14 insertions, 16 deletions
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<ElvDataA> g_fvElv;
- extern FileView<DlvDataA> 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<DlvDataA> 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. */