mpxplugins/viewplugins/views/addtracksdialog/src/mpxaddtrackslistmodel.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2006 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 "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:  A list model for add tracks dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bamdesca.h>
       
    21 #include <badesca.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 #include <mpxlog.h>
       
    25 #include <mpxmedia.h>
       
    26 #include <mpxmediaarray.h>
       
    27 #include <mpxmediageneraldefs.h>
       
    28 #include <mpxcommonuihelper.h>
       
    29 
       
    30 #include "mpxaddtracksdialog.hrh"
       
    31 #include "mpxaddtrackslistmodel.h"
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMPXAddTracksListModel::NewL
       
    39 // Two-phased constructor.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMPXAddTracksListModel* CMPXAddTracksListModel::NewL()
       
    43     {
       
    44     MPX_FUNC( "CMPXAddTracksListModel::NewL" );
       
    45     CMPXAddTracksListModel* self =
       
    46         new (ELeave) CMPXAddTracksListModel();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop();
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMPXAddTracksListModel::CMPXAddTracksListModel
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMPXAddTracksListModel::CMPXAddTracksListModel()
       
    60     :iCurrentHighlightIndex(0),
       
    61     iFindSongs( EFalse )
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMPXAddTracksListModel::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CMPXAddTracksListModel::ConstructL()
       
    71     {
       
    72     MPX_FUNC( "CMPXAddTracksListModel::ConstructL" );
       
    73     iTracksList = CMPXMediaArray::NewL();
       
    74     iMMCDrive = CMPXCommonUiHelper::MMCDriveNumber();
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Destructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CMPXAddTracksListModel::~CMPXAddTracksListModel()
       
    82     {
       
    83     MPX_DEBUG1( "CMPXAddTracksListModel::~CMPXAddTracksListModel START" );
       
    84     if ( iTracksList )
       
    85         {
       
    86         iTracksList->Reset();
       
    87         delete iTracksList;
       
    88         }
       
    89     iExpandedIndices.Reset();
       
    90     iExpandedIndices.Close();
       
    91     MPX_DEBUG1( "CMPXAddTracksListModel::~CMPXAddTracksListModel END" );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMPXAddTracksListModel::ResetTracksList
       
    96 // Reset tracks list.
       
    97 // (other items were commented in a header).
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMPXAddTracksListModel::ResetTracksList()
       
   101     {
       
   102     MPX_FUNC( "CMPXAddTracksListModel::ResetTracksList" );
       
   103     iTracksList->Reset();
       
   104     iExpandedIndices.Reset();
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CMPXAddTracksListModel::TrackName
       
   109 // Return track name.
       
   110 // (other items were commented in a header).
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 const TDesC& CMPXAddTracksListModel::TrackName( TInt aIndex ) const
       
   114     {
       
   115     //MPX_FUNC( "CMPXAddTracksListModel::TrackName" );
       
   116     CMPXMedia* item( NULL );
       
   117     TInt count( iTracksList->Count() );
       
   118     if ( count > 0 && aIndex < count )
       
   119         {
       
   120         TRAP_IGNORE( item = iTracksList->AtL( aIndex ) );
       
   121         }
       
   122     return item ? item->ValueText( KMPXMediaGeneralTitle ) : KNullDesC;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMPXAddTracksListModel::TrackTypeL
       
   127 // Return track type.
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CMPXAddTracksListModel::TrackTypeL( TInt aIndex ) const
       
   132     {
       
   133     //MPX_FUNC( "CMPXAddTracksListModel::TrackTypeL" );
       
   134     CMPXMedia* item( NULL );
       
   135     TInt count( iTracksList->Count() );
       
   136     if ( count > 0 && aIndex < count )
       
   137         {
       
   138         item = iTracksList->AtL( aIndex );
       
   139         User::LeaveIfNull( item );
       
   140         }
       
   141     else
       
   142         {
       
   143         User::Leave( KErrArgument );
       
   144         }
       
   145     return *item->Value<TMPXGeneralType>( KMPXMediaGeneralType );
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CMPXAddTracksListModel::TrackCategoryL
       
   150 // Return track Category.
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CMPXAddTracksListModel::TrackCategoryL( TInt aIndex ) const
       
   155     {
       
   156     //MPX_FUNC( "CMPXAddTracksListModel::TrackCategoryL" );
       
   157     CMPXMedia* item( NULL );
       
   158     TInt count( iTracksList->Count() );
       
   159     if ( count > 0 && aIndex < count )
       
   160         {
       
   161         item = iTracksList->AtL( aIndex );
       
   162         User::LeaveIfNull( item );
       
   163         }
       
   164     else
       
   165         {
       
   166         User::Leave( KErrArgument );
       
   167         }
       
   168     return *item->Value<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMPXAddTracksListModel::TrackIdL
       
   173 // Return track id.
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TMPXItemId CMPXAddTracksListModel::TrackIdL( TInt aIndex ) const
       
   178     {
       
   179     //MPX_FUNC( "CMPXAddTracksListModel::TrackIdL" );
       
   180     CMPXMedia* item( NULL );
       
   181     TInt count( iTracksList->Count() );
       
   182     if ( count > 0 && aIndex < count )
       
   183         {
       
   184         item = iTracksList->AtL( aIndex );
       
   185         User::LeaveIfNull( item );
       
   186         }
       
   187     else
       
   188         {
       
   189         User::Leave( KErrArgument );
       
   190         }
       
   191     return *item->Value<TMPXItemId>( KMPXMediaGeneralId );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CMPXAddTracksListModel::MediaL
       
   196 // Return track media.
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 const CMPXMedia& CMPXAddTracksListModel::MediaL( TInt aIndex ) const
       
   201     {
       
   202     //MPX_FUNC( "CMPXAddTracksListModel::MediaL" );
       
   203     TInt entriesCount( iTracksList->Count() );
       
   204     if ( ( entriesCount < aIndex + 1 ) || ( aIndex < 0 ) )
       
   205         {
       
   206         User::Leave( KErrArgument );
       
   207         }
       
   208     CMPXMedia* item( iTracksList->AtL( aIndex ) );
       
   209     User::LeaveIfNull( item );
       
   210     return *item;
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CMPXAddTracksListModel::TracksListCount
       
   215 // Return number of tracks stored in the list.
       
   216 // (other items were commented in a header).
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 TInt CMPXAddTracksListModel::TracksListCount() const
       
   220     {
       
   221     MPX_FUNC( "CMPXAddTracksListModel::TracksListCount" );
       
   222     return iTracksList->Count();
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CMPXAddTracksListModel::InsertGroupsL
       
   227 // Insert groups at aPos of the tracks list.
       
   228 // (other items were commented in a header).
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CMPXAddTracksListModel::InsertGroupsL(
       
   232     CMPXMediaArray& aMedia, TInt aPos , TInt aCategory)
       
   233     {
       
   234     MPX_FUNC( "CMPXAddTracksListModel::InsertGroupsL" );
       
   235     TInt count = aMedia.Count();
       
   236     MPX_DEBUG2( "CMPXAddTracksListModel::InsertGroupsL MdcaCount = %d", count );
       
   237     for ( TInt index = 0; index < count; index++ )
       
   238         {
       
   239         MPX_DEBUG2( "CMPXAddTracksListModel::InsertGroupsL index = %d", index );
       
   240         CMPXMedia* origItem( aMedia.AtL( index ) );
       
   241         User::LeaveIfNull( origItem );
       
   242         CMPXMedia* item( CMPXMedia::NewL( *origItem ) );
       
   243         item->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup );
       
   244         item->SetTObjectValueL( KMPXMediaGeneralCategory, aCategory );
       
   245         if ( aPos == -1 )
       
   246             {
       
   247             iTracksList->AppendL( item );
       
   248             }
       
   249         else
       
   250             {
       
   251             iTracksList->InsertL( item, aPos + index );
       
   252             }
       
   253         }
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CMPXAddTracksListModel::InsertTrackL
       
   258 // Insert track at position.
       
   259 // (other items were commented in a header).
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CMPXAddTracksListModel::InsertTrackL(
       
   263     CMPXMedia& aTrack, TInt aIndex )
       
   264     {
       
   265     MPX_FUNC( "CMPXAddTracksListModel::InsertTrackL" );
       
   266     CMPXMedia* media = CMPXMedia::NewL( aTrack );
       
   267     iTracksList->Insert( media, aIndex );
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CMPXAddTracksListModel::InsertTracksUnderGroupL
       
   272 // Insert tracks under the current group. Update the expanded array too.
       
   273 // (other items were commented in a header).
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CMPXAddTracksListModel::InsertTracksUnderGroupL(
       
   277     CMPXMediaArray& aTracks, TInt aIndex )
       
   278     {
       
   279     MPX_FUNC( "CMPXAddTracksListModel::InsertTracksUnderGroupL" );
       
   280     // Make sure the current index is a group
       
   281     if ( TrackTypeL( aIndex ) == EMPXGroup )
       
   282         {
       
   283         TInt count = aTracks.Count();
       
   284         for ( TInt i = 0; i < count; i++ )
       
   285             {
       
   286             CMPXMedia* origItem( aTracks.AtL( i ) );
       
   287             User::LeaveIfNull( origItem );
       
   288             CMPXMedia* media = CMPXMedia::NewL( *origItem );
       
   289             iTracksList->Insert( media, aIndex + 1 + i );
       
   290             }
       
   291         // Mark as expanded
       
   292         MarkExpandedL( aIndex, count );
       
   293         }
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CMPXAddTracksListModel::RemoveAllTracksFromGroupL
       
   298 // Remove all tracks under group.
       
   299 // (other items were commented in a header).
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TInt CMPXAddTracksListModel::RemoveAllTracksFromGroupL( TInt aIndex )
       
   303     {
       
   304     MPX_FUNC( "CMPXAddTracksListModel::RemoveAllTracksFromGroupL" );
       
   305     TInt count = 0;
       
   306     if ( TrackTypeL( aIndex ) == EMPXGroup )
       
   307         {
       
   308         TInt pos = aIndex + 1;
       
   309         while ( ( pos < TracksListCount() ) &&
       
   310             ( TrackTypeL( pos ) != EMPXGroup ) )
       
   311             {
       
   312             // Remove the track from the list
       
   313             iTracksList->Remove( pos );
       
   314             count++;
       
   315             }
       
   316         // Mark as collapsed
       
   317         UnMarkExpanded( aIndex, count );
       
   318         }
       
   319     return count;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CMPXAddTracksListModel::RemoveTracks
       
   324 // Remove tracks.
       
   325 // (other items were commented in a header).
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CMPXAddTracksListModel::RemoveTracks( TInt aIndex )
       
   329     {
       
   330     MPX_FUNC( "CMPXAddTracksListModel::RemoveTracks" );
       
   331     iTracksList->Remove( aIndex );
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CMPXAddTracksListModel::ExpandedGroupsCount
       
   336 // Return expanded groups count.
       
   337 // (other items were commented in a header).
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 TInt CMPXAddTracksListModel::ExpandedGroupsCount() const
       
   341     {
       
   342     MPX_FUNC( "CMPXAddTracksListModel::ExpandedGroupsCount" );
       
   343     return iExpandedIndices.Count();
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CMPXAddTracksListModel::IsExpandedIndex
       
   348 // Check if the index is expanded or not.
       
   349 // (other items were commented in a header).
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 TBool CMPXAddTracksListModel::IsExpandedIndex( TInt aIndex ) const
       
   353     {
       
   354     //MPX_FUNC( "CMPXAddTracksListModel::IsExpandedIndex" );
       
   355     TBool result = EFalse;
       
   356     if ( iExpandedIndices.Find( aIndex ) != KErrNotFound )
       
   357         {
       
   358         result = ETrue;
       
   359         }
       
   360 
       
   361     return result;
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CMPXAddTracksListModel::MarkExpandedL
       
   366 // Mark the current index as expanded.
       
   367 // (other items were commented in a header).
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void CMPXAddTracksListModel::MarkExpandedL( TInt aIndex, TInt aCount )
       
   371     {
       
   372     MPX_FUNC( "CMPXAddTracksListModel::MarkExpandedL" );
       
   373     // Update the expanded array accordingly.
       
   374     TInt count = iExpandedIndices.Count();
       
   375     for ( TInt i = 0; i < count; i++ )
       
   376         {
       
   377         TInt& temp = iExpandedIndices[ i ];
       
   378         if ( temp > aIndex )
       
   379             {
       
   380             temp += aCount;
       
   381             }
       
   382         }
       
   383 
       
   384     iExpandedIndices.Append( aIndex );
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CMPXAddTracksListModel::UnMarkExpanded
       
   389 // Clear the current index as collapsed.
       
   390 // (other items were commented in a header).
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CMPXAddTracksListModel::UnMarkExpanded( TInt aIndex, TInt aCount )
       
   394     {
       
   395     MPX_FUNC( "CMPXAddTracksListModel::UnMarkExpanded" );
       
   396     TInt pos = iExpandedIndices.Find( aIndex );
       
   397     if ( pos != KErrNotFound )
       
   398         {
       
   399         iExpandedIndices.Remove( pos );
       
   400 
       
   401         // Update the expanded array accordingly.
       
   402         TInt count = iExpandedIndices.Count();
       
   403         for ( TInt i = 0; i < count; i++ )
       
   404             {
       
   405             TInt& temp = iExpandedIndices[ i ];
       
   406             if ( temp > aIndex )
       
   407                 {
       
   408                 temp -= aCount;
       
   409                 }
       
   410             }
       
   411 
       
   412         iExpandedIndices.Compress();
       
   413         }
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CMPXAddTracksListModel::OldestExpandedGroupIndex
       
   418 // Return the oldest expanded group index.
       
   419 // (other items were commented in a header).
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TInt CMPXAddTracksListModel::OldestExpandedGroupIndex()
       
   423     {
       
   424     MPX_FUNC( "CMPXAddTracksListModel::OldestExpandedGroupIndex" );
       
   425     // Oldest item is always located at the top of the list
       
   426     return iExpandedIndices[ 0 ];
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // CMPXAddTracksListModel::ClosestExpandedGroupIdx
       
   431 // Return the closest expanded group index.
       
   432 // (other items were commented in a header).
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 TInt CMPXAddTracksListModel::ClosestExpandedGroupIdx( TInt aIndex )
       
   436     {
       
   437     MPX_FUNC( "CMPXAddTracksListModel::ClosestExpandedGroupIdx" );
       
   438     TInt count = iExpandedIndices.Count();
       
   439     TInt result = KErrNotFound;
       
   440 
       
   441     for ( TInt i = 0; i < count; i++ )
       
   442         {
       
   443         TInt temp = iExpandedIndices[ i ];
       
   444         if ( ( temp <= aIndex ) &&
       
   445             ( temp > result ) )
       
   446             {
       
   447             result = temp;
       
   448             }
       
   449         }
       
   450     return result;
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CMPXAddTracksListModel::AnimationIconNum
       
   455 // Return animation icon index for highlight item.
       
   456 // (other items were commented in a header).
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 TInt CMPXAddTracksListModel::AnimationIconNum( TInt aIndex )
       
   460     {
       
   461     //MPX_FUNC( "CMPXAddTracksListModel::AnimationIconNum" );
       
   462     TInt trackType = EMPXNoType;
       
   463     MPX_TRAPD( error, trackType = TrackTypeL( aIndex ) );
       
   464 
       
   465     if( ( aIndex == iCurrentHighlightIndex )
       
   466         && ( trackType != EMPXGroup )
       
   467         && ( error == KErrNone ) )
       
   468         {
       
   469         return iAnimIconNum;
       
   470         }
       
   471     else
       
   472         {
       
   473         return 0;   // no animation icon
       
   474         }
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CMPXAddTracksListModel::SetAnimationIconNum
       
   479 // Set animation icon index number.
       
   480 // (other items were commented in a header).
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CMPXAddTracksListModel::SetAnimationIconNum(
       
   484     TInt aIndex,
       
   485     TInt aAnimIconNum )
       
   486     {
       
   487     MPX_FUNC( "CMPXAddTracksListModel::SetAnimationIconNum" );
       
   488     iCurrentHighlightIndex = aIndex;
       
   489     iAnimIconNum = aAnimIconNum;
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CMPXAddTracksListModel::FindSongs
       
   494 // Provide info if there is matched songs.
       
   495 // (other items were commented in a header).
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 TBool CMPXAddTracksListModel::FindSongs()
       
   499     {
       
   500     MPX_FUNC( "CMPXAddTracksListModel::FindSongs" );
       
   501     return iFindSongs;
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CMPXAddTracksListModel::SetFindSongsFlag
       
   506 // Set flag to indicate if there are mathed songs.
       
   507 // (other items were commented in a header).
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 void CMPXAddTracksListModel::SetFindSongsFlag( TBool aFindSongs )
       
   511     {
       
   512     MPX_FUNC( "CMPXAddTracksListModel::SetFindSongsFlag" );
       
   513     iFindSongs = aFindSongs;
       
   514     }
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CMPXAddTracksListModel::FindSongs
       
   518 // determines if the current item is on removable drive
       
   519 // (other items were commented in a header).
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 TBool CMPXAddTracksListModel::IsOnRemovableDrive( TInt aIndex )
       
   523     {
       
   524     MPX_FUNC( "CMPXAddTracksListModel::IsOnRemovableDrive" );
       
   525     CMPXMedia* entry( NULL );
       
   526     TInt count( iTracksList->Count() );
       
   527     if ( count > 0 && aIndex < count )
       
   528         {
       
   529         TRAP_IGNORE( entry = iTracksList->AtL( aIndex ) ) ;
       
   530         }
       
   531 
       
   532     TUint flags(0);
       
   533     if ( entry )
       
   534         {
       
   535         if( entry->IsSupported( KMPXMediaGeneralFlags ) )
       
   536             {
       
   537             TRAP_IGNORE( flags = entry->ValueTObjectL<TUint>( KMPXMediaGeneralFlags ) );
       
   538             }
       
   539         }
       
   540 
       
   541     TInt driveNum( ( flags ) & ( KMPXMediaGeneralFlagsDriveInfo ) );
       
   542     return ( driveNum == iMMCDrive );
       
   543     }
       
   544 
       
   545 //  End of File