예제 #1
0
void CRuleManager::WriteFavToFile()
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KFavRuleFile);
	
	int pos = filename.LocateReverse('\\');
	if (pos != KErrNotFound)
		{
		TPtrC dirName = filename.Left(pos + 1);
		CCoeEnv::Static()->FsSession().MkDirAll(dirName);
		}

	RFile file;
	TInt err;

	err = file.Replace(CCoeEnv::Static()->FsSession(), filename,
			EFileWrite);
	if (KErrNone != err)
		{
		return;
		}
	CleanupClosePushL(file);	

	WriteToFile(file,iFavRule);
	TBuf8<4> num;
	num.AppendNum(iFavRule->GetFavCount());
	file.Write(num);

	CleanupStack::PopAndDestroy(); // file	
	}
예제 #2
0
void CRuleManager::WriteToFile(RPointerArray<CRule>* aRules)
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KRuleFile);
	
	int pos = filename.LocateReverse('\\');
	if (pos != KErrNotFound)
		{
		TPtrC dirName = filename.Left(pos + 1);
		CCoeEnv::Static()->FsSession().MkDirAll(dirName);
		}

	RFile file;
	TInt err;

	err = file.Replace(CCoeEnv::Static()->FsSession(), filename,
			EFileWrite);
	if (KErrNone != err)
		{
		return;
		}
	CleanupClosePushL(file);
	
	for(TInt i=0; i<aRules->Count(); i++)
		{
		CRule* rule = (*aRules)[i];
		WriteToFile(file,rule);
		}

	CleanupStack::PopAndDestroy(); // file	
	}
/**
Get a default parent object, ff the request does not specify a parent object, 
*/
void CMTPImageDpCopyObject::SetDefaultParentObjectL()
    {
    OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_ENTRY );
    TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId)));
    LEAVEIFERROR(drive,
            OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL, "No driver number for %d! error code %d",iStorageId, munged_err));
    TChar driveLetter;
    iFramework.Fs().DriveToChar(drive, driveLetter);
    TFileName driveBuf;
    driveBuf.Append(driveLetter);
    driveBuf = BaflUtils::RootFolderPath(driveBuf.Left(1));
    delete iDest;
    iDest = NULL;
    iDest = driveBuf.AllocL();
    iNewParentHandle = KMTPHandleNoParent;
    OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_EXIT );
    }
예제 #4
0
void CRuleManager::WriteToFile(CRule* aRule)
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KRuleFile);
	
	int pos = filename.LocateReverse('\\');
	if (pos != KErrNotFound)
		{
		TPtrC dirName = filename.Left(pos + 1);
		CCoeEnv::Static()->FsSession().MkDirAll(dirName);
		}

	RFile file;
	TInt err;

	if (BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), filename))
		err = file.Open(CCoeEnv::Static()->FsSession(), filename, EFileWrite
				| EFileStreamText);
	else
		err = file.Replace(CCoeEnv::Static()->FsSession(), filename,
				EFileWrite);
	if (KErrNone != err)
		{
		return;
		}
	CleanupClosePushL(file);

	TInt end = 0;
	file.Seek(ESeekEnd, end);

	WriteToFile(file,aRule);

	CleanupStack::PopAndDestroy(); // file

	}
