📄 oggfiles.cpp
字号:
}
}
#endif
while (tf.Read(line)==KErrNone)
{
TOggFile* o = NULL;
TRAP( err, o = TOggFile::NewL(tf, iVersion); );
if (err != KErrNone)
{
in.Close();
return ETrue;
}
o->iAbsoluteIndex = iFiles->Count();
iFiles->AppendL(o);
}
in.Close();
#ifdef PLAYLIST_SUPPORT
// Parse playlists
for (i = 0 ; i<numPlayLists ; i++)
{
// Parse the playlist, ignoring any errors.
TRAP(err, playLists[i]->ScanPlayListL(session, this));
}
CleanupStack::PopAndDestroy(&playLists);
#endif
return ETrue;
}
return EFalse;
}
void TOggFiles::WriteDbL(const TFileName& aFileName, RFs& session)
{
CEikonEnv::Static()->BusyMsgL(R_OGG_STRING_2);
RFile out;
TBuf<64> buf;
TInt err= out.Replace(session, aFileName, EFileWrite|EFileStreamText);
if (err!=KErrNone)
{
CEikonEnv::Static()->BusyMsgCancel();
buf.SetLength(0);
buf.Append(_L("Error at open: "));
buf.AppendNum(err);
User::InfoPrint(buf);
User::After(TTimeIntervalMicroSeconds32(1000000));
return;
}
TFileText tf;
tf.Set(out);
// Write file version:
TBuf<16> line;
#ifdef PLAYLIST_SUPPORT
line.Num(2);
#else
line.Num(1);
#endif
err = tf.Write(line);
HBufC* dat = HBufC::NewLC(KDiskWriteBufferSize);
HBufC* tempBuf = HBufC::NewLC(KTFileTextBufferMaxSize*KNofOggDescriptors);
// Buffer up writes. Speed issue on phones without MMC write cache.
TInt i;
#ifdef PLAYLIST_SUPPORT
TInt numFiles = iFiles->Count();
if (err==KErrNone)
{
RPointerArray<TOggPlayList> playLists;
CleanupClosePushL(playLists);
for (i = 0 ; i<numFiles ; i++)
{
TOggFile* o = (*iFiles)[i];
if (o->FileType() == TOggFile::EPlayList)
playLists.Append((TOggPlayList*) o);
}
TInt numPlayLists = playLists.Count();
line.Num(numPlayLists);
tf.Write(line);
for (i = 0 ; i<numPlayLists ; i++)
{
if ((err = playLists[i]->Write(i,tempBuf)) != KErrNone)
break;
TInt newSize = dat->Length() + tempBuf->Length();
if( KDiskWriteBufferSize < newSize )
{
// Write to disk. Remove the last '\n' since Write() will add this
dat->Des().SetLength( dat->Des().Length()-1 );
err = tf.Write(dat->Des());
if (err != KErrNone)
break;
dat->Des().Zero();
}
dat->Des().Append(tempBuf->Des());
}
CleanupStack::PopAndDestroy(&playLists);
}
#endif
if (err == KErrNone)
{
for ( i=0; i<numFiles; i++)
{
TOggFile* o = (*iFiles)[i];
if (o->FileType() == TOggFile::EPlayList)
continue;
if ((err = (*iFiles)[i]->Write(i,tempBuf)) != KErrNone)
break;
TInt newSize = dat->Length() + tempBuf->Length();
if( KDiskWriteBufferSize < newSize )
{
// Write to disk. Remove the last '\n' since Write() will add this
dat->Des().SetLength( dat->Des().Length()-1 );
err = tf.Write(dat->Des());
if (err != KErrNone)
break;
dat->Des().Zero();
}
dat->Des().Append(tempBuf->Des());
}
}
// Final write to disk.
if( (dat->Des().Length() > 0) && (err == KErrNone))
{
dat->Des().SetLength( dat->Des().Length()-1 );
err = tf.Write(dat->Des());
}
CleanupStack::PopAndDestroy(2); // dat + tempBuf
if (err!=KErrNone)
{
buf.Append(_L("Error at write: "));
buf.AppendNum(err);
User::InfoPrint(buf);
User::After(TTimeIntervalMicroSeconds32(1000000));
}
out.Close();
CEikonEnv::Static()->BusyMsgCancel();
}
void
TOggFiles::AppendLine(CDesCArray& arr, COggListBox::TItemTypes aType, const TDesC& aText, const TInt anAbsoluteIndex)
{
TInt lineLength = aText.Length() + 15;
HBufC* hbuf = HBufC::NewLC(lineLength);
TPtr hbufDes = hbuf->Des();
hbufDes.AppendNum((TInt) aType);
hbufDes.Append(KColumnListSeparator);
hbufDes.Append(aText);
hbufDes.Append(KColumnListSeparator);
hbufDes.AppendNum(anAbsoluteIndex);
hbufDes.Append(KColumnListSeparator);
hbufDes.AppendNum(0);
arr.AppendL(hbufDes);
CleanupStack::PopAndDestroy();
}
void
TOggFiles::AppendLine(CDesCArray& arr, COggListBox::TItemTypes aType, const TDesC& aText, const TDesC& anInternalText)
{
TInt lineLength = aText.Length() + anInternalText.Length() + 15;
HBufC* hbuf = HBufC::NewLC(lineLength);
TPtr hbufDes = hbuf->Des();
hbufDes.AppendNum((TInt) aType);
hbufDes.Append(KColumnListSeparator);
hbufDes.Append(aText);
hbufDes.Append(KColumnListSeparator);
hbufDes.Append(anInternalText);
arr.AppendL(hbufDes);
CleanupStack::PopAndDestroy();
}
void
TOggFiles::AppendTitleAndArtist(CDesCArray& arr, COggListBox::TItemTypes aType, const TDesC& aTitle, const TDesC& aDelim, const TDesC& aArtist, const TInt anAbsoluteIndex)
{
TInt lineLength = aTitle.Length() + aDelim.Length() + aArtist.Length() + 15;
HBufC* hbuf = HBufC::NewLC(lineLength);
TPtr hbufDes = hbuf->Des();
hbufDes.AppendNum((TInt) aType);
hbufDes.Append(KColumnListSeparator);
hbufDes.Append(aTitle);
hbufDes.Append(aDelim);
hbufDes.Append(aArtist);
hbufDes.Append(KColumnListSeparator);
hbufDes.AppendNum(anAbsoluteIndex);
hbufDes.Append(KColumnListSeparator);
hbufDes.AppendNum(0);
arr.AppendL(hbufDes);
CleanupStack::PopAndDestroy();
}
void
TOggFiles::ClearFiles()
{
iFiles->ResetAndDestroy();
}
TDesC &
TOggFiles::FindFromIndex(TInt anIndex)
{
_LIT(Empty, "-");
TOggFile * o = TOggFile::NewL(anIndex, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty);
CleanupStack::PushL(o);
TInt foundIdx=-1;
iFiles->Find( (TOggFile * const &) *o, iOggKeyAbsoluteIndex, foundIdx );
CleanupStack::PopAndDestroy();
return *(*iFiles)[foundIdx]->iFileName;
}
TOggFile* TOggFiles::FindFromFileNameL(TFileName& aFileName)
{
_LIT(Empty, "-");
TOggFile* o = TOggFile::NewL(-1, Empty, Empty, Empty, Empty, Empty, aFileName, Empty, Empty);
TInt foundIdx;
TBool found = EFalse;
for (foundIdx = 0 ; foundIdx < iFiles->Count() ; foundIdx++)
{
TOggFile* o2 = (*iFiles)[foundIdx];
if (!(o2->iFileName->Compare(*o->iFileName)))
{
found = ETrue;
break;
}
}
delete o;
return (found) ? (*iFiles)[foundIdx] : NULL ;
}
void
TOggFiles::FillTitles(CDesCArray& arr, const TDesC& anAlbum,
const TDesC& anArtist, const TDesC& aGenre,
const TDesC& aSubFolder)
{
arr.Reset();
if (anAlbum.Length()>0)
iFiles->Sort(iOggKeyTrackTitle);
else {
if (aSubFolder.Length()>0)
iFiles->Sort(iOggKeyFileNames);
else
iFiles->Sort(iOggKeyTitles);
}
if( anAlbum.Length()==0 && anArtist.Length()==0 && aGenre.Length()==0 && aSubFolder.Length()==0 ) {
TBuf<10> buf;
CEikonEnv::Static()->ReadResource(buf, R_OGG_BY);
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
if (o.FileType() != TOggFile::EPlayList)
AppendTitleAndArtist(arr, COggListBox::ETitle, *(o.iTitle), buf, *(o.iArtist), (TInt) &o);
}
} else {
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
TBool select=
(anAlbum.Length()==0 || *o.iAlbum==anAlbum) &&
(anArtist.Length()==0 || *o.iArtist==anArtist) &&
(aGenre.Length()==0 || *o.iGenre==aGenre) &&
(aSubFolder.Length()==0 || *o.iSubFolder==aSubFolder);
if (select)
{
if (o.FileType() != TOggFile::EPlayList)
AppendLine(arr, COggListBox::ETitle, *(o.iTitle), (TInt) &o);
}
}
}
}
void TOggFiles::FillAlbums(CDesCArray& arr, const TDesC& /*anArtist*/, const TFileName& aSubFolder)
{
arr.Reset();
iFiles->Sort(iOggKeyAlbums);
TBuf<256> lastAlbum;
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
// Playlists don't appear in album view
if (o.FileType() == TOggFile::EPlayList)
continue;
if (aSubFolder.Length()==0 || *(o.iSubFolder)==aSubFolder) {
if (lastAlbum!=*o.iAlbum) {
AppendLine(arr, COggListBox::EAlbum, *(o.iAlbum), *(o.iAlbum));
lastAlbum= *o.iAlbum;
}
}
}
}
void TOggFiles::FillArtists(CDesCArray& arr, const TFileName& aSubFolder)
{
arr.Reset();
iFiles->Sort(iOggKeyArtists);
TBuf<256> lastArtist;
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
// Playlists don't appear in artist view
if (o.FileType() == TOggFile::EPlayList)
continue;
if (aSubFolder.Length()==0 || *o.iSubFolder==aSubFolder) {
if (lastArtist!=*o.iArtist) {
AppendLine(arr, COggListBox::EArtist, *o.iArtist, *o.iArtist);
lastArtist= *o.iArtist;
}
}
}
}
void TOggFiles::FillFileNames(CDesCArray& arr, const TDesC& anAlbum, const TDesC& anArtist,
const TDesC& aGenre, const TFileName& aSubFolder)
{
arr.Reset();
iFiles->Sort(iOggKeyFileNames);
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
TBool select=
(anAlbum.Length()==0 || *o.iAlbum==anAlbum) &&
(anArtist.Length()==0 || *o.iArtist==anArtist) &&
(aGenre.Length()==0 || *o.iGenre==aGenre) &&
(aSubFolder.Length()==0 || *o.iSubFolder==aSubFolder);
if (select)
{
if (o.FileType() == TOggFile::EPlayList)
AppendLine(arr, COggListBox::EPlayList, *o.iShortName, (TInt) &o);
else
AppendLine(arr, COggListBox::EFileName, *o.iShortName, (TInt) &o);
}
}
}
void TOggFiles::FillSubFolders(CDesCArray& arr)
{
arr.Reset();
iFiles->Sort(iOggKeySubFolders);
TBuf<256> lastSubFolder;
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
if (lastSubFolder!=*o.iSubFolder) {
AppendLine(arr, COggListBox::ESubFolder, *o.iSubFolder, *o.iSubFolder);
lastSubFolder= *o.iSubFolder;
}
}
}
void TOggFiles::FillGenres(CDesCArray& arr, const TDesC& anAlbum,
const TDesC& anArtist, const TFileName& aSubFolder)
{
arr.Reset();
iFiles->Sort(iOggKeyGenres);
TBuf<256> lastGenre;
for (TInt i=0; i<iFiles->Count(); i++) {
TOggFile& o= *(*iFiles)[i];
// Playlists don't appear in genre view
if (o.FileType() == TOggFile::EPlayList)
continue;
if (lastGenre!=*o.iGenre) {
TBool select=
(anAlbum.Length()==0 || *o.iAlbum==anAlbum) &&
(anArtist.Length()==0 || *o.iAlbum==anArtist) &&
(aSubFolder.Length()==0 || *o.iSubFolder==aSubFolder);
if (select) {
AppendLine(arr, COggListBox::EGenre, *o.iGenre, *o.iGenre);
lastGenre= *o.iGenre;
}
}
}
}
#ifdef PLAYLIST_SUPPORT
void TOggFiles::FillPlayLists(CDesCArray& arr)
{
arr.Reset();
iFiles->Sort(iOggKeyFileNames);
TInt numFiles = iFiles->Count();
for (TInt i=0 ; i<numFiles ; i++)
{
TOggFile* o = (*iFiles)[i];
if (o->FileType() == TOggFile::EPlayList)
AppendLine(arr, COggListBox::EPlayList, *(o->iShortName), (TInt) o);
}
}
void TOggFiles::FillPlayList(CDesCArray& arr, const TDesC& aPlayListFile)
{
arr.Reset();
TInt playListInt(0);
TLex parse(aPlayListFile);
parse.Val(playListInt);
TOggPlayList* playList = (TOggPlayList*) playListInt;
// Loop through the entries and add them
TInt numEntries = playList->Count();
for (TInt i = 0 ; i<numEntries ; i++)
{
TOggFile* o = (*playList)[i];
if (o->FileType() == TOggFile::EPlayList)
AppendLine(arr, COggListBox::EPlayList, *(o->iShortName), (TInt) o);
else
AppendLine(arr, COggListBox::EFileName, *(o->iShortName), (TInt) o);
}
}
#endif
#ifdef PLUGIN_SYSTEM
TBool TOggFiles::IsSupportedAudioFile(TParsePtrC& p)
{
TBool result=EFalse;
if (p.ExtPresent())
{
TPtrC pp (p.Ext().Mid(1)); // Remove the . in front of the extension
for (TInt i=0; i<iSupportedExtensionList->Count(); i++)
{
result=(pp.CompareF( (*iSupportedExtensionList)[i] ) == 0 );
if (result)
break;
}
}
return result;
}
#else /*PLUGIN_SYSTEM */
_LIT(KOggExt, ".ogg");
_LIT(KOggExtUC, ".OGG");
TBool TOggFiles::IsSupportedAudioFile(TParsePtrC& p)
{
TBool result= (p.Ext().Compare(KOggExt)==0) || (p.Ext().Compare(KOggExtUC)==0);
#ifdef MP3_SUPPORT
result=result || (p.Ext().Compare( _L(".mp3"))==0 || p.Ext().Compare( _L(".MP3"))==0);
#endif
return result;
}
#endif /* PLUGIN_SYSTEM */
_LIT(KPlayListExt, ".m3u");
_LIT(KPlayListExtUC, ".M3U");
TBool TOggFiles::IsPlayListFile(TParsePtrC& p)
{
return (p.Ext().Compare(KPlayListExt) == 0) || (p.Ext().Compare(KPlayListExtUC) == 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -