Refactoring
This commit is contained in:
@@ -42,6 +42,15 @@ static std::set<std::string> GetAvailableDrives()
|
||||
return std::move(avail);
|
||||
}
|
||||
|
||||
static bool IsRefreshKeyMessage(const MSG *message)
|
||||
{
|
||||
return message
|
||||
&& ((message->message == WM_KEYDOWN) || (message->message == WM_KEYUP))
|
||||
&& (message->wParam == VK_F5);
|
||||
}
|
||||
|
||||
|
||||
#pragma region CAboutDialog
|
||||
// CAboutDlg dialog used for App About
|
||||
|
||||
class CAboutDlg : public CDialogEx
|
||||
@@ -73,10 +82,11 @@ void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
|
||||
END_MESSAGE_MAP()
|
||||
#pragma endregion
|
||||
|
||||
|
||||
// CSiaDriveDlg dialog
|
||||
|
||||
#pragma region CSiaDriveDialog Event Map
|
||||
BEGIN_DHTML_EVENT_MAP(CSiaDriveDlg)
|
||||
DHTML_EVENT_ONCLICK(_T("ID_Renter_Edit"), OnButtonRenterEdit)
|
||||
DHTML_EVENT_ONCLICK(_T("ButtonOK"), OnButtonOK)
|
||||
@@ -86,7 +96,7 @@ BEGIN_DHTML_EVENT_MAP(CSiaDriveDlg)
|
||||
DHTML_EVENT_ONCLICK(_T("UnlockWalletButton"), OnButtonUnlockWallet)
|
||||
DHTML_EVENT_ONCLICK(_T("ID_MountButton"), OnButtonMount)
|
||||
END_DHTML_EVENT_MAP()
|
||||
|
||||
#pragma endregion
|
||||
|
||||
CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDHtmlDialog(IDD_SIADRIVE_DIALOG, IDR_HTML_SIADRIVE_DIALOG, pParent),
|
||||
@@ -102,14 +112,13 @@ void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletCreatedSeed"), _walletCreatedSeed);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||
ON_WM_SYSCOMMAND()
|
||||
ON_WM_TIMER()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CSiaDriveDlg message handlers
|
||||
|
||||
BOOL CSiaDriveDlg::OnInitDialog()
|
||||
{
|
||||
CDHtmlDialog::OnInitDialog();
|
||||
@@ -155,10 +164,6 @@ void CSiaDriveDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
}
|
||||
}
|
||||
|
||||
// If you add a minimize button to your dialog, you will need the code below
|
||||
// to draw the icon. For MFC applications using the document/view model,
|
||||
// this is automatically done for you by the framework.
|
||||
|
||||
void CSiaDriveDlg::OnPaint()
|
||||
{
|
||||
if (IsIconic())
|
||||
@@ -184,6 +189,131 @@ void CSiaDriveDlg::OnPaint()
|
||||
}
|
||||
}
|
||||
|
||||
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
||||
{
|
||||
return static_cast<HCURSOR>(m_hIcon);
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonOK(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnOK();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnCancel();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
_seedCreation = false;
|
||||
_walletCreatedSeed = L"";
|
||||
|
||||
ReloadDisplay();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
SetBodyEnabled(false);
|
||||
String pwd = GetWalletUnlockPassword();
|
||||
std::thread th([this, pwd]() {
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Unlock(pwd)))
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
SetBodyEnabled(true);
|
||||
ReloadDisplay();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
AfxMessageBox(L"Invalid password entered");
|
||||
SetBodyEnabled(true);
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
});
|
||||
}
|
||||
});
|
||||
th.detach();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonMount(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonRenterEdit(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
DisplayPopUp(L"ID_Edit_Renter_Popup");
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
KillTimer(IDT_UI_ACTION_QUEUE);
|
||||
|
||||
// Create new API to clear all cached data used by threaded implementations
|
||||
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.0" }));
|
||||
|
||||
ClearDisplay();
|
||||
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
|
||||
|
||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
||||
|
||||
if ((_connected = UpdateUi(false)))
|
||||
{
|
||||
ConfigureWallet();
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
{
|
||||
switch (nIDEvent)
|
||||
{
|
||||
case IDT_UPDATE:
|
||||
{
|
||||
UpdateUi();
|
||||
}
|
||||
break;
|
||||
|
||||
case IDT_UI_ACTION_QUEUE:
|
||||
{
|
||||
ProcessUiActionQueue();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCreateWallet(IHTMLElement* pElement)
|
||||
{
|
||||
if (!_seedCreation)
|
||||
{
|
||||
_seedCreation = true;
|
||||
KillTimer(IDT_UPDATE);
|
||||
|
||||
String seed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
||||
{
|
||||
DisplaySeedCreated(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
void CSiaDriveDlg::SetBodyEnabled(const bool& enabled)
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> disabledNode;
|
||||
@@ -287,84 +417,12 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRe
|
||||
|
||||
// The system calls this function to obtain the cursor to display while the user drags
|
||||
// the minimized window.
|
||||
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
||||
{
|
||||
return static_cast<HCURSOR>(m_hIcon);
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonOK(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnOK();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnCancel();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
_seedCreation = false;
|
||||
_walletCreatedSeed = L"";
|
||||
|
||||
ReloadDisplay();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
SetBodyEnabled(false);
|
||||
String pwd = GetWalletUnlockPassword();
|
||||
std::thread th([this, pwd]() {
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Unlock(pwd)))
|
||||
{
|
||||
ExecuteUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
SetBodyEnabled(true);
|
||||
ReloadDisplay();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecuteUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
AfxMessageBox(L"Invalid password entered");
|
||||
SetBodyEnabled(true);
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
});
|
||||
}
|
||||
});
|
||||
th.detach();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonMount(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonRenterEdit(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
DisplayPopUp(L"ID_Edit_Renter_Popup");
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayPopUp(const String& name)
|
||||
{
|
||||
CallClientScript(L"displayPopUp", name, nullptr);
|
||||
}
|
||||
|
||||
bool IsRefreshKeyMessage(const MSG *message)
|
||||
{
|
||||
return message
|
||||
&& ((message->message == WM_KEYDOWN) || (message->message == WM_KEYUP))
|
||||
&& (message->wParam == VK_F5);
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
//TODO: Implement copy/paste context menu
|
||||
@@ -478,49 +536,7 @@ void CSiaDriveDlg::ClearDisplay()
|
||||
SetConsensusHeight(0);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
KillTimer(IDT_UI_ACTION_QUEUE);
|
||||
|
||||
// Create new API to clear all cached data used by threaded implementations
|
||||
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.0" }));
|
||||
|
||||
ClearDisplay();
|
||||
|
||||
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
|
||||
|
||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
||||
|
||||
if ((_connected = UpdateUi(false)))
|
||||
{
|
||||
ConfigureWallet();
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
{
|
||||
switch (nIDEvent)
|
||||
{
|
||||
case IDT_UPDATE:
|
||||
{
|
||||
UpdateUi();
|
||||
}
|
||||
break;
|
||||
|
||||
case IDT_UI_ACTION_QUEUE:
|
||||
{
|
||||
ProcessUiActionQueue();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ExecuteUiAction(std::function<void()> fn)
|
||||
void CSiaDriveDlg::QueueUiAction(std::function<void()> fn)
|
||||
{
|
||||
if (GetCurrentThreadId() == _uiThreadId)
|
||||
{
|
||||
@@ -742,23 +758,26 @@ void CSiaDriveDlg::SetChildWindow(const String& parentName, const String& name)
|
||||
}
|
||||
}
|
||||
|
||||
CComPtr<IHTMLDOMNode> divNode;
|
||||
CComPtr<IHTMLElement> divElement;
|
||||
if (SUCCEEDED(GetDomNodeAndElementById(name, divNode, divElement)))
|
||||
if (!name.empty())
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> parent;
|
||||
if (SUCCEEDED(divNode->get_parentNode(&parent)))
|
||||
CComPtr<IHTMLDOMNode> divNode;
|
||||
CComPtr<IHTMLElement> divElement;
|
||||
if (SUCCEEDED(GetDomNodeAndElementById(name, divNode, divElement)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> removedNode;
|
||||
if (SUCCEEDED(parent->removeChild(divNode, &removedNode)))
|
||||
CComPtr<IHTMLDOMNode> parent;
|
||||
if (SUCCEEDED(divNode->get_parentNode(&parent)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> appendedNode;
|
||||
if (SUCCEEDED(mainNode->appendChild(removedNode, &appendedNode)))
|
||||
CComPtr<IHTMLDOMNode> removedNode;
|
||||
if (SUCCEEDED(parent->removeChild(divNode, &removedNode)))
|
||||
{
|
||||
CComPtr<IHTMLStyle> style;
|
||||
if (SUCCEEDED(divElement->get_style(&style)))
|
||||
CComPtr<IHTMLDOMNode> appendedNode;
|
||||
if (SUCCEEDED(mainNode->appendChild(removedNode, &appendedNode)))
|
||||
{
|
||||
style->put_display(L"block");
|
||||
CComPtr<IHTMLStyle> style;
|
||||
if (SUCCEEDED(divElement->get_style(&style)))
|
||||
{
|
||||
style->put_display(L"block");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -775,21 +794,4 @@ void CSiaDriveDlg::SetMainWindow(const String& name)
|
||||
void CSiaDriveDlg::SetTabWindow(const String& name)
|
||||
{
|
||||
SetChildWindow(L"ID_ActiveTab", name);
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCreateWallet(IHTMLElement* pElement)
|
||||
{
|
||||
if (!_seedCreation)
|
||||
{
|
||||
_seedCreation = true;
|
||||
KillTimer(IDT_UPDATE);
|
||||
|
||||
String seed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
||||
{
|
||||
DisplaySeedCreated(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
@@ -84,7 +84,7 @@ private:
|
||||
void SetRenterUsedFunds(const SiaCurrency& currency);
|
||||
void SetRenterHosts(const std::uint64_t& hosts);
|
||||
void SetRenterTotalUsed(const std::uint64_t& bytes);
|
||||
void ExecuteUiAction(std::function<void()> action);
|
||||
void QueueUiAction(std::function<void()> action);
|
||||
void ProcessUiActionQueue();
|
||||
void ClearDisplay();
|
||||
|
||||
|
Reference in New Issue
Block a user