diff options
Diffstat (limited to 'plugins/Dropbox/src/dropbox_dialogs.cpp')
-rw-r--r-- | plugins/Dropbox/src/dropbox_dialogs.cpp | 117 |
1 files changed, 44 insertions, 73 deletions
diff --git a/plugins/Dropbox/src/dropbox_dialogs.cpp b/plugins/Dropbox/src/dropbox_dialogs.cpp index 445da14a3f..c649c3e60e 100644 --- a/plugins/Dropbox/src/dropbox_dialogs.cpp +++ b/plugins/Dropbox/src/dropbox_dialogs.cpp @@ -58,94 +58,65 @@ INT_PTR CALLBACK CDropbox::TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wPara INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+
switch (msg)
{
case WM_INITDIALOG:
+ {
TranslateDialogDefault(hwndDlg);
- {
- CheckDlgButton(hwndDlg, IDC_USE_SHORT_LINKS, db_get_b(NULL, MODULE, "UseSortLinks", 1));
- }
+
+ instance = (CDropbox*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+
+ CheckDlgButton(hwndDlg, IDC_USE_SHORT_LINKS, db_get_b(NULL, MODULE, "UseSortLinks", 1));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
+
+ LOGFONT lf;
+ HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_AUTH_STATUS, WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ SendDlgItemMessage(hwndDlg, IDC_AUTH_STATUS, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+
+ if (instance->HasAccessToken())
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you are already authorized"));
+ else
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you are not authorized yet"));
+ }
return TRUE;
case WM_COMMAND:
- if (HIWORD(wParam) == STN_CLICKED)
+ switch (LOWORD(wParam))
{
- switch (LOWORD(wParam))
- {
- case IDC_GETAUTH:
- CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY);
- break;
-
- case IDC_USE_SHORT_LINKS:
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_AUTHORIZE:
- {
- char request_token[128];
- GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, request_token, SIZEOF(request_token));
-
- char data[1024];
- mir_snprintf(
- data,
- SIZEOF(data),
- "grant_type=authorization_code&code=%s",
- request_token);
-
- HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token");
- request->pData = mir_strdup(data);
- request->dataLength = (int)strlen(data);
- request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
-
- delete request;
-
- MCONTACT hContact = CDropbox::GetDefaultContact();
-
- if (response)
- {
- JSONNODE *root = json_parse(response->pData);
- if (root)
- {
- if (response->resultCode == HTTP_STATUS::OK)
- {
- JSONNODE *node = json_get(root, "access_token");
- ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
- db_set_s(NULL, MODULE, "TokenSecret", access_token);
-
- if (hContact)
- {
- if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
- db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
- }
-
- ShowNotification(TranslateT("You have been authorized"), MB_ICONINFORMATION);
- }
- else
- {
- JSONNODE *node = json_get(root, "error_description");
- ptrW error_description(json_as_string(node));
-
- ShowNotification((wchar_t*)error_description, MB_ICONERROR);
- }
- }
- }
- else
- HandleFileTransferError(response, hContact);
-
- }
- }
+ case IDC_GETAUTH:
+ CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY);
+ SetFocus(GetDlgItem(hwndDlg, IDC_REQUEST_CODE));
break;
+
+ case IDC_REQUEST_CODE:
+ {
+ if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0;
+
+ char requestToken[128];
+ GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), strlen(requestToken) != 0);
+ }
+ break;
+
+ case IDC_AUTHORIZE:
+ mir_forkthreadowner(CDropbox::RequestAcceessTokenAsync, instance, hwndDlg, 0);
+ break;
+
+ case IDC_USE_SHORT_LINKS:
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
}
break;
case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
- {
db_set_b(NULL, MODULE, "UseSortLinks", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USE_SHORT_LINKS));
- }
break;
}
return FALSE;
|