idlehomescreen/nativeuicontroller/src/aitoolbarrenderer.cpp
branchRCL_3
changeset 9 f966699dea19
parent 0 f72a12da539e
equal deleted inserted replaced
5:c743ef5928ba 9:f966699dea19
    13 *
    13 *
    14 * Description:  Touch Toolbar
    14 * Description:  Touch Toolbar
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 // System includes
       
    19 #include <centralrepository.h>
       
    20 #include <akntoolbar.h>
       
    21 #include <aknbutton.h>
       
    22 #include <AknsUtils.h>
       
    23 #include <gulicon.h>
       
    24 #include <e32property.h>
       
    25 #include <aknappui.h>
       
    26 
       
    27 // User includes
       
    28 #include <hscontentpublisher.h>
       
    29 #include <hspublisherinfo.h>
    19 #include "aitoolbarrenderer.h"
    30 #include "aitoolbarrenderer.h"
    20 #include "aifweventhandler.h"
    31 #include "aifweventhandler.h"
    21 #include "aicontentobserver.h"
    32 #include "aicontentobserver.h"
    22 #include "activeidle2domaincrkeys.h"
    33 #include "activeidle2domaincrkeys.h"
    23 #include "activeidle2domainpskeys.h"
    34 #include "activeidle2domainpskeys.h"
    24 #include "aiscutplugindomaincrkeys.h"
    35 #include "aiscutplugindomaincrkeys.h"
    25 #include <aipropertyextension.h>
    36 
    26 #include "ainativeuiplugins.h"
    37 #include "ainativeuiplugins.h"
    27 
    38 
    28 #include <AiNativeUi.rsg>
    39 #include <AiNativeUi.rsg>
    29 #include <akntoolbar.h>
       
    30 #include <aknbutton.h>
       
    31 #include <AknsUtils.h>
       
    32 #include <gulicon.h>
       
    33 #include <e32property.h>
       
    34 #include <aknappui.h>
       
    35 
       
    36 #include "centralrepository.h"
       
    37 
       
    38 
       
    39 #include "debug.h"
    40 #include "debug.h"
    40 
    41 
    41 using namespace AiNativeUiController;
    42 using namespace AiNativeUiController;
    42 
    43 
       
    44 // Constants
    43 // Action to send to framework
    45 // Action to send to framework
    44 _LIT( KOpenAppByIndex,              "Shortcut/LaunchByIndex(%d)" );
    46 _LIT( KOpenAppByIndex,              "Shortcut/LaunchByIndex(%d)" );
    45 _LIT( KOpenAppByIndexAlternate,     "Shortcut/LaunchByIndexAlternate(%d)");
    47 _LIT( KOpenAppByIndexAlternate,     "Shortcut/LaunchByIndexAlternate(%d)");
    46 
    48 
    47 const TInt KOpenAppByIndexParameterLength = 2;
    49 const TInt KOpenAppByIndexParameterLength = 2;
    50 const TInt KSecondButton = 1;
    52 const TInt KSecondButton = 1;
    51 const TInt KThirdButton  = 2;
    53 const TInt KThirdButton  = 2;
    52 
    54 
    53 const TInt KRadix = 10;
    55 const TInt KRadix = 10;
    54 
    56 
       
    57 // ======== LOCAL FUNCTIONS ========
       
    58 // ----------------------------------------------------------------------------
       
    59 // IndexLength()
       
    60 //
       
    61 // ----------------------------------------------------------------------------
       
    62 //
    55 static TInt IndexLength( TInt aIndex )
    63 static TInt IndexLength( TInt aIndex )
    56     {
    64     {
    57     TInt length = 0;
    65     TInt length = 0;
    58 
    66 
    59     if ( aIndex < 0 )
    67     if ( aIndex < 0 )
    69     while ( aIndex != 0 );
    77     while ( aIndex != 0 );
    70 
    78 
    71     return length;
    79     return length;
    72     }
    80     }
    73 
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CreateEventStringL()
       
    84 //
       
    85 // ----------------------------------------------------------------------------
       
    86 //
    74 static HBufC* CreateEventStringL( const TDesC& aFrom, TInt aEventIndex )
    87 static HBufC* CreateEventStringL( const TDesC& aFrom, TInt aEventIndex )
    75     {
    88     {
    76     HBufC* buffer = NULL;
    89     HBufC* buffer = NULL;
    77 
    90 
    78     TInt bufferLength = aFrom.Length() -
    91     TInt bufferLength = aFrom.Length() -
    85     bufferPtr.Format( aFrom, aEventIndex );
    98     bufferPtr.Format( aFrom, aEventIndex );
    86 
    99 
    87     return buffer;
   100     return buffer;
    88     }
   101     }
    89 
   102 
    90 // ========== MEMBER FUNCTIONS ================================================
   103 // ======== MEMBER FUNCTIONS ========
    91 
   104 // ----------------------------------------------------------------------------
    92 CAiToolbarRenderer::CAiToolbarRenderer( MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar )
   105 // CAiToolbarRenderer::CAiToolbarRenderer()
       
   106 //
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 CAiToolbarRenderer::CAiToolbarRenderer( MAiFwEventHandler& aAiFwEventHandler, 
       
   110     CAknToolbar& aToolbar )
    93     : iToolbar( aToolbar ),
   111     : iToolbar( aToolbar ),
    94     iAiFwEventHandler( aAiFwEventHandler )
   112     iAiFwEventHandler( aAiFwEventHandler )
    95 
       
    96     {
   113     {
    97     // no implementation required
   114     // no implementation required
    98     }
   115     }
    99 
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // CAiToolbarRenderer::ConstructL()
       
   119 //
       
   120 // ----------------------------------------------------------------------------
       
   121 //
   100 void CAiToolbarRenderer::ConstructL( )
   122 void CAiToolbarRenderer::ConstructL( )
   101     {
   123     {
   102     iToolbarEnabled = EFalse;
   124     iToolbarEnabled = EFalse;
   103 
   125 
   104     TInt err = KErrNone;
   126     TInt err = KErrNone;
   117     else
   139     else
   118         {
   140         {
   119         iToolbar.SetToolbarObserver( this );
   141         iToolbar.SetToolbarObserver( this );
   120         iToolbar.SetToolbarVisibility( ETrue, EFalse );
   142         iToolbar.SetToolbarVisibility( ETrue, EFalse );
   121         }
   143         }
   122 
   144     }
   123     }
   145 
   124 
   146 // ----------------------------------------------------------------------------
   125 CAiToolbarRenderer* CAiToolbarRenderer::NewLC( MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar )
   147 // CAiToolbarRenderer::NewLC()
   126     {
   148 //
   127     CAiToolbarRenderer* self = new (ELeave) CAiToolbarRenderer( aAiFwEventHandler, aToolbar );
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 CAiToolbarRenderer* CAiToolbarRenderer::NewLC( 
       
   152     MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar )
       
   153     {
       
   154     CAiToolbarRenderer* self = 
       
   155         new ( ELeave ) CAiToolbarRenderer( aAiFwEventHandler, aToolbar );
   128     CleanupStack::PushL( self );
   156     CleanupStack::PushL( self );
   129     self->ConstructL( );
   157     self->ConstructL();
   130     return self;
   158     return self;
   131     }
   159     }
   132 
   160 
   133 CAiToolbarRenderer* CAiToolbarRenderer::NewL( MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar )
   161 // ----------------------------------------------------------------------------
   134     {
   162 // CAiToolbarRenderer::NewL()
   135     CAiToolbarRenderer* self = CAiToolbarRenderer::NewLC( aAiFwEventHandler, aToolbar );
   163 //
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 CAiToolbarRenderer* CAiToolbarRenderer::NewL( 
       
   167     MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar )
       
   168     {
       
   169     CAiToolbarRenderer* self = 
       
   170         CAiToolbarRenderer::NewLC( aAiFwEventHandler, aToolbar );
   136     CleanupStack::Pop(); // self
   171     CleanupStack::Pop(); // self
   137     return self;
   172     return self;
   138     }
   173     }
   139 
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CAiToolbarRenderer::~CAiToolbarRenderer()
       
   177 //
       
   178 // ----------------------------------------------------------------------------
       
   179 //
   140 CAiToolbarRenderer::~CAiToolbarRenderer()
   180 CAiToolbarRenderer::~CAiToolbarRenderer()
   141     {
   181     {
   142     // We don't want anymore events from toolbar
   182     // We don't want anymore events from toolbar
   143     iToolbar.SetToolbarObserver( NULL );
   183     iToolbar.SetToolbarObserver( NULL );
   144     iButtons.ResetAndDestroy();
   184     iButtons.ResetAndDestroy();
   145     }
   185     }
   146 
   186 
   147 void CAiToolbarRenderer::DynInitToolbarL( TInt /*aResourceId*/, CAknToolbar* /*aToolbar*/ )
   187 // ----------------------------------------------------------------------------
       
   188 // CAiToolbarRenderer::DynInitToolbarL()
       
   189 //
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 void CAiToolbarRenderer::DynInitToolbarL( TInt /*aResourceId*/, 
       
   193     CAknToolbar* /*aToolbar*/ )
   148     {
   194     {
   149     // do nothing
   195     // do nothing
   150     }
   196     }
   151 
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CAiToolbarRenderer::OfferToolbarEventL()
       
   200 //
       
   201 // ----------------------------------------------------------------------------
       
   202 //
   152 void CAiToolbarRenderer::OfferToolbarEventL( TInt aCommand )
   203 void CAiToolbarRenderer::OfferToolbarEventL( TInt aCommand )
   153     {
   204     {
   154     TInt modifiers = iToolbar.EventModifiers();
   205     TInt modifiers = iToolbar.EventModifiers();
   155 
   206 
   156 
       
   157     if ( aCommand >= 0 && aCommand < iButtons.Count())
   207     if ( aCommand >= 0 && aCommand < iButtons.Count())
   158         {
   208         {
   159         CAiToolbarButton* button = iButtons[aCommand];
   209         CAiToolbarButton* button = iButtons[aCommand];
       
   210         
   160         if ( button )
   211         if ( button )
   161             {
   212             {
   162 
       
   163             HBufC *event = NULL;
   213             HBufC *event = NULL;
       
   214             
   164             if ( modifiers == CAknToolbar::ELongPress )
   215             if ( modifiers == CAknToolbar::ELongPress )
   165                 {
   216                 {
   166                 event = CreateEventStringL( KOpenAppByIndexAlternate, button->ShortcutId() );
   217                 event = CreateEventStringL( 
       
   218                     KOpenAppByIndexAlternate, button->ShortcutId() );
       
   219                 
   167                 CleanupStack::PushL( event );
   220                 CleanupStack::PushL( event );
   168                 }
   221                 }
   169             else
   222             else
   170                 {
   223                 {
   171                 event = CreateEventStringL( KOpenAppByIndex, button->ShortcutId() );
   224                 event = CreateEventStringL( 
       
   225                     KOpenAppByIndex, button->ShortcutId() );
       
   226                 
   172                 CleanupStack::PushL( event );
   227                 CleanupStack::PushL( event );
   173                 }
   228                 }
       
   229             
   174             iAiFwEventHandler.HandlePluginEvent( *event );
   230             iAiFwEventHandler.HandlePluginEvent( *event );
   175             CleanupStack::PopAndDestroy( event );
   231             CleanupStack::PopAndDestroy( event );
   176             }
   232             }
   177         }
   233         }
   178     }
   234     }
   179 
   235 
   180 void CAiToolbarRenderer::DoPublishL( MAiPropertyExtension& aPlugin,
   236 // ----------------------------------------------------------------------------
   181                                      TInt aContent,
   237 // CAiToolbarRenderer::DoPublishL()
   182                                      const TDesC16& aText,
   238 //
   183                                      TInt aIndex )
   239 // ----------------------------------------------------------------------------
   184     {
   240 //
       
   241 void CAiToolbarRenderer::DoPublishL( CHsContentPublisher& aPlugin,
       
   242     TInt aContent, const TDesC16& aText, TInt aIndex )                                                                        
       
   243     {
       
   244     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
       
   245     
   185     // Only interested on certain publish events
   246     // Only interested on certain publish events
   186     if (  aPlugin.PublisherInfoL()->iUid == KShortcutPluginUid &&
   247     if ( info.Uid() == KShortcutPluginUid &&
   187           aContent == EAiScutContentShortcutToolbarCaption &&
   248           aContent == EAiScutContentShortcutToolbarCaption &&
   188         ( aIndex == EAiScutToolbarFirst ||
   249         ( aIndex == EAiScutToolbarFirst ||
   189           aIndex == EAiScutToolbarSecond ||
   250           aIndex == EAiScutToolbarSecond ||
   190           aIndex == EAiScutToolbarThird )
   251           aIndex == EAiScutToolbarThird )
   191         )
   252         )
   197             iCommitted = EFalse;
   258             iCommitted = EFalse;
   198             }
   259             }
   199         }
   260         }
   200     }
   261     }
   201 
   262 
   202 void CAiToolbarRenderer::DoPublishL( MAiPropertyExtension& aPlugin,
   263 // ----------------------------------------------------------------------------
   203                                      TInt aContent,
   264 // CAiToolbarRenderer::DoPublishL()
   204                                      const TDesC8& aBuf,
   265 //
   205                                      TInt aIndex )
   266 // ----------------------------------------------------------------------------
   206     {
   267 //
       
   268 void CAiToolbarRenderer::DoPublishL( CHsContentPublisher& aPlugin,
       
   269     TInt aContent, const TDesC8& aBuf, TInt aIndex )
       
   270     {
       
   271     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
       
   272     
   207     // Only interested on certain publish events
   273     // Only interested on certain publish events
   208     if (  aPlugin.PublisherInfoL()->iUid == KShortcutPluginUid &&
   274     if ( info.Uid() == KShortcutPluginUid &&
   209           aContent == EAiScutContentShortcutToolbarIcon &&
   275           aContent == EAiScutContentShortcutToolbarIcon &&
   210         ( aIndex == EAiScutToolbarFirst ||
   276         ( aIndex == EAiScutToolbarFirst ||
   211           aIndex == EAiScutToolbarSecond ||
   277           aIndex == EAiScutToolbarSecond ||
   212           aIndex == EAiScutToolbarThird )
   278           aIndex == EAiScutToolbarThird )
   213         )
   279         )
   237         // We have received stuff we cannot publish.
   303         // We have received stuff we cannot publish.
   238         User::Leave(KErrNotFound);
   304         User::Leave(KErrNotFound);
   239         }
   305         }
   240     }
   306     }
   241 
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // CAiToolbarRenderer::ButtonL()
       
   310 //
       
   311 // ----------------------------------------------------------------------------
       
   312 //
   242 CAiToolbarButton* CAiToolbarRenderer::ButtonL( TInt aShortcutId )
   313 CAiToolbarButton* CAiToolbarRenderer::ButtonL( TInt aShortcutId )
   243     {
   314     {
   244     TInt index = KErrNotFound;
   315     TInt index = KErrNotFound;
   245     CAiToolbarButton *button = NULL;
   316     CAiToolbarButton *button = NULL;
   246     switch ( aShortcutId )
   317     switch ( aShortcutId )
   277         button->SetShortcutId( aShortcutId );
   348         button->SetShortcutId( aShortcutId );
   278         }
   349         }
   279     return button;
   350     return button;
   280     }
   351     }
   281 
   352 
   282 
   353 // ----------------------------------------------------------------------------
       
   354 // CAiToolbarRenderer::TransactionCommittedL()
       
   355 //
       
   356 // ----------------------------------------------------------------------------
       
   357 //
   283 void CAiToolbarRenderer::TransactionCommittedL()
   358 void CAiToolbarRenderer::TransactionCommittedL()
   284     {
   359     {
   285     if ( !iCommitted )
   360     if ( !iCommitted )
   286         {
   361         {
   287         for(TInt i = 0; i < iButtons.Count(); i++)
   362         for ( TInt i = 0; i < iButtons.Count(); i++ )
   288             {
   363             {
   289             CAiToolbarButton *button = iButtons[i];
   364             CAiToolbarButton *button = iButtons[i];
   290             if ( button && button->Icon())
   365             if ( button && button->Icon())
   291                 {
   366                 {
   292                 // remove the old button
   367                 // remove the old button
   298             }
   373             }
   299          iCommitted = ETrue;
   374          iCommitted = ETrue;
   300         }
   375         }
   301     }
   376     }
   302 
   377 
   303 
       
   304 // End of File.
   378 // End of File.