/** return the minimum resolution in the list of images */ float GeoImageList::minResolution() { if (!minMaxResUptodate_) maxResolution(); return minRes_; }
void QUAlbumArtExCollector::processSearchResults() { QRegExp rx = QRegExp(";src=(.*)\" width=.*(\\d+)×(\\d+)\""); rx.setMinimal(true); rx.setCaseSensitivity(Qt::CaseInsensitive); QString text(buffer()->data()); QStringList allUrls; QList<QPair<int, int> > resolutions; int pos = 0; while ((pos = rx.indexIn(text, pos)) != -1) { allUrls << rx.cap(1).trimmed().replace("%2F", "/"); resolutions << QPair<int, int>(QVariant(rx.cap(2)).toInt(), QVariant(rx.cap(3)).toInt()); pos += rx.matchedLength(); } rx.setPattern("Images (\\d+)\\-(\\d+) of (\\d+)\\."); rx.indexIn(text); int from = QVariant(rx.cap(1)).toInt(); int to = QVariant(rx.cap(2)).toInt(); int last = QVariant(rx.cap(3)).toInt(); handleOldDownloads(); QStringList urls; QPair<int, int> maxResolution( QVariant(source()->customDataField(source()->customDataFields().at(0))).toInt(), QVariant(source()->customDataField(source()->customDataFields().at(1))).toInt()); for(int i = 0; i < allUrls.size(); i++) if(resolutions.at(i).first <= maxResolution.first and resolutions.at(i).second <= maxResolution.second) urls << allUrls.at(i); ignoredUrls = allUrls.size() - qMin(urls.size(), source()->limit()) + last - to; if(urls.isEmpty()) { setState(Idle); if(ignoredUrls > 0) communicator()->send(tr("No results, %1 ignored.").arg(ignoredUrls)); else communicator()->send(tr("No results.")); communicator()->send(QUCommunicatorInterface::Done); return; } setState(ImageRequest); for(int i = 0; i < urls.size() and i < source()->limit(); i++) { QFile *file = openLocalFile(source()->imageFolder(song()).filePath(QFileInfo(urls.at(i)).fileName())); // song()->log(tr("[albumartex - result] ") + "http://" + source()->host() + urls.at(i), QU::Help); if(file) { http()->setHost(source()->host()); http()->get("http://" + source()->host() + urls.at(i), file); } } }
inline Array<Setting> Enum( const Optional<Size>& targetResolution = none, const Optional<int32>& targetRefreshRate = 60, const Optional<size_t>& targetDisplayIndex = 0) { Array<Setting> results; { const auto outputs = Graphics::EnumOutputs(); size_t displayIndex = 0; for (const auto& output : outputs) { Size maxResolution(0, 0); // Get max resolution for (const auto& mode : output.displayModes) { if ((maxResolution.x * maxResolution.y) < (mode.size.x * mode.size.y)) { maxResolution = mode.size; } } const double screenAspect = static_cast<double>(maxResolution.x) / maxResolution.y; for (const auto& mode : output.displayModes) { const double aspect = static_cast<double>(mode.size.x) / mode.size.y; if (targetResolution) { if ((mode.size.x >= targetResolution->x && mode.size.y >= targetResolution->y) || mode.size == maxResolution) { results.push_back({ displayIndex, mode, screenAspect / aspect }); } } else { results.push_back({ displayIndex, mode, screenAspect / aspect }); } } ++displayIndex; } if (targetDisplayIndex && results.count_if([index = *targetDisplayIndex](const auto& result){ return result.displayIndex == index; })) { results.remove_if([index = *targetDisplayIndex](const auto& result){ return result.displayIndex != index; }); } } Array<Setting> results2; { Array<Setting> tmps; std::pair<size_t, Size> previous(0, Size(0, 0)); for (const auto& result : results) { const auto current = std::make_pair(result.displayIndex, result.dislayMode.size); if (previous == current) { tmps.push_back(result); } else { if (tmps.size() > 1) { if (targetRefreshRate) { results2.push_back(tmps.sorted_by([target = *targetRefreshRate](const auto& a, const auto& b) { return std::abs(target - a.dislayMode.refreshRateHz) < std::abs(target - b.dislayMode.refreshRateHz); }).front()); tmps.clear(); } else { results2.push_back(tmps.sorted_by([](const auto& a, const auto& b) { return a.dislayMode.refreshRateHz < b.dislayMode.refreshRateHz; }).back()); tmps.clear(); } } else if (tmps.size() == 1) { results2.push_back(tmps.front()); tmps.clear(); } previous = current; tmps.push_back(result); } } if (tmps.size() > 1) { if (targetRefreshRate) { results2.push_back(tmps.sorted_by([target = *targetRefreshRate](const auto& a, const auto& b) { return std::abs(target - a.dislayMode.refreshRateHz) < std::abs(target - b.dislayMode.refreshRateHz); }).front()); } else { results2.push_back(tmps.sorted_by([](const auto& a, const auto& b) { return a.dislayMode.refreshRateHz < b.dislayMode.refreshRateHz; }).back()); } } else if (tmps.size() == 1) { results2.push_back(tmps.front()); } } return results2; }