summaryrefslogtreecommitdiff
path: root/protocols/Twitter/src/proto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Twitter/src/proto.cpp')
-rw-r--r--protocols/Twitter/src/proto.cpp96
1 files changed, 47 insertions, 49 deletions
diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp
index c35be99ad1..1a6996192c 100644
--- a/protocols/Twitter/src/proto.cpp
+++ b/protocols/Twitter/src/proto.cpp
@@ -17,29 +17,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
-#include "proto.h"
-#include "utility.h"
#include "theme.h"
#include "ui.h"
static volatile LONG g_msgid = 1;
-TwitterProto::TwitterProto(const char *proto_name, const wchar_t *username) :
- PROTO<TwitterProto>(proto_name, username),
- m_szChatId(mir_utf8encodeW(username))
+CTwitterProto::CTwitterProto(const char *proto_name, const wchar_t *username) :
+ PROTO<CTwitterProto>(proto_name, username),
+ m_szChatId(mir_utf8encodeW(username)),
+ m_szBaseUrl("https://api.twitter.com/")
{
- CreateProtoService(PS_CREATEACCMGRUI, &TwitterProto::SvcCreateAccMgrUI);
+ CreateProtoService(PS_CREATEACCMGRUI, &CTwitterProto::SvcCreateAccMgrUI);
- CreateProtoService(PS_JOINCHAT, &TwitterProto::OnJoinChat);
- CreateProtoService(PS_LEAVECHAT, &TwitterProto::OnLeaveChat);
+ CreateProtoService(PS_JOINCHAT, &CTwitterProto::OnJoinChat);
+ CreateProtoService(PS_LEAVECHAT, &CTwitterProto::OnLeaveChat);
- CreateProtoService(PS_GETMYAVATAR, &TwitterProto::GetAvatar);
- CreateProtoService(PS_SETMYAVATAR, &TwitterProto::SetAvatar);
+ CreateProtoService(PS_GETMYAVATAR, &CTwitterProto::GetAvatar);
+ CreateProtoService(PS_SETMYAVATAR, &CTwitterProto::SetAvatar);
- HookProtoEvent(ME_OPT_INITIALISE, &TwitterProto::OnOptionsInit);
- HookProtoEvent(ME_DB_CONTACT_DELETED, &TwitterProto::OnContactDeleted);
- HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &TwitterProto::OnBuildStatusMenu);
+ HookProtoEvent(ME_OPT_INITIALISE, &CTwitterProto::OnOptionsInit);
+ HookProtoEvent(ME_DB_CONTACT_DELETED, &CTwitterProto::OnContactDeleted);
+ HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &CTwitterProto::OnBuildStatusMenu);
// Initialize hotkeys
char text[512];
@@ -82,16 +81,14 @@ TwitterProto::TwitterProto(const char *proto_name, const wchar_t *username) :
MessageBox(nullptr, error, L"Miranda NG", MB_OK | MB_ICONERROR);
}
- twit_.set_handle(this, m_hNetlibUser);
-
db_set_resident(m_szModuleName, "Homepage");
for (auto &it : AccContacts())
setString(it, "Homepage", "https://twitter.com/" + getMStringA(it, TWITTER_KEY_UN));
}
-TwitterProto::~TwitterProto()
+CTwitterProto::~CTwitterProto()
{
- twit_.Disconnect();
+ Disconnect();
if (hAvatarNetlib_)
Netlib_CloseHandle(hAvatarNetlib_);
@@ -99,7 +96,7 @@ TwitterProto::~TwitterProto()
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR TwitterProto::GetCaps(int type, MCONTACT)
+INT_PTR CTwitterProto::GetCaps(int type, MCONTACT)
{
switch (type) {
case PFLAGNUM_1:
@@ -121,27 +118,28 @@ INT_PTR TwitterProto::GetCaps(int type, MCONTACT)
/////////////////////////////////////////////////////////////////////////////////////////
-struct send_direct
+struct TSendDirect
{
- __inline send_direct(MCONTACT _hContact, const std::string &_msg, int _msgid) :
+ __inline TSendDirect(MCONTACT _hContact, const CMStringA &_msg, int _msgid) :
hContact(_hContact), msg(_msg), msgid(_msgid)
{}
MCONTACT hContact;
- std::string msg;
+ CMStringA msg;
int msgid;
};
-void TwitterProto::SendSuccess(void *p)
+void CTwitterProto::SendSuccess(void *p)
{
if (p == nullptr)
return;
- send_direct *data = static_cast<send_direct*>(p);
+
+ auto *data = (TSendDirect*)p;
DBVARIANT dbv;
if (!db_get_s(data->hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
mir_cslock s(twitter_lock_);
- twit_.send_direct(dbv.pszVal, data->msg);
+ send_direct(dbv.pszVal, data->msg);
ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0);
db_free(&dbv);
@@ -150,19 +148,19 @@ void TwitterProto::SendSuccess(void *p)
delete data;
}
-int TwitterProto::SendMsg(MCONTACT hContact, int, const char *msg)
+int CTwitterProto::SendMsg(MCONTACT hContact, int, const char *msg)
{
if (m_iStatus != ID_STATUS_ONLINE)
return 0;
int seq = InterlockedIncrement(&g_msgid);
- ForkThread(&TwitterProto::SendSuccess, new send_direct(hContact, msg, seq));
+ ForkThread(&CTwitterProto::SendSuccess, new TSendDirect(hContact, msg, seq));
return seq;
}
/////////////////////////////////////////////////////////////////////////////////////////
-int TwitterProto::SetStatus(int new_status)
+int CTwitterProto::SetStatus(int new_status)
{
int old_status = m_iStatus;
if (new_status == m_iStatus)
@@ -172,7 +170,7 @@ int TwitterProto::SetStatus(int new_status)
// 40072 - 40078 are the "online" statuses, basically every status except offline. see statusmodes.h
if (new_status >= 40072 && new_status <= 40078) {
- m_iDesiredStatus = ID_STATUS_ONLINE; //i think i have to set this so it forces the twitter proto to be online (and not away, DND, etc)
+ m_iDesiredStatus = ID_STATUS_ONLINE; //i think i have to set this so it forces the CTwitterProto proto to be online (and not away, DND, etc)
// if we're already connecting and they want to go online, BAIL! we're already trying to connect you dumbass
if (old_status == ID_STATUS_CONNECTING)
@@ -187,10 +185,10 @@ int TwitterProto::SetStatus(int new_status)
// ok.. here i think we're telling the core that this protocol something.. but why?
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- ForkThread(&TwitterProto::SignOn, this);
+ ForkThread(&CTwitterProto::SignOn, this);
}
else if (new_status == ID_STATUS_OFFLINE) {
- twit_.Disconnect();
+ Disconnect();
m_iStatus = m_iDesiredStatus;
setAllContactStatuses(ID_STATUS_OFFLINE);
SetChatStatus(ID_STATUS_OFFLINE);
@@ -203,12 +201,12 @@ int TwitterProto::SetStatus(int new_status)
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR TwitterProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam)
+INT_PTR CTwitterProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam)
{
return (INT_PTR)CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TWITTERACCOUNT), (HWND)lParam, first_run_dialog, (LPARAM)this);
}
-INT_PTR TwitterProto::ReplyToTweet(WPARAM wParam, LPARAM)
+INT_PTR CTwitterProto::ReplyToTweet(WPARAM wParam, LPARAM)
{
MCONTACT hContact = (MCONTACT) wParam;
// TODO: support replying to tweets instead of just users
@@ -225,7 +223,7 @@ INT_PTR TwitterProto::ReplyToTweet(WPARAM wParam, LPARAM)
return 0;
}
-INT_PTR TwitterProto::VisitHomepage(WPARAM hContact, LPARAM)
+INT_PTR CTwitterProto::VisitHomepage(WPARAM hContact, LPARAM)
{
Utils_OpenUrl(getMStringA(MCONTACT(hContact), "Homepage"));
return 0;
@@ -233,7 +231,7 @@ INT_PTR TwitterProto::VisitHomepage(WPARAM hContact, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-int TwitterProto::OnBuildStatusMenu(WPARAM, LPARAM)
+int CTwitterProto::OnBuildStatusMenu(WPARAM, LPARAM)
{
CMenuItem mi(&g_plugin);
mi.root = Menu_GetProtocolRoot(this);
@@ -244,7 +242,7 @@ int TwitterProto::OnBuildStatusMenu(WPARAM, LPARAM)
// TODO: Disable this menu item when offline
// "Send Tweet..."
mi.pszService = "/Tweet";
- CreateProtoService(mi.pszService, &TwitterProto::OnTweet);
+ CreateProtoService(mi.pszService, &CTwitterProto::OnTweet);
mi.name.w = LPGENW("Send Tweet...");
mi.position = 200001;
mi.hIcolibItem = GetIconHandle("tweet");
@@ -252,7 +250,7 @@ int TwitterProto::OnBuildStatusMenu(WPARAM, LPARAM)
return 0;
}
-int TwitterProto::OnOptionsInit(WPARAM wParam, LPARAM)
+int CTwitterProto::OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 271828;
@@ -273,7 +271,7 @@ int TwitterProto::OnOptionsInit(WPARAM wParam, LPARAM)
return 0;
}
-INT_PTR TwitterProto::OnTweet(WPARAM, LPARAM)
+INT_PTR CTwitterProto::OnTweet(WPARAM, LPARAM)
{
if (m_iStatus != ID_STATUS_ONLINE)
return 1;
@@ -283,7 +281,7 @@ INT_PTR TwitterProto::OnTweet(WPARAM, LPARAM)
return 0;
}
-void TwitterProto::OnModulesLoaded()
+void CTwitterProto::OnModulesLoaded()
{
GCREGISTER gcr = {};
gcr.pszModule = m_szModuleName;
@@ -302,7 +300,7 @@ void TwitterProto::OnModulesLoaded()
SetChatStatus(ID_STATUS_OFFLINE);
}
-int TwitterProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
+int CTwitterProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
{
MCONTACT hContact = (MCONTACT) wParam;
if (IsMyContact(hContact))
@@ -311,14 +309,14 @@ int TwitterProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
return 0;
}
-int TwitterProto::ShowPinDialog()
+int CTwitterProto::ShowPinDialog()
{
HWND hDlg = (HWND)DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TWITTERPIN), nullptr, pin_proc, reinterpret_cast<LPARAM>(this));
ShowWindow(hDlg, SW_SHOW);
return 0;
}
-void TwitterProto::ShowPopup(const wchar_t *text, int Error)
+void CTwitterProto::ShowPopup(const wchar_t *text, int Error)
{
POPUPDATAW popup = {};
mir_snwprintf(popup.lpwzContactName, TranslateT("%s Protocol"), m_tszUserName);
@@ -332,11 +330,11 @@ void TwitterProto::ShowPopup(const wchar_t *text, int Error)
PUAddPopupW(&popup);
}
-void TwitterProto::ShowPopup(const char *text, int Error)
+void CTwitterProto::ShowPopup(const char *text, int Error)
{
POPUPDATAW popup = {};
mir_snwprintf(popup.lpwzContactName, TranslateT("%s Protocol"), m_tszUserName);
- mbcs_to_tcs(CP_UTF8, text, popup.lpwzText, _countof(popup.lpwzText));
+ wcsncpy_s(popup.lpwzText, Utf2T(text), _TRUNCATE);
if (Error) {
popup.iSeconds = -1;
popup.colorBack = 0x000000FF;
@@ -349,7 +347,7 @@ void TwitterProto::ShowPopup(const char *text, int Error)
// TODO: the more I think about it, the more I think all twit.* methods should
// be in MessageLoop
-void TwitterProto::SendTweetWorker(void *p)
+void CTwitterProto::SendTweetWorker(void *p)
{
if (p == nullptr)
return;
@@ -363,12 +361,12 @@ void TwitterProto::SendTweetWorker(void *p)
}
mir_cslock s(twitter_lock_);
- twit_.set_status(text);
+ set_status(text);
mir_free(text);
}
-void TwitterProto::UpdateSettings()
+void CTwitterProto::UpdateSettings()
{
if (getByte(TWITTER_KEY_CHATFEED)) {
if (!in_chat_)
@@ -387,19 +385,19 @@ void TwitterProto::UpdateSettings()
}
}
-std::wstring TwitterProto::GetAvatarFolder()
+CMStringW CTwitterProto::GetAvatarFolder()
{
wchar_t path[MAX_PATH];
mir_snwprintf(path, L"%s\\%s", VARSW(L"%miranda_avatarcache%").get(), m_tszUserName);
return path;
}
-INT_PTR TwitterProto::GetAvatar(WPARAM, LPARAM)
+INT_PTR CTwitterProto::GetAvatar(WPARAM, LPARAM)
{
return 0;
}
-INT_PTR TwitterProto::SetAvatar(WPARAM, LPARAM)
+INT_PTR CTwitterProto::SetAvatar(WPARAM, LPARAM)
{
return 0;
}