ImagePrint/ImagePrintUI/imageprintapp/src/printapputil.cpp
branchGCC_SURGE
changeset 25 59ea2209bb67
parent 23 08cc4cc059d4
parent 15 a92d00fca574
equal deleted inserted replaced
23:08cc4cc059d4 25:59ea2209bb67
     1 /*
       
     2 * Copyright (c) 2004-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <StringLoader.h>
       
    21 #include <aknnotewrappers.h>
       
    22 #include <ErrorUI.h>
       
    23 #include <eikappui.h>
       
    24 #include <eikapp.h>
       
    25 #include <eikenv.h>
       
    26 #include <obex.h>
       
    27 #include <bluetooth/hci/hcierrors.h>
       
    28 #include <imageprintapp.rsg>
       
    29 
       
    30 #include "printapputil.h"
       
    31 #include "printmessagecodes.h"
       
    32 #include "cimageprintappui.h"
       
    33 #include "clog.h"
       
    34 
       
    35 // Displays the error note
       
    36 void PrintAppUtil::ShowErrorNoteL(
       
    37     TInt aResourceId )
       
    38     {
       
    39     HBufC* str = StringLoader::LoadLC( aResourceId );
       
    40     CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
    41     note->ExecuteLD( *str );
       
    42     CleanupStack::PopAndDestroy( str );  // str
       
    43     }
       
    44 
       
    45 // Displays the information note
       
    46 void PrintAppUtil::ShowInfoNoteL(
       
    47     TInt aResourceId )
       
    48     {
       
    49     HBufC* str = StringLoader::LoadLC( aResourceId );
       
    50     CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
    51     note->ExecuteLD( *str );
       
    52     CleanupStack::PopAndDestroy( str);  // str
       
    53     }
       
    54 
       
    55 // Displays error message based on the error code
       
    56 void PrintAppUtil::ShowErrorMsgL(
       
    57     TInt aErrCode )
       
    58     {
       
    59     if ( aErrCode != KErrNone )
       
    60         {
       
    61         HBufC* str = PrintAppUtil::PrintErrorMsgLC( aErrCode );
       
    62         CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
    63         note->ExecuteLD( *str );
       
    64         CleanupStack::PopAndDestroy( str );  // str
       
    65         }
       
    66     }
       
    67 
       
    68 //  Loads printer application specific error message
       
    69 HBufC* PrintAppUtil::PrintErrorMsgLC(
       
    70     TInt aErrCode )
       
    71     {
       
    72     HBufC* errStr = 0;
       
    73     TInt resourceId( 0 );
       
    74 
       
    75     switch ( aErrCode )
       
    76         { 
       
    77         case ( KHCIErrorBase - EPageTimedOut ):
       
    78             resourceId = R_NOTE_CONNECT_PRINT_ERROR;
       
    79             break;
       
    80         case KErrIrObexRespServiceUnavail:
       
    81             resourceId = R_NOTE_SEND_PRINT_ERROR;
       
    82             break;   
       
    83         case KErrDisconnected:
       
    84             resourceId = R_NOTE_DISCONNECT_PRINT_ERROR;
       
    85             break;
       
    86         case EObexGeneralError:
       
    87             resourceId = R_NOTE_GENERAL_PRINT_ERROR;
       
    88             break;
       
    89         case EPbStatusErrorReasonInk:
       
    90         	resourceId = R_NOTE_IMAGEPRINT_ERROR_INK;
       
    91         	break;
       
    92         case EPbStatusErrorReasonHardwareCoverOpen:
       
    93         	resourceId = R_NOTE_IMAGEPRINT_ERROR_HARDWARE_COVER_OPEN;
       
    94         	break;
       
    95         case EPbStatusErrorReasonHardwarePrinterBusy:
       
    96         	resourceId = R_NOTE_IMAGEPRINT_ERROR_HARDWARE_PRINTER_BUSY;
       
    97         	break;
       
    98         case EPbStatusErrorReasonHardwareNoInkCartridge:
       
    99         	resourceId = R_NOTE_IMAGEPRINT_ERROR_HARDWARE_NO_INK_CARTRIDGE;
       
   100         	break;
       
   101         case EPbStatusErrorReasonNoReason:
       
   102             resourceId  = R_NOTE_PRINT_STATUS_ERROR;
       
   103             break;
       
   104         case EPbOutOfPaper:
       
   105             resourceId = R_NOTE_IMAGEPRINT_ERROR_PAPER_OUT;
       
   106             break;    
       
   107         case EPbStatusErrorReasonInkEmpty:
       
   108             resourceId = R_NOTE_IMAGEPRINT_ERROR_INK_OUT;
       
   109             break;        
       
   110         case EPrintReasonPaused:
       
   111         	resourceId = R_NOTE_IMAGEPRINT_ERROR_PRINTER_PAUSED;
       
   112         	break;
       
   113         case EPrintReasonMarkerFailure:
       
   114         	resourceId = R_NOTE_IMAGEPRINT_ERROR_MARKER_FAILURE;
       
   115         	break;
       
   116         	
       
   117         case KErrHCILinkDisconnection:
       
   118         	resourceId = R_NOTE_DISCONNECT_PRINT_ERROR;
       
   119         	break;
       
   120          
       
   121         default:
       
   122             resourceId = R_NOTE_GENERAL_PRINT_ERROR;
       
   123             break;
       
   124         }
       
   125 	errStr = StringLoader::LoadLC( resourceId );
       
   126     
       
   127 // Add error code to message only when debug build is created.
       
   128 #ifdef _DEBUG	
       
   129     if ( aErrCode != 0 )
       
   130     	{
       
   131     	// append error code to message
       
   132 	    _LIT( KErrTmp, ": %d" );
       
   133 	    TBuf<32> errCodeMsg;
       
   134 	    errCodeMsg.Format( KErrTmp, aErrCode );
       
   135 	    errStr = errStr->ReAllocL( errStr->Length() + 32 );
       
   136 	    CleanupStack::Pop(); // errStr before realloc
       
   137 	    CleanupStack::PushL( errStr );
       
   138 	    TPtr p( errStr->Des() );
       
   139 	    p += errCodeMsg;
       
   140     	}
       
   141 #endif // _DEBUG
       
   142     	
       
   143     return errStr;
       
   144     }
       
   145 
       
   146 //  Adds application path
       
   147 TFileName PrintAppUtil::AddApplicationPath(
       
   148     const TDesC& aFileName )
       
   149     {
       
   150     CEikAppUi* appUi = static_cast<CEikAppUi*>( CEikonEnv::Static()->AppUi() );
       
   151     TFileName fullFilePath = appUi->Application()->AppFullName();
       
   152 
       
   153     TParse parse;
       
   154     parse.Set( fullFilePath, NULL, NULL );
       
   155     fullFilePath = parse.DriveAndPath();
       
   156     fullFilePath.Append( aFileName );
       
   157     return fullFilePath;
       
   158     }
       
   159 
       
   160 //  End of File