summaryrefslogtreecommitdiff
path: root/protocols/CloudFile/src/options.cpp
blob: de961a314a027bcb5d361925273cde11169e4d49 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "stdafx.h"

COptionsMainDlg::COptionsMainDlg()
	: CDlgBase(g_plugin, IDD_OPTIONS_MAIN),
	m_defaultService(this, IDC_DEFAULTSERVICE),
	m_doNothingOnConflict(this, IDC_DONOTHINGONCONFLICT),
	m_renameOnConflict(this, IDC_RENAMEONCONFLICT),
	m_repalceOnConflict(this, IDC_REPLACEONCONFLICT),
	m_urlAutoSend(this, IDC_URL_AUTOSEND),
	m_urlPasteToMessageInputArea(this, IDC_URL_COPYTOMIA),
	m_urlCopyToClipboard(this, IDC_URL_COPYTOCB)
{
	CreateLink(m_defaultService, "DefaultService", L"");

	CreateLink(m_urlAutoSend, "UrlAutoSend", DBVT_BYTE, 1);
	CreateLink(m_urlPasteToMessageInputArea, "UrlPasteToMessageInputArea", DBVT_BYTE, 0);
	CreateLink(m_urlCopyToClipboard, "UrlCopyToClipboard", DBVT_BYTE, 0);
}

bool COptionsMainDlg::OnInitDialog()
{
	CDlgBase::OnInitDialog();

	ptrA defaultService(g_plugin.getStringA("DefaultService"));
	int iItem = m_defaultService.AddString(TranslateT("None"));
	m_defaultService.SetCurSel(iItem);

	for (auto &service : Services) {
		iItem = m_defaultService.AddString(mir_wstrdup(service->GetUserName()), (LPARAM)service);
		if (!mir_strcmpi(service->GetAccountName(), defaultService))
			m_defaultService.SetCurSel(iItem);
	}

	BYTE strategy = g_plugin.getByte("ConflictStrategy", OnConflict::REPLACE);
	switch (strategy)
	{
	case OnConflict::RENAME:
		m_renameOnConflict.SetState(TRUE);
		m_repalceOnConflict.SetState(FALSE);
		m_doNothingOnConflict.SetState(FALSE);
		break;
	case OnConflict::REPLACE:
		m_renameOnConflict.SetState(FALSE);
		m_repalceOnConflict.SetState(TRUE);
		m_doNothingOnConflict.SetState(FALSE);
		break;
	default:
		m_renameOnConflict.SetState(FALSE);
		m_repalceOnConflict.SetState(FALSE);
		m_doNothingOnConflict.SetState(TRUE);
		break;
	}
	return true;
}

bool COptionsMainDlg::OnApply()
{
	CCloudService *service = (CCloudService*)m_defaultService.GetCurData();
	if (service)
		g_plugin.setString("DefaultService", service->GetAccountName());
	else
		g_plugin.delSetting("DefaultService");

	if (m_renameOnConflict.GetState())
		g_plugin.setByte("ConflictStrategy", OnConflict::RENAME);
	else if (m_repalceOnConflict.GetState())
		g_plugin.setByte("ConflictStrategy", OnConflict::REPLACE);
	else
		g_plugin.delSetting("ConflictStrategy");
	return true;
}

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

int OnOptionsInitialized(WPARAM wParam, LPARAM)
{
	OPTIONSDIALOGPAGE odp = {};
	odp.szTitle.w = _A2W(MODULENAME);
	odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE | ODPF_DONTTRANSLATE;
	odp.szGroup.w = LPGENW("Services");

	//odp.szTab.w = LPGENW("General");
	odp.pDialog = new COptionsMainDlg();
	g_plugin.addOptions(wParam, &odp);

	return 0;
}

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

CAccountManagerDlg::CAccountManagerDlg(CCloudService *service)
	: CProtoDlgBase(service, IDD_ACCMGR),
	m_requestAccess(this, IDC_REQUESTACCESS),
	m_revokeAccess(this, IDC_REVOKEACCESS)
{
	m_requestAccess.OnClick = Callback(this, &CAccountManagerDlg::RequestAccess_OnClick);
	m_revokeAccess.OnClick = Callback(this, &CAccountManagerDlg::RevokeAccess_OnClick);
}

bool CAccountManagerDlg::OnInitDialog()
{
	ptrA token(m_proto->getStringA("TokenSecret"));
	m_requestAccess.Enable(!token);
	m_revokeAccess.Enable(token);
	return true;
}

void CAccountManagerDlg::RequestAccess_OnClick(CCtrlButton*)
{
	m_proto->Login(m_hwnd);
	ptrA token(m_proto->getStringA("TokenSecret"));
	m_requestAccess.Enable(!token);
	m_revokeAccess.Enable(token);
}

void CAccountManagerDlg::RevokeAccess_OnClick(CCtrlButton*)
{
	m_proto->Logout();
	m_requestAccess.Enable();
	m_revokeAccess.Disable();
}

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