mobilemessaging/mmsui/notmtmsrc/MMBoxArray.cpp
changeset 79 2981cb3aa489
parent 0 72b543305e3a
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Implementation of the CMMBoxArray class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <msvapi.h>                     // for CMsvSession
       
    22 #include <msvids.h>                     // for KMsvRootIndexEntryId
       
    23 #include <gulutil.h>                    // for KColumnListSeparator
       
    24 #include <txtetext.h>                  // for CEditableText
       
    25 #include <mmsconst.h>                   // for KUidMsgMMSNotification
       
    26 #include "MMBoxArray.h"
       
    27 #include "NotMtmUiData.h"
       
    28 #include "MmsMtmConst.h"                // For Logs
       
    29 
       
    30 //  LOCAL CONSTANTS AND MACROS
       
    31 const TInt KMMBoxBitmapIndex = 1;
       
    32 const TInt KMMBoxHighPriorityIconIndex = 2; 
       
    33 const TInt KMMBoxLowPriorityIconIndex = 3;
       
    34 const TInt KMMBoxMaxDisplayTextLength = 80;
       
    35 const TInt KMMBoxMaxVisibleChars = 30;
       
    36 
       
    37 //
       
    38 //
       
    39 // CMMBoxArray
       
    40 //
       
    41 //
       
    42 
       
    43 // ----------------------------------------------------
       
    44 // CMMBoxArray::CMMBoxArray
       
    45 // ----------------------------------------------------
       
    46 CMMBoxArray::CMMBoxArray( CMsvSession& aSession, CNotMtmUiData& aUiData ):
       
    47     iSession( aSession ),
       
    48     iUiData( aUiData )
       
    49     {
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------
       
    53 // CMMBoxArray::NewL
       
    54 // ----------------------------------------------------
       
    55 CMMBoxArray* CMMBoxArray::NewL( CMsvSession& aSession, CNotMtmUiData& aUiData )
       
    56     {
       
    57     CMMBoxArray* self = new (ELeave) CMMBoxArray(aSession, aUiData);
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------
       
    65 // CMMBoxArray::ConstructL
       
    66 // ----------------------------------------------------
       
    67 void CMMBoxArray::ConstructL()
       
    68     {
       
    69     LOGTEXT(_L8("MMBoxArray: Construct start"));
       
    70     TMsvSelectionOrdering ordering = TMsvSelectionOrdering(
       
    71         KMsvNoGrouping,
       
    72         EMsvSortByDateReverse,
       
    73         EFalse );
       
    74 
       
    75     iFolderEntry = CMsvEntry::NewL( 
       
    76         iSession, 
       
    77         KMsvRootIndexEntryId, 
       
    78         ordering );
       
    79 
       
    80     iListBoxText = HBufC::NewL( KMMBoxMaxDisplayTextLength );
       
    81     LOGTEXT(_L8("MMBoxArray: Construct end"));
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------
       
    85 // CMMBoxArray::~CMMBoxArray
       
    86 // ----------------------------------------------------
       
    87 CMMBoxArray::~CMMBoxArray()
       
    88     {
       
    89     LOGTEXT(_L8("MMBoxArray: Destructor"));
       
    90     delete iFolderEntry;
       
    91     delete iListBoxText;
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------
       
    95 // CMMBoxArray::MdcaCount
       
    96 // ----------------------------------------------------
       
    97 TInt CMMBoxArray::MdcaCount() const
       
    98     {
       
    99     LOGTEXT(_L8("MMBoxArray: MdcaCount"));
       
   100     TInt retVal = 0;
       
   101     CMsvEntrySelection* msgSel = NULL;
       
   102     TRAP_IGNORE( msgSel = iFolderEntry->ChildrenWithMtmL( KUidMsgMMSNotification ) );
       
   103     retVal = msgSel->Count( );
       
   104     delete msgSel;
       
   105     return retVal;
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------
       
   109 // CMMBoxArray::MdcaPoint
       
   110 // ----------------------------------------------------
       
   111 TPtrC CMMBoxArray::MdcaPoint(TInt aIndex) const
       
   112     {
       
   113     LOGTEXT(_L8("MMBoxArray: MdcaPoint"));
       
   114     TPtr tempText = iListBoxText->Des();
       
   115     tempText.Zero();
       
   116 
       
   117     TMsvId childId = EntryId( aIndex );
       
   118 
       
   119     TMsvId service=-1;
       
   120     TMsvEntry child;
       
   121     TInt error = iSession.GetEntry( childId, service, child );
       
   122 
       
   123 	if( error )
       
   124 		{
       
   125 	    tempText.AppendNum( KMMBoxBitmapIndex ); // index of the bitmap to be shown
       
   126     	tempText.Append( KColumnListSeparator );
       
   127         tempText.Append( CEditableText::ESpace );
       
   128 	    tempText.Append( KColumnListSeparator );
       
   129         tempText.Append( CEditableText::ESpace );
       
   130         return tempText;	
       
   131 		}
       
   132 	else
       
   133 		{
       
   134 	    // construct listbox-string
       
   135 	    // bitmap
       
   136 	    LOGTEXT(_L8("MMBoxArray: MdcaPoint Add bitmapindex"));
       
   137 	    tempText.AppendNum( KMMBoxBitmapIndex ); // index of the bitmap to be shown
       
   138 
       
   139 	    tempText.Append( KColumnListSeparator );
       
   140 
       
   141 	    // sender-information
       
   142 	    if ( child.iDetails.Length() > KMMBoxMaxVisibleChars )
       
   143 	        {
       
   144 	        LOGTEXT(_L8("MMBoxArray: MdcaPoint Add sender1"));
       
   145 	        tempText.Append( child.iDetails.Left( KMMBoxMaxVisibleChars-1 ) );
       
   146 	        tempText.Append( CEditableText::EEllipsis );
       
   147 	        }
       
   148 	    else if ( child.iDetails.Length( ) > 0 )
       
   149 	        {
       
   150 	        LOGTEXT(_L8("MMBoxArray: MdcaPoint Add sender2"));
       
   151 	        tempText.Append( child.iDetails );
       
   152 	        }
       
   153 	    else
       
   154 	        {
       
   155 	        // append space, needed by list box
       
   156 	        LOGTEXT(_L8("MMBoxArray: MdcaPoint Add sender3"));
       
   157 	        tempText.Append( CEditableText::ESpace );
       
   158 	        }
       
   159 
       
   160 	    tempText.Append( KColumnListSeparator );
       
   161 
       
   162 	    HBufC* statusText = NULL;
       
   163 
       
   164 	    TRAPD( err, statusText = iUiData.StatusTextL( child ) );
       
   165 	    if( !err )
       
   166 	        { // No error, status is fine
       
   167 	        TRAP_IGNORE( CleanupStack::PushL( statusText ) );
       
   168 	        if ( statusText->Length( ) > KMMBoxMaxVisibleChars )
       
   169 	            {
       
   170 	            LOGTEXT(_L8("MMBoxArray: MdcaPoint Add status1"));
       
   171 	            tempText.Append( statusText->Left( KMMBoxMaxVisibleChars-1 ) );
       
   172 	            tempText.Append( CEditableText::EEllipsis );
       
   173 	            }
       
   174 	        else if ( statusText->Length( ) > 0 )
       
   175 	            {
       
   176 	            LOGTEXT(_L8("MMBoxArray: MdcaPoint Add status2"));
       
   177 	            tempText.Append( statusText->Des() );
       
   178 	            }
       
   179 	        else
       
   180 	            {
       
   181 	            LOGTEXT(_L8("MMBoxArray: MdcaPoint Add status3"));
       
   182 	            tempText.Append( CEditableText::ESpace );
       
   183 	            }
       
   184 	        CleanupStack::PopAndDestroy( statusText );
       
   185 	        }
       
   186 	    else
       
   187 	        { // status leaved -> enter just space
       
   188 	        tempText.Append( CEditableText::ESpace );
       
   189 	        }
       
   190 
       
   191         if ( child.Priority() == EMsvHighPriority )
       
   192             {
       
   193 	        tempText.Append( KColumnListSeparator );
       
   194 	        tempText.AppendNum( KMMBoxHighPriorityIconIndex );
       
   195             }
       
   196         else if ( child.Priority() == EMsvLowPriority )
       
   197             {
       
   198 	        tempText.Append( KColumnListSeparator );
       
   199             tempText.AppendNum( KMMBoxLowPriorityIconIndex );
       
   200             }
       
   201 		}
       
   202     LOGTEXT( _L8("MMBoxArray: MdcaPoint result") );
       
   203 
       
   204     return tempText;
       
   205     }
       
   206 
       
   207 
       
   208 // ----------------------------------------------------
       
   209 // CMMBoxArray::EntryId
       
   210 // ----------------------------------------------------
       
   211 TMsvId CMMBoxArray::EntryId( TInt aIndex ) const
       
   212     {
       
   213     LOGTEXT(_L8("MMBoxArray: EntryId"));
       
   214     TMsvId retVal = 0;
       
   215     CMsvEntrySelection* msgSel = NULL;
       
   216     TRAP_IGNORE(msgSel = iFolderEntry->ChildrenWithMtmL( KUidMsgMMSNotification ) );
       
   217     retVal = msgSel->At( aIndex );
       
   218     delete msgSel;
       
   219     return retVal;
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------
       
   223 // CMMBoxArray::Entry
       
   224 // ----------------------------------------------------
       
   225 TMsvEntry CMMBoxArray::Entry( TInt aIndex ) const
       
   226     {
       
   227     LOGTEXT(_L8("MMBoxArray: Entry"));
       
   228     TMsvId service=-1;
       
   229     TMsvId indexId = EntryId( aIndex );
       
   230     TMsvEntry child;
       
   231     iSession.GetEntry( indexId, service, child );
       
   232     return child;
       
   233     }
       
   234 
       
   235 // ----------------------------------------------------
       
   236 // CMMBoxArray::RefreshArrayL
       
   237 // ----------------------------------------------------
       
   238 void CMMBoxArray::RefreshArrayL( TMsvId aFolderId )
       
   239     {
       
   240     LOGTEXT(_L8("MMBoxArray: RefreshArray"));
       
   241     iFolderEntry->SetEntryL( KMsvDraftEntryId );
       
   242     iFolderEntry->SetEntryL( aFolderId );
       
   243     }
       
   244 
       
   245 // ----------------------------------------------------
       
   246 // CMMBoxArray::SortType
       
   247 // ----------------------------------------------------
       
   248 TMMBoxSortType CMMBoxArray::SortType( ) const
       
   249     {
       
   250     LOGTEXT(_L8("MMBoxArray: SortType"));
       
   251     TMsvSelectionOrdering ordering = iFolderEntry->SortType( );
       
   252 
       
   253     TMMBoxSortType type = EMMBoxSortByDate;
       
   254 
       
   255     switch( ordering.Sorting( ) )
       
   256         {
       
   257         case EMsvSortByDate:
       
   258         case EMsvSortByDateReverse:
       
   259             break;
       
   260         case EMsvSortByDetails:
       
   261         case EMsvSortByDetailsReverse:
       
   262             type = EMMBoxSortByName;
       
   263             break;
       
   264         case EMsvSortByDescription:
       
   265         case EMsvSortByDescriptionReverse:
       
   266         default:
       
   267             type = EMMBoxSortBySubject;
       
   268             break;
       
   269         }
       
   270     return type;
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------
       
   274 // CMMBoxArray::SetSortType
       
   275 // ----------------------------------------------------
       
   276 TMsvSelectionOrdering CMMBoxArray::SetSortType( const TMMBoxSortType& aType )
       
   277     {
       
   278     LOGTEXT(_L8("MMBoxArray: SetSortType start"));
       
   279     TMsvSorting type;
       
   280 
       
   281     switch ( aType )
       
   282         {
       
   283         case EMMBoxSortByDate:
       
   284             type = EMsvSortByDateReverse;
       
   285             break;
       
   286         case EMMBoxSortByName:
       
   287             type = EMsvSortByDetails;
       
   288             break;
       
   289         case EMMBoxSortBySubject:
       
   290         default:
       
   291             type = EMsvSortByDescription;
       
   292             break;
       
   293         }
       
   294 
       
   295     if( aType == SortType( ) )
       
   296         {
       
   297         TRAP_IGNORE( ReverseSortingL( ) );
       
   298         }
       
   299     else
       
   300         {
       
   301         TMsvSelectionOrdering ordering = TMsvSelectionOrdering(
       
   302             KMsvNoGrouping,
       
   303             type,
       
   304             EFalse );
       
   305         TRAP_IGNORE( iFolderEntry->SetSortTypeL( ordering ) );
       
   306         }
       
   307     LOGTEXT(_L8("MMBoxArray: SetSortType end"));
       
   308     return iFolderEntry->SortType( );
       
   309     }
       
   310 
       
   311 // ----------------------------------------------------
       
   312 // CMMBoxArray::ReverseSorting
       
   313 // ----------------------------------------------------
       
   314 void CMMBoxArray::ReverseSortingL( )
       
   315     {
       
   316     LOGTEXT(_L8("MMBoxArray: ReverseSorting"));
       
   317     TMsvSelectionOrdering ordering = iFolderEntry->SortType( );
       
   318     TMsvSorting type = ordering.Sorting( );
       
   319 
       
   320     switch( type )
       
   321         {
       
   322         case EMsvSortByDate:
       
   323             type = EMsvSortByDateReverse;
       
   324             break;
       
   325         case EMsvSortByDateReverse:
       
   326             type = EMsvSortByDate;
       
   327             break;
       
   328         case EMsvSortByDetails:
       
   329             type = EMsvSortByDetailsReverse;
       
   330             break;
       
   331         case EMsvSortByDetailsReverse:
       
   332             type = EMsvSortByDetails;
       
   333             break;
       
   334         case EMsvSortByDescription:
       
   335             type = EMsvSortByDescriptionReverse;
       
   336             break;
       
   337         case EMsvSortByDescriptionReverse:
       
   338             type = EMsvSortByDescription;
       
   339             break;
       
   340         default: // If not found -> return from the function
       
   341             return;            
       
   342         }
       
   343     ordering.SetSorting( type );
       
   344     iFolderEntry->SetSortTypeL( ordering );
       
   345     }
       
   346 
       
   347 //  End of File