appinstaller/AppMngr2/src/appmngr2log.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:   Shows installation log in a popup list dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2log.h"                // CAppMngr2Log
       
    20 #include "appmngr2logpopuplist.h"       // CAppMngr2LogPopupList
       
    21 #include "appmngr2logdatabase.h"        // CAppMngr2LogDatabase
       
    22 #include "appmngr2logdatabaseentry.h"   // CAppMngr2LogDatabaseEntry
       
    23 #include <appmngr2.rsg>                 // Resource IDs
       
    24 #include <aknlists.h>                   // CAknDoublePopupMenuStyleListBox
       
    25 #include <StringLoader.h>               // Stingloader
       
    26 
       
    27 const TInt KMaxNumberOfShownLogItems = 50;
       
    28 const TInt KInstDateTimeTextLength = 64;
       
    29 const TInt KInstActionTextLength = 64;
       
    30 const TInt KInstLogLineTextLen = KInstDateTimeTextLength +
       
    31     KInstActionTextLength + SwiUI::KMaxLogNameLength;
       
    32 
       
    33 // Date and action separated by " - "
       
    34 _LIT( KSeparator, " - " );
       
    35 _LIT( KVersionPrefix, " (" );
       
    36 _LIT( KVersionSuffix, ")" );
       
    37 
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAppMngr2Log::CAppMngr2Log()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CAppMngr2Log::CAppMngr2Log( CEikonEnv& aEikEnv ) : iEikEnv( aEikEnv )
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CAppMngr2Log::NewLC()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CAppMngr2Log* CAppMngr2Log::NewLC()
       
    54     {
       
    55     CAppMngr2Log* self = new (ELeave) CAppMngr2Log( *( CEikonEnv::Static() ) );
       
    56     CleanupStack::PushL( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CAppMngr2Log::~CAppMngr2Log()
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CAppMngr2Log::~CAppMngr2Log()
       
    65     {
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CAppMngr2Log::ShowInstallationLogL()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CAppMngr2Log::ShowInstallationLogL()
       
    73     {    
       
    74     CEikFormattedCellListBox* listBox = new (ELeave) CAknDoublePopupMenuStyleListBox;
       
    75     CleanupStack::PushL( listBox );
       
    76 
       
    77     // AppMngr version of Avkon popup list with heading
       
    78     CAppMngr2LogPopupList* popupList = CAppMngr2LogPopupList::NewL(
       
    79             listBox, R_AVKON_SOFTKEYS_OK_EMPTY__OK, AknPopupLayouts::EMenuDoubleWindow );
       
    80     CleanupStack::PushL( popupList );
       
    81     
       
    82     // Set title text
       
    83     HBufC* title = StringLoader::LoadLC( R_INST_LOG_HEADER );
       
    84     popupList->SetTitleL( *title );
       
    85     CleanupStack::PopAndDestroy( title );
       
    86 
       
    87     // Set listbox properties and create item array
       
    88     listBox->ConstructL( popupList, EAknListBoxViewerFlags );
       
    89     listBox->CreateScrollBarFrameL( ETrue );
       
    90     listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
    91             CEikScrollBarFrame::EAuto );
       
    92     MDesCArray* itemList = listBox->Model()->ItemTextArray();
       
    93     CDesCArray* itemArray = static_cast<CDesCArray*>( itemList );    
       
    94     ConstructLogArrayL( itemArray );
       
    95 
       
    96     // Set empty text
       
    97     CListBoxView* view = listBox->View();
       
    98     HBufC* emptyText = StringLoader::LoadLC( R_QTN_SWINS_LOG_EMPTY );
       
    99     view->SetListEmptyTextL( *emptyText );
       
   100     CleanupStack::PopAndDestroy( emptyText );
       
   101     
       
   102     // Lauch popup list
       
   103     popupList->ExecuteLD();
       
   104 
       
   105     CleanupStack::Pop( popupList );
       
   106     CleanupStack::PopAndDestroy( listBox );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CAppMngr2Log::ConstructLogArrayL()
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CAppMngr2Log::ConstructLogArrayL( CDesCArray* aItemArray )
       
   114     {
       
   115     CAppMngr2LogDatabase* log = CAppMngr2LogDatabase::NewL();
       
   116     CleanupStack::PushL( log );
       
   117 
       
   118     const RPointerArray<CAppMngr2LogDatabaseEntry>& logEntries = log->Entries();
       
   119     
       
   120     // Read KMaxNumberOfShownLogItems first log entries, ignore the rest 
       
   121     TInt length = logEntries.Count();
       
   122     TInt diff = length - KMaxNumberOfShownLogItems;
       
   123 
       
   124     // Add entries from the latest log item (reverse order) into item array
       
   125     for( TInt index = length - 1; index >= diff && index >= 0; index-- )
       
   126         {
       
   127         if( logEntries[ index ] )
       
   128             {
       
   129             const CAppMngr2LogDatabaseEntry& entry = *( logEntries[ index ] );
       
   130     
       
   131             HBufC* buffer = HBufC::NewMaxLC( KInstLogLineTextLen );
       
   132             TPtr listboxLine = buffer->Des();
       
   133             listboxLine.Zero();
       
   134     
       
   135             // First row in double list item contains application name
       
   136             listboxLine.Append( entry.Name() );
       
   137             listboxLine.Append( KVersionPrefix );
       
   138             listboxLine.Append( entry.Version() );
       
   139             listboxLine.Append( KVersionSuffix );
       
   140             listboxLine.Append( KColumnListSeparator );
       
   141             
       
   142             // Second row contains date and action type (install/uninstall/partial)
       
   143             SetLogDateTimeColumnL( listboxLine, entry.Time() );
       
   144             listboxLine.Append( KSeparator );
       
   145             SetLogActionTextColumnL( listboxLine, entry.Action() );
       
   146     
       
   147             aItemArray->AppendL( listboxLine );
       
   148             CleanupStack::PopAndDestroy( buffer );
       
   149             }
       
   150         }
       
   151         
       
   152     CleanupStack::PopAndDestroy( log );
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CAppMngr2Log::SetLogActionTextColumnL()
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CAppMngr2Log::SetLogActionTextColumnL( TDes& aListboxLine,
       
   160         const SwiUI::TLogTaskAction& aAction )
       
   161     {
       
   162     TBuf<KInstActionTextLength> action;
       
   163     switch( aAction )
       
   164         {
       
   165         case SwiUI::ELogTaskActionInstall:
       
   166             iEikEnv.ReadResourceL( action, R_INST_INSTALL_EVENT );
       
   167             break;
       
   168         case SwiUI::ELogTaskActionUninstall:
       
   169             iEikEnv.ReadResourceL( action, R_INST_REMOVE_EVENT );
       
   170             break;
       
   171         // no action for R_INST_PARTIAL_INSTALL_EVENT, not supported
       
   172         default:
       
   173             break;
       
   174         }
       
   175     aListboxLine.Append( action );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CAppMngr2Log::SetLogDateTimeColumnL()
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CAppMngr2Log::SetLogDateTimeColumnL( TDes& aListboxLine,
       
   183         const TTime& aDateTime )
       
   184     {
       
   185     TBuf<KInstDateTimeTextLength> tempBuf;
       
   186     TBuf<KInstDateTimeTextLength> dateFormat;
       
   187     iEikEnv.ReadResourceL( dateFormat, R_QTN_DATE_USUAL_WITH_ZERO );   
       
   188     aDateTime.FormatL( tempBuf, dateFormat );
       
   189     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempBuf );
       
   190     aListboxLine.Append( tempBuf );
       
   191     }
       
   192