QList<webFileUtils::webFile> webFileUtils::getWebFiles(QUrl url) { QList<webFileUtils::webFile> list; QWebPage *webPage = new QWebPage(this); QEventLoop loop; connect(webPage->mainFrame(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit())); webPage->mainFrame()->load(url); loop.exec(); QUrl baseUrl = webPage->mainFrame()->baseUrl(); QWebElementCollection collection = webPage->mainFrame()->findAllElements("a"); foreach (QWebElement element, collection) { QString href = element.attribute("href"); if (!href.isEmpty()) { QUrl relativeUrl(href); QUrl absoluteUrl = baseUrl.resolved(relativeUrl); if(element.toPlainText().contains("exe") | element.toPlainText().contains("tar.xz") | element.toPlainText().contains("zip")) { webFile file; file.name = element.toPlainText(); file.url = absoluteUrl; list.append(file); } } }
EXPORT_C CUrl* CUrl::ResolveL(CUrl& aBaseUrl, CUrl& aRelativeUrl) // // Based on the relative parsing algorithm in RFC2396 { // Return copy of aRelativeUrl if aBaseUrl is empty if (aBaseUrl.UrlDes().Compare(KNullDesC)==0) return aRelativeUrl.AllocL(); TPtrC relativeUrl(aRelativeUrl.UrlDes()); TPtrC relPath(aRelativeUrl.Component(EUrlPath)); TPtrC relAuth(aRelativeUrl.Component(EUrlAuthority)); TPtrC relScheme(aRelativeUrl.Component(EUrlScheme)); TPtrC relQuery(aRelativeUrl.Component(EUrlQuery)); TPtrC relFragment(aRelativeUrl.Component(EUrlFragment)); if (relScheme.Length() > 0) { // LOOPHOLE in RFC 1630 if schemes match then remove the scheme from the relative url if (aBaseUrl.UrlDes().FindF(relScheme) == 0) relativeUrl.Set(relativeUrl.Mid(relScheme.Length() + 1)); // remove the ':' as well else // the relative url is absolute return NewL(relativeUrl); } TBool useBaseAuth = ETrue; TBool useRelQuery = ETrue; TPtrC basePath(aBaseUrl.Component(EUrlPath)); HBufC* resolvedPath = NULL; if (relPath.Compare(KNullDesC)==0 && relAuth.Compare(KNullDesC)==0 && relScheme.Compare(KNullDesC)==0 && relQuery.Compare(KNullDesC)==0) // relative URL could just be a fragment { // Use current document url (assume that it is aBaseUrl), including query, then add relative URL fragment useRelQuery = EFalse; resolvedPath = basePath.AllocLC(); } else if (relativeUrl.Find(KUrlLoc) == 0) // relative url is a network path { // Set resolved path to be the relative path useBaseAuth = EFalse; resolvedPath = relPath.AllocLC(); } else if (relPath.Locate('/') == 0) // relative url is an absolute path { resolvedPath = relPath.AllocLC(); } else { // Do path resolution, merge the base path and relative path if (relPath.Length() != 0) // if the relative path is a query or fragment then shouldn't strip the document from the basePath { TInt endBasePath = basePath.LocateReverse('/'); if (endBasePath != KErrNotFound) basePath.Set(basePath.Left(endBasePath + 1)); // keep the '/' else basePath.Set(_L("/")); // Create path of just '/' } // Resolve relative path against base path resolvedPath = HBufC::NewLC(relPath.Length() + basePath.Length()); TRelativePaths relativePaths(basePath, relPath, resolvedPath->Des()); relativePaths.ResolveRelativePaths(); } // put the url together TPtrC baseScheme(aBaseUrl.Component(EUrlScheme)); TPtrC baseAuth(aBaseUrl.Component(EUrlAuthority)); TPtrC baseQuery(aBaseUrl.Component(EUrlQuery)); HBufC* resolvedUrl = HBufC::NewLC(aBaseUrl.UrlDes().Length() + relativeUrl.Length() + KUrlColon().Length() + KUrlLoc().Length() + KUrlQMark().Length() + KUrlHash().Length() + 1); // this will be long enough - extra 1 just in case basePath was empty TPtr resolvedBuf = resolvedUrl->Des(); if (baseScheme.Length() > 0) { resolvedBuf.Append(baseScheme); resolvedBuf.Append(KUrlColon); } resolvedBuf.Append(KUrlLoc); if (useBaseAuth && baseAuth.Length() >0) { resolvedBuf.Append(baseAuth); } else if (relAuth.Length() > 0) { resolvedBuf.Append(relAuth); } resolvedBuf.Append(*resolvedPath); if (useRelQuery && relQuery.Length() >0) { resolvedBuf.Append(KUrlQMark); resolvedBuf.Append(relQuery); } else if (!useRelQuery && baseQuery.Length() >0) { resolvedBuf.Append(KUrlQMark); resolvedBuf.Append(baseQuery); } if (relFragment.Length() >0) { resolvedBuf.Append(KUrlHash); resolvedBuf.Append(relFragment); } CUrl * url = CUrl::NewL(*resolvedUrl); CleanupStack::PopAndDestroy(2); // resolvedUrl, resolvedPath return url; }