filemanager/GFLM/src/CGflmFileFinderItem.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 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:  File finder item definitions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include <f32file.h>
       
    23 #include "CGflmFileFinderItem.h"
       
    24 #include "GflmUtils.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt16 KExactMatch = 0;
       
    28 const TInt16 KBeginMatch = 1;
       
    29 const TInt16 KNoMatch = KMaxTInt16;
       
    30 
       
    31 
       
    32 // ============================= LOCAL FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // GetSortValue
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 TInt16 GetSortValue( const TDesC& aName, const TDesC& aSearchString )
       
    39     {
       
    40     TInt16 ret( 0 );
       
    41     TInt pos( 0 );
       
    42     if ( GflmUtils::HasWildCard( aSearchString ) )
       
    43         {
       
    44         pos = aName.MatchC( aSearchString );
       
    45         if ( pos != KErrNotFound )
       
    46             {
       
    47             ret = KBeginMatch + pos;
       
    48             }
       
    49         else
       
    50             {
       
    51             ret = KNoMatch;
       
    52             }
       
    53         }
       
    54     else
       
    55         {
       
    56         pos = aName.FindC( aSearchString );
       
    57         if ( !pos && aName.Length() == aSearchString.Length() )
       
    58             {
       
    59             ret = KExactMatch;
       
    60             }
       
    61         else if ( pos != KErrNotFound )
       
    62             {
       
    63             ret = KBeginMatch + pos;
       
    64             }
       
    65         else
       
    66             {
       
    67             ret = KNoMatch;
       
    68             }
       
    69         }
       
    70     return ret;
       
    71     }
       
    72 
       
    73 // ============================ MEMBER FUNCTIONS ===============================
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CGflmFileFinderItem::CGflmFileFinderItem
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CGflmFileFinderItem::CGflmFileFinderItem( const TEntry& aEntry ) :
       
    80         iEntry( aEntry )
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CGflmFileFinderItem::NewLC
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CGflmFileFinderItem* CGflmFileFinderItem::NewLC(
       
    89         const TEntry& aFSEntry,
       
    90         const TDesC& aBasePath )
       
    91     {
       
    92     CGflmFileFinderItem* self = new( ELeave ) CGflmFileFinderItem( aFSEntry );
       
    93 
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL( aBasePath );
       
    96 
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CGflmFileFinderItem::ConstructL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CGflmFileFinderItem::ConstructL( const TDesC& aBasePath )
       
   105     {
       
   106     iBasePath = aBasePath.AllocL();
       
   107     SetBasePath( *iBasePath );
       
   108     SetEntry( iEntry );
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CGflmFileFinderItem::~CGflmFileFinderItem
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CGflmFileFinderItem::~CGflmFileFinderItem()
       
   116     {
       
   117     delete iBasePath;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CGflmFileFinderItem::PrepareSort
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CGflmFileFinderItem::PrepareSort(
       
   125         const TDesC& aSearchString )
       
   126     {
       
   127     iSortValue = GetSortValue( Name(), aSearchString );
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CGflmFileFinderItem::CompareByMatch
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TInt CGflmFileFinderItem::CompareByMatch(
       
   135         const CGflmGroupItem& aFirst,
       
   136         const CGflmGroupItem& aSecond )
       
   137     {
       
   138     const CGflmFileFinderItem& first(
       
   139         static_cast< const CGflmFileFinderItem& >( aFirst ) );
       
   140     const CGflmFileFinderItem& second(
       
   141         static_cast< const CGflmFileFinderItem& >( aSecond ) );
       
   142 
       
   143     if ( first.iSortValue == second.iSortValue )
       
   144         {
       
   145         // If both sort value is the same then the directory should be first
       
   146         TBool isFirstDir( first.iEntry.IsDir() );
       
   147         TBool isSecondDir( second.iEntry.IsDir() );
       
   148         if ( isFirstDir && !isSecondDir )
       
   149             {
       
   150             return -1;
       
   151             }
       
   152         if ( !isFirstDir && isSecondDir )
       
   153             {
       
   154             return 1;
       
   155             }
       
   156         // If even then alphabetical order is used
       
   157         return CompareByNameWithoutItemType( aFirst, aSecond );
       
   158         }
       
   159     if ( first.iSortValue < second.iSortValue )
       
   160         {
       
   161         return -1;
       
   162         }
       
   163     return 1;
       
   164     }
       
   165 
       
   166 //  End of File