Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "mmfsubtitleutility.h"
24 CMMFSubtitleUtility* CMMFSubtitleUtility::NewL(RMMFController& aController, RWsSession &aWs)
26 CMMFSubtitleUtility* self = new(ELeave) CMMFSubtitleUtility(aController);
27 CleanupStack::PushL(self);
28 self->ConstructL(aWs);
33 CMMFSubtitleUtility::CMMFSubtitleUtility(RMMFController& aController): iSubtitleSupportCustomCommands(aController)
37 void CMMFSubtitleUtility::ConstructL(RWsSession &aWs)
39 iDevice = new (ELeave) CWsScreenDevice(aWs);
40 User::LeaveIfError(iDevice->Construct());
41 iSubtitleGc = new (ELeave) CWindowGc(iDevice);
42 User::LeaveIfError(iSubtitleGc->Construct());
45 CMMFSubtitleUtility::~CMMFSubtitleUtility()
49 iSubtitleLanguages.Close();
50 iCrpDataArray.Close();
53 // Add subtitle related config to controller
54 TInt CMMFSubtitleUtility::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
56 TCrpData crpData(aConfig.iWindowId);
57 // Add the crp data before calling custom commands in case append fails
58 TInt err = iCrpDataArray.Append(crpData);
61 err = iSubtitleSupportCustomCommands.AddSubtitleConfig(aConfig);
65 // removed the added crp data on error
66 iCrpDataArray.Remove(iCrpDataArray.Count()-1);
73 // Found the index of the subtitle data in iCrpDataArray given aWindowId
74 TInt CMMFSubtitleUtility::FindCrpArrayIndex(TInt aWindowId)
76 TInt ret = KErrNotFound;
77 for (TInt i = iCrpDataArray.Count(); --i >= 0; )
79 if (iCrpDataArray[i].iWindowId == aWindowId)
88 // Remove subtitle related config from controller
89 TInt CMMFSubtitleUtility::RemoveSubtitleConfig(TInt aWindowId)
91 TInt ret = FindCrpArrayIndex(aWindowId);
94 iCrpDataArray.Remove(ret);
95 ret = iSubtitleSupportCustomCommands.RemoveSubtitleConfig(aWindowId);
100 // Update subtitle related config from controller and clear the subtitle region
101 TInt CMMFSubtitleUtility::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
103 TInt ret = FindCrpArrayIndex(aConfig.iWindowId);
107 iCrpDataArray[ret].iCrpId.Set(0);
109 ret = iSubtitleSupportCustomCommands.UpdateSubtitleConfig(aConfig);
114 // Return if subtitle is available
115 TBool CMMFSubtitleUtility::SubtitlesAvailable(RMMFController& aController)
117 TBool available = EFalse;
118 RMMFVideoPlaySubtitleSupportCustomCommands subtitleSupportCustomCommands(aController);
119 subtitleSupportCustomCommands.GetSubtitlesAvailable(available);
123 TInt CMMFSubtitleUtility::EnableSubtitles()
125 return iSubtitleSupportCustomCommands.EnableSubtitles();
128 void CMMFSubtitleUtility::DisableSubtitles()
130 for (TInt i = iCrpDataArray.Count(); --i >= 0; )
132 iSubtitleSupportCustomCommands.RemoveSubtitleConfig(iCrpDataArray[i].iWindowId);
135 iCrpDataArray.Reset();
137 // still need to send disable command to controller event if array count was 0
138 // because window may have been removed after subtitle is enabled
139 iSubtitleSupportCustomCommands.DisableSubtitles();
142 // Helper function to draw CRP
143 void CMMFSubtitleUtility::DrawCrp(RWindow& aWindow, TInt aCrpIdx, TBool aCallBeginRedraw)
145 TCrpData& crpData = iCrpDataArray[aCrpIdx];
147 if (crpData.iCrpId.Id() != 0)
150 if (aCallBeginRedraw)
152 // CRP is ready to be drawn
153 aWindow.Invalidate(crpData.iCrpRect);
154 aWindow.BeginRedraw(crpData.iCrpRect);
157 iSubtitleGc->Activate(aWindow);
158 iSubtitleGc->DrawWsGraphic(crpData.iCrpId, crpData.iCrpRect);
159 iSubtitleGc->Deactivate();
161 if (aCallBeginRedraw)
168 // Handle CRP ready event from controller and draw the CRP
169 void CMMFSubtitleUtility::HandleCrpReady(RWindow& aWindow)
171 TInt index = FindCrpArrayIndex(aWindow.WsHandle());
174 TCrpData& crpData = iCrpDataArray[index];
175 TInt err = iSubtitleSupportCustomCommands.GetCrpParameters(aWindow.WsHandle(),
181 DrawCrp(aWindow, index, ETrue);
185 // Window may have been removed before the event was received, ignore event
186 RDebug::Print(_L("CMMFSubtitleUtility::HandleCrpReady aWindowId=%d, err==%d"), aWindow.WsHandle(), err);
191 // Redraw subtitle CRP if redraw rect intersect with subtitle region
192 void CMMFSubtitleUtility::RedrawSubtitle(RWindow& aWindow, const TRect& aRedrawRect)
194 TInt index = FindCrpArrayIndex(aWindow.WsHandle());
195 if (index >= 0 && aRedrawRect.Intersects(iCrpDataArray[index].iCrpRect))
197 DrawCrp(aWindow, index, EFalse);
201 TInt CMMFSubtitleUtility::SetSubtitleLanguage(TLanguage aSubtitleLanguage)
203 return iSubtitleSupportCustomCommands.SetSubtitleLanguage(aSubtitleLanguage);
206 TArray<TLanguage> CMMFSubtitleUtility::SupportedSubtitleLanguagesL()
208 TRAPD(err, iSubtitleSupportCustomCommands.GetSupportedSubtitleLanguagesL(iSubtitleLanguages));
210 // Do not propagate KErrNotSupported; return empty list of languages.
211 if (KErrNone != err && KErrNotSupported != err)
215 return iSubtitleLanguages.Array();
218 TLanguage CMMFSubtitleUtility::SubtitleLanguage()
220 TLanguage language = ELangNone;
222 // ignore returned value, language parameter is unchanged on error
223 iSubtitleSupportCustomCommands.GetSubtitleLanguage(language);