|         |      1 /* | 
|         |      2 * Copyright (c) 2006 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:  Restore settings | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18  | 
|         |     19  | 
|         |     20 // INCLUDE FILES | 
|         |     21 #include <StringLoader.h> | 
|         |     22 #include <FileManagerEngine.rsg> | 
|         |     23 #include <AknUtils.h> | 
|         |     24 #include "FileManagerEngine.hrh" | 
|         |     25 #include "CFileManagerEngine.h" | 
|         |     26 #include "CFileManagerRestoreSettings.h" | 
|         |     27 #include "CFileManagerBackupSettings.h" | 
|         |     28 #include "TFileManagerDriveInfo.h" | 
|         |     29 #include "FileManagerPrivateCRKeys.h" | 
|         |     30 #include "FileManagerDebug.h" | 
|         |     31  | 
|         |     32  | 
|         |     33 // CONSTANTS | 
|         |     34 _LIT( KDateFormat1, "%1" ); | 
|         |     35 _LIT( KDateFormat2, "%2" ); | 
|         |     36 _LIT( KDateFormat3, "%3" ); | 
|         |     37 _LIT( KTimeFormatBefore, " %-B %J:%T" ); | 
|         |     38 _LIT( KTimeFormatAfter, " %J:%T %+B" ); | 
|         |     39 _LIT( KEmptyChar, " " ); | 
|         |     40 const TUint KSecondSeparator = 1; | 
|         |     41 const TUint KThirdSeparator = 2; | 
|         |     42 const TInt KTimeStrMax = 20; | 
|         |     43 _LIT( KSeparator, "\t" ); | 
|         |     44 const TInt KSeparatorSpace = 9; | 
|         |     45 _LIT( KIconFormat, "%d" ); | 
|         |     46 const TInt KIconIdStrMax = 3; | 
|         |     47 _LIT( KTimeSeparatorPlaceHolder, ":" ); | 
|         |     48 const TInt KHourMinSeparator = 1; | 
|         |     49  | 
|         |     50  | 
|         |     51 // ======== MEMBER FUNCTIONS ======== | 
|         |     52  | 
|         |     53 // ---------------------------------------------------------------------------- | 
|         |     54 // CFileManagerRestoreSettings::CFileManagerRestoreSettings | 
|         |     55 // ---------------------------------------------------------------------------- | 
|         |     56 // | 
|         |     57 CFileManagerRestoreSettings::CFileManagerRestoreSettings( | 
|         |     58         CFileManagerEngine& aEngine ) : | 
|         |     59     iEngine( aEngine ) | 
|         |     60     { | 
|         |     61     FUNC_LOG | 
|         |     62     } | 
|         |     63  | 
|         |     64 // ---------------------------------------------------------------------------- | 
|         |     65 // CFileManagerRestoreSettings::~CFileManagerRestoreSettings | 
|         |     66 // ---------------------------------------------------------------------------- | 
|         |     67 // | 
|         |     68 CFileManagerRestoreSettings::~CFileManagerRestoreSettings() | 
|         |     69     { | 
|         |     70     FUNC_LOG | 
|         |     71  | 
|         |     72     iList.ResetAndDestroy(); | 
|         |     73     iList.Close(); | 
|         |     74     } | 
|         |     75  | 
|         |     76 // ---------------------------------------------------------------------------- | 
|         |     77 // CFileManagerRestoreSettings::NewL | 
|         |     78 // ---------------------------------------------------------------------------- | 
|         |     79 // | 
|         |     80 CFileManagerRestoreSettings* CFileManagerRestoreSettings::NewL( | 
|         |     81         CFileManagerEngine& aEngine ) | 
|         |     82     { | 
|         |     83     CFileManagerRestoreSettings* self = | 
|         |     84         new ( ELeave ) CFileManagerRestoreSettings( | 
|         |     85             aEngine ); | 
|         |     86     CleanupStack::PushL( self ); | 
|         |     87     self->ConstructL(); | 
|         |     88     CleanupStack::Pop( self ); | 
|         |     89     return self; | 
|         |     90     } | 
|         |     91  | 
|         |     92 // ---------------------------------------------------------------------------- | 
|         |     93 // CFileManagerRestoreSettings::ConstructL | 
|         |     94 // ---------------------------------------------------------------------------- | 
|         |     95 // | 
|         |     96 void CFileManagerRestoreSettings::ConstructL() | 
|         |     97     { | 
|         |     98     FUNC_LOG | 
|         |     99  | 
|         |    100     RefreshL(); | 
|         |    101     } | 
|         |    102  | 
|         |    103 // ---------------------------------------------------------------------------- | 
|         |    104 // CFileManagerRestoreSettings::SetSelection | 
|         |    105 // ---------------------------------------------------------------------------- | 
|         |    106 // | 
|         |    107 EXPORT_C void CFileManagerRestoreSettings::SetSelection( | 
|         |    108         const TUint64& aSelection ) | 
|         |    109     { | 
|         |    110     iSelection = aSelection; | 
|         |    111     } | 
|         |    112  | 
|         |    113 // ---------------------------------------------------------------------------- | 
|         |    114 // CFileManagerRestoreSettings::RefreshL | 
|         |    115 // ---------------------------------------------------------------------------- | 
|         |    116 // | 
|         |    117 EXPORT_C void CFileManagerRestoreSettings::RefreshL() | 
|         |    118     { | 
|         |    119     FUNC_LOG | 
|         |    120      | 
|         |    121     iList.ResetAndDestroy(); | 
|         |    122  | 
|         |    123     RArray< TInfo > infoArray; | 
|         |    124     iEngine.GetRestoreInfoArrayL( infoArray ); | 
|         |    125     CleanupClosePushL( infoArray ); | 
|         |    126  | 
|         |    127     TInt count( infoArray.Count() ); | 
|         |    128     TUint32 mask( EFileManagerBackupContentFirst); | 
|         |    129     while ( mask <= EFileManagerBackupContentLast ) | 
|         |    130         { | 
|         |    131         for ( TInt i( 0 ); i < count; ++i ) | 
|         |    132             { | 
|         |    133             TInfo& info( infoArray[ i ] ); | 
|         |    134             if ( info.iContent & mask ) | 
|         |    135                 { | 
|         |    136                 CEntry* entry = CreateEntryLC( info ); | 
|         |    137                 iList.AppendL( entry ); | 
|         |    138                 CleanupStack::Pop( entry ); | 
|         |    139                 } | 
|         |    140             } | 
|         |    141         mask <<= 1; | 
|         |    142         } | 
|         |    143     CleanupStack::PopAndDestroy( &infoArray ); | 
|         |    144  | 
|         |    145     } | 
|         |    146  | 
|         |    147 // ---------------------------------------------------------------------------- | 
|         |    148 // CFileManagerRestoreSettings::CEntry::MdcaCount | 
|         |    149 // ---------------------------------------------------------------------------- | 
|         |    150 // | 
|         |    151 TInt CFileManagerRestoreSettings::MdcaCount() const | 
|         |    152     { | 
|         |    153     return iList.Count(); | 
|         |    154     } | 
|         |    155  | 
|         |    156 // ---------------------------------------------------------------------------- | 
|         |    157 // CFileManagerRestoreSettings::CEntry::MdcaPoint | 
|         |    158 // ---------------------------------------------------------------------------- | 
|         |    159 // | 
|         |    160 TPtrC CFileManagerRestoreSettings::MdcaPoint( TInt aIndex ) const | 
|         |    161     { | 
|         |    162     return TPtrC( *( iList[ aIndex ]->iText ) ); | 
|         |    163     } | 
|         |    164  | 
|         |    165 // ---------------------------------------------------------------------------- | 
|         |    166 // CFileManagerRestoreSettings::CEntry::CreateEntryLC | 
|         |    167 // ---------------------------------------------------------------------------- | 
|         |    168 // | 
|         |    169 CFileManagerRestoreSettings::CEntry* | 
|         |    170     CFileManagerRestoreSettings::CreateEntryLC( | 
|         |    171         const TInfo& aInfo ) | 
|         |    172     { | 
|         |    173     TBuf< KIconIdStrMax > iconStr; | 
|         |    174     CEntry* entry = new ( ELeave ) CEntry; | 
|         |    175     CleanupStack::PushL( entry ); | 
|         |    176  | 
|         |    177     TInt titleId( CFileManagerBackupSettings::ContentToTextId( aInfo.iContent ) ); | 
|         |    178     HBufC* title = StringLoader::LoadLC( titleId ); | 
|         |    179     HBufC* timeAndDate = DateTimeStringLC( aInfo.iTime ); | 
|         |    180     entry->iText = HBufC::NewL( | 
|         |    181         title->Length() + timeAndDate->Length() + KSeparatorSpace ); | 
|         |    182  | 
|         |    183     // "0\tFirstLabel\tSecondLabel\t0" | 
|         |    184     TPtr ptr( entry->iText->Des() ); | 
|         |    185     iconStr.Copy( KIconFormat ); | 
|         |    186     iconStr.Format( KIconFormat, EIconCheckBoxOff ); | 
|         |    187     ptr.Append( iconStr ); | 
|         |    188     ptr.Append( KSeparator ); | 
|         |    189     ptr.Append( *title ); | 
|         |    190     ptr.Append( KSeparator ); | 
|         |    191     ptr.Append( *timeAndDate ); | 
|         |    192     ptr.Append( KSeparator ); | 
|         |    193  | 
|         |    194     TUint32 drvState( 0 ); | 
|         |    195     if ( iEngine.DriveState( drvState, aInfo.iDrive ) == KErrNone ) | 
|         |    196         { | 
|         |    197         TInt icon( KErrNotFound ); | 
|         |    198         if ( drvState & TFileManagerDriveInfo::EDriveUsbMemory ) | 
|         |    199             { | 
|         |    200             icon = EIconUsbMemory; | 
|         |    201             } | 
|         |    202         else if ( drvState & TFileManagerDriveInfo::EDriveRemovable ) | 
|         |    203             { | 
|         |    204             icon = EIconMemoryCard; | 
|         |    205             } | 
|         |    206         if ( icon >= 0 ) | 
|         |    207             { | 
|         |    208             iconStr.Copy( KIconFormat ); | 
|         |    209             iconStr.Format( KIconFormat, icon ); | 
|         |    210             ptr.Append( iconStr ); | 
|         |    211             } | 
|         |    212         } | 
|         |    213     entry->iInfo = aInfo; | 
|         |    214  | 
|         |    215     CleanupStack::PopAndDestroy( timeAndDate ); | 
|         |    216     CleanupStack::PopAndDestroy( title ); | 
|         |    217     return entry; | 
|         |    218     } | 
|         |    219  | 
|         |    220 // ---------------------------------------------------------------------------- | 
|         |    221 // CFileManagerRestoreSettings::CEntry::~CEntry | 
|         |    222 // ---------------------------------------------------------------------------- | 
|         |    223 // | 
|         |    224 CFileManagerRestoreSettings::CEntry::~CEntry() | 
|         |    225     { | 
|         |    226     delete iText; | 
|         |    227     } | 
|         |    228  | 
|         |    229 // ---------------------------------------------------------------------------- | 
|         |    230 // CFileManagerRestoreSettings::GetSelectionL | 
|         |    231 // ---------------------------------------------------------------------------- | 
|         |    232 // | 
|         |    233 void CFileManagerRestoreSettings::GetSelectionL( | 
|         |    234         RArray< TInfo >& aInfoArray ) const | 
|         |    235     { | 
|         |    236     aInfoArray.Reset(); | 
|         |    237  | 
|         |    238     TInt count( iList.Count() ); | 
|         |    239  | 
|         |    240     for ( TInt i( 0 ); i < count; ++i ) | 
|         |    241         { | 
|         |    242         if ( ( ( ( TUint64 ) 1 ) << i ) & iSelection ) | 
|         |    243             { | 
|         |    244             aInfoArray.AppendL( iList[ i ]->iInfo ); | 
|         |    245             } | 
|         |    246         } | 
|         |    247     } | 
|         |    248  | 
|         |    249 // ---------------------------------------------------------------------------- | 
|         |    250 // CFileManagerRestoreSettings::DateTimeStringLC | 
|         |    251 // ---------------------------------------------------------------------------- | 
|         |    252 // | 
|         |    253 HBufC* CFileManagerRestoreSettings::DateTimeStringLC( const TTime& aTime ) | 
|         |    254     { | 
|         |    255     TBuf< KTimeStrMax > dateStr; | 
|         |    256     TBuf< KTimeStrMax > dateStrFormat; | 
|         |    257  | 
|         |    258     // Localized date separator form | 
|         |    259     TLocale local; | 
|         |    260     dateStrFormat.Append( KDateFormat1 ); | 
|         |    261     dateStrFormat.Append( local.DateSeparator( KSecondSeparator ) ); | 
|         |    262     dateStrFormat.Append( KDateFormat2 ); | 
|         |    263     dateStrFormat.Append( local.DateSeparator( KThirdSeparator ) ); | 
|         |    264     dateStrFormat.Append( KDateFormat3 ); | 
|         |    265     aTime.FormatL( dateStr, dateStrFormat ); | 
|         |    266  | 
|         |    267     TBuf< KTimeStrMax > timeFormatStr; | 
|         |    268     if ( local.AmPmSymbolPosition() == ELocaleBefore ) | 
|         |    269         { | 
|         |    270         timeFormatStr.Copy( KTimeFormatBefore ); | 
|         |    271         } | 
|         |    272     else | 
|         |    273         { | 
|         |    274         timeFormatStr.Copy( KTimeFormatAfter ); | 
|         |    275         } | 
|         |    276  | 
|         |    277     TChar timeSeparator( local.TimeSeparator( KHourMinSeparator ) ); | 
|         |    278     AknTextUtils::ReplaceCharacters( | 
|         |    279         timeFormatStr, KTimeSeparatorPlaceHolder, timeSeparator ); | 
|         |    280     TBuf< KTimeStrMax > timeStr; | 
|         |    281     aTime.FormatL( timeStr, timeFormatStr ); | 
|         |    282  | 
|         |    283     HBufC* buf = HBufC::NewLC( dateStr.Length() + | 
|         |    284                                KEmptyChar().Length() + | 
|         |    285                                timeStr.Length() ); | 
|         |    286     TPtr ptrBuffer( buf->Des() ); | 
|         |    287     ptrBuffer.Append( timeStr ); | 
|         |    288     ptrBuffer.Append( KEmptyChar ); | 
|         |    289     ptrBuffer.Append( dateStr ); | 
|         |    290  | 
|         |    291     return buf; | 
|         |    292     } | 
|         |    293  | 
|         |    294 // End of File |