localconnectivityservice/dun/utils/src/DunNoteHandler.cpp
changeset 33 883e91c086aa
parent 28 85e0c0339cc3
equal deleted inserted replaced
28:85e0c0339cc3 33:883e91c086aa
    14 * Description:  Manages note showing in UI
    14 * Description:  Manages note showing in UI
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <bautils.h>
       
    20 #include <featmgr.h>
       
    21 #include <aknSDData.h>
       
    22 #include <secondarydisplay/dunsecondarydisplayapi.h>
       
    23 #include "DunNoteHandler.h"
    19 #include "DunNoteHandler.h"
    24 #include "DunDebug.h"
    20 #include "DunDebug.h"
    25 
       
    26 _LIT( KDunUtilsDriveSpec, "z:" );
       
    27 _LIT( KDunUtilsResourceFileName, "dunutils.rsc" );
       
    28 
       
    29 const TInt KDunCoverEnumStart     = (ECmdNone + 1);  // start after ECmdNone
       
    30 const TInt KDunPtr8toPtr16Divider = 2;               // Divider for converting
       
    31 const TInt KDunThreeItemsToPop    = 3;
       
    32 
    21 
    33 // ======== MEMBER FUNCTIONS ========
    22 // ======== MEMBER FUNCTIONS ========
    34 
    23 
    35 // ---------------------------------------------------------------------------
    24 // ---------------------------------------------------------------------------
    36 // Two-phased constructor.
    25 // Two-phased constructor.
    89     if ( retTrap != KErrNone )
    78     if ( retTrap != KErrNone )
    90         {
    79         {
    91         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (trapped!) complete (%d)"), retTrap));
    80         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (trapped!) complete (%d)"), retTrap));
    92         return retTrap;
    81         return retTrap;
    93         }
    82         }
    94     SetActive();
       
    95     iNoteState = EDunStateUiNoting;
    83     iNoteState = EDunStateUiNoting;
    96     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() complete") ));
    84     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() complete") ));
    97     return KErrNone;
    85     return KErrNone;
    98     }
    86     }
    99 
    87 
   112     if ( !iNote )
   100     if ( !iNote )
   113         {
   101         {
   114         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (iNote not initialized!) complete") ));
   102         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (iNote not initialized!) complete") ));
   115         return KErrGeneral;
   103         return KErrGeneral;
   116         }
   104         }
   117     iNote->CancelConfirmationQuery();
   105     iNote->Close();
   118     Cancel();
       
   119     iNoteState = EDunStateIdle;
   106     iNoteState = EDunStateIdle;
   120     FTRACE(FPrint( _L("CDunNoteHandler::Stop() complete") ));
   107     FTRACE(FPrint( _L("CDunNoteHandler::Stop() complete") ));
   121     return KErrNone;
   108     return KErrNone;
   122     }
   109     }
   123 
   110 
   124 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   125 // CDunNoteHandler::CDunNoteHandler
   112 // CDunNoteHandler::CDunNoteHandler
   126 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   127 //
   114 //
   128 CDunNoteHandler::CDunNoteHandler() :
   115 CDunNoteHandler::CDunNoteHandler()
   129     CActive( EPriorityStandard )
       
   130     {
   116     {
   131     Initialize();
   117     Initialize();
   132     }
   118     }
   133 
   119 
   134 // ---------------------------------------------------------------------------
   120 // ---------------------------------------------------------------------------
   136 // ---------------------------------------------------------------------------
   122 // ---------------------------------------------------------------------------
   137 //
   123 //
   138 void CDunNoteHandler::ConstructL()
   124 void CDunNoteHandler::ConstructL()
   139     {
   125     {
   140     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL()") ));
   126     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL()") ));
   141     CActiveScheduler::Add( this );
       
   142     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL() complete") ));
   127     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL() complete") ));
   143     }
   128     }
   144 
   129 
   145 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   146 // Initializes this class
   131 // Initializes this class
   164     if ( iNote )
   149     if ( iNote )
   165         {
   150         {
   166         FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() (ERROR) complete") ));
   151         FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() (ERROR) complete") ));
   167         User::Leave( KErrGeneral );
   152         User::Leave( KErrGeneral );
   168         }
   153         }
   169     HBufC16* unicodeString = NULL;
   154 
   170     ReadResourceTextL( R_DUN_MAXIMUM_DIALUPS, unicodeString );
   155     CHbDeviceMessageBoxSymbian* messageBox =
   171     CAknGlobalConfirmationQuery* note = CAknGlobalConfirmationQuery::NewLC();
   156             CHbDeviceMessageBoxSymbian::NewL(
   172     // Publish cover UI note data
   157                     CHbDeviceMessageBoxSymbian::EWarning);
   173     CAknSDData* sdData = CAknSDData::NewL( KDunNoteCategory,
   158     CleanupStack::PushL(messageBox);
   174                                            ECmdMaxNumber - KDunCoverEnumStart,
   159     //ToDo: Need to use localised strings.
   175                                            KNullDesC8 );
   160     _LIT(KText, "Maximum number of dialup-connections. Dial-up failed.");
   176     note->SetSecondaryDisplayData( sdData );  // ownership transferred
   161     messageBox->SetTextL(KText);
   177     // Start to show note
   162     messageBox->SetObserver(this);
   178     iStatus = KRequestPending;
   163     messageBox->SetTimeout(0);
   179     note->ShowConfirmationQueryL( iStatus,
   164     messageBox->ShowL();
   180                                   *unicodeString,
   165     CleanupStack::Pop(messageBox);
   181                                   R_AVKON_SOFTKEYS_OK_EMPTY,
   166     iNote = messageBox;
   182                                   R_QGN_NOTE_ERROR_ANIM,
       
   183                                   KNullDesC,
       
   184                                   0,
       
   185                                   0,
       
   186                                   CAknQueryDialog::EErrorTone );
       
   187     CleanupStack::Pop( note );
       
   188     delete unicodeString;
       
   189     iNote = note;
       
   190     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() complete") ));
   167     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() complete") ));
   191     }
   168     }
   192 
   169 
   193 // ---------------------------------------------------------------------------
   170 // ---------------------------------------------------------------------------
   194 // Reads resource string
   171 // From class MHbDeviceMessageBoxObserver.
       
   172 // Gets called on dialog close.
   195 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   196 //
   174 //
   197 void CDunNoteHandler::ReadResourceTextL( TInt aResourceId, HBufC16*& aUnicode )
   175 void CDunNoteHandler::MessageBoxClosed(
       
   176     const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
       
   177     CHbDeviceMessageBoxSymbian::TButtonId /*aButton*/ )
   198     {
   178     {
   199     FTRACE(FPrint( _L("CDunNoteHandler::ReadNoteResourceL()") ));
   179     FTRACE(FPrint( _L("CDunNoteHandler::MessageBoxClosed()" ) ));
   200     // Connect to file server (for resource file reading)
       
   201     RFs fileSession;
       
   202     CleanupClosePushL<RFs>( fileSession );
       
   203     User::LeaveIfError( fileSession.Connect() );
       
   204     // Create dunutils.rsc path and file name
       
   205     TFileName fileName;
       
   206     fileName = KDunUtilsDriveSpec;
       
   207     fileName += KDC_RESOURCE_FILES_DIR;
       
   208     fileName += KDunUtilsResourceFileName;
       
   209     // Find nearest language file for resource
       
   210     BaflUtils::NearestLanguageFile( fileSession, fileName );
       
   211     // Read note resource
       
   212     RResourceFile resourceFile;
       
   213     CleanupClosePushL<RResourceFile>( resourceFile );
       
   214     resourceFile.OpenL( fileSession, fileName );
       
   215     resourceFile.ConfirmSignatureL();
       
   216     HBufC8* readBuffer = resourceFile.AllocReadLC( aResourceId );
       
   217     // Convert read HBufC8 to HBufC16
       
   218     const TPtrC16 ptr16(reinterpret_cast<const TUint16*>
       
   219                        (readBuffer->Ptr()),
       
   220                        (readBuffer->Size() / KDunPtr8toPtr16Divider) );
       
   221     aUnicode = HBufC16::NewL( ptr16.Length() );
       
   222     *aUnicode = ptr16;
       
   223     CleanupStack::PopAndDestroy( KDunThreeItemsToPop );  // readBuffer, resourceFile, fileSession
       
   224     FTRACE(FPrint( _L("CDunNoteHandler::ReadNoteResourceL() complete") ));
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // From class CActive.
       
   229 // Gets called when UI note dismissed
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CDunNoteHandler::RunL()
       
   233     {
       
   234     FTRACE(FPrint( _L("CDunNoteHandler::RunL()" ) ));
       
   235     iNoteState = EDunStateIdle;
   180     iNoteState = EDunStateIdle;
   236     delete iNote;
   181     delete iNote;
   237     iNote = NULL;
   182     iNote = NULL;
   238     FTRACE(FPrint( _L("CDunNoteHandler::RunL() complete" ) ));
   183     FTRACE(FPrint( _L("CDunNoteHandler::MessageBoxClosed() complete" ) ));
   239     }
   184     }
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // From class CActive.
       
   243 // Gets called on cancel
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CDunNoteHandler::DoCancel()
       
   247     {
       
   248     }