コード例 #1
0
ファイル: thread.cpp プロジェクト: nohal/piman_pi
wxCurlThreadError wxCurlBaseThread::SetURL(const wxString &url)
{
    wxCHECK_MSG(!IsAlive(), wxCTE_NO_RESOURCE, wxS("Cannot use this function after the tranfer has begun"));

    // which protocol is required by given url?
    wxCurlProtocol curr = GetProtocolFromURL(url);
    if (curr == wxCP_INVALID)
        return wxCTE_INVALID_PROTOCOL;

    if (curr != m_protocol)
    {
        m_protocol = curr;

        // we need to (re)create the m_pCurl object
        wxDELETE(m_pCurl);
        m_pCurl = CreateHandlerFor(m_protocol);
    }

    if (!m_pCurl || !m_pCurl->IsOk())
        return wxCTE_INVALID_PROTOCOL;

    // enable event sending (it's the only way the wxCurlDownloadThread user can
    // receive info about the progress of the transfer)
    m_pCurl->SetEvtHandler(GetEvtHandler(), GetId());
    m_pCurl->SetFlags(wxCURL_SEND_PROGRESS_EVENTS | wxCURL_SEND_BEGINEND_EVENTS);

    m_url = url;

    return wxCTE_NO_ERROR;
}
コード例 #2
0
ファイル: utils.cpp プロジェクト: stahta01/wxCode_components
void *wxCurlSizeQueryThread::Entry()
{
    wxLogDebug(wxS("wxSizeCacherThread::Entry - caching file sizes"));

    wxMemoryOutputStream os;
    bool allok = true;
    wxCurlHTTP http;
    wxCurlFTP ftp;

    m_urlSize.Clear();
    for (size_t i=0; i<m_urls.GetCount() && !TestDestroy(); i++)
    {
        unsigned long sz;

        wxCurlProtocol prot = GetProtocolFromURL(m_urls[i]);
        switch (prot)
        {
            case wxCP_HTTP:
            {
                http.OverrideProgressCallback(wxcurl_size_query_progress_func, &sz);
                allok &= http.Get(os, m_urls[i]);
            }
            break;

            case wxCP_FTP:
            {
                ftp.OverrideProgressCallback(wxcurl_size_query_progress_func, &sz);
                allok &= ftp.Get(os, m_urls[i]);
            }
            break;

            default:
                sz = (unsigned long)-1;
                wxFAIL;
        }

        m_urlSize.Add(sz);

        // send the event
        wxCurlSizeEvent ev(GetId(), m_urls[i], sz);
        wxPostEvent(GetEvtHandler(), ev);
    }

    wxLogDebug(wxS("wxSizeCacherThread::Entry - caching of file sizes completed"));
    return (void *)allok;
}