void showPopup(LPCSTR lpzText,HANDLE hContact,HICON hIcon, UINT type)
{
	//type=0 key colors
	//type=1 session colors
	//type=2 SR colors

	if (!bPopupExists) return;

	COLORREF colorBack, colorText;
	int timeout=0;

	DBVARIANT dbv;

	if (type == 0) {
		colorBack = db_get_dw(0, MODULENAME, "colorKeyb", RGB(230,230,255));
		colorText = db_get_dw(0, MODULENAME, "colorKeyt", RGB(0,0,0));
		if (!db_get_s(0, MODULENAME, "timeoutKey", &dbv)) {
			timeout = atoi(dbv.pszVal);
			db_free(&dbv);
		}
	}
	else if (type == 1) {
		colorBack = db_get_dw(0, MODULENAME, "colorSecb", RGB(255,255,200));
		colorText = db_get_dw(0, MODULENAME, "colorSect", RGB(0,0,0));
		if (!db_get_s(0, MODULENAME, "timeoutSec" ,&dbv)) {
			timeout = atoi(dbv.pszVal);
			db_free(&dbv);
		}
	}
	else if (type >= 2) {
		colorBack = db_get_dw(0, MODULENAME, "colorSRb", RGB(200,255,200));
		colorText = db_get_dw(0, MODULENAME, "colorSRt", RGB(0,0,0));
		if (!db_get_s(0, MODULENAME, "timeoutSR", &dbv)) {
			timeout = atoi(dbv.pszVal);
			db_free(&dbv);
		}
	}

	POPUPDATAW ppd = {0};
	ppd.lchContact = hContact; //Be sure to use a GOOD handle, since this will not be checked.
	ppd.lchIcon = hIcon;
	LPWSTR lpwzContactName = (LPWSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME,(WPARAM)hContact,GSMDF_UNICODE);
	wcscpy(ppd.lpwzContactName, lpwzContactName);
	LPWSTR lpwzText = mir_a2u(lpzText);
	wcscpy(ppd.lpwzText, TranslateW(lpwzText));
	mir_free(lpwzText);
	ppd.colorBack = colorBack;
	ppd.colorText = colorText;
	ppd.iSeconds = timeout;
	PUAddPopupW(&ppd);
}
Exemple #2
0
int PopupShow(PLUGIN_OPTIONS* pluginOptions, MCONTACT hContact, MEVENT hEvent, UINT eventType)
{
	TCHAR* sampleEvent;
	long iSeconds;

	//there has to be a maximum number of popups shown at the same time
	if (PopupCount >= MAX_POPUPS)
		return 2;

	//check if we should report this kind of event
	//get the prefered icon as well
	//CHANGE: iSeconds is -1 because I use my timer to hide popup
	POPUPDATAW pudw;
	pudw.iSeconds = -1; 

	switch (eventType) {
	case EVENTTYPE_MESSAGE:
		if (!(pluginOptions->maskNotify & MASK_MESSAGE)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
		pudw.colorBack = pluginOptions->bDefaultColorMsg ? 0 : pluginOptions->colBackMsg;
		pudw.colorText = pluginOptions->bDefaultColorMsg ? 0 : pluginOptions->colTextMsg;
		iSeconds = pluginOptions->iDelayMsg;
		sampleEvent = TranslateT("This is a sample message event :-)");
		break;

	case EVENTTYPE_URL:
		if (!(pluginOptions->maskNotify & MASK_URL)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_URL);
		pudw.colorBack = pluginOptions->bDefaultColorUrl ? 0 : pluginOptions->colBackUrl;
		pudw.colorText = pluginOptions->bDefaultColorUrl ? 0 : pluginOptions->colTextUrl;
		iSeconds = pluginOptions->iDelayUrl;
		sampleEvent = TranslateT("This is a sample URL event ;-)");
		break;

	case EVENTTYPE_FILE:
		if (!(pluginOptions->maskNotify & MASK_FILE)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_EVENT_FILE);
		pudw.colorBack = pluginOptions->bDefaultColorFile ? 0 : pluginOptions->colBackFile;
		pudw.colorText = pluginOptions->bDefaultColorFile ? 0 : pluginOptions->colTextFile;
		iSeconds = pluginOptions->iDelayFile;
		sampleEvent = TranslateT("This is a sample file event :-D");
		break;

	default:
		if (!(pluginOptions->maskNotify & MASK_OTHER)) return 1;
		pudw.lchIcon = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
		pudw.colorBack = pluginOptions->bDefaultColorOthers ? 0 : pluginOptions->colBackOthers;
		pudw.colorText = pluginOptions->bDefaultColorOthers ? 0 : pluginOptions->colTextOthers;
		iSeconds = pluginOptions->iDelayOthers;
		sampleEvent = TranslateT("This is a sample other event ;-D");
		break;
	}

	//get DBEVENTINFO with pBlob if preview is needed (when is test then is off)
	DBEVENTINFO dbe = { sizeof(dbe) };
	if (hEvent) {
		if ((pluginOptions->bPreview || eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST)) {
			dbe.cbBlob = db_event_getBlobSize(hEvent);
			dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob);
		}
		db_event_get(hEvent, &dbe);
	}

	EVENT_DATA_EX *eventData = (EVENT_DATA_EX*)mir_alloc(sizeof(EVENT_DATA_EX));
	eventData->hEvent = hEvent;
	eventData->number = 1;
	eventData->next = NULL;
	eventData->prev = NULL;

	// retrieve correct hContact for AUTH events
	if (dbe.pBlob && (eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST))
		hContact = DbGetAuthEventContact(&dbe);

	// set plugin_data ... will be usable within PopupDlgProc
	PLUGIN_DATA *pdata = (PLUGIN_DATA*)mir_alloc(sizeof(PLUGIN_DATA));
	pdata->eventType = eventType;
	pdata->hContact = hContact;
	pdata->pluginOptions = pluginOptions;
	pdata->countEvent = 1;
	pdata->iLock = 0;
	pdata->iSeconds = (iSeconds > 0) ? iSeconds : pluginOptions->iDelayDefault;
	pdata->firstEventData = pdata->firstShowEventData = pdata->lastEventData = eventData;

	// finally create the popup
	pudw.lchContact = hContact;
	pudw.PluginWindowProc = PopupDlgProc;
	pudw.PluginData = pdata;

	// if hContact is NULL, && hEvent is NULL then popup is only Test
	if ((hContact == NULL) && (hEvent == NULL)) {
		_tcsncpy(pudw.lptzContactName, TranslateT("Plugin Test"), MAX_CONTACTNAME);
		_tcsncpy(pudw.lptzText, TranslateTS(sampleEvent), MAX_SECONDLINE);
	}
	else { // get the needed event data
		_tcsncpy(pudw.lptzContactName, (TCHAR*)pcli->pfnGetContactDisplayName(hContact, 0), MAX_CONTACTNAME);
		_tcsncpy(pudw.lptzText, ptrT(GetEventPreview(&dbe)), MAX_SECONDLINE);
	}

	PopupCount++;

	PopupList[NumberPopupData(NULL, -1)] = pdata;
	// send data to popup plugin

	if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
		// popup creation failed, release popupdata
		if (PUAddPopupW(&pudw) < 0) {
			FreePopupEventData(pdata);
			mir_free(pdata);
		}
	}

	if (dbe.pBlob)
		mir_free(dbe.pBlob);
	return 0;
}
void CMraProto::MraPopupShowW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszTitle, LPCWSTR lpszMessage)
{
	if (getByte("PopupsEnabled", MRA_DEFAULT_POPUPS_ENABLED))
	if (GetBit(getDword("PopupsEventFilter", MRA_DEFAULT_POPUPS_EVENT_FILTER), dwType))
	if ( ServiceExists(MS_POPUP_ADDPOPUPW)) {
		POPUPDATAT ppd = { 0 };

		// delete old email popup
		if (dwType == MRA_POPUP_TYPE_EMAIL_STATUS && hWndEMailPopupStatus) {
			PUDeletePopup(hWndEMailPopupStatus);
			hWndEMailPopupStatus = NULL;
		}

		// load icon
		switch (dwType) {
		case MRA_POPUP_TYPE_NONE:// proto icon
			ppd.lchIcon = g_hMainIcon;
			break;
		case MRA_POPUP_TYPE_DEBUG:// IDI_APPLICATION
			ppd.lchIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		case MRA_POPUP_TYPE_INFORMATION:// IDI_INFORMATION
			ppd.lchIcon = (HICON)LoadImage(NULL, IDI_INFORMATION, IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		case MRA_POPUP_TYPE_QUESTION:// IDI_QUESTION
			ppd.lchIcon = (HICON)LoadImage(NULL, IDI_QUESTION, IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		case MRA_POPUP_TYPE_WARNING:// IDI_WARNING
			ppd.lchIcon = (HICON)LoadImage(NULL, IDI_WARNING, IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		case MRA_POPUP_TYPE_ERROR:// IDI_ERROR
			ppd.lchIcon = (HICON)LoadImage(NULL, IDI_ERROR, IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		case MRA_POPUP_TYPE_EMAIL_STATUS:
			ppd.lchIcon = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_MAIL_NOTIFY), IMAGE_ICON, 0, 0, LR_SHARED);
			break;
		}

		MraPopupData *dat = (MraPopupData*)mir_calloc( sizeof(MraPopupData));
		dat->iPopupType = dwType;
		dat->ppro = this;

		ppd.lchContact = hContact;
		if (lpszTitle)
			lstrcpyn(ppd.lptzContactName, lpszTitle, MAX_CONTACTNAME);
		if (lpszMessage)
			lstrcpyn(ppd.lptzText, lpszMessage, MAX_SECONDLINE);
		ppd.PluginWindowProc = MraPopupDlgProc;
		ppd.PluginData = dat;

		char szBuff[MAX_PATH];
		mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SUseWinColors", lpcwszPopupsTypes[dwType]);
		BOOL bUseWinColors = getByte(szBuff, MRA_DEFAULT_POPUP_USE_WIN_COLORS);
		if (bUseWinColors) {
			ppd.colorBack = GetSysColor(COLOR_BTNFACE);
			ppd.colorText = GetSysColor(COLOR_WINDOWTEXT);
		}
		else {
			mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorBack", lpcwszPopupsTypes[dwType]);
			ppd.colorBack = getDword(szBuff, MRA_DEFAULT_POPUP_COLOR_BACK);

			mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorText", lpcwszPopupsTypes[dwType]);
			ppd.colorText = getDword(szBuff, MRA_DEFAULT_POPUP_COLOR_TEXT);
		}

		mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%STimeout", lpcwszPopupsTypes[dwType]);
		ppd.iSeconds = getDword(szBuff, MRA_DEFAULT_POPUP_TIMEOUT);

		if (dat->iPopupType == MRA_POPUP_TYPE_EMAIL_STATUS && dat->ppro->hWndEMailPopupStatus)
			PUChangeTextW(dat->ppro->hWndEMailPopupStatus, ppd.lpwzText);
		else
			PUAddPopupW(&ppd);
	}
	else if (dwFlags & MRA_POPUP_ALLOW_MSGBOX)
		MessageBox(NULL, lpszMessage, lpszTitle, MB_OK+(dwType == MRA_POPUP_TYPE_WARNING)?MB_ICONERROR:MB_ICONINFORMATION);
}