upnpframework/upnpcommand/src/upnpnotehandler.cpp
changeset 0 7f85d04be362
child 38 5360b7ddc251
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Source file for CUpnpNoteHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // system
       
    21 #include <bautils.h>                            // BaflUtils
       
    22 #include <eikenv.h>                             // CEikonEnv
       
    23 #include <AknWaitDialog.h>                      // CAknWaitDialog
       
    24 #include <StringLoader.h>                       // StringLoader
       
    25 #include <aknnotewrappers.h>                    // CAknErrorNote
       
    26 // upnpframework / common ui
       
    27 #include "upnpcommonui.h"                       // CUPnPCommonUI
       
    28 // command internal
       
    29 #include <upnpcommandresources.rsg>             // UpnpCommand resource file
       
    30 #include "upnpnotehandler.h"
       
    31 
       
    32 _LIT( KComponentLogfile, "upnpcommand.log");
       
    33 #include "upnplog.h"
       
    34 
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT( KResFileName,     "\\resource\\upnpcommandresources.rsc" );
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // CUpnpNoteHandler::NewL
       
    41 // Creates an instance of the implementation.
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 CUpnpNoteHandler* CUpnpNoteHandler::NewL()
       
    45     {
       
    46     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::NewL" );
       
    47 
       
    48     // Create instance
       
    49     CUpnpNoteHandler* self = NULL;
       
    50     self = new (ELeave) CUpnpNoteHandler();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54 
       
    55     return self;
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CUpnpNoteHandler::CUpnpNoteHandler
       
    60 // First phase construction.
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CUpnpNoteHandler::CUpnpNoteHandler()
       
    64     {
       
    65     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::Constructor" );
       
    66 
       
    67     iWaitNote = NULL;
       
    68     
       
    69     // DRM note will be shown only once
       
    70     iDrmNoteShown = EFalse;
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // Destructor.
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 CUpnpNoteHandler::~CUpnpNoteHandler()
       
    78     {
       
    79     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::Destructor" );
       
    80 
       
    81     // If wait note is running, finish it
       
    82     if( iWaitNote )
       
    83         {
       
    84         TRAP_IGNORE( iWaitNote->ProcessFinishedL() );
       
    85         }
       
    86 
       
    87     // Un-load resource file
       
    88     if ( iResFileOffset )
       
    89         {
       
    90         CEikonEnv::Static()->DeleteResourceFile( iResFileOffset );
       
    91         iResFileOffset = 0;
       
    92         }
       
    93     }
       
    94 
       
    95 // --------------------------------------------------------------------------
       
    96 // CUpnpNoteHandler::ConstructL
       
    97 // Perform the second phase of two phase construction. Reserves the Upnp Fw
       
    98 // resources (they are released when the task is destroyed).
       
    99 // --------------------------------------------------------------------------
       
   100 //
       
   101 void CUpnpNoteHandler::ConstructL()
       
   102     {
       
   103     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ConstructL" );
       
   104 
       
   105     // Get the pointer to coe env (owned by Eikon env)
       
   106     CEikonEnv* coeEnv = CEikonEnv::Static();
       
   107     if( !coeEnv )
       
   108         {
       
   109         User::Leave( KErrNotSupported );
       
   110         }
       
   111 
       
   112     // Get the filesession reference from coe env
       
   113     RFs& fileSession = coeEnv->FsSession();
       
   114 
       
   115     // Load resource file
       
   116     TFileName rscFileName( KResFileName );
       
   117     TFileName dllName;
       
   118     Dll::FileName( dllName );
       
   119     TBuf<2> drive = dllName.Left( 2 ); // Drive letter followed by ':' 
       
   120     rscFileName.Insert( 0, drive );
       
   121 
       
   122     // Get the exact filename of the resource file
       
   123     BaflUtils::NearestLanguageFile( fileSession, rscFileName );
       
   124 
       
   125     // Check if the resource file exists or not
       
   126     if ( !BaflUtils::FileExists( fileSession, rscFileName ) )
       
   127         {
       
   128         __LOG( "[UpnpCommand]\t Resource file does not exist!" );
       
   129         User::Leave( KErrNotFound );
       
   130         }
       
   131 
       
   132     // Read the resource file offset
       
   133     iResFileOffset = coeEnv->AddResourceFileL( rscFileName );
       
   134     }
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // CUpnpNoteHandler::RunConnectingWaitNote
       
   138 // Launches the "Connecting" wait note.
       
   139 // --------------------------------------------------------------------------
       
   140 //
       
   141 TInt CUpnpNoteHandler::RunConnectingWaitNote()
       
   142     {
       
   143     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::\
       
   144 RunConnectingWaitNote" );
       
   145 
       
   146     TInt status = KErrNone;
       
   147     status = RunWaitNote( R_COMMAND_CONNECTING_WAIT_NOTE );
       
   148     return status;
       
   149     }
       
   150 
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CUpnpNoteHandler::ShowDrmNoteL
       
   154 // Show "DRM protected files not supported." info note.
       
   155 // --------------------------------------------------------------------------
       
   156 //
       
   157 void CUpnpNoteHandler::ShowDrmNoteL()
       
   158     {
       
   159     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowDrmNoteL" );
       
   160 
       
   161     if( !iDrmNoteShown )
       
   162         {
       
   163         iDrmNoteShown = ETrue;
       
   164         ShowErrorNoteL( R_COMMAND_DRM_FILE_TEXT );
       
   165         }
       
   166     else
       
   167         {
       
   168         __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowDrmNoteL, skipped" );
       
   169         }
       
   170     }
       
   171 
       
   172 // --------------------------------------------------------------------------
       
   173 // CUpnpNoteHandler::ShowConnectionLostNoteL
       
   174 // Show "Connection failed." info note.
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 void CUpnpNoteHandler::ShowConnectionLostNoteL()
       
   178     {
       
   179     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowConnectionLostNoteL" );
       
   180 
       
   181     ShowErrorNoteL( R_COMMAND_ERR_CON_FAILED_TEXT );
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CUpnpNoteHandler::ShowLocalMSStartErrorNoteL
       
   186 // Show "Connection failed." info note.
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 void CUpnpNoteHandler::ShowLocalMSStartErrorNoteL()
       
   190     {
       
   191     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowLocalMSStartErrorNoteL" );
       
   192 
       
   193     // local mediaserver refuses to start.
       
   194     // use "connection failed" - this describes the error best.
       
   195     ShowErrorNoteL( R_COMMAND_ERR_CON_FAILED_TEXT );
       
   196     }
       
   197 
       
   198 // --------------------------------------------------------------------------
       
   199 // CUpnpNoteHandler::ShowCopyInfoNoteL
       
   200 // Show "%N files copied to %U" info note.
       
   201 // --------------------------------------------------------------------------
       
   202 //
       
   203 void CUpnpNoteHandler::ShowCopyInfoNoteL( TInt aCount, 
       
   204         const TDesC& aServerName )
       
   205     {
       
   206     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowCopyInfoNoteL" );
       
   207 
       
   208     HBufC* infoText = NULL;
       
   209     
       
   210     if( aCount == 1 )
       
   211         {                               
       
   212         infoText = StringLoader::LoadLC( 
       
   213                 R_COMMAND_INFO_COPY_EXT_ONE_TEXT,
       
   214                 aServerName );
       
   215         }
       
   216     else
       
   217         {
       
   218         infoText = StringLoader::LoadLC( 
       
   219                 R_COMMAND_INFO_COPY_EXT_MANY_TEXT,
       
   220                 aServerName,
       
   221                 aCount );
       
   222         }
       
   223 
       
   224     ShowInfoNoteL( *infoText );
       
   225     
       
   226     CleanupStack::PopAndDestroy( infoText );
       
   227     }
       
   228 
       
   229 // --------------------------------------------------------------------------
       
   230 // CUpnpNoteHandler::ShowMoveInfoNoteL
       
   231 // Show "1 file moved to %U" info note.
       
   232 // --------------------------------------------------------------------------
       
   233 //
       
   234 void CUpnpNoteHandler::ShowMoveInfoNoteL( TInt aCount, 
       
   235         const TDesC& aServerName )
       
   236     {
       
   237     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowMoveInfoNoteL" );
       
   238     // NOTE: defect in UI spec. Missing loc text. Using
       
   239     // "N files copied" localisation instead.
       
   240 
       
   241     HBufC* infoText = NULL;
       
   242 
       
   243     if( aCount == 1 )
       
   244         {                                       
       
   245         infoText = StringLoader::LoadLC( 
       
   246                 R_COMMAND_INFO_MOVE_EXT_ONE_TEXT,
       
   247                 aServerName );
       
   248         }
       
   249     else
       
   250         {
       
   251         infoText = StringLoader::LoadLC( 
       
   252                 R_COMMAND_INFO_MOVE_EXT_MANY_TEXT,
       
   253                 aServerName,
       
   254                 aCount );
       
   255         }
       
   256 
       
   257     ShowInfoNoteL( *infoText );
       
   258     
       
   259     CleanupStack::PopAndDestroy( infoText );
       
   260     }
       
   261 
       
   262 // --------------------------------------------------------------------------
       
   263 // CUpnpNoteHandler::ShowCopyErrorNoteL
       
   264 // Show "Selected device does not support this operation" error note
       
   265 // --------------------------------------------------------------------------
       
   266 //
       
   267 void CUpnpNoteHandler::ShowCopyErrorNoteL()
       
   268     {
       
   269     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowCopyErrorNoteL" );
       
   270   
       
   271     ShowErrorNoteL( R_COMMAND_ERR_GENERAL_FAILURE_TEXT );
       
   272     }
       
   273 
       
   274 // --------------------------------------------------------------------------
       
   275 // CUpnpNoteHandler::ShowMoveErrorNoteL
       
   276 // Show "Selected device does not support this operation" error note
       
   277 // --------------------------------------------------------------------------
       
   278 //
       
   279 void CUpnpNoteHandler::ShowMoveErrorNoteL()
       
   280     {
       
   281     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowMoveErrorNoteL" );
       
   282 
       
   283     ShowErrorNoteL( R_COMMAND_ERR_GENERAL_FAILURE_TEXT );
       
   284     }
       
   285 
       
   286 // --------------------------------------------------------------------------
       
   287 // CUpnpNoteHandler::ShowCopyDisconnectionErrorNoteL
       
   288 // Show "Connection lost, some files may not be copied" error note
       
   289 // --------------------------------------------------------------------------
       
   290 //
       
   291 void CUpnpNoteHandler::ShowCopyDisconnectionErrorNoteL()
       
   292     {
       
   293     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::\
       
   294 ShowCopyDisconnectionErrorNoteL" );
       
   295  
       
   296     ShowErrorNoteL( R_COMMAND_ERR_CONN_LOST_COPY_TEXT );
       
   297     }
       
   298 
       
   299 // --------------------------------------------------------------------------
       
   300 // CUpnpNoteHandler::ShowMoveDisconnectionErrorNoteL
       
   301 // Show "Connection lost. Some files might not be moved" error note
       
   302 // --------------------------------------------------------------------------
       
   303 //
       
   304 void CUpnpNoteHandler::ShowMoveDisconnectionErrorNoteL()
       
   305     {
       
   306     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::\
       
   307 ShowMoveDisconnectionErrorNoteL" );
       
   308 
       
   309     ShowErrorNoteL( R_COMMAND_ERR_CONN_LOST_MOVE_TEXT);
       
   310     }
       
   311 
       
   312 // --------------------------------------------------------------------------
       
   313 // CUpnpNoteHandler::ShowPlaybackFailedNoteL
       
   314 // Show "Playback failed on the remote device for unknown error. 
       
   315 // Try again" info note.
       
   316 // --------------------------------------------------------------------------
       
   317 //
       
   318 void CUpnpNoteHandler::ShowPlaybackFailedNoteL()
       
   319     {
       
   320     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowPlaybackFailedNoteL" );
       
   321     
       
   322     ShowErrorNoteL( R_COMMAND_ERR_RENDERING_FAILED_UNKNOWN_TEXT );
       
   323     }
       
   324 
       
   325 // --------------------------------------------------------------------------
       
   326 // CUpnpNoteHandler::RunWaitNote
       
   327 // Launches the wait note.
       
   328 // --------------------------------------------------------------------------
       
   329 //
       
   330 TInt CUpnpNoteHandler::RunWaitNote( TInt aResource )
       
   331     {
       
   332     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::RunWaitNote" );
       
   333 
       
   334     TInt status = KErrNone;
       
   335     
       
   336     
       
   337     // If the note is already showing
       
   338     if( iWaitNote )
       
   339         {
       
   340         status = KErrInUse;
       
   341         }
       
   342     else
       
   343         {
       
   344         // Create the wait note
       
   345         iWaitNote = new CAknWaitDialog(
       
   346             ( REINTERPRET_CAST( CEikDialog**, &iWaitNote ) ), ETrue );
       
   347         if( iWaitNote )
       
   348             {
       
   349             // Execute the wait note
       
   350             TBool noteResult = EFalse;
       
   351             TRAP( status, noteResult =
       
   352                 iWaitNote->ExecuteLD(
       
   353                 aResource ) );
       
   354             if( !noteResult )
       
   355                 {
       
   356                 status = KErrCancel;
       
   357                 }
       
   358 
       
   359             // Clean up
       
   360             iWaitNote = NULL;
       
   361             }
       
   362         else
       
   363             {
       
   364             // If we failed to allocate memory for the note
       
   365             status = KErrNoMemory;
       
   366             }
       
   367 
       
   368         }
       
   369 
       
   370     return status;
       
   371     }
       
   372 
       
   373 // --------------------------------------------------------------------------
       
   374 // CUpnpNoteHandler::CloseWaitNote
       
   375 // Closes the "Activating sharing" wait note.
       
   376 // --------------------------------------------------------------------------
       
   377 //
       
   378 void CUpnpNoteHandler::CloseWaitNote()
       
   379     {
       
   380     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::CloseWaitNote" );
       
   381 
       
   382     // If wait note is running, finish it
       
   383     if( iWaitNote )
       
   384         {
       
   385         TRAP_IGNORE( iWaitNote->ProcessFinishedL() );
       
   386         }
       
   387     }
       
   388 
       
   389 // --------------------------------------------------------------------------
       
   390 // CUpnpNoteHandler::ShowInfoNoteL
       
   391 // Show info note
       
   392 // --------------------------------------------------------------------------
       
   393 //    
       
   394 void CUpnpNoteHandler::ShowInfoNoteL( const TDesC& aText )
       
   395     {
       
   396     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowInfoNoteL" );
       
   397     
       
   398     CAknInformationNote* infoNote = 
       
   399         new ( ELeave ) CAknInformationNote( ETrue );
       
   400     infoNote->ExecuteLD( aText );
       
   401     }
       
   402 
       
   403 // --------------------------------------------------------------------------
       
   404 // CUpnpNoteHandler::ShowErrorNoteL
       
   405 // Show error note
       
   406 // --------------------------------------------------------------------------
       
   407 //    
       
   408 void CUpnpNoteHandler::ShowErrorNoteL( TInt aResource )
       
   409     {
       
   410     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ShowInfoNoteL" );
       
   411 
       
   412     // Load the string, and show the note
       
   413     HBufC* errorText = StringLoader::LoadLC( aResource );
       
   414     CAknInformationNote* errorNote = 
       
   415         new ( ELeave ) CAknInformationNote( ETrue );
       
   416     errorNote->ExecuteLD( *errorText );
       
   417     CleanupStack::PopAndDestroy( errorText );
       
   418     }
       
   419 
       
   420 // --------------------------------------------------------------------------
       
   421 // CUpnpNoteHandler::ResetDrmNoteCount
       
   422 // Drm note can shoud be shown only one in operation
       
   423 // this reset calculator so that note can be shown again
       
   424 // --------------------------------------------------------------------------
       
   425 //     
       
   426 void CUpnpNoteHandler::ResetDrmNoteCount()
       
   427     {
       
   428     __LOG( "[UpnpCommand]\t CUpnpNoteHandler::ResetDrmNoteCount" );
       
   429     iDrmNoteShown = EFalse;
       
   430     }
       
   431 
       
   432 // End of File