void testInsertAndExtract() { ScopedFileCopy copy("matroska", ".mka"); string filename = copy.fileName(); { EBML::Matroska::File f1(filename.c_str()); CPPUNIT_ASSERT(f1.isValid()); Tag* t = f1.tag(); CPPUNIT_ASSERT(t != 0); t->setTitle("Seconds of Silence"); t->setArtist("Nobody"); t->setAlbum("TagLib Test Suite"); t->setComment("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"); t->setGenre("Air"); t->setYear(2013); t->setTrack(15); CPPUNIT_ASSERT(f1.save()); } { EBML::Matroska::File f2(filename.c_str()); CPPUNIT_ASSERT(f2.isValid()); Tag* t = f2.tag(); CPPUNIT_ASSERT(t != 0); CPPUNIT_ASSERT_EQUAL(String("Seconds of Silence"), t->title()); CPPUNIT_ASSERT_EQUAL(String("Nobody"), t->artist()); CPPUNIT_ASSERT_EQUAL(String("TagLib Test Suite"), t->album()); CPPUNIT_ASSERT_EQUAL(String("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"), t->comment()); CPPUNIT_ASSERT_EQUAL(String("Air"), t->genre()); CPPUNIT_ASSERT_EQUAL(2013u, t->year()); CPPUNIT_ASSERT_EQUAL(15u, t->track()); PropertyMap pm = f2.properties(); pm.erase("COMMENT"); f2.setProperties(pm); CPPUNIT_ASSERT(f2.save()); } { EBML::Matroska::File f3(filename.c_str()); CPPUNIT_ASSERT(f3.isValid()); PropertyMap pm = f3.properties(); PropertyMap::Iterator i = pm.find("GENRE"); CPPUNIT_ASSERT(i != pm.end()); CPPUNIT_ASSERT_EQUAL(String("Air"), i->second.front()); } }
QMPlay_Tag::QMPlay_Tag( const char *_fileName ) { using namespace TagLib; fileName = _fileName; isNull = true; canWriteID3 = false; dontUse = false; isFLAC = fileName.right( 5 ) == ".flac"; if ( !isFLAC ) { QByteArray r4 = fileName.right( 4 ); if ( r4 == ".wav" ) { dontUse = true; return; } if ( r4 == ".mp3" ) canWriteID3 = true; } //General tags { Load_FileRef if ( !f->isNull() && f->tag() ) { Tag *tag = f->tag(); title = tag->title(); artist = tag->artist(); album = tag->album(); comment = tag->comment(); genre = tag->genre(); year = tag->year(); track = tag->track(); isNull = false; } delete f; } //ID3v2 picture if ( canWriteID3 ) { Load_MPEG_File ID3v2::Tag *id3v2 = f->ID3v2Tag(); if ( id3v2 && !id3v2->isEmpty() ) { ID3v2::FrameList pict = id3v2->frameList( "APIC" ); if ( !pict.isEmpty() ) { picture = ID3v2::AttachedPictureFrame( pict.front()->render() ).picture(); isNull = false; } } delete f; } //FLAC picture if ( isFLAC ) { Load_FLAC_File if ( f->pictureList().size() ) { FLAC::Picture *p = f->pictureList().front(); if ( p ) { picture = p->data(); isNull = false; } } delete f; } }
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(); }