EngSrc/IEFileLoader.cpp
changeset 3 93fff7023be8
equal deleted inserted replaced
2:e1e28b0273b0 3:93fff7023be8
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors: Juha Kauppinen, Mika Hokkanen
       
    13 * 
       
    14 * Description: Photo Browser
       
    15 *
       
    16 */
       
    17 
       
    18 // Include files
       
    19 
       
    20 #include <bautils.h>
       
    21 #include <IEBgpsInfo.h>
       
    22 
       
    23 
       
    24 #include "IEEngineImp.h"
       
    25 #include "IEFileLoader.h"
       
    26 #include "IEImageFinder.h"
       
    27 #include "ImageMonitorAO.h"
       
    28 
       
    29 #ifdef _S60_5x_ACCELEROMETER_
       
    30 #include "IESensorMonitor.h"
       
    31 #endif
       
    32 
       
    33 #define IMAGEFINDERMONITORAO
       
    34 
       
    35 //_LIT(KFacesPath, "ImagicFaces");
       
    36 
       
    37 
       
    38 CIEFileLoader* CIEFileLoader::NewL(
       
    39         RFs& aFileServer, 
       
    40         CIEEngineImp* aEngImp, 
       
    41         RCriticalSection* aCritical/*, TRequestStatus& aStatus*/)
       
    42     {
       
    43     DP0_IMAGIC(_L("CIEFileLoader::NewL++"));
       
    44     
       
    45 	CIEFileLoader* self = new (ELeave) CIEFileLoader(aFileServer, aEngImp, aCritical/*, aStatus*/);
       
    46 	CleanupStack::PushL(self);
       
    47 	self->ConstructL();
       
    48 	CleanupStack::Pop();
       
    49 	DP0_IMAGIC(_L("CIEFileLoader::NewL--"));
       
    50 	return self;
       
    51     }
       
    52 
       
    53 CIEFileLoader::~CIEFileLoader()
       
    54     {
       
    55     DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader++"));
       
    56     
       
    57     // Save database file if needed
       
    58     if (iImageList)
       
    59         TRAP_IGNORE(iImageList->WriteDatabaseL());
       
    60     
       
    61    	DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader 1"));
       
    62 #ifdef IMAGEFINDERMONITORAO
       
    63    	if(iImageFinderMonitor->IsActive())
       
    64    	    {
       
    65    	    DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader 1.1"));
       
    66    	    iImageFinderMonitor->Cancel();
       
    67    	    }
       
    68    	
       
    69    	DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader 2"));
       
    70    	delete iImageFinderMonitor;
       
    71    	iImageFinderMonitor = NULL;
       
    72 #endif
       
    73    	
       
    74 	// The object is created in ThreadEngine CreateThreadsL().
       
    75     // This is done because thread1 needs to cleanup before killing
       
    76     // the thread.
       
    77 	iImageFinderThread->Stop();
       
    78 	delete iImageFinderThread;
       
    79 	iImageFinderThread = NULL;
       
    80 	DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader 3"));
       
    81 
       
    82 	for(TInt i = 0;i < iFileNameData.Count();i++)
       
    83 	    delete iFileNameData[i];
       
    84 	
       
    85     for(TInt i = 0;i < iFaceFilenameData.Count();i++)
       
    86         delete iFaceFilenameData[i];
       
    87         
       
    88     iFileNameData.Reset();
       
    89     iFileNameData.Close();
       
    90     
       
    91     iFaceFilenameData.Reset();
       
    92     iFaceFilenameData.Close();
       
    93     
       
    94     delete iImageList;
       
    95 	
       
    96 	//delete iFileSystemMonitor;
       
    97 	DP0_IMAGIC(_L("CIEFileLoader::~CIEFileLoader--"));
       
    98     }
       
    99 
       
   100 CIEFileLoader::CIEFileLoader(
       
   101         RFs& aFileServer, 
       
   102         CIEEngineImp* aEngImp, 
       
   103         RCriticalSection* aCritical) :
       
   104         iFileServer(aFileServer),
       
   105         iEngImp(aEngImp),
       
   106         iCritical(aCritical)
       
   107     {
       
   108           
       
   109     }
       
   110 
       
   111 void CIEFileLoader::ConstructL()
       
   112     {
       
   113     DP0_IMAGIC(_L("CIEFileLoader::ConstructL++"));
       
   114     
       
   115 	iCurrentFileIndex = 0;
       
   116 	//iJpgFileCountingComplete = EFalse;
       
   117 	iImageFinderState = EImageFinderRunning;
       
   118 
       
   119 	iImageList = CIEImageList::NewL(iFileNameData, this);
       
   120 	
       
   121 	TFileName rootPath;
       
   122     
       
   123 	//iFileSystemMonitor = FileSystemMonitorAO::NewL(iFileServer, this);
       
   124 	//iFileSystemMonitor->StartMonitoring();
       
   125 #ifdef IMAGEFINDERMONITORAO		
       
   126 	iImageFinderMonitor = CImageMonitorAO::NewL(iEngImp);
       
   127 	iImageFinderMonitor->iStatus = KRequestPending; 
       
   128 	iImageFinderMonitor->ActiveRequest();
       
   129 #endif    
       
   130 	//Create and start ImageFinder thread
       
   131 	iImageFinderThread = CFileFinderThread::NewL(
       
   132 	        this, 
       
   133 	        iFileNameData, 
       
   134 	        iFaceFilenameData, 
       
   135 	        iCritical, 
       
   136 	        rootPath);
       
   137 
       
   138 	iImageFinderThread->StartL();
       
   139 	
       
   140 	iMainThreadId = RThread().Id();
       
   141 	
       
   142 	DP0_IMAGIC(_L("CIEFileLoader::ConstructL--"));
       
   143 }
       
   144 
       
   145 CIEFileLoader::TImageFinderState CIEFileLoader::ImageFinderState() const
       
   146     {
       
   147     return iImageFinderState;
       
   148     //return (iImageFinderThread != NULL);
       
   149     }
       
   150 
       
   151 CIEImageList& CIEFileLoader::GetImageList()
       
   152     {
       
   153     return *iImageList;
       
   154     }
       
   155 
       
   156 void CIEFileLoader::StopImageFinder()
       
   157     {
       
   158     DP0_IMAGIC(_L("CIEFileLoader::Stop++"));
       
   159     if (iImageFinderState == EImageFinderRunning)
       
   160         iImageFinderState = EImageFinderStopping;
       
   161     DP0_IMAGIC(_L("CIEFileLoader::Stop--"));
       
   162     }
       
   163 
       
   164 void CIEFileLoader::ImageFinderStopped()
       
   165     {
       
   166     iImageFinderState = EImageFinderStopped;
       
   167     }
       
   168 
       
   169 void CIEFileLoader::ImageListChanged(TInt aIndex, TBool aAdded) 
       
   170     {
       
   171     iEngImp->GetObserver().ImageListChanged(aIndex, aAdded);
       
   172     }
       
   173 
       
   174 /* Added new image */
       
   175 void CIEFileLoader::AddNewImage(CImageData* aTmpImageData, TInt aImageIndex)
       
   176     {
       
   177     //Insert new image data to filename array
       
   178     iFileNameData.Insert(aTmpImageData, aImageIndex);
       
   179     }   
       
   180 
       
   181 /* Added new image */
       
   182 void CIEFileLoader::AddNewFaceCropImage(CImageData* aTmpImageData, TInt aImageIndex)
       
   183     {
       
   184     
       
   185     //Insert new image data to filename array
       
   186     aTmpImageData->iGridData.iCorrupted = EFalse;
       
   187     aTmpImageData->iGridData.iRotationAngle = 0;//rotation angle of one image
       
   188     aTmpImageData->iGridData.iTargetRotationAngle = 0;//target rotation angle of one image
       
   189     aTmpImageData->iGridData.iX = aTmpImageData->iGridData.iY = aTmpImageData->iGridData.iZ = 0;//OpenGL Z coord
       
   190     aTmpImageData->iGridData.iScale = 0;//OpenGL iScale
       
   191     aTmpImageData->iGridData.iGlLQ32TextIndex = 0;//OpenGL 32x32 texture index
       
   192     aTmpImageData->iGridData.iGlLQ128TextIndex = 0;//OpenGL 128x128 texture index
       
   193     aTmpImageData->iGridData.iGlHQ512TextIndex = 0;//OpenGL 512x512 texture index
       
   194     aTmpImageData->iGridData.iGlSuperHQTextIndex = 0;//OpenGL 2048x2048 texture index
       
   195     
       
   196     iFaceFilenameData.Insert(aTmpImageData, aImageIndex);
       
   197     }   
       
   198 
       
   199 
       
   200 /*
       
   201 void CIEFileLoader::StartFileSystemMonitoring()
       
   202     {
       
   203     //iFileSystemMonitor->StartMonitoring();    
       
   204     }
       
   205 
       
   206 void CIEFileLoader::StopFileSystemMonitoring()
       
   207     {
       
   208     //iFileSystemMonitor->StopMonitoring();    
       
   209     }
       
   210 
       
   211 void CIEFileLoader::FileSystemChanged()
       
   212     {
       
   213     
       
   214     }
       
   215 */
       
   216 CIEEngineImp* CIEFileLoader::GetEngineImpPtr()
       
   217     {
       
   218     return iEngImp;
       
   219     }
       
   220     
       
   221 void CIEFileLoader::ModifyImageData(CImageData* aTmpImageData, TInt aImageIndex)
       
   222     {
       
   223     //Insert new image data to filename array
       
   224     iFileNameData[aImageIndex] = aTmpImageData;
       
   225     }
       
   226 
       
   227 
       
   228 /* All files are added to fine name array */
       
   229 void CIEFileLoader::AllFilesAddedToFilenameArray()
       
   230     {
       
   231 #ifdef IMAGEFINDERMONITORAO        
       
   232     TRequestStatus* status = &iImageFinderMonitor->iStatus;
       
   233     RThread mainThread;
       
   234     mainThread.Open( iMainThreadId );
       
   235     mainThread.RequestComplete( status, KErrNone );
       
   236 #else    
       
   237     iEngImp->AllFilesAddedToFilenameArrayL();
       
   238 #endif    
       
   239     DP0_IMAGIC(_L("CIEFileLoader::AllFilesAddedToFilenameArray 1"));
       
   240     //JPG File counting completed
       
   241     //iJpgFileCountingComplete = ETrue;
       
   242     
       
   243     }
       
   244 
       
   245 //Only used for getting number of TNs in file system 
       
   246 #if 0
       
   247 void CIEFileLoader::SearchFileCountL(const TDesC& aRootPath, const TDesC& aSearchName, TInt& aImageFileCount, TInt& aFacesFileCount)
       
   248     {
       
   249     DP0_IMAGIC(_L("CIEFileLoader::SearchFileCountL++"));
       
   250     TInt error = KErrNone;
       
   251     TInt tnFileCount = 0;
       
   252     
       
   253     CDirScan* dirScan = CDirScan::NewL(iFileServer);
       
   254     dirScan->SetScanDataL(aRootPath, KEntryAttDir|KEntryAttMatchExclusive, ESortNone, CDirScan::EScanDownTree);
       
   255     
       
   256     while(1)
       
   257         {
       
   258          CDir* dir = NULL;
       
   259          dirScan->NextL(dir);
       
   260          
       
   261          if(error || !dir)
       
   262           break;
       
   263          
       
   264          delete dir;
       
   265          
       
   266          TBool isFace = EFalse;
       
   267          TPtrC FacesDir = dirScan->FullPath();
       
   268          if(FacesDir.Find(KFacesPath) != KErrNotFound)
       
   269              {
       
   270              aFacesFileCount += ScanDirFileCountL(dirScan->FullPath(), aSearchName);    
       
   271              }
       
   272          else
       
   273              {
       
   274              aImageFileCount += ScanDirFileCountL(dirScan->FullPath(), aSearchName);    
       
   275              }
       
   276          } 
       
   277     
       
   278     delete dirScan;
       
   279     dirScan = NULL;
       
   280     
       
   281     DP0_IMAGIC(_L("CIEFileLoader::SearchFileCountL--"));
       
   282     }
       
   283 
       
   284 
       
   285 //Only used for getting number of TNs in file system
       
   286 TInt CIEFileLoader::ScanDirFileCountL(const TDesC& aDir, const TDesC& aWild)
       
   287 {
       
   288     DP0_IMAGIC(_L("CIEFileLoader::ScanDirFileCountL++"));
       
   289     TParse parse;
       
   290     TInt count = 0;
       
   291     
       
   292     parse.Set(aWild, &aDir, NULL);
       
   293     TPtrC spec(parse.FullName());
       
   294 
       
   295     TFindFile findFile(iFileServer);
       
   296     CDir* dir;
       
   297     
       
   298     if (!findFile.FindWildByPath(parse.FullName(), NULL, dir))
       
   299     {
       
   300         CleanupStack::PushL(dir);
       
   301         
       
   302         count = dir->Count(); 
       
   303 
       
   304         CleanupStack::PopAndDestroy(dir);
       
   305     }
       
   306  
       
   307     return count;
       
   308 
       
   309 }
       
   310 #endif
       
   311 
       
   312 /* Deleting all corresponding Thumbnails including Gallery TNs */
       
   313 TInt CIEFileLoader::DeleteFile(TInt aIndex)
       
   314     {
       
   315     TInt err = KErrNotFound;
       
   316     if(aIndex < iFileNameData.Count())
       
   317         {
       
   318         err = DeleteFile(iFileNameData[aIndex]);
       
   319     
       
   320         if (err == KErrNone)
       
   321             {
       
   322             CImageData* imageData = iFileNameData[aIndex];
       
   323             iFileNameData.Remove(aIndex);
       
   324             delete imageData;
       
   325             iNumberOfImages = iFileNameData.Count();
       
   326             }
       
   327         }
       
   328     return err;
       
   329     }
       
   330 
       
   331 TInt CIEFileLoader::DeleteFile(const CImageData* aImageData)
       
   332     {
       
   333     TFileName fileName;
       
   334     TInt err = KErrNone;
       
   335 
       
   336     if(aImageData->IsImageReady(EFullSize))
       
   337         {
       
   338         aImageData->GetFileName(fileName, EFullSize);            
       
   339         TInt err = iFileServer.Delete(fileName);
       
   340         if (err != KErrNone)
       
   341             return err;
       
   342         }
       
   343     
       
   344     //Here if condition is not required. If the file does not exists
       
   345     //then it returns not found system error code ?
       
   346     //There is no value addition for extra check any way we have to remove
       
   347     // that index from the array...( Cross check)
       
   348     if(aImageData->IsImageReady(ESize128x128)) 
       
   349         {
       
   350         aImageData->GetFileName(fileName, ESize128x128);
       
   351         iFileServer.Delete(fileName);
       
   352         }
       
   353         
       
   354     if(aImageData->IsImageReady(ESize512x512))
       
   355         {
       
   356         aImageData->GetFileName(fileName, ESize512x512);        
       
   357         iFileServer.Delete(fileName);
       
   358         }
       
   359             
       
   360     if(aImageData->IsImageReady(ESize32x32))
       
   361         {
       
   362         aImageData->GetFileName(fileName, ESize32x32);
       
   363         iFileServer.Delete(fileName);
       
   364         }
       
   365     
       
   366     // Delete standard gallery thumbnail files
       
   367     TFileName path, imageName;
       
   368     aImageData->GetPath(path);
       
   369     aImageData->GetFileName(imageName);
       
   370     
       
   371     const TPtrC thumbPaths[] = { 
       
   372         _L("_PAlbTN\\320x320\\"), _L("_320x320"),
       
   373         _L("_PAlbTN\\320x240\\"), _L(""),
       
   374         _L("_PAlbTN\\170x128\\"), _L("_170x128"),        
       
   375         _L("_PAlbTN\\"), _L("_128x96"),
       
   376         _L("_PAlbTN\\64x64dat\\"), _L(""),
       
   377         _L("_PAlbTN\\56x42\\"), _L("_56x42")
       
   378     };
       
   379     
       
   380     for (TInt i = 0;i < sizeof(thumbPaths) / sizeof(TPtrC) ;i+=2)
       
   381         {
       
   382         fileName = path;
       
   383         fileName.Append(thumbPaths[i]);
       
   384         fileName.Append(imageName);
       
   385         fileName.Append(thumbPaths[i + 1]);
       
   386         iFileServer.Delete(fileName);
       
   387         }
       
   388 
       
   389     return err;
       
   390     }
       
   391 
       
   392 /* Deleting all corresponding Thumbnails including Gallery TNs */
       
   393 TInt CIEFileLoader::DeleteFaceFile(TInt aIndex)
       
   394     {
       
   395     TInt err = KErrNotFound;
       
   396     if(aIndex < iFaceFilenameData.Count())
       
   397         {
       
   398         //Here if condition is not required. If the file does not exists
       
   399         //then it returns not found system error code ?
       
   400         //There is no value addition for extra check any way we have to remove
       
   401         // that index from the array...( Cross check)
       
   402         err = DeleteFile(iFaceFilenameData[aIndex]);
       
   403         CImageData* imageData = iFaceFilenameData[aIndex];
       
   404         iFaceFilenameData.Remove(aIndex);
       
   405         delete imageData;
       
   406         iNumberOfFaces = iFaceFilenameData.Count();
       
   407         }
       
   408     return err;
       
   409     }
       
   410 
       
   411  
       
   412 RArray<CImageData*>& CIEFileLoader::GetFileNameArray()
       
   413 {
       
   414     return iFileNameData;
       
   415 }
       
   416 
       
   417 RArray<CImageData*>& CIEFileLoader::GetFacesFileNameArray()
       
   418 {
       
   419     return iFaceFilenameData;
       
   420 }
       
   421 
       
   422 TInt CIEFileLoader::GetTotalNumOfImages()
       
   423 {
       
   424     //return iNumberOfImages;
       
   425     return iFileNameData.Count();
       
   426 }
       
   427 
       
   428 void CIEFileLoader::GetTotalNumOfImages(TInt& aNumOfImages, TInt& aNumOfFaces)
       
   429     {
       
   430     aNumOfImages = iFileNameData.Count();
       
   431     aNumOfFaces = iFaceFilenameData.Count();
       
   432     }
       
   433 
       
   434 void CIEFileLoader::GetUpdatedNumOfImages(TInt& aNumOfImages, TInt& aNumOfFaces)
       
   435     {
       
   436     aNumOfImages = iFileNameData.Count();
       
   437     aNumOfFaces = iFaceFilenameData.Count();
       
   438     }
       
   439 
       
   440 void CIEFileLoader::GetFileNameL(TInt aFileIndex, TFileName& aFileName, TThumbSize aThumbRes)
       
   441 {
       
   442 	if(aFileIndex < 0 || aFileIndex > iFileNameData.Count())
       
   443 	    {
       
   444 		User::Leave(KErrArgument);
       
   445 	    }
       
   446 	else
       
   447 	    {
       
   448         iFileNameData[aFileIndex]->GetFileName(aFileName, aThumbRes);
       
   449     	}
       
   450 }
       
   451 
       
   452 /*CImageData* CIEFileLoader::GetImageData(TInt aIndex)
       
   453     {
       
   454     return (aIndex < iFileNameData.Count()) ? iFileNameData[aIndex] : NULL;
       
   455     }*/
       
   456 
       
   457 CImageData* CIEFileLoader::GetImageData(TInt aIndex/*, TImageArrayMode aMode*/)
       
   458     {
       
   459     return (aIndex >= 0 && aIndex < iFileNameData.Count()) ? iFileNameData[aIndex] : NULL;
       
   460     }
       
   461 
       
   462 void CIEFileLoader::SetImageData(TInt aIndex, CImageData* aGridData)
       
   463     {
       
   464     if(aIndex < iFileNameData.Count())
       
   465         iFileNameData[aIndex] = aGridData;
       
   466     }
       
   467 
       
   468 #ifdef _ACCELEROMETER_SUPPORTED_
       
   469 TImagicDeviceOrientation CIEFileLoader::DeviceOrientation()
       
   470     {
       
   471     return iEngImp->GetDeviceOrientation();
       
   472     }
       
   473 #endif
       
   474 
       
   475 // EOF