videocollection/hgmyvideos/src/vcxhgmyvideosvideocopier.cpp
changeset 0 96612d01cf9f
child 11 5294c000a26d
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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:      Class for handling move/copy related notes and operations.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <CAknMemorySelectionDialogMultiDrive.h>
       
    22 #include <AknWaitDialog.h>
       
    23 #include <AknCommonDialogsDynMem.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <StringLoader.h>
       
    26 #include <vcxmyvideosdefs.h>
       
    27 #include <vcxhgmyvideos.rsg>
       
    28 #include "IptvDebug.h"
       
    29 #include "vcxhgmyvideoscollectionclient.h"
       
    30 #include "vcxhgmyvideosvideomodelhandler.h"
       
    31 #include "vcxhgmyvideosmodel.h"
       
    32 #include "vcxhgmyvideosvideocopier.h"
       
    33 #include "CIptvDriveMonitor.h"
       
    34 
       
    35 // =========================== MEMBER FUNCTIONS ==============================
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CVcxHgMyVideosVideoCopier::CVcxHgMyVideosVideoCopier()
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CVcxHgMyVideosVideoCopier::CVcxHgMyVideosVideoCopier(
       
    42         CVcxHgMyVideosVideoListImpl& aVideoList,
       
    43         CVcxHgMyVideosVideoModelHandler& aVideoModel,
       
    44         CVcxHgMyVideosModel& aModel )
       
    45  :  iVideoList( aVideoList ),
       
    46     iVideoModel( aVideoModel ),
       
    47     iModel( aModel )
       
    48     {
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CVcxHgMyVideosVideoCopier::ConstructL()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CVcxHgMyVideosVideoCopier::ConstructL()
       
    56     {
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CVcxHgMyVideosVideoCopier::NewL()
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CVcxHgMyVideosVideoCopier* CVcxHgMyVideosVideoCopier::NewL( 
       
    64         CVcxHgMyVideosVideoListImpl& aVideoList,
       
    65         CVcxHgMyVideosVideoModelHandler& aVideoModel,
       
    66         CVcxHgMyVideosModel& aModel )
       
    67     {
       
    68     CVcxHgMyVideosVideoCopier* self = 
       
    69         new( ELeave ) CVcxHgMyVideosVideoCopier( aVideoList, aVideoModel, aModel );
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CVcxHgMyVideosVideoCopier::~CVcxHgMyVideosVideoCopier()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CVcxHgMyVideosVideoCopier::~CVcxHgMyVideosVideoCopier()
       
    81     {
       
    82     CloseMoveCopyWaitNote();
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CVcxHgMyVideosVideoCopier::ShowMenuItemsL()
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CVcxHgMyVideosVideoCopier::ShowMenuItemsL( 
       
    90         const RArray<TInt>& aOperationTargets,
       
    91         TBool& aShowMoveAndCopySubmenu,
       
    92         TBool& aShowCopy,
       
    93         TBool& aShowMove )
       
    94     {
       
    95     TVcxMyVideosDownloadState dlState( EVcxMyVideosDlStateNone );
       
    96     CIptvDriveMonitor& driveMonitor = iModel.DriveMonitorL();
       
    97     HBufC* videoUri = NULL;
       
    98     TInt drive( 0 );
       
    99 
       
   100     TUint32 flags;
       
   101 
       
   102     for ( TInt i = 0; i < aOperationTargets.Count(); i++ )
       
   103         {
       
   104         dlState = iVideoModel.VideoDownloadState( aOperationTargets[i] );
       
   105 
       
   106         // If video is not under download, there is source file that can be moved/copied.
       
   107         if ( dlState == EVcxMyVideosDlStateNone )
       
   108             {
       
   109             // When we found source file that can be moved/copied, we need
       
   110             // to also check that there is target drive that we can use.
       
   111             videoUri = iVideoModel.GetVideoUri( aOperationTargets[i] ).AllocLC();
       
   112             if ( videoUri->Length() > 0 )
       
   113                 {
       
   114                 if ( iModel.FileServerSessionL().CharToDrive( videoUri->Des()[0], drive )
       
   115                       == KErrNone )
       
   116                     {
       
   117                     for ( TInt j = 0; j < driveMonitor.iAvailableDrives.Count(); j++ )
       
   118                         {
       
   119                         flags = driveMonitor.iAvailableDrives[j].iFlags;
       
   120     
       
   121                         if ( driveMonitor.iAvailableDrives[j].iDrive != drive &&
       
   122                                 !(flags & TIptvDriveInfo::ELocked) && !(flags & TIptvDriveInfo::EMediaNotPresent) )
       
   123                             {
       
   124                             aShowMoveAndCopySubmenu = aShowCopy = aShowMove = ETrue;
       
   125 
       
   126                             // No need to continue, we know that menu can be shown.
       
   127                             CleanupStack::PopAndDestroy( videoUri );
       
   128                             return;
       
   129                             }
       
   130                         }
       
   131                     }
       
   132                 }
       
   133             CleanupStack::PopAndDestroy( videoUri );
       
   134             }
       
   135         }
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CVcxHgMyVideosVideoCopier::MoveOrCopyL()
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CVcxHgMyVideosVideoCopier::MoveOrCopyL( 
       
   143         const RArray<TInt>& aOperationTargets,
       
   144         TBool aCopy )
       
   145     {
       
   146     TInt targetDrive( EDriveC );
       
   147 
       
   148     if ( QueryTargetDriveL( aCopy, targetDrive ) )
       
   149         {
       
   150         // Wait note is closed in destructor (CloseMoveCopyWaitNote()), 
       
   151         // in DialogDismissedL() or in VideoMoveOrCopyCompletedL().
       
   152         OpenMoveCopyWaitNoteL( aOperationTargets, aCopy );
       
   153 
       
   154         iVideoModel.MoveOrCopyVideosL( aOperationTargets, targetDrive, aCopy );
       
   155         iCopy = aCopy;
       
   156         }
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CVcxHgMyVideosVideoCopier::QueryTargetDriveL()
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TBool CVcxHgMyVideosVideoCopier::QueryTargetDriveL( TBool aCopy, TInt& aTargetDrive )
       
   164     {
       
   165     TCommonDialogType dialogType;
       
   166     TBool driveSelected( EFalse );
       
   167     TDriveNumber selectedMem( EDriveC );
       
   168     TInt includedMedias( 0 );
       
   169 
       
   170     if ( aCopy )
       
   171         {
       
   172         dialogType = ECFDDialogTypeCopy;
       
   173         }
       
   174     else
       
   175         {
       
   176         dialogType = ECFDDialogTypeMove;
       
   177         }
       
   178     
       
   179     if ( iModel.DriveMonitorL().MassStorageDrive() != KErrNotFound )
       
   180         {
       
   181         includedMedias |= AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage;
       
   182         }
       
   183     if ( iModel.DriveMonitorL().MemoryCardDrive() != KErrNotFound )
       
   184         {
       
   185         includedMedias |= AknCommonDialogsDynMem::EMemoryTypeMMCExternal;
       
   186         }
       
   187     if ( iModel.DriveMonitorL().FixedDrive( EFalse ) == EDriveC )
       
   188         {
       
   189         includedMedias |= AknCommonDialogsDynMem::EMemoryTypePhone;
       
   190         }
       
   191     // If CIptvDriveMonitor does not publish C-drive, it means that product
       
   192     // has (at least) two other usable memories, and therefore there is no
       
   193     // need to allow user to move / copy items to (small) C-drive. 
       
   194     if ( iModel.DriveMonitorL().PhoneMemoryDrive() == KErrNotFound )
       
   195         {
       
   196         includedMedias &= ~AknCommonDialogsDynMem::EMemoryTypePhone;
       
   197         }
       
   198 
       
   199 // Skip the dialog in emulator as ASSERT_DEBUG macro does not allow single memory dialog.
       
   200 #if !defined(__WINS__) && !defined(__WINSCW__)
       
   201     CAknMemorySelectionDialogMultiDrive* dlg =
       
   202         CAknMemorySelectionDialogMultiDrive::NewL(
       
   203             dialogType,
       
   204             R_VCXHGMYVIDEOS_MEMORY_SELECTION_DIALOG,
       
   205             EFalse,
       
   206             includedMedias );
       
   207     CleanupStack::PushL( dlg );
       
   208     driveSelected = dlg->ExecuteL( selectedMem );
       
   209     CleanupStack::PopAndDestroy(); // dlg
       
   210 #else
       
   211     driveSelected = ETrue;
       
   212     selectedMem = EDriveE;
       
   213 #endif // !defined(__WINS__) && !defined(__WINSCW__)
       
   214 
       
   215     if ( driveSelected )
       
   216         {
       
   217         aTargetDrive = static_cast<TInt>( selectedMem );
       
   218         return ETrue;
       
   219         }
       
   220 
       
   221     return EFalse;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CVcxHgMyVideosVideoCopier::OpenMoveCopyWaitNoteL()
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CVcxHgMyVideosVideoCopier::OpenMoveCopyWaitNoteL( 
       
   229     const RArray<TInt>& aOperationTargets,
       
   230     TBool aCopy )
       
   231     {
       
   232     CloseMoveCopyWaitNote();
       
   233 
       
   234     HBufC* note = NULL;
       
   235 
       
   236     if ( aOperationTargets.Count() == 1 )
       
   237         {
       
   238         HBufC* name = iVideoModel.GetVideoName( aOperationTargets[0] ).AllocLC();
       
   239         if ( aCopy )
       
   240             {
       
   241             note = StringLoader::LoadL( R_VCXHGMYVIDEOS_COPYING_ONE, *name );
       
   242             }
       
   243         else
       
   244             {
       
   245             note = StringLoader::LoadL( R_VCXHGMYVIDEOS_MOVING_ONE, *name );
       
   246             }
       
   247         CleanupStack::PopAndDestroy( name );
       
   248         CleanupStack::PushL( note );
       
   249         }
       
   250     else
       
   251         {
       
   252         if ( aCopy )
       
   253             {
       
   254             note = StringLoader::LoadLC( R_VCXHGMYVIDEOS_COPYING_MANY );
       
   255             }
       
   256         else
       
   257             {
       
   258             note = StringLoader::LoadLC( R_VCXHGMYVIDEOS_MOVING_MANY );
       
   259             }
       
   260         }
       
   261 
       
   262     iMoveCopyWaitDialog = new (ELeave) 
       
   263             CAknWaitDialog( ( REINTERPRET_CAST( CEikDialog**, &iMoveCopyWaitDialog ) ), ETrue );
       
   264     iMoveCopyWaitDialog->SetCallback( this );
       
   265     iMoveCopyWaitDialog->SetTextL( *note );
       
   266     
       
   267     if ( aCopy )
       
   268         {
       
   269         iMoveCopyWaitDialog->ExecuteLD( R_VCXHGMYVIDEOS_COPY_WAIT_NOTE );
       
   270         }
       
   271     else
       
   272         {
       
   273         iMoveCopyWaitDialog->ExecuteLD( R_VCXHGMYVIDEOS_MOVE_WAIT_NOTE );
       
   274         }
       
   275 
       
   276     CleanupStack::PopAndDestroy( note );
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CVcxHgMyVideosVideoCopier::CloseMoveCopyWaitNote()
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CVcxHgMyVideosVideoCopier::CloseMoveCopyWaitNote()
       
   284     {
       
   285     if ( iMoveCopyWaitDialog )
       
   286         {
       
   287         TRAPD( error, iMoveCopyWaitDialog->ProcessFinishedL() );
       
   288         if ( error != KErrNone )
       
   289             {
       
   290             delete iMoveCopyWaitDialog;
       
   291             }
       
   292         iMoveCopyWaitDialog = NULL;
       
   293         }
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CVcxHgMyVideosVideoCopier::DialogDismissedL()
       
   298 // Callback about (move/copy) wait note dismissal.
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void CVcxHgMyVideosVideoCopier::DialogDismissedL( TInt aButtonId )
       
   302     {
       
   303     if ( aButtonId == EAknSoftkeyCancel )
       
   304         {
       
   305         iModel.CollectionClient().CancelMoveOrCopyVideosL();
       
   306         }
       
   307     iMoveCopyWaitDialog = NULL;
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CVcxHgMyVideosVideoCopier::VideoMoveOrCopyCompletedL()
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CVcxHgMyVideosVideoCopier::VideoMoveOrCopyCompletedL( TInt aFailedCount,
       
   315                                                            const TDesC& aFailedName )
       
   316     {
       
   317     CloseMoveCopyWaitNote();
       
   318 
       
   319     if ( aFailedCount > 0 )
       
   320         {
       
   321         HBufC* text = NULL;
       
   322 
       
   323         if ( aFailedCount == 1 )
       
   324             {
       
   325             if ( iCopy )
       
   326                 {
       
   327                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_ITEM_CANNOT_BE_COPIED,
       
   328                                              aFailedName );
       
   329                 }
       
   330             else
       
   331                 {
       
   332                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_ITEM_CANNOT_BE_MOVED,
       
   333                                              aFailedName );                
       
   334                 }
       
   335             }
       
   336         else
       
   337             {
       
   338             if ( iCopy )
       
   339                 {
       
   340                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_SOME_ITEMS_CANT_COPY, 
       
   341                                              aFailedCount );
       
   342                 }
       
   343             else
       
   344                 {
       
   345                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_SOME_ITEMS_CANT_MOVE, 
       
   346                                              aFailedCount );                
       
   347                 }            
       
   348             }
       
   349 
       
   350         CAknErrorNote* note = new ( ELeave ) CAknErrorNote( ETrue );
       
   351         note->ExecuteLD( *text );
       
   352         CleanupStack::PopAndDestroy( text );  
       
   353         }    
       
   354     }