From 60074fa377aeaed72a7cb1bb8d3ed7781a68eeb1 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Thu, 25 Dec 2014 11:22:02 +0000 Subject: =?UTF-8?q?VKontakte:=20move=20GetAttachmentDescr=20to=20misc.cpp?= =?UTF-8?q?=20add=20=E2=80=98View=20settings=E2=80=99=20option=20page=20an?= =?UTF-8?q?d=20more=20options=20for=20view=20attachments,=20news=20and=20n?= =?UTF-8?q?otification=20in=20message=20log=20code=20cleanup=20and=20reorg?= =?UTF-8?q?anization=20version=20bump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@11624 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/misc.cpp | 448 ++++++++++++++++++++++++--------- protocols/VKontakte/src/resource.h | 15 +- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_feed.cpp | 95 +++---- protocols/VKontakte/src/vk_options.cpp | 101 +++++++- protocols/VKontakte/src/vk_proto.cpp | 4 +- protocols/VKontakte/src/vk_proto.h | 97 ++++--- protocols/VKontakte/src/vk_thread.cpp | 125 --------- 8 files changed, 528 insertions(+), 359 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 3e68df1325..051c34f929 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -17,6 +17,127 @@ along with this program. If not, see . #include "stdafx.h" +static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" }; + +LPCSTR findHeader(NETLIBHTTPREQUEST *pReq, LPCSTR szField) +{ + for (int i = 0; i < pReq->headersCount; i++) + if (!_stricmp(pReq->headers[i].szName, szField)) + return pReq->headers[i].szValue; + + return NULL; +} + +bool tlstrstr(TCHAR* _s1, TCHAR* _s2) +{ + TCHAR s1[1024], s2[1024]; + + _tcsncpy_s(s1, _s1, _TRUNCATE); + CharLowerBuff(s1, SIZEOF(s1)); + _tcsncpy_s(s2, _s2, _TRUNCATE); + CharLowerBuff(s2, SIZEOF(s2)); + + return _tcsstr(s1, s2) != NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static IconItem iconList[] = +{ + { LPGEN("Captcha form icon"), "key", IDI_KEYS }, + { LPGEN("Notification icon"), "notification", IDI_NOTIFICATION }, + { LPGEN("Read message icon"), "read", IDI_READMSG }, + { LPGEN("Visit profile icon"), "profile", IDI_VISITPROFILE }, + { LPGEN("Load server history icon"), "history", IDI_HISTORY }, + { LPGEN("Add to friend list icon"), "addfriend", IDI_FRIENDADD }, + { LPGEN("Delete from friend list icon"), "delfriend", IDI_FRIENDDEL }, + { LPGEN("Report abuse icon"), "abuse", IDI_ABUSE }, + { LPGEN("Ban user icon"), "ban", IDI_BAN }, + { LPGEN("Broadcast icon"), "broadcast", IDI_BROADCAST } +}; + +void InitIcons() +{ + Icon_Register(hInst, LPGEN("Protocols")"/"LPGEN("VKontakte"), iconList, SIZEOF(iconList), "VKontakte"); +} + +HANDLE GetIconHandle(int iCommand) +{ + for (int i = 0; i < SIZEOF(iconList); i++) + if (iconList[i].defIconID == iCommand) + return iconList[i].hIcolib; + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +AsyncHttpRequest::AsyncHttpRequest() +{ + cbSize = sizeof(NETLIBHTTPREQUEST); + m_bApiReq = true; + AddHeader("Connection", "keep-alive"); + AddHeader("Accept-Encoding", "booo"); + pUserInfo = NULL; + m_iRetry = MAX_RETRIES; +} + +AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc) +{ + cbSize = sizeof(NETLIBHTTPREQUEST); + m_bApiReq = true; + AddHeader("Connection", "keep-alive"); + AddHeader("Accept-Encoding", "booo"); + + flags = VK_NODUMPHEADERS | NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT; + if (bSecure) + flags |= NLHRF_SSL; + + if (*_url == '/') { // relative url leads to a site + m_szUrl = ((bSecure) ? "https://" : "http://") + CMStringA("api.vk.com"); + m_szUrl += _url; + bIsMainConn = true; + } + else m_szUrl = _url; + + if (bSecure) + this << CHAR_PARAM("access_token", ppro->m_szAccessToken); + + requestType = iRequestType; + m_pFunc = pFunc; + pUserInfo = NULL; + m_iRetry = MAX_RETRIES; +} + +AsyncHttpRequest::~AsyncHttpRequest() +{ + for (int i = 0; i < headersCount; i++) { + mir_free(headers[i].szName); + mir_free(headers[i].szValue); + } + mir_free(headers); + mir_free(pData); +} + +void AsyncHttpRequest::AddHeader(LPCSTR szName, LPCSTR szValue) +{ + headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); + headers[headersCount].szName = mir_strdup(szName); + headers[headersCount].szValue = mir_strdup(szValue); + headersCount++; +} + +void AsyncHttpRequest::Redirect(NETLIBHTTPREQUEST *nhr) +{ + for (int i = 0; i < nhr->headersCount; i++) { + LPCSTR szValue = nhr->headers[i].szValue; + if (!_stricmp(nhr->headers[i].szName, "Location")) + m_szUrl = szValue; + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + TCHAR* CVkProto::GetUserStoredPassword() { debugLogA("CVkProto::GetUserStoredPassword"); @@ -38,6 +159,8 @@ void CVkProto::SetAllContactStatuses(int iStatus) } } +///////////////////////////////////////////////////////////////////////////////////////// + MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate) { if (!dwUserid) @@ -79,6 +202,8 @@ MCONTACT CVkProto::FindChat(LONG dwUserid) return NULL; } +///////////////////////////////////////////////////////////////////////////////////////// + bool CVkProto::CheckMid(int guid) { for (int i = m_sendIds.getCount() - 1; i >= 0; i--) @@ -90,14 +215,7 @@ bool CVkProto::CheckMid(int guid) return false; } -LPCSTR findHeader(NETLIBHTTPREQUEST *pReq, LPCSTR szField) -{ - for (int i = 0; i < pReq->headersCount; i++) - if (!_stricmp(pReq->headers[i].szName, szField)) - return pReq->headers[i].szValue; - - return NULL; -} +///////////////////////////////////////////////////////////////////////////////////////// JSONNODE* CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT &pRoot) { @@ -180,36 +298,6 @@ void CVkProto::OnReceiveSmth(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) debugLog(_T("CVkProto::OnReceiveSmth %s"), json_as_string(pResponse)); } -///////////////////////////////////////////////////////////////////////////////////////// - -static IconItem iconList[] = -{ - { LPGEN("Captcha form icon"), "key", IDI_KEYS }, - { LPGEN("Notification icon"), "notification", IDI_NOTIFICATION }, - { LPGEN("Read message icon"), "read", IDI_READMSG }, - { LPGEN("Visit profile icon"), "profile", IDI_VISITPROFILE }, - { LPGEN("Load server history icon"), "history", IDI_HISTORY }, - { LPGEN("Add to friend list icon"), "addfriend", IDI_FRIENDADD }, - { LPGEN("Delete from friend list icon"), "delfriend", IDI_FRIENDDEL }, - { LPGEN("Report abuse icon"), "abuse", IDI_ABUSE }, - { LPGEN("Ban user icon"), "ban", IDI_BAN}, - { LPGEN("Broadcast icon"), "broadcast", IDI_BROADCAST} -}; - -void InitIcons() -{ - Icon_Register(hInst, LPGEN("Protocols")"/"LPGEN("VKontakte"), iconList, SIZEOF(iconList), "VKontakte"); -} - -HANDLE GetIconHandle(int iCommand) -{ - for (int i=0; i < SIZEOF(iconList); i++) - if (iconList[i].defIconID == iCommand) - return iconList[i].hIcolib; - - return 0; -} - ///////////////////////////////////////////////////////////////////////////////////////// // Quick & dirty form parser @@ -292,70 +380,6 @@ bool CVkProto::AutoFillForm(char *pBody, CMStringA &szAction, CMStringA& szResul ///////////////////////////////////////////////////////////////////////////////////////// -AsyncHttpRequest::AsyncHttpRequest() -{ - cbSize = sizeof(NETLIBHTTPREQUEST); - m_bApiReq = true; - AddHeader("Connection", "keep-alive"); - AddHeader("Accept-Encoding", "booo"); - pUserInfo = NULL; - m_iRetry = MAX_RETRIES; -} - -AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc) -{ - cbSize = sizeof(NETLIBHTTPREQUEST); - m_bApiReq = true; - AddHeader("Connection", "keep-alive"); - AddHeader("Accept-Encoding", "booo"); - - flags = VK_NODUMPHEADERS | NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT; - if (bSecure) - flags |= NLHRF_SSL; - - if (*_url == '/') { // relative url leads to a site - m_szUrl = ((bSecure) ? "https://" : "http://") + CMStringA("api.vk.com"); - m_szUrl += _url; - bIsMainConn = true; - } - else m_szUrl = _url; - - if (bSecure) - this << CHAR_PARAM("access_token", ppro->m_szAccessToken); - - requestType = iRequestType; - m_pFunc = pFunc; - pUserInfo = NULL; - m_iRetry = MAX_RETRIES; -} - -AsyncHttpRequest::~AsyncHttpRequest() -{ - for (int i = 0; i < headersCount; i++) { - mir_free(headers[i].szName); - mir_free(headers[i].szValue); - } - mir_free(headers); - mir_free(pData); -} - -void AsyncHttpRequest::AddHeader(LPCSTR szName, LPCSTR szValue) -{ - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup(szName); - headers[headersCount].szValue = mir_strdup(szValue); - headersCount++; -} - -void AsyncHttpRequest::Redirect(NETLIBHTTPREQUEST *nhr) -{ - for (int i = 0; i < nhr->headersCount; i++) { - LPCSTR szValue = nhr->headers[i].szValue; - if (!_stricmp(nhr->headers[i].szName, "Location")) - m_szUrl = szValue; - } -} - void CVkProto::GrabCookies(NETLIBHTTPREQUEST *nhr) { debugLogA("CVkProto::GrabCookies"); @@ -414,6 +438,8 @@ void CVkProto::ApplyCookies(AsyncHttpRequest *pReq) pReq->AddHeader("Cookie", szCookie); } +///////////////////////////////////////////////////////////////////////////////////////// + void CVkProto::DBAddAuthRequest(const MCONTACT hContact) { debugLogA("CVkProto::DBAddAuthRequest"); @@ -476,6 +502,8 @@ MCONTACT CVkProto::MContactFromDbEvent(HANDLE hDbEvent) return hContact; } +///////////////////////////////////////////////////////////////////////////////////////// + void CVkProto::SetMirVer(MCONTACT hContact, int platform) { if (hContact == NULL || hContact == INVALID_CONTACT_ID) @@ -539,17 +567,7 @@ void CVkProto::SetMirVer(MCONTACT hContact, int platform) setTString(hContact, "MirVer", MirVer.GetBuffer()); } -bool tlstrstr(TCHAR* _s1, TCHAR* _s2) -{ - TCHAR s1[1024], s2[1024]; - - _tcsncpy_s(s1, _s1, _TRUNCATE); - CharLowerBuff(s1, SIZEOF(s1)); - _tcsncpy_s(s2, _s2, _TRUNCATE); - CharLowerBuff(s2, SIZEOF(s2)); - - return _tcsstr(s1, s2) != NULL; -} +///////////////////////////////////////////////////////////////////////////////////////// void CVkProto::ContactTypingThread(void *p) { @@ -632,11 +650,11 @@ int CVkProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam) return 0; } -////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// CMString CVkProto::SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent) { - CVkNotification vkNotification[] = { + CVKNotification vkNotification[] = { // type, parent, feedback, string for translate { _T("follow"), vkNull, vkUsers, _T("") }, { _T("friend_accepted"), vkNull, vkUsers, _T("") }, @@ -675,4 +693,204 @@ CMString CVkProto::SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedba break; } return tszRes; +} + +CMString CVkProto::GetVkPhotoItem(JSONNODE *pPhoto) +{ + CMString tszRes; + + if (pPhoto == NULL) + return tszRes; + + ptrT ptszLink, ptszPreviewLink; + for (int i = 0; i < SIZEOF(szImageTypes); i++) { + JSONNODE *n = json_get(pPhoto, szImageTypes[i]); + if (n != NULL) { + ptszLink = json_as_string(n); + break; + } + } + + switch (m_iIMGBBCSupport){ + case imgNo: + ptszPreviewLink = NULL; + break; + case imgFullSize: + ptszPreviewLink = ptszLink; + break; + case imgPreview130: + case imgPreview604: + ptszPreviewLink = json_as_string(json_get(pPhoto, m_iIMGBBCSupport == imgPreview130 ? "photo_130" : "photo_604")); + break; + } + + int iWidth = json_as_int(json_get(pPhoto, "width")); + int iHeight = json_as_int(json_get(pPhoto, "height")); + + tszRes.AppendFormat(_T("%s: %s (%dx%d)"), TranslateT("Photo"), ptszLink ? ptszLink : _T(""), iWidth, iHeight); + if (m_iIMGBBCSupport) + tszRes.AppendFormat(_T("\n\t[img]%s[/img]"), ptszPreviewLink ? ptszPreviewLink : (ptszLink ? ptszLink : _T(""))); + CMString tszText = json_as_string(json_get(pPhoto, "text")); + if (!tszText.IsEmpty()) + tszRes += "\n" + tszText; + + return tszRes; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) +{ + debugLogA("CVkProto::GetAttachmentDescr"); + CMString res; + res.AppendChar('\n'); + res += TranslateT("Attachments:"); + res.AppendChar('\n'); + JSONNODE *pAttach; + for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) { + res.AppendChar('\t'); + ptrT ptszType(json_as_string(json_get(pAttach, "type"))); + if (!mir_tstrcmp(ptszType, _T("photo"))) { + JSONNODE *pPhoto = json_get(pAttach, "photo"); + if (pPhoto == NULL) + continue; + + res += GetVkPhotoItem(pPhoto); + } + else if (!mir_tstrcmp(ptszType, _T("audio"))) { + JSONNODE *pAudio = json_get(pAttach, "audio"); + if (pAudio == NULL) + continue; + + ptrT ptszArtist(json_as_string(json_get(pAudio, "artist"))); + ptrT ptszTitle(json_as_string(json_get(pAudio, "title"))); + ptrT ptszUrl(json_as_string(json_get(pAudio, "url"))); + res.AppendFormat(_T("%s: (%s - %s) - %s"), + TranslateT("Audio"), ptszArtist, ptszTitle, ptszUrl); + } + else if (!mir_tstrcmp(ptszType, _T("video"))) { + JSONNODE *pVideo = json_get(pAttach, "video"); + if (pVideo == NULL) + continue; + + ptrT ptszTitle(json_as_string(json_get(pVideo, "title"))); + int vid = json_as_int(json_get(pVideo, "id")); + int ownerID = json_as_int(json_get(pVideo, "owner_id")); + res.AppendFormat(_T("%s: %s - http://vk.com/video%d_%d"), TranslateT("Video"), ptszTitle, ownerID, vid); + } + else if (!mir_tstrcmp(ptszType, _T("doc"))) { + JSONNODE *pDoc = json_get(pAttach, "doc"); + if (pDoc == NULL) + continue; + + ptrT ptszTitle(json_as_string(json_get(pDoc, "title"))); + ptrT ptszUrl(json_as_string(json_get(pDoc, "url"))); + res.AppendFormat(_T("%s: (%s) - %s"), TranslateT("Document"), ptszTitle, ptszUrl); + } + else if (!mir_tstrcmp(ptszType, _T("wall"))) { + JSONNODE *pWall = json_get(pAttach, "wall"); + if (pWall == NULL) + continue; + + ptrT ptszText(json_as_string(json_get(pWall, "text"))); + int id = json_as_int(json_get(pWall, "id")); + int fromID = json_as_int(json_get(pWall, "from_id")); + res.AppendFormat(_T("%s: %s - http://vk.com/wall%d_%d"), TranslateT("Wall post"), ptszText ? ptszText : _T(" "), fromID, id); + } + else if (!mir_tstrcmp(ptszType, _T("sticker"))) { + JSONNODE *pSticker = json_get(pAttach, "sticker"); + if (pSticker == NULL) + continue; + res.Empty(); // sticker is not really an attachment, so we don't want all that heading info + + if (m_bStikersAsSmyles) { + int id = json_as_int(json_get(pSticker, "id")); + res.AppendFormat(_T("[sticker:%d]"), id); + } + else { + ptrT ptszLink; + for (int i = 0; i < SIZEOF(szImageTypes); i++) { + JSONNODE *n = json_get(pSticker, szImageTypes[i]); + if (n != NULL) { + ptszLink = json_as_string(n); + break; + } + } + res.AppendFormat(_T("%s"), ptszLink); + + if (m_iIMGBBCSupport) + res.AppendFormat(_T("[img]%s[/img]"), ptszLink); + } + } + else if (!mir_tstrcmp(ptszType, _T("link"))){ + JSONNODE *pLink = json_get(pAttach, "link"); + if (pLink == NULL) + continue; + + ptrT ptszUrl(json_as_string(json_get(pLink, "url"))); + ptrT ptszTitle(json_as_string(json_get(pLink, "title"))); + ptrT ptszDescription(json_as_string(json_get(pLink, "description"))); + CMString tszImage(json_as_string(json_get(pLink, "image_src"))); + + res.AppendFormat(_T("%s: %s (%s)"), TranslateT("Link"), ptszTitle ? ptszTitle : _T(""), ptszUrl ? ptszUrl : _T("")); + if (!tszImage.IsEmpty()) + if (m_iIMGBBCSupport) + res.AppendFormat(_T("\n\t%s: [img]%s[/img]"), TranslateT("Image"), tszImage.GetBuffer()); + else + res.AppendFormat(_T("\n\t%s: %s"), TranslateT("Image"), tszImage.GetBuffer()); + + if (ptszDescription) + res.AppendFormat(_T("\n\t%s"), ptszDescription); + } + else res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), ptszType); + + res.AppendChar('\n'); + } + + return res; +} + +CMString CVkProto::SetBBCString(TCHAR *tszString, VKBBCType bbcType, TCHAR *tszAddString) +{ + CVKBBCItem bbcItem[] = { + { vkbbcB, bbcNo, _T("%s") }, + { vkbbcB, bbcBasic, _T("[b]%s[/b]") }, + { vkbbcB, bbcAdvanced, _T("[b]%s[/b]") }, + { vkbbcI, bbcNo, _T("%s") }, + { vkbbcI, bbcBasic, _T("[i]%s[/i]") }, + { vkbbcI, bbcAdvanced, _T("[i]%s[/i]") }, + { vkbbcS, bbcNo, _T("%s") }, + { vkbbcS, bbcBasic, _T("[s]%s[/s]") }, + { vkbbcS, bbcAdvanced, _T("[s]%s[/s]") }, + { vkbbcU, bbcNo, _T("%s") }, + { vkbbcU, bbcBasic, _T("[u]%s[/u]") }, + { vkbbcU, bbcAdvanced, _T("[u]%s[/u]") }, + { vkbbcUrl, bbcNo, _T("%s (%s)") }, + { vkbbcUrl, bbcBasic, _T("[b]%s[/b] (%s)") }, + { vkbbcUrl, bbcAdvanced, _T("[url=%s]%s[/url]") }, + { vkbbcSize, bbcNo, _T("%s") }, + { vkbbcSize, bbcBasic, _T("%s") }, + { vkbbcSize, bbcAdvanced, _T("[size=%s]%s[/size]") }, + { vkbbcColor, bbcNo, _T("%s") }, + { vkbbcColor, bbcBasic, _T("%s") }, + { vkbbcColor, bbcAdvanced, _T("[color=%s]%s[/color]") }, + }; + + TCHAR *ptszFormat; + for (int i = 0; i < SIZEOF(bbcItem); i++) + if (bbcItem[i].vkBBCType == bbcType && bbcItem[i].vkBBCSettings == m_iBBCForNews){ + ptszFormat = bbcItem[i].ptszTempate; + break; + } + + CMString res; + + if (bbcType == vkbbcUrl && m_iBBCForNews != bbcAdvanced) + res.AppendFormat(ptszFormat, tszString ? tszString : _T(""), tszAddString ? tszAddString : _T("")); + else if (m_iBBCForNews == bbcAdvanced && bbcType >= vkbbcUrl) + res.AppendFormat(ptszFormat, tszAddString ? tszAddString : _T(""), tszString ? tszString : _T("")); + else + res.AppendFormat(ptszFormat, tszString ? tszString : _T("")); + + return res; } \ No newline at end of file diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 404ab529ec..5313811205 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -18,6 +18,7 @@ #define IDI_VISITPROFILE 115 #define IDI_HISTORY 116 #define IDI_BROADCAST 117 +#define IDD_OPT_VIEW 118 #define IDI_KEYS 203 #define IDC_LOGIN 1001 #define IDC_PASSWORD 1002 @@ -41,7 +42,6 @@ #define IDC_CLEAR_SERVER_HISTORY 1031 #define IDC_REMOVE_FROM_FRENDLIST 1032 #define IDC_REMOVE_FROM_CLIST 1033 -#define IDC_ADD_IMG_BBC 1034 #define IDC_FORCE_ONLINE_ON_ACT 1035 #define IDC_STICKERS_AS_SMYLES 1036 #define IDC_ONREAD 1039 @@ -61,21 +61,28 @@ #define IDC_SYNC_LAST3DAY 1053 #define IDC_NEWS_ENBL 1054 #define IDC_NOTIF_ENBL 1055 -#define IDC_BBC_NEWS 1056 #define IDC_ED_INT_NEWS 1057 #define IDC_SPIN_INT_NEWS 1058 #define IDC_ED_INT_NOTIF 1059 #define IDC_SPIN_INT_NOTIF 1060 #define IDC_SPEC_CONT_ENBL 1061 +#define IDC_IMG_OFF 1062 +#define IDC_IMG_FULLSIZE 1063 +#define IDC_IMG_130 1064 +#define IDC_IMG_604 1065 +#define IDC_NEWSBBC_OFF 1066 +#define IDC_NEWSBBC_BASIC 1067 +#define IDC_NEWSBBC_ADV 1068 +#define IDC_IEVIEW 1069 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 118 +#define _APS_NEXT_RESOURCE_VALUE 119 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1062 +#define _APS_NEXT_CONTROL_VALUE 1070 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 906031dc49..142a18f885 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 35 +#define __BUILD_NUM 36 #include diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 0c9e4b54f8..e4152d5ae5 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -17,8 +17,6 @@ along with this program. If not, see . #include "stdafx.h" -static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" }; - void CVkProto::AddFeedSpecialUser() { bool bSpecialContact = m_bNewsEnabled || m_bNotificationsEnabled || m_bSpecialContactAlwaysEnabled; @@ -128,35 +126,6 @@ void CVkProto::CreateVkUserInfoList(OBJLIST &vkUsers, JSONNODE *pRe } } -CMString CVkProto::GetVkPhotoItem(JSONNODE *pPhoto) -{ - CMString tszRes; - - if (pPhoto == NULL) - return tszRes; - - ptrT ptszLink; - for (int i = 0; i < SIZEOF(szImageTypes); i++) { - JSONNODE *n = json_get(pPhoto, szImageTypes[i]); - if (n != NULL) { - ptszLink = json_as_string(n); - break; - } - } - - int iWidth = json_as_int(json_get(pPhoto, "width")); - int iHeight = json_as_int(json_get(pPhoto, "height")); - - tszRes.AppendFormat(_T("%s: %s (%dx%d)"), TranslateT("Photo"), ptszLink ? ptszLink : _T(""), iWidth, iHeight); - if (m_bAddImgBbc) - tszRes.AppendFormat(_T("\n\t[img]%s[/img]"), ptszLink); - CMString tszText = json_as_string(json_get(pPhoto, "text")); - if (!tszText.IsEmpty()) - tszRes += "\n" + tszText; - - return tszRes; -} - ////////////////////////////////////////////////////////////////////////////////////////////////////////// CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST &vkUsers, bool isRepost) @@ -232,23 +201,22 @@ CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST &vkUs } CMString tszResFormat; - CMString tszBBCIn = m_bBBCOnNews ? _T("[b]") : _T(""); - CMString tszBBCOut = m_bBBCOnNews ? _T("[/b]") : _T(""); if (!isRepost) - tszResFormat = Translate("News from %s%s%s (%s)\n%s"); + tszResFormat = Translate("News from %s\n%s"); else { - tszResFormat = Translate("\tRepost from %s%s%s (%s)\n%s"); + tszResFormat = Translate("\tRepost from %s\n%s"); bPostLink = false; } - vkNewsItem->tszText.AppendFormat(tszResFormat, tszBBCIn.GetBuffer(), vkNewsItem->vkUser->m_tszUserNick.GetBuffer(), tszBBCOut.GetBuffer(), - vkNewsItem->vkUser->m_tszLink.GetBuffer(), tszText.GetBuffer()); + vkNewsItem->tszText.AppendFormat(tszResFormat, SetBBCString(vkNewsItem->vkUser->m_tszUserNick.GetBuffer(), vkbbcUrl, + vkNewsItem->vkUser->m_tszLink.GetBuffer()), tszText.GetBuffer()); vkNewsItem->tszId.AppendFormat(_T("%d_%d"), vkNewsItem->vkUser->m_UserId, iPostId); if (bPostLink) { vkNewsItem->tszLink = CMString(_T("https://vk.com/wall")) + vkNewsItem->tszId; - vkNewsItem->tszText.AppendFormat(TranslateT("\nNews link: %s"), vkNewsItem->tszLink.GetBuffer()); + vkNewsItem->tszText.AppendChar(_T('\n')); + vkNewsItem->tszText += SetBBCString(TranslateT("Link"), vkbbcUrl, vkNewsItem->tszLink.GetBuffer()); } debugLog(_T("CVkProto::GetVkNewsItem %d %d <%s> <%s>"), iSourceId, iPostId, vkNewsItem->tszText.GetBuffer(), tszText.GetBuffer()); @@ -265,19 +233,16 @@ CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, if (!pFeedback || !vkFeedbackType) return tszRes; - - CMString tszBBCIn = m_bBBCOnNews ? _T("[b]") : _T(""); - CMString tszBBCOut = m_bBBCOnNews ? _T("[/b]") : _T(""); CMString tszFormat; LONG iUserId = 0; if (vkFeedbackType == vkComment) { iUserId = json_as_int(json_get(pFeedback, "from_id")); - tszFormat = _T("%s%s%s (%s) %%s %%s\n%s"); + tszFormat = _T("%s %%s %%s\n%s"); } else if (vkFeedbackType == vkPost) { iUserId = json_as_int(json_get(pFeedback, "owner_id ")); - tszFormat = _T("%s%s%s (%s) %%s %%s\n%s"); + tszFormat = _T("%s %%s %%s\n%s"); } else if (vkFeedbackType == VKObjType::vkUsers || vkFeedbackType == vkCopy){ JSONNODE *pUsers = json_get(pFeedback, "items"), *pUserItem; @@ -290,7 +255,7 @@ CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, vkUser = GetVkUserInfo(iUserId, vkUsers); if (!tszUsers.IsEmpty()) tszUsers += _T(", "); - tszUsers.AppendFormat(_T("%s%s%s (%s)"), tszBBCIn.GetBuffer(), vkUser->m_tszUserNick.GetBuffer(), tszBBCOut.GetBuffer(), vkUser->m_tszLink.GetBuffer()); + tszUsers += SetBBCString(vkUser->m_tszUserNick.GetBuffer(), vkbbcUrl, vkUser->m_tszLink.GetBuffer()); } tszRes.AppendFormat(_T("%s %%s %%s"), tszUsers.GetBuffer()); vkUser = NULL; @@ -309,50 +274,50 @@ CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, tszText = tszName + _T(",") + tszBody; } - tszRes.AppendFormat(tszFormat, tszBBCIn.GetBuffer(), vkUser->m_tszUserNick.GetBuffer(), tszBBCOut.GetBuffer(), vkUser->m_tszLink.GetBuffer(), tszText.GetBuffer()); + tszRes.AppendFormat(tszFormat, SetBBCString(vkUser->m_tszUserNick.GetBuffer(), vkbbcUrl, vkUser->m_tszLink.GetBuffer()), tszText.GetBuffer()); } return tszRes; } -CMString CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType) +CMString CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TCHAR *ptszReply) { debugLogA("CVkProto::GetVkParent"); CMString tszRes; if (!pParent || !vkParentType) return tszRes; - - CMString tszBBCIn = m_bBBCOnNews ? _T("[b]") : _T(""); - CMString tszBBCOut = m_bBBCOnNews ? _T("[/b]") : _T(""); - + if (vkParentType == vkPhoto) { CMString tszPhoto = GetVkPhotoItem(pParent); LONG iOwnerId = json_as_int(json_get(pParent, "owner_id")); LONG iId = json_as_int(json_get(pParent, "id")); - CMString tszFormat = _T("\n%s\n%s%s%s: https://vk.com/photo%d_%d"); - tszRes.AppendFormat(tszFormat, tszPhoto.GetBuffer(), tszBBCIn.GetBuffer(), TranslateT("Link"), tszBBCOut.GetBuffer(), iOwnerId, iId); + + CMString tszLink; + tszLink.AppendFormat(_T("https://vk.com/photo%d_%d"), iOwnerId, iId); + tszRes.AppendFormat(_T("\n%s\n%s"), tszPhoto.GetBuffer(), SetBBCString(TranslateT("Link"), vkbbcUrl, tszLink.GetBuffer())); } else if (vkParentType == vkVideo) { LONG iOwnerId = json_as_int(json_get(pParent, "owner_id")); LONG iId = json_as_int(json_get(pParent, "id")); CMString tszTitle = json_as_string(json_get(pParent, "title")); - - CMString tszFormat = _T("\n%s%s%s\n%s%s%s: https://vk.com/video%d_%d"); - tszRes.AppendFormat(tszFormat, tszBBCIn.GetBuffer(), tszTitle.GetBuffer(), tszBBCOut.GetBuffer(), tszBBCIn.GetBuffer(), TranslateT("Link"), tszBBCOut.GetBuffer(), iOwnerId, iId); + CMString tszLink; + tszLink.AppendFormat(_T("https://vk.com/video%d_%d"), iOwnerId, iId); + tszRes.AppendFormat(_T("\n%s"), SetBBCString(tszTitle.GetBuffer(), vkbbcUrl, tszLink.GetBuffer())); } else if (vkParentType == vkPost) { LONG iOwnerId = json_as_int(json_get(pParent, "from_id")); LONG iId = json_as_int(json_get(pParent, "id")); - CMString tszFormat = _T("\n%s%s%s: https://vk.com/wall%d_%d"); - tszRes.AppendFormat(tszFormat, tszBBCIn.GetBuffer(), TranslateT("Link"), tszBBCOut.GetBuffer(), iOwnerId, iId); + CMString tszLink; + tszLink.AppendFormat(_T("https://vk.com/wall%d_%d%s"), iOwnerId, iId, ptszReply ? ptszReply : _T("")); + tszRes.AppendFormat(_T("\n%s"), SetBBCString(TranslateT("Link"), vkbbcUrl, tszLink.GetBuffer())); } else if (vkParentType == vkTopic) { LONG iOwnerId = json_as_int(json_get(pParent, "owner_id")); LONG iId = json_as_int(json_get(pParent, "id")); CMString tszTitle = json_as_string(json_get(pParent, "title")); - - CMString tszFormat = _T("%s%s%s\n%s%s%s: https://vk.com/topic%d_%d"); - tszRes.AppendFormat(tszFormat, tszBBCIn.GetBuffer(), tszTitle.GetBuffer(), tszBBCOut.GetBuffer(), tszBBCIn.GetBuffer(), TranslateT("Link"), tszBBCOut.GetBuffer(), iOwnerId, iId); + CMString tszLink; + tszLink.AppendFormat(_T("https://vk.com/topic%d_%d%s"), iOwnerId, iId, ptszReply ? ptszReply : _T("")); + tszRes.AppendFormat(_T("\n%s"), SetBBCString(tszTitle.GetBuffer(), vkbbcUrl, tszLink.GetBuffer())); } else if (vkParentType == vkComment) { JSONNODE *pNode = json_get(pParent, "photo"); @@ -367,15 +332,17 @@ CMString CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType) pNode = json_get(pParent, "post"); if (pNode){ - tszRes = GetVkParent(pNode, vkPost); - tszRes.AppendFormat(_T("?reply=%d"), iId); + CMString tszRepl; + tszRepl.AppendFormat(_T("?reply=%d"), iId); + tszRes = GetVkParent(pNode, vkPost, tszRepl.GetBuffer()); return tszRes; } pNode = json_get(pParent, "topic"); if (pNode){ - tszRes = GetVkParent(pNode, vkTopic); - tszRes.AppendFormat(_T("?reply=%d"), iId); + CMString tszRepl; + tszRepl.AppendFormat(_T("?reply=%d"), iId); + tszRes = GetVkParent(pNode, vkTopic, tszRepl.GetBuffer()); return tszRes; } } diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index a6f4aa46b0..e601164676 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -244,8 +244,6 @@ INT_PTR CALLBACK CVkProto::OptionsAdvProc(HWND hwndDlg, UINT uMsg, WPARAM wParam CheckDlgButton(hwndDlg, IDC_HIDECHATS, ppro->m_bHideChats ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_MESASUREAD, ppro->m_bMesAsUnread ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_ADD_IMG_BBC, ppro->m_bAddImgBbc ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_STICKERS_AS_SMYLES, ppro->m_bStikersAsSmyles ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_FORCE_ONLINE_ON_ACT, ppro->m_bUserForceOnlineOnActivity ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_REPORT_ABUSE, ppro->m_bReportAbuse ? BST_CHECKED : BST_UNCHECKED); @@ -264,9 +262,7 @@ INT_PTR CALLBACK CVkProto::OptionsAdvProc(HWND hwndDlg, UINT uMsg, WPARAM wParam switch (LOWORD(wParam)) { case IDC_HIDECHATS: case IDC_MESASUREAD: - case IDC_ADD_IMG_BBC: case IDC_FORCE_ONLINE_ON_ACT: - case IDC_STICKERS_AS_SMYLES: case IDC_REPORT_ABUSE: case IDC_CLEAR_SERVER_HISTORY: case IDC_REMOVE_FROM_FRENDLIST: @@ -289,11 +285,8 @@ INT_PTR CALLBACK CVkProto::OptionsAdvProc(HWND hwndDlg, UINT uMsg, WPARAM wParam ppro->m_bMesAsUnread = IsDlgButtonChecked(hwndDlg, IDC_MESASUREAD) == BST_CHECKED; ppro->setByte("MesAsUnread", ppro->m_bMesAsUnread); - ppro->m_bAddImgBbc = IsDlgButtonChecked(hwndDlg, IDC_ADD_IMG_BBC) == BST_CHECKED; - ppro->setByte("AddImgBbc", ppro->m_bAddImgBbc); - ppro->m_bStikersAsSmyles = IsDlgButtonChecked(hwndDlg, IDC_STICKERS_AS_SMYLES) == BST_CHECKED; - ppro->setByte("StikersAsSmyles", ppro->m_bStikersAsSmyles); + ppro->m_bUserForceOnlineOnActivity = IsDlgButtonChecked(hwndDlg, IDC_FORCE_ONLINE_ON_ACT) == BST_CHECKED; ppro->setByte("UserForceOnlineOnActivity", ppro->m_bUserForceOnlineOnActivity); @@ -355,7 +348,6 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar CheckDlgButton(hwndDlg, IDC_NEWS_ENBL, ppro->m_bNewsEnabled ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_NOTIF_ENBL, ppro->m_bNotificationsEnabled ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SPEC_CONT_ENBL, ppro->m_bSpecialContactAlwaysEnabled ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_BBC_NEWS, ppro->m_bBBCOnNews ? BST_CHECKED : BST_UNCHECKED); SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NEWS, UDM_SETRANGE, 0, MAKELONG(60*24, 1)); SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NEWS, UDM_SETPOS, 0, ppro->m_iNewsInterval); @@ -376,7 +368,6 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar case IDC_NEWS_ENBL: case IDC_NOTIF_ENBL: case IDC_SPEC_CONT_ENBL: - case IDC_BBC_NEWS: if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -397,9 +388,6 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar ppro->m_bSpecialContactAlwaysEnabled = IsDlgButtonChecked(hwndDlg, IDC_SPEC_CONT_ENBL) == BST_CHECKED; ppro->setByte("SpecialContactAlwaysEnabled", ppro->m_bSpecialContactAlwaysEnabled); - ppro->m_bBBCOnNews = IsDlgButtonChecked(hwndDlg, IDC_BBC_NEWS) == BST_CHECKED; - ppro->setByte("BBCOnNews", ppro->m_bBBCOnNews); - TCHAR buffer[5] = { 0 }; GetDlgItemText(hwndDlg, IDC_ED_INT_NEWS, buffer, SIZEOF(buffer)); ppro->setDword("NewsInterval", ppro->m_iNewsInterval = _ttoi(buffer)); @@ -423,6 +411,87 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar return FALSE; } +INT_PTR CALLBACK CVkProto::OptionsViewProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + + ppro = (CVkProto*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon, 1)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon)); + + CheckDlgButton(hwndDlg, IDC_IMG_OFF, (ppro->m_iIMGBBCSupport == imgNo) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_IMG_FULLSIZE, (ppro->m_iIMGBBCSupport == imgFullSize) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_IMG_130, (ppro->m_iIMGBBCSupport == imgPreview130) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_IMG_604, (ppro->m_iIMGBBCSupport == imgPreview604) ? BST_CHECKED : BST_UNCHECKED); + + CheckDlgButton(hwndDlg, IDC_NEWSBBC_OFF, (ppro->m_iBBCForNews == bbcNo) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_NEWSBBC_BASIC, (ppro->m_iBBCForNews == bbcBasic) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_NEWSBBC_ADV, (ppro->m_iBBCForNews == bbcAdvanced) ? BST_CHECKED : BST_UNCHECKED); + + CheckDlgButton(hwndDlg, IDC_STICKERS_AS_SMYLES, ppro->m_bStikersAsSmyles ? BST_CHECKED : BST_UNCHECKED); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_IMG_OFF: + case IDC_IMG_FULLSIZE: + case IDC_IMG_130: + case IDC_IMG_604: + case IDC_NEWSBBC_OFF: + case IDC_NEWSBBC_BASIC: + case IDC_NEWSBBC_ADV: + case IDC_STICKERS_AS_SMYLES: + if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == PSN_APPLY) { + if (IsDlgButtonChecked(hwndDlg, IDC_IMG_OFF) == BST_CHECKED) + ppro->m_iIMGBBCSupport = imgNo; + if (IsDlgButtonChecked(hwndDlg, IDC_IMG_FULLSIZE) == BST_CHECKED) + ppro->m_iIMGBBCSupport = imgFullSize; + if (IsDlgButtonChecked(hwndDlg, IDC_IMG_130) == BST_CHECKED) + ppro->m_iIMGBBCSupport = imgPreview130; + if (IsDlgButtonChecked(hwndDlg, IDC_IMG_604) == BST_CHECKED) + ppro->m_iIMGBBCSupport = imgPreview604; + ppro->setByte("IMGBBCSupport", ppro->m_iIMGBBCSupport); + + if (IsDlgButtonChecked(hwndDlg, IDC_NEWSBBC_OFF) == BST_CHECKED) + ppro->m_iBBCForNews = bbcNo; + if (IsDlgButtonChecked(hwndDlg, IDC_NEWSBBC_BASIC) == BST_CHECKED) + ppro->m_iBBCForNews = bbcBasic; + if (IsDlgButtonChecked(hwndDlg, IDC_NEWSBBC_ADV) == BST_CHECKED) + ppro->m_iBBCForNews = bbcAdvanced; + ppro->setByte("BBCForNews", ppro->m_iBBCForNews); + + ppro->m_bStikersAsSmyles = IsDlgButtonChecked(hwndDlg, IDC_STICKERS_AS_SMYLES) == BST_CHECKED; + ppro->setByte("StikersAsSmyles", ppro->m_bStikersAsSmyles); + } + break; + + case WM_CLOSE: + EndDialog(hwndDlg, 0); + break; + + case WM_DESTROY: + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_BIG, 0)); + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0)); + break; + } + + return FALSE; +} + int CVkProto::OnOptionsInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { sizeof(odp) }; @@ -449,5 +518,11 @@ int CVkProto::OnOptionsInit(WPARAM wParam, LPARAM) odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FEEDS); odp.pfnDlgProc = &CVkProto::OptionsFeedsProc; Options_AddPage(wParam, &odp); + + odp.ptszTab = LPGENT("View settings"); + odp.position = 4; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_VIEW); + odp.pfnDlgProc = &CVkProto::OptionsViewProc; + Options_AddPage(wParam, &odp); return 0; } diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 8362f77d23..ef47adc411 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -70,7 +70,6 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : m_bRemoveFromClist = getBool("RemoveFromClistOnBanUser", false); m_bPopUpSyncHistory = getBool("PopUpSyncHistory", false); m_iMarkMessageReadOn = getByte("MarkMessageReadOn", 0); - m_bAddImgBbc = getBool("AddImgBbc", false); m_bStikersAsSmyles = getBool("StikersAsSmyles", false); m_bUserForceOnlineOnActivity = getBool("UserForceOnlineOnActivity", false); m_iMusicSendMetod = getByte("MusicSendMetod", sendBroadcastOnly); @@ -81,9 +80,10 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : m_bNewsEnabled = getBool("NewsEnabled", false); m_bNotificationsEnabled = getBool("NotificationsEnabled", false); m_bSpecialContactAlwaysEnabled = getBool("SpecialContactAlwaysEnabled", false); - m_bBBCOnNews = getBool("BBCOnNews", false); m_iNewsInterval = getDword("NewsInterval", 15); m_iNotificationsInterval = getDword("NotificationsInterval", 1); + m_iIMGBBCSupport = getByte("IMGBBCSupport", 0); + m_iBBCForNews = getByte("BBCForNews", 0); // Set all contacts offline -- in case we crashed SetAllContactStatuses(ID_STATUS_OFFLINE); diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 757026b2b8..5592662f32 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -181,7 +181,7 @@ struct CVkUserInfo : public MZeroedObject { enum VKObjType { vkNull, vkPost, vkPhoto, vkVideo, vkComment, vkTopic, vkUsers, vkCopy }; -struct CVkNotification { +struct CVKNotification { TCHAR *ptszType; VKObjType vkParent, vkFeedback; TCHAR *ptszTranslate; @@ -206,6 +206,16 @@ struct CVKNewsItem : public MZeroedObject { bool bIsRepost; }; +enum VKBBCType { vkbbcB, vkbbcI, vkbbcS, vkbbcU, vkbbcUrl, vkbbcSize, vkbbcColor }; +enum BBCForNewsSupport { bbcNo, bbcBasic, bbcAdvanced }; + +struct CVKBBCItem { + VKBBCType vkBBCType; + BBCForNewsSupport vkBBCSettings; + TCHAR *ptszTempate; +}; + + struct TFakeAckParams { __inline TFakeAckParams(MCONTACT _hContact, int _msgid) : @@ -277,8 +287,7 @@ struct CVkProto : public PROTO void OnOAuthAuthorize(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - + //==== Services ====================================================================== INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM); @@ -314,7 +323,7 @@ struct CVkProto : public PROTO void InitPopups(void); void MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR *szTitle, bool err = false); - //==== Hooks ====+==================================================================== + //==== Hooks ========================================================================= int __cdecl OnProcessSrmmEvent(WPARAM, LPARAM); int __cdecl OnDbEventRead(WPARAM, LPARAM); @@ -349,7 +358,7 @@ struct CVkProto : public PROTO CMString GetVkNotificationsItem(JSONNODE *pItem, OBJLIST &vkUsers, time_t &tDate); CMString GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, OBJLIST &vkUsers, CVkUserInfo *vkUser); - CMString GetVkParent(JSONNODE *pParent, VKObjType vkParentType); + CMString GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TCHAR *ptszReply = NULL); void RetrieveUnreadNews(time_t tLastNewsTime); void OnReceiveUnreadNews(NETLIBHTTPREQUEST*, AsyncHttpRequest*); @@ -360,11 +369,41 @@ struct CVkProto : public PROTO INT_PTR __cdecl SvcLoadVKNews(WPARAM, LPARAM); - CMString SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent); - //==== Misc ========================================================================== TCHAR* GetUserStoredPassword(void); + void SetAllContactStatuses(int status); + + MCONTACT FindUser(LONG userid, bool bCreate = false); + MCONTACT FindChat(LONG dwUserid); + + bool CheckMid(int guid); + + JSONNODE* CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT&); + bool CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE*); + void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + + bool AutoFillForm(char*, CMStringA&, CMStringA&); + + void GrabCookies(NETLIBHTTPREQUEST *nhr); + void ApplyCookies(AsyncHttpRequest*); + + void DBAddAuthRequest(const MCONTACT hContact); + MCONTACT MContactFromDbEvent(HANDLE hDbEvent); + + void SetMirVer(MCONTACT hContact, int platform); + + void __cdecl ContactTypingThread(void *p); + void SetSrmmReadStatus(MCONTACT hContact); + + char* GetStickerId(const char* Msg, int& stickerid); + + CMString SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent); + CMString SetBBCString(TCHAR *tszString, VKBBCType, TCHAR *tszAddString = NULL); + + CMString GetAttachmentDescr(JSONNODE*); + + //==================================================================================== void RetrieveStatusMsg(const CMString &StatusMsg); void RetrieveStatusMusic(const CMString &StatusMsg); @@ -386,7 +425,7 @@ struct CVkProto : public PROTO void RetrieveUnreadMessages(); void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveDlgs(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - CMString GetAttachmentDescr(JSONNODE*); + void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*); @@ -404,8 +443,6 @@ struct CVkProto : public PROTO void OnReceiveAuthRequest(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveDeleteFriend(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void DBAddAuthRequest(const MCONTACT hContact); - MCONTACT MContactFromDbEvent(HANDLE hDbEvent); void SetServerStatus(int); @@ -417,11 +454,6 @@ struct CVkProto : public PROTO __forceinline LPCTSTR getGroup() const { return m_defaultGroup; } __forceinline void setGroup(LPCTSTR grp) { m_defaultGroup = mir_tstrdup(grp); } - void SetMirVer(MCONTACT hContact, int platform); - void SetSrmmReadStatus(MCONTACT hContact); - void __cdecl ContactTypingThread(void *p); - char* GetStickerId(const char* Msg, int& stickerid); - static UINT_PTR m_timer; private: @@ -477,10 +509,9 @@ private: CMStringA m_name, m_value, m_domain; }; - OBJLIST m_cookies; - void GrabCookies(NETLIBHTTPREQUEST *nhr); - void ApplyCookies(AsyncHttpRequest*); + OBJLIST m_cookies; + void InitQueue(); void UninitQueue(); void ExecuteRequest(AsyncHttpRequest*); @@ -489,10 +520,6 @@ private: AsyncHttpRequest* Push(AsyncHttpRequest*, int iTimeout = 10000); bool RunCaptchaForm(LPCSTR szUrl, CMStringA&); - bool AutoFillForm(char*, CMStringA&, CMStringA&); - - bool CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE*); - JSONNODE* CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT&); bool ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE*); void ConnectionFailed(int iReason); @@ -504,13 +531,11 @@ private: void GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen); void ReloadAvatarInfo(MCONTACT hContact); - MCONTACT FindUser(LONG userid, bool bCreate = false); - MCONTACT FindChat(LONG dwUserid); - - void SetAllContactStatuses(int status); - void __cdecl SendMsgAck(void *param); + //============== Options ============================================================= + + bool m_prevError, m_bOnline, m_bHideChats, @@ -521,25 +546,27 @@ private: m_bRemoveFromFrendlist, m_bRemoveFromClist, m_bPopUpSyncHistory, - m_bAddImgBbc, m_bStikersAsSmyles, m_bUserForceOnlineOnActivity, m_bNewsEnabled, m_bNotificationsEnabled, - m_bSpecialContactAlwaysEnabled, - m_bBBCOnNews; + m_bSpecialContactAlwaysEnabled; int m_iNewsInterval, m_iNotificationsInterval; - enum MarkMsgReadOn{ markOnRead, markOnReceive, markOnReply, markOnTyping }; - int m_iMarkMessageReadOn; + enum MarkMsgReadOn { markOnRead, markOnReceive, markOnReply, markOnTyping }; + int m_iMarkMessageReadOn; - enum SyncHistoryMetod{ syncOff, syncAuto, sync1Days, sync3Days }; + enum SyncHistoryMetod { syncOff, syncAuto, sync1Days, sync3Days }; int m_iSyncHistoryMetod; - enum MusicSendMetod{ sendNone, sendStatusOnly, sendBroadcastOnly, sendBroadcastAndStatus }; + enum MusicSendMetod { sendNone, sendStatusOnly, sendBroadcastOnly, sendBroadcastAndStatus }; int m_iMusicSendMetod; + enum IMGBBCSypport { imgNo, imgFullSize, imgPreview130, imgPreview604 }; + int m_iIMGBBCSupport; + int m_iBBCForNews; + LONG m_myUserId; ptrT m_defaultGroup; @@ -558,11 +585,11 @@ private: ULONG m_msgId; LIST m_sendIds; - bool CheckMid(int guid); static INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK OptionsAdvProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK OptionsViewProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); OBJLIST m_chats; CVkChatInfo* AppendChat(int id, JSONNODE *pNode); diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index e92e85914d..4d1aa375f3 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -20,7 +20,6 @@ along with this program. If not, see . UINT_PTR CVkProto::m_timer; char szBlankUrl[] = "http://api.vk.com/blank.html"; -static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" }; static char VK_TOKEN_BEG[] = "access_token="; static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, online, status, about, domain"; @@ -1249,128 +1248,4 @@ INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// - -CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) -{ - debugLogA("CVkProto::GetAttachmentDescr"); - CMString res; - res.AppendChar('\n'); - res += TranslateT("Attachments:"); - res.AppendChar('\n'); - JSONNODE *pAttach; - for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) { - res.AppendChar('\t'); - ptrT ptszType(json_as_string(json_get(pAttach, "type"))); - if (!mir_tstrcmp(ptszType, _T("photo"))) { - JSONNODE *pPhoto = json_get(pAttach, "photo"); - if (pPhoto == NULL) - continue; - - ptrT ptszLink; - for (int i = 0; i < SIZEOF(szImageTypes); i++) { - JSONNODE *n = json_get(pPhoto, szImageTypes[i]); - if (n != NULL) { - ptszLink = json_as_string(n); - break; - } - } - - int iWidth = json_as_int(json_get(pPhoto, "width")); - int iHeight = json_as_int(json_get(pPhoto, "height")); - res.AppendFormat(_T("%s: %s (%dx%d)"), TranslateT("Photo"), ptszLink ? ptszLink : _T(""), iWidth, iHeight); - if (m_bAddImgBbc) - res.AppendFormat(_T("\n\t[img]%s[/img]"), ptszLink); - } - else if (!mir_tstrcmp(ptszType, _T("audio"))) { - JSONNODE *pAudio = json_get(pAttach, "audio"); - if (pAudio == NULL) - continue; - - ptrT ptszArtist(json_as_string(json_get(pAudio, "artist"))); - ptrT ptszTitle(json_as_string(json_get(pAudio, "title"))); - ptrT ptszUrl(json_as_string(json_get(pAudio, "url"))); - res.AppendFormat(_T("%s: (%s - %s) - %s"), - TranslateT("Audio"), ptszArtist, ptszTitle, ptszUrl); - } - else if (!mir_tstrcmp(ptszType, _T("video"))) { - JSONNODE *pVideo = json_get(pAttach, "video"); - if (pVideo == NULL) - continue; - - ptrT ptszTitle(json_as_string(json_get(pVideo, "title"))); - int vid = json_as_int(json_get(pVideo, "id")); - int ownerID = json_as_int(json_get(pVideo, "owner_id")); - res.AppendFormat(_T("%s: %s - http://vk.com/video%d_%d"), TranslateT("Video"), ptszTitle, ownerID, vid); - } - else if (!mir_tstrcmp(ptszType, _T("doc"))) { - JSONNODE *pDoc = json_get(pAttach, "doc"); - if (pDoc == NULL) - continue; - ptrT ptszTitle(json_as_string(json_get(pDoc, "title"))); - ptrT ptszUrl(json_as_string(json_get(pDoc, "url"))); - res.AppendFormat(_T("%s: (%s) - %s"), TranslateT("Document"), ptszTitle, ptszUrl); - } - else if (!mir_tstrcmp(ptszType, _T("wall"))) { - JSONNODE *pWall = json_get(pAttach, "wall"); - if (pWall == NULL) - continue; - - ptrT ptszText(json_as_string(json_get(pWall, "text"))); - int id = json_as_int(json_get(pWall, "id")); - int fromID = json_as_int(json_get(pWall, "from_id")); - res.AppendFormat(_T("%s: %s - http://vk.com/wall%d_%d"), TranslateT("Wall post"), ptszText ? ptszText : _T(" "), fromID, id); - } - else if (!mir_tstrcmp(ptszType, _T("sticker"))) { - JSONNODE *pSticker = json_get(pAttach, "sticker"); - if (pSticker == NULL) - continue; - res.Empty(); // sticker is not really an attachment, so we don't want all that heading info - - if (m_bStikersAsSmyles) { - int id = json_as_int(json_get(pSticker, "id")); - res.AppendFormat(_T("[sticker:%d]"), id); - } - else { - ptrT ptszLink; - for (int i = 0; i < SIZEOF(szImageTypes); i++) { - JSONNODE *n = json_get(pSticker, szImageTypes[i]); - if (n != NULL) { - ptszLink = json_as_string(n); - break; - } - } - res.AppendFormat(_T("%s"), ptszLink); - - if (m_bAddImgBbc) - res.AppendFormat(_T("[img]%s[/img]"), ptszLink); - } - } - else if (!mir_tstrcmp(ptszType, _T("link"))){ - JSONNODE *pLink = json_get(pAttach, "link"); - if (pLink == NULL) - continue; - - ptrT ptszUrl(json_as_string(json_get(pLink, "url"))); - ptrT ptszTitle(json_as_string(json_get(pLink, "title"))); - ptrT ptszDescription(json_as_string(json_get(pLink, "description"))); - CMString tszImage(json_as_string(json_get(pLink, "image_src"))); - - res.AppendFormat(_T("%s: %s (%s)"), TranslateT("Link"), ptszTitle ? ptszTitle : _T(""), ptszUrl ? ptszUrl : _T("")); - if (!tszImage.IsEmpty()) - if (m_bAddImgBbc) - res.AppendFormat(_T("\n\t%s: [img]%s[/img]"), TranslateT("Image"), tszImage.GetBuffer()); - else - res.AppendFormat(_T("\n\t%s: %s"), TranslateT("Image"), tszImage.GetBuffer()); - - if (ptszDescription) - res.AppendFormat(_T("\n\t%s"), ptszDescription); - } - else res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), ptszType); - - res.AppendChar('\n'); - } - - return res; -} -- cgit v1.2.3