⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggfiles.cpp

📁 OggPlay for Symbian 是symbian上的一个媒体播放程序的源码。它支持ogg,wav等等多媒体格式。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
 *  Copyright (c) 2003 L. H. Wilden.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <OggOs.h>
#include "OggFiles.h"

#include "OggAbsPlayback.h"
#include "OggLog.h"

#include <eikfutil.h>


TOggPlayList::TOggPlayList()
{
}
  
TOggPlayList* TOggPlayList::NewL(TInt aAbsoluteIndex, const TDesC& aSubFolder, const TDesC& aFileName, const TDesC& aShortName)
  {
  TOggPlayList* self = new (ELeave) TOggPlayList();
  CleanupStack::PushL(self);

  TBuf<128> buf;
  CEikonEnv::Static()->ReadResource(buf, R_OGG_STRING_13);

  self->SetText(self->iTitle, aShortName);
  self->SetText(self->iAlbum, buf);
  self->SetText(self->iArtist, buf);
  self->SetText(self->iGenre,buf);
  self->SetText(self->iTrackNumber, buf);
  self->SetTrackTitle();

  self->iSubFolder =  HBufC::NewL(aSubFolder.Length());
  *(self->iSubFolder) = aSubFolder;

  self->iFileName =  HBufC::NewL(aFileName.Length());
  *(self->iFileName) = aFileName;

  self->iShortName =  HBufC::NewL(aShortName.Length());
  *(self->iShortName) = aShortName;

  self->iAbsoluteIndex = aAbsoluteIndex;
  CleanupStack::Pop(self);
  return self;
  }

TOggPlayList* TOggPlayList::NewL(TFileText& tf)
  {
  TOggPlayList* self = new (ELeave) TOggPlayList();
  CleanupStack::PushL(self);

  TBuf<128> buf;
  CEikonEnv::Static()->ReadResource(buf, R_OGG_STRING_13);

  self->SetText(self->iAlbum, buf);
  self->SetText(self->iArtist, buf);
  self->SetText(self->iGenre,buf);
  self->SetText(self->iTrackNumber, buf);

  self->ReadL(tf);
  self->SetText(self->iTitle, *(self->iShortName));
  self->SetTrackTitle();

  CleanupStack::Pop(); // self
  return self;
  }

TOggPlayList::~TOggPlayList()
{
  iPlayListEntries.Close();
}

TInt TOggPlayList::Count()
{
	return iPlayListEntries.Count();
}

TOggFile* TOggPlayList::operator[] (TInt aIndex)
{
	return iPlayListEntries[aIndex];
}

TOggFile::TFileTypes TOggPlayList::FileType() const
{
	return EPlayList;
}

void TOggPlayList::SetTextFromFileL(TFileText& aTf, HBufC* &aBuffer)
{
  TBuf<KTFileTextBufferMaxSize> buf;
  User::LeaveIfError(aTf.Read(buf));

  delete aBuffer;
  aBuffer = NULL;
  
  aBuffer= buf.AllocL();  
}

void TOggPlayList::ReadL(TFileText& tf)
{
  SetTextFromFileL(tf, iSubFolder);
  SetTextFromFileL(tf, iFileName);
  SetTextFromFileL(tf, iShortName);
}    

void TOggPlayList::ScanPlayListL(RFs& aFs, TOggFiles* aFiles)
{
  RFile file;
  User::LeaveIfError(file.Open(aFs, *iFileName, EFileShareReadersOnly));
  CleanupClosePushL(file);

  TInt fileSize;
  User::LeaveIfError(file.Size(fileSize));
  HBufC8* buf = HBufC8::NewLC(fileSize);
  TPtr8 bufPtr(buf->Des());
  User::LeaveIfError(file.Read(bufPtr));

  TInt i = 0;
  TInt j = -1;
  while (j<fileSize)
  {
	i = j+1; // Start of next line

	// Skip any white space
	TText8 nextChar;
	for ( ; i<fileSize ; i++)
	{
		nextChar = bufPtr[i];
		if ((nextChar == ' ') || (nextChar == '\n') || (nextChar == '\r') || (nextChar == '\t'))
			continue;

		break;
	}

	// Check if we have reached the end
	if (i == fileSize)
		break;

	// Extract the file name
	for (j = i ; j<fileSize ; j++)
	{
		nextChar = bufPtr[j];
		if (nextChar == '\n')
			break;
	}

	// Remove any white space from the end
	do
	{
		j--;
		nextChar = bufPtr[j];
	} while ((nextChar == ' ') || (nextChar == '\r') || (nextChar == '\t'));

	// Skip comment lines
	if (bufPtr[i] == '#')
		continue;

	// Construct the filename (add the playlist path if the filename is relative)
	TFileName fileName;
	fileName.Copy(bufPtr.Mid(i, (j-i) + 1));
	if (fileName[0] == '\\')
		fileName.Insert(0, TPtrC(iFileName->Ptr(), 2));
	else if (fileName[1] != ':')
		fileName.Insert(0, TPtrC(iFileName->Ptr(), iFileName->Length()-(iShortName->Length()+4)));

	// Search for the file and add it to the list (if found)
	TOggFile* o = aFiles->FindFromFileNameL(fileName);
	if (o)
		iPlayListEntries.Append(o);
  }

  CleanupStack::PopAndDestroy(2, &file); 
}

