From 3e9e349a53492e5377154b8518803058d72e37ed Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 13 May 2015 19:32:08 +0000 Subject: Dropbox: moved to core ui git-svn-id: http://svn.miranda-ng.org/main/trunk@13574 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/res/resource.rc | 6 +-- plugins/Dropbox/src/api/account.h | 3 +- plugins/Dropbox/src/dropbox.h | 18 +-------- plugins/Dropbox/src/dropbox_dialogs.cpp | 17 +++++++++ plugins/Dropbox/src/dropbox_dialogs.h | 24 ++++++++++++ plugins/Dropbox/src/dropbox_events.cpp | 17 --------- plugins/Dropbox/src/dropbox_options.cpp | 66 +++++++++++++++++++++++++++++++++ plugins/Dropbox/src/dropbox_options.h | 30 +++++++++++++++ plugins/Dropbox/src/stdafx.h | 33 ++++++++++++++--- plugins/Dropbox/src/version.h | 2 +- 10 files changed, 171 insertions(+), 45 deletions(-) create mode 100644 plugins/Dropbox/src/dropbox_dialogs.h create mode 100644 plugins/Dropbox/src/dropbox_options.cpp create mode 100644 plugins/Dropbox/src/dropbox_options.h diff --git a/plugins/Dropbox/res/resource.rc b/plugins/Dropbox/res/resource.rc index c685e85e80..86708c0e07 100644 --- a/plugins/Dropbox/res/resource.rc +++ b/plugins/Dropbox/res/resource.rc @@ -7,7 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#include "afxres.h" +#include "winres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -39,7 +39,7 @@ BEGIN EDITTEXT IDC_REQUEST_CODE,144,51,169,13,ES_AUTOHSCROLL LTEXT "3.",IDC_STATIC,21,71,8,8 LTEXT "Initiate authorization",IDC_STATIC,29,71,109,16 - PUSHBUTTON "Authorize",IDC_AUTHORIZE,144,68,169,14,BS_CENTER + PUSHBUTTON "Authorize",IDC_AUTHORIZE,144,68,169,14,BS_CENTER | WS_DISABLED GROUPBOX "Download link",IDC_STATIC,5,111,313,70 CONTROL "Use shortened download links",IDC_URL_USE_SHORT,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,125,298,10 LTEXT "4.",IDC_STATIC,22,89,8,8 @@ -123,7 +123,7 @@ END 2 TEXTINCLUDE BEGIN - "#include ""afxres.h""\r\n" + "#include ""winres.h""\r\n" "\0" END diff --git a/plugins/Dropbox/src/api/account.h b/plugins/Dropbox/src/api/account.h index 4db79622d2..9c8bf20e7e 100644 --- a/plugins/Dropbox/src/api/account.h +++ b/plugins/Dropbox/src/api/account.h @@ -11,8 +11,7 @@ public: AddHeader("Content-Type", "application/x-www-form-urlencoded"); CMStringA data(CMStringDataFormat::FORMAT, "grant_type=authorization_code&code=%s", requestToken); - pData = data.GetBuffer(); - dataLength = data.GetLength(); + SetData(data.GetBuffer(), data.GetLength()); } }; diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 1036ff5e04..e8340d5fcd 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -1,22 +1,6 @@ #ifndef _DROPBOX_PROTO_H_ #define _DROPBOX_PROTO_H_ -#include "http_request.h" -#include "file_transfer.h" - -#define DROPBOX_API_VER "1" -#define DROPBOX_API_ROOT "sandbox" -#define DROPBOX_WWW_URL "https://www.dropbox.com/" -#define DROPBOX_API_URL "https://api.dropbox.com/" DROPBOX_API_VER -#define DROPBOX_APICONTENT_URL "https://api-content.dropbox.com/" DROPBOX_API_VER - -#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg" -#include "..\..\..\miranda-private-keys\Dropbox\secret_key.h" - -#define DROPBOX_FILE_CHUNK_SIZE 4 * 1024 * 1024 //4 MB - -#define BBB_ID_FILE_SEND 10001 - enum { CMI_SEND_FILES, @@ -25,6 +9,8 @@ enum class CDropbox : public MZeroedObject { + friend CDropboxOptionsMain; + struct CommandParam { CDropbox *instance; diff --git a/plugins/Dropbox/src/dropbox_dialogs.cpp b/plugins/Dropbox/src/dropbox_dialogs.cpp index 1bbc71326e..0634fab398 100644 --- a/plugins/Dropbox/src/dropbox_dialogs.cpp +++ b/plugins/Dropbox/src/dropbox_dialogs.cpp @@ -1,5 +1,22 @@ #include "stdafx.h" +CDropboxDlgBase::CDropboxDlgBase(CDropbox *instance, int idDialog) + : CDlgBase(g_hInstance, idDialog), m_instance(instance) +{ +} + +void CDropboxDlgBase::CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue) +{ + ctrl.CreateDbLink(MODULE, szSetting, type, iValue); +} + +void CDropboxDlgBase::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue) +{ + ctrl.CreateDbLink(MODULE, szSetting, szValue); +} + +///////////////////////////////////////////////////////////// + INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CDropbox *instance = (CDropbox*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); diff --git a/plugins/Dropbox/src/dropbox_dialogs.h b/plugins/Dropbox/src/dropbox_dialogs.h new file mode 100644 index 0000000000..c39e3e342a --- /dev/null +++ b/plugins/Dropbox/src/dropbox_dialogs.h @@ -0,0 +1,24 @@ +#ifndef _DROPBOX_DIALOGS_H_ +#define _DROPBOX_DIALOGS_H_ + +class CDropboxDlgBase : public CDlgBase +{ +protected: + CDropbox *m_instance; + +public: + CDropboxDlgBase(CDropbox *instance, int idDialog); + + void CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue); + void CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue); + + template + __inline void CreateLink(CCtrlData& ctrl, CMOption &option) + { + ctrl.CreateDbLink(new CMOptionLink(option)); + } + + __inline CDropbox *GetInstance() { return m_instance; } +}; + +#endif //_DROPBOX_DIALOGS_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index fa0e3d91a8..8673eb85b1 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -61,23 +61,6 @@ int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM) return 0; } -int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.position = 100000000; - odp.hInstance = g_hInstance; - odp.flags = ODPF_BOLDGROUPS; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_MAIN); - odp.pszGroup = LPGEN("Network"); - odp.pszTitle = "Dropbox"; - odp.pfnDlgProc = MainOptionsProc; - odp.dwInitParam = (LPARAM)this; - - Options_AddPage(wParam, &odp); - - return 0; -} - int CDropbox::OnSrmmWindowOpened(WPARAM, LPARAM lParam) { MessageWindowEventData *ev = (MessageWindowEventData*)lParam; diff --git a/plugins/Dropbox/src/dropbox_options.cpp b/plugins/Dropbox/src/dropbox_options.cpp new file mode 100644 index 0000000000..5dacc24535 --- /dev/null +++ b/plugins/Dropbox/src/dropbox_options.cpp @@ -0,0 +1,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; +} diff --git a/plugins/Dropbox/src/dropbox_options.h b/plugins/Dropbox/src/dropbox_options.h new file mode 100644 index 0000000000..d216a5b546 --- /dev/null +++ b/plugins/Dropbox/src/dropbox_options.h @@ -0,0 +1,30 @@ +#ifndef _DROPBOX_OPTIONS_H_ +#define _DROPBOX_OPTIONS_H_ + +class CDropboxOptionsMain : public CDropboxDlgBase +{ +private: + CCtrlHyperlink m_auth; + CCtrlEdit m_requestCode; + CCtrlButton m_authorize; + CCtrlBase m_authStatus; + + CCtrlCheck m_useShortUrl; + CCtrlCheck m_urlAutoSend; + CCtrlCheck m_urlPasteToMessageInputArea; + CCtrlCheck m_urlCopyToClipboard; + +protected: + void OnInitDialog(); + + void Auth_OnClick(CCtrlBase*); + void RequestCode_OnChange(CCtrlBase*); + void Authorize_OnClick(CCtrlBase*); + +public: + CDropboxOptionsMain(CDropbox *instance, int idDialog); + + static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsMain((CDropbox*)param, IDD_OPTIONS_MAIN); } +}; + +#endif //_DROPBOX_OPTIONS_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h index c2eca7328b..c541f3ad4a 100644 --- a/plugins/Dropbox/src/stdafx.h +++ b/plugins/Dropbox/src/stdafx.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,6 +12,7 @@ #include #include +#include #include #include #include @@ -21,26 +23,45 @@ #include #include #include +#include #include #include #include -#include - #include -#include "dropbox.h" -#include "api\account.h" -#include "api\upload.h" -#include "api\operations.h" #include "version.h" #include "resource.h" +class CDropbox; + +#define DROPBOX_API_VER "1" +#define DROPBOX_API_ROOT "sandbox" +#define DROPBOX_WWW_URL "https://www.dropbox.com/" +#define DROPBOX_API_URL "https://api.dropbox.com/" DROPBOX_API_VER +#define DROPBOX_APICONTENT_URL "https://api-content.dropbox.com/" DROPBOX_API_VER + +#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg" +#include "..\..\..\miranda-private-keys\Dropbox\secret_key.h" + +#include "dropbox_dialogs.h" +#include "dropbox_options.h" +#include "http_request.h" +#include "api\account.h" +#include "api\upload.h" +#include "api\operations.h" +#include "file_transfer.h" +#include "dropbox.h" + #define MODULE "Dropbox" extern HINSTANCE g_hInstance; +#define DROPBOX_FILE_CHUNK_SIZE 4 * 1024 * 1024 //4 MB + +#define BBB_ID_FILE_SEND 10001 + // icons void InitializeIcons(); HANDLE GetIconHandle(int iconId); diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index f1cd12cd17..a8bcc19833 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 12 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3