videocollection/hgmyvideos/src/vcxhgmyvideosvideocopier.cpp
branchRCL_3
changeset 57 befca0ec475f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     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     CIptvDriveMonitor& driveMonitor = iModel.DriveMonitorL();
       
    96     HBufC* videoUri = NULL;
       
    97     TInt drive( 0 );
       
    98 
       
    99     TUint32 flags;
       
   100 
       
   101     for ( TInt i = 0; i < aOperationTargets.Count(); i++ )
       
   102         {
       
   103         // When we found source file that can be moved/copied, we need
       
   104         // to also check that there is target drive that we can use.
       
   105         videoUri = iVideoModel.GetVideoUri( aOperationTargets[i] ).AllocLC();
       
   106         if ( videoUri->Length() > 0 )
       
   107             {
       
   108             if ( iModel.FileServerSessionL().CharToDrive( videoUri->Des()[0], drive )
       
   109                   == KErrNone )
       
   110                 {
       
   111                 for ( TInt j = 0; j < driveMonitor.iAvailableDrives.Count(); j++ )
       
   112                     {
       
   113                     flags = driveMonitor.iAvailableDrives[j].iFlags;
       
   114 
       
   115                     if ( driveMonitor.iAvailableDrives[j].iDrive != drive &&
       
   116                             !(flags & TIptvDriveInfo::ELocked) && !(flags & TIptvDriveInfo::EMediaNotPresent) )
       
   117                         {
       
   118                         aShowMoveAndCopySubmenu = aShowCopy = aShowMove = ETrue;
       
   119 
       
   120                         // No need to continue, we know that menu can be shown.
       
   121                         CleanupStack::PopAndDestroy( videoUri );
       
   122                         return;
       
   123                         }
       
   124                     }
       
   125                 }
       
   126             }
       
   127         CleanupStack::PopAndDestroy( videoUri );
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CVcxHgMyVideosVideoCopier::MoveOrCopyL()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CVcxHgMyVideosVideoCopier::MoveOrCopyL( 
       
   136         const RArray<TInt>& aOperationTargets,
       
   137         TBool aCopy )
       
   138     {
       
   139     TInt targetDrive( EDriveC );
       
   140 
       
   141     if ( QueryTargetDriveL( aCopy, targetDrive ) )
       
   142         {
       
   143         // Wait note is closed in destructor (CloseMoveCopyWaitNote()), 
       
   144         // in DialogDismissedL() or in VideoMoveOrCopyCompletedL().
       
   145         OpenMoveCopyWaitNoteL( aOperationTargets, aCopy );
       
   146 
       
   147         TRAPD( ret, iVideoModel.MoveOrCopyVideosL( aOperationTargets, targetDrive, aCopy ));
       
   148         
       
   149         if( ret != KErrNone )
       
   150             {
       
   151             CloseMoveCopyWaitNote();
       
   152             }
       
   153         
       
   154         iCopy = aCopy;
       
   155         }
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CVcxHgMyVideosVideoCopier::QueryTargetDriveL()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TBool CVcxHgMyVideosVideoCopier::QueryTargetDriveL( TBool aCopy, TInt& aTargetDrive )
       
   163     {
       
   164     TCommonDialogType dialogType;
       
   165     TBool driveSelected( EFalse );
       
   166     TDriveNumber selectedMem( EDriveC );
       
   167     TInt includedMedias( 0 );
       
   168 
       
   169     if ( aCopy )
       
   170         {
       
   171         dialogType = ECFDDialogTypeCopy;
       
   172         }
       
   173     else
       
   174         {
       
   175         dialogType = ECFDDialogTypeMove;
       
   176         }
       
   177     
       
   178     if ( iModel.DriveMonitorL().MassStorageDrive() != KErrNotFound )
       
   179         {
       
   180         includedMedias |= AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage;
       
   181         }
       
   182     if ( iModel.DriveMonitorL().MemoryCardDrive() != KErrNotFound )
       
   183         {
       
   184         includedMedias |= AknCommonDialogsDynMem::EMemoryTypeMMCExternalInDevice;
       
   185         }
       
   186     if ( iModel.DriveMonitorL().FixedDrive( EFalse ) == EDriveC )
       
   187         {
       
   188         includedMedias |= AknCommonDialogsDynMem::EMemoryTypePhone;
       
   189         }
       
   190     // If CIptvDriveMonitor does not publish C-drive, it means that product
       
   191     // has (at least) two other usable memories, and therefore there is no
       
   192     // need to allow user to move / copy items to (small) C-drive. 
       
   193     if ( iModel.DriveMonitorL().PhoneMemoryDrive() == KErrNotFound )
       
   194         {
       
   195         includedMedias &= ~AknCommonDialogsDynMem::EMemoryTypePhone;
       
   196         }
       
   197 
       
   198 // Skip the dialog in emulator as ASSERT_DEBUG macro does not allow single memory dialog.
       
   199 #if !defined(__WINS__) && !defined(__WINSCW__)
       
   200     CAknMemorySelectionDialogMultiDrive* dlg =
       
   201         CAknMemorySelectionDialogMultiDrive::NewL(
       
   202             dialogType,
       
   203             R_VCXHGMYVIDEOS_MEMORY_SELECTION_DIALOG,
       
   204             EFalse,
       
   205             includedMedias );
       
   206     CleanupStack::PushL( dlg );
       
   207     driveSelected = dlg->ExecuteL( selectedMem );
       
   208     CleanupStack::PopAndDestroy(); // dlg
       
   209 #else
       
   210     driveSelected = ETrue;
       
   211     selectedMem = EDriveE;
       
   212 #endif // !defined(__WINS__) && !defined(__WINSCW__)
       
   213 
       
   214     if ( driveSelected )
       
   215         {
       
   216         aTargetDrive = static_cast<TInt>( selectedMem );
       
   217         return ETrue;
       
   218         }
       
   219 
       
   220     return EFalse;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CVcxHgMyVideosVideoCopier::OpenMoveCopyWaitNoteL()
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CVcxHgMyVideosVideoCopier::OpenMoveCopyWaitNoteL( 
       
   228     const RArray<TInt>& aOperationTargets,
       
   229     TBool aCopy )
       
   230     {
       
   231     CloseMoveCopyWaitNote();
       
   232 
       
   233     HBufC* note = NULL;
       
   234 
       
   235     if ( aOperationTargets.Count() == 1 )
       
   236         {
       
   237         HBufC* name = iVideoModel.GetVideoName( aOperationTargets[0] ).AllocLC();
       
   238         if ( aCopy )
       
   239             {
       
   240             note = StringLoader::LoadL( R_VCXHGMYVIDEOS_COPYING_ONE, *name );
       
   241             }
       
   242         else
       
   243             {
       
   244             note = StringLoader::LoadL( R_VCXHGMYVIDEOS_MOVING_ONE, *name );
       
   245             }
       
   246         CleanupStack::PopAndDestroy( name );
       
   247         CleanupStack::PushL( note );
       
   248         }
       
   249     else
       
   250         {
       
   251         if ( aCopy )
       
   252             {
       
   253             note = StringLoader::LoadLC( R_VCXHGMYVIDEOS_COPYING_MANY );
       
   254             }
       
   255         else
       
   256             {
       
   257             note = StringLoader::LoadLC( R_VCXHGMYVIDEOS_MOVING_MANY );
       
   258             }
       
   259         }
       
   260 
       
   261     iMoveCopyWaitDialog = new (ELeave) 
       
   262             CAknWaitDialog( ( REINTERPRET_CAST( CEikDialog**, &iMoveCopyWaitDialog ) ), ETrue );
       
   263     iMoveCopyWaitDialog->SetCallback( this );
       
   264     iMoveCopyWaitDialog->SetTextL( *note );
       
   265     
       
   266     if ( aCopy )
       
   267         {
       
   268         iMoveCopyWaitDialog->ExecuteLD( R_VCXHGMYVIDEOS_COPY_WAIT_NOTE );
       
   269         }
       
   270     else
       
   271         {
       
   272         iMoveCopyWaitDialog->ExecuteLD( R_VCXHGMYVIDEOS_MOVE_WAIT_NOTE );
       
   273         }
       
   274 
       
   275     CleanupStack::PopAndDestroy( note );
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CVcxHgMyVideosVideoCopier::CloseMoveCopyWaitNote()
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CVcxHgMyVideosVideoCopier::CloseMoveCopyWaitNote()
       
   283     {
       
   284     if ( iMoveCopyWaitDialog )
       
   285         {
       
   286         TRAPD( error, iMoveCopyWaitDialog->ProcessFinishedL() );
       
   287         if ( error != KErrNone )
       
   288             {
       
   289             delete iMoveCopyWaitDialog;
       
   290             }
       
   291         iMoveCopyWaitDialog = NULL;
       
   292         }
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CVcxHgMyVideosVideoCopier::DialogDismissedL()
       
   297 // Callback about (move/copy) wait note dismissal.
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CVcxHgMyVideosVideoCopier::DialogDismissedL( TInt aButtonId )
       
   301     {
       
   302     if ( aButtonId == EAknSoftkeyCancel )
       
   303         {
       
   304         iModel.CollectionClient().CancelMoveOrCopyVideosL();
       
   305         }
       
   306     iMoveCopyWaitDialog = NULL;
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CVcxHgMyVideosVideoCopier::VideoMoveOrCopyCompletedL()
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CVcxHgMyVideosVideoCopier::VideoMoveOrCopyCompletedL( TInt aFailedCount,
       
   314                                                            const TDesC& aFailedName )
       
   315     {
       
   316     CloseMoveCopyWaitNote();
       
   317 
       
   318     if ( aFailedCount > 0 )
       
   319         {
       
   320         HBufC* text = NULL;
       
   321 
       
   322         if ( aFailedCount == 1 )
       
   323             {
       
   324             if ( iCopy )
       
   325                 {
       
   326                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_ITEM_CANNOT_BE_COPIED,
       
   327                                              aFailedName );
       
   328                 }
       
   329             else
       
   330                 {
       
   331                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_ITEM_CANNOT_BE_MOVED,
       
   332                                              aFailedName );                
       
   333                 }
       
   334             }
       
   335         else
       
   336             {
       
   337             if ( iCopy )
       
   338                 {
       
   339                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_SOME_ITEMS_CANT_COPY, 
       
   340                                              aFailedCount );
       
   341                 }
       
   342             else
       
   343                 {
       
   344                 text = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FLDR_SOME_ITEMS_CANT_MOVE, 
       
   345                                              aFailedCount );                
       
   346                 }            
       
   347             }
       
   348 
       
   349         CAknErrorNote* note = new ( ELeave ) CAknErrorNote( ETrue );
       
   350         note->ExecuteLD( *text );
       
   351         CleanupStack::PopAndDestroy( text );  
       
   352         }    
       
   353     }