예제 #1
0
void WCoverArtMenu::slotUnset() {
    CoverArt art;
    art.info.type = CoverInfo::NONE;
    art.info.source = CoverInfo::USER_SELECTED;
    qDebug() << "WCoverArtMenu::slotUnset emit" << art;
    emit(coverArtSelected(art));
}
예제 #2
0
void WCoverArtMenu::slotChange() {
    QFileInfo fileInfo;
    if (!m_trackLocation.isEmpty()) {
        fileInfo = QFileInfo(m_trackLocation);
    } else if (!m_coverInfo.trackLocation.isEmpty()) {
        fileInfo = QFileInfo(m_coverInfo.trackLocation);
    }

    QString initialDir;
    if (m_coverInfo.type == CoverInfo::FILE) {
        QFileInfo coverFile(fileInfo.dir(), m_coverInfo.coverLocation);
        initialDir = coverFile.absolutePath();
    } else {
        // Default to the track's directory if the cover is not
        // stored in a separate file.
        initialDir = fileInfo.absolutePath();
    }

    QStringList extensions = CoverArtUtils::supportedCoverArtExtensions();
    for (auto&& extension : extensions) {
        extension.prepend("*.");
    }
    QString supportedText = QString("%1 (%2)").arg(tr("Image Files"))
            .arg(extensions.join(" "));

    // open file dialog
    QString selectedCoverPath = QFileDialog::getOpenFileName(
        this, tr("Change Cover Art"), initialDir, supportedText);
    if (selectedCoverPath.isEmpty()) {
        return;
    }

    // TODO(rryan): Ask if user wants to copy the file.

    CoverArt art;
    // Create a security token for the file.
    QFileInfo selectedCover(selectedCoverPath);
    SecurityTokenPointer pToken = Sandbox::openSecurityToken(
        selectedCover, true);
    art.image = QImage(selectedCoverPath);
    if (art.image.isNull()) {
        // TODO(rryan): feedback
        return;
    }
    art.info.type = CoverInfo::FILE;
    art.info.source = CoverInfo::USER_SELECTED;
    art.info.coverLocation = selectedCoverPath;
    // TODO() here we may introduce a duplicate hash code
    art.info.hash = CoverArtUtils::calculateHash(art.image);
    qDebug() << "WCoverArtMenu::slotChange emit" << art;
    emit(coverArtSelected(art));
}