photosgallery/viewframework/views/viewbase/src/glxtoolbarcontroller.cpp
branchRCL_3
changeset 60 5b3385a43d68
child 68 5b238bc8ffb6
equal deleted inserted replaced
59:8e5f6eea9c9f 60:5b3385a43d68
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Media item list observer interface 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxtoolbarcontroller.h"
       
    22 #include <aknbutton.h>
       
    23 #include <akntoolbar.h>                     // For Toolbar
       
    24 #include <glxcommandhandlers.hrh>           // For Command ids
       
    25 #include <glxtracer.h>                         // For Logs
       
    26 #include <glxlog.h>                         // For Logs
       
    27 #include <mglxmedialist.h>
       
    28 
       
    29 #include <glxnavigationalstate.h>
       
    30 #include <mpxcollectionpath.h>
       
    31 #include <glxcollectionpluginimageviewer.hrh>
       
    32 #include <centralrepository.h>              // for checking the ShareOnline version
       
    33 #include <glxuiutility.h>
       
    34 
       
    35 // CONSTANTS AND DEFINITIONS
       
    36 namespace
       
    37     {
       
    38     // ShareOnline application UID    
       
    39     const TUid KShareOnlineUid = { 0x2002CC1F };
       
    40     // Shareonline Application version
       
    41     const TUint32 KShareApplicationVersion = 0x1010020;
       
    42     // Buffer to maintain the ShareOnline version number in use
       
    43     const TInt KPhotosShareOnlineVersionBufLen = 12;
       
    44     // Minimum version required for OneClickUpload to work
       
    45     const TVersion KShareOnlineMinimumVersion( 5, 0, 0 );
       
    46     }
       
    47 
       
    48 //----------------------------------------------------------------------------------
       
    49 // NewL
       
    50 //----------------------------------------------------------------------------------
       
    51 //
       
    52 CGlxToolbarController* CGlxToolbarController::NewL()
       
    53     {
       
    54     TRACER("CGlxToolbarController::NewL");
       
    55     
       
    56     CGlxToolbarController *self = new( ELeave ) CGlxToolbarController ();
       
    57     return self;
       
    58     }
       
    59 
       
    60 //----------------------------------------------------------------------------------
       
    61 // Default Constructor
       
    62 //----------------------------------------------------------------------------------
       
    63 //
       
    64 CGlxToolbarController::CGlxToolbarController( )
       
    65     {
       
    66     TRACER("CGlxToolbarController::Default constructor");
       
    67     
       
    68     }
       
    69     
       
    70 //----------------------------------------------------------------------------------
       
    71 // AddToObserver
       
    72 //----------------------------------------------------------------------------------
       
    73 //
       
    74 void CGlxToolbarController::AddToObserverL (MGlxMediaList& aList, CAknToolbar* aToolbar)
       
    75     {
       
    76     TRACER("CGlxToolbarController::AddToObserverL");
       
    77 
       
    78     iToolbar = aToolbar;
       
    79     iAttributeAvailable = EFalse;
       
    80     aList.AddMediaListObserverL ( this );
       
    81     }
       
    82 
       
    83 //----------------------------------------------------------------------------------
       
    84 // RemoveFromObserver 
       
    85 //----------------------------------------------------------------------------------
       
    86 //
       
    87 void CGlxToolbarController::RemoveFromObserver (MGlxMediaList& aList)
       
    88     {
       
    89     TRACER("CGlxToolbarController::RemoveFromObserver");
       
    90     
       
    91     if( aList.SelectionCount()<= 0 )
       
    92         {
       
    93         EnableLatch( EGlxCmdStartMultipleMarking, EFalse );
       
    94         }
       
    95 
       
    96     aList.RemoveMediaListObserver ( this );
       
    97     }
       
    98 
       
    99 //----------------------------------------------------------------------------
       
   100 // HandleItemAddedL
       
   101 //----------------------------------------------------------------------------
       
   102 //
       
   103 void CGlxToolbarController::HandleItemAddedL(TInt /*aStartIndex*/, TInt /*aEndIndex*/, 
       
   104         MGlxMediaList* /*aList*/)
       
   105     {
       
   106     TRACER("CGlxToolbarController::HandleItemAddedL");
       
   107     
       
   108     }
       
   109 
       
   110 //----------------------------------------------------------------------------
       
   111 // HandleMediaL
       
   112 //----------------------------------------------------------------------------
       
   113 //
       
   114 void CGlxToolbarController::HandleMediaL(TInt /*aListIndex*/, MGlxMediaList* /*aList*/)
       
   115     {
       
   116     TRACER("CGlxToolbarController::HandleMediaL");
       
   117     
       
   118     }
       
   119 
       
   120 //----------------------------------------------------------------------------
       
   121 // HandleItemRemovedL
       
   122 //----------------------------------------------------------------------------
       
   123 //
       
   124 void CGlxToolbarController::HandleItemRemovedL(TInt /*aStartIndex*/, 
       
   125         TInt /*aEndIndex*/, MGlxMediaList* aList)
       
   126     {
       
   127     TRACER("CGlxToolbarController::HandleItemRemovedL");
       
   128     
       
   129     if( aList->Count() <= 0 )
       
   130         {
       
   131          SetToolbarItemsDimmed(ETrue);
       
   132         }
       
   133     }
       
   134 
       
   135 //----------------------------------------------------------------------------
       
   136 // HandleItemModifiedL
       
   137 //----------------------------------------------------------------------------
       
   138 //
       
   139 void CGlxToolbarController::HandleItemModifiedL(const RArray<TInt>& /*aItemIndexes*/, 
       
   140         MGlxMediaList* /*aList*/)
       
   141     {
       
   142     TRACER("CGlxToolbarController::HandleItemModifiedL");
       
   143     
       
   144     }
       
   145 
       
   146 //----------------------------------------------------------------------------
       
   147 // HandleAttributesAvailableL
       
   148 //----------------------------------------------------------------------------
       
   149 //
       
   150 void CGlxToolbarController::HandleAttributesAvailableL(TInt aItemIndex, 
       
   151         const RArray<TMPXAttribute>& /*aAttributes*/, 
       
   152         MGlxMediaList* aList)
       
   153     {
       
   154     TRACER("CGlxToolbarController::HandleAttributesAvailableL");
       
   155     
       
   156     if( aItemIndex == aList->FocusIndex() )
       
   157         {        
       
   158         iAttributeAvailable = ETrue;
       
   159         SetStatusL(aList);
       
   160         }
       
   161     }
       
   162 
       
   163 //----------------------------------------------------------------------------
       
   164 // HandleFocusChangedL
       
   165 //----------------------------------------------------------------------------
       
   166 //
       
   167 void CGlxToolbarController::HandleFocusChangedL(
       
   168         NGlxListDefs::TFocusChangeType /*aType*/, TInt /*aNewIndex*/, 
       
   169         TInt /*aOldIndex*/, MGlxMediaList* aList)
       
   170     {  
       
   171     TRACER("CGlxToolbarController::HandleFocusChangedL");
       
   172     if (aList->Count() <= 0)
       
   173         {
       
   174         SetToolbarItemsDimmed(ETrue);
       
   175         }
       
   176     }
       
   177 
       
   178 //----------------------------------------------------------------------------
       
   179 // HandleItemSelectedL
       
   180 //----------------------------------------------------------------------------
       
   181 //
       
   182 void CGlxToolbarController::HandleItemSelectedL(TInt /*aIndex*/, TBool /*aSelected*/, 
       
   183         MGlxMediaList* aList)
       
   184     {
       
   185     TRACER("CGlxToolbarController::HandleItemSelectedL");
       
   186     GLX_DEBUG2("CGlxToolbarController::HandleItemSelectedL()"
       
   187             " aList->SelectionCount()=%d", aList->SelectionCount());
       
   188 
       
   189     // If atleast 1 item is marked, or if Mark All is called, then Latch the mark button.
       
   190     if ((aList->SelectionCount() == 1) || (aList->SelectionCount()
       
   191             == aList->Count()))
       
   192         {
       
   193         EnableLatch(EGlxCmdStartMultipleMarking, ETrue);
       
   194         }
       
   195     }
       
   196 
       
   197 //----------------------------------------------------------------------------
       
   198 // HandleMessageL
       
   199 //----------------------------------------------------------------------------
       
   200 //
       
   201 void CGlxToolbarController::HandleMessageL(const CMPXMessage& /*aMessage*/, 
       
   202         MGlxMediaList* /*aList*/)
       
   203     {
       
   204     TRACER("CGlxToolbarController::HandleMessageL");
       
   205     
       
   206     }
       
   207 
       
   208 //----------------------------------------------------------------------------
       
   209 // Destructor
       
   210 //----------------------------------------------------------------------------
       
   211 //
       
   212 CGlxToolbarController::~CGlxToolbarController()
       
   213     {
       
   214     TRACER("CGlxToolbarController Destructor");
       
   215     
       
   216     }
       
   217 
       
   218 //----------------------------------------------------------------------------
       
   219 // SetStatusOnViewActivationL
       
   220 //----------------------------------------------------------------------------
       
   221 //
       
   222 void CGlxToolbarController::SetStatusOnViewActivationL( MGlxMediaList* aList )
       
   223      {
       
   224     TRACER("CGlxToolbarController::SetStatusOnViewActivationL");
       
   225     TRAPD(err, CheckShareonlineVersionL());
       
   226     GLX_LOG_INFO2("CGlxToolbarController::SetStatusOnViewActivationL(%d),"
       
   227             " err(%d)", aList->Count(), err);
       
   228     if (iToolbar->IsDimmed())
       
   229     	{
       
   230         iToolbar->SetDimmed(EFalse);
       
   231     	}
       
   232     CGlxNavigationalState* navigationalState =
       
   233             CGlxNavigationalState::InstanceL();
       
   234     CleanupClosePushL(*navigationalState);
       
   235     if (navigationalState->ViewingMode() == NGlxNavigationalState::EBrowse)
       
   236         {
       
   237         if (err == KErrNone)
       
   238             {
       
   239             CAknButton* sendButton =
       
   240                     static_cast<CAknButton*> (iToolbar->ControlOrNull(
       
   241                             EGlxCmdSend));
       
   242             if (sendButton)
       
   243                 {
       
   244                 iToolbar->RemoveItem(EGlxCmdSend);
       
   245                 }
       
   246             }
       
   247         else
       
   248             {
       
   249             CAknButton* uploadButton =
       
   250                     static_cast<CAknButton*> (iToolbar->ControlOrNull(
       
   251                             EGlxCmdUpload));
       
   252             if (uploadButton)
       
   253                 {
       
   254                 iToolbar->RemoveItem(EGlxCmdUpload);
       
   255                 }
       
   256             }
       
   257         iToolbar->SetItemDimmed(EGlxCmdSlideshowPlay, EFalse, ETrue);
       
   258         iToolbar->SetItemDimmed(EGlxCmdStartMultipleMarking, EFalse, ETrue);
       
   259         TBool dimmed = aList->SelectionCount() ? EFalse : ETrue;
       
   260         iToolbar->SetItemDimmed(EGlxCmdSend, dimmed, ETrue);
       
   261         iToolbar->SetItemDimmed(EGlxCmdUpload, dimmed, ETrue);
       
   262         }
       
   263     else if (navigationalState->ViewingMode() == NGlxNavigationalState::EView)
       
   264         {
       
   265         if (err == KErrNone)
       
   266             {
       
   267             CAknButton* slideshowButton =
       
   268                     static_cast<CAknButton*> (iToolbar->ControlOrNull(
       
   269                             EGlxCmdSlideshowPlay));
       
   270             if (slideshowButton)
       
   271                 {
       
   272                 iToolbar->RemoveItem(EGlxCmdSlideshowPlay);
       
   273                 }
       
   274             }
       
   275         else
       
   276             {
       
   277             CAknButton* uploadButton =
       
   278                     static_cast<CAknButton*> (iToolbar->ControlOrNull(
       
   279                             EGlxCmdUpload));
       
   280             if (uploadButton)
       
   281                 {
       
   282                 iToolbar->RemoveItem(EGlxCmdUpload);
       
   283                 }
       
   284             }
       
   285         SetToolbarItemsDimmed(EFalse);
       
   286         }
       
   287     CleanupStack::PopAndDestroy(navigationalState);
       
   288 
       
   289     // When going back from fullscreen to grid, when the attributes are already 
       
   290     // available in the cache, there is no HandleAttributeAvailable callback. Hence,
       
   291     // checking for medialist count.
       
   292     if (!iAttributeAvailable)
       
   293         {
       
   294         SetStatusL(aList);
       
   295         }
       
   296     }
       
   297 
       
   298 //----------------------------------------------------------------------------
       
   299 //SetStatusL
       
   300 //----------------------------------------------------------------------------
       
   301 //
       
   302 void CGlxToolbarController::SetStatusL(MGlxMediaList* aList)
       
   303 	{
       
   304     TRACER("CGlxToolbarController::SetStatusL");
       
   305 
       
   306 	GLX_LOG_INFO1("CGlxToolbarController::SetStatusL(%d)", aList->Count());
       
   307     // When going back from fullscreen to grid, when the attributes are already 
       
   308     // available in the cache, there is no HandleAttributeAvailable callback. Hence,
       
   309     // checking for medialist count and backward navigation
       
   310 	CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   311 	CleanupClosePushL(*uiUtility);
       
   312 	if (aList->Count() <= 0 && (uiUtility->ViewNavigationDirection()
       
   313 			== EGlxNavigationBackwards))
       
   314 		{
       
   315 		SetToolbarItemsDimmed(ETrue);
       
   316 		}
       
   317 	else if (KErrNotFound != aList->FocusIndex())
       
   318 		{
       
   319 		CGlxNavigationalState* navigationalState =
       
   320 				CGlxNavigationalState::InstanceL();
       
   321 		CleanupClosePushL(*navigationalState);
       
   322 		if (navigationalState->ViewingMode() == NGlxNavigationalState::EView)
       
   323 			{
       
   324 			SetToolbarItemsDimmed(EFalse);
       
   325 			}
       
   326 		else if (navigationalState->ViewingMode()
       
   327 				== NGlxNavigationalState::EBrowse)
       
   328 			{
       
   329 			TBool dimmed = aList->SelectionCount() ? EFalse : ETrue;
       
   330 			iToolbar->SetItemDimmed(EGlxCmdSend, dimmed, ETrue);
       
   331 			iToolbar->SetItemDimmed(EGlxCmdUpload, dimmed, ETrue);
       
   332 			}
       
   333 		CleanupStack::PopAndDestroy(navigationalState);
       
   334 		}
       
   335 	CleanupStack::PopAndDestroy(uiUtility);
       
   336 	}
       
   337 
       
   338 //----------------------------------------------------------------------------
       
   339 // EnableLatch
       
   340 //----------------------------------------------------------------------------
       
   341 //
       
   342 void CGlxToolbarController::EnableLatch( TInt aCommandId, TInt aLatched )
       
   343     {
       
   344     TRACER("CGlxToolbarController::EnableLatch()");
       
   345     GLX_DEBUG2("CGlxToolbarController::EnableLatch() aLatched=%d", aLatched);
       
   346 
       
   347     CAknButton* toolbarButton =
       
   348             static_cast<CAknButton*> (iToolbar->ControlOrNull(aCommandId));
       
   349 
       
   350     if( toolbarButton )
       
   351         {
       
   352         toolbarButton->SetCurrentState(aLatched, ETrue);
       
   353         }
       
   354     }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // HandlePopulatedL
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void CGlxToolbarController::HandlePopulatedL( MGlxMediaList* aList )
       
   361     {
       
   362     TRACER("CGlxToolbarController::HandlePopulatedL()");
       
   363     if (aList->Count() <= 0)
       
   364         {
       
   365         SetToolbarItemsDimmed(ETrue);
       
   366         }
       
   367     if (!iToolbar->IsVisible())
       
   368         {
       
   369         GLX_DEBUG1("CGlxToolbarController::HandlePopulatedL()"
       
   370                 " - SetToolbarVisibility(ETrue)");       
       
   371         iToolbar->SetToolbarVisibility(ETrue);
       
   372         } 
       
   373     }
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // SetToolbarItemsDimmed
       
   377 // ----------------------------------------------------------------------------
       
   378 //
       
   379 void CGlxToolbarController::SetToolbarItemsDimmed(TBool aDimmed)
       
   380     {
       
   381     TRACER("CGlxToolbarController::SetToolbarItemsDimmed()");
       
   382     if (iToolbar)
       
   383         {
       
   384         iToolbar->SetItemDimmed(EGlxCmdSlideshowPlay, aDimmed, ETrue);
       
   385         iToolbar->SetItemDimmed(EGlxCmdStartMultipleMarking, aDimmed, ETrue);
       
   386         iToolbar->SetItemDimmed(EGlxCmdSend, aDimmed, ETrue);
       
   387         iToolbar->SetItemDimmed(EGlxCmdUpload, aDimmed, ETrue);
       
   388         }
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // CheckShareonlineVersionL
       
   393 // ----------------------------------------------------------------------------
       
   394 //
       
   395 void CGlxToolbarController::CheckShareonlineVersionL()
       
   396     {
       
   397     TRACER("CGlxToolbarController::CheckShareonlineVersionL");
       
   398 
       
   399     CRepository* rep = CRepository::NewLC(KShareOnlineUid);
       
   400     //
       
   401     TBuf<KPhotosShareOnlineVersionBufLen> versionBuf;
       
   402     // Query the ShareOnline version in the build
       
   403     User::LeaveIfError(rep->Get(KShareApplicationVersion, versionBuf));
       
   404 
       
   405     // Initialize version to zero
       
   406     TVersion version(0, 0, 0);
       
   407     TLex lex(versionBuf);
       
   408     User::LeaveIfError(lex.Val(version.iMajor));
       
   409     if (lex.Get() != TChar('.'))
       
   410         {
       
   411         User::Leave(KErrCorrupt);
       
   412         }
       
   413     User::LeaveIfError(lex.Val(version.iMinor));
       
   414     if (lex.Get() != TChar('.'))
       
   415         {
       
   416         User::Leave(KErrCorrupt);
       
   417         }
       
   418     User::LeaveIfError(lex.Val(version.iBuild));
       
   419 
       
   420     // Compare version number and leave if the detected
       
   421     // version is less than KShareOnlineMinimumVersion.
       
   422     if (version.iMajor < KShareOnlineMinimumVersion.iMajor)
       
   423         {
       
   424         User::LeaveIfError(KErrNotSupported);
       
   425         }
       
   426     else if (version.iMajor == KShareOnlineMinimumVersion.iMajor)
       
   427         {
       
   428         if (version.iMinor < KShareOnlineMinimumVersion.iMinor)
       
   429             {
       
   430             User::LeaveIfError(KErrNotSupported);
       
   431             }
       
   432         else if (version.iMinor == KShareOnlineMinimumVersion.iMinor)
       
   433             {
       
   434             if (version.iBuild < KShareOnlineMinimumVersion.iBuild)
       
   435                 {
       
   436                 User::LeaveIfError(KErrNotSupported);
       
   437                 }
       
   438             else
       
   439                 {
       
   440                 // Version is supported, fall through
       
   441                 }
       
   442             }
       
   443         else
       
   444             {
       
   445             // Version is supported, fall through
       
   446             }
       
   447         }
       
   448     else
       
   449         {
       
   450         // Version is supported, fall through
       
   451         }
       
   452     CleanupStack::PopAndDestroy(rep);
       
   453     }
       
   454 
       
   455 //end of file
       
   456