summaryrefslogtreecommitdiff
path: root/plugins/NewAwaySysMod/src/Client.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-02-20 20:21:34 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-02-20 20:21:34 +0000
commitf9ac6bc30beec86994091fa144dc3a569cd4a843 (patch)
tree97108f0d771971dddc60cc98e64603d7f5645ebe /plugins/NewAwaySysMod/src/Client.cpp
parentae9f3725b8dfa376cf66f346429ec78d1e4ab748 (diff)
- standardized version resource;
- unused header file removed from project; - code cleaning; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@8198 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewAwaySysMod/src/Client.cpp')
-rw-r--r--plugins/NewAwaySysMod/src/Client.cpp133
1 files changed, 51 insertions, 82 deletions
diff --git a/plugins/NewAwaySysMod/src/Client.cpp b/plugins/NewAwaySysMod/src/Client.cpp
index 9d8c520f7c..23e71972a1 100644
--- a/plugins/NewAwaySysMod/src/Client.cpp
+++ b/plugins/NewAwaySysMod/src/Client.cpp
@@ -33,26 +33,19 @@ void __cdecl UpdateMsgsThreadProc(void *)
int ProtoCount;
PROTOCOLDESCRIPTOR **proto;
CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&ProtoCount, (LPARAM)&proto);
- int I;
- while (WaitForSingleObject(g_hTerminateUpdateMsgsThread, 0) == WAIT_TIMEOUT && !Miranda_Terminated())
- {
+ while (WaitForSingleObject(g_hTerminateUpdateMsgsThread, 0) == WAIT_TIMEOUT && !Miranda_Terminated()) {
DWORD MinUpdateTimeDifference = g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_UPDATEMSGSPERIOD) * 1000; // in milliseconds
- for (I = 0; I < ProtoCount; I++)
- {
- if (proto[I]->type == PROTOTYPE_PROTOCOL && CallProtoService(proto[I]->szName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND && !IsAnICQProto(proto[I]->szName))
- {
- int Status = CallProtoService(proto[I]->szName, PS_GETSTATUS, 0, 0);
- if (Status < ID_STATUS_OFFLINE || Status > ID_STATUS_OUTTOLUNCH)
- {
- Status = g_ProtoStates[proto[I]->szName].Status;
+ for (int i = 0; i < ProtoCount; i++) {
+ if (proto[i]->type == PROTOTYPE_PROTOCOL && CallProtoService(proto[i]->szName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND && !IsAnICQProto(proto[i]->szName)) {
+ int Status = CallProtoService(proto[i]->szName, PS_GETSTATUS, 0, 0);
+ if (Status < ID_STATUS_OFFLINE || Status > ID_STATUS_OUTTOLUNCH) {
+ Status = g_ProtoStates[proto[i]->szName].Status;
}
- if (CallProtoService(proto[I]->szName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(Status) && g_ProtoStates[proto[I]->szName].CurStatusMsg.GetUpdateTimeDifference() >= MinUpdateTimeDifference)
- {
- TCString CurMsg(GetDynamicStatMsg(INVALID_CONTACT_ID, proto[I]->szName));
- if ((TCString)g_ProtoStates[proto[I]->szName].CurStatusMsg != (const TCHAR*)CurMsg) // if the message has changed
- {
- g_ProtoStates[proto[I]->szName].CurStatusMsg = CurMsg;
- CallAllowedPS_SETAWAYMSG(proto[I]->szName, Status, (char*)_T2A(CurMsg));
+ if (CallProtoService(proto[i]->szName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(Status) && g_ProtoStates[proto[i]->szName].CurStatusMsg.GetUpdateTimeDifference() >= MinUpdateTimeDifference) {
+ TCString CurMsg(GetDynamicStatMsg(INVALID_CONTACT_ID, proto[i]->szName));
+ if ((TCString)g_ProtoStates[proto[i]->szName].CurStatusMsg != (const TCHAR*)CurMsg) { // if the message has changed
+ g_ProtoStates[proto[i]->szName].CurStatusMsg = CurMsg;
+ CallAllowedPS_SETAWAYMSG(proto[i]->szName, Status, (char*)_T2A(CurMsg));
}
}
}
@@ -61,26 +54,23 @@ void __cdecl UpdateMsgsThreadProc(void *)
}
}
-
static void __stdcall DummyAPCFunc(ULONG_PTR)
{
return;
}
-
void InitUpdateMsgs()
{
int UpdateMsgs = g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_UPDATEMSGS);
- if (g_hUpdateMsgsThread && !UpdateMsgs)
- {
+ if (g_hUpdateMsgsThread && !UpdateMsgs) {
_ASSERT(WaitForSingleObject(g_hUpdateMsgsThread, 0) == WAIT_TIMEOUT);
SetEvent(g_hTerminateUpdateMsgsThread);
QueueUserAPC(DummyAPCFunc, g_hUpdateMsgsThread, 0); // wake up the thread, as it's most probably in SleepEx() now
WaitForSingleObject(g_hUpdateMsgsThread, INFINITE);
g_hUpdateMsgsThread = NULL;
CloseHandle(g_hTerminateUpdateMsgsThread);
- } else if (!g_hUpdateMsgsThread && UpdateMsgs)
- {
+ }
+ else if (!g_hUpdateMsgsThread && UpdateMsgs) {
g_hTerminateUpdateMsgsThread = CreateEvent(NULL, TRUE, FALSE, NULL);
g_hUpdateMsgsThread = (HANDLE)mir_forkthread(UpdateMsgsThreadProc, NULL);
}
@@ -90,33 +80,28 @@ void InitUpdateMsgs()
void ChangeProtoMessages(char* szProto, int iMode, TCString &Msg)
{
TCString CurMsg(Msg);
- if (szProto)
- {
+ if (szProto) {
if (Msg == NULL)
- {
CurMsg = GetDynamicStatMsg(INVALID_CONTACT_ID, szProto);
- }
+
CallAllowedPS_SETAWAYMSG(szProto, iMode, (char*)_T2A(CurMsg));
g_ProtoStates[szProto].CurStatusMsg = CurMsg;
- } else // change message of all protocols
- {
+ }
+ else { // change message of all protocols
int ProtoCount;
PROTOCOLDESCRIPTOR **proto;
CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&ProtoCount, (LPARAM)&proto);
- int I;
- for (I = 0; I < ProtoCount; I++)
- {
- if (proto[I]->type == PROTOTYPE_PROTOCOL && !db_get_b(NULL, proto[I]->szName, "LockMainStatus", 0))
- {
+ for (int i = 0; i < ProtoCount; i++) {
+ if (proto[i]->type == PROTOTYPE_PROTOCOL && !db_get_b(NULL, proto[i]->szName, "LockMainStatus", 0)) {
if (Msg == NULL)
- {
- CurMsg = GetDynamicStatMsg(INVALID_CONTACT_ID, proto[I]->szName);
- }
- CallAllowedPS_SETAWAYMSG(proto[I]->szName, iMode, (char*)_T2A(CurMsg));
- g_ProtoStates[proto[I]->szName].CurStatusMsg = CurMsg;
+ CurMsg = GetDynamicStatMsg(INVALID_CONTACT_ID, proto[i]->szName);
+
+ CallAllowedPS_SETAWAYMSG(proto[i]->szName, iMode, (char*)_T2A(CurMsg));
+ g_ProtoStates[proto[i]->szName].CurStatusMsg = CurMsg;
}
}
}
+
static struct
{
int Status;
@@ -134,49 +119,39 @@ void ChangeProtoMessages(char* szProto, int iMode, TCString &Msg)
ID_STATUS_OUTTOLUNCH, "Otl",
ID_STATUS_IDLE, "Idl"
};
- int I;
- for (I = 0; I < lengthof(StatusSettings); I++)
- {
- if (iMode == StatusSettings[I].Status)
- {
- db_set_ts(NULL, "SRAway", CString(StatusSettings[I].Setting) + "Msg", CurMsg);
- db_set_ts(NULL, "SRAway", CString(StatusSettings[I].Setting) + "Default", CurMsg); // TODO: make it more accurate, and change not only here, but when changing status messages through UpdateMsgsTimerFunc too; and when changing messages through AutoAway() ?
+
+ for (int i = 0; i < SIZEOF(StatusSettings); i++) {
+ if (iMode == StatusSettings[i].Status) {
+ db_set_ts(NULL, "SRAway", CString(StatusSettings[i].Setting) + "Msg", CurMsg);
+ db_set_ts(NULL, "SRAway", CString(StatusSettings[i].Setting) + "Default", CurMsg); // TODO: make it more accurate, and change not only here, but when changing status messages through UpdateMsgsTimerFunc too; and when changing messages through AutoAway() ?
break;
}
}
-// InitUpdateMsgs();
+ // InitUpdateMsgs();
}
int GetRecentGroupID(int iMode)
{ // returns an ID of a group where recent messages are stored, accordingly to current settings and status mode.
// -1 if the group is not found
-// COptPage MoreOptData(g_MoreOptPage);
+ // COptPage MoreOptData(g_MoreOptPage);
COptPage MsgTreeData(g_MsgTreePage);
COptItem_TreeCtrl *TreeCtrl = (COptItem_TreeCtrl*)MsgTreeData.Find(IDV_MSGTREE);
TreeCtrl->DBToMem(CString(MOD_NAME));
- int Order;
- if (g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_PERSTATUSMRM))
- {
- for (Order = 0; Order < TreeCtrl->Value.GetSize(); Order++) // find a group named accordingly to the current status
- {
- if (TreeCtrl->Value[Order].ParentID == g_Messages_RecentRootID && TreeCtrl->Value[Order].Flags & TIF_GROUP && !_tcsicmp(TreeCtrl->Value[Order].Title, iMode ? (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iMode, GSMDF_TCHAR) : MSGTREE_RECENT_OTHERGROUP))
- {
- return TreeCtrl->Value[Order].ID;
- }
- }
- } else // simply use Recent Messages category
- {
+
+ if (!g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_PERSTATUSMRM))
return g_Messages_RecentRootID;
- }
+
+ for (int Order = 0; Order < TreeCtrl->Value.GetSize(); Order++) // find a group named accordingly to the current status
+ if (TreeCtrl->Value[Order].ParentID == g_Messages_RecentRootID && TreeCtrl->Value[Order].Flags & TIF_GROUP && !_tcsicmp(TreeCtrl->Value[Order].Title, iMode ? (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iMode, GSMDF_TCHAR) : MSGTREE_RECENT_OTHERGROUP))
+ return TreeCtrl->Value[Order].ID;
+
return -1;
}
-
int ICQStatusToGeneralStatus(int bICQStat)
{
- switch (bICQStat)
- {
+ switch (bICQStat) {
case MTYPE_AUTOONLINE: return ID_STATUS_ONLINE;
case MTYPE_AUTOAWAY: return ID_STATUS_AWAY;
case MTYPE_AUTONA: return ID_STATUS_NA;
@@ -187,11 +162,9 @@ int ICQStatusToGeneralStatus(int bICQStat)
}
}
-
TCString VariablesEscape(TCString Str)
{
- if (!Str.GetLen())
- {
+ if (!Str.GetLen()) {
return _T("");
}
enum eState
@@ -201,31 +174,27 @@ TCString VariablesEscape(TCString Str)
eState State = ST_QUOTE;
TCString Result(_T("`"));
const TCHAR *p = Str;
- while (*p)
- {
- if (*p == '`')
- {
- if (State == ST_TEXT)
- {
+ while (*p) {
+ if (*p == '`') {
+ if (State == ST_TEXT) {
Result += _T("````");
State = ST_QUOTE;
- } else
- {
+ }
+ else {
Result += _T("``");
}
- } else
- {
+ }
+ else {
Result += *p;
State = ST_TEXT;
}
p++;
}
- if (State == ST_QUOTE)
- {
+ if (State == ST_QUOTE) {
Result.GetBuffer()[Result.GetLen() - 1] = '\0';
Result.ReleaseBuffer();
- } else
- {
+ }
+ else {
Result += '`';
}
return Result;