wvuing/wvuiave/AppSrc/CCASearchView.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005,2006 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:  View class for search view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCASearchView.h"
       
    21 #include    "CCASearchViewContainer.h"
       
    22 #include    "CAExternalInterface.h"
       
    23 #include    "chatngclient.hrh"
       
    24 #include    "CCAAppUi.h"
       
    25 #include    "CCAStatusPanehandler.h"
       
    26 #include	"IMDialogUtils.h"
       
    27 
       
    28 #include    "CCAUISessionManager.h"
       
    29 #include    "ChatDebugPrint.h"
       
    30 #include    "IMUtils.h"
       
    31 #include    <aknviewappui.h>
       
    32 #include    <stringloader.h>
       
    33 #include    <eikmenup.h>
       
    34 #include	<eikmenub.h>
       
    35 #include    <eiklbx.h>
       
    36 #include    <chatNG.rsg>
       
    37 #include	<bldvariant.hrh>
       
    38 
       
    39 #include    <hlplch.h>
       
    40 #include    <FeatMgr.h>
       
    41 
       
    42 // local variation
       
    43 #include    "IMPrivateCRKeys.h"
       
    44 #include    "IMVariant.hrh"
       
    45 #include    "MCAProcessManager.h"
       
    46 #include	"MCASearchInterfacePC.h"
       
    47 #include    "TEnumsPC.h"
       
    48 
       
    49 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    50 // so the enums for keys and central repository header is added here
       
    51 #include 	"VariantKeys.h"
       
    52 
       
    53 // ================= MEMBER FUNCTIONS =======================
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CCASearchView::CCASearchView()
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CCASearchView::CCASearchView()
       
    63 
       
    64     {
       
    65 
       
    66     iSearchInterfacePC = CAAppUi()->GetProcessManager().GetSearchInterface();
       
    67     // want all events for group synchronization
       
    68     CHAT_DP_TXT(
       
    69         "CCASearchView::CCASearchView - Registering background observer" );
       
    70 
       
    71     iSearchInterfacePC->RegisterBackgroundObserver( this,
       
    72                                                     TEnumsPC::EGroupFetch, ~0x0 );
       
    73 
       
    74     // only fire once. set to true when the group fetch finishes
       
    75 
       
    76 
       
    77     TInt status( iSearchInterfacePC->BackgroundTaskStatus(
       
    78                      TEnumsPC::EGroupFetch ) );
       
    79 
       
    80     CHAT_DP( D_CHAT_LIT( "group fetch status %d" ), status );
       
    81 
       
    82     // if background task doesn't exist, mark group sync as done
       
    83     iGroupSyncDone = ( status == KErrNotFound );
       
    84 
       
    85     CHAT_DP_TXT( "CCASearchView::CCASearchView - Registered background \
       
    86                  observer, everything good" );
       
    87     }
       
    88 
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CCASearchView::~CCASearchView()
       
    93 // C++ Destructor
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 CCASearchView::~CCASearchView()
       
    97     {
       
    98     if ( iSearchInterfacePC )
       
    99         {
       
   100         iSearchInterfacePC->UnRegisterBackgroundObserver( this );
       
   101         }
       
   102 
       
   103     if ( iPopUpMenu )
       
   104         {
       
   105         AppUi()->RemoveFromViewStack( *this, iPopUpMenu );
       
   106         }
       
   107     delete iPopUpMenu;
       
   108 
       
   109     if ( iContainer )
       
   110         {
       
   111         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   112         iContainer->DeleteSelfD();
       
   113         }
       
   114 
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CCASearchView::HandleCommandL( TInt aCommand )
       
   120 // This class all commands from menu
       
   121 // (other items were commented in a header).
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 void CCASearchView::HandleCommandL( TInt aCommand )
       
   125     {
       
   126     CHAT_DP( D_CHAT_LIT( "SearchView: HandleCommand( %d )" ), aCommand );
       
   127     if ( iPopUpMenu && iPopUpMenu->IsDisplayed() )
       
   128         {
       
   129         iPopUpMenu->StopDisplayingMenuBar();
       
   130         }
       
   131 
       
   132     switch ( aCommand )
       
   133         {
       
   134         case EChatClientSearchNew:
       
   135         case EChatClientSearchMore:
       
   136         case EChatClientSearchPrev:
       
   137         case EChatClientSearchStartConversation:
       
   138         case EChatClientSearchAddFriends:
       
   139         case EChatClientSearchInvite:
       
   140         case EChatClientSearchBlock:
       
   141         case EChatClientSearchBlockEnter:
       
   142         case EChatClientSearchBlockShow:
       
   143         case EChatClientSearchJoin:
       
   144             {
       
   145             UISessionManager().LoginL( MCAUiLoginCmdCB::EQueryLogin );
       
   146             if ( !UISessionManager().IsLoggedIn() )
       
   147                 {
       
   148                 // if still not logged in just return
       
   149                 return;
       
   150                 }
       
   151             break;
       
   152             }
       
   153         default:
       
   154             {
       
   155             break;
       
   156             }
       
   157         }
       
   158 
       
   159     switch ( aCommand )
       
   160         {
       
   161             //Next two commands have same function
       
   162         case EAknSoftkeyBack:
       
   163         case EChatClientCmdBack:
       
   164             {
       
   165             iContainer->SetObserverToNull();
       
   166             CAAppUi()->SwitchViewL( iPrevViewId.iViewUid );
       
   167             break;
       
   168             }
       
   169         case EChatClientSearchNew:
       
   170             {
       
   171             iContainer->NewSearchL();
       
   172             break;
       
   173             }
       
   174         case EChatClientSearchMore:
       
   175             {
       
   176             TRAPD( searchMoreErr, iContainer->SearchMoreL() );
       
   177             if ( searchMoreErr == KErrNoMemory
       
   178                  || searchMoreErr == KErrDiskFull )
       
   179                 {
       
   180                 User::Leave( searchMoreErr );
       
   181                 }
       
   182             if ( searchMoreErr != KErrNone )
       
   183                 {
       
   184                 CActiveScheduler::Current()->Error( searchMoreErr );
       
   185                 }
       
   186             break;
       
   187             }
       
   188         case EChatClientSearchPrev:
       
   189             {
       
   190             TRAPD( searchPrevErr, iContainer->SearchPreviousL() );
       
   191             if ( searchPrevErr == KErrNoMemory
       
   192                  || searchPrevErr == KErrDiskFull )
       
   193                 {
       
   194                 User::Leave( searchPrevErr );
       
   195                 }
       
   196             if ( searchPrevErr != KErrNone )
       
   197                 {
       
   198                 CActiveScheduler::Current()->Error( searchPrevErr );
       
   199                 }
       
   200             break;
       
   201             }
       
   202 
       
   203         case EChatClientSearchStartConversation:
       
   204             {
       
   205             iContainer->StartConversationL();
       
   206             break;
       
   207             }
       
   208 
       
   209         case EChatClientSearchAddFriends:
       
   210             {
       
   211             iContainer->AddToFriendsL();
       
   212             break;
       
   213             }
       
   214 
       
   215         case EChatClientSearchInvite:
       
   216             {
       
   217             if ( UISessionManager().IsSupported( CCAUISessionManager::EInvite ) )
       
   218                 {
       
   219                 iContainer->InviteL();
       
   220                 }
       
   221             else
       
   222                 {
       
   223                 IMDialogUtils::DisplayNoteDialogL(
       
   224                     R_CHAT_ERROR_NOT_SUP_FUNCTIONS );
       
   225                 }
       
   226             break;
       
   227             }
       
   228 
       
   229         case EChatClientSearchBlock:
       
   230             {
       
   231             iContainer->BlockUserL();
       
   232             break;
       
   233             }
       
   234         case EChatClientSearchBlockEnter:
       
   235             {
       
   236             iContainer->BlockUserWVIdL();
       
   237             break;
       
   238             }
       
   239         case EChatClientSearchBlockShow:
       
   240             {
       
   241             iContainer->DisplayBlockedListL();
       
   242             break;
       
   243             }
       
   244         case EChatClientSearchJoin:
       
   245             {
       
   246             iContainer->JoinToGroupL();
       
   247             break;
       
   248             }
       
   249         case EChatClientSearchFavor:
       
   250             {
       
   251             iContainer->SaveAsFavouriteL();
       
   252             break;
       
   253             }
       
   254         case EChatClientSearchEdit:
       
   255             {
       
   256             break;
       
   257             }
       
   258         // Help key support EChatClientCmdHelp is assigned EAknCmdHelp in
       
   259         // chatngclient.hrh
       
   260         case EChatClientCmdHelp:
       
   261             {
       
   262             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   263                                                  AppUi()->AppHelpContextL() );
       
   264             break;
       
   265             }
       
   266         case EAknSoftkeyContextOptions: // MSK command show context menu
       
   267             {
       
   268             ShowPopUpMenuL();
       
   269             break;
       
   270             }
       
   271         default:
       
   272             {
       
   273             AppUi()->HandleCommandL( aCommand );
       
   274             break;
       
   275             }
       
   276         }
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------
       
   280 // CCASearcView::DynInitMenuPaneL()
       
   281 // Initialises menu pane when needed
       
   282 // (other items were commented in a header).
       
   283 // ---------------------------------------------------------
       
   284 //
       
   285 void CCASearchView::DynInitMenuPaneL( TInt aResourceId,
       
   286                                       CEikMenuPane* aMenuPane )
       
   287     {
       
   288 
       
   289     TInt curIndex( iContainer->ListBox()->CurrentItemIndex() );
       
   290 
       
   291     if ( aResourceId == R_CHATCLIENT_SEARCH_VIEW_MENU ||
       
   292          aResourceId == R_CHATCLIENT_SEARCH_VIEW_CONTEXT_MENU )
       
   293         {
       
   294 
       
   295         if ( iContainer->SearchType()
       
   296              == CCASearchViewContainer::ESearchGroups || curIndex < 0 )
       
   297             {
       
   298             aMenuPane->SetItemDimmed( EChatClientSearchAddFriends, ETrue );
       
   299             aMenuPane->SetItemDimmed(
       
   300                 EChatClientSearchStartConversation, ETrue );
       
   301             aMenuPane->SetItemDimmed( EChatClientSearchInvite, ETrue );
       
   302             }
       
   303         else
       
   304             if ( !iContainer->IsOnline()
       
   305                  && !( IMUtils::IntResourceValueL(
       
   306                            RSC_CHAT_VARIATION_SEND_MSG_IGNORE_OFFLINE_NOTIFY )
       
   307                        || IMUtils::IntResourceValueL(
       
   308                            RSC_CHAT_VARIATION_SEND_MSG_IGNORE_OFFLINE ) ) )
       
   309                 {
       
   310                 aMenuPane->SetItemDimmed(
       
   311                     EChatClientSearchStartConversation, ETrue );
       
   312                 aMenuPane->SetItemDimmed( EChatClientSearchInvite, ETrue );
       
   313                 }
       
   314 
       
   315         TInt joinedGroups( iSearchInterfacePC->JoinedGroups() );
       
   316         CHAT_DP( D_CHAT_LIT( "Number of joined groups: %d" ), joinedGroups );
       
   317         if (  joinedGroups == 0 )
       
   318             {
       
   319             aMenuPane->SetItemDimmed( EChatClientSearchInvite, ETrue );
       
   320             }
       
   321 
       
   322         if ( iContainer->SearchType() == CCASearchViewContainer::ESearchUsers ||
       
   323              curIndex < 0 )
       
   324             {
       
   325             aMenuPane->SetItemDimmed( EChatClientSearchJoin, ETrue );
       
   326             }
       
   327 
       
   328         if ( iContainer->SearchType() == CCASearchViewContainer::ESearchUsers ||
       
   329              curIndex < 0 || iContainer->IsFavouriteChatGroup() )
       
   330             {
       
   331             aMenuPane->SetItemDimmed( EChatClientSearchFavor, ETrue );
       
   332             }
       
   333 
       
   334 
       
   335         if ( iContainer->SearchType() == CCASearchViewContainer::ESearchUsers
       
   336              && iSearchInterfacePC->FindAnyContactL( iContainer->SearchData() ) )
       
   337             {
       
   338             aMenuPane->SetItemDimmed( EChatClientSearchAddFriends, ETrue );
       
   339             }
       
   340 
       
   341         }
       
   342 
       
   343     // Block submenu
       
   344     if ( ( aResourceId == R_CHATCLIENT_SEARCH_BLOCK_SUBMENU ) &&
       
   345          ( iContainer->SearchType() == CCASearchViewContainer::ESearchUsers ) )
       
   346         {
       
   347         if ( iContainer->IsBlocked() )
       
   348             {
       
   349             aMenuPane->SetItemDimmed( EChatClientSearchBlock, ETrue );
       
   350             }
       
   351         // show/hide "show blocked list" option
       
   352         if ( !IMUtils::IntResourceValueL(
       
   353                  RSC_CHAT_VARIATION_SHOW_BLOCKED_LIST ) )
       
   354             {
       
   355             aMenuPane->SetItemDimmed(
       
   356                 EChatClientSearchBlockShow, ETrue );
       
   357             }
       
   358         }
       
   359 
       
   360     // Items only in Context specific menu
       
   361     if ( aResourceId == R_CHATCLIENT_SEARCH_VIEW_CONTEXT_MENU )
       
   362         {
       
   363         // put them here
       
   364         }
       
   365 
       
   366     // Items only in Options menu
       
   367     if ( aResourceId == R_CHATCLIENT_SEARCH_VIEW_MENU )
       
   368         {
       
   369         if ( curIndex < 0 || !iContainer->PrevResultsAvailable() )
       
   370             {
       
   371             aMenuPane->SetItemDimmed( EChatClientSearchPrev, ETrue );
       
   372             }
       
   373 
       
   374         if ( curIndex < 0 || !iContainer->MoreResultsAvailable() )
       
   375             {
       
   376             aMenuPane->SetItemDimmed( EChatClientSearchMore, ETrue );
       
   377             }
       
   378 
       
   379         // check if user block/unblock is supported according to variation
       
   380         if ( !UISessionManager().IsSupported( CCAUISessionManager::EBlock ) )
       
   381             {
       
   382             aMenuPane->SetItemDimmed( EChatClientSearchBlockOpt, ETrue );
       
   383             }
       
   384         if ( iContainer->SearchType()
       
   385              == CCASearchViewContainer::ESearchGroups || curIndex < 0 )
       
   386             {
       
   387             aMenuPane->SetItemDimmed( EChatClientSearchBlockOpt, ETrue );
       
   388             }
       
   389         }
       
   390     // if we're displaying general menu and help feature is not supported..
       
   391     if ( ( aResourceId == R_CHATCLIENT_GENERAL_MENU ) &&
       
   392          ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) )
       
   393         {
       
   394         // dimm the help menu item
       
   395         aMenuPane->SetItemDimmed( EChatClientCmdHelp, ETrue );
       
   396         }
       
   397     }
       
   398 
       
   399 
       
   400 // ---------------------------------------------------------
       
   401 // CCASearchView::ShowPopUpMenuL()
       
   402 // (other items were commented in a header).
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 void CCASearchView::ShowPopUpMenuL()
       
   406     {
       
   407 
       
   408 #ifdef	RD_30_DISABLE_TOUCH
       
   409     // In 3.0 we need to launch context menu by ourself
       
   410     iPopUpMenu->TryDisplayMenuBarL();
       
   411 #else
       
   412     MenuBar()->TryDisplayContextMenuBarL();
       
   413 #endif //RD_30_DISABLE_TOUCH   
       
   414 
       
   415     }
       
   416 
       
   417 
       
   418 // ---------------------------------------------------------
       
   419 // CCASearchView::ShowRecipientsListL()
       
   420 // (other items were commented in a header).
       
   421 // ---------------------------------------------------------
       
   422 //
       
   423 TInt CCASearchView::ShowRecipientsListL( TInt /*aResourceId*/ )
       
   424     {
       
   425     return User::LeaveIfError( -1 );
       
   426     }
       
   427 
       
   428 
       
   429 // ---------------------------------------------------------
       
   430 // CCASearchView::DoActivateL()
       
   431 // Activates view
       
   432 // (other items were commented in a header).
       
   433 // ---------------------------------------------------------
       
   434 //
       
   435 void CCASearchView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   436                                  TUid aCustomMessageId, const TDesC8& /* aCustomMessage*/ )
       
   437     {
       
   438     CHAT_DP( D_CHAT_LIT( "CCASearchView::DoActivateL( viewid=%d" ),
       
   439              aPrevViewId.iViewUid );
       
   440 
       
   441     // Unregister the view that was registered from Forward option.
       
   442     // didn't find any better place to put this.
       
   443     if ( TEnumsPC::EToBeUnregistered == CAAppUi()->RetForwardTo() )
       
   444         {
       
   445         CAAppUi()->UnRegisterPreviousview( );
       
   446         CAAppUi()->SetResetForwardTo( TEnumsPC::EUnregistered );
       
   447         }
       
   448     // To prevent looping between this view and ...
       
   449     // - refresh view
       
   450     // - conversation view
       
   451     if ( aPrevViewId.iViewUid != KUidRefreshView &&
       
   452          aPrevViewId.iViewUid != KUidConversationsView &&
       
   453          aPrevViewId.iViewUid != KUidChatView &&
       
   454          aPrevViewId.iViewUid != KUidInvitationView )
       
   455         {
       
   456         iPrevViewId = aPrevViewId;
       
   457         }
       
   458 
       
   459     CAAppUi()->CAStatusPane()->ClearNaviPaneL();
       
   460 
       
   461     if ( !iContainer )
       
   462         {
       
   463         TBool users( aCustomMessageId == KUidSearchViewMsgIdUser );
       
   464 
       
   465         CHAT_DP( D_CHAT_LIT(
       
   466                      "CCASearchView::DoActivateL constructing container" ) );
       
   467         iContainer = CCASearchViewContainer::NewL( iSearchInterfacePC, ClientRect(),
       
   468                                                    *CAViewSwitcher(), *this, users, iGroupSyncDone,
       
   469                                                    KNullDesC );
       
   470 
       
   471         iContainer->SetMopParent( this );
       
   472 
       
   473         AppUi()->AddToViewStackL( *this, iContainer );
       
   474         }
       
   475 
       
   476     // SimplifiedUI localisation variation for empty list
       
   477     if ( IMUtils::CRKeyL( KCRUidIMVariation, KIMVariationKey ) &
       
   478          EIMFeatSimplifiedUI )
       
   479         {
       
   480         iContainer->SetEmptyTextsToListboxL();
       
   481         }
       
   482 
       
   483     // Context sensitive menu
       
   484 #ifndef RD_30_DISABLE_TOUCH
       
   485     // S60 Common
       
   486     MenuBar()->SetContextMenuTitleResourceId( R_SEARCH_VIEW_POPUP_MENU_BAR );
       
   487 #else
       
   488     // S60 3.0
       
   489     if ( !iPopUpMenu )
       
   490         {
       
   491         iPopUpMenu = new( ELeave ) CEikMenuBar;
       
   492         iPopUpMenu->ConstructL( this, 0, R_SEARCH_VIEW_POPUP_MENU_BAR );
       
   493         iEikonEnv->EikAppUi()->AddToStackL( iPopUpMenu, ECoeStackPriorityMenu,
       
   494                                             ECoeStackFlagRefusesFocus );
       
   495         }
       
   496 
       
   497     CHAT_DP( D_CHAT_LIT( "CCASearchView::DoActivateL ends" ) );
       
   498 #endif //RD_30_DISABLE_TOUCH
       
   499 
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------
       
   503 // CCASearchView::DoDeactivate()
       
   504 // Deactivates the view
       
   505 // (other items were commented in a header).
       
   506 // ---------------------------------------------------------
       
   507 //
       
   508 void CCASearchView::DoDeactivate()
       
   509     {
       
   510     CHAT_DP( D_CHAT_LIT( "CCASearchView::DoDeactivate" ) );
       
   511     if ( iContainer )
       
   512         {
       
   513         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   514         }
       
   515 
       
   516     iContainer->DeleteSelfD();
       
   517     iContainer = NULL;
       
   518 
       
   519 
       
   520     if ( iPopUpMenu )
       
   521         {
       
   522         AppUi()->RemoveFromViewStack( *this, iPopUpMenu );
       
   523         }
       
   524     delete iPopUpMenu;
       
   525     iPopUpMenu = NULL;
       
   526     }
       
   527 
       
   528 
       
   529 // ---------------------------------------------------------
       
   530 // CCASearchView::HandleBackgroundEventPC()
       
   531 // (other items were commented in a header).
       
   532 // ---------------------------------------------------------
       
   533 //
       
   534 void CCASearchView::HandleBackgroundEventPC(
       
   535     TEnumsPC::TCABackgroundTasks aEventSource,
       
   536     TEnumsPC::TCABackgroundStatus aStatus,
       
   537     TInt  /*aSubTaskNumber*/,
       
   538     TInt  /*aLeaveCode*/ )
       
   539     {
       
   540     CHAT_DP_FUNC_ENTER( "HandleBackgroundEvent" );
       
   541 
       
   542     if ( iGroupSyncDone )
       
   543         {
       
   544         // we're not interested in this event anymore, but apparently
       
   545         // we can't unregister it inside here
       
   546         return;
       
   547         }
       
   548 
       
   549     // Currently we are interested only group fetching events
       
   550     if ( aEventSource == TEnumsPC::EGroupFetch )
       
   551         {
       
   552         CHAT_DP_FUNC_ENTER( "HandleBackgroundEvent - EGroupFetch" );
       
   553         if ( aStatus == TEnumsPC::ECompleted
       
   554              || aStatus == TEnumsPC::EFailedStatus )
       
   555             {
       
   556             CHAT_DP_TXT( "CCASearchView::HandleBackgroundEvent - \
       
   557                          Got ECompleted/EFailed, nuke wait note" );
       
   558 
       
   559             iGroupSyncDone = ETrue;
       
   560 
       
   561             if ( iContainer )
       
   562                 {
       
   563                 iContainer->SetGroupSyncDone();
       
   564                 }
       
   565             }
       
   566         }
       
   567 
       
   568     CHAT_DP_FUNC_DONE( "HandleBackgroundEvent" );
       
   569     }
       
   570 
       
   571 //  End of File