int GetGoodAccNum(bool *bDiffers, bool *bConn) { PROTOACCOUNT **acc; int AccNum, i; Proto_EnumAccounts(&AccNum, &acc); if (bConn) *bConn = FALSE; WORD s = 0; BYTE d = 0; for (i = AccNum, AccNum = 0; i--;) { if (!acc[i]->bIsVirtual && acc[i]->bIsVisible && !acc[i]->bDynDisabled && acc[i]->ppro) { AccNum++; if (!d) { s = acc[i]->ppro->m_iStatus; d = 1; } else if (s != acc[i]->ppro->m_iStatus) d = 2; if (bConn) if (IsStatusConnecting(acc[i]->ppro->m_iStatus)) *bConn = TRUE; } } *bDiffers = d == 2; return AccNum; }
static int lua_EnumAccounts(lua_State *L) { ObsoleteMethod(L, "Use \"for x in protos.AllAccounts \" instead"); if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); return 1; } lua_pushvalue(L, 1); int ref = luaL_ref(L, LUA_REGISTRYINDEX); int count; PROTOACCOUNT** accounts; Proto_EnumAccounts(&count, &accounts); for (int i = 0; i < count; i++) { lua_rawgeti(L, LUA_REGISTRYINDEX, ref); MapToTable(L, accounts[i]); if (lua_pcall(L, 1, 0, 0)) CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); } luaL_unref(L, LUA_REGISTRYINDEX, ref); lua_pushinteger(L, count); return 1; }
int FillTree(HWND hwnd) { ProtocolData *PD; TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; TreeView_DeleteAllItems(hwnd); int n; PROTOACCOUNT** pa; Proto_EnumAccounts(&n, &pa); for (int i = 0; i < n; i++) { if (Proto_IsAccountEnabled(pa[i])) { PD = (ProtocolData*)mir_alloc(sizeof(ProtocolData)); PD->RealName = pa[i]->szModuleName; PD->enabled = IsProtoIM(pa[i]); PD->show = PD->enabled ? (plSets->ProtoDisabled(PD->RealName) ? 1 : 0) : 100; tvis.item.lParam = (LPARAM)PD; tvis.item.pszText = pa[i]->tszAccountName; tvis.item.iImage = tvis.item.iSelectedImage = PD->show; TreeView_InsertItem(hwnd, &tvis); } } return 0; }
void createProtocolList(void) { PROTOACCOUNT **proto; Proto_EnumAccounts(&ProtoList.protoCount, &proto); ProtoList.protoInfo = (PROTOCOL_INFO *)malloc(ProtoList.protoCount * sizeof(PROTOCOL_INFO)); if (!ProtoList.protoInfo) { ProtoList.protoCount = 0; return; } for (int i = 0; i < ProtoList.protoCount; i++) { ProtoList.protoInfo[i].xstatus.count = 0; ProtoList.protoInfo[i].xstatus.enabled = NULL; ProtoList.protoInfo[i].szProto = (char *)malloc(mir_strlen(proto[i]->szModuleName) + 1); if (!ProtoList.protoInfo[i].szProto) { ProtoList.protoInfo[i].enabled = FALSE; ProtoList.protoInfo[i].visible = FALSE; } else { mir_strcpy(ProtoList.protoInfo[i].szProto, proto[i]->szModuleName); ProtoList.protoInfo[i].enabled = FALSE; if (!mir_strcmp(proto[i]->szModuleName, META_PROTO)) ProtoList.protoInfo[i].visible = FALSE; else { ProtoList.protoInfo[i].visible = TRUE; updateXstatusProto(&(ProtoList.protoInfo[i])); } } } }
int StatusChanged(WPARAM wParam, LPARAM lParam) { LogMessage("MS_CLIST_SETSTATUSMODE called. szProto=%s, Status=%d", lParam ? (char*)lParam : "NULL", wParam); g_ProtoStates[(char*)lParam].Status = wParam; // let's check if we handle this thingy if (g_fNoProcessing) { // we're told not to do anything g_fNoProcessing = false; // take it off return 0; } DWORD Flag1 = 0; DWORD Flag3 = 0; if (lParam) { Flag1 = CallProtoService((char*)lParam, PS_GETCAPS, PFLAGNUM_1, 0); Flag3 = CallProtoService((char*)lParam, PS_GETCAPS, PFLAGNUM_3, 0); } else { PROTOACCOUNT **accs; int numAccs = 0; Proto_EnumAccounts(&numAccs, &accs); for (int i = 0; i < numAccs; i++) { Flag1 |= CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0); Flag3 |= CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); } } if (!(Flag1 & PF1_MODEMSGSEND || Flag3 & Proto_Status2Flag(wParam) || (Flag1 & PF1_IM) == PF1_IM)) return 0; // there are no protocols with changed status that support autoreply or away messages for this status if (g_SetAwayMsgPage.GetWnd()) { SetForegroundWindow(g_SetAwayMsgPage.GetWnd()); return 0; } int i; for (i = _countof(StatusModeList) - 1; i >= 0; i--) if (wParam == StatusModeList[i].Status) break; if (i < 0) return 0; BOOL bScreenSaverRunning; SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &bScreenSaverRunning, 0); if (bScreenSaverRunning || g_MoreOptPage.GetDBValueCopy(StatusModeList[i].DontShowDialogCtlID)) { CProtoSettings((char*)lParam).SetMsgFormat(SMF_PERSONAL, CProtoSettings((char*)lParam).GetMsgFormat(GMF_LASTORDEFAULT)); ChangeProtoMessages((char*)lParam, wParam, TCString()); } else { SetAwayMsgData *dat = new SetAwayMsgData; memset(dat, 0, sizeof(SetAwayMsgData)); dat->szProtocol = (char*)lParam; dat->IsModeless = false; DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_SETAWAYMSG), NULL, SetAwayMsgDlgProc, (LPARAM)dat); } return 0; }
static int OnOkToExit(WPARAM, LPARAM) { // save last protocolstatus int count; PROTOACCOUNT** protos; Proto_EnumAccounts(&count, &protos); for (int i = 0; i < count; i++) { PROTOACCOUNT *pa = protos[i]; if (!IsSuitableProto(pa)) continue; if (!Proto_GetAccount(pa->szModuleName)) continue; char lastName[128], lastMsg[128]; mir_snprintf(lastName, "%s%s", PREFIX_LAST, pa->szModuleName); db_set_w(NULL, MODULENAME, lastName, (WORD)CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0)); mir_snprintf(lastMsg, "%s%s", PREFIX_LASTMSG, pa->szModuleName); db_unset(NULL, MODULENAME, lastMsg); if (!(CallProtoService(pa->szModuleName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0) & PF1_MODEMSGSEND & ~PF1_INDIVMODEMSG)) continue; int status = CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0); if (!(CallProtoService(pa->szModuleName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0) & Proto_Status2Flag(status))) continue; // NewAwaySys if (ServiceExists(MS_NAS_GETSTATE)) { NAS_PROTOINFO npi = { sizeof(npi) }; npi.szProto = pa->szModuleName; CallService(MS_NAS_GETSTATE, (WPARAM)&npi, 1); if (npi.szMsg == NULL) { npi.status = 0; npi.szProto = NULL; CallService(MS_NAS_GETSTATE, (WPARAM)&npi, 1); } if (npi.szMsg != NULL) { db_set_ts(NULL, MODULENAME, lastMsg, npi.tszMsg); mir_free(npi.tszMsg); } } } if (db_get_b(NULL, MODULENAME, SETTING_SETPROFILE, 1) || db_get_b(NULL, MODULENAME, SETTING_OFFLINECLOSE, 0)) { if (ServiceExists(MS_CLIST_SETSTATUSMODE)) CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)ID_STATUS_OFFLINE, 0); else log_debugA("StartupStatus: MS_CLIST_SETSTATUSMODE not available!"); } return 0; }
static bool AnyProtoHasCaps(DWORD caps1) { int nProtoCount; PROTOACCOUNT **protos; Proto_EnumAccounts(&nProtoCount, &protos); for (int i = 0; i < nProtoCount; ++i) if (CallProtoService(protos[i]->szModuleName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&caps1) return true; /* CALLSERVICE_NOTFOUND also handled gracefully */ return false; }
static int InternalRemoveMyAvatar(char *protocol) { SetIgnoreNotify(protocol, TRUE); // Remove avatar int ret = 0; if (protocol != NULL) { if (ProtoServiceExists(protocol, PS_SETMYAVATAR)) ret = SaveAvatar(protocol, NULL); else ret = -3; if (ret == 0) { // Has global avatar? DBVARIANT dbv = { 0 }; if (!db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv)) { db_free(&dbv); db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); DeleteGlobalUserAvatar(); } } } else { PROTOACCOUNT **accs; int i, count; Proto_EnumAccounts(&count, &accs); for (i = 0; i < count; i++) { if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR)) continue; if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName)) continue; // Found a protocol int retTmp = SaveAvatar(accs[i]->szModuleName, NULL); if (retTmp != 0) ret = retTmp; } DeleteGlobalUserAvatar(); if (ret) db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); else db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 0); } SetIgnoreNotify(protocol, FALSE); ReportMyAvatarChanged(WPARAM((protocol == NULL) ? "" : protocol), 0); return ret; }
void RemoveDirectories() { char buffer[10000]; char dir[MAX_PATH]; // Remove protocol folders if (GetSettingBool("GlobalSettings", "RemoveProtocolFolders", TRUE)) { PROTOACCOUNT **accounts; int count; Proto_EnumAccounts(&count, &accounts); for (int i = 0; i < count; i++) { /*if (protos[i]->type != PROTOTYPE_PROTOCOL) continue;*/ if (!accounts[i]->bIsEnabled) continue; if (accounts[i]->szModuleName == NULL || accounts[i]->szModuleName[0] == '\0') continue; mir_snprintf(dir, "%s%s", gMirandaDir, accounts[i]->szModuleName); DeleteFileOrFolder(dir); } } // Remove other folders if ( GetSettings("RemoveFilesOrFolders", buffer, sizeof(buffer)) ) { char *name; char *value; name = buffer; while(name[0] != '\0') { value = strchr(name, '='); if (value == NULL) value = &name[mir_strlen(name)]; // Has " ? if (*name == '"' && *(value-1) == '"') { name++; *(value-1) = '\0'; } // Delete it if (name[0] != '\0') { mir_snprintf(dir, "%s%s", gMirandaDir, name); DeleteFileOrFolder(dir); } // Get next one name = value + mir_strlen(value) + 1; } } }
void DlgOption::SubInput::onWMInitDialog() { TranslateDialogDefault(getHWnd()); // init options control m_Options << GetDlgItem(getHWnd(), IDC_OPTIONS); // settings OptionsCtrl::Item hTemp, hTemp2; hTemp = m_Options.insertGroup(NULL, TranslateT("History interpretation"), OptionsCtrl::OCF_ROOTGROUP); m_hChatSessionMinDur = m_Options.insertEdit(hTemp, TranslateT("Time a chat session must last to be counted (seconds)"), _T(""), OptionsCtrl::OCF_NUMBER); m_hChatSessionTimeout = m_Options.insertEdit(hTemp, TranslateT("Time between two chat sessions (seconds)"), _T(""), OptionsCtrl::OCF_NUMBER); m_hAverageMinTime = m_Options.insertEdit(hTemp, TranslateT("Minimum time to assume when calculating average (days)"), _T(""), OptionsCtrl::OCF_NUMBER); m_hWordDelimiters = m_Options.insertEdit(hTemp, TranslateT("Word delimiting characters")); hTemp = m_Options.insertGroup(NULL, TranslateT("Contact filtering"), OptionsCtrl::OCF_ROOTGROUP | OptionsCtrl::OCF_NODISABLECHILDS); m_hProtocols = m_Options.insertGroup(hTemp, TranslateT("Ignore all contacts with protocol...")); hTemp2 = m_Options.insertGroup(hTemp, TranslateT("History read mode for metacontacts"), 0); m_hMetaContactsMode = m_Options.insertRadio(hTemp2, NULL, TranslateT("Use only metacontact's history")); m_Options.insertRadio(hTemp2, m_hMetaContactsMode, TranslateT("Use only subcontacts' histories (for one metacontact)")); m_Options.insertRadio(hTemp2, m_hMetaContactsMode, TranslateT("Use metacontact's history and its subcontacts' histories")); m_Options.insertRadio(hTemp2, m_hMetaContactsMode, TranslateT("Treat metacontacts and subcontacts as normal contacts")); m_hMergeContacts = m_Options.insertCheck(hTemp, TranslateT("Merge contacts with same name"), OptionsCtrl::OCF_DISABLECHILDSONUNCHECK); m_hMergeContactsGroups = m_Options.insertCheck(m_hMergeContacts, TranslateT("Only merge if contacts are in the same group")); hTemp2 = m_Options.insertGroup(hTemp, TranslateT("Duplicate detection when reading merged contacts")); m_hMergeMode = m_Options.insertRadio(hTemp2, NULL, TranslateT("Merge events (tolerant)")); m_Options.insertRadio(hTemp2, m_hMergeMode, TranslateT("Merge events (strict)")); m_Options.insertRadio(hTemp2, m_hMergeMode, TranslateT("Don't merge events")); hTemp = m_Options.insertGroup(NULL, TranslateT("Message filtering"), OptionsCtrl::OCF_ROOTGROUP); hTemp2 = m_Options.insertGroup(hTemp, TranslateT("Ignore messages...")); m_hIgnoreOlder = m_Options.insertEdit(hTemp2, TranslateT("...older than (days, 0=no limit)"), _T(""), OptionsCtrl::OCF_NUMBER); m_hIgnoreBefore = m_Options.insertDateTime(hTemp2, TranslateT("...before date (none=no limit)"), 0, _T("%Y-%m-%d"), OptionsCtrl::OCF_ALLOWNONE); m_hIgnoreAfter = m_Options.insertDateTime(hTemp2, TranslateT("...after date (none=no limit)"), 0, _T("%Y-%m-%d"), OptionsCtrl::OCF_ALLOWNONE); m_hFilterRawRTF = m_Options.insertCheck(hTemp, TranslateT("Strip raw RTF control sequences from message")); m_hFilterBBCodes = m_Options.insertCheck(hTemp, TranslateT("Strip BBCode tags from messages")); // insert known protocols m_hProtosIgnore.clear(); PROTOACCOUNT **protoList; int protoCount; Proto_EnumAccounts(&protoCount, &protoList); upto_each_(i, protoCount) { m_hProtosIgnore.push_back(m_Options.insertCheck( m_hProtocols, Protocol::getDisplayName(protoList[i]->szModuleName).c_str(), 0, reinterpret_cast<INT_PTR>(protoList[i]->szModuleName))); }
static int lua_AllAccounts(lua_State *L) { int count; PROTOACCOUNT** accounts; Proto_EnumAccounts(&count, &accounts); lua_pushinteger(L, 0); lua_pushinteger(L, count); lua_pushlightuserdata(L, accounts); lua_pushcclosure(L, lua_AccountIterator, 3); return 1; }
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 GetProtoIndex(char * szName) { if (szName) { PROTOACCOUNT **accs = NULL; int accCount = 0; Proto_EnumAccounts(&accCount, &accs); for (int i = 0; i < accCount; i++) if (!mir_strcmpi(szName, accs[i]->szModuleName)) return accs[i]->iOrder; } return -1; }
static void GetProtocolStrings(CMString& buffer) { PROTOACCOUNT **accList; int accCount; int i, j; Proto_EnumAccounts(&accCount, &accList); int protoCount; PROTOCOLDESCRIPTOR **protoList; Proto_EnumProtocols(&protoCount, &protoList); int protoCountMy = 0; char** protoListMy = (char**)alloca((protoCount + accCount) * sizeof(char*)); for (i = 0; i < protoCount; i++) { if (protoList[i]->type != PROTOTYPE_PROTOCOL) continue; protoListMy[protoCountMy++] = protoList[i]->szName; } for (j = 0; j < accCount; j++) { for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) break; if (i == protoCountMy) protoListMy[protoCountMy++] = accList[j]->szProtoName; } ProtoCount *protos = (ProtoCount*)alloca(sizeof(ProtoCount) * protoCountMy); memset(protos, 0, sizeof(ProtoCount) * protoCountMy); for (j = 0; j < accCount; j++) for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) { protos[i].nloaded = accList[j]->bDynDisabled != 0; if (Proto_IsAccountEnabled(accList[j])) ++protos[i].countse; else ++protos[i].countsd; break; } for (i = 0; i < protoCountMy; i++) buffer.AppendFormat(TEXT("%-24s %d - Enabled %d - Disabled %sLoaded\r\n"), (TCHAR*)_A2T(protoListMy[i]), protos[i].countse, protos[i].countsd, protos[i].nloaded ? _T("Not ") : _T("")); }
LPCSTR GetJidAcc(LPCTSTR jid) { int count = 0; PROTOACCOUNT **protos; Proto_EnumAccounts(&count, &protos); for (int i = 0; i < count; i++) { if (getJabberApi(protos[i]->szModuleName)) { ptrT tszJid(db_get_tsa(0, protos[i]->szModuleName, "jid")); if (!mir_tstrcmpi(jid, tszJid)) return protos[i]->szModuleName; } } return NULL; }
void SvcTimezoneSyncWithWindows() { TIME_ZONE_INFORMATION tzi = { 0 }; GetTimeZoneInformation(&tzi); PROTOACCOUNT **pAcc; int nAccCount; Proto_EnumAccounts(&nAccCount, &pAcc); for (int i = 0; i < nAccCount; i++) { // update local timezone as database setting if (IsProtoAccountEnabled(pAcc[i]) && SvcTimezoneSyncWithWindowsProc(pAcc[i]->szModuleName, tzi.Bias)) // update my contact information on icq server CallProtoService(pAcc[i]->szModuleName, PS_CHANGEINFOEX, CIXT_LOCATION, NULL); } }
void Protocol::SetStatus(int aStatus) { if (ServiceExists(MS_CS_SETSTATUSEX)) { // BEGIN From commomstatus.cpp (KeepStatus) int i, count, pCount; PROTOACCOUNT **accs; pCount = 0; Proto_EnumAccounts(&count, &accs); for (i = 0; i < count; i++) { if (CallProtoService(accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) continue; pCount++; } // END From commomstatus.cpp (KeepStatus) PROTOCOLSETTINGEX **pse = (PROTOCOLSETTINGEX **)mir_calloc(pCount * sizeof(PROTOCOLSETTINGEX *)); for (i = 0; i < pCount; i++) { pse[i] = (PROTOCOLSETTINGEX *)mir_calloc(sizeof(PROTOCOLSETTINGEX)); pse[i]->szName = ""; } pse[0]->cbSize = sizeof(PROTOCOLSETTINGEX); pse[0]->status = aStatus; pse[0]->szName = name; TCHAR status_msg[256]; GetStatusMsg(aStatus, status_msg, _countof(status_msg)); pse[0]->szMsg = status_msg; CallService(MS_CS_SETSTATUSEX, (WPARAM)&pse, 0); for (i = 0; i < pCount; i++) mir_free(pse[i]); mir_free(pse); } else { CallProtoService(name, PS_SETSTATUS, aStatus, 0); if (CanSetStatusMsg(aStatus)) { TCHAR status_msg[MS_MYDETAILS_GETMYSTATUSMESSAGE_BUFFER_SIZE]; GetStatusMsg(aStatus, status_msg, _countof(status_msg)); SetStatusMsg(aStatus, status_msg); } } }
void SmileyCategoryListType::AddAllProtocolsAsCategory(void) { CMString displayName = TranslateT("Standard"); CMString tname = _T("Standard"); AddCategory(tname, displayName, smcStd); const CMString &defaultFile = GetSmileyCategory(tname)->GetFilename(); PROTOCOLDESCRIPTOR **proto; int protoCount = 0; Proto_EnumProtocols(&protoCount, &proto); for (int i = 0; i < protoCount; i++) { PROTOCOLDESCRIPTOR *pd = proto[i]; if (pd->type == PROTOTYPE_PROTOCOL && pd->cbSize == sizeof(*pd)) AddProtoAsCategory(pd->szName, defaultFile); } PROTOACCOUNT **accList; Proto_EnumAccounts(&protoCount, &accList); for (int i = 0; i < protoCount; i++) AddAccountAsCategory(accList[i], defaultFile); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) AddContactTransportAsCategory(hContact, defaultFile); CMString cats; opt.ReadCustomCategories(cats); int cppv = 0; for (;;) { int cp = cats.Find('#', cppv); if (cp == -1) break; displayName = cats.Mid(cppv, cp - cppv); AddCategory(displayName, displayName, smcCustom, defaultFile); cppv = cp + 1; } if (cppv != cats.GetLength()) { displayName = cats.Mid(cppv); AddCategory(displayName, displayName, smcCustom, defaultFile); } }
void LoadProtocols(void) { //Load the default nudge mir_snprintf(DefaultNudge.ProtocolName, "Default"); mir_snprintf(DefaultNudge.NudgeSoundname, "Nudge : Default"); SkinAddNewSoundEx(DefaultNudge.NudgeSoundname, LPGEN("Nudge"), LPGEN("Default Nudge")); DefaultNudge.Load(); GlobalNudge.Load(); int numberOfProtocols = 0; PROTOACCOUNT **ppProtocolDescriptors; Proto_EnumAccounts(&numberOfProtocols, &ppProtocolDescriptors); for (int i = 0; i < numberOfProtocols; i++) Nudge_AddAccount(ppProtocolDescriptors[i]); shake.Load(); }
void InitSelfSounds() { // initializing self sounds for protocols int protoCount = 0; PROTOACCOUNT** protos = 0; Proto_EnumAccounts(&protoCount, &protos); for (int i = 0; i < protoCount; i++) { for (int j = 0; j < _countof(selfSounds); j++) { char namebuf[128]; mir_snprintf(namebuf, _countof(namebuf), "%s%s", protos[i]->szModuleName, selfSounds[j].szName); TCHAR infobuf[256]; mir_sntprintf(infobuf, _countof(infobuf), _T("%s [%s]"), TranslateT("Self status"), protos[i]->tszAccountName); SkinAddNewSoundExT(namebuf, infobuf, pcli->pfnGetStatusModeDescription(selfSounds[j].iStatus, 0)); } } }
VOID CALLBACK cliTrayCycleTimerProc(HWND, UINT, UINT_PTR, DWORD) { if (!pcli->trayIconCount) return; PROTOACCOUNT **acc; int AccNum; Proto_EnumAccounts(&AccNum, &acc); // looking for the appropriate account to show its icon int t = pcli->cycleStep; do { pcli->cycleStep = (pcli->cycleStep + 1) % AccNum; if (pcli->cycleStep == t) return; } while (acc[pcli->cycleStep]->bIsVirtual || !acc[pcli->cycleStep]->bIsVisible); cliTrayCalcChanged(acc[pcli->cycleStep]->szModuleName, 0, 0); }
int GetProfile( int profile, TSettingsList& arSettings ) { if ( profile < 0 ) // get default profile profile = db_get_w(NULL, MODULENAME, SETTING_DEFAULTPROFILE, 0); int count = db_get_w(NULL, MODULENAME, SETTING_PROFILECOUNT, 0); if ( profile >= count && count > 0 ) return -1; arSettings.destroy(); // if count == 0, continue so the default profile will be returned PROTOACCOUNT** protos; Proto_EnumAccounts( &count, &protos ); for ( int i=0; i < count; i++ ) if ( IsSuitableProto( protos[i] )) arSettings.insert( new TSSSetting( profile, protos[i] )); return ( arSettings.getCount() == 0 ) ? -1 : 0; }
void InitProtocolData() { PROTOACCOUNT **protos; int count; Proto_EnumAccounts(&count, &protos); protocols = new ProtocolArray(count); for (int i = 0; i < count; i++) { PROTOACCOUNT *acc = protos[i]; if (acc->szModuleName == NULL || acc->szModuleName[0] == '\0' || acc->bIsVirtual) continue; // Found a protocol Protocol *p = new Protocol(acc->szModuleName, acc->tszAccountName); if (p->IsValid()) protocols->Add(p); else delete p; } }
/** * name: ProtoIcon * class: CPsTreeItem * desc: check if current tree item name is a protocol name and return its icon if so * params: none * return: nothing **/ HICON CPsTreeItem::ProtoIcon() { if (!_pszName) return NULL; PROTOACCOUNT **pa; int ProtoCount; Proto_EnumAccounts(&ProtoCount, &pa); for (int i = 0; i < ProtoCount; i++) { if (!mir_tstrncmpi(pa[i]->tszAccountName, _A2T(_pszName), mir_tstrlen(pa[i]->tszAccountName))) { CHAR szIconID[MAX_PATH]; mir_snprintf(szIconID, "core_status_%s1", pa[i]->szModuleName); HICON hIco = IcoLib_GetIcon(szIconID); if (!hIco) hIco = (HICON)CallProtoService(pa[i]->szModuleName, PS_LOADICON, PLI_PROTOCOL, NULL); return hIco; } } return NULL; }
void SetProtoStatus(TCHAR *pszLabel, char *pszProto, int if_status, int new_status) { if (mir_strcmp(pszProto, Translate("<all>")) == 0) { int num_protocols; PROTOACCOUNT **pppDesc; Proto_EnumAccounts(&num_protocols, &pppDesc); for (int i = 0; i < num_protocols; i++) SetProtoStatus(pszLabel, pppDesc[i]->szModuleName, if_status, new_status); } else { if (ProtoServiceExists(pszProto, PS_GETSTATUS)) { if (CallProtoService(pszProto, PS_GETSTATUS, 0, 0) == if_status) { if (options.logging) { TCHAR buf[1024]; mir_sntprintf(buf, TranslateT("%s - setting status of protocol '%S' (%d)"), pszLabel, pszProto, new_status); CallService(PLUG "/Log", (WPARAM)buf, 0); } CallProtoService(pszProto, PS_SETSTATUS, new_status, 0); } } } }
void SetProtocolsOffline() { if ( GetSettingBool("GlobalSettings", "SetProtocolsOffline", TRUE) ) { PROTOACCOUNT **accounts; int count; Proto_EnumAccounts(&count, &accounts); for (int i = 0; i < count; i++) { /*if (protos[i]->type != PROTOTYPE_PROTOCOL) continue;*/ if (!accounts[i]->bIsEnabled) continue; if (accounts[i]->szModuleName == NULL || accounts[i]->szModuleName[0] == '\0') continue; CallProtoService(accounts[i]->szModuleName, PS_SETSTATUS, ID_STATUS_OFFLINE, 0); } // Give some time to make it really offline Sleep(2000); } }
static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); int sel; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SETCURSEL, (LPARAM)-1, 0); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); } SendMessage(lv, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); { // add list columns LVCOLUMN lvc; // Initialize the LVCOLUMN structure. // The mask specifies that the format, width, text, and // subitem members of the structure are valid. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = 0; lvc.pszText = TranslateT(LANG_PROTO); lvc.cx = 85; // width of column in pixels ListView_InsertColumn(lv, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TranslateT(LANG_POLICY); lvc.cx = 80; // width of column in pixels ListView_InsertColumn(lv, 1, &lvc); lvc.iSubItem = 2; lvc.pszText = TranslateT(LANG_FINGERPRINT); lvc.cx = 275; // width of column in pixels ListView_InsertColumn(lv, 2, &lvc); } PostMessage(hwndDlg, WMU_REFRESHPROTOLIST, 0, 0); return TRUE; case WMU_REFRESHPROTOLIST: ListView_DeleteAllItems(lv); { LV_ITEM item = { 0 }; int num_protocols; PROTOACCOUNT **pppDesc; Proto_EnumAccounts(&num_protocols, &pppDesc); for (int i = 0; i < num_protocols; i++) { if (!mir_strcmp(pppDesc[i]->szModuleName, META_PROTO)) continue; if ((CallProtoService(pppDesc[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == 0) continue; item.mask = LVIF_TEXT | LVIF_PARAM; item.pszText = pppDesc[i]->tszAccountName; item.lParam = (LPARAM)pppDesc[i]->szModuleName; int ilvItem = ListView_InsertItem(lv, &item); ListView_SetItemText(lv, ilvItem, 1, (TCHAR*)policy_to_string(db_get_dw(0, MODULENAME"_ProtoPol", pppDesc[i]->szModuleName, CONTACT_DEFAULT_POLICY))); char fprint[45]; if (otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szModuleName, pppDesc[i]->szModuleName)) { TCHAR *temp = mir_a2t(fprint); ListView_SetItemText(lv, ilvItem, 2, temp); mir_free(temp); } } } return TRUE; case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: switch (LOWORD(wParam)) { case IDC_BTN_PROTO_NEWKEY: sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (sel != -1) { PROTOREGENKEYOPTIONS *opts = new PROTOREGENKEYOPTIONS(); opts->refresh = hwndDlg; ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, opts->proto, _countof(opts->proto)); CloseHandle((HANDLE)_beginthreadex(0, 0, regen_key_thread, opts, 0, 0)); } break; case IDC_BTN_PROTO_FORGET: sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (sel != -1) { TCHAR buff_proto[128]; ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, buff_proto, _countof(buff_proto)); TCHAR buff[512]; mir_sntprintf(buff, TranslateT(LANG_OTR_ASK_REMOVEKEY), buff_proto); if (IDYES == MessageBox(hwndDlg, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION | MB_YESNO)) { char *proto = GetProtoName(lv, sel); if (proto == NULL) break; OtrlPrivKey *key = otrl_privkey_find(otr_user_state, proto, proto); if (key) { otrl_privkey_forget(key); otrl_privkey_write(otr_user_state, _T2A(g_private_key_filename)); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, _T("")); } } } } break; case CBN_SELCHANGE: switch (LOWORD(wParam)) { case IDC_CMB_PROTO_POLICY: int proto = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (proto == -1) break; int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETCURSEL, 0, 0); if (sel == CB_ERR) break; int len = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXTLEN, sel, 0); if (len < 0) break; TCHAR *text = new TCHAR[len + 1]; SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), proto, 1, text); delete[] text; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED && ((LPNMHDR)lParam)->hwndFrom == lv) { LPNMLISTVIEW notif = (LPNMLISTVIEW)lParam; if ((notif->uNewState & LVIS_SELECTED) == 0) break; if (notif->iItem == -1) { SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SETCURSEL, (LPARAM)-1, 0); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); } else { EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), TRUE); TCHAR buff[50]; ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, notif->iItem, 1, buff, _countof(buff)); SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); } } else if (((LPNMHDR)lParam)->code == PSN_APPLY) { int cnt = ListView_GetItemCount(lv); TCHAR policy[64]; for (int i = 0; i < cnt; ++i) { char *proto = GetProtoName(lv, i); if (proto == NULL) continue; ListView_GetItemText(lv, i, 1, policy, _countof(policy)); db_set_dw(0, MODULENAME"_ProtoPol", proto, policy_from_string(policy)); } // handle apply return TRUE; } break; } return FALSE; }
INT_PTR CALLBACK SaveOptsDlgProc(OptPageControl *controls, int controlsSize, char *module, HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { TCHAR tmp[1024]; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); for (int i = 0; i < controlsSize; i++) { OptPageControl *ctrl = &controls[i]; if (GetDlgItem(hwndDlg, ctrl->nID) == NULL) continue; switch (ctrl->type) { case CONTROL_CHECKBOX: CheckDlgButton(hwndDlg, ctrl->nID, db_get_b(NULL, module, ctrl->setting, ctrl->dwDefValue) == 1 ? BST_CHECKED : BST_UNCHECKED); break; case CONTROL_SPIN: SendDlgItemMessage(hwndDlg, ctrl->nIDSpin, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, ctrl->nID), 0); SendDlgItemMessage(hwndDlg, ctrl->nIDSpin, UDM_SETRANGE, 0, MAKELONG(ctrl->max, ctrl->min)); SendDlgItemMessage(hwndDlg, ctrl->nIDSpin, UDM_SETPOS, 0, MAKELONG(db_get_w(NULL, module, ctrl->setting, ctrl->dwDefValue), 0)); break; case CONTROL_COLOR: SendDlgItemMessage(hwndDlg, ctrl->nID, CPM_SETCOLOUR, 0, (COLORREF)db_get_dw(NULL, module, ctrl->setting, ctrl->dwDefValue)); break; case CONTROL_RADIO: CheckDlgButton(hwndDlg, ctrl->nID, db_get_w(NULL, module, ctrl->setting, ctrl->dwDefValue) == ctrl->value ? BST_CHECKED : BST_UNCHECKED); break; case CONTROL_COMBO: SendDlgItemMessage(hwndDlg, ctrl->nID, CB_SETCURSEL, db_get_w(NULL, module, ctrl->setting, ctrl->dwDefValue), 0); break; case CONTROL_PROTOCOL_LIST: { // Fill list view HWND hwndProtocols = GetDlgItem(hwndDlg, ctrl->nID); LVCOLUMN lvc; LVITEM lvi; ListView_SetExtendedListViewStyle(hwndProtocols, LVS_EX_CHECKBOXES); memset(&lvc, 0, sizeof(lvc)); lvc.mask = LVCF_FMT; lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT; ListView_InsertColumn(hwndProtocols, 0, &lvc); memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.iSubItem = 0; lvi.iItem = 1000; int count; PROTOACCOUNT **protos; Proto_EnumAccounts(&count, &protos); for (int k = 0; k < count; k++) { PROTOACCOUNT *p = protos[k]; if (p->szModuleName == NULL || p->szModuleName[0] == '\0') continue; if (ctrl->allowProtocol != NULL && !ctrl->allowProtocol(p->szModuleName)) continue; char *setting = (char *)mir_alloc(128 * sizeof(char)); mir_snprintf(setting, 128, ctrl->setting, p->szModuleName); BOOL show = (BOOL)db_get_b(NULL, module, setting, ctrl->dwDefValue); lvi.lParam = (LPARAM)setting; lvi.pszText = p->tszAccountName; lvi.iItem = ListView_InsertItem(hwndProtocols, &lvi); ListView_SetItemState(hwndProtocols, lvi.iItem, INDEXTOSTATEIMAGEMASK(show ? 2 : 1), LVIS_STATEIMAGEMASK); } ListView_SetColumnWidth(hwndProtocols, 0, LVSCW_AUTOSIZE); ListView_Arrange(hwndProtocols, LVA_ALIGNLEFT | LVA_ALIGNTOP); } break; case CONTROL_TEXT: SetDlgItemText(hwndDlg, ctrl->nID, MyDBGetContactSettingTString(NULL, module, ctrl->setting, tmp, 1024, ctrl->tszDefValue == NULL ? NULL : TranslateTS(ctrl->tszDefValue))); SendDlgItemMessage(hwndDlg, ctrl->nID, EM_LIMITTEXT, min(ctrl->max <= 0 ? 1024 : ctrl->max, 1024), 0); break; case CONTROL_INT: SetDlgItemInt(hwndDlg, ctrl->nID, db_get_dw(NULL, module, ctrl->setting, ctrl->dwDefValue), ctrl->min <= 0); SendDlgItemMessage(hwndDlg, ctrl->nID, EM_LIMITTEXT, 9, 0); break; case CONTROL_FILE: MyDBGetContactSettingTString(NULL, module, ctrl->setting, tmp, 1024, ctrl->tszDefValue == NULL ? NULL : ctrl->tszDefValue); { TCHAR abs[1024]; PathToAbsolute(abs, 1024, tmp); SetDlgItemText(hwndDlg, ctrl->nID, abs); } SendDlgItemMessage(hwndDlg, ctrl->nID, EM_LIMITTEXT, min(ctrl->max <= 0 ? 1024 : ctrl->max, 1024), 0); break; case CONTROL_COMBO_TEXT: MyDBGetContactSettingTString(NULL, module, ctrl->setting, tmp, 1024, ctrl->tszDefValue == NULL ? NULL : TranslateTS(ctrl->tszDefValue)); SendDlgItemMessage(hwndDlg, ctrl->nID, CB_SELECTSTRING, 0, (WPARAM)tmp); break; case CONTROL_COMBO_ITEMDATA: MyDBGetContactSettingTString(NULL, module, ctrl->setting, tmp, 1024, ctrl->tszDefValue == NULL ? NULL : TranslateTS(ctrl->tszDefValue)); { int count = SendDlgItemMessage(hwndDlg, ctrl->nID, CB_GETCOUNT, 0, 0); int k; for (k = 0; k < count; k++) { TCHAR *id = (TCHAR *)SendDlgItemMessage(hwndDlg, ctrl->nID, CB_GETITEMDATA, (WPARAM)k, 0); if (mir_tstrcmp(id, tmp) == 0) break; } if (k < count) SendDlgItemMessage(hwndDlg, ctrl->nID, CB_SETCURSEL, k, 0); } break; } } break; case WM_COMMAND: for (int i = 0; i < controlsSize; i++) { OptPageControl *ctrl = &controls[i]; if (LOWORD(wParam) == ctrl->nID) { switch (ctrl->type) { case CONTROL_TEXT: case CONTROL_SPIN: case CONTROL_INT: // Don't make apply enabled during buddy set if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; break; case CONTROL_COMBO_ITEMDATA: case CONTROL_COMBO_TEXT: case CONTROL_COMBO: if (HIWORD(wParam) != CBN_SELCHANGE || (HWND)lParam != GetFocus()) return 0; break; } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } break; case WM_NOTIFY: { LPNMHDR lpnmhdr = (LPNMHDR)lParam; if (lpnmhdr->idFrom == 0 && lpnmhdr->code == PSN_APPLY) { for (int i = 0; i < controlsSize; i++) { OptPageControl *ctrl = &controls[i]; if (GetDlgItem(hwndDlg, ctrl->nID) == NULL) continue; switch (ctrl->type) { case CONTROL_CHECKBOX: db_set_b(NULL, module, ctrl->setting, (BYTE)IsDlgButtonChecked(hwndDlg, ctrl->nID)); break; case CONTROL_SPIN: db_set_w(NULL, module, ctrl->setting, (WORD)SendDlgItemMessage(hwndDlg, ctrl->nIDSpin, UDM_GETPOS, 0, 0)); break; case CONTROL_COLOR: db_set_dw(NULL, module, ctrl->setting, (DWORD)SendDlgItemMessage(hwndDlg, ctrl->nID, CPM_GETCOLOUR, 0, 0)); break; case CONTROL_RADIO: if (IsDlgButtonChecked(hwndDlg, ctrl->nID)) db_set_w(NULL, module, ctrl->setting, (BYTE)ctrl->value); break; case CONTROL_COMBO: db_set_w(NULL, module, ctrl->setting, (WORD)SendDlgItemMessage(hwndDlg, ctrl->nID, CB_GETCURSEL, 0, 0)); break; case CONTROL_PROTOCOL_LIST: { LVITEM lvi = { 0 }; lvi.mask = (UINT)LVIF_PARAM; HWND hwndProtocols = GetDlgItem(hwndDlg, ctrl->nID); int count = ListView_GetItemCount(hwndProtocols); for (int k = 0; k < count; k++) { lvi.iItem = k; ListView_GetItem(hwndProtocols, &lvi); char *setting = (char *)lvi.lParam; db_set_b(NULL, module, setting, (BYTE)ListView_GetCheckState(hwndProtocols, k)); } } break; case CONTROL_TEXT: GetDlgItemText(hwndDlg, ctrl->nID, tmp, _countof(tmp)); db_set_ts(NULL, module, ctrl->setting, tmp); break; case CONTROL_INT: BOOL trans; { int val = GetDlgItemInt(hwndDlg, ctrl->nID, &trans, ctrl->min <= 0); if (!trans) val = ctrl->dwDefValue; if (ctrl->max != 0) val = min(val, ctrl->max); if (ctrl->min != 0) val = max(val, ctrl->min); db_set_dw(NULL, module, ctrl->setting, val); } break; case CONTROL_FILE: GetDlgItemText(hwndDlg, ctrl->nID, tmp, _countof(tmp)); { TCHAR rel[1024]; PathToRelative(rel, 1024, tmp); db_set_ts(NULL, module, ctrl->setting, rel); } break; case CONTROL_COMBO_TEXT: GetDlgItemText(hwndDlg, ctrl->nID, tmp, _countof(tmp)); db_set_ts(NULL, module, ctrl->setting, tmp); break; case CONTROL_COMBO_ITEMDATA: int sel = SendDlgItemMessage(hwndDlg, ctrl->nID, CB_GETCURSEL, 0, 0); db_set_ts(NULL, module, ctrl->setting, (TCHAR *)SendDlgItemMessage(hwndDlg, ctrl->nID, CB_GETITEMDATA, (WPARAM)sel, 0)); break; } LoadOpt(ctrl, module); } return TRUE; } else if (lpnmhdr->idFrom != 0 && lpnmhdr->code == LVN_ITEMCHANGED) { // Changed for protocols for (int i = 0; i < controlsSize; i++) { OptPageControl *ctrl = &controls[i]; if (ctrl->type == CONTROL_PROTOCOL_LIST && ctrl->nID == lpnmhdr->idFrom) { NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam; if (IsWindowVisible(GetDlgItem(hwndDlg, ctrl->nID)) && ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } } } } break; case WM_DESTROY: for (int i = 0; i < controlsSize; i++) { OptPageControl *ctrl = &controls[i]; if (GetDlgItem(hwndDlg, ctrl->nID) == NULL) continue; switch (ctrl->type) { case CONTROL_PROTOCOL_LIST: LVITEM lvi = { 0 }; lvi.mask = (UINT)LVIF_PARAM; HWND hwndProtocols = GetDlgItem(hwndDlg, ctrl->nID); int count = ListView_GetItemCount(hwndProtocols); for (i = 0; i < count; i++) { lvi.iItem = i; ListView_GetItem(hwndProtocols, &lvi); mir_free((char *)lvi.lParam); } break; } } break; } return 0; }
void CluiProtocolStatusChanged(int, const char*) { int maxOnline = 0, onlineness = 0; WORD maxStatus = ID_STATUS_OFFLINE; DBVARIANT dbv = { 0 }; int iIcon = 0; HICON hIcon = 0; int rdelta = cfg::dat.bCLeft + cfg::dat.bCRight; BYTE windowStyle; if (pcli->hwndStatus == 0 || cfg::shutDown) return; int protoCount; PROTOACCOUNT **accs; Proto_EnumAccounts(&protoCount, &accs); if (protoCount == 0) return; FreeProtocolData(); g_maxStatus = ID_STATUS_OFFLINE; g_maxProto[0] = 0; int borders[3]; SendMessage(pcli->hwndStatus, SB_GETBORDERS, 0, (LPARAM)&borders); int *partWidths = (int*)_alloca((protoCount + 1)*sizeof(int)); int partCount; if (cfg::dat.bEqualSections) { RECT rc; GetClientRect(pcli->hwndStatus, &rc); rc.right -= borders[0] * 2; int toshow = 0; for (int i = 0; i < protoCount; i++) if (pcli->pfnGetProtocolVisibility(accs[i]->szModuleName)) toshow++; if (toshow > 0) { for (int part = 0, i = 0; i < protoCount; i++) { if (!pcli->pfnGetProtocolVisibility(accs[i]->szModuleName)) continue; partWidths[part] = ((rc.right - rc.left - rdelta) / toshow)*(part + 1) + cfg::dat.bCLeft; if (part == toshow - 1) partWidths[part] += cfg::dat.bCRight; part++; } } partCount = toshow; } else { SIZE textSize; BYTE showOpts = cfg::getByte("CLUI", "SBarShow", 1); TCHAR szName[32]; HDC hdc = GetDC(NULL); HFONT hofont = reinterpret_cast<HFONT>(SelectObject(hdc, (HFONT)SendMessage(pcli->hwndStatus, WM_GETFONT, 0, 0))); // count down since built in ones tend to go at the end partCount = 0; for (int i = 0; i < protoCount; i++) { int idx = pcli->pfnGetAccountIndexByPos(i); if (idx == -1) continue; PROTOACCOUNT *pa = accs[idx]; if (!pcli->pfnGetProtocolVisibility(pa->szModuleName)) continue; int x = 2; if (showOpts & 1) x += 16; if (showOpts & 2) { mir_tstrncpy(szName, pa->tszAccountName, _countof(szName)); szName[_countof(szName) - 1] = 0; if ((showOpts & 4) && mir_tstrlen(szName) < sizeof(szName) - 1) mir_tstrcat(szName, _T(" ")); GetTextExtentPoint32(hdc, szName, (int)mir_tstrlen(szName), &textSize); x += textSize.cx + GetSystemMetrics(SM_CXBORDER) * 4; // The SB panel doesnt allocate enough room } if (showOpts & 4) { TCHAR* modeDescr = pcli->pfnGetStatusModeDescription(CallProtoService(accs[i]->szModuleName, PS_GETSTATUS, 0, 0), 0); GetTextExtentPoint32(hdc, modeDescr, (int)mir_tstrlen(modeDescr), &textSize); x += textSize.cx + GetSystemMetrics(SM_CXBORDER) * 4; // The SB panel doesnt allocate enough room } partWidths[partCount] = (partCount ? partWidths[partCount - 1] : cfg::dat.bCLeft) + x + 2; partCount++; } SelectObject(hdc, hofont); ReleaseDC(NULL, hdc); } if (partCount == 0) { SendMessage(pcli->hwndStatus, SB_SIMPLE, TRUE, 0); return; } SendMessage(pcli->hwndStatus, SB_SIMPLE, FALSE, 0); partWidths[partCount - 1] = -1; windowStyle = cfg::getByte("CLUI", "WindowStyle", 0); SendMessage(pcli->hwndStatus, SB_SETMINHEIGHT, 18 + cfg::dat.bClipBorder + ((windowStyle == SETTING_WINDOWSTYLE_THINBORDER || windowStyle == SETTING_WINDOWSTYLE_NOBORDER) ? 3 : 0), 0); SendMessage(pcli->hwndStatus, SB_SETPARTS, partCount, (LPARAM)partWidths); // count down since built in ones tend to go at the end char *szMaxProto = NULL; partCount = 0; for (int i = 0; i < protoCount; i++) { int idx = pcli->pfnGetAccountIndexByPos(i); if (idx == -1) continue; PROTOACCOUNT *pa = accs[idx]; if (!pcli->pfnGetProtocolVisibility(pa->szModuleName)) continue; int status = CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0); ProtocolData *PD = (ProtocolData*)mir_alloc(sizeof(ProtocolData)); PD->RealName = mir_strdup(pa->szModuleName); PD->protopos = partCount; { int flags; flags = SBT_OWNERDRAW; if (cfg::getByte("CLUI", "SBarBevel", 1) == 0) flags |= SBT_NOBORDERS; SendMessageA(pcli->hwndStatus, SB_SETTEXTA, partCount | flags, (LPARAM)PD); } int caps2 = CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0); int caps1 = CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0); if ((caps1 & PF1_IM) && (caps2 & (PF2_LONGAWAY | PF2_SHORTAWAY))) { onlineness = GetStatusOnlineness(status); if (onlineness > maxOnline) { maxStatus = status; maxOnline = onlineness; szMaxProto = pa->szModuleName; } } partCount++; } // update the clui button WORD wStatus = 0; if (!db_get(NULL, "CList", "PrimaryStatus", &dbv)) { if (dbv.type == DBVT_ASCIIZ && mir_strlen(dbv.pszVal) > 1) { wStatus = (WORD)CallProtoService(dbv.pszVal, PS_GETSTATUS, 0, 0); iIcon = IconFromStatusMode(dbv.pszVal, (int)wStatus, 0, &hIcon); } mir_free(dbv.pszVal); } else { wStatus = maxStatus; iIcon = IconFromStatusMode((wStatus >= ID_STATUS_CONNECTING && wStatus < ID_STATUS_OFFLINE) ? szMaxProto : NULL, (int)wStatus, 0, &hIcon); g_maxStatus = (int)wStatus; if (szMaxProto) strncpy_s(g_maxProto, _countof(g_maxProto), szMaxProto, _TRUNCATE); } /* * this is used globally (actually, by the clist control only) to determine if * any protocol is "in connection" state. If true, then the clist discards redraws * and uses timer based sort and redraw handling. This can improve performance * when connecting multiple protocols significantly. */ TCHAR *szStatus = pcli->pfnGetStatusModeDescription(wStatus, 0); /* * set the global status icon and display the global (most online) status mode on the * status mode button */ if (szStatus && pcli->hwndContactList) { HWND hwndClistBtn = GetDlgItem(pcli->hwndContactList, IDC_TBGLOBALSTATUS); if (IsWindow(hwndClistBtn)) { SetWindowText(hwndClistBtn, szStatus); if (!hIcon) SendMessage(hwndClistBtn, BUTTONSETIMLICON, (WPARAM)hCListImages, (LPARAM)iIcon); else SendMessage(hwndClistBtn, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); InvalidateRect(hwndClistBtn, NULL, TRUE); } HWND hwndTtbStatus = ClcGetButtonWindow(IDC_TBTOPSTATUS); if (IsWindow(hwndTtbStatus)) { if (g_ButtonItems == NULL) { if (!hIcon) SendMessage(hwndTtbStatus, BUTTONSETIMLICON, (WPARAM)hCListImages, (LPARAM)iIcon); else SendMessage(hwndTtbStatus, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); } InvalidateRect(hwndTtbStatus, NULL, TRUE); } } }
int cliTrayIconInit(HWND hwnd) { BYTE Mode; if (pcli->trayIconCount != 0) return 0; if (TimerID) { KillTimer(NULL, TimerID); TimerID = 0; } // Присутствуют ли в базе новые настройки? Если да, то обновление не нужно. if (-1 == db_get_b(NULL, "CList", "tiModeS", -1)) SettingsMigrate(); // Нужно узнать количество годных аккаунтов и неодинаковость их статусов. bool bDiffers; pcli->trayIconCount = GetGoodAccNum(&bDiffers, NULL); // Если таковых аккаунтов не нашлось вообще, то будем показывать основную иконку Миранды. if (!pcli->trayIconCount) { pcli->trayIconCount = 1; pcli->trayIcon = (trayIconInfo_t*)mir_calloc(sizeof(trayIconInfo_t) * pcli->trayIconCount); pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); OldMode = TRAY_ICON_MODE_GLOBAL; return 0; } if (!bDiffers) // all equal OldMode = Mode = db_get_b(NULL, "CList", "tiModeS", TRAY_ICON_MODE_GLOBAL); else OldMode = Mode = db_get_b(NULL, "CList", "tiModeV", TRAY_ICON_MODE_GLOBAL); // Некоторые режимы всегда показывают единственную иконку. if (Mode < 8) pcli->trayIconCount = 1; pcli->trayIcon = (trayIconInfo_t*)mir_calloc(sizeof(trayIconInfo_t) * pcli->trayIconCount); // Добавляем иконки. switch (Mode) { case TRAY_ICON_MODE_GLOBAL: pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); break; case TRAY_ICON_MODE_ACC: { ptrA szProto(db_get_sa(NULL, "CList", (!bDiffers) ? "tiAccS" : "tiAccV")); if (!szProto) break; PROTOACCOUNT *pa = Proto_GetAccount(szProto); if (!pa || !pa->ppro) pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); else pcli->pfnTrayIconAdd(hwnd, pa->szModuleName, NULL, pa->ppro->m_iStatus); } break; case TRAY_ICON_MODE_CYCLE: pcli->pfnTrayIconAdd(hwnd, NULL, NULL, CListTray_GetGlobalStatus(0, 0)); pcli->cycleStep = 0; cliTrayCycleTimerProc(0, 0, 0, 0); // force icon update // Не сохраняем ID таймера в pcli, чтобы fnTrayIconUpdateBase не убивала его. TimerID = CLUI_SafeSetTimer(NULL, 0, db_get_w(NULL, "CList", "CycleTime", SETTING_CYCLETIME_DEFAULT) * 1000, cliTrayCycleTimerProc); break; case TRAY_ICON_MODE_ALL: PROTOACCOUNT **acc; int AccNum, i; Proto_EnumAccounts(&AccNum, &acc); for (i = AccNum; i--;) { if (!acc[i]->bIsVirtual && acc[i]->bIsVisible && !acc[i]->bDynDisabled && acc[i]->ppro) pcli->pfnTrayIconAdd(hwnd, acc[i]->szModuleName, NULL, acc[i]->ppro->m_iStatus); } break; } return 0; }