INT_PTR NudgeSend(WPARAM hContact, LPARAM lParam) { char *protoName = GetContactProto(hContact); int diff = time(NULL) - db_get_dw(hContact, "Nudge", "LastSent", time(NULL) - 30); if (diff < GlobalNudge.sendTimeSec) { TCHAR msg[500]; mir_sntprintf(msg, TranslateT("You are not allowed to send too much nudge (only 1 each %d sec, %d sec left)"), GlobalNudge.sendTimeSec, 30 - diff); if (GlobalNudge.useByProtocol) { for (int i = 0; i < arNudges.getCount(); i++) { CNudgeElement &p = arNudges[i]; if (!mir_strcmp(protoName, p.ProtocolName)) Nudge_ShowPopup(&p, hContact, msg); } } else Nudge_ShowPopup(&DefaultNudge, hContact, msg); return 0; } db_set_dw(hContact, "Nudge", "LastSent", time(NULL)); if (GlobalNudge.useByProtocol) { for (int i = 0; i < arNudges.getCount(); i++) { CNudgeElement &p = arNudges[i]; if (!mir_strcmp(protoName, p.ProtocolName)) if (p.showStatus) Nudge_SentStatus(&p, hContact); } } else if (DefaultNudge.showStatus) Nudge_SentStatus(&DefaultNudge, hContact); CallProtoService(protoName, PS_SEND_NUDGE, hContact, lParam); return 0; }
void CJabberDlgDataPage::Layout() { RECT rc; GetClientRect(m_hwnd, &rc); int w = rc.right - 20; int x = 10; int y = 10; m_height = rc.bottom; m_scrollPos = GetScrollPos(m_hwnd, SB_VERT); HDWP hdwp = BeginDeferWindowPos(m_controls.getCount()); for (int i = 0; i < m_controls.getCount(); ++i) if (int h = m_controls[i].Layout(hdwp, x, y - m_scrollPos, w)) y += h + 5; EndDeferWindowPos(hdwp); m_dataHeight = y + 5; SCROLLINFO si = {0}; si.cbSize = sizeof(si); si.fMask = SIF_DISABLENOSCROLL|SIF_PAGE|SIF_RANGE; si.nPage = m_height; si.nMin = 0; si.nMax = m_dataHeight; SetScrollInfo(m_hwnd, SB_VERT, &si, TRUE); }
LRESULT CALLBACK APCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_NULL: while (APCCallQueue.getCount()) { APCCall tmpCall; WaitForSingleObject(hApcMutex, INFINITE); if (APCCallQueue.getCount()) { tmpCall = APCCallQueue[0]; APCCallQueue.remove(0); } ReleaseMutex(hApcMutex); if (tmpCall.func) tmpCall.func(tmpCall.param); } SleepEx(0, TRUE); // process APCs created by plugins that do not use core service break; case WM_TIMECHANGE: RecalculateTime(); break; } return DefWindowProc(hwnd,msg,wParam,lParam); }
void __cdecl SmileyDownloadThread(void*) { bool needext = false; HANDLE hHttpDwnl = NULL; WaitForSingleObject(g_hDlMutex, 3000); while (!Miranda_Terminated() && dlQueue.getCount()) { ReleaseMutex(g_hDlMutex); if (_taccess(dlQueue[0].fname.c_str(), 0) != 0) { InternetDownloadFile(T2A_SM(dlQueue[0].url.c_str()), T2A_SM(dlQueue[0].fname.c_str()), hHttpDwnl); WaitForSingleObject(g_hDlMutex, 3000); CMString fname(dlQueue[0].fname); if (dlQueue[0].needext) { fname += GetImageExt(fname); needext = true; } _trename(dlQueue[0].fname.c_str(), fname.c_str()); } else WaitForSingleObject(g_hDlMutex, 3000); dlQueue.remove(0); } dlQueue.destroy(); if (hHttpDwnl) Netlib_CloseHandle(hHttpDwnl); threadRunning = false; ReleaseMutex(g_hDlMutex); if (!Miranda_Terminated()) { if (needext) CallServiceSync(MS_SMILEYADD_RELOAD, 0, 0); else NotifyEventHooks(hEvent1, 0, 0); } }
void RecalculateTime(void) { GetTimeZoneInformation(&myInfo.myTZ.tzi); myInfo.timestamp = time(NULL); myInfo.myTZ.offset = INT_MIN; bool found = false; DYNAMIC_TIME_ZONE_INFORMATION dtzi; if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) { TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName); _tcsncpy_s(myInfo.myTZ.tszName, myTzKey, _TRUNCATE); mir_free(myTzKey); found = true; } for (int i = 0; i < g_timezones.getCount(); i++) { MIM_TIMEZONE &tz = g_timezones[i]; if (tz.offset != INT_MIN) tz.offset = INT_MIN; if (!found) { if (!mir_wstrcmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || !mir_wstrcmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) { _tcsncpy_s(myInfo.myTZ.tszName, tz.tszName, _TRUNCATE); found = true; } } } }
// преобразует mode в HICON который НЕ НУЖНО разрушать в конце static ICON_CACHE& getCacheItem(int mode, int type) { int m = mode & 0x0f, s = (mode & SECURED)>>4, i; // разобрали на части - режим и состояние HICON icon; for (i=0; i < arIcoList.getCount(); i++) if (arIcoList[i].mode == ((type<<8) | mode)) return arIcoList[i]; i = s; switch(type) { case 1: i += IEC_CL_DIS; break; case 2: i += ICO_CM_DIS; break; case 3: i += ICO_MW_DIS; break; } if (type == 1) icon = BindOverlayIcon(g_hIEC[i], g_hICO[ICO_OV_NAT+m]); else icon = BindOverlayIcon(g_hICO[i], g_hICO[ICO_OV_NAT+m]); ICON_CACHE *p = new ICON_CACHE; p->icon = icon; p->mode = (type << 8) | mode; p->hCLIcon = NULL; arIcoList.insert(p); return *p; }
static INT_PTR VoiceUnregister(WPARAM wParam, LPARAM lParam) { char *moduleName = (char *) wParam; if (moduleName == NULL || moduleName[0] == 0) return -1; VoiceProvider *module = FindModule(moduleName); if (module == NULL) return -2; for(int i = calls.getCount() - 1; i >= 0; --i) { VoiceCall *call = &calls[i]; if (call->module == module) { call->Drop(); call->SetState(VOICE_STATE_ENDED); calls.remove(i); } } modules.remove(module); if (hwnd_frame != NULL) PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); return 0; }
static void RemoveProtoIconIndex(PROTOACCOUNT *pa) { for (int i = 0; i < protoIconIndex.getCount(); i++) if (mir_strcmp(protoIconIndex[i].szProto, pa->szModuleName) == 0) { protoIconIndex.remove(i); break; } }
static void RemoveVoiceCall(const char *szModule, const char *id) { for(int i = calls.getCount() - 1; i >= 0; --i) { if (IsCall(&calls[i], szModule, id)) calls.remove(i); } }
VoiceProvider * FindModule(const char *szModule) { for(int i = 0; i < modules.getCount(); i++) if (strcmp(modules[i].name, szModule) == 0) return &modules[i]; return NULL; }
static void AddMethodsFrom(OBJLIST<CallingMethod> *list, HANDLE hContact, const TCHAR *number) { for(int i = 0; i < modules.getCount(); i++) { VoiceProvider *provider = &modules[i]; if (provider->CanCall(number)) list->insert(new CallingMethod(provider, hContact, number)); } }
void xpt_OnWM_THEMECHANGED() { xptlock(); { for (int i=0; i < xptObjectList.getCount(); i++) _sttXptReloadThemeData(&xptObjectList[i]); } xptunlock(); }
void RefreshContactListIcons(void) { for (int i=0; i < arIcoList.getCount(); i++) arIcoList[i].hCLIcon = 0; for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (isSecureProtocol(hContact)) ShowStatusIcon(hContact); }
static void QueueRemove(MCONTACT hContact) { mir_cslock lck(cs); for (int i = queue.getCount() - 1; i >= 0; i--) { QueueItem& item = queue[i]; if (item.hContact == hContact) queue.remove(i); } }
bool CanCall(HANDLE hContact, BOOL now) { for(int i = 0; i < modules.getCount(); i++) { if (modules[i].CanCall(hContact, now)) return true; } return false; }
bool CanCall(const TCHAR *number) { for(int i = 0; i < modules.getCount(); i++) { if (modules[i].CanCall(number)) return true; } return false; }
bool CanCallNumber() { for(int i = 0; i < modules.getCount(); i++) { if (modules[i].flags & VOICE_CAPS_CALL_STRING) return true; } return false; }
VoiceCall * FindVoiceCall(HANDLE hContact) { for(int i = 0; i < calls.getCount(); i++) { if (calls[i].state != VOICE_STATE_ENDED && calls[i].hContact == hContact) { return &calls[i]; } } return NULL; }
XmlNode *CJabberDlgDataPage::FetchData() { XmlNode *result = new XmlNode("x"); result->addAttr("xmlns", JABBER_FEAT_DATA_FORMS); result->addAttr("type", "submit"); for (int i = 0; i < m_controls.getCount(); ++i) if (XmlNode *field = m_controls[i].FetchData()) result->addChild(field); return result; }
// Helper functions static WhatsAppProto* GetInstanceByHContact(MCONTACT hContact) { char *proto = GetContactProto(hContact); if (!proto) return 0; for (int i = 0; i < g_Instances.getCount(); i++) if (!mir_strcmp(proto, g_Instances[i].m_szModuleName)) return &g_Instances[i]; return 0; }
VoiceCall * GetTalkingCall() { for(int i = 0; i < calls.getCount(); ++i) { VoiceCall *call = &calls[i]; if (call->state == VOICE_STATE_TALKING) return call; } return NULL; }
static void RequestThread(void *vParam) { while (!g_shutDown) { EnterCriticalSection(&cs); if (queue.getCount() == 0) { // No items, so suspend thread LeaveCriticalSection(&cs); mir_sleep(POOL_DELAY); continue; } // Take a look at first item QueueItem& qi = queue[queue.getCount() - 1]; if (qi.check_time > GetTickCount()) { // Not time to request yet, wait... LeaveCriticalSection(&cs); mir_sleep(POOL_DELAY); continue; } // Will request this item MCONTACT hContact = qi.hContact; queue.remove(queue.getCount() - 1); QueueRemove(hContact); LeaveCriticalSection(&cs); if (FetchAvatarFor(hContact) == GAIR_WAITFOR) { // Mark to not request this contact avatar for more 30 min { mir_cslock lock(cs); QueueRemove(hContact); QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME); } // Wait a little until requesting again mir_sleep(REQUEST_DELAY); } } }
static int CListIconsChanged(WPARAM, LPARAM) { for (int i = 0; i < _countof(statusModeList); i++) ImageList_ReplaceIcon_IconLibLoaded(hCListImages, i + 1, Skin_LoadIcon(skinIconStatusList[i])); ImageList_ReplaceIcon_IconLibLoaded(hCListImages, IMAGE_GROUPOPEN, Skin_LoadIcon(SKINICON_OTHER_GROUPOPEN)); ImageList_ReplaceIcon_IconLibLoaded(hCListImages, IMAGE_GROUPSHUT, Skin_LoadIcon(SKINICON_OTHER_GROUPSHUT)); for (int i = 0; i < protoIconIndex.getCount(); i++) for (int j = 0; j < _countof(statusModeList); j++) ImageList_ReplaceIcon_IconLibLoaded(hCListImages, protoIconIndex[i].iIconBase + j, Skin_LoadProtoIcon(protoIconIndex[i].szProto, statusModeList[j])); cli.pfnTrayIconIconsChanged(); cli.pfnInvalidateRect(cli.hwndContactList, NULL, TRUE); return 0; }
static void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD) { WaitForSingleObject(g_hMutexIm, 3000); const time_t ts = time(NULL) - 10; if (lastmodule && ts > laststamp) { FreeLibrary(lastmodule); lastmodule = NULL; lastdllname.Empty(); } for (int i=g_imagecache.getCount()-1; i >= 0; i--) g_imagecache[i].ProcessTimerTick(ts); if (g_imagecache.getCount() == 0) { g_imagecache.destroy(); if (timerId && (timerId+1) && lastmodule == NULL) { KillTimer(NULL, timerId); timerId = 0; } } ReleaseMutex(g_hMutexIm); }
INT_PTR NudgeShowMenu(WPARAM wParam, LPARAM lParam) { bool bEnabled = false; for (int i = 0; i < arNudges.getCount(); i++) { CNudgeElement &p = arNudges[i]; if (!mir_strcmp((char*)wParam, p.ProtocolName)) { bEnabled = (GlobalNudge.useByProtocol) ? p.enabled : DefaultNudge.enabled; break; } } Menu_ShowItem(g_hContactMenu, bEnabled && lParam != 0); return 0; }
static void HoldOtherCalls(VoiceCall *call) { for(int i = 0; i < calls.getCount(); ++i) { VoiceCall *other = &calls[i]; if (other == call || other->state != VOICE_STATE_TALKING) continue; if (other->CanHold()) other->Hold(); else other->Drop(); } }
void CheckLogs() { LARGE_INTEGER li; QueryPerformanceCounter(&li); for (int i=0; i < arLoggers.getCount(); i++) { Logger &p = arLoggers[i]; mir_cslock lck(p.m_cs); if (p.m_out && li.QuadPart - p.m_lastwrite > llIdlePeriod) { fclose(p.m_out); p.m_out = NULL; } else fflush(p.m_out); } }
void xpt_FreeThemeForWindow(HWND hwnd) { xptlock(); { for (int i=0; i < xptObjectList.getCount(); ) { XPTObject& xptObject = xptObjectList[i]; if (xptObject.hOwnerWindow == hwnd) { _sttXptCloseThemeData(&xptObject); xptObjectList.remove(i); } else i++; } } xptunlock(); }
static void QueueAdd(MCONTACT hContact, int waitTime) { if (fei == NULL || g_shutDown) return; mir_cslock lck(cs); // Only add if not exists yet for (int i = queue.getCount() - 1; i >= 0; i--) if (queue[i].hContact == hContact) return; QueueItem *item = new QueueItem; item->hContact = hContact; item->check_time = GetTickCount() + waitTime; queue.insert(item); }
static VOID CALLBACK ClearOldVoiceCalls(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { DWORD now = GetTickCount(); BOOL refresh = FALSE; for(int i = calls.getCount() - 1; i >= 0; --i) { VoiceCall *call = &calls[i]; if (call->state == VOICE_STATE_ENDED && call->end_time + TIME_TO_SHOW_ENDED_CALL < now) { calls.remove(i); refresh = TRUE; } } if (refresh && hwnd_frame != NULL) PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); }