summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox_options.cpp
blob: 5dacc245356f4db8758087d8082a1c51917a571f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"

CDropboxOptionsMain::CDropboxOptionsMain(CDropbox *instance, int idDialog)
	: CDropboxDlgBase(instance, idDialog),
	m_auth(NULL, IDC_GETAUTH, DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_APP_KEY),
	m_requestCode(NULL, IDC_REQUEST_CODE), m_authorize(NULL, IDC_AUTHORIZE), m_authStatus(NULL, IDC_AUTH_STATUS),
	m_useShortUrl(this, IDC_USE_SHORT_LINKS), m_urlAutoSend(this, IDC_URL_AUTOSEND),
	m_urlPasteToMessageInputArea(this, IDC_URL_COPYTOMIA), m_urlCopyToClipboard(this, IDC_URL_COPYTOCB)
{
	CreateLink(m_useShortUrl, "UseSortLinks", DBVT_BYTE, 1);
	CreateLink(m_urlAutoSend, "UrlAutoSend", DBVT_BYTE, 1);
	CreateLink(m_urlPasteToMessageInputArea, "UrlPasteToMessageInputArea", DBVT_BYTE, 0);
	CreateLink(m_urlCopyToClipboard, "UrlCopyToClipboard", DBVT_BYTE, 0);

	//m_auth.OnClick = Callback(this, &CDropboxOptionsMain::Auth_OnClick);
	m_requestCode.OnChange = Callback(this, &CDropboxOptionsMain::RequestCode_OnChange);
	m_authorize.OnClick = Callback(this, &CDropboxOptionsMain::Authorize_OnClick);
}

void CDropboxOptionsMain::OnInitDialog()
{
	CDropboxDlgBase::OnInitDialog();

	LOGFONT lf;
	HFONT hFont = (HFONT)m_authStatus.SendMsg(WM_GETFONT, 0, 0);
	GetObject(hFont, sizeof(lf), &lf);
	lf.lfWeight = FW_BOLD;
	m_authStatus.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);

	if (m_instance->HasAccessToken())
		m_authStatus.SetText(TranslateT("you are already authorized"));
	else
		m_authStatus.SetText(TranslateT("you are not authorized yet"));
}

void CDropboxOptionsMain::Auth_OnClick(CCtrlBase*)
{
	SetFocus(m_requestCode.GetHwnd());
}

void CDropboxOptionsMain::RequestCode_OnChange(CCtrlBase*)
{
	ptrA requestToken(m_requestCode.GetTextA());
	EnableWindow(m_authorize.GetHwnd(), mir_strlen(requestToken) != 0);
}

void CDropboxOptionsMain::Authorize_OnClick(CCtrlBase*)
{
	mir_forkthreadowner(CDropbox::RequestAccessTokenAsync, m_instance, m_hwnd, 0);
}

/////////////////////////////////////////////////////////////////////////////////

int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM)
{
	OPTIONSDIALOGPAGE odp = { 0 };
	odp.ptszTitle = _T(MODULE);
	odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
	odp.ptszGroup = LPGENT("Network");

	odp.ptszTab = LPGENT("Dropbox");
	odp.pDialog = CDropboxOptionsMain::CreateOptionsPage(this);
	Options_AddPage(wParam, &odp);

	return 0;
}