imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailcenrep.cpp
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     1 /*
       
     2 * Copyright (c) 2006-2007 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:
       
    13 *
       
    14 * Description:  Class for handling central repositoty data
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 
       
    21 #include <thumbnailmanager.h>
       
    22 
       
    23 #include "thumbnailcenrep.h"
       
    24 #include "thumbnailmanageruids.hrh"
       
    25 #include "thumbnailstore.h"
       
    26 #include "thumbnailmanagerconstants.h"
       
    27 #include "thumbnailmanagerprivatecrkeys.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // TThumbnailPersistentSize::TThumbnailPersistentSize
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 TThumbnailPersistentSize::TThumbnailPersistentSize( const TSize& aSize, TBool
       
    34     aCrop, TDisplayMode aMode, TInt aFormat ) : iSize( aSize ), iCrop( aCrop ),
       
    35     iMode( aMode ), iFormat( aFormat )
       
    36     {
       
    37     iType = EUnknownThumbnailSize;
       
    38     iSourceType = EUnknownSourceType;
       
    39     iAutoCreate = ETrue;
       
    40     iSizeType = EUnknownSizeType;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // TThumbnailPersistentSize::TThumbnailPersistentSize
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 TThumbnailPersistentSize::TThumbnailPersistentSize( TThumbnailSize aType,
       
    48     const TSize& aSize, TBool aCrop, TDisplayMode aMode, TInt aFormat,
       
    49     TBool aAutoCreate, TThumbnailSizeType aSizeType )
       
    50     : iType( aType ), iSize( aSize ), iCrop( aCrop ), iMode( aMode ),
       
    51       iFormat( aFormat ), iAutoCreate( aAutoCreate ), iSizeType( aSizeType ) 
       
    52     {
       
    53     switch ( aType )
       
    54         {        
       
    55         case EImageGridThumbnailSize:
       
    56         case EImageListThumbnailSize:
       
    57         case EImageFullScreenThumbnailSize:
       
    58             iSourceType = EImage;
       
    59             break;
       
    60         case EVideoGridThumbnailSize:
       
    61         case EVideoListThumbnailSize:
       
    62         case EVideoFullScreenThumbnailSize:  
       
    63             iSourceType = EVideo;
       
    64             break;
       
    65         case EAudioGridThumbnailSize:
       
    66         case EAudioListThumbnailSize:
       
    67         case EAudioFullScreenThumbnailSize:
       
    68             iSourceType = EAudio;
       
    69             break;
       
    70         case EContactGridThumbnailSize:
       
    71         case EContactListThumbnailSize:
       
    72         case EContactFullScreenThumbnailSize:
       
    73             iSourceType = EContact;
       
    74             break;
       
    75         default:
       
    76             iSourceType = EUnknownSourceType;        
       
    77         }
       
    78 
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // TThumbnailAutoCreate::TThumbnailAutoCreate
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 TThumbnailAutoCreate::TThumbnailAutoCreate()
       
    86     : iImageGrid(EFalse), iImageList(EFalse), iImageFullscreen(EFalse),
       
    87       iVideoGrid(EFalse), iVideoList(EFalse), iVideoFullscreen(EFalse),
       
    88       iAudioGrid(EFalse), iAudioList(EFalse), iAudioFullscreen(EFalse),
       
    89       iContactGrid(EFalse), iContactList(EFalse), iContactFullscreen(EFalse)
       
    90     {
       
    91     // No implementation required
       
    92     }
       
    93 
       
    94 // ======== MEMBER FUNCTIONS ========
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CThumbnailCenRep::CThumbnailCenRep()
       
    98 // C++ default constructor can NOT contain any code, that might leave.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CThumbnailCenRep::CThumbnailCenRep()
       
   102     {
       
   103     // No implementation required
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CThumbnailCenRep::~CThumbnailCenRep()
       
   109 // Destructor.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CThumbnailCenRep::~CThumbnailCenRep()
       
   113     {
       
   114     iPersistentSizes.Close();
       
   115     delete iAutoCreate;
       
   116     iAutoCreate = NULL;
       
   117     delete iRepository;
       
   118     iRepository = NULL;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CThumbnailCenRep::NewL()
       
   123 // Two-phased constructor.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CThumbnailCenRep* CThumbnailCenRep::NewL()
       
   127     {
       
   128     CThumbnailCenRep* self = new( ELeave )CThumbnailCenRep();
       
   129     CleanupStack::PushL( self );
       
   130     self->ConstructL();
       
   131     CleanupStack::Pop( self );
       
   132     return self;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CThumbnailCenRep::ConstructL()
       
   137 // Returns id of specific task.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CThumbnailCenRep::ConstructL()
       
   141     {
       
   142     iRepository = CRepository::NewL( TUid::Uid( THUMBNAIL_CENREP_UID ));
       
   143 
       
   144     TInt xSize( 0 );
       
   145     TInt ySize( 0 );
       
   146     TBool flags( EFalse );
       
   147     const TBool KGridAndListThumbnailCropped = ETrue; 
       
   148     TInt raw_mode( KThumbnailDefaultDisplayMode );
       
   149     TInt format( 0 );
       
   150     TBool autoCreate( EFalse );
       
   151     
       
   152     User::LeaveIfError( iRepository->Get( KSizeImageGridWidth, xSize ));
       
   153     User::LeaveIfError( iRepository->Get( KSizeImageGridHeight, ySize ));
       
   154     User::LeaveIfError( iRepository->Get( KAutoCreateImageGrid, autoCreate ));
       
   155 
       
   156     iPersistentSizes.AppendL( TThumbnailPersistentSize( EImageGridThumbnailSize, TSize( xSize, ySize ),
       
   157             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EGrid ));
       
   158 
       
   159     User::LeaveIfError( iRepository->Get( KSizeImageListWidth, xSize ));
       
   160     User::LeaveIfError( iRepository->Get( KSizeImageListHeight, ySize ));
       
   161     User::LeaveIfError( iRepository->Get( KAutoCreateImageList, autoCreate ));
       
   162 
       
   163     iPersistentSizes.AppendL( TThumbnailPersistentSize( EImageListThumbnailSize, TSize( xSize, ySize ),
       
   164             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EList ));
       
   165     
       
   166     User::LeaveIfError( iRepository->Get( KSizeImageFullscreenWidth, xSize ));
       
   167     User::LeaveIfError( iRepository->Get( KSizeImageFullscreenHeight, ySize ));
       
   168     User::LeaveIfError( iRepository->Get( KAutoCreateImageFullscreen, autoCreate ));
       
   169     
       
   170     iPersistentSizes.AppendL( TThumbnailPersistentSize( EImageFullScreenThumbnailSize, TSize( xSize, ySize ),
       
   171                               flags, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EFullscreen ));
       
   172     
       
   173     User::LeaveIfError( iRepository->Get( KSizeVideoGridWidth, xSize ));
       
   174     User::LeaveIfError( iRepository->Get( KSizeVideoGridHeight, ySize ));
       
   175     User::LeaveIfError( iRepository->Get( KAutoCreateVideoGrid, autoCreate ));
       
   176 
       
   177     iPersistentSizes.AppendL( TThumbnailPersistentSize( EVideoGridThumbnailSize, TSize( xSize, ySize ),
       
   178             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EGrid ));
       
   179 
       
   180     User::LeaveIfError( iRepository->Get( KSizeVideoListWidth, xSize ));
       
   181     User::LeaveIfError( iRepository->Get( KSizeVideoListHeight, ySize ));
       
   182     User::LeaveIfError( iRepository->Get( KAutoCreateVideoList, autoCreate ));
       
   183 
       
   184     iPersistentSizes.AppendL( TThumbnailPersistentSize( EVideoListThumbnailSize, TSize( xSize, ySize ),
       
   185             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EList ));
       
   186     
       
   187     User::LeaveIfError( iRepository->Get( KSizeVideoFullscreenWidth, xSize ));
       
   188     User::LeaveIfError( iRepository->Get( KSizeVideoFullscreenHeight, ySize ));
       
   189     User::LeaveIfError( iRepository->Get( KAutoCreateVideoFullscreen, autoCreate ));
       
   190     
       
   191     iPersistentSizes.AppendL( TThumbnailPersistentSize( EVideoFullScreenThumbnailSize, TSize( xSize, ySize ),
       
   192                               flags, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EFullscreen ));  
       
   193     
       
   194     User::LeaveIfError( iRepository->Get( KSizeAudioGridWidth, xSize ));
       
   195     User::LeaveIfError( iRepository->Get( KSizeAudioGridHeight, ySize ));
       
   196     User::LeaveIfError( iRepository->Get( KAutoCreateAudioGrid, autoCreate ));
       
   197 
       
   198     iPersistentSizes.AppendL( TThumbnailPersistentSize( EAudioGridThumbnailSize, TSize( xSize, ySize ),
       
   199             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EGrid ));
       
   200 
       
   201     User::LeaveIfError( iRepository->Get( KSizeAudioListWidth, xSize ));
       
   202     User::LeaveIfError( iRepository->Get( KSizeAudioListHeight, ySize ));
       
   203     User::LeaveIfError( iRepository->Get( KAutoCreateAudioList, autoCreate ));
       
   204 
       
   205     iPersistentSizes.AppendL( TThumbnailPersistentSize( EAudioListThumbnailSize, TSize( xSize, ySize ),
       
   206             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EList ));
       
   207     
       
   208     User::LeaveIfError( iRepository->Get( KSizeAudioFullscreenWidth, xSize ));
       
   209     User::LeaveIfError( iRepository->Get( KSizeAudioFullscreenHeight, ySize ));
       
   210     User::LeaveIfError( iRepository->Get( KAutoCreateAudioFullscreen, autoCreate ));
       
   211     
       
   212     iPersistentSizes.AppendL( TThumbnailPersistentSize( EAudioFullScreenThumbnailSize, TSize( xSize, ySize ),
       
   213                               flags, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EFullscreen ));     
       
   214 
       
   215 // Contact TN, set default values if not found
       
   216     if(iRepository->Get( KSizeContactGridWidth, xSize ) != KErrNone)
       
   217         {
       
   218         xSize = 54;
       
   219         }
       
   220     if( iRepository->Get( KSizeContactGridHeight, ySize ) != KErrNone)
       
   221         {
       
   222         ySize = 54;
       
   223         }
       
   224     
       
   225     if( iRepository->Get( KAutoCreateContactGrid, autoCreate ) != KErrNone)
       
   226     {
       
   227         autoCreate = 1;
       
   228     }
       
   229 
       
   230     iPersistentSizes.AppendL( TThumbnailPersistentSize( EContactGridThumbnailSize, TSize( xSize, ySize ),
       
   231             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EGrid ));
       
   232     
       
   233     if(  iRepository->Get( KSizeContactListWidth, xSize ) != KErrNone)
       
   234         {
       
   235         xSize = 64;
       
   236         }
       
   237     if(  iRepository->Get( KSizeContactListHeight, ySize ) != KErrNone)
       
   238         {
       
   239         ySize = 64;
       
   240         }
       
   241     if(  iRepository->Get( KAutoCreateContactList, autoCreate ) != KErrNone)
       
   242         {
       
   243         autoCreate = 1;
       
   244         }
       
   245 
       
   246     iPersistentSizes.AppendL( TThumbnailPersistentSize( EContactListThumbnailSize, TSize( xSize, ySize ),
       
   247             KGridAndListThumbnailCropped, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EList ));
       
   248     
       
   249     if( iRepository->Get( KSizeContactFullscreenWidth, xSize ) != KErrNone)
       
   250         {
       
   251         xSize = 250;
       
   252         }
       
   253     if( iRepository->Get( KSizeContactFullscreenHeight, ySize ) != KErrNone)
       
   254         {
       
   255         ySize = 250;
       
   256         }
       
   257     if( iRepository->Get( KAutoCreateContactFullscreen, autoCreate) != KErrNone)
       
   258         {
       
   259         autoCreate = 1;
       
   260         }
       
   261     
       
   262     iPersistentSizes.AppendL( TThumbnailPersistentSize( EContactFullScreenThumbnailSize, TSize( xSize, ySize ),
       
   263                               flags, static_cast <TDisplayMode> (raw_mode), format, autoCreate, TThumbnailPersistentSize::EFullscreen ));     
       
   264     
       
   265     
       
   266     iAutoCreate = new (ELeave) TThumbnailAutoCreate();
       
   267     
       
   268     User::LeaveIfError( iRepository->Get( KAutoCreateImageGrid, iAutoCreate->iImageGrid ));
       
   269     User::LeaveIfError( iRepository->Get( KAutoCreateImageList, iAutoCreate->iImageList ));
       
   270     User::LeaveIfError( iRepository->Get( KAutoCreateImageFullscreen, iAutoCreate->iImageFullscreen ));
       
   271     User::LeaveIfError( iRepository->Get( KAutoCreateVideoGrid, iAutoCreate->iVideoGrid ));
       
   272     User::LeaveIfError( iRepository->Get( KAutoCreateVideoList, iAutoCreate->iVideoList ));
       
   273     User::LeaveIfError( iRepository->Get( KAutoCreateVideoFullscreen, iAutoCreate->iVideoFullscreen ));
       
   274     User::LeaveIfError( iRepository->Get( KAutoCreateAudioGrid, iAutoCreate->iAudioGrid ));
       
   275     User::LeaveIfError( iRepository->Get( KAutoCreateAudioList, iAutoCreate->iAudioList ));
       
   276     User::LeaveIfError( iRepository->Get( KAutoCreateAudioFullscreen, iAutoCreate->iAudioFullscreen ));    
       
   277     
       
   278     if( iRepository->Get( KAutoCreateContactGrid, iAutoCreate->iContactGrid ) != KErrNone )
       
   279         {
       
   280         iAutoCreate->iContactGrid = 1;
       
   281         }
       
   282     if( iRepository->Get( KAutoCreateContactList, iAutoCreate->iContactList ) != KErrNone )
       
   283         {
       
   284         iAutoCreate->iContactList = 1;
       
   285         }
       
   286     if( iRepository->Get( KAutoCreateContactFullscreen, iAutoCreate->iContactFullscreen ) != KErrNone )
       
   287         {
       
   288         iAutoCreate->iContactFullscreen = 1;
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CThumbnailCenRep::GetPersistentSizes()
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 RArray < TThumbnailPersistentSize > & CThumbnailCenRep::GetPersistentSizes()
       
   297     {
       
   298     return iPersistentSizes;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CThumbnailCenRep::GetAutoCreateParams()
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 TThumbnailAutoCreate & CThumbnailCenRep::GetAutoCreateParams()
       
   306     {
       
   307     return *iAutoCreate;
       
   308     }
       
   309 
       
   310 TThumbnailPersistentSize & CThumbnailCenRep::PersistentSizeL( TThumbnailSize
       
   311         aThumbnailSize )
       
   312     {
       
   313     TThumbnailPersistentSize* persistentSize = NULL;
       
   314     TInt i = iPersistentSizes.Count();
       
   315     for ( ; --i >= 0; )
       
   316         {
       
   317         persistentSize = &iPersistentSizes[i];
       
   318         if ( persistentSize->iType == aThumbnailSize )
       
   319             {
       
   320             break;
       
   321             }
       
   322         }
       
   323     if ( i < 0 )
       
   324         { // size not found
       
   325         User::Leave( KErrNotFound );
       
   326         }
       
   327     
       
   328     return *persistentSize;
       
   329     }
       
   330 
       
   331 // End of file