Beispiel #1
0
void KNMusicLibraryImageManager::removeImage(const QString &imageHash)
{
    //Check is the file exist.
    QFileInfo imageFileInfo(m_imageFolderPath + "/" + imageHash + ".png");
    //If it's exist.
    if(imageFileInfo.exists())
    {
        //If it's a file, remove it.
        if(imageFileInfo.isFile())
        {
            QFile imageFile(imageFileInfo.absoluteFilePath());
            imageFile.remove();
            return;
        }
    }
}
Beispiel #2
0
void Album::parseLastFmInfo(QByteArray bytes) {
    QXmlStreamReader xml(bytes);

    while(!xml.atEnd() && !xml.hasError()) {
        QXmlStreamReader::TokenType token = xml.readNext();
        if(token == QXmlStreamReader::StartElement) {

            if(xml.name() == "image" && xml.attributes().value("size") == "extralarge") {

                // qDebug() << title << " photo:" << imageUrl;

                bool imageAlreadyPresent = false;
                QString imageLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/albums/" + getHash();
                if (QFile::exists(imageLocation)) {
                    QFileInfo imageFileInfo(imageLocation);
                    const uint imagelastModified = imageFileInfo.lastModified().toTime_t();
                    if (imagelastModified > QDateTime::currentDateTime().toTime_t() - 86400*30) {
                        imageAlreadyPresent = true;
                    }
                }

                if (!imageAlreadyPresent) {
                    QString imageUrl = xml.readElementText();
                    // qDebug() << name << " photo:" << imageUrl;
                    if (!imageUrl.isEmpty()) {
                        QUrl url = QUrl::fromEncoded(imageUrl.toUtf8());
                        QObject *reply = The::http()->get(url);
                        connect(reply, SIGNAL(data(QByteArray)), SLOT(setPhoto(QByteArray)));
                    }
                }

            }

            else if(xml.name() == "releasedate") {
                QString releasedateString = xml.readElementText().simplified();
                if (!releasedateString.isEmpty()) {
                    // Something like "6 Apr 1999, 00:00"
                    QDateTime releaseDate = QDateTime::fromString(releasedateString, "d MMM yyyy, hh:mm");
                    int releaseYear = releaseDate.date().year();
                    if (releaseYear > 0) {
                        year = releaseDate.date().year();
                    }
                    // qDebug() << name << releasedateString << releaseDate.toString();
                }
            }

            // wiki
            // TODO check at least parent element name
            else if(xml.name() == "content") {
                QString bio = xml.readElementText();
                // qDebug() << name << " got wiki";
                if (!bio.isEmpty()) {
                    // store bio
                    const QString storageLocation =
                            QDesktopServices::storageLocation(QDesktopServices::DataLocation)
                            + "/albums/wikis/";
                    QDir dir;
                    dir.mkpath(storageLocation);
                    QFile file(storageLocation + getHash());
                    if (!file.open(QIODevice::WriteOnly)) {
                        qDebug() << "Error opening file for writing" << file.fileName();
                    }
                    QTextStream stream( &file ); // we will serialize the data into the file
                    stream << bio;
                }
            }

        }

    }

    /* Error handling. */
    if(xml.hasError()) {
        qDebug() << xml.errorString();
    }

    emit gotInfo();
}