localconnectivityservice/dun/utils/src/DunNoteHandler.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Manages note showing in UI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "DunNoteHandler.h"
       
    20 #include "DunDebug.h"
       
    21 
       
    22 // ======== MEMBER FUNCTIONS ========
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Two-phased constructor.
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CDunNoteHandler* CDunNoteHandler::NewL()
       
    29     {
       
    30     CDunNoteHandler* self = new (ELeave) CDunNoteHandler();
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Destructor
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CDunNoteHandler::~CDunNoteHandler()
       
    42     {
       
    43     FTRACE(FPrint( _L("CDunNoteHandler::~CDunNoteHandler()") ));
       
    44     ResetData();
       
    45     FTRACE(FPrint( _L("CDunNoteHandler::~CDunNoteHandler() complete") ));
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Resets data to initial values
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CDunNoteHandler::ResetData()
       
    53     {
       
    54     FTRACE(FPrint( _L("CDunNoteHandler::ResetData()") ));
       
    55     // APIs affecting this:
       
    56     // IssueRequest()
       
    57     Stop();
       
    58     delete iNote;
       
    59     iNote = NULL;
       
    60     // Internal
       
    61     Initialize();
       
    62     FTRACE(FPrint( _L("CDunNoteHandler::ResetData() complete") ));
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Issues request to start showing UI note
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TInt CDunNoteHandler::IssueRequest()
       
    70     {
       
    71     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest()") ));
       
    72     if ( iNoteState != EDunStateIdle )
       
    73         {
       
    74         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (not ready) complete") ));
       
    75         return KErrNotReady;
       
    76         }
       
    77     TRAPD( retTrap, DoIssueRequestL() );
       
    78     if ( retTrap != KErrNone )
       
    79         {
       
    80         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (trapped!) complete (%d)"), retTrap));
       
    81         return retTrap;
       
    82         }
       
    83     iNoteState = EDunStateUiNoting;
       
    84     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() complete") ));
       
    85     return KErrNone;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Stops showing UI note
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 TInt CDunNoteHandler::Stop()
       
    93     {
       
    94     FTRACE(FPrint( _L("CDunNoteHandler::Stop()") ));
       
    95     if ( iNoteState != EDunStateUiNoting )
       
    96         {
       
    97         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (not ready) complete") ));
       
    98         return KErrNotReady;
       
    99         }
       
   100     if ( !iNote )
       
   101         {
       
   102         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (iNote not initialized!) complete") ));
       
   103         return KErrGeneral;
       
   104         }
       
   105     iNote->Close();
       
   106     iNoteState = EDunStateIdle;
       
   107     FTRACE(FPrint( _L("CDunNoteHandler::Stop() complete") ));
       
   108     return KErrNone;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CDunNoteHandler::CDunNoteHandler
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 CDunNoteHandler::CDunNoteHandler()
       
   116     {
       
   117     Initialize();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CDunNoteHandler::ConstructL
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CDunNoteHandler::ConstructL()
       
   125     {
       
   126     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL()") ));
       
   127     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL() complete") ));
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // Initializes this class
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CDunNoteHandler::Initialize()
       
   135     {
       
   136     FTRACE(FPrint( _L("CDunNoteHandler::Initialize()" ) ));
       
   137     iNote = NULL;
       
   138     iNoteState = EDunStateIdle;
       
   139     FTRACE(FPrint( _L("CDunNoteHandler::Initialize() complete" ) ));
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // Issues request to start showing UI note
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CDunNoteHandler::DoIssueRequestL()
       
   147     {
       
   148     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL()") ));
       
   149     if ( iNote )
       
   150         {
       
   151         FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() (ERROR) complete") ));
       
   152         User::Leave( KErrGeneral );
       
   153         }
       
   154 
       
   155     CHbDeviceMessageBoxSymbian* messageBox =
       
   156             CHbDeviceMessageBoxSymbian::NewL(
       
   157                     CHbDeviceMessageBoxSymbian::EWarning);
       
   158     CleanupStack::PushL(messageBox);
       
   159     //ToDo: Need to use localised strings.
       
   160     _LIT(KText, "Maximum number of dialup-connections. Dial-up failed.");
       
   161     messageBox->SetTextL(KText);
       
   162     messageBox->SetObserver(this);
       
   163     messageBox->SetTimeout(0);
       
   164     messageBox->ShowL();
       
   165     CleanupStack::Pop(messageBox);
       
   166     iNote = messageBox;
       
   167     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() complete") ));
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // From class MHbDeviceMessageBoxObserver.
       
   172 // Gets called on dialog close.
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CDunNoteHandler::MessageBoxClosed(
       
   176     const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
       
   177     CHbDeviceMessageBoxSymbian::TButtonId /*aButton*/ )
       
   178     {
       
   179     FTRACE(FPrint( _L("CDunNoteHandler::MessageBoxClosed()" ) ));
       
   180     iNoteState = EDunStateIdle;
       
   181     delete iNote;
       
   182     iNote = NULL;
       
   183     FTRACE(FPrint( _L("CDunNoteHandler::MessageBoxClosed() complete" ) ));
       
   184     }