videditor/ManualVideoEditor/src/VeiTrimForMmsContainer.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description: 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 // System includes
       
    23 #include <AknIconUtils.h>   // AknIconUtils
       
    24 #include <eikenv.h>     // iEikonEnv
       
    25 #include <manualvideoeditor.rsg>    // Video Editor resources
       
    26 #include <StringLoader.h>   // StringLoader
       
    27 
       
    28 #include <aknbiditextutils.h>
       
    29 #include <gulfont.h>
       
    30 
       
    31 #include <aknsdrawutils.h> 
       
    32 #include <aknsdatacontext.h> 
       
    33 #include <aknsbasicbackgroundcontrolcontext.h>
       
    34 
       
    35 #include <AknProgressDialog.h> 
       
    36 #include <eikprogi.h>
       
    37 #include <AknWaitDialog.h>
       
    38 
       
    39 
       
    40 // User includes
       
    41 #include "VeiTrimForMmsContainer.h"
       
    42 #include "VeiVideoDisplay.h"
       
    43 #include "VideoEditorCommon.h"
       
    44 #include "VideoEditorHelp.hlp.hrh"  // Topic contexts (literals)
       
    45 #include "veiframetaker.h"
       
    46 #include "VeiTrimForMmsView.h"
       
    47 #include "VeiCutterBar.h"
       
    48 #include "VeiVideoEditorSettings.h"
       
    49 #include "VideoEditorUtils.h"
       
    50 #include "VideoEditorDebugUtils.h"
       
    51 
       
    52 void CVeiTrimForMmsContainer::DialogDismissedL( TInt /*aButtonId*/ )
       
    53     {
       
    54     iProgressInfo = NULL;
       
    55     }
       
    56 
       
    57 
       
    58 CVeiTrimForMmsContainer* CVeiTrimForMmsContainer::NewL( const TRect& aRect, 
       
    59                                                         CVedMovie& aMovie, 
       
    60                                                         CVeiTrimForMmsView& aView )
       
    61     {
       
    62     CVeiTrimForMmsContainer* self = CVeiTrimForMmsContainer::NewLC( aRect, aMovie, aView );
       
    63     CleanupStack::Pop( self );
       
    64 
       
    65     return self;
       
    66     }
       
    67 
       
    68 CVeiTrimForMmsContainer* CVeiTrimForMmsContainer::NewLC( const TRect& aRect, 
       
    69                                                          CVedMovie& aMovie, 
       
    70                                                          CVeiTrimForMmsView& aView )
       
    71     {
       
    72     CVeiTrimForMmsContainer* self = new( ELeave )CVeiTrimForMmsContainer( aMovie, aView );
       
    73 
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aRect );
       
    76 
       
    77     return self;
       
    78     }
       
    79 
       
    80 
       
    81 CVeiTrimForMmsContainer::CVeiTrimForMmsContainer( CVedMovie& aMovie, CVeiTrimForMmsView& aView ): 
       
    82                             iLastKeyLeftOrRight( EFalse ), iMovie( aMovie ), iView( aView )
       
    83 
       
    84 {}
       
    85 
       
    86 
       
    87 void CVeiTrimForMmsContainer::ConstructL( const TRect& aRect )
       
    88     {
       
    89     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::ConstructL: in" );
       
    90 
       
    91     // Make this compound control window-owning.
       
    92     CreateWindowL();
       
    93 
       
    94     iMovie.RegisterMovieObserverL( this );
       
    95 
       
    96     // Read the texts shown above the thumbnails from resources
       
    97     iStartText = StringLoader::LoadL( R_VED_THUMBNAIL_START_TEXT, iEikonEnv );
       
    98     iEndText = StringLoader::LoadL( R_VED_THUMBNAIL_END_TEXT, iEikonEnv );
       
    99 
       
   100     iSeekPos = TTimeIntervalMicroSeconds( 0 );
       
   101 
       
   102     iVideoDisplayStart = CVeiVideoDisplay::NewL( iVideoDisplayStartRect, this, *this );
       
   103 
       
   104     iVideoDisplayEnd = CVeiVideoDisplay::NewL( iVideoDisplayEndRect, this, * this );
       
   105 
       
   106     iCutterBar = CVeiCutterBar::NewL( this );
       
   107     iCutterBar->SetPlayHeadVisible( EFalse );
       
   108     iVideoDisplay = CVeiVideoDisplay::NewL( aRect, this, * this );
       
   109 
       
   110     iFrameTaker = CVeiFrameTaker::NewL( *this );
       
   111 
       
   112     /* Timer to keep back light on when user is not giving key events */
       
   113     iScreenLight = CVeiDisplayLighter::NewL();
       
   114     CVeiVideoEditorSettings::GetMaxMmsSizeL( iMaxMmsSize );
       
   115     /* SharedData returns maxmmssize in kbytes. Change it to bytes(1000) and
       
   116     add some margin to final value.*/
       
   117     iMaxMmsSize = STATIC_CAST( TInt, iMaxMmsSize* 0.98 );
       
   118     iBlack = EFalse;
       
   119 
       
   120     // Set this control extent.
       
   121     SetRect( aRect );
       
   122     iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
   123 
       
   124     ActivateL();
       
   125 
       
   126     iKeyEnable = EFalse;
       
   127     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::ConstructL: out" );
       
   128     }
       
   129 
       
   130 
       
   131 
       
   132 CVeiTrimForMmsContainer::~CVeiTrimForMmsContainer()
       
   133     {
       
   134     iMovie.UnregisterMovieObserver( this );
       
   135 
       
   136     delete iEndText;
       
   137     delete iStartText;
       
   138     delete iScreenLight;
       
   139 
       
   140     delete iCutterBar;
       
   141 
       
   142     delete iVideoDisplayStart;
       
   143     delete iVideoDisplayEnd;
       
   144     if ( iVideoDisplay )
       
   145         {
       
   146         delete iVideoDisplay;
       
   147         iVideoDisplay = NULL;
       
   148         }
       
   149 
       
   150     if ( iFrameTaker )
       
   151         {
       
   152         delete iFrameTaker;
       
   153         iFrameTaker = NULL;
       
   154         }
       
   155 
       
   156     if ( iProgressNote )
       
   157         {
       
   158         delete iProgressNote;
       
   159         iProgressNote = NULL;
       
   160         }
       
   161     iProgressInfo = NULL;
       
   162 
       
   163     delete iBgContext;
       
   164     }
       
   165 
       
   166 void CVeiTrimForMmsContainer::SetMaxMmsSize( TInt aMaxSizeInBytes )
       
   167     {
       
   168     iMaxMmsSize = aMaxSizeInBytes;
       
   169     }
       
   170 
       
   171 const TTimeIntervalMicroSeconds& CVeiTrimForMmsContainer::CutInTime()const
       
   172     {
       
   173     return iSeekPos;
       
   174     }
       
   175 
       
   176 
       
   177 const TTimeIntervalMicroSeconds& CVeiTrimForMmsContainer::CutOutTime()const
       
   178     {
       
   179     return iSeekEndPos;
       
   180     }
       
   181 
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // CVeiTrimForMmsContainer::ComponentControl(...) const
       
   185 //
       
   186 // Gets the specified component of a compound control. 
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 CCoeControl* CVeiTrimForMmsContainer::ComponentControl( TInt aIndex )const
       
   190     {
       
   191     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::ComponentControl()" );
       
   192 
       
   193     switch ( aIndex )
       
   194         {
       
   195         //
       
   196         // iCutterDisplay
       
   197         //
       
   198         case ECutFrame:
       
   199                 {
       
   200                 return iCutterBar;
       
   201                 }
       
   202             //
       
   203             // iVideoDisplayStart
       
   204             //
       
   205         case EVideoDisplayStart:
       
   206                 {
       
   207                 return iVideoDisplayStart;
       
   208                 }
       
   209             //
       
   210             // iVideoDisplayEnd
       
   211             //
       
   212         case EVideoDisplayEnd:
       
   213                 {
       
   214                 return iVideoDisplayEnd;
       
   215                 }
       
   216             //
       
   217             // iVideoDisplay
       
   218             //
       
   219         case EVideoPreview:
       
   220                 {
       
   221                 return iVideoDisplay;
       
   222                 }
       
   223             //
       
   224             // Default
       
   225             //
       
   226         default:
       
   227                 {
       
   228                 return NULL;
       
   229                 }
       
   230         }
       
   231 
       
   232     }
       
   233 
       
   234 
       
   235 // ----------------------------------------------------------------------------
       
   236 // CVeiTrimForMmsContainer::CountComponentControls() const
       
   237 //
       
   238 // Gets the number of controls contained in a compound control.
       
   239 // ----------------------------------------------------------------------------
       
   240 //
       
   241 TInt CVeiTrimForMmsContainer::CountComponentControls()const
       
   242     {
       
   243     return ENumberOfControls;
       
   244     }
       
   245 
       
   246 
       
   247 void CVeiTrimForMmsContainer::Draw( const TRect& aRect )const
       
   248     {
       
   249     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::Draw(): In" );
       
   250 
       
   251     CWindowGc& gc = SystemGc();
       
   252     gc.Clear( aRect );
       
   253 
       
   254     // Black backbround for the preview
       
   255     if ( iBlack )
       
   256         {
       
   257         iVideoDisplay->MakeVisible( EFalse );
       
   258         gc.SetPenStyle( CWindowGc::ENullPen );
       
   259         gc.SetBrushColor( KRgbBlack );
       
   260         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   261         gc.DrawRect( aRect );
       
   262         gc.SetPenStyle( CWindowGc::ESolidPen );
       
   263         gc.DrawRoundRect( aRect, TSize( 4, 4 ));
       
   264         return ;
       
   265         }
       
   266     else
       
   267         {
       
   268         // Draw skin background
       
   269         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   270         MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   271         AknsDrawUtils::Background( skin, cc, this, gc, aRect );
       
   272 
       
   273         // Get text color from skin
       
   274         TRgb textColor( KRgbBlack );
       
   275         AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   276         gc.SetPenColor( textColor );
       
   277 
       
   278         const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontSecondaryFont );
       
   279         TBuf < 95 > startVisualText;
       
   280         TPoint startTextPoint;
       
   281         TBuf < 95 > endVisualText;
       
   282         TPoint endTextPoint;
       
   283 
       
   284         startTextPoint.iY = iStartTextBox.iTl.iY + font->HeightInPixels();
       
   285         endTextPoint.iY = iEndTextBox.iTl.iY + font->HeightInPixels();
       
   286 
       
   287         gc.UseFont( font );
       
   288 
       
   289         TBidiText::TDirectionality textDirectionality;
       
   290 
       
   291         textDirectionality = AknTextUtils::CurrentScriptDirectionality();
       
   292 
       
   293         TInt maxWidthNonClippingStart = iStartTextBox.Width();
       
   294 
       
   295         AknBidiTextUtils::ConvertToVisualAndClip( *iStartText, 
       
   296                                                   startVisualText, 
       
   297                                                   *font, 
       
   298                                                   maxWidthNonClippingStart, 
       
   299                                                   maxWidthNonClippingStart );
       
   300         /** check text alignment */
       
   301         if ( textDirectionality == TBidiText::ELeftToRight )
       
   302             {
       
   303             startTextPoint.iX = iVideoDisplayStartRect.iTl.iX;
       
   304             }
       
   305         else
       
   306             {
       
   307             startTextPoint.iX = iVideoDisplayStartRect.iBr.iX - font->TextWidthInPixels( startVisualText );
       
   308             }
       
   309 
       
   310         gc.DrawText( startVisualText, startTextPoint );
       
   311 
       
   312 
       
   313         TInt maxWidthNonClippingEnd = iEndTextBox.Width();
       
   314 
       
   315         AknBidiTextUtils::ConvertToVisualAndClip( *iEndText, 
       
   316                                                   endVisualText, 
       
   317                                                   *font, 
       
   318                                                   maxWidthNonClippingEnd, 
       
   319                                                   maxWidthNonClippingEnd );
       
   320         /** check text alignment */
       
   321         if ( textDirectionality == TBidiText::ELeftToRight )
       
   322             {
       
   323             endTextPoint.iX = iVideoDisplayEndRect.iTl.iX;
       
   324             }
       
   325         else
       
   326             {
       
   327             endTextPoint.iX = iVideoDisplayEndRect.iBr.iX - font->TextWidthInPixels( endVisualText );
       
   328             }
       
   329 
       
   330         gc.DrawText( endVisualText, endTextPoint );
       
   331 
       
   332         gc.DiscardFont();
       
   333 
       
   334         // Draw Start/End displays
       
   335         iVideoDisplayStart->SetRect( iVideoDisplayStartRect );
       
   336         iVideoDisplayEnd->SetRect( iVideoDisplayEndRect );
       
   337 
       
   338         if ( iPreviewState == EPlaying )
       
   339             {
       
   340             iVideoDisplay->MakeVisible( ETrue );
       
   341             }
       
   342         else
       
   343             {
       
   344             iVideoDisplay->MakeVisible( EFalse );
       
   345             }
       
   346 
       
   347         }
       
   348 
       
   349     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::Draw(): Out" );
       
   350     }
       
   351 
       
   352 
       
   353 // ----------------------------------------------------------------------------
       
   354 // CVeiTrimForMmsContainer::GetHelpContext(...) const
       
   355 //
       
   356 // Gets the control's help context. Associates the control with a particular
       
   357 // Help file and topic in a context sensitive application.
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void CVeiTrimForMmsContainer::GetHelpContext( TCoeHelpContext& aContext )const
       
   361     {
       
   362     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::GetHelpContext(): In" );
       
   363 
       
   364     // Set UID of the CS Help file (same as application UID).
       
   365     aContext.iMajor = KUidVideoEditor;
       
   366 
       
   367     // Set the context/topic.
       
   368     aContext.iContext = KVED_HLP_TRIM_FOR_MMS_VIEW;
       
   369 
       
   370     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::GetHelpContext(): Out" );
       
   371     }
       
   372 
       
   373 // ----------------------------------------------------------------------------
       
   374 // CVeiTrimForMmsContainer::SizeChanged()
       
   375 //
       
   376 // The function is called whenever SetExtent(), SetSize(), SetRect(),
       
   377 // SetCornerAndSize(), or SetExtentToWholeScreen() are called on the control.
       
   378 // ----------------------------------------------------------------------------
       
   379 //
       
   380 void CVeiTrimForMmsContainer::SizeChanged()
       
   381     {
       
   382     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::SizeChanged(): In" );
       
   383 
       
   384     TRect rect = Rect();
       
   385     if ( iBgContext )
       
   386         {
       
   387         iBgContext->SetRect( rect );
       
   388         }
       
   389 
       
   390     if ( VideoEditorUtils::IsLandscapeScreenOrientation())
       
   391     //Landscape
       
   392         {
       
   393         //  Start Text rect
       
   394         TInt startTextTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.00962 );
       
   395         TInt startTextTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.01389 );
       
   396         TInt startTextBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.49512 );
       
   397         TInt startTextBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.09375 );
       
   398 
       
   399         iStartTextBox = TRect( startTextTlX, startTextTlY, startTextBrX, startTextBrY );
       
   400         //  End Text rect
       
   401         TInt endTextTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.50481 );
       
   402         TInt endTextTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.01389 );
       
   403         TInt endTextBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.99039 );
       
   404         TInt endTextBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.09375 );
       
   405 
       
   406         iEndTextBox = TRect( endTextTlX, endTextTlY, endTextBrX, endTextBrY );
       
   407 
       
   408         // Start Video rect
       
   409         TInt startVideoTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.00962 );
       
   410         TInt startVideoTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.10764 );
       
   411         TInt startVideoBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.49512 );
       
   412         TInt startVideoBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.68056 );
       
   413 
       
   414         iVideoDisplayStartRect = TRect( startVideoTlX, startVideoTlY, startVideoBrX, startVideoBrY );
       
   415         //  End Video rect
       
   416         TInt endVideoTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.50481 );
       
   417         TInt endVideoTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.10764 );
       
   418         TInt endVideoBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.99039 );
       
   419         TInt endVideoBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.68056 );
       
   420 
       
   421         iVideoDisplayEndRect = TRect( endVideoTlX, endVideoTlY, endVideoBrX, endVideoBrY );
       
   422 
       
   423         // Timeline rect
       
   424         TInt timeLineTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.0114 );
       
   425         TInt timeLineTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.80208 );
       
   426 
       
   427         TSize cutBarSize = TSize( STATIC_CAST( TInt, rect.iBr.iX* 0.9773 ), STATIC_CAST( TInt, rect.iBr.iY* 0.0973 ));
       
   428 
       
   429         iTimelineRect = TRect( TPoint( timeLineTlX, timeLineTlY ), cutBarSize );
       
   430         }
       
   431     else
       
   432     // Portrait
       
   433         {
       
   434         //  Start Text rect
       
   435         TInt startTextTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.01136 );
       
   436         TInt startTextTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.01389 );
       
   437         TInt startTextBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.49432 );
       
   438         TInt startTextBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.10417 );
       
   439 
       
   440         iStartTextBox = TRect( startTextTlX, startTextTlY, startTextBrX, startTextBrY );
       
   441 
       
   442         //  End Text rect
       
   443         TInt endTextTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.50568 );
       
   444         TInt endTextTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.01389 );
       
   445         TInt endTextBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.98864 );
       
   446         TInt endTextBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.10417 );
       
   447 
       
   448         iEndTextBox = TRect( endTextTlX, endTextTlY, endTextBrX, endTextBrY );
       
   449 
       
   450         // Start Video rect
       
   451         TInt startVideoTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.01136 );
       
   452         TInt startVideoTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.11806 );
       
   453         TInt startVideoBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.49432 );
       
   454         TInt startVideoBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.60069 );
       
   455 
       
   456         iVideoDisplayStartRect = TRect( startVideoTlX, startVideoTlY, startVideoBrX, startVideoBrY );
       
   457 
       
   458         //  End Video rect
       
   459         TInt endVideoTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.50568 );
       
   460         TInt endVideoTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.11806 );
       
   461         TInt endVideoBrX = STATIC_CAST( TInt, rect.iBr.iX* 0.98864 );
       
   462         TInt endVideoBrY = STATIC_CAST( TInt, rect.iBr.iY* 0.60069 );
       
   463 
       
   464         iVideoDisplayEndRect = TRect( endVideoTlX, endVideoTlY, endVideoBrX, endVideoBrY );
       
   465 
       
   466         // Timeline rect
       
   467         TInt timeLineTlX = STATIC_CAST( TInt, rect.iBr.iX* 0.0114 );
       
   468         TInt timeLineTlY = STATIC_CAST( TInt, rect.iBr.iY* 0.767361 );
       
   469 
       
   470 
       
   471         TSize cutBarSize = TSize( STATIC_CAST( TInt, rect.iBr.iX* 0.9773 ), STATIC_CAST( TInt, rect.iBr.iY* 0.0973 ));
       
   472 
       
   473         iTimelineRect = TRect( TPoint( timeLineTlX, timeLineTlY ), cutBarSize );
       
   474         }
       
   475 
       
   476     iCutterBar->SetRect( iTimelineRect );
       
   477 
       
   478     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::SizeChanged(): Out" );
       
   479     }
       
   480 
       
   481 TKeyResponse CVeiTrimForMmsContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   482     {
       
   483     if ( iKeyEnable )
       
   484         {
       
   485         switch ( aType )
       
   486             {
       
   487             //
       
   488             // Key down event
       
   489             //
       
   490             case EEventKeyDown:
       
   491                     {
       
   492                     iKeyRepeatCount = 0;
       
   493                     if ( iPreviewState == EPlaying )
       
   494                         {
       
   495                         //					iView.SetTrimStateL( CVeiTrimForMmsView::ESeek );
       
   496                         //					Stop( ETrue );
       
   497                         return EKeyWasConsumed;
       
   498                         }
       
   499                     else
       
   500                         {
       
   501                         //iMovie.VideoClipSetCutInTime( 0,TTimeIntervalMicroSeconds(0) );
       
   502                         //iMovie.VideoClipSetCutOutTime( 0, iDuration );
       
   503                         return EKeyWasConsumed;
       
   504                         }
       
   505                     }
       
   506                 //
       
   507                 // The key event
       
   508                 //
       
   509             case EEventKey:
       
   510                     {
       
   511                     if ( iPreviewState == EPlaying )
       
   512                         {
       
   513                         return EKeyWasConsumed;
       
   514                         }
       
   515                     switch ( aKeyEvent.iCode )
       
   516                         {
       
   517                         //
       
   518                         // Navi-key right
       
   519                         //
       
   520                     case EKeyRightArrow:
       
   521                             {
       
   522 
       
   523                             if ( 0 == iKeyRepeatCount )
       
   524                                 {
       
   525                                 iMovie.VideoClipSetCutInTime( 0, TTimeIntervalMicroSeconds( 0 ));
       
   526                                 iMovie.VideoClipSetCutOutTime( 0, iDuration );
       
   527                                 }
       
   528 
       
   529                             if ( iSeekEndPos != iDuration )
       
   530                                 {
       
   531                                 iSeekEvent = ETrue;
       
   532                                 iLastKeyLeftOrRight = ETrue;
       
   533                                 if ( iKeyRepeatCount < 18 )
       
   534                                     {
       
   535                                     iKeyRepeatCount++;
       
   536                                     }
       
   537 
       
   538                                 TInt adjustment = TimeIncrement( iKeyRepeatCount );
       
   539                                 TInt64 newPos = iSeekPos.Int64() + adjustment;
       
   540 
       
   541                                 TTimeIntervalMicroSeconds endTime( 0 );
       
   542                                 iMovie.GetDurationEstimateL( iMaxMmsSize, newPos, endTime );
       
   543 
       
   544                                 // what is the reasoning behid this?
       
   545                                 // should args be checked before call to GetDurationEstimateL(), like in 
       
   546                                 // EKeyLeftArrow?
       
   547                                 if ( endTime.Int64() >= iDuration.Int64() - adjustment )
       
   548                                     {
       
   549                                     iKeyRepeatCount -= 3;
       
   550                                     adjustment = TimeIncrement( iKeyRepeatCount );
       
   551                                     endTime = iDuration;
       
   552                                     newPos += adjustment;
       
   553                                     }
       
   554 
       
   555                                 iSeekPos = TTimeIntervalMicroSeconds( newPos );
       
   556                                 iSeekEndPos = endTime;
       
   557                                 iCutterBar->SetInPoint( iSeekPos );
       
   558                                 iCutterBar->SetOutPoint( endTime );
       
   559                                 }
       
   560 
       
   561                             return EKeyWasConsumed;
       
   562                             }
       
   563                         //
       
   564                         // Navi-key left
       
   565                         //
       
   566                     case EKeyLeftArrow:
       
   567                             {
       
   568 
       
   569                             if ( 0 == iKeyRepeatCount )
       
   570                                 {
       
   571                                 iMovie.VideoClipSetCutInTime( 0, TTimeIntervalMicroSeconds( 0 ));
       
   572                                 iMovie.VideoClipSetCutOutTime( 0, iDuration );
       
   573                                 }
       
   574 
       
   575                             if ( iSeekPos.Int64() > 0 )
       
   576                                 {
       
   577                                 iSeekEvent = ETrue;
       
   578                                 iLastKeyLeftOrRight = ETrue;
       
   579                                 // Process the command only when repeat count is zero.
       
   580                                 iKeyRepeatCount++;
       
   581 
       
   582 
       
   583                                 TInt adjustment = TimeIncrement( iKeyRepeatCount );
       
   584 
       
   585                                 TInt64 newPos = iSeekPos.Int64() - adjustment;
       
   586                                 if ( newPos < 0 )
       
   587                                     {
       
   588                                     newPos = 0;
       
   589                                     }
       
   590                                 iSeekPos = TTimeIntervalMicroSeconds( newPos );
       
   591 
       
   592                                 TTimeIntervalMicroSeconds endTime( 0 );
       
   593                                 iMovie.GetDurationEstimateL( iMaxMmsSize, newPos, endTime );
       
   594 
       
   595                                 iSeekEndPos = endTime;
       
   596 
       
   597                                 iCutterBar->SetInPoint( iSeekPos );
       
   598                                 iCutterBar->SetOutPoint( endTime );
       
   599                                 }
       
   600                             return EKeyWasConsumed;
       
   601                             }
       
   602                         //
       
   603                         // Default
       
   604                         //
       
   605                     default:
       
   606                             {
       
   607                             return EKeyWasNotConsumed;
       
   608                             }
       
   609                         }
       
   610                     }
       
   611                 //
       
   612                 // Key up event
       
   613                 //
       
   614 
       
   615             case EEventKeyUp:
       
   616                     {
       
   617                     iKeyRepeatCount = 0;
       
   618                     if ( iPreviewState == EPlaying )
       
   619                         {
       
   620                         iView.SetTrimStateL( CVeiTrimForMmsView::ESeek );
       
   621 
       
   622                         Stop( ETrue );
       
   623                         return EKeyWasConsumed;
       
   624                         }
       
   625                     else
       
   626                         {
       
   627                         if ( iLastKeyLeftOrRight )
       
   628                             {
       
   629                             iView.ProcessNeeded( ETrue );
       
   630                             iMovie.VideoClipSetCutInTime( 0, iSeekPos );
       
   631                             iMovie.VideoClipSetCutOutTime( 0, iSeekEndPos );
       
   632                             iView.UpdateNaviPaneL( iMovie.GetSizeEstimateL() / 1024, iMovie.Duration());
       
   633                             iLastKeyLeftOrRight = EFalse;
       
   634                             if ( iSeekEvent )
       
   635                                 {
       
   636                                 StartFrameTakerL( iClipIndex );
       
   637                                 iSeekEvent = EFalse;
       
   638                                 }
       
   639                             return EKeyWasConsumed;
       
   640                             }
       
   641                         }
       
   642                     break;
       
   643                     }
       
   644                 //
       
   645                 // Default
       
   646                 //
       
   647             default:
       
   648                 return EKeyWasNotConsumed;
       
   649             }
       
   650     } //iKeyEnable
       
   651     return EKeyWasNotConsumed;
       
   652     }
       
   653 
       
   654 
       
   655 TInt CVeiTrimForMmsContainer::TimeIncrement( TInt aKeyCount )const
       
   656     {
       
   657     if ( aKeyCount < 3 )
       
   658         {
       
   659         return 100000;
       
   660         }
       
   661     else if ( aKeyCount < 6 )
       
   662     // 4
       
   663         {
       
   664         return 300000;
       
   665         }
       
   666     else if ( aKeyCount < 9 )
       
   667     // 5
       
   668         {
       
   669         return 500000;
       
   670         }
       
   671     else if ( aKeyCount < 12 )
       
   672     // 10
       
   673         {
       
   674         return 1000000;
       
   675         }
       
   676     else if ( aKeyCount < 15 )
       
   677     // 13
       
   678         {
       
   679         return 2000000;
       
   680         }
       
   681     else if ( aKeyCount < 18 )
       
   682     // 15
       
   683         {
       
   684         return 3000000;
       
   685         }
       
   686     else
       
   687         {
       
   688         return 5000000;
       
   689         }
       
   690     }
       
   691 
       
   692 
       
   693 void CVeiTrimForMmsContainer::NotifyVideoDisplayEvent( const TPlayerEvent aEvent, const TInt& aInfo )
       
   694     {
       
   695     switch ( aEvent )
       
   696         {
       
   697         case MVeiVideoDisplayObserver::EOpenComplete: 
       
   698             {
       
   699             iVideoDisplay->SetRect( iPreviewRect );
       
   700             if ( !VideoEditorUtils::IsLandscapeScreenOrientation())
       
   701             //Portrait
       
   702                 {
       
   703                 iVideoDisplay->SetRotationL( EVideoRotationClockwise90 );
       
   704                 }
       
   705             iPreviewState = ELoading;
       
   706 
       
   707             iVideoDisplay->SetPositionL( CutInTime());
       
   708             iVideoDisplay->PlayL( iMovie.VideoClipInfo( iClipIndex )->FileName(), CutInTime(), CutOutTime());
       
   709 
       
   710             break;
       
   711             }
       
   712 
       
   713         case MVeiVideoDisplayObserver::ELoadingComplete: 
       
   714             {
       
   715 
       
   716             iVideoDisplay->MakeVisible( ETrue );
       
   717             iPreviewState = EPlaying;
       
   718             break;
       
   719             }
       
   720 
       
   721         case MVeiVideoDisplayObserver::EStop: 
       
   722             {
       
   723             iPreviewState = EIdle;
       
   724             iView.SetTrimStateL( CVeiTrimForMmsView::ESeek );
       
   725 
       
   726             iVideoDisplay->MakeVisible( EFalse );
       
   727 
       
   728             DrawDeferred();
       
   729             break;
       
   730             }
       
   731         case MVeiVideoDisplayObserver::EPlayComplete: 
       
   732             {
       
   733             iView.SetTrimStateL( CVeiTrimForMmsView::ESeek );
       
   734             Stop( ETrue );
       
   735             if ( KErrNoMemory == aInfo )
       
   736                 {
       
   737                 iView.ShowGlobalErrorNoteL( KErrNoMemory );
       
   738                 }
       
   739             break;
       
   740             }
       
   741         default:
       
   742                 {
       
   743                 break;
       
   744                 }
       
   745         }
       
   746     }
       
   747 
       
   748 
       
   749 /**
       
   750  * Called to notify that a new video clip has been successfully
       
   751  * added to the movie. Note that the indices and the start and end times
       
   752  * of the video clips after the new clip have also changed as a result.
       
   753  * Note that the transitions may also have changed. 
       
   754  *
       
   755  * @param aMovie  movie
       
   756  * @param aIndex  index of video clip in movie
       
   757  */
       
   758 void CVeiTrimForMmsContainer::NotifyVideoClipAdded( CVedMovie& aMovie, TInt aIndex )
       
   759     {
       
   760     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::NotifyVideoClipAdded: in" );
       
   761 
       
   762     iSeekPos = TTimeIntervalMicroSeconds( 0 );
       
   763 
       
   764     aMovie.GetDurationEstimateL( iMaxMmsSize, iSeekPos, iSeekEndPos );
       
   765     LOGFMT3( KVideoEditorLogFile, "CVeiTrimForMmsContainer::NotifyVideoClipAdded: 1, iMaxMmsSize:%d, iSeekPos:%Ld, iSeekEndPos:%Ld", iMaxMmsSize, iSeekPos.Int64(), iSeekEndPos.Int64());
       
   766 
       
   767     iCutterBar->SetInPoint( iSeekPos );
       
   768     iCutterBar->SetOutPoint( iSeekEndPos );
       
   769     iCutterBar->SetTotalDuration( aMovie.Duration());
       
   770     iDuration = aMovie.Duration();
       
   771 
       
   772     iClipIndex = aIndex;
       
   773 
       
   774     aMovie.VideoClipSetCutInTime( 0, iSeekPos );
       
   775     aMovie.VideoClipSetCutOutTime( 0, iSeekEndPos );
       
   776 
       
   777     TInt movieSizeLimit = static_cast < TInt > ( iMaxMmsSize* 0.9 );
       
   778     aMovie.SetMovieSizeLimit( movieSizeLimit );
       
   779 
       
   780     LOGFMT( KVideoEditorLogFile, "CVeiTrimForMmsContainer::NotifyVideoClipAdded(): 2, movie size set to:%d", movieSizeLimit );
       
   781 
       
   782     StartFrameTakerL( iClipIndex );
       
   783 
       
   784     iSeekEvent = EFalse;
       
   785 
       
   786 
       
   787     iView.UpdateNaviPaneL( iMovie.GetSizeEstimateL() / 1024, iMovie.Duration());
       
   788 
       
   789     iKeyEnable = ETrue;
       
   790 
       
   791     LOG( KVideoEditorLogFile, "CVeiTrimForMmsContainer::NotifyVideoClipAdded: out" );
       
   792     }
       
   793 
       
   794 
       
   795 void CVeiTrimForMmsContainer::NotifyVideoClipAddingFailed( CVedMovie& /*aMovie*/, TInt /*aError*/ ){}
       
   796 
       
   797 void CVeiTrimForMmsContainer::NotifyVideoClipRemoved( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   798 
       
   799 void CVeiTrimForMmsContainer::NotifyVideoClipIndicesChanged( CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, TInt /*aNewIndex*/ ){}
       
   800 
       
   801 void CVeiTrimForMmsContainer::NotifyVideoClipTimingsChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   802 
       
   803 void CVeiTrimForMmsContainer::NotifyVideoClipColorEffectChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   804 
       
   805 void CVeiTrimForMmsContainer::NotifyVideoClipAudioSettingsChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   806 
       
   807 void CVeiTrimForMmsContainer::NotifyVideoClipGeneratorSettingsChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   808 
       
   809 void CVeiTrimForMmsContainer::NotifyVideoClipDescriptiveNameChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   810 
       
   811 void CVeiTrimForMmsContainer::NotifyStartTransitionEffectChanged( CVedMovie& /*aMovie*/ ){}
       
   812 
       
   813 
       
   814 void CVeiTrimForMmsContainer::NotifyMiddleTransitionEffectChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   815 
       
   816 void CVeiTrimForMmsContainer::NotifyEndTransitionEffectChanged( CVedMovie& /*aMovie*/ ){}
       
   817 
       
   818 void CVeiTrimForMmsContainer::NotifyAudioClipAdded( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   819 
       
   820 void CVeiTrimForMmsContainer::NotifyAudioClipAddingFailed( CVedMovie& /*aMovie*/, TInt /*aError*/ ){}
       
   821 
       
   822 void CVeiTrimForMmsContainer::NotifyAudioClipRemoved( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   823 
       
   824 void CVeiTrimForMmsContainer::NotifyAudioClipIndicesChanged( CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, TInt /*aNewIndex*/ ){}
       
   825 
       
   826 void CVeiTrimForMmsContainer::NotifyAudioClipTimingsChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ ){}
       
   827 
       
   828 void CVeiTrimForMmsContainer::NotifyMovieQualityChanged( CVedMovie& /*aMovie*/
       
   829  ){}
       
   830 
       
   831 
       
   832 void CVeiTrimForMmsContainer::NotifyMovieReseted( CVedMovie& /*aMovie*/ ){}
       
   833 
       
   834 void CVeiTrimForMmsContainer::NotifyMovieOutputParametersChanged( CVedMovie& /*aMovie*/ ){}
       
   835 
       
   836 void CVeiTrimForMmsContainer::NotifyAudioClipDynamicLevelMarkInserted( CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/ ){}
       
   837 
       
   838 void CVeiTrimForMmsContainer::NotifyAudioClipDynamicLevelMarkRemoved( CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/ ){}
       
   839 
       
   840 void CVeiTrimForMmsContainer::NotifyVideoClipDynamicLevelMarkInserted( CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/ ){}
       
   841 
       
   842 void CVeiTrimForMmsContainer::NotifyVideoClipDynamicLevelMarkRemoved( CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/ ){}
       
   843 
       
   844 void CVeiTrimForMmsContainer::PlayL( const TDesC& aFilename, const TRect& aRect )
       
   845     {
       
   846     iCutterBar->MakeVisible( EFalse );
       
   847     iVideoDisplayStart->MakeVisible( EFalse );
       
   848     iVideoDisplayEnd->MakeVisible( EFalse );
       
   849     iVideoDisplay->MakeVisible( EFalse );
       
   850 
       
   851     iVideoDisplay->ShowBlackScreen();
       
   852 
       
   853     iPreviewRect = aRect;
       
   854     iBlack = ETrue;
       
   855     if ( !iScreenLight->IsActive())
       
   856         {
       
   857         iScreenLight->Start();
       
   858         }
       
   859 
       
   860 
       
   861     iPreviewState = EOpeningFile;
       
   862     iVideoDisplay->OpenFileL( aFilename );
       
   863     }
       
   864 
       
   865 void CVeiTrimForMmsContainer::Stop( TBool aCloseStream )
       
   866     {
       
   867     iCutterBar->MakeVisible( ETrue );
       
   868     iVideoDisplayStart->MakeVisible( ETrue );
       
   869     iVideoDisplayEnd->MakeVisible( ETrue );
       
   870     iBlack = EFalse;
       
   871     iScreenLight->Stop();
       
   872     iVideoDisplay->Stop( aCloseStream );
       
   873     DrawNow();
       
   874     }
       
   875 
       
   876 void CVeiTrimForMmsContainer::PauseL()
       
   877     {
       
   878     iPreviewState = EPause;
       
   879     iVideoDisplay->PauseL();
       
   880     iVideoDisplay->MakeVisible( EFalse );
       
   881     DrawNow();
       
   882     }
       
   883 
       
   884 TInt CVeiTrimForMmsContainer::PreviewState()const
       
   885     {
       
   886     return iPreviewState;
       
   887     }
       
   888 
       
   889 void CVeiTrimForMmsContainer::NotifyFramesCompleted( CFbsBitmap* aFirstFrame, 
       
   890                                                      CFbsBitmap* aLastFrame, 
       
   891                                                      CFbsBitmap*  /*aTimelineFrame*/, 
       
   892                                                      TInt aError )
       
   893     {
       
   894     if ( aError == KErrNone )
       
   895         {
       
   896         iVideoDisplayStart->ShowPictureL( *aFirstFrame );
       
   897         iVideoDisplayEnd->ShowPictureL( *aLastFrame );
       
   898         }
       
   899 
       
   900     if ( iProgressNote )
       
   901         {
       
   902         iProgressInfo->SetAndDraw( 100 );
       
   903         iProgressNote->ProcessFinishedL();
       
   904         }
       
   905     }
       
   906 
       
   907 void CVeiTrimForMmsContainer::StartFrameTakerL( TInt aIndex )
       
   908     {
       
   909     iProgressNote = new( ELeave )CAknProgressDialog( REINTERPRET_CAST( CEikDialog** , &iProgressNote ), ETrue );
       
   910     iProgressNote->SetCallback( this );
       
   911     iProgressNote->ExecuteDlgLD( R_VEI_PROGRESS_NOTE );
       
   912 
       
   913     HBufC* stringholder;
       
   914     stringholder = StringLoader::LoadL( R_VEI_PROGRESS_NOTE_PROCESSING, iEikonEnv );
       
   915     CleanupStack::PushL( stringholder );
       
   916     iProgressNote->SetTextL( *stringholder );
       
   917     CleanupStack::PopAndDestroy( stringholder );
       
   918 
       
   919     iProgressInfo = iProgressNote->GetProgressInfoL();
       
   920     iProgressInfo->SetFinalValue( 100 );
       
   921     iProgressInfo->SetAndDraw( 50 );
       
   922 
       
   923     // First frame is shown in main display so it is bigger.. Last frame is always
       
   924     // on transition display and one frame for the video timeline.
       
   925     TSize firstThumbResolution = iVideoDisplayStart->GetScreenSize();
       
   926     TSize lastThumbResolution = iVideoDisplayEnd->GetScreenSize();
       
   927     TSize timelineThumbResolution = TSize( 34, 28 );
       
   928 
       
   929     TInt frameCount = iMovie.VideoClipInfo( aIndex )->VideoFrameCount();
       
   930 
       
   931     TInt firstThumbNailIndex = iMovie.VideoClipInfo( aIndex )->GetVideoFrameIndexL( CutInTime());
       
   932     TInt lastThumbNailIndex = iMovie.VideoClipInfo( aIndex )->GetVideoFrameIndexL( CutOutTime());
       
   933     if ( lastThumbNailIndex >= frameCount )
       
   934         {
       
   935         lastThumbNailIndex = frameCount - 1;
       
   936         }
       
   937 
       
   938 
       
   939     iFrameTaker->GetFramesL( *iMovie.VideoClipInfo( aIndex ), 
       
   940                              firstThumbNailIndex, 
       
   941                              &firstThumbResolution, 
       
   942                              lastThumbNailIndex, 
       
   943                              &lastThumbResolution, 
       
   944                              firstThumbNailIndex, 
       
   945                              &timelineThumbResolution, 
       
   946                              EPriorityLow );
       
   947     }
       
   948 
       
   949 TTypeUid::Ptr CVeiTrimForMmsContainer::MopSupplyObject( TTypeUid aId )
       
   950     {
       
   951     if ( aId.iUid == MAknsControlContext::ETypeId && iBgContext )
       
   952         {
       
   953         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   954         }
       
   955     return CCoeControl::MopSupplyObject( aId );
       
   956     }
       
   957 
       
   958 // End of File