From a6203909a9b4bfbae252ab5b7c616309119d84b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 13 Dec 2012 09:00:44 +0000 Subject: FacebookRM: Experimental and buggy support for custom smileys git-svn-id: http://svn.miranda-ng.org/main/trunk@2734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/res/facebook.rc | 4 ++- protocols/FacebookRM/src/common.h | 1 + protocols/FacebookRM/src/constants.h | 1 + protocols/FacebookRM/src/contacts.cpp | 14 ++++++++++ protocols/FacebookRM/src/db.h | 1 + protocols/FacebookRM/src/dialogs.cpp | 2 ++ protocols/FacebookRM/src/messages.cpp | 52 +++++++++++++++++++++++++++++++++++ protocols/FacebookRM/src/process.cpp | 5 ++++ protocols/FacebookRM/src/proto.h | 2 ++ protocols/FacebookRM/src/resource.h | 1 + protocols/FacebookRM/src/utils.cpp | 20 +++++++++++++- protocols/FacebookRM/src/utils.h | 2 +- 12 files changed, 102 insertions(+), 3 deletions(-) diff --git a/protocols/FacebookRM/res/facebook.rc b/protocols/FacebookRM/res/facebook.rc index d5690adac5..3811d707fe 100644 --- a/protocols/FacebookRM/res/facebook.rc +++ b/protocols/FacebookRM/res/facebook.rc @@ -156,7 +156,7 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - GROUPBOX "Advanced Settings",IDC_STATIC,7,7,291,93 + GROUPBOX "Advanced Settings",IDC_STATIC,7,7,291,104 CONTROL "Force secure (HTTPS) connection",IDC_SECURE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,32,267,10 CONTROL "Post Miranda statuses to Wall",IDC_SET_STATUS,"Button",BS_AUTOCHECKBOX | BS_TOP | WS_TABSTOP,17,56,267,10 CONTROL "Enable logging for debugging purposes",IDC_LOGGING, @@ -167,6 +167,8 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,68,267,10 CONTROL "Map non-standard statuses to Invisible (instead of Online)",IDC_MAP_STATUSES, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,81,267,10 + CONTROL "Enable support for Custom smileys (EXPERIMENTAL + BUGGY!)",IDC_CUSTOM_SMILEYS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,95,267,10 END diff --git a/protocols/FacebookRM/src/common.h b/protocols/FacebookRM/src/common.h index aa2c0aaaa3..eefa387364 100644 --- a/protocols/FacebookRM/src/common.h +++ b/protocols/FacebookRM/src/common.h @@ -80,6 +80,7 @@ along with this program. If not, see . #include #include #include +#include #include "version.h" diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index c160596abd..d7b870fe43 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -62,6 +62,7 @@ along with this program. If not, see . #define DEFAULT_DISCONNECT_CHAT 0 #define DEFAULT_MAP_STATUSES 0 #define DEFAULT_LOAD_MOBILE 0 +#define DEFAULT_CUSTOM_SMILEYS 0 #define DEFAULT_EVENT_NOTIFICATIONS_ENABLE 1 #define DEFAULT_EVENT_FEEDS_ENABLE 1 diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index aea08663fb..8ef306dbf3 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -154,6 +154,20 @@ void FacebookProto::SetAllContactStatuses(int status, bool reset_client) DBWriteContactSettingTString(hContact,m_szModuleName,"MirVer", _T(FACEBOOK_NAME)); DBFreeVariant(&dbv); } + + + std::tstring foldername = GetAvatarFolder() + L"\\smileys\\"; + TCHAR *path = _tcsdup(foldername.c_str()); + + if (DBGetContactSettingByte(NULL,m_szModuleName,FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = hContact; + cont.type = 0; + cont.path = path; + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + mir_free(path); + } } if (DBGetContactSettingWord(hContact,m_szModuleName,"Status",ID_STATUS_OFFLINE) != status) diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index 1cdcf8143b..a9979a7ea1 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -60,6 +60,7 @@ along with this program. If not, see . #define FACEBOOK_KEY_DISCONNECT_CHAT "DisconnectChatEnable" #define FACEBOOK_KEY_MAP_STATUSES "MapStatuses" #define FACEBOOK_KEY_LOAD_MOBILE "LoadMobile" +#define FACEBOOK_KEY_CUSTOM_SMILEYS "CustomSmileys" #define FACEBOOK_KEY_POLL_RATE "PollRate" // [HIDDEN] #define FACEBOOK_KEY_TIMEOUTS_LIMIT "TimeoutsLimit" // [HIDDEN] diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index b9c6d6ac6a..0f7db03273 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -303,6 +303,7 @@ INT_PTR CALLBACK FBOptionsAdvancedProc( HWND hwnd, UINT message, WPARAM wparam, LoadDBCheckState(proto, hwnd, IDC_SET_STATUS, FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS); LoadDBCheckState(proto, hwnd, IDC_LOGGING, FACEBOOK_KEY_LOGGING_ENABLE, DEFAULT_LOGGING_ENABLE); LoadDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES); + LoadDBCheckState(proto, hwnd, IDC_CUSTOM_SMILEYS, FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS); EnableWindow(GetDlgItem(hwnd, IDC_SECURE_CHANNEL), IsDlgButtonChecked(hwnd, IDC_SECURE)); @@ -330,6 +331,7 @@ INT_PTR CALLBACK FBOptionsAdvancedProc( HWND hwnd, UINT message, WPARAM wparam, StoreDBCheckState(proto, hwnd, IDC_SECURE_CHANNEL, FACEBOOK_KEY_FORCE_HTTPS_CHANNEL); StoreDBCheckState(proto, hwnd, IDC_DISCONNECT_CHAT, FACEBOOK_KEY_DISCONNECT_CHAT); StoreDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES); + StoreDBCheckState(proto, hwnd, IDC_CUSTOM_SMILEYS, FACEBOOK_KEY_CUSTOM_SMILEYS); BOOL setStatus = IsDlgButtonChecked(hwnd, IDC_SET_STATUS); BOOL setStatusOld = DBGetContactSettingByte(NULL, proto->m_szModuleName, FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS); diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index fb86195c58..d1bd01df6f 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -54,6 +54,8 @@ void FacebookProto::SendMsgWorker(void *p) } else if ( !DBGetContactSettingString(data->hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) { + //parseSmileys(data->msg, data->hContact); + int retries = 5; std::string error_text = ""; bool result = false; @@ -180,3 +182,53 @@ void FacebookProto::MessagingWorker(void *p) delete data; } + +void FacebookProto::parseSmileys(std::string message, HANDLE hContact) +{ + if (!DBGetContactSettingByte(NULL,m_szModuleName,FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) + return; + + HANDLE nlc = NULL; + std::string::size_type pos = 0; + bool anything = false; + while ((pos = message.find("[[", pos)) != std::string::npos) { + std::string::size_type pos2 = message.find("]]", pos); + if (pos2 == std::string::npos) + break; + + std::string smiley = message.substr(pos, pos2+2-pos); + pos = pos2; + + std::string url = "http://graph.facebook.com/%s/picture"; + utils::text::replace_first(&url, "%s", smiley.substr(2, smiley.length()-4)); + + + size_t slen = smiley.length(); + size_t rlen = Netlib_GetBase64EncodedBufferSize(slen); + char* buf = (char*)mir_alloc(rlen); + + NETLIBBASE64 nlb = { buf, (int)rlen, (PBYTE)smiley.c_str(), (int)slen }; + CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb)); + + std::string b64 = buf; + b64 = utils::url::encode(b64); + + std::tstring filename = GetAvatarFolder() + L"\\smileys\\" + (TCHAR*)_A2T(b64.c_str()) + _T(".jpg"); + FILE *f = _tfopen(filename.c_str(), _T("r")); + if (!f) { + facy.save_url(url, filename, nlc); + + TCHAR *path = _tcsdup(filename.c_str()); + + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = hContact; + cont.type = 1; + cont.path = path; + + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + mir_free(path); + } else + fclose(f); + } +} \ No newline at end of file diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 9d19c6ddcc..75d1c05dda 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -390,11 +390,14 @@ void FacebookProto::ProcessUnreadMessages( void* ) } std::string message_text = messagesgroup.substr(pos3, messagesgroup.find( "<\\/div", pos3 ) + 6 - pos3); + LOG("Got unread message: \"%s\"", message_text.c_str()); message_text = utils::text::source_get_value( &message_text, 2, "\\\">", "<\\/div" ); message_text = utils::text::trim( utils::text::special_expressions_decode( utils::text::remove_html( message_text )) ); + parseSmileys(message_text, hContact); + if (!message_attachments.empty()) { if (!message_text.empty()) message_text += "\r\n\r\n"; @@ -454,6 +457,8 @@ void FacebookProto::ProcessMessages( void* data ) // TODO: if contact is newly added, get his user info // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages? + parseSmileys(messages[i]->message_text, hContact); + PROTORECVEVENT recv = {0}; recv.flags = PREF_UTF; recv.szMessage = const_cast(messages[i]->message_text.c_str()); diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 6f2d8ed057..09cb8fb6ea 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -184,6 +184,7 @@ public: bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url); void CheckAvatarChange(HANDLE hContact, std::string image_url); void ToggleStatusMenuItems( BOOL bEnable ); + void parseSmileys(std::string message, HANDLE hContact); // Handles, Locks HGENMENU m_hMenuRoot; @@ -200,6 +201,7 @@ public: std::string last_status_msg_; std::tstring def_avatar_folder_; HANDLE hAvatarFolder_; + HANDLE hSmileysFolder_; std::vector avatar_queue; static void CALLBACK APC_callback(ULONG_PTR p); diff --git a/protocols/FacebookRM/src/resource.h b/protocols/FacebookRM/src/resource.h index dae487ee80..5e1fa69790 100644 --- a/protocols/FacebookRM/src/resource.h +++ b/protocols/FacebookRM/src/resource.h @@ -26,6 +26,7 @@ #define IDC_BIGGER_AVATARS 1030 #define IDC_MAP_STATUSES 1032 #define IDC_LOAD_MOBILE 1033 +#define IDC_CUSTOM_SMILEYS 1034 #define IDC_NOTIFICATIONS_ENABLE 1041 #define IDC_FEEDS_ENABLE 1042 #define IDC_OTHER_ENABLE 1043 diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp index 999cb69c56..c3948f67b2 100644 --- a/protocols/FacebookRM/src/utils.cpp +++ b/protocols/FacebookRM/src/utils.cpp @@ -134,7 +134,7 @@ unsigned int utils::text::count_all(std::string* data, std::string term) return count; } -void utils::text::append_ordinal(unsigned int value, std::string* data) +void utils::text::append_ordinal(unsigned long value, std::string* data) { if (value >= 128 && value <= 2047) { // U+0080 .. U+07FF @@ -198,6 +198,24 @@ std::string utils::text::special_expressions_decode(std::string data) continue; } + if (data.at(i) == -19 && (i+2) < data.length()) { + std::string chs = data.substr(i, i+2).c_str(); + unsigned char a[4] = {0}; + memcpy(&a[1], chs.c_str(), 3); + + new_string += "\\u"; + utils::text::append_ordinal((unsigned long)a, &new_string); + + /*u = reinterpret_cast(data.at(i+1)); + utils::text::append_ordinal(u, &new_string); + + u = reinterpret_cast(data.at(i+2)); + utils::text::append_ordinal(u, &new_string);*/ + + i += 2; + continue; + } + new_string += data.at(i); } diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h index b9cb11a369..49006cfd90 100644 --- a/protocols/FacebookRM/src/utils.h +++ b/protocols/FacebookRM/src/utils.h @@ -93,7 +93,7 @@ namespace utils std::string source_get_value(std::string* data, unsigned int argument_count, ...); std::string source_get_value2(std::string* data, const char *term, const char *endings); void explode(std::string str, std::string separator, std::vector* results); - void append_ordinal(unsigned int value, std::string* data); + void append_ordinal(unsigned long value, std::string* data); }; namespace conversion -- cgit v1.2.3