QVariantMap MediaPlayer2Player::Metadata() const { QVariantMap metaData; // The track ID is annoying since it must result in a valid DBus object // path, and the regex for that is, and I quote: [a-zA-Z0-9_]*, along with // the normal / delimiters for paths. PlaylistItem *item = Playlist::playingItem(); if (!item) return metaData; FileHandle playingFile = item->file(); QByteArray playingTrackFileId = idFromPlaylistItem(item); metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>( QDBusObjectPath(playingTrackFileId.constData())); metaData["xesam:album"] = playingFile.tag()->album(); metaData["xesam:title"] = playingFile.tag()->title(); metaData["xesam:artist"] = QStringList(playingFile.tag()->artist()); metaData["xesam:genre"] = QStringList(playingFile.tag()->genre()); metaData["mpris:length"] = qint64(playingFile.tag()->seconds() * 1000000); metaData["xesam:url"] = QString::fromLatin1( KUrl::fromLocalFile(playingFile.absFilePath()).toEncoded()); if(playingFile.coverInfo()->hasCover()) { QString fallbackFileName = KStandardDirs::locateLocal("tmp", QString("juk-cover-%1.png").arg(item->trackId())); QString path = fallbackFileName; if(!QFile::exists(path)) { path = playingFile.coverInfo()->localPathToCover(fallbackFileName); } metaData["mpris:artUrl"] = QString::fromLatin1(QUrl::fromLocalFile( path).toEncoded()); } return metaData; }
bool TagTransactionManager::processChangeList(bool undo) { TagAlterationList::ConstIterator it, end; QStringList errorItems; it = undo ? m_undoList.constBegin() : m_list.constBegin(); end = undo ? m_undoList.constEnd() : m_list.constEnd(); emit signalAboutToModifyTags(); for(; it != end; ++it) { PlaylistItem *item = (*it).item(); Tag *tag = (*it).tag(); QFileInfo newFile(tag->fileName()); if(item->file().fileInfo().fileName() != newFile.fileName()) { if(!renameFile(item->file().fileInfo(), newFile)) { errorItems.append(item->text(1) + QString(" - ") + item->text(0)); continue; } } if(tag->save()) { if(!undo) m_undoList.append(TagTransactionAtom(item, duplicateTag(item->file().tag()))); item->file().setFile(tag->fileName()); item->refreshFromDisk(); item->repaint(); item->playlist()->dataChanged(); item->playlist()->update(); } else { Tag *errorTag = item->file().tag(); QString str = errorTag->artist() + " - " + errorTag->title(); if(errorTag->artist().isEmpty()) str = errorTag->title(); errorItems.append(str); } kapp->processEvents(); } undo ? m_undoList.clear() : m_list.clear(); if(!undo && !m_undoList.isEmpty()) action("edit_undo")->setEnabled(true); else action("edit_undo")->setEnabled(false); if(!errorItems.isEmpty()) KMessageBox::errorList(static_cast<QWidget *>(parent()), i18n("The following files were unable to be changed."), errorItems, i18n("Error")); emit signalDoneModifyingTags(); return errorItems.isEmpty(); }