Ejemplo n.º 1
0
void KNMusicLibraryImageManager::recoverFromFolder()
{
    //Check is the path exist or it's a file.
    QFileInfo pathChecker(m_imageFolderPath);
    QDir imageDir(m_imageFolderPath);
    //Check it's existance and it's file or not.
    if(pathChecker.exists() && pathChecker.isFile())
    {
        //Delete the file.
        QFile fileRemover(pathChecker.absoluteFilePath());
        fileRemover.remove();
    }
    //Check if it's not exist, simply generate the folder.
    if(!pathChecker.exists())
    {
        //Generate the folder.
        imageDir.mkpath(imageDir.absolutePath());
        //Do nothing, return.
        return;
    }
    //Load the image in the dir.
    QFileInfoList contentInfos=imageDir.entryInfoList();
    //Check each file.
    for(QFileInfoList::iterator i=contentInfos.begin();
        i!=contentInfos.end();
        ++i)
    {
        //Load all the png image to hash list.
        if((*i).isFile() && (*i).suffix().toLower()=="png")
        {
            //Load the image.
            QImage currentImage=QImage((*i).absoluteFilePath(), "png");
            //If there's image data, insert to pixmap list.
            if(!currentImage.isNull())
            {
                m_pixmapList->setImage((*i).completeBaseName(), currentImage);
            }
        }
    }
    //Emit recover complete signal.
    emit recoverComplete();
}
Ejemplo n.º 2
0
void KNMusicLibraryImageManager::recoverAlbumArt(const QStringList &hashList)
{
    //Check out the image hash list has been set or not.
    if(m_hashAlbumArt==nullptr)
    {
        return;
    }
    //Get the image folder path information.
    QFileInfo pathChecker(m_imageFolderPath);
    //Check is the path exist or it's a file
    if(pathChecker.exists() && pathChecker.isFile())
    {
        //Delete the file.
        QFile::remove(pathChecker.absoluteFilePath());
    }
    //Generate the image directory.
    QDir imageDir(m_imageFolderPath);
    //Check if it's not exist, simply generate the folder.
    if(!pathChecker.exists())
    {
        //Generate the folder.
        imageDir.mkpath(imageDir.absolutePath());
        //Do nothing, return. Because the folder is just created.
        return;
    }
    //Check the existance again, if the path is still not exist, then failed.
    if(!pathChecker.isDir() || !pathChecker.exists())
    {
        return;
    }
    //Get the entry info list.
    QFileInfoList contentInfos=imageDir.entryInfoList();
    //Check each file.
    for(auto i : contentInfos)
    {
        //Check the information of all the file and the suffix.
        if(i.isFile() && i.suffix().toLower()=="png")
        {
            //Get the hash key, which is the base name.
            QString hashKey=i.completeBaseName();
            //Check whether the file is in the hash list.
            if(hashList.contains(hashKey))
            {
                //Load the image.
                QPixmap currentPixmap=QPixmap(i.absoluteFilePath(), "png");
                //If there's image data is not null.
                if(!currentPixmap.isNull())
                {
                    //Insert the image to the hash list.
                    m_hashAlbumArt->insert(i.completeBaseName(),
                                           QVariant(currentPixmap));
                    //Continue to next file.
                    continue;
                }
            }
        }
        //Remove the no use file.
        QFile::remove(i.absoluteFilePath());
    }
    //After loading the images, emit recover signal.
    emit recoverImageComplete();
}