inline void download(const string &path, uint8_t *&data, unsigned &size) { data = 0; size = 0; send({ "GET ", path, " HTTP/1.1\r\n" "Host: ", hostname, "\r\n" "Connection: close\r\n" "\r\n" }); header = downloadHeader(); downloadContent(data, size); }
inline bool download(const string &path) { total_length = 0; total_read = 0; send({ "GET ", path, " HTTP/1.1\r\n" "Host: ", hostname, "\r\n" "Connection: close\r\n" "User-Agent: nall::http\r\n" "\r\n" }); header = downloadHeader(); if(!header.iposition("200 OK")) return false; return downloadContent(); }
// --- NEW TAB --- // Open a new browser tab at the end of the tab bar. void MainWindow::newTab() { qDebug("Loading new tab..."); //QMessageBox msgBox; wv = new WFWebView(); //connect(wv, SIGNAL(loadFinished(bool)), this, SLOT(diagnoseLoad(bool))); connect(wv->page()->mainFrame(), SIGNAL(loadFinished(bool)), this, SLOT(diagnoseLoad(bool))); connect(wv, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString))); if (wv == 0) { qDebug("WV is null"); return; } wv->page()->setNetworkAccessManager(nam); /*QWebSettings* ws = wv->settings(); ws->setAttribute(QWebSettings::PluginsEnabled, true); ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); ws->setIconDatabasePath(icondb);*/ wv->page()->setForwardUnsupportedContent(true); // enable downloads connect(wv->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(downloadContent(QNetworkReply*))); // set up slot connect(wv->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadContent(QNetworkRequest))); // context menu call connect(wv->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString))); qDebug("Settings changed."); int index = tabWidget->count(); ++index; index = tabWidget->insertTab(index, wv, tr("New Tab")); qDebug("Inserted tab."); addressBar->setText(""); //addressBar->setFocus(Qt::OtherFocusReason); gotoAddressBar(); tabWidget->setCurrentIndex(index); setWindowTitle("WildFox"); }
/* ==================================================================== */ int sci_getURLcontent(char *fname, int fname_len) { SciErr sciErr; int length = 0; int *piAddr = NULL; char *url = NULL; char *username = NULL; char *password = NULL; int iRows = 0, iCols = 0; int iType = 0; int *piAddressVarOne = NULL; int ret = 0; char *content = NULL; int iRhs = nbInputArgument(pvApiCtx); CheckInputArgument(pvApiCtx, 1, 3); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarOne, &url); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 1); freeAllocatedStrings(url, username, password); return 0; } if (iRhs > 1) { /* Specify the username */ int *piAddressVarTwo = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedStrings(url, username, password); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &username); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 2); freeAllocatedStrings(url, username, password); return 0; } } if (iRhs > 2) { /* Specify the password */ int *piAddressVarThree = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedStrings(url, username, password); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarThree, &password); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 3); freeAllocatedStrings(url, username, password); return 0; } } /* Set to NULL if 0 length strings */ if (url != NULL && strlen(url) == 0) { url = NULL; } if (username != NULL && strlen(username) == 0) { username = NULL; } if (password != NULL && strlen(password) == 0) { password = NULL; } // call function content = downloadContent(url, username, password); if (content != NULL) { //create new variable int res = createSingleString(pvApiCtx, iRhs + 1, content); FREE(content); content = NULL; if (res) { Scierror(999, _("%s: Could not create the output argument.\n")); freeAllocatedStrings(url, username, password); return 0; } } AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; }
// --- DOWNLOAD CONTENT --- // Download the content requested by the provided QNetworkRequest in a separate // thread. void MainWindow::downloadContent(QNetworkRequest request) { QNetworkAccessManager* nam = new QNetworkAccessManager(this); QNetworkReply* reply = nam->get(request); downloadContent(reply); }