idlehomescreen/nativeuicontroller/src/aistatuspanetouchui.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Choice list.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AknLayout2ScalableDef.h>
       
    20 #include <aknstyluspopupmenu.h>
       
    21 #include <AknUtils.h>
       
    22 #include <aknnavide.h>
       
    23 #include <akntitle.h>
       
    24 #include <MProfileEngine.h>
       
    25 #include <viewcli.h>
       
    26 #include <aknlayoutscalable_avkon.cdl.h>
       
    27 #ifdef RD_TACTILE_FEEDBACK
       
    28 #include <touchfeedback.h>
       
    29 #endif
       
    30 #include <hscontentpublisher.h>
       
    31 #include <hspublisherinfo.h>
       
    32 #include <aidevicestatuscontentmodel.h>
       
    33 #include <AiNativeUi.rsg>
       
    34 
       
    35 // User includes
       
    36 #include "aistrcnv.h"
       
    37 #include "aistatuspanetouchui.h"
       
    38 #include "aistatuspanel.h"
       
    39 #include "ainativeuiplugins.h"
       
    40 #include "aifweventhandler.h"
       
    41 #include "aiconsts.h"
       
    42 
       
    43 using namespace AiNativeUiController;
       
    44 
       
    45 // Constants
       
    46 _LIT( KProfileSwitchByIndexEvent, "Profile/SwitchProfileByIndex" );
       
    47 const TInt KProfileSwitchByIndexEventLength = 28;
       
    48 const TInt KRadix = 10;
       
    49 const TText16 KEventParameterTerminator = ')';
       
    50 const TInt KExtraItems = 2;
       
    51 const TInt KStylusMenuMaxItemsDefault = 0;
       
    52 
       
    53 _LIT( KOpenAppProfiles, "Shortcut/LaunchByValue(localapp:0x100058F8)" );
       
    54 _LIT( KOpenAppCalendar, "Shortcut/LaunchByValue(localapp:0x10005901)" );
       
    55 
       
    56 // ======== LOCAL FUNCTIONS ========
       
    57 // ----------------------------------------------------------------------------
       
    58 // IndexLength()
       
    59 //
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 static TInt IndexLength( TInt aIndex )
       
    63     {
       
    64     TInt length = 0;
       
    65 
       
    66     if ( aIndex < 0 )
       
    67          {
       
    68          ++length;
       
    69          }
       
    70 
       
    71     do
       
    72       {
       
    73         aIndex /= KRadix;
       
    74         ++length;
       
    75         }
       
    76     while ( aIndex != 0 );
       
    77     return length;
       
    78   }
       
    79 
       
    80 // ======== MEMBER FUNCTIONS ========
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CAiStatusPaneTouchUi::NewL()
       
    84 //
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CAiStatusPaneTouchUi* CAiStatusPaneTouchUi::NewL( CAiStatusPanel& aStatusPanel,
       
    88     MAiFwEventHandler& aEventHandler )
       
    89     {
       
    90     CAiStatusPaneTouchUi* self = 
       
    91         CAiStatusPaneTouchUi::NewLC( aStatusPanel, aEventHandler );
       
    92     CleanupStack::Pop( self );
       
    93 
       
    94     return self;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // CAiStatusPaneTouchUi::NewLC()
       
    99 //
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 CAiStatusPaneTouchUi* CAiStatusPaneTouchUi::NewLC( CAiStatusPanel& aStatusPanel,
       
   103     MAiFwEventHandler& aEventHandler )
       
   104     {
       
   105     CAiStatusPaneTouchUi* self = 
       
   106         new ( ELeave ) CAiStatusPaneTouchUi( aStatusPanel, aEventHandler );
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL();
       
   109 
       
   110     return self;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CAiStatusPaneTouchUi::CAiStatusPaneTouchUi()
       
   115 //
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 CAiStatusPaneTouchUi::CAiStatusPaneTouchUi( CAiStatusPanel& aStatusPanel,
       
   119     MAiFwEventHandler& aEventHandler )
       
   120     : iStatusPane( aStatusPanel ), iEventHandler( aEventHandler )
       
   121     {
       
   122     // no implementation required
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CAiStatusPaneTouchUi::~CAiStatusPaneTouchUi()
       
   127 //
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 CAiStatusPaneTouchUi::~CAiStatusPaneTouchUi()
       
   131     {
       
   132     delete iEventBuffer;
       
   133     delete iMenu;
       
   134     iProfileNamePointerArray.ResetAndDestroy();
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // CAiStatusPaneTouchUi::ConstructL()
       
   139 //
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void CAiStatusPaneTouchUi::ConstructL()
       
   143     {
       
   144     if( AknLayoutUtils::PenEnabled() )
       
   145         {
       
   146         iStatusPane.SetNaviDecoratorObserver( this );
       
   147         }
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CAiStatusPaneTouchUi::LoadUIDefinitionL()
       
   152 //
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 void CAiStatusPaneTouchUi::LoadUIDefinitionL()
       
   156     {
       
   157     // If profile popup exists, for example, when screendevicechange occurs,
       
   158     // the popup is closed
       
   159     if( iMenu )
       
   160         {
       
   161         delete iMenu;
       
   162         iMenu = NULL;
       
   163         }
       
   164     }
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // CAiStatusPaneTouchUi::ProcessCommandL()
       
   168 //
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 void CAiStatusPaneTouchUi::ProcessCommandL( TInt aCommandId )
       
   172     {
       
   173     if( aCommandId == EAIGotoCalendarCmdLink )
       
   174       {
       
   175       //Open calendar application
       
   176       iEventHandler.HandlePluginEvent( KOpenAppCalendar );
       
   177       }
       
   178     else if( aCommandId == EAIShowAllProfileCmdLink )
       
   179       {
       
   180       //Open profile application
       
   181       iEventHandler.HandlePluginEvent( KOpenAppProfiles );
       
   182       }
       
   183     else
       
   184       {
       
   185 
       
   186     // Calculate event buffer length
       
   187       TInt length = KProfileSwitchByIndexEventLength
       
   188                     + KPluginEventSeparatorLength
       
   189                   + IndexLength( aCommandId - EAIProfileCmdLink )
       
   190                     + KEventParameterSeparatorLength;
       
   191 
       
   192         // Allocate event buffer
       
   193         TPtr event = AiUtility::EnsureBufMaxLengthL( iEventBuffer, length );
       
   194 
       
   195         // Create event string
       
   196         event.Zero();
       
   197         event.Append( KProfileSwitchByIndexEvent );
       
   198         event.Append( KEventParameterSeparator );
       
   199         event.AppendNum( aCommandId - EAIProfileCmdLink );
       
   200         event.Append( KEventParameterTerminator );
       
   201 
       
   202       iEventHandler.HandlePluginEvent( event );
       
   203       }
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CAiStatusPaneTouchUi::HandleNaviDecoratorEventL()
       
   208 //
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void CAiStatusPaneTouchUi::HandleNaviDecoratorEventL( TInt aEventID )
       
   212     {
       
   213     if( aEventID == EAknNaviDecoratorEventNaviLabel )
       
   214         {
       
   215 #ifdef RD_TACTILE_FEEDBACK
       
   216         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   217         if ( feedback )
       
   218             {
       
   219             feedback->InstantFeedback( ETouchFeedbackBasic );
       
   220             }
       
   221 #endif
       
   222 
       
   223         TBool isShowAllProfilesItem = EFalse;
       
   224         TInt count = iProfileNamePointerArray.Count();
       
   225 
       
   226         if ( !count )
       
   227             {
       
   228             //profile plugin is not ready!
       
   229             return;
       
   230             }
       
   231 
       
   232         TInt aiStylusMenuMaxItems = KStylusMenuMaxItemsDefault;
       
   233         TPoint tapPoint(0,0);
       
   234         TRect clientRect;
       
   235         TRect naviRect;
       
   236 
       
   237         // Check screen sizes
       
   238         TInt isMainPane = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect );
       
   239         TInt isNaviPane = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, naviRect );
       
   240 
       
   241         // Calculating how many items fits into menu, using font height
       
   242         TAknLayoutText layoutText;
       
   243         layoutText.LayoutText( naviRect,
       
   244                 AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine());
       
   245 
       
   246         TInt txtHeight = layoutText.Font()->HeightInPixels();
       
   247         // More additional space for marginals
       
   248         txtHeight += txtHeight + txtHeight/2;
       
   249 
       
   250         if( isNaviPane )
       
   251             {
       
   252             if ( AknLayoutUtils::LayoutMirrored() )
       
   253                 {
       
   254                 tapPoint.SetXY( naviRect.iBr.iX, naviRect.iBr.iY );
       
   255                 }
       
   256             else
       
   257                 {
       
   258                 tapPoint.SetXY( naviRect.iTl.iX, naviRect.iBr.iY );
       
   259                 }
       
   260             }
       
   261 
       
   262         if ( iMenu )
       
   263             {
       
   264             delete iMenu;
       
   265             iMenu = NULL;
       
   266             }
       
   267 
       
   268         iMenu = CAknStylusPopUpMenu::NewL( this, tapPoint );
       
   269 
       
   270         if( isMainPane )
       
   271             {
       
   272             // Count how many menu items would fit into screen
       
   273             aiStylusMenuMaxItems = clientRect.Height() / txtHeight;
       
   274             }
       
   275 
       
   276             HBufC* caleText = StringLoader::LoadLC( R_IDLE_NAVI_TAPPED_CALE );
       
   277             iMenu->AddMenuItemL( *caleText, EAIGotoCalendarCmdLink );
       
   278             CleanupStack::PopAndDestroy( caleText );
       
   279             count++;
       
   280 
       
   281       // Space for 2 extra items GotoCalendar and ShowAllProfiles
       
   282       if( count > aiStylusMenuMaxItems )
       
   283     	  {
       
   284     	  count = aiStylusMenuMaxItems - KExtraItems;
       
   285             isShowAllProfilesItem = ETrue;
       
   286             }
       
   287         else
       
   288             {
       
   289     	  count -= 1;
       
   290             }
       
   291 
       
   292         for( TInt i = 0; i < count; i++ )
       
   293             {
       
   294             iMenu->AddMenuItemL( iProfileNamePointerArray[i]->Des(), i + EAIProfileCmdLink );
       
   295             }
       
   296 
       
   297         if( isShowAllProfilesItem )
       
   298             {
       
   299             HBufC* allProfilesText = StringLoader::LoadLC( R_IDLE_NAVI_TAPPED_ALL_PROF );
       
   300             iMenu->AddMenuItemL( *allProfilesText, EAIShowAllProfileCmdLink );
       
   301             CleanupStack::PopAndDestroy( allProfilesText );
       
   302             }
       
   303 
       
   304         iMenu->ShowMenu();
       
   305         }
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // CAiStatusPaneTouchUi::DoPublishL()
       
   310 //
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 void CAiStatusPaneTouchUi::DoPublishL( CHsContentPublisher& aPlugin,
       
   314     TInt aContent, const TDesC16& aText, TInt aIndex )
       
   315     {
       
   316     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
       
   317     
       
   318     if( info.Uid() == KProfilePluginUid )
       
   319       {
       
   320       switch( aContent )
       
   321         {
       
   322         case EAiProfileContentProfileName:
       
   323         {
       
   324         if( aIndex - 1 == 0  )
       
   325           {
       
   326           iProfileNamePointerArray.ResetAndDestroy();
       
   327           }
       
   328 
       
   329         TInt count = iProfileNamePointerArray.Count();
       
   330 
       
   331         if( count >= aIndex  )
       
   332           {
       
   333           delete iProfileNamePointerArray[ aIndex - 1 ];
       
   334           iProfileNamePointerArray.Remove( aIndex - 1);
       
   335           }
       
   336 
       
   337         HBufC* name = aText.AllocL();
       
   338         iProfileNamePointerArray.Insert( name, aIndex - 1 );
       
   339         break;
       
   340         }
       
   341         default:
       
   342           {
       
   343           break;
       
   344           }
       
   345         };
       
   346       }
       
   347 
       
   348     else
       
   349       {
       
   350       User::Leave( KErrNotFound );
       
   351       }
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------------------------------
       
   355 // CAiStatusPaneTouchUi::SetEmphasis()
       
   356 //
       
   357 // ----------------------------------------------------------------------------
       
   358 //
       
   359 void CAiStatusPaneTouchUi::SetEmphasis( CCoeControl* /*aMenuControl*/, 
       
   360     TBool /*aEmphasis*/ )
       
   361     {
       
   362     }
       
   363 
       
   364 // End of file