QString KNMusicLibraryImageManager::insertHashImage(const QImage &image) { //Calculate the meta data of the image(MD4 of image content). QByteArray hashResult= QCryptographicHash::hash(QByteArray((char *)image.bits(), image.byteCount()), QCryptographicHash::Md4); //Get the image key of the image. QString imageHashKey; //Add hash result data to image hash key. for(int i=0; i<hashResult.size(); ++i) { //Get the text string of the current number. QString currentByteText=QString::number((quint8)hashResult.at(i), 16); //Check out the data of image hash key. imageHashKey.append(hashResult.at(i)<16?"0"+currentByteText: currentByteText); } //Check whether the hash is already exists in image list. if(m_hashAlbumArt!=nullptr && !m_hashAlbumArt->contains(imageHashKey)) { //If this image is first time exist in the hash list, save the image //first. m_hashAlbumArt->insert(imageHashKey, QVariant(QPixmap::fromImage(image))); //Ask to save the image. emit requireSaveImage(imageHashKey); } return imageHashKey; }
void KNLibHashPixmapList::onActionHashComplete() { if(m_buffer->identifyData()== m_analysisQueue.first().index->data(m_identifyDataRole).toString()) { QString currentKey=m_buffer->hash(); m_needToSaveImage=!m_list.contains(currentKey); if(m_needToSaveImage) { m_list[currentKey]=m_analysisQueue.first().pixmap; } UpdateQueueItem updateItem; updateItem.index=m_analysisQueue.first().index; updateItem.key=currentKey; m_updateQueue.append(updateItem); emit requireUpdatePixmap(); m_analysisQueue.removeFirst(); if(m_needToSaveImage) { emit requireSaveImage(); } else { onActionSaveComplete(); } return; } m_analysisQueue.removeFirst(); onActionSaveComplete(); }