TInt TOggPlayList::Write(TInt aLineNumber, HBufC* aBuf)
{
  aBuf->Des().Format(_L("%d\n%S\n%S\n%S\n"), aLineNumber, iSubFolder, iFileName, iShortName);
 
  return KErrNone;
}


////////////////////////////////////////////////////////////////
//
// TOggFile
//
////////////////////////////////////////////////////////////////

TOggFile::TOggFile()
  {
  }

TOggFile* TOggFile::NewL()
  {
  TOggFile* self = new (ELeave) TOggFile();
  CleanupStack::PushL(self);
  self->SetText(self->iTitle,_L("-"));
  self->SetText(self->iAlbum,_L("-"));
  self->SetText(self->iArtist,_L("-"));
  self->SetText(self->iGenre,_L("-"));
  self->SetText(self->iFileName,_L("-"));
  self->SetText(self->iSubFolder,_L("-"));
  self->SetText(self->iShortName,_L("-"));
  self->SetText(self->iTrackNumber,_L("-"));
  self->SetText(self->iTrackTitle,_L("-"));
  CleanupStack::Pop(); // self
  //TRACE(COggLog::VA(_L("TOggFile::NewL() 0x%X"), self ));
  return self;
  }

TOggFile* TOggFile::NewL(TInt aAbsoluteIndex,
           const TDesC& aTitle,
		   const TDesC& anAlbum,
		   const TDesC& anArtist,
		   const TDesC& aGenre,
		   const TDesC& aSubFolder,
		   const TDesC& aFileName,
		   const TDesC& aShortName,
		   const TDesC& aTrackNumber)
  {
  TOggFile* self = new (ELeave) TOggFile();
  CleanupStack::PushL(self);

  TBuf<128> buf;

#ifdef PLAYLIST_SUPPORT
  CEikonEnv::Static()->ReadResource(buf, R_OGG_STRING_13);
#else
  CEikonEnv::Static()->ReadResource(buf, R_OGG_STRING_12);
#endif

  self->iAbsoluteIndex = aAbsoluteIndex;
  if (aTitle.Length()>0) self->SetText(self->iTitle, aTitle); else self->SetText(self->iTitle, aShortName);
  if (anAlbum.Length()>0) self->SetText(self->iAlbum, anAlbum); else self->SetText(self->iAlbum, buf);
  if (anArtist.Length()>0) self->SetText(self->iArtist, anArtist); else self->SetText(self->iArtist, buf);
  if (aGenre.Length()>0) self->SetText(self->iGenre, aGenre); else self->SetText(self->iGenre,buf);
  if (aSubFolder.Length()>0) self->SetText(self->iSubFolder, aSubFolder); else self->SetText(self->iSubFolder,buf);
  self->SetText(self->iFileName, aFileName);
  self->SetText(self->iShortName, aShortName);
  if (aTrackNumber.Length()>0) self->SetText(self->iTrackNumber, aTrackNumber); else self->SetText(self->iTrackNumber, buf);

  self->SetTrackTitle();
  CleanupStack::Pop(); // self
  return self;
  }

TOggFile* TOggFile::NewL(TFileText& tf, TInt aVersion)
  {
  TOggFile* self = new (ELeave) TOggFile();
  CleanupStack::PushL(self);
  self->ReadL(tf, aVersion);

  CleanupStack::Pop(); // self
  return self;
  }

void
TOggFile::SetTrackTitle() 
{
  TInt track(0);
  TLex parse(*iTrackNumber);
  parse.Val(track);
  if (track>999) track=999;
  TBuf<128> buf;
  buf.NumFixedWidth(track,EDecimal,2);
  buf.Append(_L(" "));
  buf.Append(iTitle->Left(123));
  SetText(iTrackTitle,buf);
}

TOggFile::~TOggFile()
{
  delete iTitle;
  delete iAlbum;
  delete iArtist;
  delete iGenre;
  delete iSubFolder;
  delete iFileName;
  delete iShortName;
  delete iTrackNumber;
  delete iTrackTitle;
}

TOggFile::TFileTypes TOggFile::FileType() const
{
	return EFile;
}

void
TOggFile::SetText(HBufC* & aBuffer, const TDesC& aText)
{
  if (aBuffer) delete aBuffer;
  aBuffer= 0;
  aBuffer= HBufC::New(aText.Length());
  *aBuffer= aText;
}

void
TOggFile::SetTextFromFileL(TFileText& aTf, HBufC* & aBuffer)
{
  TBuf<KTFileTextBufferMaxSize> buf;
  User::LeaveIfError( aTf.Read(buf) );

  if (aBuffer) 
  {
      delete(aBuffer);
      aBuffer =NULL;
  }
  
  aBuffer= buf.AllocL();  
    
}