EXPORT_C void LoadIcons(CArrayPtrFlat<CGulIcon> * aIconList, const TIconID* aIconDefs, 
			TInt aNbIcons, TInt aScale)
{
	CALLSTACKITEM_N(_CL(""), _CL("LoadIcons"));

	TFileName real; TFileName prev;
	CEikonEnv* env=CEikonEnv::Static();
	RFs& fs=env->FsSession();
	CWsScreenDevice* screen=env->ScreenDevice();
	RWsSession& ws=env->WsSession();
	RArray<TInt> Offsets; RFile File; bool file_is_open=false;
	CleanupClosePushL(Offsets);
	RFileReadStream s;
	int j=0;

	bool romfile=false;
	for (int i = 0; i<aNbIcons;i++)
	{
		TPtrC file((TText16*)aIconDefs[i].iMbmFile);
#ifdef __S60V3__
		if (file.FindF(_L("avkon"))==KErrNotFound) {
#endif
			
		if (prev.Compare(file)) {
#ifndef __S60V3__
			real=file;
#else
			TParse p; p.Set(file, 0, 0);
			real=_L("c:\\resource\\");
			real.Append(p.NameAndExt());				
				
#endif

#ifdef __WINS__
			real.Replace(0, 1, _L("z"));
#else
			if (! BaflUtils::FileExists(fs, real)) {
				real.Replace(0, 1, _L("e"));
			}
#endif
			prev=file;
			if (file_is_open) {
				s.Close();
				file_is_open=false;
			}
			if (real.Left(1).CompareF(_L("z"))==0) {
				romfile=true;
			} else {
				romfile=false;
				GetIconInfo(real, fs, File, s, Offsets, j);
				file_is_open=true;
			}
			++j;
		}

		auto_ptr<CWsBitmap> bitmap(new (ELeave) CWsBitmap(ws));
		if (!romfile) {
			RFile f1=File;
			s.Attach(f1, Offsets[aIconDefs[i].iBitmap]);	
			bitmap->InternalizeL(s);
		} else {
			TInt err=bitmap->Load(real, aIconDefs[i].iBitmap);
			if (err!=KErrNone) 
				User::Leave(err);
		}
		bitmap->SetSizeInTwips(screen);
#ifdef __S60V2__
		if (aScale>1) {
			auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
			ScaleFbsBitmapL(bitmap.get(), scaled.get(), aScale);
			bitmap=scaled;
		}
#endif
		
		auto_ptr<CWsBitmap> mask(NULL);
		if ( aIconDefs[i].iMask != KErrNotFound )
			{
				mask.reset(new (ELeave) CWsBitmap(ws));
				if (!romfile) {
					RFile f2=File;
					s.Attach(f2, Offsets[aIconDefs[i].iMask]);
					mask->InternalizeL(s);
				} else {
					User::LeaveIfError(mask->Load(real, aIconDefs[i].iMask));
				}
				mask->SetSizeInTwips(screen);
#ifdef __S60V2__
				if (aScale>1) {
					auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
					ScaleFbsBitmapL(mask.get(), scaled.get(), aScale);
					mask=scaled;
				}
#endif
			}

		auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
		bitmap.release(); mask.release();
		aIconList->AppendL(icon.get()); icon.release();
#ifdef __S60V3__
		} else {
			auto_ptr<CFbsBitmap> bitmap(0);
			auto_ptr<CFbsBitmap> mask(0);
			if ( aIconDefs[i].iMask != KErrNotFound ) {
				CFbsBitmap *bitmapp=0, *maskp=0;
				AknIconUtils::CreateIconL(bitmapp, maskp, AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap, aIconDefs[i].iMask);
				bitmap.reset(bitmapp);
				mask.reset(maskp);
			} else {
				bitmap.reset(AknIconUtils::CreateIconL(AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap));
			}
			bitmap->SetSizeInTwips(screen);
			if (mask.get()) mask->SetSizeInTwips(screen);
			auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
			bitmap.release(); mask.release();
			aIconList->AppendL(icon.get()); icon.release();
		}
#endif
	}
	if (file_is_open) {
		s.Close();
	}
	CleanupStack::PopAndDestroy(); // Offsets
}
예제 #6
0
TInt CMusicPlayerImgEngine::GetAlbumArtFilename(const CMetadata &aMetadata, const TSize &aSize, TFileName &aCoverFilename, CImageDecoder **aDecoder) 
{
	/* Function returns KErrNotFound if we find nothing, it returns 0 if we find a file, and it returns 1 if the elemnt is in cache
	 * In aCacheIndex returns the cache index, if found there, or -1. If found in cache, the cache is updated.
	 * If NOT found in cache, aCoverFilename contains the cover filename. If aMetadata.iCover is valid (non-NULL)
	 * then the aCoverFilename is non-existent, e.g. e:\\Music\\Something\\Else.mp3_360.jpg The purpose in this case
	 * would be to identify the image in the cache.
	 * 
	 * The algorithm for finding the album art:
	 * 1. Check if there is aMetadata.iCover. If it does, check the cache, update aCoverFilename, return.
	 * 2. Check for KAlbumCoverNameGeneric (cover.jpg) in song's folder.
	 * 3. Check for KAlbumCoverNameGeneric2 (folder.jpg) in song's folder.
	 * 4. If aMetadata artist and album are non-NULL, check the Source/__Covers/Artist-Album.jpg
	 * 5. If enabled in Preferences, create a "hint" Source/__Covers/Artist-Album.hint having 0 bytes
	 * 6. If here, return KErrNotFound
	 */
	
	aMetadata.iFileDirEntry->GetFullPath(aCoverFilename,ETrue);
	LOG(ELogGeneral,1,"GetAlbumArtFilename++ (%S), iCover=%x",&aCoverFilename,aMetadata.iCover);

	TInt r,err;
	TEntry entry;
	
	*aDecoder=NULL;
	if(aMetadata.iCover) {
		aMetadata.iFileDirEntry->GetFullPath(aCoverFilename);
		//check if we have this in cache
		if(IsInCache(aCoverFilename,aSize)) {
			LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (we have embedded cover, in cache)");
			return 1; 
		}
		else {
			TRAP(err,*aDecoder=CImageDecoder::DataNewL(iEikEnv->FsSession(),*aMetadata.iCover));
			if(!err) {
				LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (we have embedded cover)");
				return 0; 
			}
			else LOG0("Instantiating a CImageDecoder for the embedded cover failed. Checking other options.");
		}
	}
	
	//check for KAlbumCoverNameGeneric
	aMetadata.iFileDirEntry->iParent->GetFullPath(aCoverFilename,ETrue);
	TInt pathLength=aCoverFilename.Length();
	aCoverFilename.Append(KAlbumCoverNameGeneric);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//check for KAlbumCoverNameGeneric2
	aCoverFilename.SetLength(pathLength);
	aCoverFilename.Append(KAlbumCoverNameGeneric2);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//if we are here, we need to check if we have valid Artist and Album metadata
	if(aMetadata.iAlbum && aMetadata.iArtist)
	{
		//we can construct Source/__Covers/Artist-Album.jpg
		aMetadata.iFileDirEntry->GetSource()->GetFullPath(aCoverFilename,ETrue);
		aCoverFilename.Append(KCoversFolderName);
		pathLength=aCoverFilename.Length();
		if(pathLength+aMetadata.iArtist->Length()+aMetadata.iAlbum->Length()+6<=KMaxFileName) //6= the dash + length of .jpg or .jpeg or .hint
		{
			//check for __Covers/Artist-Album.jpg
			aCoverFilename.Append(*aMetadata.iArtist);
			aCoverFilename.Append('-');
			aCoverFilename.Append(*aMetadata.iAlbum);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
			
			//if we are here, the file does not exist!
			if((iPreferences->iPFlags&CMLauncherPreferences::EPreferencesCreateCoverHintFiles) &&
					(pathLength+KIgnoreFolderName().Length()+aMetadata.iArtist->Length()+aMetadata.iAlbum->Length()+6<=KMaxFileName)) //filename size requirements
			{
				//check first if the hint file is in the "IGNORE" folder
				aCoverFilename.SetLength(pathLength);
				aCoverFilename.Append(KIgnoreFolderName);
				aCoverFilename.Append(*aMetadata.iArtist);
				aCoverFilename.Append('-');
				aCoverFilename.Append(*aMetadata.iAlbum);
				aCoverFilename.Append(KHintFileExtension);
				if(iEikEnv->FsSession().Entry(aCoverFilename,entry)){
					//the hint file was not found in the IGNORE folder
					//we should create a hint file
					aCoverFilename.SetLength(pathLength);
					aCoverFilename.Append(*aMetadata.iArtist);
					aCoverFilename.Append('-');
					aCoverFilename.Append(*aMetadata.iAlbum);
					aCoverFilename.Append(KHintFileExtension);
					LOG0("Creating hint file for %S",&aCoverFilename);
					//first, we try to make the folder
					if(!iEikEnv->FsSession().MkDir(aCoverFilename.Left(pathLength))){
						//set the entry as hidden
						TTime modifTime;
						modifTime.UniversalTime();
						iEikEnv->FsSession().SetEntry(aCoverFilename.Left(pathLength),modifTime,KEntryAttHidden,0);
					}
					//now we create the file, IF it does not exist
					if(iEikEnv->FsSession().Entry(aCoverFilename,entry)){
						RFile f;
						if((err=f.Create(iEikEnv->FsSession(),aCoverFilename,EFileWrite))){
							LOG0("Creating %S hint file failed with error %d",&aCoverFilename,err);
						}
						else {
							LOG0("Hint file %S created successfully!",&aCoverFilename);
							f.Close();
						};
					}
				}
			}
			
			//check __Covers/Album.jpg
			aCoverFilename.SetLength(pathLength);
			aCoverFilename.Append(*aMetadata.iAlbum);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
						
			//check __Covers/Artist.jpg
			aCoverFilename.SetLength(pathLength);
			aCoverFilename.Append(*aMetadata.iArtist);
			aCoverFilename.Append(KAlbumCoverExtension);
			if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
				return r;
			
		}//if(pathLength+ ...
	}//if(aMetadata.iAlbum && aMetadata.iArtist)
	
	//if we are here, we did not find a cover art anywhere, so we will use the generic cover art
	//first, check if the user has specified their own album art, and try to decode that
	aCoverFilename.Copy(KAlternateGenericAlbumArtName);
	if((r=GetAlbumArtFilenameHelper(aSize,aCoverFilename,aDecoder))>=0)
		return r;
	
	//if we are here, we will use generic album art
	LOG(ELogGeneral,-1,"GetAlbumArtFilename-- (no match found, use generic)");
	*aDecoder=NULL;
	return KErrNotFound;
}