| 66 | } |
| 67 | |
| 68 | void RSSPhotoFrameSource::onSourceUpdate(const FileTransfer& transfer) |
| 69 | { |
| 70 | // load the rss feed |
| 71 | vector<PhotoFrameSourceItem> items; |
| 72 | QString rssFeedStr = transfer.getTemporaryString(); |
| 73 | if (!rssFeedStr.isEmpty()) |
| 74 | { |
| 75 | // NOTE: most sites use the <media:content ... /> tag to denote full images, with the exception of flickr |
| 76 | // which uses <link .../>, however, all sites have an attribute 'type="image/<format>"' which is what we |
| 77 | // first search for. Once we have these set of tags, we drill down for the actual image path, and extract |
| 78 | // the image from that. |
| 79 | // |
| 80 | // On the first try, use tags with 'image/type' mime type set |
| 81 | // On the second try, use any tag with a height |
| 82 | // On the third and final try, use all text |
| 83 | QRegExp imgTagRe("(<[^>]*image/(jpg|jpeg|gif|png)[^>]*>)"); |
| 84 | QRegExp imgUrlRe("(http://[\\w\\.-]+(:\\d+)?(/[\\w\\.\\+-]+)+\\.(jpg|jpeg|gif|png))"); |
| 85 | imgTagRe.setCaseSensitivity(Qt::CaseInsensitive); |
| 86 | imgUrlRe.setCaseSensitivity(Qt::CaseInsensitive); |
| 87 | int tries = 0; |
| 88 | while (tries < 3) |
| 89 | { |
| 90 | int offset = 0; |
| 91 | while (offset > -1 && offset < rssFeedStr.size()) |
| 92 | { |
| 93 | offset = imgTagRe.indexIn(rssFeedStr, offset); |
| 94 | offset += imgTagRe.matchedLength(); |
| 95 | QStringList tagMatches = imgTagRe.capturedTexts(); |
| 96 | for (int i = 1; i < tagMatches.size(); ++i) |
| 97 | { |
| 98 | if (tagMatches[i].isEmpty()) |
| 99 | continue; |
| 100 | |
| 101 | imgUrlRe.indexIn(tagMatches[i]); |
| 102 | QStringList urlMatches = imgUrlRe.capturedTexts(); |
| 103 | for (int j = 1; j < urlMatches.size(); ++j) |
| 104 | { |
| 105 | if (urlMatches[j].isEmpty()) |
| 106 | continue; |
| 107 | |
| 108 | // extract the image filename from the url |
| 109 | QString imgUrl = urlMatches[j]; |
| 110 | QString imgFilename = imgUrl.mid(imgUrl.lastIndexOf('/') + 1); |
| 111 | QString localFilename = native(make_file(_localCacheDirectory, imgFilename)); |
| 112 | |
| 113 | // set the expected local texture path |
| 114 | if (!localFilename.isEmpty()) |
| 115 | { |
| 116 | // ensure that the url does not already exist |
| 117 | bool resourceAlreadyExists = false; |
| 118 | vector<PhotoFrameSourceItem>::const_iterator citer = items.begin(); |
| 119 | while ((citer != items.end()) && !resourceAlreadyExists) |
| 120 | { |
| 121 | resourceAlreadyExists = (citer->getResourceId() == imgUrl); |
| 122 | citer++; |
| 123 | } |
| 124 | |
| 125 | if (!resourceAlreadyExists) |
nothing calls this directly
no test coverage detected