void
TOggFile::ReadL(TFileText& tf, TInt aVersion)
{
  SetTextFromFileL( tf, iTitle );
  SetTextFromFileL( tf, iAlbum );
  SetTextFromFileL( tf, iArtist );
  SetTextFromFileL( tf, iGenre );
  SetTextFromFileL( tf, iSubFolder );
  SetTextFromFileL( tf, iFileName );
  SetTextFromFileL( tf, iShortName );
  if( aVersion >= 1 )
    SetTextFromFileL( tf, iTrackNumber );
  SetTrackTitle();
}    


TInt
TOggFile::Write( TInt aLineNumber, HBufC* aBuf )
{
  aBuf->Des().Format(_L("%d\n%S\n%S\n%S\n%S\n%S\n%S\n%S\n%S\n"), 
    aLineNumber, 
    iTitle, iAlbum, iArtist, iGenre, iSubFolder, iFileName, iShortName, iTrackNumber);
 
  return KErrNone;
}


////////////////////////////////////////////////////////////////
//
// TOggKey
//
////////////////////////////////////////////////////////////////

TOggKey::TOggKey(TInt anOrder) : 
  TKeyArrayFix(0,ECmpNormal),
  iFiles(0),
  iOrder(anOrder)
{
  iSample= TOggFile::NewL();
  SetPtr(iSample);
}

TOggKey::~TOggKey() 
{
    delete iSample;
}

void
TOggKey::SetFiles(CArrayPtrFlat<TOggFile>* theFiles)
{
  iFiles= theFiles;
}

TAny*
TOggKey::At(TInt anIndex) const
{
  if (anIndex==KIndexPtr) return(&iSample->iTitle);

  if (anIndex>=0 && anIndex<iFiles->Count()) {
    switch (iOrder) {
    case COggPlayAppUi::ETitle : return (*iFiles)[anIndex]->iTitle;
    case COggPlayAppUi::EAlbum : return (*iFiles)[anIndex]->iAlbum;
    case COggPlayAppUi::EArtist: return (*iFiles)[anIndex]->iArtist;
    case COggPlayAppUi::EGenre : return (*iFiles)[anIndex]->iGenre;
    case COggPlayAppUi::ESubFolder: return (*iFiles)[anIndex]->iSubFolder;
    case COggPlayAppUi::EFileName : return (*iFiles)[anIndex]->iShortName;
    case COggPlayAppUi::ETrackTitle: return (*iFiles)[anIndex]->iTrackTitle;
    }
  }

  return 0;
}



////////////////////////////////////////////////////////////////
//
// TOggKeyNumeric
//
////////////////////////////////////////////////////////////////

TOggKeyNumeric::TOggKeyNumeric() : 
  TKeyArrayFix(_FOFF(TOggFile,iAbsoluteIndex),ECmpTInt),
  iFiles(0)
{
  SetPtr(&iInteger); 
}

TOggKeyNumeric::~TOggKeyNumeric() 
{
}

void
TOggKeyNumeric::SetFiles(CArrayPtrFlat<TOggFile>* theFiles)
{
  iFiles= theFiles;
}

TAny*
TOggKeyNumeric::At(TInt anIndex) const
{
  if (anIndex==KIndexPtr) 
      return( (TUint8 *)iPtr + iKeyOffset );

  if (anIndex>=0 && anIndex<iFiles->Count()) {
       return &( (*iFiles)[anIndex]->iAbsoluteIndex );
  }

  return 0;
}


////////////////////////////////////////////////////////////////
//
// TOggFiles
//
////////////////////////////////////////////////////////////////


TOggFiles::TOggFiles(CAbsPlayback* anOggPlayback) :
  iFiles(0),
  iOggPlayback(anOggPlayback),
  iOggKeyTitles(COggPlayAppUi::ETitle),
  iOggKeyAlbums(COggPlayAppUi::EAlbum),
  iOggKeyArtists(COggPlayAppUi::EArtist),
  iOggKeyGenres(COggPlayAppUi::EGenre),
  iOggKeySubFolders(COggPlayAppUi::ESubFolder),
  iOggKeyFileNames(COggPlayAppUi::EFileName),
  iOggKeyTrackTitle(COggPlayAppUi::ETrackTitle),
  iOggKeyAbsoluteIndex(),
  iVersion(-1)
{
  iFiles= new(ELeave) CArrayPtrFlat<TOggFile>(10);

  iOggKeyTitles.SetFiles(iFiles);
  iOggKeyAlbums.SetFiles(iFiles);
  iOggKeyArtists.SetFiles(iFiles);
  iOggKeyGenres.SetFiles(iFiles);
  iOggKeySubFolders.SetFiles(iFiles);
  iOggKeyFileNames.SetFiles(iFiles);
  iOggKeyTrackTitle.SetFiles(iFiles);
  iOggKeyAbsoluteIndex.SetFiles(iFiles);

#ifdef PLUGIN_SYSTEM
  iSupportedExtensionList = iOggPlayback->GetPluginListL().SupportedExtensions();
#endif
}

TOggFiles::~TOggFiles() {
  iFiles->ResetAndDestroy();
  delete iFiles;

#ifdef PLUGIN_SYSTEM
  delete iSupportedExtensionList;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -