static int AutoAwayEvent(WPARAM, LPARAM lParam) { MIRANDA_IDLE_INFO mii = { sizeof(mii) }; CallService(MS_IDLE_GETIDLEINFO, 0, (LPARAM)&mii); if (mii.idlesoundsoff) iBreakSounds = (lParam & IDF_ISIDLE) != 0; // we don't need to switch the status if (mii.aaStatus == 0) return 0; int numAccounts; PROTOACCOUNT** accounts; Proto_EnumAccounts(&numAccounts, &accounts); for (int i = 0; i < numAccounts; i++) { PROTOACCOUNT *pa = accounts[i]; if (!Proto_IsAccountEnabled(pa) || Proto_IsAccountLocked(pa)) continue; int currentstatus = CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0); int statusbits = CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0); int status = mii.aaStatus; if (!(statusbits & Proto_Status2Flag(status))) { // the protocol doesnt support the given status if (statusbits & Proto_Status2Flag(ID_STATUS_AWAY)) status = ID_STATUS_AWAY; } if (lParam & IDF_ISIDLE) { if (currentstatus != ID_STATUS_ONLINE && currentstatus != ID_STATUS_FREECHAT) continue; // save old status of account and set to given status db_set_w(NULL, AA_MODULE, pa->szModuleName, currentstatus); Proto_SetStatus(pa->szModuleName, status); } else { int oldstatus = db_get_w(NULL, AA_MODULE, pa->szModuleName, 0); if (oldstatus != ID_STATUS_ONLINE && oldstatus != ID_STATUS_FREECHAT) continue; // returning from idle and this accout was set away, set it back db_unset(NULL, AA_MODULE, pa->szModuleName); if (!mii.aaLock) Proto_SetStatus(pa->szModuleName, oldstatus); } } return 0; }
INT_PTR StatusMenuExecService(WPARAM wParam, LPARAM) { StatusMenuExecParam *smep = (StatusMenuExecParam*)wParam; if (smep != NULL) { if (smep->custom) { if (smep->svc && *smep->svc) CallService(smep->svc, 0, (LPARAM)smep->hMenuItem); } else { if (smep->status == 0 && smep->protoindex != 0 && smep->proto != NULL) { PMO_IntMenuItem pimi; char *prot = smep->proto; char szHumanName[64] = { 0 }; PROTOACCOUNT *acc = Proto_GetAccount(smep->proto); bool bIsLocked = !Proto_IsAccountLocked(acc); db_set_b(NULL, prot, "LockMainStatus", bIsLocked); CallProtoServiceInt(NULL, smep->proto, PS_GETNAME, (WPARAM)SIZEOF(szHumanName), (LPARAM)szHumanName); pimi = MO_GetIntMenuItem((HGENMENU)smep->protoindex); PMO_IntMenuItem root = (PMO_IntMenuItem)pimi->mi.root; mir_free(pimi->mi.pszName); mir_free(root->mi.pszName); if (bIsLocked) { TCHAR buf[256]; pimi->mi.flags |= CMIF_CHECKED; if (cli.bDisplayLocked) { mir_sntprintf(buf, SIZEOF(buf), TranslateT("%s (locked)"), acc->tszAccountName); pimi->mi.ptszName = mir_tstrdup(buf); root->mi.ptszName = mir_tstrdup(buf); } else { pimi->mi.ptszName = mir_tstrdup(acc->tszAccountName); root->mi.ptszName = mir_tstrdup(acc->tszAccountName); } } else { pimi->mi.ptszName = mir_tstrdup(acc->tszAccountName); root->mi.ptszName = mir_tstrdup(acc->tszAccountName); pimi->mi.flags &= ~CMIF_CHECKED; } if (cli.hwndStatus) InvalidateRect(cli.hwndStatus, NULL, TRUE); } else if (smep->proto != NULL) { Proto_SetStatus(smep->proto, smep->status); NotifyEventHooks(hStatusModeChangeEvent, smep->status, (LPARAM)smep->proto); } else { int MenusProtoCount = 0; for (int i = 0; i < accounts.getCount(); i++) if (cli.pfnGetProtocolVisibility(accounts[i]->szModuleName)) MenusProtoCount++; cli.currentDesiredStatusMode = smep->status; for (int j = 0; j < accounts.getCount(); j++) { PROTOACCOUNT *pa = accounts[j]; if (!Proto_IsAccountEnabled(pa)) continue; if (MenusProtoCount > 1 && Proto_IsAccountLocked(pa)) continue; Proto_SetStatus(pa->szModuleName, cli.currentDesiredStatusMode); } NotifyEventHooks(hStatusModeChangeEvent, cli.currentDesiredStatusMode, 0); db_set_w(NULL, "CList", "Status", (WORD)cli.currentDesiredStatusMode); return 1; } } } return 0; }