summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-02-27 09:59:53 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-02-27 09:59:53 +0000
commit2e51a3103f26ca7a9fec8f96baf56f4d51fd0112 (patch)
tree239feacbe6263d41b7bb021f4e226e2687775904 /plugins/Dropbox/src/dropbox.cpp
parent9b5210ac07c6e4e00af25eb90fdf653da791299a (diff)
Dropbox:
- added error notifications - fixed menu items behavior git-svn-id: http://svn.miranda-ng.org/main/trunk@8283 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox.cpp')
-rw-r--r--plugins/Dropbox/src/dropbox.cpp52
1 files changed, 20 insertions, 32 deletions
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp
index 41c53d22a4..3498680c24 100644
--- a/plugins/Dropbox/src/dropbox.cpp
+++ b/plugins/Dropbox/src/dropbox.cpp
@@ -37,7 +37,7 @@ bool CDropbox::HasAccessToken()
return db_get_sa(NULL, MODULE, "TokenSecret") != NULL;
}
-void CDropbox::RequestAcceessToken(MCONTACT hContact)
+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);
@@ -63,16 +63,18 @@ void CDropbox::RequestAcceessToken(MCONTACT hContact)
request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
- NETLIBHTTPREQUEST *response = request->Send();
+ mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
delete request;
+ MCONTACT hContact = CDropbox::GetDefaultContact();
+
if (response)
{
- if (response->resultCode == HTTP_STATUS::OK)
+ JSONNODE *root = json_parse(response->pData);
+ if (root)
{
- JSONNODE *root = json_parse(response->pData);
- if (root != NULL)
+ if (response->resultCode == HTTP_STATUS::OK)
{
JSONNODE *node = json_get(root, "access_token");
ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
@@ -80,46 +82,34 @@ void CDropbox::RequestAcceessToken(MCONTACT hContact)
if (hContact)
{
- node = json_get(root, "uid");
- wchar_t *uid = json_as_string(node);
- db_set_ws(hContact, MODULE, "uid", uid);
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("Access request"), TranslateT("Access granted"), MB_ICONINFORMATION);
-
- delete node;
- delete root;
+ CDropbox::ShowNotification(TranslateT("You have been authorized"), MB_ICONINFORMATION);
}
- }
- else
- {
- JSONNODE *root = json_parse(response->pData);
- if (root != NULL)
+ else
{
JSONNODE *node = json_get(root, "error_description");
- wchar_t *error_description = json_as_string(node);
+ ptrW error_description(json_as_string(node));
- CDropbox::ShowNotification(TranslateT("Access request"), error_description, MB_ICONERROR);
-
- delete node;
- delete root;
+ CDropbox::ShowNotification((wchar_t*)error_description, MB_ICONERROR);
}
}
-
- mir_free(response);
}
+ else
+ HandleFileTransferError(response, hContact);
}
}
-void CDropbox::DestroyAcceessToken(MCONTACT hContact)
+void CDropbox::DestroyAcceessToken()
{
HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/disable_access_token");
- NETLIBHTTPREQUEST *response = request->Send();
+ mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
delete request;
- mir_free(response);
+
+ MCONTACT hContact = CDropbox::GetDefaultContact();
db_unset(NULL, MODULE, "TokenSecret");
if (hContact)
@@ -131,17 +121,15 @@ void CDropbox::DestroyAcceessToken(MCONTACT hContact)
void CDropbox::RequestApiAuthorizationAsync(void *arg)
{
- MCONTACT hContact = (MCONTACT)arg;
-
if (HasAccessToken() && MessageBox(
NULL,
TranslateT("Are you sure you want to request athorization?"),
TranslateT("Request athorization"),
MB_YESNO | MB_ICONQUESTION) == IDYES)
{
- INSTANCE->DestroyAcceessToken(hContact);
- INSTANCE->RequestAcceessToken(hContact);
+ INSTANCE->DestroyAcceessToken();
+ INSTANCE->RequestAcceessToken();
}
else
- INSTANCE->RequestAcceessToken(hContact);
+ INSTANCE->RequestAcceessToken();
} \ No newline at end of file