Exemplo n.º 1
0
void Cache_GetFirstLineText(ClcData *dat, ClcContact *contact)
{
	if (GetCurrentThreadId() != g_dwMainThreadID)
		return;

	ClcCacheEntry *pdnce = contact->pce;
	wchar_t *name = Clist_GetContactDisplayName(contact->hContact);
	if (dat->first_line_append_nick && !dat->bForceInDialog) {
		DBVARIANT dbv = { 0 };
		if (!db_get_ws(pdnce->hContact, pdnce->szProto, "Nick", &dbv)) {
			wchar_t nick[_countof(contact->szText)];
			mir_wstrncpy(nick, dbv.ptszVal, _countof(contact->szText));
			db_free(&dbv);

			// They are the same -> use the name to keep the case
			if (mir_wstrcmpi(name, nick) == 0)
				mir_wstrncpy(contact->szText, name, _countof(contact->szText));
			else // Append then
				mir_snwprintf(contact->szText, L"%s - %s", name, nick);
		}
		else mir_wstrncpy(contact->szText, name, _countof(contact->szText));
	}
	else mir_wstrncpy(contact->szText, name, _countof(contact->szText));

	if (!dat->bForceInDialog)
		contact->ssText.ReplaceSmileys(dat, pdnce, contact->szText, dat->first_line_draw_smileys);
}
Exemplo n.º 2
0
int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2)
{
	ClcCacheEntry *c1 = contact1->pce, *c2 = contact2->pce;

	for (int i = 0; i < _countof(g_CluiData.bSortByOrder); i++) {
		BYTE &by = g_CluiData.bSortByOrder[i];

		if (by == SORTBY_STATUS) { //status
			int ordera = GetStatusModeOrdering(c1->getStatus());
			int orderb = GetStatusModeOrdering(c2->getStatus());
			if (ordera == orderb)
				continue;
			return ordera - orderb;
		}

		// one is offline: offline goes below online
		if (!g_CluiData.fSortNoOfflineBottom) {
			int statusa = c1->getStatus();
			int statusb = c2->getStatus();
			if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE))
				return 2 * (statusa == ID_STATUS_OFFLINE) - 1;
		}

		int r = 0;

		switch (by) {
		case SORTBY_NAME: // name
			r = mir_wstrcmpi(contact1->szText, contact2->szText);
			break;

		case SORTBY_NAME_LOCALE: // name
			if (LocaleId == -1)
				LocaleId = Langpack_GetDefaultLocale();
			r = CompareString(LocaleId, NORM_IGNORECASE, SAFETSTRING(contact1->szText), -1, SAFETSTRING(contact2->szText), -1) - 2;
			break;

		case SORTBY_LASTMSG: // last message
			r = (int)CompareContacts2_getLMTime(contact2->hContact) - (int)CompareContacts2_getLMTime(contact1->hContact);
			break;

		case SORTBY_PROTO:
			if (contact1->proto == nullptr || contact2->proto == nullptr)
				continue;
			r = GetProtoIndex(contact1->proto) - GetProtoIndex(contact2->proto);
			break;

		case SORTBY_RATE:
			r = contact2->bContactRate - contact1->bContactRate; // reverse order 
			break;

		default: // should never happen
			continue;
		}

		if (r != 0)
			return r;
	}
	return 0;
}
Exemplo n.º 3
0
void CToxOptionsMultimedia::EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *pEnumerator, EDataFlow dataFlow, const char* setting)
{
	LPWSTR pwszDefID = NULL;
	ptrW wszDefID(m_proto->getWStringA(setting));
	if (wszDefID != NULL)
	{
		size_t len = mir_wstrlen(wszDefID) + 1;
		pwszDefID = (LPWSTR)CoTaskMemAlloc(len*2);
		mir_wstrncpy(pwszDefID, wszDefID, len);
	}
	else
	{
		CComPtr<IMMDevice> pDevice = NULL;
		if (FAILED(pEnumerator->GetDefaultAudioEndpoint(dataFlow, eConsole, &pDevice))) return;
		if (FAILED(pDevice->GetId(&pwszDefID))) return;
	}

	CComPtr<IMMDeviceCollection> pDevices = NULL;
	EXIT_ON_ERROR(pEnumerator->EnumAudioEndpoints(dataFlow, DEVICE_STATE_ACTIVE, &pDevices));

	UINT count;
	EXIT_ON_ERROR(pDevices->GetCount(&count));

	for (UINT i = 0; i < count; i++)
	{
		CComPtr<IMMDevice> pDevice = NULL;
		EXIT_ON_ERROR(pDevices->Item(i, &pDevice));

		CComPtr<IPropertyStore> pProperties = NULL;
		EXIT_ON_ERROR(pDevice->OpenPropertyStore(STGM_READ, &pProperties));

		PROPVARIANT varName;
		PropVariantInit(&varName);
		EXIT_ON_ERROR(pProperties->GetValue(PKEY_Device_FriendlyName, &varName));

		LPWSTR pwszID = NULL;
		EXIT_ON_ERROR(pDevice->GetId(&pwszID));
		combo.InsertString(varName.pwszVal, i, (LPARAM)mir_wstrdup(pwszID));
		if (mir_wstrcmpi(pwszID, pwszDefID) == 0)
			combo.SetCurSel(i);
		CoTaskMemFree(pwszID);

		PropVariantClear(&varName);
	}

Exit:
	CoTaskMemFree(pwszDefID);
}
Exemplo n.º 4
0
static void WinNT_PollThread(void *vparam)
{
	CpuUsageThreadParams *param = (CpuUsageThreadParams*)vparam;

	DWORD dwBufferSize=0,dwCount;
	BYTE *pBuffer=NULL;
	PERF_DATA_BLOCK *pPerfData=NULL; 
	LONG res,lCount;
	PERF_OBJECT_TYPE *pPerfObj;
	PERF_COUNTER_DEFINITION *pPerfCounter; 
	PERF_INSTANCE_DEFINITION *pPerfInstance; 
	PERF_COUNTER_BLOCK *pPerfCounterBlock;
	DWORD dwObjectId,dwCounterId; 
	WCHAR wszValueName[11],*pwszInstanceName;
	BYTE nCpuUsage;
	BOOL fSwitched,fFound,fIsFirst=FALSE;
	LARGE_INTEGER liPrevCounterValue={0},liCurrentCounterValue={0},liPrevPerfTime100nSec={0};

	/* init */
	dwObjectId=238;             /*'Processor' object */
	dwCounterId=6;              /* '% processor time' counter */
	pwszInstanceName=L"_Total"; /* '_Total' instance */
	_itot_s(dwObjectId, wszValueName, 10);
	fSwitched = WinNT_PerfStatsSwitch(_T("PerfOS"), FALSE);

	/* poll */
	for(;;) {
		/* retrieve data for given object */
		res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,(BYTE*)pPerfData,&dwBufferSize);
		while(!pBuffer || res==ERROR_MORE_DATA) {
			pBuffer=(BYTE*)mir_realloc(pPerfData,dwBufferSize+=256);
			if (!pBuffer) break;
			pPerfData=(PERF_DATA_BLOCK*)pBuffer;
			res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,pBuffer,&dwBufferSize);
		}
		if (res != ERROR_SUCCESS) break;

		/* find object in data */
		fFound=FALSE;
		/* first object */
		pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfData+pPerfData->HeaderLength);
		for(dwCount=0;dwCount<pPerfData->NumObjectTypes;++dwCount) {
			if (pPerfObj->ObjectNameTitleIndex==dwObjectId) {
				/* find counter in object data */
				/* first counter */
				pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->HeaderLength);
				for(dwCount=0;dwCount<(pPerfObj->NumCounters);++dwCount) { 
					if (pPerfCounter->CounterNameTitleIndex==dwCounterId) {
						/* find instance in counter data */
						if (pPerfObj->NumInstances==PERF_NO_INSTANCES) { 
							pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
							liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
							fFound=TRUE;
						}
						else {
							/* first instance */
							pPerfInstance=(PERF_INSTANCE_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
							for(lCount=0;lCount<(pPerfObj->NumInstances);++lCount) {
								pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfInstance+pPerfInstance->ByteLength);
								if (!mir_wstrcmpi(pwszInstanceName,(WCHAR*)((BYTE*)pPerfInstance+pPerfInstance->NameOffset))) {
									liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
									fFound=TRUE;
									break;
								}
								/* next instance */
								pPerfInstance=(PPERF_INSTANCE_DEFINITION)((BYTE*)pPerfCounterBlock+pPerfCounterBlock->ByteLength);
							} 
						} 
						break;
					}
					/* next counter */
					pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfCounter+pPerfCounter->ByteLength);
				}
				break; 
			} 
			/* next object */
			pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfObj+pPerfObj->TotalByteLength);
		}
		if (!fFound) break;

		/* calc val from data, we need two samplings
		 * counter type: PERF_100NSEC_TIMER_INV
		 * calc: time base=100Ns, value=100*(1-(data_diff)/(100NsTime_diff)) */
		if (!fIsFirst) {
			nCpuUsage=(BYTE)((1.0-(Li2Double(liCurrentCounterValue)-Li2Double(liPrevCounterValue))/(Li2Double(pPerfData->PerfTime100nSec)-Li2Double(liPrevPerfTime100nSec)))*100.0+0.5);
			if (!CallBackAndWait(param,nCpuUsage)) break;
		}
		else fIsFirst=FALSE;
		/* store current sampling for next */
		memcpy(&liPrevCounterValue,&liCurrentCounterValue,sizeof(LARGE_INTEGER)); 
		memcpy(&liPrevPerfTime100nSec,&pPerfData->PerfTime100nSec,sizeof(LARGE_INTEGER)); 
	}

	/* uninit */
	if (pPerfData) mir_free(pPerfData);
	if (fSwitched) WinNT_PerfStatsSwitch(_T("PerfOS"),TRUE);

	/* return error for PollCpuUsage() if never succeeded */
	if (param->hFirstEvent != NULL) SetEvent(param->hFirstEvent);
	mir_free(param);
}