void GCF::IconCache::iconDownloaded() { GCF::AbstractFileDownloader* downloader = qobject_cast<GCF::AbstractFileDownloader*>(sender()); if(downloader) { QUrl url = downloader->url(); QString extension = url.toString().split(".").last(); QString downloadedFile = downloader->downloadedFileName(); QString iconFileName = QString("${CACHE}/Icons/%1.%2") .arg( QFileInfo(downloadedFile).fileName() ) .arg( extension ); iconFileName = GCF::UpdaterComponent::instance().resolveFileName(iconFileName); QFile::copy(downloadedFile, iconFileName); QMutexLocker locker(&d->mutex); d->urlIconFileMap[url] = iconFileName; d->fetchingList.removeAll(url); GCF_UPDATER_LOG( QString("Downloaded icon %1 into %2").arg(url.toString()).arg(iconFileName) ); downloader->deleteLater(); emit iconFetched(url); } }
void BookmarksImportIconFetcher::slotIconFetched(const QImage &image) { IconFetcher* fetcher = qobject_cast<IconFetcher*>(sender()); if (!fetcher) { return; } QTreeWidgetItem* itemPointer = static_cast<QTreeWidgetItem*>(fetcher->data().value<void*>()); emit iconFetched(image, itemPointer); }
void BookmarksImportIconFetcher::slotStartFetching() { QNetworkAccessManager* manager = new QNetworkAccessManager(this); foreach(const Pair & pair, m_pairs) { QVariant itemPointer = QVariant::fromValue((void*) pair.item); IconFetcher* fetcher = new IconFetcher(this); fetcher->setNetworkAccessManager(manager); fetcher->setData(itemPointer); fetcher->fetchIcon(pair.url); connect(fetcher, SIGNAL(iconFetched(QImage)), this, SLOT(slotIconFetched(QImage))); connect(fetcher, SIGNAL(finished()), this, SLOT(slotFetcherFinished())); m_fetchers.append(fetcher); }
void IconFetcher::iconDownloaded() { FollowRedirectReply* reply = qobject_cast<FollowRedirectReply*> (sender()); if (!reply) { return; } QByteArray response = reply->reply()->readAll(); reply->deleteLater(); if (!response.isEmpty()) { QImage image; image.loadFromData(response); QIcon icon = QIcon(QPixmap::fromImage(image)); if (!icon.isNull()) { emit iconFetched(icon); } } emit finished(); }