QString QUrlProto::errorString() const { QUrl *item = qscriptvalue_cast<QUrl*>(thisObject()); if (item) return item->errorString(); return QString(); }
void HttpWindow::downloadFile() { const QString urlSpec = "http://www.youtubeinmp3.com/fetch/?video=" + urlLineEdit->text().trimmed(); if (urlSpec.isEmpty()) return; const QUrl newUrl = QUrl::fromUserInput(urlSpec); if (!newUrl.isValid()) { QMessageBox::information(this, tr("Error"), tr("Invalid URL: %1: %2").arg(urlSpec, newUrl.errorString())); return; } QString fileName = newUrl.fileName(); if (fileName.isEmpty()) fileName = defaultFileLineEdit->text().trimmed(); if (fileName.isEmpty()) fileName = defaultFileName; QString downloadDirectory = QDir::cleanPath(downloadDirectoryLineEdit->text().trimmed()); if (!downloadDirectory.isEmpty() && QFileInfo(downloadDirectory).isDir()) fileName.prepend(downloadDirectory + '/'); if (QFile::exists(fileName)) { if (QMessageBox::question(this, tr("Overwrite Existing File"), tr("There already exists a file called %1 in " "the current directory. Overwrite?").arg(fileName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No) return; QFile::remove(fileName); } file = openFileForWrite(fileName); if (!file) return; downloadButton->setEnabled(false); // schedule the request //Download QQueue if (songBeingDownloaded == true)//song is being downloaded currently songsThatNeedToBeDownloaded.enqueue(newUrl); else startRequest(newUrl); /** else if (!songsThatNeedToBeDownloaded.isEmpty()) { songsThatNeedToBeDownloaded.enqueue(newUrl); while (!songsThatNeedToBeDownloaded.isEmpty() && songBeingDownloaded == false) { QUrl tempURL = songsThatNeedToBeDownloaded.dequeue(); startRequest(tempURL); } } else startRequest(newUrl); */ }
void MainWindow::changePage() { // every time a user enters a url to the address field // this function is called. It starts the request and timer. // The timer is set to trigger after 120 s and stops // the loading QUrl url = QUrl::fromUserInput(locationEdit->text()); if (url.isValid() && !url.isEmpty()) { view->load(url); startRequest(url); view->setFocus(); pageTimer->start(1000 * 120); } else { view->stop(); view->setHtml("<h3><font color=red>Given url (" + url.toString() + ") is not valid." "</font></h3><br>" + url.errorString() + "<br>" + "Please check that you have given a right url."); } }
int Url::errorString ( lua_State * L )// const : QString { QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 ); lua_pushstring(L, lhs->errorString().toLatin1() ); return 1; }