예제 #1
0
static TCHAR* GetAwayMessage(int statusMode, char *szProto)
{
	DBVARIANT dbv;
	
	if (szProto && !(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(statusMode)))
		return NULL;

	if (DBGetContactSettingByte(NULL, "SRAway", StatusModeToDbSetting(statusMode, "Ignore"), 0))
		return NULL;

	if (DBGetContactSettingByte(NULL, "SRAway", StatusModeToDbSetting(statusMode, "UsePrev"),0)) 
	{
		if (DBGetContactSettingTString(NULL, "SRAway", StatusModeToDbSetting(statusMode, "Msg"), &dbv))
			dbv.ptszVal = mir_tstrdup(GetDefaultMessage(statusMode));
	}
	else {
		int i;
		TCHAR substituteStr[128];
		if (DBGetContactSettingTString(NULL, "SRAway", StatusModeToDbSetting(statusMode,"Default"), &dbv))
			dbv.ptszVal = mir_tstrdup(GetDefaultMessage(statusMode));

		for (i=0; dbv.ptszVal[i]; i++) 
		{
			if (dbv.ptszVal[i] != '%') continue;
			if (!_tcsnicmp(dbv.ptszVal + i, _T("%time%"), 6)) 
			{
				MIRANDA_IDLE_INFO mii = {0};
				mii.cbSize = sizeof(mii);
				CallService(MS_IDLE_GETIDLEINFO, 0, (LPARAM)&mii);

				if (mii.idleType == 1)
				{
					int mm;
					SYSTEMTIME t;
					GetLocalTime(&t);
					mm = t.wMinute + t.wHour * 60 - mii.idleTime;
					if (mm < 0) mm += 60 * 24;
					t.wMinute = mm % 60;
					t.wHour = mm / 60;
					GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &t, NULL, substituteStr, SIZEOF(substituteStr));
				}
				else GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, NULL, NULL, substituteStr, SIZEOF(substituteStr));
			}
			else if (!_tcsnicmp(dbv.ptszVal + i, _T("%date%"), 6))
				GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, substituteStr, SIZEOF(substituteStr));
			else continue;
			if (lstrlen(substituteStr) > 6) 
				dbv.ptszVal = (TCHAR*)mir_realloc(dbv.ptszVal, (lstrlen(dbv.ptszVal) + 1 + lstrlen(substituteStr) - 6) * sizeof(TCHAR));
			MoveMemory(dbv.ptszVal + i + lstrlen(substituteStr), dbv.ptszVal + i + 6, (lstrlen(dbv.ptszVal) - i - 5) * sizeof(TCHAR));
			CopyMemory(dbv.ptszVal+i, substituteStr, lstrlen(substituteStr) * sizeof(TCHAR));
		}
	}
	return dbv.ptszVal;
}
예제 #2
0
static INT_PTR CALLBACK DlgProcAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	AwayMsgDlgData *dat = (AwayMsgDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	HWND hLst = GetDlgItem(hwndDlg, IDC_LST_STATUS);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			dat = (AwayMsgDlgData*)mir_alloc(sizeof(AwayMsgDlgData));
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			dat->oldPage = -1;
			for (int i = 0; i < SIZEOF(statusModes); i++) {
				if (!(protoModeMsgFlags & Proto_Status2Flag(statusModes[i])))
					continue;

				int j;
				if (hLst) {
					j = SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModes[i], 0));
					SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_SETITEMDATA, j, statusModes[i]);
				}
				else {
					j = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModes[i], 0));
					SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, j, statusModes[i]);
				}

				dat->info[j].ignore = GetStatusModeByte(statusModes[i], "Ignore");
				dat->info[j].noDialog = GetStatusModeByte(statusModes[i], "NoDlg", true);
				dat->info[j].usePrevious = GetStatusModeByte(statusModes[i], "UsePrev");

				DBVARIANT dbv;
				if (db_get_ts(NULL, "SRAway", StatusModeToDbSetting(statusModes[i], "Default"), &dbv))
					if (db_get_ts(NULL, "SRAway", StatusModeToDbSetting(statusModes[i], "Msg"), &dbv))
						dbv.ptszVal = mir_tstrdup(GetDefaultMessage(statusModes[i]));
				lstrcpy(dat->info[j].msg, dbv.ptszVal);
				mir_free(dbv.ptszVal);
			}
			if (hLst)
				SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_SETCURSEL, 0, 0);
			else
				SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETCURSEL, 0, 0);
			SendMessage(hwndDlg, WM_COMMAND, hLst ? MAKEWPARAM(IDC_LST_STATUS, LBN_SELCHANGE) : MAKEWPARAM(IDC_STATUS, CBN_SELCHANGE), 0);
		}
		return TRUE;

	case WM_MEASUREITEM:
		{
			LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam;
			if (mis->CtlID == IDC_LST_STATUS)
				mis->itemHeight = 20;
		}
		break;

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			if (dis->CtlID != IDC_LST_STATUS) break;
			if (dis->itemID < 0) break;

			TCHAR buf[128];
			SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_GETTEXT, dis->itemID, (LPARAM)buf);

			if (dis->itemState & (ODS_SELECTED | ODS_FOCUS)) {
				FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
				SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			}
			else {
				FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW));
				SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT));
			}

			RECT rc = dis->rcItem;
			DrawIconEx(dis->hDC, 3, (rc.top + rc.bottom - 16) / 2, LoadSkinnedProtoIcon(NULL, dis->itemData), 16, 16, 0, NULL, DI_NORMAL);
			rc.left += 25;
			SetBkMode(dis->hDC, TRANSPARENT);
			DrawText(dis->hDC, buf, -1, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_LST_STATUS:
		case IDC_STATUS:
			if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == LBN_SELCHANGE)) {
				int i = hLst ?
					SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_GETCURSEL, 0, 0) :
					SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETCURSEL, 0, 0);
				if (dat->oldPage != -1) {
					dat->info[dat->oldPage].ignore = IsDlgButtonChecked(hwndDlg, IDC_DONTREPLY);
					dat->info[dat->oldPage].noDialog = IsDlgButtonChecked(hwndDlg, IDC_NODIALOG);
					dat->info[dat->oldPage].usePrevious = IsDlgButtonChecked(hwndDlg, IDC_USEPREVIOUS);
					GetDlgItemText(hwndDlg, IDC_MSG, dat->info[dat->oldPage].msg, SIZEOF(dat->info[dat->oldPage].msg));
				}
				CheckDlgButton(hwndDlg, IDC_DONTREPLY, i < 0 ? 0 : dat->info[i].ignore);
				CheckDlgButton(hwndDlg, IDC_NODIALOG, i < 0 ? 0 : dat->info[i].noDialog);
				CheckDlgButton(hwndDlg, IDC_USEPREVIOUS, i < 0 ? 0 : dat->info[i].usePrevious);
				CheckDlgButton(hwndDlg, IDC_USESPECIFIC, i < 0 ? 0 : !dat->info[i].usePrevious);

				SetDlgItemText(hwndDlg, IDC_MSG, i < 0 ? _T("") : dat->info[i].msg);

				EnableWindow(GetDlgItem(hwndDlg, IDC_NODIALOG), i < 0 ? 0 : !dat->info[i].ignore);
				EnableWindow(GetDlgItem(hwndDlg, IDC_USEPREVIOUS), i < 0 ? 0 : !dat->info[i].ignore);
				EnableWindow(GetDlgItem(hwndDlg, IDC_USESPECIFIC), i < 0 ? 0 : !dat->info[i].ignore);
				EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), i < 0 ? 0 : !(dat->info[i].ignore || dat->info[i].usePrevious));
				dat->oldPage = i;
			}
			return 0;

		case IDC_DONTREPLY:
		case IDC_USEPREVIOUS:
		case IDC_USESPECIFIC:
			SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_STATUS, CBN_SELCHANGE), 0);
			break;

		case IDC_MSG:
			if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
				return 0;
			break;
		}
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
				SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_STATUS, CBN_SELCHANGE), 0);
				{
					int i = hLst ? (SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_GETCOUNT, 0, 0) - 1) :
						(SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETCOUNT, 0, 0) - 1);
					for (; i >= 0; i--) {
						int status = hLst ?
							SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_GETITEMDATA, i, 0) :
							SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETITEMDATA, i, 0);
						SetStatusModeByte(status, "Ignore", (BYTE)dat->info[i].ignore);
						SetStatusModeByte(status, "NoDlg", (BYTE)dat->info[i].noDialog);
						SetStatusModeByte(status, "UsePrev", (BYTE)dat->info[i].usePrevious);
						db_set_ts(NULL, "SRAway", StatusModeToDbSetting(status, "Default"), dat->info[i].msg);
					}
					return TRUE;
				}
			}
			break;
		}
		break;

	case WM_DESTROY:
		mir_free(dat);
		break;
	}
	return FALSE;
}
예제 #3
0
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void tCruisePage::PollCruiseData()
{
    if (isVisible() == false)
    {
        return;
    }
    QString message = GetDefaultMessage();
    QString debugMessage;

    quint16 min = 0;
    quint16 max = 0;
    quint16 setpoint = 0;

    m_SetpointRemoteChange = true;

    tMercuryCommand* pCommand = tMercuryDataManager::Instance()->MercuryCommand();
    if( pCommand )
    {
        // check if mode hasn't changed
        if( ( m_CruiseType == eCruiseTypeRPM && pCommand->IsCruiseInSpeedMode() ) || ( m_CruiseType == eCruiseTypeSpeed && pCommand->IsCruiseInSpeedMode() == false ) )
        {
            CreateInputSpinner();
        }

        bool enabled = pCommand->IsCruiseAllowed();
 
        pCommand->CruiseLimitsConverted( min, max );
        setpoint = pCommand->CruiseSetpointConverted();

        if( tMercurySettings::Instance()->GatewaySimulateEnabled() == false )
        {
            if( !( min && max && enabled ) )
            {
                m_pCruiseSetPointSpinner->setEnabled( false );
 
                if( enabled == false )
                {
                    m_pCruiseSetPointModel->SetLimits( min, max );

                    if( pCommand->CruiseActiveHelmsMatch() == false )
                    {
                        message = tr("Active helms do not match, cruise disabled");
                    } 
                    else if( pCommand->CruiseIsCorrectActiveHelm() == false )
                    {
                        message = tr("MFD cannot control active helm, cruise disabled");
                    }
                    else if( pCommand->IsCruiseInSpeedMode() && pCommand->IsCruiseSpeedEngineSelected() == false )
                    {
                        message = tr("Control engine not selected for speed cruise");
                    }
                    else if( pCommand->IsCruiseInSpeedMode() && pCommand->CruiseValidGpsSpeed() == false )
                    {
                        message = tr("Speed data not available");
                    }
                    else
                    {
                        message = tr("Cruise not supported");
                    }
                }
                else
                {
                    m_pCruiseSetPointModel->SetLimits( setpoint, setpoint );
                    message = tr("Unable to get limits, control not possible");
                }
///  /            DbgPrintf("Cannot get cruise limits");
            }
            else
            {
                EnableOrDisableOnSpecialCondition(pCommand, message);
                m_pCruiseSetPointModel->SetLimits( min, max );
            }
 
 
            if( setpoint != 0 && setpoint != m_pCruiseSetPointModel->Value() && pCommand->CruiseSetpointUpdateAllowed() && m_pTimerToBlockNetworkUpdate && m_pTimerToBlockNetworkUpdate->isActive() == false )
            {
                if( setpoint >= min )
                {
                    m_pCruiseSetPointModel->SetValue( setpoint );
                }
                else
                {
                    m_pCruiseSetPointModel->SetValue( min );
                }
            }
        }

        // added speed debug message
        if( m_ShowDebugInfo )
        {
            debugMessage = QString("%1\n%2\n%3\n%4\n%5")
                .arg( QString( "S%1 R%2 B%3 G%4 L%5 A%6" )
                    .arg( pCommand->IsCruiseSpeedStable( pCommand->IsCruiseInSpeedMode()), 0 )
                    .arg( pCommand->IsCruiseRpmStable(), 0 ) 
                    .arg( pCommand->IsCruiseBearingStable(), 0 )
                    .arg( pCommand->CruiseValidGpsSpeed(), 0 )
                    .arg( pCommand->CruiseLimitsReceived(), 0 )
                    .arg( pCommand->IsCruiseSpeedAdapting(), 0 ) )
                .arg( pCommand->CruiseSpeedRpmTableHeader( 7 ) )
                .arg( pCommand->CruiseSpeedRpmTableValues( 7 ) )
                .arg( pCommand->CruiseSpeedDebugInfo() )
                .arg( pCommand->CruiseRpmDebugInfo() );
        }
    }
    else
    {
        debugMessage = "no info";
    }

    if( tMercurySettings::Instance()->GatewaySimulateEnabled() )
    {
        m_pCruiseSetPointSpinner->setEnabled( false );
        m_pCruiseSetPointModel->SetValue( setpoint );
        message = tr("Feature disabled in simulation mode");
    }

    m_SetpointRemoteChange = false;

    bool updateScreen = false;
    if( message != m_WarningMessage )
    {
        m_WarningMessage = message;
        updateScreen = true;
    }

    if( debugMessage != m_DebugMessage )
    {
        m_DebugMessage = debugMessage;
        updateScreen = true;
    }

    if( updateScreen )
    {
        update();
    }
}