upnpframework/upnpcommonui/src/upnpadvfinddialog.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 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:  Advanced find dialog component source code
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 // System
       
    22 #include <StringLoader.h>
       
    23 #include <upnpstring.h>
       
    24 
       
    25 // upnpframework / avcontroller api
       
    26 #include "upnpavbrowsingsession.h"
       
    27 #include "upnpavdevice.h"
       
    28 
       
    29 // upnpframework / internal api's
       
    30 #include "upnpcommonutils.h"
       
    31 
       
    32 // common ui internal
       
    33 #include "upnpcommonui.h"
       
    34 #include <upnpcommonui.rsg>
       
    35 #include "upnpadvfinddialog.h"
       
    36 #include "upnpadvfindlist.h"
       
    37 
       
    38 // debug stuff
       
    39 _LIT( KComponentLogfile, "commonui.txt");
       
    40 #include "upnplog.h"
       
    41 
       
    42 // CONSTANTS
       
    43 const TInt KLength = 100;
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ============================
       
    46 // --------------------------------------------------------------------------
       
    47 // CUPnPAdvancedFindDialog::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // --------------------------------------------------------------------------
       
    50 //
       
    51 void CUPnPAdvancedFindDialog::ConstructL(TInt aMenuResource)
       
    52     {
       
    53     __LOG( "CUPnPAdvancedFindDialog::ConstructL" );
       
    54     CAknDialog::ConstructL(aMenuResource);
       
    55     
       
    56     iOriginalTitleText = HBufC16::NewL( KMaxFileName );
       
    57     }
       
    58 
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CUPnPAdvancedFindDialog::CUPnPAdvancedFindDialog
       
    62 // default constructor
       
    63 // --------------------------------------------------------------------------
       
    64 CUPnPAdvancedFindDialog::CUPnPAdvancedFindDialog(
       
    65                                 MUPnPAVController& aAVControl,
       
    66                                 MUPnPAVBrowsingSession& aBrowsingSession,
       
    67                                 CUPnPCommonUI& aCommonUI ):
       
    68                                 iAVControl(aAVControl),
       
    69                                 iBrowseSession(aBrowsingSession),
       
    70                                 iCommonUI(aCommonUI)
       
    71 
       
    72     {
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CUPnPAdvancedFindDialog::NewL
       
    77 // Two-phased constructor.
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 CUPnPAdvancedFindDialog* CUPnPAdvancedFindDialog::NewL(
       
    81                                 TInt aMenuResource,
       
    82                                 MUPnPAVController& aAVControl,
       
    83                                 MUPnPAVBrowsingSession& aBrowsingSession,
       
    84                                 CUPnPCommonUI& aCommonUI )
       
    85     {    
       
    86     __LOG( "CUPnPAdvancedFindDialog::NewL" );
       
    87 
       
    88     CUPnPAdvancedFindDialog* self = new ( ELeave ) CUPnPAdvancedFindDialog(
       
    89         aAVControl, aBrowsingSession, aCommonUI );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL( aMenuResource );
       
    92     CleanupStack::Pop();
       
    93     return self;
       
    94     }
       
    95     
       
    96 // Destructor
       
    97 CUPnPAdvancedFindDialog::~CUPnPAdvancedFindDialog()
       
    98     {
       
    99     __LOG( "CUPnPAdvancedFindDialog destructor" );
       
   100     // Set original title pane text
       
   101     if( iOriginalTitleText && iTitlePane )
       
   102         {
       
   103         TRAP_IGNORE( iTitlePane->SetTextL( *iOriginalTitleText ) );
       
   104         delete iOriginalTitleText;    
       
   105         }
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CUPnPAdvancedFindDialog::OkToExitL( TInt aButtonId )
       
   110 // called by framework when trying to close the dialog
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 TBool CUPnPAdvancedFindDialog::OkToExitL( TInt aButtonId )
       
   114     {
       
   115     __LOG( "CUPnPAdvancedFindDialog::OkToExitL" );
       
   116     TInt error = KErrNone;
       
   117     TBool retval = EFalse;
       
   118     
       
   119     if ( aButtonId == EAknSoftkeyOk )
       
   120         {
       
   121         iSettingsList->SetMopParent( this );
       
   122         error = iSettingsList->MakeQueryL();
       
   123         
       
   124         iTitlePane = (CAknTitlePane*)iStatusPane->ControlL(
       
   125                                     TUid::Uid( EEikStatusPaneUidTitle ) );
       
   126         SetTitleL();
       
   127         TryExitL( error );
       
   128         }
       
   129     else if ( aButtonId == EAknSoftkeyOptions )
       
   130         {
       
   131         DisplayMenuL();
       
   132         }
       
   133     else if ( aButtonId == EAknSoftkeyBack || 
       
   134               aButtonId == KErrSessionClosed ||
       
   135               aButtonId == KErrDisconnected ||
       
   136               aButtonId == EAknCmdExit ||
       
   137               aButtonId == EEikCmdExit )
       
   138         {
       
   139         retval = ETrue; //back to previous dialog
       
   140         }
       
   141     else if( aButtonId == EAknSoftkeyOpen )
       
   142         {
       
   143         TKeyEvent tmpEvent;
       
   144         tmpEvent.iCode = EKeyOK;
       
   145         tmpEvent.iModifiers = 0;
       
   146         tmpEvent.iRepeats = 0;
       
   147         tmpEvent.iScanCode = 0;
       
   148         TEventCode eventType = EEventKey;
       
   149         OfferKeyEventL( tmpEvent, eventType );
       
   150         }
       
   151     return retval;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CUPnPAdvancedFindDialog::PreLayoutDynInitL()
       
   156 // called by framework before dialog is shown 
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CUPnPAdvancedFindDialog::PreLayoutDynInitL()
       
   160     {
       
   161     __LOG( "CUPnPAdvancedFindDialog::PreLayoutDynInitL" );
       
   162     iStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   163     iTitlePane = ( CAknTitlePane* )iStatusPane->ControlL( 
       
   164                                     TUid::Uid( EEikStatusPaneUidTitle ) );
       
   165     
       
   166     // Take backup of title text
       
   167     iOriginalTitleText->Des().Copy( *iTitlePane->Text() );
       
   168     // set dialog title
       
   169     SetTitleL();
       
   170     }
       
   171     
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CUPnPAdvancedFindDialog::ProcessCommandL()
       
   175 // ---------------------------------------------------------
       
   176 //    
       
   177 void CUPnPAdvancedFindDialog::ProcessCommandL ( TInt aCommand )
       
   178     {
       
   179     __LOG( "CUPnPAdvancedFindDialog::ProcessCommandL" );
       
   180     HideMenu();    
       
   181     CAknDialog::ProcessCommandL( aCommand );
       
   182     }
       
   183   
       
   184 // ---------------------------------------------------------
       
   185 // CUPnPAdvancedFindDialog::OfferKeyEventL()
       
   186 // called by framework when key is pressed 
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 TKeyResponse CUPnPAdvancedFindDialog::OfferKeyEventL(
       
   190                                                 const TKeyEvent &aKeyEvent,
       
   191                                                 TEventCode aType )
       
   192     {
       
   193     __LOG( "CUPnPAdvancedFindDialog::OfferKeyEventL" );
       
   194     if ( aType != EEventKey )
       
   195         {
       
   196         return EKeyWasNotConsumed;
       
   197         }
       
   198     switch ( aKeyEvent.iCode )
       
   199         {
       
   200         case EKeyDownArrow: // flow through
       
   201         case EKeyUpArrow:
       
   202             {
       
   203             iSettingsList->OfferKeyEventL( aKeyEvent, aType );
       
   204             break;
       
   205             }
       
   206         case EKeyOK:
       
   207             {
       
   208             TInt selected_item = iSettingsList->ListBox()->CurrentItemIndex();
       
   209             iSettingsList->EditItemL( selected_item, ETrue );
       
   210             if( !iClose )
       
   211                 {
       
   212                 iSettingsList->HandleChangeInItemArrayOrVisibilityL();    
       
   213                 }
       
   214             
       
   215             break;
       
   216             }       
       
   217         default:
       
   218             {
       
   219             CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   220             break;    
       
   221             }
       
   222         }
       
   223 
       
   224     return EKeyWasConsumed;
       
   225     }
       
   226 
       
   227 // --------------------------------------------------------------------------
       
   228 // CUPnPAdvancedFindDialog::CreateCustomControlL
       
   229 // --------------------------------------------------------------------------
       
   230 //
       
   231 SEikControlInfo CUPnPAdvancedFindDialog::CreateCustomControlL(
       
   232                                                         TInt aControlType )
       
   233     {
       
   234     __LOG( "CUPnPAdvancedFindDialog::CreateCustomControlL" );
       
   235     SEikControlInfo controlInfo;
       
   236     controlInfo.iControl = NULL;
       
   237     controlInfo.iTrailerTextId = 0;
       
   238     controlInfo.iFlags = 0;
       
   239     switch ( aControlType )
       
   240         {
       
   241         case KAknCtLastControlId:
       
   242             {            
       
   243             iSettingsList = CUPnPAdvancedFindList::NewL( iAVControl, 
       
   244                                                          iBrowseSession,
       
   245                                                          *this,
       
   246                                                          iCommonUI );
       
   247             controlInfo.iControl = iSettingsList;          
       
   248             break;
       
   249             }
       
   250         default:
       
   251             {
       
   252             break;
       
   253             }
       
   254         }    
       
   255     return controlInfo;
       
   256     }        
       
   257 
       
   258 // --------------------------------------------------------------------------
       
   259 // CUPnPAdvancedFindDialog::DismissItselfL
       
   260 // --------------------------------------------------------------------------
       
   261 //
       
   262 void CUPnPAdvancedFindDialog::DismissItselfL( TInt aError )
       
   263     {
       
   264     iClose = ETrue;
       
   265     if( iSettingsList )
       
   266         {
       
   267         //if setting page is not open, close it, otherwise, do nothing
       
   268         if( !iSettingsList->IsSettingPageOpen() )
       
   269             {
       
   270             TryExitL( aError );
       
   271             }
       
   272         }
       
   273     else
       
   274         {
       
   275         TryExitL( aError );
       
   276         }
       
   277     }
       
   278 
       
   279 // --------------------------------------------------------------------------
       
   280 // CUPnPAdvancedFindDialog::SetTitleL
       
   281 // --------------------------------------------------------------------------
       
   282 //
       
   283 void CUPnPAdvancedFindDialog::SetTitleL()
       
   284     {
       
   285     const CUpnpAVDevice* device = &( iBrowseSession.Device() );
       
   286     
       
   287     // Get device friendly name and replace illegal characters.
       
   288     HBufC8* tmpfriendlyname = 
       
   289         UPnPCommonUtils::ReplaceIllegalFilenameCharactersL( 
       
   290         ( ( CUpnpAVDevice* )device )->FriendlyName() );    
       
   291     
       
   292     CleanupStack::PushL( tmpfriendlyname );
       
   293     TPtrC8 friendlyname = *tmpfriendlyname;
       
   294         
       
   295     HBufC* titleString = UpnpString::ToUnicodeL( 
       
   296         friendlyname.Left( KLength ) );
       
   297     CleanupStack::PushL( titleString );
       
   298     
       
   299     iTitlePane->SetTextL( *titleString );
       
   300     CleanupStack::PopAndDestroy( titleString );
       
   301     CleanupStack::PopAndDestroy( tmpfriendlyname );
       
   302     }
       
   303 // End of file