void Tab::startDownload(QNetworkReply *reply) { std::cout<<"startDownload(QNetworkReply *reply): downloadrequested() signal emitted by the webpage\n"; Downloader *downloader = new Downloader; if(downloader->handleDownloadRequest(WebView->page()->networkAccessManager(),reply)) downloader->show(); }
//Main Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer<QApplication> app(createApplication(argc, argv)); QmlApplicationViewer viewer; //system("sudo ifup wlan0"); Downloader d; d.doDownload("http://www.vesta-tab.com/jo/showId.php"); Object data; viewer.setCursor(Qt::BlankCursor); viewer.rootContext()->setContextProperty("image", &data); viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); //viewer.setMainQmlFile("qrc:/main.qml"); viewer.setSource(QUrl("qrc:/qml/BBB/main.qml")); viewer.showFullScreen(); return app->exec(); }
bool idpDownloadFiles() { downloader.setUI(NULL); downloader.setUserAgent(userAgent); downloader.setInternetOptions(internetOptions); return downloader.downloadFiles(); }
bool idpGetFilesSize(DWORDLONG *size) { downloader.setUi(NULL); downloader.setInternetOptions(internetOptions); *size = downloader.getFileSizes(false); return *size != FILE_SIZE_UNKNOWN; }
void idpReportError() { ui.unlockButtons(); // allow user to click Retry or Next if(downloader.filesDownloaded() || (ui.errorDlgMode == DLG_NONE)) ui.clickNextButton(); // go to next page else if(ui.errorDlgMode == DLG_SIMPLE) { if(ui.messageBox(ui.msg("Download failed") + _T(": ") + downloader.getLastErrorStr() + _T("\r\n") + (ui.allowContinue ? ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Next' to continue installing anyway.") : ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Cancel' to terminate setup.")), ui.msg("Download failed"), MB_ICONWARNING | (ui.hasRetryButton ? MB_OK : MB_RETRYCANCEL)) == IDRETRY) idpStartDownload(); } else { ui.dllHandle = idpDllHandle; switch(ui.errorDialog(&downloader)) { case IDRETRY : idpStartDownload(); break; case IDIGNORE: ui.clickNextButton(); break; } } }
void MediaBase::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error) { if (args->GetProperty ()->GetOwnerType() != Type::MEDIABASE) { FrameworkElement::OnPropertyChanged (args, error); return; } if (args->GetId () == MediaBase::SourceProperty) { const char *uri = args->GetNewValue() ? args->GetNewValue()->AsString () : NULL; if (IsAttached () && AllowDownloads ()) { if (uri && *uri) { Downloader *dl; if ((dl = GetDeployment ()->CreateDownloader ())) { dl->Open ("GET", uri, GetDownloaderPolicy (uri)); SetSource (dl, ""); dl->unref (); } else { // we're shutting down } } else { SetSource (NULL, NULL); } } else { source_changed = true; } InvalidateMeasure (); } NotifyListenersOfPropertyChange (args, error); }
void MediaBase::SetAllowDownloads (bool allow) { const char *uri; Downloader *dl; if ((allow_downloads && allow) || (!allow_downloads && !allow)) return; if (allow && IsAttached () && source_changed) { source_changed = false; if ((uri = GetSource ()) && *uri) { if (!(dl = GetDeployment ()->CreateDownloader ())) { // we're shutting down return; } dl->Open ("GET", uri, GetDownloaderPolicy (uri)); SetSource (dl, ""); dl->unref (); } } allow_downloads = allow; }
void Downloader::SendAsync (EventObject *user_data) { Downloader *downloader = (Downloader *) user_data; downloader->SendInternal (); }
bool idpDownloadFiles() { downloader.ownMsgLoop = false; downloader.setUi(NULL); downloader.setInternetOptions(internetOptions); return downloader.downloadFiles(false); }
// CURL 下载线程 static void * download(void *arg) { //LOG("downloading...\n"); Downloader *downloader = (Downloader *)arg; downloader->performDownload(); return NULL; }
bool Util::Download(RequestParameter param, string file) { HttpRequest request; Downloader downloader; downloader.SetFile(file); request.SetListener(&downloader); request.SetRequestParameter(param); return request.Get(10); }
void downloadThreadProc(void *param) { Downloader *d = (Downloader *)param; bool res = d->downloadFiles(); if((!d->downloadCancelled) && d->finishedCallback) d->finishedCallback(d, res); }
void * Downloader::downloaderThread(void *opaque) { Downloader *instance = reinterpret_cast<Downloader *>(opaque); int canc = vlc_savecancel(); instance->Run(); vlc_restorecancel( canc ); return NULL; }
void idpStartDownload() { ui.lockButtons(); downloader.ownMsgLoop = false; downloader.setUi(&ui); downloader.setInternetOptions(internetOptions); downloader.setFinishedCallback(&downloadFinished); downloader.startDownload(); }
void idpStartDownload() { ui.lockButtons(); downloader.setUI(&ui); downloader.setUserAgent(userAgent); downloader.setInternetOptions(internetOptions); downloader.setFinishedCallback(&downloadFinished); downloader.startDownload(); }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); Downloader *d = Downloader::instance(); qDebug() << "download return code" << d->fetch(QUrl("http://download.cegit.de/kde-windows/installer/config.txt"),"config.txt"); qDebug() << "download return code" << d->fetch(QUrl("http://go.microsoft.com/fwlink/?LinkId=51410&clcid=0x409"),"vcexpress.exe"); qDebug() << "download return code" << d->fetch(QUrl("ftp://ftp.scarlet.be/pub/kde/unstable/3.97/windows/"),"config-ftp.txt"); return 0; }
bool Util::Download(string host, string url, int port, string file) { HttpRequest request; Downloader downloader; downloader.SetFile(file); request.SetListener(&downloader); request.SetHost(host); request.SetIpPort(port); request.SetUrl(url); return request.Get(10); }
int Downloader::ProgressFileFunction(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { assert(clientp); int percentage = dlnow * 100.0 / dltotal; if (percentage < 0) percentage = 0; if (percentage > 100) percentage = 100; Downloader* c = (Downloader *) clientp; c->ProgressFileCallback((size_t)percentage); return 0; }
int main( int argc, char* argv[] ) { // creating the qt-application object QApplication qApplication( argc, argv ); qApplication.setQuitOnLastWindowClosed( true ); // creating downloader object, and showing it Downloader downloader; downloader.initEnvironement(); downloader.show(); // running the application return qApplication.exec(); }
int curl_progress(void *pointer, double dltotal, double dlnow, double ultotal, double ulnow) { Q_UNUSED(dltotal); Q_UNUSED(dlnow); Q_UNUSED(ultotal); Q_UNUSED(ulnow); Downloader *dl = (Downloader *)pointer; dl->mutex()->lock (); bool aborted = dl->stream()->aborted; dl->mutex()->unlock(); if (aborted) { return -1; } return 0; }
void Http::Request(const string &url, bool async, bool usePost, const void *data, size_t dataLen, HttpCallback callback, void *callbackArg, map<std::string, string> *header, int timeout) { if( timeout <= 0 ) { timeout = 60; } CURL *handle = curl_easy_init(); Downloader *downloader = new Downloader(handle, callback, callbackArg); curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); curl_easy_setopt(handle, CURLOPT_TIMEOUT, timeout); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1); curl_easy_setopt(handle, CURLOPT_WRITEDATA, downloader); curl_easy_setopt(handle, CURLOPT_PRIVATE, downloader); if( usePost ){ curl_easy_setopt(handle, CURLOPT_POST, 1); curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, dataLen); curl_easy_setopt(handle, CURLOPT_COPYPOSTFIELDS, data); } if( header != NULL ) { struct curl_slist *headers = NULL; map<string,string>::const_iterator it = header->begin(); for(; it != header->end(); it++ ) { headers = curl_slist_append(headers, (it->first + ": " + it->second).c_str()); } curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); downloader->setHeaders(headers); } if( async ) { curl_multi_add_handle(m_mcurl, handle); int running = 0; curl_multi_perform(m_mcurl, &running); }else { int repCode = -1; CURLcode code = curl_easy_perform(handle); if ( CURLE_OK == code ) { curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &repCode); } downloader->didFinish(code, repCode); delete downloader; } }
NetworkResult NetworkFactory::performNetworkOperation(const QString &url, int timeout, const QByteArray &input_data, const QString &input_content_type, QByteArray &output, QNetworkAccessManager::Operation operation, bool protected_contents, const QString &username, const QString &password, bool set_basic_header) { Downloader downloader; QEventLoop loop; NetworkResult result; QString str(input_data); downloader.appendRawHeader("Content-Type", input_content_type.toLocal8Bit()); if (set_basic_header) { QString basic_value = username + ":" + password; QString header_value = QString("Basic ") + QString(basic_value.toUtf8().toBase64()); downloader.appendRawHeader("Authorization", header_value.toLocal8Bit()); } // We need to quit event loop when the download finishes. QObject::connect(&downloader, SIGNAL(completed(QNetworkReply::NetworkError)), &loop, SLOT(quit())); downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password); loop.exec(); output = downloader.lastOutputData(); result.first = downloader.lastOutputError(); result.second = downloader.lastContentType(); return result; }
void AsyncDownloadQueue::checkComplete() { int maxRuning = 10; for( int i=0; i<m_downloaders.size(); ) { Downloader *downloader = m_downloaders[i]; if( downloader && downloader->state() == COMPLETE ) { downloader->invokeCallback(); m_downloaders.erase(m_downloaders.begin()+i); } else { if( downloader && downloader->state() == RUNNING ) { maxRuning -= 1; } i++; } } if( maxRuning > 0 ) { for( int i=0; i<m_downloaders.size() && maxRuning > 0; i++) { Downloader *downloader = m_downloaders[i]; if( downloader && downloader->state() == PREPARED ) { downloader->start(); maxRuning -= 1; } } } }
void testObj::test<3>(void) { // note that there is race condition in next two lines - it may happen that between // download of blacklisted IPs by strategy and download by donwloader it may change // thus there is some (small) probablilty that this test will randomly fail. const Downloader dwnl(1); // just one entry to download const DShieldParser dsp( dwnl.download() ); // parse it Strategy s( InstanceName("x"), Strategy::Parameters(1, 10, 0.5) ); // initiliaze strategy to use ensure("no entries parsed", dsp.begin()!=dsp.end() ); GraphNodePtrNN leaf=makeNewLeaf( (*dsp.begin()).to_string().c_str() ); // make leaf that is blacklisted // this host should be blacklisted s.process(leaf, changed_); ensure_equals("nothing changed", changed_.size(), 1u); changed_.clear(); // now it should NOT be blacklisted, since it has already changed s.process(leaf, changed_); ensure_equals("the same host has been black-listed twice", changed_.size(), 0u); }
int Http::Get(const string &url, string &content, map<std::string, string> *header, int timeout) { if( timeout <= 0 ) { timeout = 60; } CURL *handle = curl_easy_init(); Downloader *downloader = new Downloader(handle); curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); curl_easy_setopt(handle, CURLOPT_TIMEOUT, timeout); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1); curl_easy_setopt(handle, CURLOPT_WRITEDATA, downloader); curl_easy_setopt(handle, CURLOPT_PRIVATE, downloader); if( header != NULL ) { struct curl_slist *headers = NULL; map<string,string>::const_iterator it = header->begin(); for(; it != header->end(); it++ ) { headers = curl_slist_append(headers, (it->first + ": " + it->second).c_str()); } curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); downloader->setHeaders(headers); } int repCode = -1; CURLcode code = curl_easy_perform(handle); if ( CURLE_OK == code ) { curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &repCode); } int downloaded = -1; if( repCode == 200 ) { content = downloader->getText(); downloaded = content.size(); } delete downloader; return downloaded; }
bool idpDownloadFilesCompUi() { ui.lockButtons(); downloader.ownMsgLoop = true; downloader.processMessages(); downloader.setUi(&ui); downloader.setInternetOptions(internetOptions); bool res; while(true) { res = downloader.downloadFiles(true); TRACE(_T("idpDownloadFilesCompUi: ui.errorDlgMode == %d"), ui.errorDlgMode); if(res || (ui.errorDlgMode == DLG_NONE) || downloader.downloadCancelled) break; // go to next page else if(ui.errorDlgMode == DLG_SIMPLE) { int dlgRes = ui.messageBox(ui.msg("Download failed") + _T(": ") + downloader.getLastErrorStr() + _T("\r\n") + (ui.allowContinue ? ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Next' to continue installing anyway.") : ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Cancel' to terminate setup.")), ui.msg("Download failed"), MB_ICONWARNING | (ui.hasRetryButton ? MB_OK : MB_RETRYCANCEL)); if (dlgRes == IDRETRY) continue; else if(dlgRes == IDCANCEL) break; } else { ui.dllHandle = idpDllHandle; int dlgRes = ui.errorDialog(&downloader); if (dlgRes == IDRETRY) continue; else if(dlgRes == IDABORT) break; else if(dlgRes == IDIGNORE) break; } } ui.unlockButtons(); return res; }
void downloadFinished(Downloader *d, bool res) { ui.unlockButtons(); // allow user to click Retry or Next if(res) ui.clickNextButton(); // go to next page else { if(ui.hasRetryButton) ui.messageBox(ui.msg("Download failed") + _T(": ") + downloader.getLastErrorStr() + _T("\r\n") + (ui.allowContinue ? ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Next' to continue installing anyway.") : ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Cancel' to terminate setup.")), ui.msg("Download failed"), MB_OK | MB_ICONWARNING); else if(ui.messageBox(ui.msg("Download failed") + _T(": ") + downloader.getLastErrorStr() + _T("\r\n") + (ui.allowContinue ? ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Next' to continue installing anyway.") : ui.msg("Check your connection and click 'Retry' to try downloading the files again, or click 'Cancel' to terminate setup.")), ui.msg("Download failed"), MB_OK | MB_ICONWARNING | MB_RETRYCANCEL) == IDRETRY) idpStartDownload(); } }
void Http::update() { int running = 0; curl_multi_perform(m_mcurl, &running); CURLMsg *msg; int msgs_left; while ((msg = curl_multi_info_read(m_mcurl, &msgs_left))) { if(msg->msg == CURLMSG_DONE) { int repCode = -1; Downloader *downloader = NULL; curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &repCode); curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &downloader); curl_multi_remove_handle(m_mcurl, msg->easy_handle); downloader->didFinish(msg->data.result, repCode); delete downloader; } } }
void MediaBase::SetSourceAsyncCallback () { Downloader *downloader; char *part_name; DownloaderAbort (); downloader = source.downloader; part_name = source.part_name; source.queued = false; source.downloader = NULL; source.part_name = NULL; if (!IsAttached ()) return; SetSourceInternal (downloader, part_name); if (downloader) downloader->unref (); }
bool idpDownloadFile(_TCHAR *url, _TCHAR *filename) { Downloader d; d.setInternetOptions(internetOptions); d.setOptions(&downloader); d.setMirrorList(&downloader); d.addFile(STR(url), STR(filename)); return d.downloadFiles(); }