calendarui/controller/src/calenactionui.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 45 b6db4fd4947b
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDES
    19 // INCLUDES
    20 #include <aknViewAppUi.h>
       
    21 #include <avkon.hrh>
       
    22 #include <aknnavi.h>
       
    23 #include <akntitle.h>
       
    24 #include <eikspane.h>
       
    25 #include <Calendar.rsg>
       
    26 #include <calencommonui.rsg>
       
    27 #include <calenservices.h>
       
    28 #include <calentoolbar.h>
       
    29 
       
    30 #include "calendarui_debug.h"
    20 #include "calendarui_debug.h"
    31 #include "calenactionui.h"
    21 #include "calenactionui.h"
    32 #include "calencontroller.h"
    22 #include "calencontroller.h"
    33 #include "calendeleteui.h"
    23 #include "calendeleteui.h"
    34 #include "caleneditui.h"
    24 #include "caleneditui.h"
    35 #include "calenlocationui.h"
       
    36 #include "calensettingsui.h"
       
    37 #include "calennotifier.h"
    25 #include "calennotifier.h"
    38 #include "calenmultipledbui.h"
    26 #include "calenservices.h"
    39 #include "calenattachmentui.h"
    27 #include "calensettingsview.h"
       
    28 #include "calenviewmanager.h"
       
    29 #include <hbmainwindow.h>
    40 
    30 
    41 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    42 // CCalenActionUi::NewL
    32 // CCalenActionUi::NewL
    43 // 1st phase of construction
    33 // 1st phase of construction
    44 // (other items were commented in a header).
    34 // (other items were commented in a header).
    91 CCalenActionUi::~CCalenActionUi()
    81 CCalenActionUi::~CCalenActionUi()
    92     {
    82     {
    93     TRACE_ENTRY_POINT;
    83     TRACE_ENTRY_POINT;
    94 
    84 
    95     delete iDeleteUi;
    85     delete iDeleteUi;
    96     delete iEditUi;
    86     delete iEditUi;   
    97     delete iLocationUi;
    87 
    98     delete iAttachmentUi;
       
    99     
       
   100     TRACE_EXIT_POINT;
    88     TRACE_EXIT_POINT;
   101     }
    89     }
   102 
    90 
   103 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
   104 // CCalenActionUi::GetCommandHandlerL
    92 // CCalenActionUi::GetCommandHandlerL
   107 //
    95 //
   108 MCalenCommandHandler* CCalenActionUi::GetCommandHandlerL( TInt aCommand )
    96 MCalenCommandHandler* CCalenActionUi::GetCommandHandlerL( TInt aCommand )
   109     {
    97     {
   110     MCalenCommandHandler* handler = NULL;
    98     MCalenCommandHandler* handler = NULL;
   111 
    99 
   112     if( aCommand >= ECalenEditCommandBase &&
   100     if ( aCommand >= ECalenEditCommandBase
   113         aCommand < ECalenDeleteCommandBase )
   101       && aCommand < ECalenDeleteCommandBase )
   114         {
       
   115         if(!iEditUi)
       
   116             {
       
   117             iEditUi = CCalenEditUi::NewL(iController);
       
   118             }
       
   119         handler = iEditUi;
       
   120         }
       
   121     else if( aCommand >= ECalenDeleteCommandBase &&
       
   122              aCommand < ECalenSettingsCommandBase )
       
   123         {
       
   124         if(!iDeleteUi)
       
   125             {
       
   126             iDeleteUi = CCalenDeleteUi::NewL( iController );
       
   127             }
       
   128         handler = iDeleteUi;
       
   129         }
       
   130     else if( aCommand >= ECalenSettingsCommandBase &&
       
   131              aCommand < ECalenMapCommandBase )
       
   132         {
       
   133         handler = this;
       
   134         }
       
   135     else if( aCommand >= ECalenMapCommandBase &&
       
   136              aCommand < ECalenAttachmentCommandBase )
       
   137         {
       
   138         if(!iLocationUi)
       
   139             {
       
   140             iLocationUi = CCalenLocationUi::NewL( iController );
       
   141             }
       
   142         handler = iLocationUi;
       
   143         }
       
   144     else if( aCommand >= ECalenAttachmentCommandBase && 
       
   145              aCommand < ECalenLastCommand )
       
   146         {
       
   147         if(!iAttachmentUi)
       
   148             {
       
   149             iAttachmentUi = CCalenAttachmentUi::NewL(iController);
       
   150             }
       
   151         handler = iAttachmentUi;
       
   152         }
       
   153 
       
   154     TRACE_EXIT_POINT;
       
   155     return handler;
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CCalenActionUi::HandleCommmandL
       
   160 // Handles Calendar commands. Delegates to appropriate action ui.
       
   161 // (other items were commented in a header).
       
   162 // ----------------------------------------------------------------------------
       
   163 //
       
   164 /*TBool CCalenActionUi::HandleActionUiCommandL( TInt aCommand )
       
   165     {
       
   166     TRACE_ENTRY_POINT;
       
   167 
       
   168     // Lazy initialisation for action uis.
       
   169     TBool handled( EFalse );
       
   170 
       
   171     if( aCommand >= ECalenEditCommandBase && aCommand < ECalenLastCommand )
       
   172         {
   102         {
   173         if( !iEditUi )
   103         if( !iEditUi )
   174             {
   104             {
   175             iEditUi = CCalenEditUi::NewL( iController );
   105             iEditUi = CCalenEditUi::NewL( iController );
   176             }
   106             }
   177         handled = iEditUi->HandleActionUiCommandL( aCommand );
   107         handler = iEditUi;
   178 
   108         }
   179         if( !handled )
   109     else if ( aCommand >= ECalenDeleteCommandBase
       
   110       && aCommand < ECalenSettingsCommandBase )
       
   111         {
       
   112         if( !iDeleteUi )
   180             {
   113             {
   181             if( !iDeleteUi )
   114             iDeleteUi = CalenDeleteUi::NewL( iController );
   182                 {
       
   183                 iDeleteUi = CCalenDeleteUi::NewL( iController );
       
   184                 }
       
   185             handled = iDeleteUi->HandleActionUiCommandL( aCommand );
       
   186             }
   115             }
   187 
   116         handler = iDeleteUi;
   188         if( !handled && aCommand == ECalenShowSettings )
       
   189             {
       
   190             handled = ETrue;
       
   191 
       
   192             ShowSettingsL();
       
   193             }
       
   194         }
   117         }
   195 
   118     else if ( aCommand >= ECalenSettingsCommandBase
       
   119       && aCommand < ECalenMapCommandBase )
       
   120         {
       
   121         handler = this;
       
   122         }
       
   123     else if ( aCommand >= ECalenMapCommandBase
       
   124       && aCommand < ECalenLastCommand )
       
   125         {
       
   126         }
       
   127         
   196     TRACE_EXIT_POINT;
   128     TRACE_EXIT_POINT;
   197     return handled;
   129     return handler;
   198     }*/
   130     }
   199 
       
   200 
   131 
   201 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
   202 // CCalenActionUi::HandleCommandL
   133 // CCalenActionUi::HandleCommandL
   203 // Handles key presses.
   134 // Handles key presses.
   204 // (other items were commented in a header).
   135 // (other items were commented in a header).
   206 //
   137 //
   207 TBool CCalenActionUi::HandleCommandL( const TCalenCommand& aCommand )
   138 TBool CCalenActionUi::HandleCommandL( const TCalenCommand& aCommand )
   208     {
   139     {
   209     TRACE_ENTRY_POINT;
   140     TRACE_ENTRY_POINT;
   210     TBool continueCommand(EFalse);
   141     TBool continueCommand(EFalse);
   211 
   142     
   212     switch(aCommand.Command())
   143     if(aCommand.Command()==ECalenShowSettings)
   213         {
   144         {  
   214         case ECalenShowSettings:
   145         launchSettingsView();
   215             {
       
   216             ShowSettingsL();
       
   217             }
       
   218             break;
       
   219         case ECalenShowCalendars:
       
   220             {
       
   221             ShowCalendarsL();
       
   222             }
       
   223             break;
       
   224         default:
       
   225             break;
       
   226         }
   146         }
   227 
   147     
   228     TRACE_EXIT_POINT;
   148     TRACE_EXIT_POINT;
   229     return continueCommand;
   149     return continueCommand;    }
   230     }
       
   231 
   150 
   232 // ----------------------------------------------------------------------------
   151 // ----------------------------------------------------------------------------
   233 // CCalenActionUi::CalenCommandHandlerExtensionL
   152 // CCalenActionUi::launchSettingsView
   234 // Dummy implementation.
   153 // Launches settings view
   235 // (other items were commented in a header).
   154 // (other items were commented in a header).
   236 // ----------------------------------------------------------------------------
   155 // ----------------------------------------------------------------------------
   237 //
   156 //
   238 TAny* CCalenActionUi::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ )
   157 void CCalenActionUi::launchSettingsView()
   239     {
   158     {
   240     TRACE_ENTRY_POINT;
   159     CalenSettingsView* settingsView = iController.ViewManager().settingsView();
   241     TRACE_EXIT_POINT;
   160     settingsView->initializeForm();
   242     return NULL;
   161     iController.Services().MainWindow().setCurrentView(settingsView);
   243     }
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CCalenActionUi::ShowCalendarsL
       
   247 // Shows the multiple db calendar's dialog
       
   248 // (other items were commented in a header).
       
   249 // ----------------------------------------------------------------------------
       
   250 //
       
   251 void CCalenActionUi::ShowCalendarsL()
       
   252     {
       
   253     TRACE_ENTRY_POINT;
       
   254     // Create settings own titlepane and navipane, and swap with existing ones
       
   255     CEikStatusPane* sp = CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   256     
       
   257     // Titlepane
       
   258     CAknTitlePane* newtp = new( ELeave ) CAknTitlePane();
       
   259     CleanupStack::PushL( newtp );
       
   260     CCoeControl* oldtp = sp->SwapControlL( TUid::Uid(EEikStatusPaneUidTitle), newtp );
       
   261     CleanupStack::Pop( newtp ); // ownership is passed to statuspane
       
   262     TRect oldRect( 0, 0, 0, 0 );
       
   263     if( oldtp )
       
   264         {
       
   265         CleanupStack::PushL( oldtp );
       
   266         oldRect = oldtp->Rect();
       
   267         CCoeControl* ctrl = sp->ContainerControlL( TUid::Uid( EEikStatusPaneUidTitle ));
       
   268         newtp->SetContainerWindowL( *ctrl );
       
   269         newtp->ConstructL();
       
   270         newtp->SetRect(oldRect);
       
   271         newtp->ActivateL();
       
   272         }        
       
   273     // NaviPane
       
   274     CAknNavigationControlContainer* newnp = new( ELeave )CAknNavigationControlContainer();
       
   275     CleanupStack::PushL( newnp );
       
   276     CCoeControl* oldnp = sp->SwapControlL( TUid::Uid( EEikStatusPaneUidNavi ), newnp );
       
   277     CleanupStack::Pop( newnp ); // ownership is passed to statuspane
       
   278     if( oldnp )
       
   279         {
       
   280         CleanupStack::PushL( oldnp );
       
   281         oldRect = oldnp->Rect();
       
   282         CCoeControl* ctrl = sp->ContainerControlL( TUid::Uid( EEikStatusPaneUidNavi ) );
       
   283         newnp->SetContainerWindowL( *ctrl );
       
   284         newnp->ConstructL();
       
   285         newnp->SetRect( oldRect );
       
   286         newnp->PushDefaultL();
       
   287         newnp->ActivateL();
       
   288         }
       
   289             
       
   290         // Hide the toolbar before we display settings menu
       
   291         MCalenToolbar* toolbar = iController.Services().ToolbarOrNull();
       
   292         if(toolbar)
       
   293             {
       
   294             toolbar->SetToolbarVisibilityL(EFalse);  
       
   295             }
       
   296         
       
   297         // defer settings notifications before launching the settings  
       
   298         CCalenNotifier& notifier = iController.Notifier();
       
   299         notifier.DeferSettingsNotifications();
       
   300         
       
   301         CCalenMultipleDbUi* dlg = CCalenMultipleDbUi::NewL(iController);
       
   302         TInt retValue = KErrNone;
       
   303         // Trap showing settings so settings watcher is always resumed.
       
   304         PIM_TRAPD_HANDLE( retValue = dlg->ExecuteLD( R_CALEN_MULTIPLEDB_DIALOG ) );
       
   305         notifier.ResumeSettingsNotifications();
       
   306         
       
   307         // Unhide the toolbar when settings is closed
       
   308         if(toolbar)
       
   309             {
       
   310             toolbar->SetToolbarVisibilityL(ETrue); 
       
   311             }
       
   312         
       
   313     // When setting is closed, swap back old titlepane and navipane
       
   314     if( oldnp && sp->SwapControlL( TUid::Uid(EEikStatusPaneUidNavi), oldnp ) )
       
   315         {
       
   316         CleanupStack::Pop( oldnp );
       
   317         delete newnp;
       
   318         oldnp->ActivateL();
       
   319         }
       
   320     if( oldtp && sp->SwapControlL( TUid::Uid(EEikStatusPaneUidTitle), oldtp ) )
       
   321         {
       
   322         CleanupStack::Pop( oldtp );
       
   323         delete newtp;
       
   324         oldtp->ActivateL();
       
   325         }
       
   326     
       
   327     iController.BroadcastNotification( ECalenNotifyCalendarFieldChanged );
       
   328 
       
   329     if( retValue == EAknCmdExit ||
       
   330         retValue == EKeyEscape )
       
   331         {
       
   332         // iController.IssueCommandL( EAknCmdExit );
       
   333         // FIX ME ::
       
   334         // Issuing the command from here will not exit the application properly
       
   335         // because aknviewappui is not exited
       
   336         // Calling ProcessCommandL of aknviewappui will exits the application
       
   337         iController.AppUi().ProcessCommandL(EAknCmdExit);
       
   338         }
       
   339     else if(retValue == EAknSoftkeyExit)
       
   340         {
       
   341         // iController.IssueCommandL( EAknCmdExit );
       
   342         // FIX ME ::
       
   343         // Issuing the command from here will not exit the application properly
       
   344         // because aknviewappui is not exited
       
   345         // Calling ProcessCommandL of aknviewappui will exits the application
       
   346         iController.AppUi().ProcessCommandL(EAknSoftkeyExit);
       
   347         }
       
   348 
       
   349     TRACE_EXIT_POINT;
       
   350     }
       
   351 
       
   352 // ----------------------------------------------------------------------------
       
   353 // CCalenActionUi::ShowSettingsL
       
   354 // Shows the settings dialog
       
   355 // (other items were commented in a header).
       
   356 // ----------------------------------------------------------------------------
       
   357 //
       
   358 void CCalenActionUi::ShowSettingsL()
       
   359     {
       
   360     TRACE_ENTRY_POINT;
       
   361     
       
   362     // Create settings own titlepane and navipane, and swap with existing ones
       
   363     CEikStatusPane* sp = CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   364     
       
   365     // Titlepane
       
   366     CAknTitlePane* newtp = new( ELeave ) CAknTitlePane();
       
   367     CleanupStack::PushL( newtp );
       
   368     CCoeControl* oldtp = sp->SwapControlL( TUid::Uid(EEikStatusPaneUidTitle), newtp );
       
   369     CleanupStack::Pop( newtp ); // ownership is passed to statuspane
       
   370     TRect oldRect( 0, 0, 0, 0 );
       
   371     if( oldtp )
       
   372         {
       
   373         CleanupStack::PushL( oldtp );
       
   374         oldRect = oldtp->Rect();
       
   375         CCoeControl* ctrl = sp->ContainerControlL( TUid::Uid( EEikStatusPaneUidTitle ));
       
   376         newtp->SetContainerWindowL( *ctrl );
       
   377         newtp->ConstructL();
       
   378         newtp->SetRect(oldRect);
       
   379         newtp->ActivateL();
       
   380         }        
       
   381     
       
   382     // NaviPane
       
   383     CAknNavigationControlContainer* newnp = new( ELeave )CAknNavigationControlContainer();
       
   384     CleanupStack::PushL( newnp );
       
   385     CCoeControl* oldnp = sp->SwapControlL( TUid::Uid( EEikStatusPaneUidNavi ), newnp );
       
   386     CleanupStack::Pop( newnp ); // ownership is passed to statuspane
       
   387     if( oldnp )
       
   388         {
       
   389         CleanupStack::PushL( oldnp );
       
   390         oldRect = oldnp->Rect();
       
   391         CCoeControl* ctrl = sp->ContainerControlL( TUid::Uid( EEikStatusPaneUidNavi ) );
       
   392         newnp->SetContainerWindowL( *ctrl );
       
   393         newnp->ConstructL();
       
   394         newnp->SetRect( oldRect );
       
   395         newnp->PushDefaultL();
       
   396         newnp->ActivateL();
       
   397         }
       
   398         
       
   399     // Hide the toolbar before we display settings menu
       
   400     MCalenToolbar* toolbar = iController.Services().ToolbarOrNull();
       
   401     if(toolbar)
       
   402         {
       
   403         toolbar->SetToolbarVisibilityL(EFalse);  
       
   404         }
       
   405     
       
   406     // defer settings notifications before launching the settings  
       
   407     CCalenNotifier& notifier = iController.Notifier();
       
   408     notifier.DeferSettingsNotifications();
       
   409     
       
   410     CCalenSettingsUi* dlg = CCalenSettingsUi::NewL(iController.CustomisationManager());
       
   411     TInt retValue = KErrNone;
       
   412     // Trap showing settings so settings watcher is always resumed.
       
   413     PIM_TRAPD_HANDLE( retValue = dlg->ExecuteLD( R_CALEN_SETTING_DIALOG ) );
       
   414     notifier.ResumeSettingsNotifications();
       
   415     
       
   416     // Unhide the toolbar when settings is closed
       
   417     if(toolbar)
       
   418         {
       
   419         toolbar->SetToolbarVisibilityL(ETrue); 
       
   420         }
       
   421     
       
   422     // When setting is closed, swap back old titlepane and navipane
       
   423     if( oldnp && sp->SwapControlL( TUid::Uid(EEikStatusPaneUidNavi), oldnp ) )
       
   424         {
       
   425         CleanupStack::Pop( oldnp );
       
   426         delete newnp;
       
   427         oldnp->ActivateL();
       
   428         }
       
   429     if( oldtp && sp->SwapControlL( TUid::Uid(EEikStatusPaneUidTitle), oldtp ) )
       
   430         {
       
   431         CleanupStack::Pop( oldtp );
       
   432         delete newtp;
       
   433         oldtp->ActivateL();
       
   434         }
       
   435     
       
   436     iController.BroadcastNotification( ECalenNotifySettingsClosed );
       
   437 
       
   438       if( retValue == EAknCmdExit ||
       
   439         retValue == EKeyEscape )
       
   440         {
       
   441         // iController.IssueCommandL( EAknCmdExit );
       
   442         // FIX ME ::
       
   443         // Issuing the command from here will not exit the application properly
       
   444         // because aknviewappui is not exited
       
   445         // Calling ProcessCommandL of aknviewappui will exits the application
       
   446         iController.AppUi().ProcessCommandL(EAknCmdExit);
       
   447         }
       
   448     else if(retValue == EAknSoftkeyExit)
       
   449         {
       
   450         // iController.IssueCommandL( EAknCmdExit );
       
   451         // FIX ME ::
       
   452         // Issuing the command from here will not exit the application properly
       
   453         // because aknviewappui is not exited
       
   454         // Calling ProcessCommandL of aknviewappui will exits the application
       
   455         iController.AppUi().ProcessCommandL(EAknSoftkeyExit);
       
   456         }
       
   457     
       
   458     TRACE_EXIT_POINT;
       
   459     }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CCalenActionUi::IsEditorActive
       
   463 // Tells framework whether editor is active or not
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 TBool CCalenActionUi::IsEditorActive()
       
   467     {
       
   468     if(iEditUi)
       
   469         {
       
   470         return(iEditUi->IsEditorActive());
       
   471         }
       
   472     else
       
   473         return EFalse;
       
   474     }
   162     }
   475 
   163 
   476 // End of file
   164 // End of file