tstaskmonitor/backstepping/src/tsbackstepping.cpp
changeset 103 b99b84bcd2d1
parent 83 156f692b1687
equal deleted inserted replaced
83:156f692b1687 103:b99b84bcd2d1
    25 #include <startupdomainpskeys.h>
    25 #include <startupdomainpskeys.h>
    26 
    26 
    27 #include "tsbackstepping.h"
    27 #include "tsbackstepping.h"
    28 
    28 
    29 const TUid KHSUid = {0x20022f35};
    29 const TUid KHSUid = {0x20022f35};
    30 const int KOrdinalPositionNoZOrder(-1);
       
    31 
    30 
    32 
    31 
    33 /** 
    32 /** 
    34  *  CTsBackstepping::NewL
    33  *  CTsBackstepping::NewL
    35  *  two phase constructor
    34  *  two phase constructor
    36  */
    35  */
    37 EXPORT_C CTsBackstepping* CTsBackstepping::NewL(RWsSession &session)
    36 EXPORT_C CTsBackstepping* CTsBackstepping::NewL(MTsWindowGroupsMonitor &monitor)
    38   {
    37   {
    39   RDebug::Print(_L("CTsBackstepping::NewL"));
    38   RDebug::Print(_L("CTsBackstepping::NewL"));
    40   CTsBackstepping* self = CTsBackstepping::NewLC(session);
    39   CTsBackstepping* self = CTsBackstepping::NewLC(monitor);
    41   CleanupStack::Pop(self);
    40   CleanupStack::Pop(self);
    42   return self;
    41   return self;
    43   }
    42   }
    44 
    43 
    45 /** 
    44 /** 
    46  *  CTsBackstepping::NewLC
    45  *  CTsBackstepping::NewLC
    47  *  two phase constructor
    46  *  two phase constructor
    48  */
    47  */
    49 EXPORT_C CTsBackstepping* CTsBackstepping::NewLC(RWsSession &session)
    48 EXPORT_C CTsBackstepping* CTsBackstepping::NewLC(MTsWindowGroupsMonitor &monitor)
    50 { 
    49 { 
    51   CTsBackstepping* self = new (ELeave) CTsBackstepping(session);
    50   CTsBackstepping* self = new (ELeave) CTsBackstepping(monitor);
    52   CleanupStack::PushL(self);
    51   CleanupStack::PushL(self);
    53   self->ConstructL();
    52   self->ConstructL();
    54   return self;
    53   return self;
    55 }
    54 }
    56 
    55 
    57 /** 
    56 /** 
    58  * CTsBackstepping::CTsBackstepping
    57  * CTsBackstepping::CTsBackstepping
    59  * constructor
    58  * constructor
    60  */
    59  */
    61 CTsBackstepping::CTsBackstepping(RWsSession &session)
    60 CTsBackstepping::CTsBackstepping(MTsWindowGroupsMonitor &monitor)
    62 :CActive(EPriorityStandard),
    61 :
    63 mWsSession(session)
    62 CTsWindowGroupsObserver(monitor)
    64 {
    63 {
    65     CActiveScheduler::Add(this);
       
    66 }
    64 }
    67 
    65 
    68 
    66 
    69 /** 
    67 /** 
    70  *  CTsBackstepping::~CTsBackstepping
    68  *  CTsBackstepping::~CTsBackstepping
    71  *  deconstructor
    69  *  deconstructor
    72  */
    70  */
    73 EXPORT_C CTsBackstepping::~CTsBackstepping()
    71 EXPORT_C CTsBackstepping::~CTsBackstepping()
    74 {
    72 {
    75     RDebug::Print(_L("CTsBackstepping::~CTsBackstepping"));
       
    76     // Cancel AO
       
    77     Cancel();
       
    78     // Close opened session
       
    79     mWg.Close();
       
    80     
       
    81 }
    73 }
    82 
    74 
    83 /** 
    75 /** 
    84  *  CTsBackstepping::ConstructL
    76  *  CTsBackstepping::ConstructL
    85  *  two phase constructor
    77  *  two phase constructor
    86  */
    78  */
    87 void CTsBackstepping::ConstructL ()
    79 void CTsBackstepping::ConstructL ()
    88 {
    80 {
    89     RDebug::Print(_L("CTsBackstepping::ConstructL"));
    81     RDebug::Print(_L("CTsBackstepping::ConstructL"));
    90     // Initial window group
    82     BaseConstructL();
    91     mWg = RWindowGroup (mWsSession);
       
    92     User::LeaveIfError (mWg.Construct ((TUint32)&mWg, EFalse));
       
    93     mWg.SetOrdinalPosition (KOrdinalPositionNoZOrder);
       
    94     mWg.EnableReceiptOfFocus (EFalse);
       
    95 
       
    96     // Hide window
       
    97     CApaWindowGroupName* wn = CApaWindowGroupName::NewLC (mWsSession);
       
    98     wn->SetHidden (ETrue);
       
    99     wn->SetWindowGroupName (mWg);
       
   100     CleanupStack::PopAndDestroy (wn);
       
   101 
       
   102     // Window group change event
       
   103     User::LeaveIfError (mWg.EnableGroupListChangeEvents());
       
   104     
       
   105     TRAP_IGNORE(AnalyseWindowStackL());//not critical operation
       
   106     Subscribe();
       
   107 }
       
   108 
       
   109 /** 
       
   110  *  CTsBackstepping::RunL
       
   111  *  called for handling events from window server
       
   112  */
       
   113 void CTsBackstepping::RunL()
       
   114 {
       
   115     User::LeaveIfError(iStatus.Int());
       
   116     TWsEvent wsEvent;
       
   117     mWsSession.GetEvent (wsEvent);
       
   118     if (EEventWindowGroupListChanged == wsEvent.Type()) {
       
   119         RDebug::Print(_L("CTsBackstepping::RunL : EEventWindowGroupListChanged"));
       
   120         AnalyseWindowStackL ();
       
   121     }
       
   122     Subscribe();
       
   123 }
       
   124 
       
   125 /** 
       
   126  *  CTsBackstepping::DoCancel
       
   127  *  Handling RunL errors.
       
   128  */
       
   129 TInt CTsBackstepping::RunError(TInt error)
       
   130 {
       
   131     if (!IsActive() && KErrCancel != error) {
       
   132         Subscribe();
       
   133     }
       
   134     return KErrNone;
       
   135 }
       
   136 
       
   137 /** 
       
   138  *  CTsBackstepping::DoCancel
       
   139  *  Stopping active object
       
   140  */
       
   141 void CTsBackstepping::DoCancel ()
       
   142 {
       
   143     if (IsActive()) {
       
   144         mWsSession.EventReadyCancel();
       
   145     }
       
   146 }
       
   147 
       
   148 /** 
       
   149  *  CTsBackstepping::ActivateListeningL
       
   150  *  Starts listening to Window session events
       
   151  */
       
   152 void CTsBackstepping::Subscribe()
       
   153 {
       
   154     RDebug::Print(_L("CTsBackstepping::Subscribe"));
       
   155     // and start listening
       
   156     iStatus = KRequestPending;
       
   157     mWsSession.EventReady( &iStatus );
       
   158     SetActive();
       
   159 }
    83 }
   160 
    84 
   161 /** 
    85 /** 
   162  * CTsBackstepping::AnalyseWindowStackL
    86  * CTsBackstepping::AnalyseWindowStackL
   163  * Analyzes window stack and move homescreen to proper position
    87  * Analyzes window stack and move homescreen to proper position
   164  */
    88  */
   165 void CTsBackstepping::AnalyseWindowStackL ()
    89 void CTsBackstepping::HandleWindowGroupChanged(MTsResourceManager &resource, const TArray<RWsSession::TWindowGroupChainInfo> &windowGroups)
       
    90 {
       
    91     TRAP_IGNORE(HandleWindowGroupChangedL(resource, windowGroups));
       
    92 }
       
    93 
       
    94 /** 
       
    95  * CTsBackstepping::AnalyseWindowStackL
       
    96  * Analyzes window stack and move homescreen to proper position
       
    97  */
       
    98 void CTsBackstepping::HandleWindowGroupChangedL(MTsResourceManager &resource,
       
    99                                                 const TArray<RWsSession::TWindowGroupChainInfo> &windowGroups)
   166 {  
   100 {  
   167     RDebug::Print(_L("CTsBackstepping::GetWindowCaption"));
   101     RDebug::Print(_L("CTsBackstepping::GetWindowCaption"));
   168     
   102     
   169     RArray<RWsSession::TWindowGroupChainInfo> windowGroups;
   103     CApaWindowGroupName *windowGroupName = CApaWindowGroupName::NewLC(resource.WsSession());
   170     CleanupClosePushL(windowGroups);
       
   171     
       
   172     CApaWindowGroupName *windowGroupName = CApaWindowGroupName::NewLC(mWsSession );
       
   173     //update window group list
       
   174     mWsSession.WindowGroupList( &windowGroups );
       
   175     
   104     
   176     TInt count(windowGroups.Count());
   105     TInt count(windowGroups.Count());
   177     TInt pos(0);
   106     TInt pos(0);
   178     TInt whereToJump(1);
   107     TInt whereToJump(1);
   179     for (TInt i=0; i<count; i++) {//iterate through list and give debug info
   108     for (TInt i=0; i<count; i++) {//iterate through list and give debug info
   180         const RWsSession::TWindowGroupChainInfo& info = windowGroups[i];
   109         windowGroupName->ConstructFromWgIdL(windowGroups[i].iId);
   181         windowGroupName->ConstructFromWgIdL(info.iId);
       
   182         if (windowGroupName->AppUid() != TUid::Null()) {
   110         if (windowGroupName->AppUid() != TUid::Null()) {
   183             // find the window group id and check that it has no parent
   111             // find the window group id and check that it has no parent
   184             if ( info.iParentId <= 0 ) {
   112             if ( windowGroups[i].iParentId <= 0 ) {
   185                 RDebug::Print( _L("CTsBackstepping::GetWindowCaption wgid:%d is standalone view"), info.iId);
   113                 RDebug::Print( _L("CTsBackstepping::GetWindowCaption wgid:%d is standalone view"), windowGroups[i].iId);
   186                 //check if it is homescreen 
   114                 //check if it is homescreen 
   187                 if (windowGroupName->AppUid() == KHSUid) {
   115                 if (windowGroupName->AppUid() == KHSUid) {
   188                     RDebug::Print(_L("CTsBackstepping::GetWindowCaption Homescreen position = %d ; list:%d/%d"), pos, i, count);
   116                     RDebug::Print(_L("CTsBackstepping::GetWindowCaption Homescreen position = %d ; list:%d/%d"), pos, i, count);
   189                     if (pos <= 1) {// HS is in foreground or second in line - do nothing 
   117                     if (pos <= 1) {// HS is in foreground or second in line - do nothing 
   190                         RDebug::Print(_L("CTsBackstepping::nothing to be done - it will stop checking here"));
   118                         RDebug::Print(_L("CTsBackstepping::nothing to be done - it will stop checking here"));
   191                     } else {//we should move homescreen to be second (ommit embeded views) from top
   119                     } else {//we should move homescreen to be second (ommit embeded views) from top
   192                         RDebug::Print(_L("CTsBackstepping::moving homescreen to be second from top"));
   120                         RDebug::Print(_L("CTsBackstepping::moving homescreen to be second from top"));
   193                         RDebug::Print(_L("CTsBackstepping::whereToJump = %d"), whereToJump);
   121                         RDebug::Print(_L("CTsBackstepping::whereToJump = %d"), whereToJump);
   194                         mWsSession.SetWindowGroupOrdinalPosition(info.iId, whereToJump);
   122                         resource.WsSession().SetWindowGroupOrdinalPosition(windowGroups[i].iId, whereToJump);
   195                     }
   123                     }
   196                     // and break
   124                     // and break
   197                     break;
   125                     break;
   198                 }
   126                 }
   199                 pos++;
   127                 pos++;
   200             } else {
   128             } else {
   201                 // only embeded items for first standalone launch should be counted
   129                 // only embeded items for first standalone launch should be counted
   202                 if (!pos) {
   130                 if (!pos) {
   203                     ++whereToJump;
   131                     ++whereToJump;
   204                 }
   132                 }
   205                 RDebug::Print(_L("CTsBackstepping::GetWindowCaption wgid:%d is embedded view"), info.iId);
   133                 RDebug::Print(_L("CTsBackstepping::GetWindowCaption wgid:%d is embedded view"), windowGroups[i].iId);
   206             }
   134             }
   207         }
   135         }
   208     }
   136     }
   209     CleanupStack::PopAndDestroy(windowGroupName);
   137     CleanupStack::PopAndDestroy(windowGroupName);
   210     CleanupStack::PopAndDestroy(&windowGroups);
       
   211 }
   138 }
   212 
   139 
   213 // end of file
   140 // end of file