cbs/cbsui/UiSrc/CCbsUiEditTopicDlg.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     Implementation of CCbsUiEditTopicDlg.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include    <avkon.hrh>             // EMultilineFirstLine, EMultilineSecondLine
       
    23 #include    <layoutmetadata.cdl.h>  // Layout_Meta_Data::IsLandscapeOrientation()  
       
    24 #include    <AknUtils.h>            // AknTextUtils
       
    25 #include    <aknQueryControl.h>
       
    26 #include    <cbsuiApp.rsg>
       
    27 #include    <StringLoader.h>
       
    28 #include    <AknDef.h>              // KEikDynamicLayoutVariantSwitch
       
    29 #include    "Cbsuiapp.hrh"
       
    30 #include    "CCbsUiEditTopicDlg.h"
       
    31 #include    "CCbsUiTopicListView.h"
       
    32 #include    "CbsUiPanic.h"
       
    33 #include    "CbsUiUtility.h"
       
    34 
       
    35 
       
    36 //CONSTANTS
       
    37 _LIT(KDummyString,"");
       
    38 
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 //
       
    44 CCbsUiEditTopicDlg::CCbsUiEditTopicDlg( CCbsUiTopicListView& aTopicListView,
       
    45                                        TBool aType ) 
       
    46                                        : 
       
    47 CAknMultiLineDataQueryDialog(ENoTone),    
       
    48 iTopicListView(aTopicListView),
       
    49 iType(aType)   
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CCbsUiEditTopicDlg::ConstructL
       
    55 // 
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 void CCbsUiEditTopicDlg::ConstructL( TDes& aDataText, TDes& aDataText2 )
       
    59     {
       
    60     SetDataL(aDataText, aDataText2);
       
    61     iUpdateLeftSoftKeyFirstTime = ETrue;   
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CCbsUiEditTopicDlg::NewL
       
    66 // 
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 CCbsUiEditTopicDlg* CCbsUiEditTopicDlg::NewL( TDes& aDataText, TDes& aDataText2,
       
    70                                              CCbsUiTopicListView& aTopicListView, TBool aType )
       
    71     {
       
    72     CCbsUiEditTopicDlg* self = 
       
    73         new (ELeave) CCbsUiEditTopicDlg(aTopicListView, aType);
       
    74     CleanupStack::PushL(self);
       
    75     self->ConstructL(aDataText, aDataText2);
       
    76     CleanupStack::Pop(); // self
       
    77     
       
    78     return self;
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 CCbsUiEditTopicDlg::~CCbsUiEditTopicDlg()
       
    83     {
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CCbsUiEditTopicDlg::OkToExitL
       
    88 // 
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 TBool CCbsUiEditTopicDlg::OkToExitL( TInt aButtonId )
       
    92     {
       
    93     // just to update the values
       
    94     TBool okToExit( CAknMultiLineDataQueryDialog::OkToExitL( aButtonId ) );
       
    95     if ( okToExit )
       
    96         {
       
    97         TBuf<KCbsDbTopicNameLength> dummy( KDummyString );
       
    98         TBuf<KCbsDbTopicNameLength> topicNumberStr;
       
    99         topicNumberStr = SecondData( dummy );
       
   100         AknTextUtils::ConvertDigitsTo( topicNumberStr, EDigitTypeWestern );
       
   101         TLex lex( topicNumberStr );
       
   102         TCbsTopicNumber tn;
       
   103         
       
   104         // No need to panic!
       
   105         User::LeaveIfError( lex.Val( tn, EDecimal ) );
       
   106         
       
   107         TCbsTopicName topicName;
       
   108         
       
   109         topicName.Append( FirstData( dummy ) );
       
   110         
       
   111         TInt ret( KErrGeneral ); // just to differ from KErrNone
       
   112         
       
   113         ret = iTopicListView.EditTopic( iType, tn, topicName );
       
   114         
       
   115         switch ( ret )
       
   116             {
       
   117             case KErrDiskFull:
       
   118                 User::Leave( KErrDiskFull );
       
   119                 break;
       
   120             case KErrNone:
       
   121                 // do nothing
       
   122                 break;
       
   123             default:
       
   124                 // shows the error note and the dialog is not closed
       
   125                 CbsUiUtility::ShowErrorNoteL( R_TEXT_NOTE_NUMBER_ERROR );
       
   126                 okToExit = EFalse;
       
   127                 SetCursorAndFocusL();
       
   128                 break;
       
   129             }
       
   130         }
       
   131     
       
   132     return okToExit;    
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CCbsUiEditTopicDlg::LineChangedL
       
   138 // 
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 void CCbsUiEditTopicDlg::LineChangedL( TInt /*aControlId*/ )
       
   142     {
       
   143     UpdateLeftSoftKeyL();
       
   144     }
       
   145 
       
   146 
       
   147 // ----------------------------------------------------
       
   148 // CCbsUiEditTopicDlg::HandleResourceChange
       
   149 //
       
   150 // ----------------------------------------------------
       
   151 void CCbsUiEditTopicDlg::HandleResourceChange( TInt aType )
       
   152     {
       
   153     CAknMultiLineDataQueryDialog::HandleResourceChange( aType );
       
   154     
       
   155     if( aType == KEikDynamicLayoutVariantSwitch )
       
   156         {
       
   157         TRAPD( ignore, UpdateLeftSoftKeyL( ) );
       
   158         if( ignore )
       
   159             {
       
   160             ignore = KErrNone; //Prevent ARMV5 compilation varning
       
   161             }
       
   162         }    
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CCbsUiEditTopicDlg::UpdateLeftSoftKeyL
       
   168 // Note: iUpdateLeftSoftKeyFirstTime must use because when we
       
   169 // go to UpdateLeftSoftKeyL() method first time then IdOfFocusControl()
       
   170 // method doesn't work ok yet.
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CCbsUiEditTopicDlg::UpdateLeftSoftKeyL()
       
   174     {
       
   175     if( ( Layout_Meta_Data::IsLandscapeOrientation() ) && 
       
   176         ( ( IdOfFocusControl() == EMultilineFirstLine) || iUpdateLeftSoftKeyFirstTime ) )
       
   177         {
       
   178         MakeLeftSoftkeyVisible( ETrue );
       
   179         }
       
   180     else
       
   181         {
       
   182         TBuf<EMaxTopicNumberLength> buf;
       
   183         SecondControl()->GetText( buf );
       
   184         AknTextUtils::ConvertDigitsTo( buf, EDigitTypeWestern );
       
   185         TLex lex( buf );
       
   186         TInt topicNumber( -1 );
       
   187         if ( lex.Val( topicNumber ) == KErrNone )
       
   188             {
       
   189             MakeLeftSoftkeyVisible( ETrue );
       
   190             }
       
   191         else
       
   192             {
       
   193             MakeLeftSoftkeyVisible( EFalse );
       
   194             }
       
   195         }
       
   196     iUpdateLeftSoftKeyFirstTime = EFalse;  
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CCbsUiEditTopicDlg::SetCursorAndFocusL
       
   201 // 
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 void CCbsUiEditTopicDlg::SetCursorAndFocusL()
       
   205     {
       
   206     TryChangeFocusToL(EMultilineSecondLine);
       
   207     CAknQueryControl* control = 
       
   208         STATIC_CAST( CAknQueryControl*, 
       
   209         Control(EMultilineSecondLine) );
       
   210     CEikEdwin* edwin = STATIC_CAST(
       
   211         CEikEdwin*, control->ControlByLayoutOrNull(EDataLayout) );
       
   212     edwin->SetSelectionL( control->GetTextLength(),0 );  
       
   213     }
       
   214 
       
   215 
       
   216 //  End of File