diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-03-11 14:19:01 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-03-11 14:19:01 +0000 |
commit | a0a667fd07e912b1dc425748e58a72fa9a50512f (patch) | |
tree | 027b0ed27a5c3d697dd1aa51a13ca0d3e1375582 /plugins/Dropbox/src/dropbox.cpp | |
parent | f8f38839dba925d30c09d9b1527258973c24e591 (diff) |
Dropbox:
- fixed TabSrmm button behavior
- added ME_DROPBOX_SEND_SUCCEEDED and ME_DROPBOX_SEND_FAILED events
- remained only unicode version of MS_DROPBOX_SEND_FILE
- minor fixes
- version bumped
git-svn-id: http://svn.miranda-ng.org/main/trunk@8557 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox.cpp')
-rw-r--r-- | plugins/Dropbox/src/dropbox.cpp | 198 |
1 files changed, 65 insertions, 133 deletions
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 74c3eb8653..9081daae85 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -7,17 +7,18 @@ CDropbox::CDropbox() pd.type = PROTOTYPE_VIRTUAL;
CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
+ HookEventObj(ME_PROTO_ACK, OnProtoAck, this);
HookEventObj(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown, this);
HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this);
- HookEventObj(ME_DB_CONTACT_DELETED, OnContactDeleted, this);
- HookEventObj(ME_OPT_INITIALISE, OnOptionsInitialized, this);
- HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu, this);
+
+ hFileSendFailedHook = CreateHookableEvent(ME_DROPBOX_SEND_FAILED);
+ hFileSendSuccessedHook = CreateHookableEvent(ME_DROPBOX_SEND_SUCCEEDED);
+ HookEventObj(ME_DROPBOX_SEND_SUCCEEDED, OnSendSuccessed, this);
CreateServiceFunctionObj(MS_DROPBOX_SEND_FILE, SendFileToDropbox, this);
- CreateServiceFunctionObj(MS_DROPBOX_SEND_FILEW, SendFileWToDropbox, this);
CreateProtoServiceFunction(MODULE, PS_GETCAPS, ProtoGetCaps);
- CreateProtoServiceFunctionObj(PSS_FILE, ProtoSendFile, this);
+ CreateProtoServiceFunctionObj(PSS_FILEW, ProtoSendFile, this);
CreateProtoServiceFunctionObj(PSS_MESSAGE, ProtoSendMessage, this);
CreateProtoServiceFunctionObj(PSR_MESSAGE, ProtoReceiveMessage, this);
@@ -33,6 +34,12 @@ CDropbox::CDropbox() hDefaultContact = hTransferContact = 0;
}
+CDropbox::~CDropbox()
+{
+ DestroyHookableEvent(hFileSendFailedHook);
+ DestroyHookableEvent(hFileSendSuccessedHook);
+}
+
MCONTACT CDropbox::GetDefaultContact()
{
if (!hDefaultContact)
@@ -61,71 +68,6 @@ bool CDropbox::HasAccessToken() return db_get_sa(NULL, MODULE, "TokenSecret") != NULL;
}
-//void CDropbox::RequestAcceessToken()
-//{
-// ShellExecuteA(NULL, "open", DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY, NULL, NULL, SW_SHOWDEFAULT);
-//
-// char request_token[128] = { 0 };
-//
-// if (DialogBoxParam(
-// g_hInstance,
-// MAKEINTRESOURCE(IDD_TOKEN_REQUEST),
-// NULL,
-// CDropbox::TokenRequestProc,
-// (LPARAM)&request_token) == IDOK)
-// {
-// char data[1024];
-// mir_snprintf(
-// data,
-// SIZEOF(data),
-// "grant_type=authorization_code&code=%s",
-// request_token);
-//
-// HttpRequest *request = new HttpRequest(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);
-// }
-//
-// CDropbox::ShowNotification(TranslateT("You have been authorized"), MB_ICONINFORMATION);
-// }
-// else
-// {
-// JSONNODE *node = json_get(root, "error_description");
-// ptrW error_description(json_as_string(node));
-//
-// CDropbox::ShowNotification((wchar_t*)error_description, MB_ICONERROR);
-// }
-// }
-// }
-// else
-// HandleFileTransferError(response, hContact);
-// }
-//}
-
void CDropbox::RequestAccountInfo()
{
HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_GET, DROPBOX_API_URL "/account/info");
@@ -136,79 +78,69 @@ void CDropbox::RequestAccountInfo() MCONTACT hContact = CDropbox::GetDefaultContact();
- if (response)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *root = json_parse(response->pData);
if (root)
{
- if (response->resultCode == HTTP_STATUS_OK)
+ JSONNODE *node = json_get(root, "referral_link");
+ if (node)
{
- JSONNODE *node = json_get(root, "referral_link");
- if (node)
- {
- ptrW referral_link = ptrW(json_as_string(node));
- db_set_ws(hContact, MODULE, "Homepage", referral_link);
- }
+ ptrW referral_link = ptrW(json_as_string(node));
+ db_set_ws(hContact, MODULE, "Homepage", referral_link);
+ }
- node = json_get(root, "display_name");
- if (node)
+ node = json_get(root, "display_name");
+ if (node)
+ {
+ ptrW display_name = ptrW(json_as_string(node));
+ wchar_t *sep = wcsrchr(display_name, L' ');
+ if (sep)
{
- ptrW display_name = ptrW(json_as_string(node));
- wchar_t *sep = wcsrchr(display_name, L' ');
- if (sep)
- {
- db_set_ws(hContact, MODULE, "LastName", sep + 1);
- display_name[wcslen(display_name) - wcslen(sep)] = '\0';
- db_set_ws(hContact, MODULE, "FirstName", display_name);
- }
- else
- {
- db_set_ws(hContact, MODULE, "FirstName", display_name);
- db_unset(hContact, MODULE, "LastName");
- }
+ db_set_ws(hContact, MODULE, "LastName", sep + 1);
+ display_name[wcslen(display_name) - wcslen(sep)] = '\0';
+ db_set_ws(hContact, MODULE, "FirstName", display_name);
}
-
- node = json_get(root, "country");
- if (node)
+ else
{
- ptrW isocodeW(json_as_string(node));
- ptrA isocode(mir_u2a(isocodeW));
-
- if (!strlen(isocode))
- db_unset(hContact, MODULE, "Country");
- else
- {
- char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0);
- db_set_s(hContact, MODULE, "Country", country);
- }
+ db_set_ws(hContact, MODULE, "FirstName", display_name);
+ db_unset(hContact, MODULE, "LastName");
}
+ }
+
+ node = json_get(root, "country");
+ if (node)
+ {
+ ptrW isocodeW(json_as_string(node));
+ ptrA isocode(mir_u2a(isocodeW));
- node = json_get(root, "quota_info");
- root = json_as_node(node);
- if (root)
+ if (!strlen(isocode))
+ db_unset(hContact, MODULE, "Country");
+ else
{
- node = json_get(root, "shared");
- if (node)
- db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node));
- node = json_get(root, "normal");
- if (node)
- db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node));
- node = json_get(root, "quota");
- if (node)
- db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node));
+ char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0);
+ db_set_s(hContact, MODULE, "Country", country);
}
}
- /*else
- {
- JSONNODE *node = json_get(root, "error_description");
- ptrW error_description(json_as_string(node));
- CDropbox::ShowNotification((wchar_t*)error_description, MB_ICONERROR);
- }*/
+ node = json_get(root, "quota_info");
+ root = json_as_node(node);
+ if (root)
+ {
+ node = json_get(root, "shared");
+ if (node)
+ db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node));
+ node = json_get(root, "normal");
+ if (node)
+ db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node));
+ node = json_get(root, "quota");
+ if (node)
+ db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node));
+ }
}
}
- //else
- // HandleFileTransferError(response, hContact);
+
+ HandleHttpResponseError(hNetlibUser, response);
}
void CDropbox::DestroyAcceessToken()
@@ -282,8 +214,8 @@ UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) if (hwndDlg)
SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
- else
- ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);
+ /*else
+ ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/
}
else
{
@@ -292,17 +224,17 @@ UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) if (hwndDlg)
SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
- else
- ShowNotification((wchar_t*)error_description, MB_ICONERROR);
+ /*else
+ ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/
}
}
}
else
{
if (hwndDlg)
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("unknown error"));
- else
- HandleFileTransferError(instance->hNetlibUser, response);
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
+
+ HandleHttpResponseError(instance->hNetlibUser, response);
}
SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");
|