sdkcreationmw/sdkcommonutils/util/Src/FolderScanner.cpp
author rajpuroh
Wed, 21 Apr 2010 09:56:53 +0530
changeset 1 ac50fd48361b
parent 0 b26acd06ea60
permissions -rw-r--r--
Second Contribution
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     1
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     2
* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     3
* All rights reserved.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     8
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     9
* Initial Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    11
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    12
* Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    13
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    14
* Description: 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    15
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    16
*/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    17
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    18
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    19
//  Include Files
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    20
#include "FolderScanner.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    21
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    22
EXPORT_C CFolderScanner::~CFolderScanner()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    23
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    24
	iFs.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    25
	delete iTimer;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    26
	delete iFolder;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    27
	delete iScanExt;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    28
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    29
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    30
void CFolderScanner::ConstructL(  CFolderScanner_if* client
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    31
								, const TDesC& folder
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    32
								, const TDesC& ext
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    33
								, int aScanPeriod)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    34
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    35
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    36
	iClient = client;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    37
	iTimeout = aScanPeriod;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    38
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    39
	iFolder = folder.AllocL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    40
	iScanExt = ext.AllocL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    41
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    42
	User::LeaveIfError(iFs.Connect());	
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    43
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    44
	// Check that folder really exist
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    45
    TEntry entry;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    46
	TInt err = iFs.Entry(folder, entry);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    47
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    48
	// If not found, attempt to create
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    49
	if(err == KErrNotFound)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    50
		{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    51
		err = iFs.MkDirAll(*iFolder);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    52
		}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    53
	User::LeaveIfError(err);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    54
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    55
	// Create a timer
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    56
	iTimer = CSysTimer::NewL(this, 0);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    57
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    58
	// we want first callback immediately
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    59
	iTimer->MilliSeconds(0);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    60
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    61
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    62
EXPORT_C CFolderScanner* CFolderScanner::NewL(  CFolderScanner_if* client
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    63
								, const TDesC& folder
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    64
								, const TDesC& ext
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    65
								, int aScanPeriod)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    66
	{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    67
	CFolderScanner* self = new (ELeave)CFolderScanner();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    68
	CleanupStack::PushL(self);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    69
	self->ConstructL(client, folder, ext, aScanPeriod);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    70
	CleanupStack::Pop();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    71
	return self;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    72
	}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    73
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    74
void CFolderScanner::Timer(int)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    75
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    76
    if(ScanOnce() == false)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    77
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    78
        iTimer->MilliSeconds(iTimeout);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    79
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    80
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    81
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    82
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    83
 * Scan folders contents once
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    84
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    85
inline bool CFolderScanner::ScanOnce()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    86
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    87
    // Perform scan
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    88
    CDir* SMSInList = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    89
    if (iFs.GetDir(*iFolder,KEntryAttNormal,ESortNone,SMSInList) == KErrNone)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    90
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    91
        for(TInt i = 0; i<SMSInList->Count(); i++)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    92
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    93
            // if we're given a wild card, we ignore chars before '.'
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    94
            // just extension chars?
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    95
            const TEntry& entry = (*SMSInList)[i];
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    96
            if (!entry.IsDir())
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    97
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    98
                TPtrC ext(entry.iName.Mid(entry.iName.LocateReverse('.')));
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    99
                if (!ext.CompareF(iScanExt->Mid(iScanExt->LocateReverse('.'))))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   100
                {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   101
                    TFileName fileName;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   102
                    fileName.Append(*iFolder);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   103
                    fileName.Append(entry.iName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   104
                    iClient->FileFound(fileName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   105
                    delete SMSInList;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   106
                    return true;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   107
                }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   108
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   109
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   110
        delete SMSInList;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   111
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   112
    return false;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   113
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   114
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   115
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   116
 * We continue scanning by getting a callback asap
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   117
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   118
EXPORT_C void CFolderScanner::ContinueScan()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   119
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   120
    iTimer->MilliSeconds(0);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   121
}