author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// |
sl@0 | 15 |
|
sl@0 | 16 |
#include <e32base.h> |
sl@0 | 17 |
#include <bautils.h> |
sl@0 | 18 |
|
sl@0 | 19 |
#include "srtreader.h" |
sl@0 | 20 |
|
sl@0 | 21 |
/** Default constructor */ |
sl@0 | 22 |
CSrtReader::CSrtReader() |
sl@0 | 23 |
{ |
sl@0 | 24 |
} |
sl@0 | 25 |
|
sl@0 | 26 |
/** Allocates and constructs a srt subtitle source |
sl@0 | 27 |
|
sl@0 | 28 |
@param aFilePath the SRT subtitle file path |
sl@0 | 29 |
@return A pointer to the new object. |
sl@0 | 30 |
@leave If an error occurs, the method will leave with a system-wide error code. |
sl@0 | 31 |
*/ |
sl@0 | 32 |
CSrtReader* CSrtReader::NewL(const TDesC& aFilePath) |
sl@0 | 33 |
{ |
sl@0 | 34 |
CSrtReader* self = new(ELeave) CSrtReader(); |
sl@0 | 35 |
CleanupStack::PushL(self); |
sl@0 | 36 |
self->ConstructL(aFilePath); |
sl@0 | 37 |
CleanupStack::Pop(self); |
sl@0 | 38 |
return self; |
sl@0 | 39 |
} |
sl@0 | 40 |
|
sl@0 | 41 |
/** Initialises the srt reader |
sl@0 | 42 |
|
sl@0 | 43 |
@leave If an error occurs, the method will leave with a system-wide error code. |
sl@0 | 44 |
*/ |
sl@0 | 45 |
void CSrtReader::ConstructL(const TDesC& aFilePath) |
sl@0 | 46 |
{ |
sl@0 | 47 |
if (aFilePath.Length() < 1) |
sl@0 | 48 |
{ |
sl@0 | 49 |
User::Leave(KErrArgument); |
sl@0 | 50 |
} |
sl@0 | 51 |
|
sl@0 | 52 |
User::LeaveIfError(iFsSession.Connect()); |
sl@0 | 53 |
|
sl@0 | 54 |
if (BaflUtils::FileExists(iFsSession, aFilePath)) |
sl@0 | 55 |
{ |
sl@0 | 56 |
User::LeaveIfError(iSource.Open(iFsSession, aFilePath, EFileRead)); |
sl@0 | 57 |
} |
sl@0 | 58 |
else |
sl@0 | 59 |
{ |
sl@0 | 60 |
User::Leave(KErrNotFound); |
sl@0 | 61 |
} |
sl@0 | 62 |
} |
sl@0 | 63 |
|
sl@0 | 64 |
/** Destructor */ |
sl@0 | 65 |
CSrtReader::~CSrtReader() |
sl@0 | 66 |
{ |
sl@0 | 67 |
iSource.Close(); |
sl@0 | 68 |
iFsSession.Close(); |
sl@0 | 69 |
} |
sl@0 | 70 |
|
sl@0 | 71 |
void CSrtReader::GetSupportedSubtitleLanguagesL(RArray<TLanguage>& /*aLanguages*/) |
sl@0 | 72 |
{ |
sl@0 | 73 |
User::Leave(KErrNotSupported); |
sl@0 | 74 |
} |
sl@0 | 75 |
|
sl@0 | 76 |
TLanguage CSrtReader::SubtitleLanguageL() |
sl@0 | 77 |
{ |
sl@0 | 78 |
User::Leave(KErrNotSupported); |
sl@0 | 79 |
return ELangEnglish; |
sl@0 | 80 |
} |
sl@0 | 81 |
|
sl@0 | 82 |
void CSrtReader::SetSubtitleLanguageL(TLanguage /*aLanguage*/) |
sl@0 | 83 |
{ |
sl@0 | 84 |
User::Leave(KErrNotSupported); |
sl@0 | 85 |
} |
sl@0 | 86 |
|
sl@0 | 87 |
TInt CSrtReader::SetPosition(TInt aPosition) |
sl@0 | 88 |
{ |
sl@0 | 89 |
return iSource.Seek(ESeekStart, aPosition); |
sl@0 | 90 |
} |
sl@0 | 91 |
|
sl@0 | 92 |
TInt CSrtReader::GetBuffer(TDes8& aBuffer) |
sl@0 | 93 |
{ |
sl@0 | 94 |
TInt err = KErrNone; |
sl@0 | 95 |
TInt bufLen = aBuffer.MaxLength(); |
sl@0 | 96 |
|
sl@0 | 97 |
if (bufLen <= 0) |
sl@0 | 98 |
{ |
sl@0 | 99 |
return KErrArgument; |
sl@0 | 100 |
} |
sl@0 | 101 |
|
sl@0 | 102 |
err = iSource.Read(aBuffer); |
sl@0 | 103 |
|
sl@0 | 104 |
if (KErrNone == err) |
sl@0 | 105 |
{ |
sl@0 | 106 |
if (0 == aBuffer.Length()) |
sl@0 | 107 |
{ |
sl@0 | 108 |
err = KErrEof; |
sl@0 | 109 |
} |
sl@0 | 110 |
} |
sl@0 | 111 |
|
sl@0 | 112 |
return err; |
sl@0 | 113 |
} |
sl@0 | 114 |
|
sl@0 | 115 |
|
sl@0 | 116 |