Exemplo n.º 1
0
void __stdcall	ShowPopup(TCHAR *line1, TCHAR *line2, int flags)
{
	if (CallService(MS_SYSTEM_TERMINATED, 0, 0)) return;

	if (ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
		ShowClassPopupT("pingpopups", line1, line2);
	}
	else if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
		POPUPDATAT *ppd = (POPUPDATAT*)calloc(sizeof(POPUPDATAT), 1);

		ppd->lchContact = NULL;
		ppd->lchIcon = (flags ? hIconResponding : hIconNotResponding);
		mir_tstrncpy(ppd->lptzContactName, line1, _countof(ppd->lptzContactName));
		mir_tstrncpy(ppd->lptzText, line2, _countof(ppd->lptzText));

		ppd->colorBack = GetSysColor(COLOR_BTNFACE);
		ppd->colorText = GetSysColor(COLOR_WINDOWTEXT);
		ppd->iSeconds = 10;

		ppd->PluginWindowProc = NullWindowProc;
		ppd->PluginData = NULL;

		QueueUserAPC(sttMainThreadCallback, mainThread, (ULONG_PTR)ppd);
	}
	else{
		MessageBox(NULL, line2, _T(PLUG) _T(" Message"), MB_OK | MB_ICONINFORMATION);
		return;
	}
}
Exemplo n.º 2
0
void MirandaUtils::setStatusOnAccount(ActionThreadArgStruct* args)
{

	logger->log(L"MirandaUtils::setStatusOnAccount: start");
	int status = CallProtoService(args->accountSzModuleName, PS_GETSTATUS, 0, 0);
	logger->log_p(L"SSOA: on account: [%S]  targetHandle = [" SCNuPTR L"]   at status = [%d]", args->accountSzModuleName, args->targetHandle, status);

	int result = -1;

	if (!(CallProtoService(args->accountSzModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_INDIVMODEMSG)){
		result = CallProtoService(args->accountSzModuleName, PS_SETAWAYMSGW, (WPARAM)status, (LPARAM)args->userActionSelection);
		if (result == CALLSERVICE_NOTFOUND){
			char *szMsg = mir_u2a(args->userActionSelection);
			result = CallProtoService(args->accountSzModuleName, PS_SETAWAYMSG, (WPARAM)status, (LPARAM)szMsg);
			mir_free(szMsg);
		}
	}

	MirandaAccount* mirandaAccount = args->mirfoxDataPtr->getMirandaAccountPtrBySzModuleName(args->accountSzModuleName);
	TCHAR* tszAccountName = NULL;
	if (mirandaAccount){
		tszAccountName = mirandaAccount->tszAccountName;
	}

	wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)];
	if(result == 0){

		if (tszAccountName != NULL){
			logger->log_p(L"SSOA: Status message set on [%s]", tszAccountName);
			mir_sntprintf(buffer, 1024, TranslateT("Status message set on %s"), tszAccountName);
		} else {
			logger->log(L"SSOA: Status message set");
			buffer = mir_wstrdup(TranslateT("Status message set"));
		}

		if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
			ShowClassPopupT("MirFox_Notify", TranslateT("MirFox"), buffer);
		} else {
			PUShowMessageT(buffer, SM_NOTIFY);
		}

	} else {

		if (tszAccountName != NULL){
			logger->log_p(L"SSOA: ERROR - Cannot set status message 2 on [%s] - result = [%d] ", tszAccountName, result);
			mir_sntprintf(buffer, 1024, TranslateT("Cannot set status message on %s"), tszAccountName);
		} else {
			logger->log_p(L"SSOA: ERROR - Cannot set status message 2 - result = [%d] ", result);
			buffer = mir_wstrdup(TranslateT("Cannot set status message"));
		}

		if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
			ShowClassPopupT("MirFox_Error", TranslateT("MirFox error"), buffer);
		} else {
			PUShowMessageT(buffer, SM_WARNING);
		}

	}
	delete buffer;

}
Exemplo n.º 3
0
void MirandaUtils::sendMessage(ActionThreadArgStruct* args, MFENUM_SEND_MESSAGE_MODE mode)
{

	logger->log_p(L"MirandaUtils::sendMessage: mode = [%d]  to = [" SCNuPTR L"]  msg = [%s]", mode, args->targetHandle, args->userActionSelection );

	if (mode == MFENUM_SMM_ONLY_SEND || mode == MFENUM_SMM_SEND_AND_SHOW_MW){

		//TODO - metacontacts support - C:\MIRANDA\SOURCES\PLUGINS\popup_trunk\src\popup_wnd2.cpp : 1083
		//	//check for MetaContact and get szProto from subcontact
		//	if(strcmp(targetHandleSzProto, gszMetaProto)==0) {
		//		HANDLE hSubContact = (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT, (WPARAM)hContact, 0);
		//		if(!hSubContact) return FALSE;
		//		targetHandleSzProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hSubContact, 0);
		//	}

		char* targetHandleSzProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)args->targetHandle, 0); //targetHandleSzProto doesnt need mir_free or delete
		if (targetHandleSzProto == NULL){
			logger->log(L"MirandaUtils::sendMessageToContact: ERROR targetHandleSzProto == NULL");
			return;
		}

		int mirandaSendModeFlag = getMirandaSendModeFlag(targetHandleSzProto);

		char* msgBuffer = NULL;
		std::size_t bufSize = 0;

		if (mirandaSendModeFlag == PREF_UTF){

			msgBuffer = mir_utf8encodeW(args->userActionSelection);
			bufSize = strlen(msgBuffer) + 1;

		} else if (mirandaSendModeFlag == PREF_UNICODE){

			msgBuffer = mir_t2a(args->userActionSelection);
			bufSize = strlen(msgBuffer) + 1;
			size_t bufSizeT = (wcslen(args->userActionSelection) + 1) * sizeof(wchar_t);
			msgBuffer = (char*)mir_realloc(msgBuffer, bufSizeT + bufSize);
			memcpy((wchar_t*)&msgBuffer[bufSize], args->userActionSelection, bufSizeT);
			bufSize += bufSizeT;

		}

		logger->log_p(L"SMTC: mirandaSendModeFlag = [%d]  bufSize = [%d]", mirandaSendModeFlag, bufSize);
		HANDLE hProcess = sendMessageMiranda(args->targetHandle, mirandaSendModeFlag, msgBuffer);
		logger->log_p(L"SMTC: hProcess = [" SCNuPTR L"]", hProcess);

		MIRFOXACKDATA* myMfAck = NULL;

		if (hProcess != NULL){
			//if hProcess of sending process is null there will not be any ack

			EnterCriticalSection(&ackMapCs);
			ackMap[hProcess] = (MIRFOXACKDATA*)NULL;
			LeaveCriticalSection(&ackMapCs);

			int counter = 0;
			const int ACK_WAIT_TIME = 250;			//[ms]
			const int MAX_ACK_WAIT_COUNTER = 40;	//40 * 250ms = 10s

			do {
				SleepEx(ACK_WAIT_TIME, TRUE);
				counter++;
				EnterCriticalSection(&ackMapCs);
				myMfAck = ackMap[hProcess];
				LeaveCriticalSection(&ackMapCs);
				if(Miranda_Terminated() || args->mirfoxDataPtr->Plugin_Terminated){
					logger->log_p(L"SMTC: ACK break by Plugin_Terminated (=%d) or Miranda_Terminated()", args->mirfoxDataPtr->Plugin_Terminated);
					break;
				}
			} while (myMfAck == NULL && counter <= MAX_ACK_WAIT_COUNTER); //TODO or Plugin_Terminated or Miranda_Terminated()

			logger->log_p(L"SMTC: ACK found  counter = [%d]   myMfAck = [" SCNuPTR L"]", counter, myMfAck);

		}


		MirandaContact* mirandaContact = args->mirfoxDataPtr->getMirandaContactPtrByHandle(args->targetHandle);
		const wchar_t* contactNameW = NULL;
		TCHAR* tszAccountName = NULL;
		if (mirandaContact){
			contactNameW = mirandaContact->contactNameW.c_str();
			MirandaAccount* mirandaAccount = mirandaContact->mirandaAccountPtr;
			if (mirandaAccount){
				tszAccountName = mirandaAccount->tszAccountName;
			}
		}

		if(myMfAck != NULL && myMfAck->result == ACKRESULT_SUCCESS){

			addMessageToDB(args->targetHandle, mirandaSendModeFlag, msgBuffer, bufSize, targetHandleSzProto);

			if (mode == MFENUM_SMM_ONLY_SEND){

				//show notyfication popup (only in SMM_ONLY_SEND mode)
				wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)];
				if (contactNameW != NULL && tszAccountName != NULL){
					mir_sntprintf(buffer, 1024, TranslateT("Message sent to %s (%s)"), contactNameW, tszAccountName);
				} else {
					buffer = mir_wstrdup(TranslateT("Message sent"));
				}

				if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
					ShowClassPopupT("MirFox_Notify", TranslateT("MirFox"), buffer);
				} else {
					PUShowMessageT(buffer, SM_NOTIFY);
				}

				delete buffer;

			} else if (mode == MFENUM_SMM_SEND_AND_SHOW_MW){

				//notify hook to open window
				if (args->mirfoxDataPtr != NULL && args->mirfoxDataPtr->hhook_EventOpenMW != NULL){

					OnHookOpenMvStruct* onHookOpenMv = new(OnHookOpenMvStruct);
					onHookOpenMv->targetHandle = args->targetHandle;
					onHookOpenMv->msgBuffer = NULL;
					NotifyEventHooks(args->mirfoxDataPtr->hhook_EventOpenMW, (WPARAM)onHookOpenMv, (LPARAM)NULL);

				} else {

					logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL");

				}

			}

		} else {

			//error - show error popup
			wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)];
			if (myMfAck != NULL){
				logger->log_p(L"SMTC: ERROR - Cannot send message - result = [%d] ", myMfAck->result);
				if (myMfAck->errorDesc != NULL){
					if (contactNameW != NULL && tszAccountName != NULL){
						mir_sntprintf(buffer, 1024, TranslateT("Cannot send message to %s (%s) - %S"), contactNameW, tszAccountName, myMfAck->errorDesc);
					} else {
						mir_sntprintf(buffer, 1024, TranslateT("Cannot send message - %S"), myMfAck->errorDesc);
					}
				} else {
					if (contactNameW != NULL && tszAccountName != NULL){
						mir_sntprintf(buffer, 1024, TranslateT("Cannot send message to %s (%s)"), contactNameW, tszAccountName);
					} else {
						buffer = mir_wstrdup(TranslateT("Cannot send message - %S"));
					}
				}

			} else {
				logger->log(L"SMTC: ERROR - Cannot send message 2");
				if (contactNameW != NULL && tszAccountName != NULL){
					mir_sntprintf(buffer, 1024, TranslateT("Cannot send message to %s (%s)"), contactNameW, tszAccountName);
				} else {
					buffer = mir_wstrdup(TranslateT("Cannot send message"));
				}
			}

			if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
				ShowClassPopupT("MirFox_Error", TranslateT("MirFox error"), buffer);
			} else {
				PUShowMessageT(buffer, SM_WARNING);
			}

			delete buffer;

		}

		if (myMfAck != NULL){ //when we found ack, not when we exceed MAX_ACK_WAIT_COUNTER
			if (myMfAck->errorDesc != NULL) delete myMfAck->errorDesc;
			delete myMfAck->szModule;
			delete myMfAck;
		}
		EnterCriticalSection(&ackMapCs);
		ackMap.erase(hProcess);
		LeaveCriticalSection(&ackMapCs);

		mir_free(msgBuffer);

	} else if (mode == MFENUM_SMM_ONLY_SHOW_MW){

		//notify hook to open window
		if (args->mirfoxDataPtr != NULL && args->mirfoxDataPtr->hhook_EventOpenMW != NULL){

			OnHookOpenMvStruct* onHookOpenMv = new(OnHookOpenMvStruct);
			onHookOpenMv->targetHandle = args->targetHandle;
			//adding newline to message in Message Window, only in this mode
			std::wstring* msgBuffer = new std::wstring(); //deleted at on_hook_OpenMW
			msgBuffer->append(args->userActionSelection);
			msgBuffer->append(L"\r\n");
			onHookOpenMv->msgBuffer = msgBuffer;
			NotifyEventHooks(args->mirfoxDataPtr->hhook_EventOpenMW, (WPARAM)onHookOpenMv, (LPARAM)NULL);

		} else {
			logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL");
		}

	}

}