コード例 #1
0
ファイル: networkfactory.cpp プロジェクト: keinkurt/rssguard
NetworkResult NetworkFactory::downloadFeedFile(const QString &url, int timeout,
                                               QByteArray &output, bool protected_contents,
                                               const QString &username, const QString &password) {
  // Here, we want to achieve "synchronous" approach because we want synchronout download API for
  // some use-cases too.
  Downloader downloader;
  QEventLoop loop;
  NetworkResult result;

  downloader.appendRawHeader("Accept", ACCEPT_HEADER_FOR_FEED_DOWNLOADER);

  // We need to quit event loop when the download finishes.
  QObject::connect(&downloader, SIGNAL(completed(QNetworkReply::NetworkError)), &loop, SLOT(quit()));

  downloader.downloadFile(url, timeout, protected_contents, username, password);
  loop.exec();
  output = downloader.lastOutputData();
  result.first = downloader.lastOutputError();
  result.second = downloader.lastContentType();

  return result;
}
コード例 #2
0
ファイル: ReportDialog.cpp プロジェクト: stein1/bbk
bool ReportDialog::Run(int step)
{
	wxString output;

	if( step == 0 )
	{
		// Do the tests
		m_Done = false;

		m_Output->Clear();

		m_Output->AppendText( wxString(TPTEST_VERSION_STRING) );
		m_Output->AppendText( wxT("\n") );
		m_Output->AppendText( wxString(wxDateTime::Now().Format(wxT("%Y-%m-%d %H:%M:%S"))) );
		m_Output->AppendText( wxT("\n") );
		m_Output->AppendText( wxT("\n") );


#ifdef WIN32
		// OS information
		OSInfo osinfo;
		std::string str_osinfo = osinfo.GetOSInfoString();
		if (str_osinfo.length() < 1) {
		  m_Output->AppendText( wxString(wxT("[Failed to get OS version info]\n")) );
		}
		else {
			m_Output->AppendText( wxString( FROMCSTR(str_osinfo.c_str()) ) );
		}
#endif	       
		m_stepDone = true;
	}
	else if( step == 1 )
	{
		// Report TCP Window size
		TcpWindowSize tcpwsz;
		output = FROMCSTR(tcpwsz.GetStr());
		m_Output->AppendText( wxString(output) );
		m_stepDone = true;
	}
	else if( step == 2 )
	{
		// External IP
		Downloader *dl = new Downloader();
		dl->downloadFile( TOCSTR(wxT("http://ghn.se/cgi-bin/whatsmyip")) );
		if( dl->content() != NULL )
		{
		  m_Output->AppendText( wxString( wxT("External IP Address: ") ) );
		  m_Output->AppendText( FROMCSTR(dl->content()) );
		}
		else
		{
		  m_Output->AppendText( wxString(wxT("Cannot determine external IP. No connection to TPTEST host.\n\n") ) );
		}
		delete dl;
		m_stepDone = true;
	}
	else if( step == 3 )
	  {
	    // ifconfig
		wxString cmd;
#ifdef WIN32
	    cmd << wxT("ipconfig /all");
#endif
#ifdef MACOSX
		cmd << wxT("ifconfig");
#endif
		m_proc = new wxProcess(this, wxID_REPORT_PROC);

		m_proc->Redirect();

		if( wxExecute( cmd, wxEXEC_ASYNC, m_proc ) > 0 )
		{
			m_proc_running = true;
			m_procIn = m_proc->GetInputStream();
		}
		else
		{
			this->m_Output->AppendText( wxT("Kan inte k�ra ifconfig.\n\n") );
			m_stepDone = true;
			m_stepError = true;
		}
	  }
	else if( step == 4 )
	  {
	    // netstat
		wxString cmd;
#ifdef WIN32
	    cmd << wxT("netstat -na");
#endif
#ifdef MACOSX
		cmd << wxT("netstat -nafinet");
#endif
		m_proc = new wxProcess(this, wxID_REPORT_PROC);

		m_proc->Redirect();

		if( wxExecute( cmd, wxEXEC_ASYNC, m_proc ) > 0 )
		{
			m_proc_running = true;
			m_procIn = m_proc->GetInputStream();
		}
		else
		{
			this->m_Output->AppendText( wxT("Kan inte k�ra netstat.\n\n") );
			m_stepDone = true;
			m_stepError = true;
		}
	  }
	else if( step == 5 )
	{
		// Standard TPTest
		TestMarshall *tm = TestMarshall::GetInstance();
		m_TPTestInitialized = tm->InitTestEngine( FULL_TPTEST );
		if( m_TPTestInitialized && tm->SetupFullTPTest() )
		{
			tm->Execute();
		}
		else
		{
			this->m_Output->AppendText( wxT("Kan inte k�ra TPTEST.\n\n") );
			m_stepDone = true;
			m_stepError = true;
		}
	}
	else if( step == 6 )
	{
		// traceroute
		if( ::g_ServerList->GetCount() > 0 )
		{
			Server *srv = ::g_ServerList->Item(0)->GetData();
			m_szTracerouteServer = (wxChar*)srv->Host.c_str();

			wxString cmd;

#ifdef WIN32		       
			cmd << wxT("tracert -w 1000 -h 20 ") << srv->Host;
#endif
#ifdef UNIX
			cmd << wxT("traceroute ") << srv->Host;
#endif
			m_proc = new wxProcess(this, wxID_REPORT_PROC);

			m_proc->Redirect();

			if( wxExecute( cmd, wxEXEC_ASYNC, m_proc ) > 0 )
			{
				m_proc_running = true;
				m_procIn = m_proc->GetInputStream();
			}
			else
			{
				m_stepDone = true;
				m_stepError = true;
				this->m_Output->AppendText( wxT("traceroute kunde inte starta p� din dator.\n\n") );
			}

		} // if servers
		else
		{
			m_stepDone = true;
			m_stepError = true;
			this->m_Output->AppendText( wxT("Ingen giltig server i serverlistan.\n\n") );
		}
	}
	else
	{
		return false;
	}
	return true;
}