Example #1
0
void VRoute::slotCmdFin(int id, bool error)
{
    if (id != m_last_id) return;

    if (error)
    {
        emit signalError(m_http->errorString());
        Logger::log(QString("VRoute:slotCmdFin: error occured (%s)").arg(m_http->errorString()));
        return;
    }

    QDomDocument xml_fp;
    if (!xml_fp.setContent(m_http->readAll()))
    {
        emit signalError("Could not parse XML FP");
        Logger::log("VRoute:slotCmdFin: coult not parse XML");
        return;
    }

    //Logger::log(QString("got FP:\n%1").arg(xml_fp.toString()));

    QDomElement root_element = xml_fp.documentElement();
    if (root_element.isNull())
    {
        emit signalError("FP XML root error");
        return;
    }

    QDomNodeList result_code_element_list = root_element.elementsByTagName("result_code");
    if (result_code_element_list.count() != 1)
    {
        emit signalError(QString("XML error %1 result codes").arg(result_code_element_list.count()));
        return;
    }

    if (result_code_element_list.at(0).toElement().text() != "200")
    {
        emit signalError(QString("XML result code (%1)").arg(result_code_element_list.at(0).toElement().text()));
        return;
    }

// <?xml version='1.0'?>
// <flightplans>
//  <result>
//   <version>1</version>
//   <num_objects>1</num_objects>
//   <result_code>200</result_code>
//  </result>
//  <flightplan source="EUroute" id="316ee2d909c8b8c21db2effcc6339313" >
//   <short_name>EUroute</short_name>
//   <full_name>EUroute Flight Plan Database</full_name>
//   <logo>http://www.euroutepro.com/euroute_logo.png</logo>
//   <link>http://www.euroutepro.com/</link>
//   <contact>[email protected]</contact>
//   <dep>LOWG</dep>
//   <arr>LOWW</arr>
//   <trans_alt_dep>0</trans_alt_dep>
//   <trans_alt_arr>0</trans_alt_arr>
//   <min_fl>70</min_fl>
//   <max_fl>150</max_fl>
//   <dep_proc/>
//   <arr_proc/>
//   <route>XANUT XANUT1W</route>
//   <full_route>XANUT XANUT1W</full_route>
//   <last_change>20080211135358</last_change>
//   <flags/>
//   <comments/>
//   <distance type="route" >86</distance>
//   <class>0</class>
//  </flightplan>
// </flightplans>

    CompactRouteList route_list;

    // extract received routes

    QDomNodeList fp_element_list = root_element.elementsByTagName("flightplan");
    if (fp_element_list.count() < 1)
    {
        emit signalError("No flightplan found");
        return;
    }

    for(int index=0; index < fp_element_list.count(); ++index)
    {
        QDomElement fp_element = fp_element_list.at(index).toElement();
        MYASSERT(!fp_element.isNull());

        CompactRoute route = CompactRoute();
        
        // traverse through the FP nodes

        QDomNode fpnode = fp_element.firstChild();
        while(!fpnode.isNull())
        {
            QDomElement fpelement = fpnode.toElement();
            if (fpelement.isNull()) continue;

            if (fpelement.tagName() == "dep") route.m_adep = fpelement.text();
            else if (fpelement.tagName() == "arr") route.m_ades = fpelement.text();
            else if (fpelement.tagName() == "route") route.m_route = fpelement.text();
            else if (fpelement.tagName() == "min_fl") route.m_min_fl = fpelement.text();
            else if (fpelement.tagName() == "max_fl") route.m_max_fl = fpelement.text();
            else if (fpelement.tagName() == "distance" &&
                     fpelement.hasAttribute("type") &&
                     fpelement.attribute("type") == "route") route.m_distance = fpelement.text();

            fpnode = fpnode.nextSibling();
        }

        if (route.isValid()) route_list.append(route);
    }

    emit signalGotRoute(route_list);
}
Example #2
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	int result = prepare(lpCmdLine);

	if (result == ERROR_ALREADY_EXISTS)
	{
		HWND handle = getInstanceWindow();
		ShowWindow(handle, SW_SHOW);
		SetForegroundWindow(handle);
		closeLogFile();
		return 2;
	}

	if (result != TRUE)
	{
		signalError();
		return 1;
	}

	splash = loadBool(SHOW_SPLASH)
			&& strstr(lpCmdLine, "--l4j-no-splash") == NULL;
	restartOnCrash = loadBool(RESTART_ON_CRASH);

	// if we should restart on crash, we must also stay alive to check for crashes
	stayAlive = restartOnCrash ||
			  (loadBool(GUI_HEADER_STAYS_ALIVE)
			&& strstr(lpCmdLine, "--l4j-dont-wait") == NULL);
			
	if (splash || stayAlive)
	{
		hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, "STATIC", "",
				WS_POPUP | SS_BITMAP,
				0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
		if (splash)
		{
			char timeout[10] = {0};
			if (loadString(SPLASH_TIMEOUT, timeout))
			{
				splashTimeout = atoi(timeout);
				if (splashTimeout <= 0 || splashTimeout > MAX_SPLASH_TIMEOUT)
				{
					splashTimeout = DEFAULT_SPLASH_TIMEOUT;
				}
			}
			splashTimeoutErr = loadBool(SPLASH_TIMEOUT_ERR)
					&& strstr(lpCmdLine, "--l4j-no-splash-err") == NULL;
			waitForWindow = loadBool(SPLASH_WAITS_FOR_WINDOW);
			HANDLE hImage = LoadImage(hInstance,	// handle of the instance containing the image
					MAKEINTRESOURCE(SPLASH_BITMAP),	// name or identifier of image
					IMAGE_BITMAP,					// type of image
					0,								// desired width
					0,								// desired height
					LR_DEFAULTSIZE);
			if (hImage == NULL)
			{
				signalError();
				return 1;
			}
			SendMessage(hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hImage);
			RECT rect;
			GetWindowRect(hWnd, &rect);
			int x = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
			int y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
			SetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
			ShowWindow(hWnd, nCmdShow);
			UpdateWindow (hWnd);
		}
	}

	do
	{
		if (splash || stayAlive)
		{
			if (!SetTimer (hWnd, ID_TIMER, 1000 /* 1s */, TimerProc))
			{
				signalError();
				return 1;
			}
		}

		if (!execute(FALSE, &dwExitCode))
		{
			signalError();
			return 1;
		}

		if (!(splash || stayAlive))
		{
			debug("Exit code:\t0\n");
			closeProcessHandles();
			closeLogFile();
			return 0;
		}
	
		MSG msg;
		while (GetMessage(&msg, NULL, 0, 0))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		
		if (restartOnCrash && dwExitCode != 0)
		{
	  		debug("Exit code:\t%d, restarting the application!\n", dwExitCode);
  		}

  		closeProcessHandles();
	} while (restartOnCrash && dwExitCode != 0);

	debug("Exit code:\t%d\n", dwExitCode);
	closeLogFile();
	return dwExitCode;
}