ImagePrint/ImagePrintUI/imageprinteng/src/csettingsmanager.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 <fbs.h>
       
    20 #include <eikenv.h>
       
    21 #include <e32std.h>
       
    22 
       
    23 #include "tprintcapability.h"
       
    24 #include "csettingsmanager.h"
       
    25 #include "ctemplatesettings.h"
       
    26 #include "cprintsettings.h"
       
    27 #include "ctintcapability.h"
       
    28 #include "clistcapability.h"
       
    29 #include "cfloatcapability.h"
       
    30 #include "ctemplatedata.h"
       
    31 #include "printcapabilitycodes.h"
       
    32 #include "settingsconverter.h"
       
    33 #include "crealfactory.h"
       
    34 #include "imageprint.h"
       
    35 #include "cimageprint.h"
       
    36 #include "imageprintvariant.h"
       
    37 #include <centralrepository.h>
       
    38 #include "imageprintprivatecrkeys.h"
       
    39 #include "mdiscovery.h"
       
    40 #include "clog.h"
       
    41 
       
    42 namespace
       
    43     {
       
    44     const TInt KDefaultPrinterNameMaxLength = 100;
       
    45     const TInt KTemplateSize = 16;
       
    46     const TInt KTemplates[] = {1554,1552,1565,1555,1501,1553,1551,1558,1502,1504,1564,1506,1509,1512,1513,1516};
       
    47     }
       
    48 
       
    49 #include "clog.h"
       
    50 
       
    51 // CONSTRUCTION
       
    52 CSettingsManager* CSettingsManager::NewL(
       
    53     CRealFactory* aFactory )
       
    54     {
       
    55     CSettingsManager* self = CSettingsManager::NewLC(
       
    56         aFactory );
       
    57     CleanupStack::Pop();    // self
       
    58 
       
    59     return self;
       
    60     }
       
    61 
       
    62 CSettingsManager* CSettingsManager::NewLC(
       
    63     CRealFactory* aFactory )
       
    64     {
       
    65     CSettingsManager* self =
       
    66         new ( ELeave ) CSettingsManager( aFactory );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 // Constrcutor
       
    74 CSettingsManager::CSettingsManager(
       
    75     CRealFactory* aFactory ) :
       
    76       iFactory( aFactory ),
       
    77       iActivePage( 1 )
       
    78     {
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 CSettingsManager::~CSettingsManager()
       
    83     {
       
    84     delete iPrintSettings;
       
    85     delete iTemplateSettings;
       
    86     delete iCurrentPrinterName;
       
    87     delete iCRSession;
       
    88     iNumberOfCopiesArray.Close();
       
    89     iNumberOfCopiesCumulativeArray.Close();
       
    90     }
       
    91 
       
    92 // 2nd phase constructor
       
    93 void CSettingsManager::ConstructL()
       
    94     {
       
    95     iPrintSettings = new ( ELeave ) CPrintSettings;
       
    96     iTemplateSettings = CTemplateSettings::NewL( iFactory );
       
    97 
       
    98     iCRSession  = CRepository::NewL( KCRUidImagePrint );
       
    99     }
       
   100 
       
   101 // Clones the current template settings
       
   102 CTemplateSettings* CSettingsManager::TemplateSettingsL()
       
   103     {
       
   104     return iTemplateSettings->CloneL();
       
   105     }
       
   106 
       
   107 // Changes active template to a new one
       
   108 void CSettingsManager::SetActiveTemplateL(
       
   109     TUint aUid )
       
   110     {
       
   111     LOG1( "CSettingsManager::SetActiveTemplateL START || aUid = %d", aUid );
       
   112     // Set active template to preview manager, if one available
       
   113     iTemplateSettings->iActiveTemplateUid = aUid;
       
   114 
       
   115     CListCapability* capab = static_cast<CListCapability*>(
       
   116         FetchCapabilityL( EPrintCapabLayout ) );
       
   117     capab->iValue = aUid;
       
   118     LOG1( "CSettingsManager::SetActiveTemplateL || iImagesOnPage = %d", iImagesOnPage );
       
   119     }
       
   120 
       
   121 // Returns the number of pages
       
   122 TUint CSettingsManager::NumOfPagesL()
       
   123     {
       
   124     // Always 1, fix this for the release 2
       
   125     // return iFactory->Engine()->GetNumPrintPages();
       
   126 
       
   127     TInt num( 1 );
       
   128     return num;
       
   129     }
       
   130 
       
   131 // Returns the number of copies
       
   132 TInt CSettingsManager::NumberOfCopies( RArray<TInt>& aArray )
       
   133     {
       
   134     TInt err( KErrNone );
       
   135     aArray.Reset();
       
   136     for( TInt i=0; i<iNumberOfCopiesArray.Count(); ++i )
       
   137         {
       
   138         err = aArray.Append( iNumberOfCopiesArray[ i ] );
       
   139         if( err != KErrNone )
       
   140             {
       
   141             return err;
       
   142             }
       
   143         }
       
   144     return KErrNone;
       
   145     }
       
   146 
       
   147 TInt CSettingsManager::NumberOfCopies( TInt& aNumberOfCopies, TInt aIndex )
       
   148     {
       
   149     if( -1 < aIndex && aIndex < iNumberOfCopiesArray.Count() )
       
   150         {
       
   151         aNumberOfCopies = iNumberOfCopiesArray[ aIndex ];
       
   152         return KErrNone;
       
   153         }
       
   154     else
       
   155         {
       
   156         return KErrArgument;
       
   157         }
       
   158     }
       
   159 
       
   160 // Sets the number of copies
       
   161 TInt CSettingsManager::SetNumberOfCopiesL( const RArray<TInt>& aArray )
       
   162     {
       
   163     TInt err( KErrNone );
       
   164     TInt numberOfCopiesCumulative( 1 );
       
   165     iNumberOfCopiesArray.Close();
       
   166     iNumberOfCopiesCumulativeArray.Close();
       
   167     for( TInt i=0; i<aArray.Count(); ++i )
       
   168         {
       
   169         err = iNumberOfCopiesArray.Append( aArray[ i ] );
       
   170         if( err != KErrNone )
       
   171             {
       
   172             return err;
       
   173             }
       
   174         err = iNumberOfCopiesCumulativeArray.Append( numberOfCopiesCumulative );
       
   175         numberOfCopiesCumulative += aArray[ i ];
       
   176         if( err != KErrNone )
       
   177             {
       
   178             return err;
       
   179             }
       
   180         }
       
   181     return err;
       
   182     }
       
   183 
       
   184 TInt CSettingsManager::UpdateNumberOfCopiesToServer()
       
   185     {
       
   186     return iFactory->Engine()->SetNumberOfCopies( iNumberOfCopiesArray );
       
   187     }
       
   188 
       
   189 // Returns
       
   190 TBool CSettingsManager::IsMMC()
       
   191     {
       
   192     TBool retVal = EFalse;
       
   193     TInt supportedProtocols = iFactory->DiscoveryIF()->SupportedProtocols();
       
   194 
       
   195 	if( (supportedProtocols & KImagePrint_PrinterProtocol_DPOF)  && 
       
   196     	( iPrinterUid == iMMCUid ))
       
   197 		{
       
   198 		retVal = ETrue;
       
   199 		}
       
   200 	LOG1( "CSettingsManager::IsMMC: %d ", retVal );
       
   201     return retVal;
       
   202     }
       
   203 
       
   204 // Changes active page for drawing a new preview
       
   205 void CSettingsManager::SetActivePageL(
       
   206     TUint aActivePage )
       
   207     {
       
   208     }
       
   209 
       
   210 // Returns current active page
       
   211 TUint CSettingsManager::CurActivePageL()
       
   212     {
       
   213     TUint num( 1 );
       
   214     return num;
       
   215     }
       
   216 
       
   217 // Clones current print settings
       
   218 CPrintSettings* CSettingsManager::PrinterSettingsL()
       
   219     {
       
   220     return iPrintSettings->CloneL();
       
   221     }
       
   222 
       
   223 // Sets all settings, not supported at the moment
       
   224 void CSettingsManager::SetPrinterSettingsL(
       
   225     CPrintSettings& /*aSettings*/ )
       
   226     {
       
   227     User::Leave( KErrNotSupported );
       
   228     }
       
   229 
       
   230 // Sets a single setting
       
   231 TInt CSettingsManager::SetPrinterSettingL(
       
   232     CBaseCapability& aCapab )
       
   233     {
       
   234     LOG( "CSettingsManager::SetPrinterSettingL START" );
       
   235     TInt getSettings( 0 );
       
   236     TInt err = iFactory->Engine()->SetJobSettingL(
       
   237         aCapab.iUid, aCapab.iValue, getSettings );
       
   238     getSettings  = 0;
       
   239     User::LeaveIfError( err );
       
   240 
       
   241     CBaseCapability* capab = FetchCapabilityL( aCapab.iUid );
       
   242     capab->iValue = aCapab.iValue;
       
   243 
       
   244 #ifdef IMG_PRINT_DYNAMIC_PRINT_SETTINGS
       
   245     // Do not initialize if only template was changed
       
   246     if( aCapab.iUid != 500 )
       
   247         {
       
   248         LOG( "CSettingsManager::SetPrinterSettingL || aCapab.iUid != 500" );
       
   249         InitCapabilitiesL( iPrinterUid );
       
   250         InitTemplateSettingsL();
       
   251         }
       
   252      else
       
   253         {
       
   254         LOG( "CSettingsManager::SetPrinterSettingL || aCapab.iUid == 500" );
       
   255         SetActiveTemplateL( aCapab.iValue );
       
   256         }
       
   257 #else
       
   258      InitCapabilitiesL( iPrinterUid );
       
   259      InitTemplateSettingsL();
       
   260 #endif
       
   261 
       
   262     LOG1( "CSettingsManager::SetPrinterSettingL getSettings = %d", getSettings );
       
   263     return getSettings;
       
   264     }
       
   265 
       
   266 // Initializes the printer settings
       
   267 void CSettingsManager::InitSettingsL(
       
   268     TInt aPrinterUid,
       
   269     TInt aMMCUid )
       
   270     {
       
   271     LOG1( "CSettingsManager::InitSettingsL aPrinterUid = %d", aPrinterUid );
       
   272     LOG1( "CSettingsManager::InitSettingsL aMMCUid     = %d", aMMCUid     );
       
   273     
       
   274     iMMCUid = aMMCUid;
       
   275     InitCapabilitiesL( aPrinterUid );
       
   276     InitTemplateSettingsL();
       
   277     iPrinterUid = aPrinterUid;
       
   278     }
       
   279 
       
   280 // Inititalizes the capabilities
       
   281 void CSettingsManager::InitCapabilitiesL(
       
   282     TInt aPrinterUid )
       
   283     {
       
   284     LOG1("CSettingsManager::InitCapabilitiesL Begin: %d", aPrinterUid);
       
   285     RArray<TInt> capabIDs;
       
   286     CleanupClosePushL( capabIDs );
       
   287 
       
   288     // Get list of IDs
       
   289     iFactory->Engine()->GetPrinterCapabilityIDsL( aPrinterUid, capabIDs );
       
   290     CPrintSettings* printSettings = new ( ELeave ) CPrintSettings;
       
   291     CleanupStack::PushL( printSettings );
       
   292 
       
   293     TInt i( 0 );
       
   294     TInt num( capabIDs.Count() );
       
   295     LOG1("CSettingsManager::InitCapabilitiesL number of capabs: %d", num);
       
   296     for ( i = 0; i < num; i++ )
       
   297         {
       
   298         TPrintCapability capab;
       
   299         iFactory->Engine()->GetPrinterCapabilityL( aPrinterUid, capabIDs[i], capab );
       
   300         capab.iType = TPrintCapability::Enum;
       
   301 
       
   302         CBaseCapability* capability = 0;
       
   303 
       
   304         // Create capability
       
   305         switch ( capab.iType )
       
   306             {
       
   307             case TPrintCapability::Int:
       
   308                 capability = SettingsConverter::AddTIntCapabilityLC(
       
   309                     capab, i, capabIDs[i] );
       
   310                 break;
       
   311 
       
   312             case TPrintCapability::Enum:
       
   313                 capability = SettingsConverter::AddListCapabilityLC(
       
   314                     capab, i, capabIDs[i], iFactory );
       
   315                 break;
       
   316 
       
   317             case TPrintCapability::Float:
       
   318                 capability = SettingsConverter::AddFloatCapabilityLC(
       
   319                     capab, i, capabIDs[i] );
       
   320                 break;
       
   321 
       
   322             default:
       
   323                 User::Leave( KErrUnknown );
       
   324                 break;
       
   325             }
       
   326         iFactory->Engine()->GetJobSetting( capabIDs[i], capability->iValue );
       
   327 
       
   328         // Add the capability to the list
       
   329         User::LeaveIfError(
       
   330             printSettings->iCapabilities.Append( capability ) );
       
   331         CleanupStack::Pop();    // capability
       
   332         }
       
   333 
       
   334     delete iPrintSettings;
       
   335     iPrintSettings = printSettings;
       
   336 
       
   337     CleanupStack::Pop();    // printSettings
       
   338     CleanupStack::PopAndDestroy();  // capabIDs
       
   339     LOG("CSettingsManager::InitCapabilitiesL End");
       
   340     }
       
   341 
       
   342 // Initializes the templates
       
   343 void CSettingsManager::InitTemplateSettingsL()
       
   344     {
       
   345     LOG("CSettingsManager::InitTemplateSettingsL Begin");
       
   346     CTemplateSettings* settings = CTemplateSettings::NewL( iFactory );
       
   347     CleanupStack::PushL( settings );
       
   348     TInt templateBuffer = iFactory->SettingsIF()->TemplateUid();
       
   349 
       
   350     TInt i( 0 );
       
   351     TInt num( iPrintSettings->iCapabilities.Count() );
       
   352     for ( i = 0; i < num; i++ )
       
   353         {
       
   354         if ( iPrintSettings->iCapabilities[i]->iUid == EPrintCapabLayout )
       
   355             {
       
   356             TInt j( 0 );
       
   357             CListCapability* layouts =
       
   358                 static_cast<CListCapability*>
       
   359                         ( iPrintSettings->iCapabilities[i] );
       
   360             for ( j = 0; j < layouts->iEnumIDs.Count(); j++ )
       
   361                 {
       
   362                 // Create new template data with the icon and Uid value
       
   363                 CTemplateData* data = CTemplateData::NewL();
       
   364                 data->iUid = layouts->iEnumIDs[j];
       
   365                 CleanupStack::PushL( data );
       
   366                 LOG1( "CSettingsManager::InitTemplateSettingsL, UID: %d", data->iUid );
       
   367                 User::LeaveIfError( settings->iTemplates.Append( data ) );
       
   368                 CleanupStack::Pop( data );
       
   369                 }
       
   370             }
       
   371         }
       
   372 
       
   373     // Sort the templates to "standard" order
       
   374     CTemplateSettings* sortsettings = CTemplateSettings::NewL( iFactory );
       
   375     CleanupStack::PushL( sortsettings );
       
   376     for ( TInt i = 0; i < KTemplateSize; i++ )
       
   377         {
       
   378         for ( TInt j = 0; j < settings->iTemplates.Count(); j++ )
       
   379             {
       
   380             if ( KTemplates[i] == settings->iTemplates[j]->iUid )
       
   381                 {
       
   382                 CTemplateData* data = CTemplateData::NewL();
       
   383                 data->iUid = settings->iTemplates[j]->iUid;
       
   384                 CleanupStack::PushL( data );
       
   385                 LOG1( "CSettingsManager::InitTemplateSettingsL, UID: %d", data->iUid );
       
   386                 User::LeaveIfError( sortsettings->iTemplates.Append( data ) );
       
   387                 CleanupStack::Pop( data );
       
   388                 break;
       
   389                 }
       
   390             }
       
   391         }
       
   392 
       
   393     CleanupStack::Pop( sortsettings );
       
   394     CleanupStack::PopAndDestroy( settings );
       
   395     delete iTemplateSettings;
       
   396     iTemplateSettings = sortsettings;
       
   397 
       
   398     TBool templateFound = EFalse;
       
   399     if ( iTemplateSettings->iTemplates.Count() > 0 )
       
   400         {
       
   401         for (TInt g = 0; g < iTemplateSettings->iTemplates.Count(); g++) 
       
   402         	{
       
   403 	        if (iTemplateSettings->iTemplates[g]->iUid == templateBuffer)
       
   404 	        	{
       
   405 	        		iTemplateSettings->iActiveTemplateUid = templateBuffer;
       
   406 	        		templateFound = ETrue;
       
   407 	        	}
       
   408         	}
       
   409         if (!templateFound){
       
   410         iTemplateSettings->iActiveTemplateUid = 
       
   411         iTemplateSettings->iTemplates[0]->iUid;
       
   412         }
       
   413         
       
   414         SetActiveTemplateL( iTemplateSettings->iActiveTemplateUid );
       
   415         }
       
   416     // If there are no templates available, draw the preview using
       
   417     // 1/page template
       
   418     else
       
   419         {
       
   420         LOG("CSettingsManager::InitTemplateSettingsL || No templates available!");
       
   421         SetActiveTemplateL( EPrintCapabLayout1UpMedium );
       
   422         }
       
   423     LOG("CSettingsManager::InitTemplateSettingsL End");
       
   424     }
       
   425 
       
   426 // Fetches capability from the list and returns it
       
   427 CBaseCapability* CSettingsManager::FetchCapabilityL(
       
   428     TInt aUid )
       
   429     {
       
   430     LOG1("CSettingsManager::FetchCapabilityL Begin: %d", aUid);
       
   431     CBaseCapability* capab = NULL;
       
   432     TInt found( KErrNotFound );
       
   433 
       
   434     TInt i( 0 );
       
   435     TInt num( iPrintSettings->iCapabilities.Count() );
       
   436     for ( i = 0; i < num && found != KErrNone; i++ )
       
   437         {
       
   438         if ( iPrintSettings->iCapabilities[i]->iUid == aUid )
       
   439             {
       
   440             capab = iPrintSettings->iCapabilities[i];
       
   441             found = KErrNone;
       
   442             }
       
   443         }
       
   444 
       
   445     User::LeaveIfError( found );
       
   446     LOG("CSettingsManager::FetchCapabilityL End");
       
   447     return capab;
       
   448     }
       
   449 
       
   450 TInt CSettingsManager::TemplateUid()
       
   451     {
       
   452     LOG1( "CSettingsManager::TemplateUid || iActiveTemplateUid = %d", iTemplateSettings->iActiveTemplateUid );
       
   453     return iTemplateSettings->iActiveTemplateUid;
       
   454     }
       
   455 
       
   456 TBool CSettingsManager::UpdatePageNumberL( TInt aCurrentImage )
       
   457     {
       
   458     TBool retValue = EFalse;
       
   459     TUint pageNumber;
       
   460 
       
   461     if( iNumberOfCopiesCumulativeArray.Count() > aCurrentImage-1 )
       
   462         {
       
   463         aCurrentImage = iNumberOfCopiesCumulativeArray[aCurrentImage-1];
       
   464         }
       
   465 
       
   466     pageNumber = aCurrentImage / iImagesOnPage;
       
   467     if ( ( aCurrentImage % iImagesOnPage ) != 0 )
       
   468         {
       
   469         pageNumber++;
       
   470         }
       
   471 
       
   472     if ( iActivePage != pageNumber )
       
   473         {
       
   474         iActivePage = pageNumber;
       
   475         retValue = ETrue;
       
   476         }
       
   477     return retValue;
       
   478     }
       
   479 
       
   480 TInt CSettingsManager::PrinterUid()
       
   481     {
       
   482     return iPrinterUid;
       
   483     }
       
   484 
       
   485 
       
   486 TBool CSettingsManager::GetUsbState()
       
   487     {
       
   488     return iUsbConnected;
       
   489     }
       
   490 
       
   491 void CSettingsManager::SetUsbState( TBool aConnected )
       
   492     {
       
   493     iUsbConnected = aConnected;
       
   494     }
       
   495 
       
   496 TInt CSettingsManager::GetDefaultPrinterProtocol()
       
   497     {
       
   498     TInt retValue;
       
   499     TInt err = iCRSession->Get( KDefaultPrinterProtocol, retValue );
       
   500 
       
   501     LOG2("CSettingsManager::GetDefaultPrinterProtocol: %d, err: %d", retValue, err);
       
   502     return ( err ) ? err : retValue;
       
   503     }
       
   504 
       
   505 
       
   506 TInt CSettingsManager::SetDefaultPrinterProtocol( TInt aProtocol )
       
   507     {
       
   508     TInt err = iCRSession->Set( KDefaultPrinterProtocol, aProtocol );
       
   509     LOG2("CSettingsManager::SetDefaultPrinterProtocol: %d, err: %d", aProtocol, err);
       
   510     return err;
       
   511     }
       
   512 
       
   513 TInt CSettingsManager::GetCurrentPrinterProtocol()
       
   514     {
       
   515     LOG1("CSettingsManager::GetCurrentPrinterProtocol: %d", iCurrentPrinterProtocol );
       
   516     return iCurrentPrinterProtocol;
       
   517     }
       
   518 
       
   519 void CSettingsManager::SetCurrentPrinterProtocol( TInt aProtocol )
       
   520     {
       
   521     LOG1("CSettingsManager::SetCurrentPrinterProtocol: %d", aProtocol );
       
   522     iCurrentPrinterProtocol = aProtocol;
       
   523     }
       
   524 
       
   525 TUint CSettingsManager::GetCurrentPrinterVendor()
       
   526     {
       
   527     LOG1("CSettingsManager::GetCurrentPrinterVendor() vendor: %d",iVendor);
       
   528     return iVendor;
       
   529     }
       
   530 
       
   531 void CSettingsManager::SetCurrentPrinterVendor( TUint aVendor )
       
   532     {
       
   533     LOG1("CSettingsManager::SetCurrentPrinterVendor() vendor: %d",aVendor);
       
   534     iVendor = aVendor;
       
   535     }
       
   536 
       
   537 TInt CSettingsManager::GetDefaultPrintID()
       
   538     {
       
   539     TInt retValue;
       
   540     TInt err = iCRSession->Get( KDefaultPrinterID, retValue );
       
   541     LOG2("CSettingsManager::GetDefaultPrintID: get: %d, err: %d", retValue, err);
       
   542     return ( err ) ? err : retValue;
       
   543     }
       
   544 
       
   545 TInt CSettingsManager::SetDefaultPrinterID( TInt aId )
       
   546     {
       
   547     TInt err = iCRSession->Set( KDefaultPrinterID, aId );
       
   548     LOG2("CSettingsManager::SetDefaultPrinterID: set: %d, err: %d", aId, err);
       
   549     return err;
       
   550     }
       
   551 
       
   552 HBufC* CSettingsManager::GetDefaultPrinterNameLC()
       
   553     {
       
   554     HBufC* name = HBufC::NewLC( KDefaultPrinterNameMaxLength );
       
   555     TPtr ptr( name->Des() );
       
   556     TInt err = iCRSession->Get( KDefaultPrinterName, ptr );
       
   557     LOG2("CSettingsManager::GetDefaultPrinterNameLC: name: %S, err: %d", &ptr, err);
       
   558     return name;
       
   559     }
       
   560 
       
   561 TInt CSettingsManager::SetDefaultPrinterNameL( const TDesC& aPrinterName )
       
   562     {
       
   563     TInt err = KErrNone;
       
   564     HBufC* stringholder = HBufC::NewLC( aPrinterName.Length() );
       
   565         *stringholder = aPrinterName;
       
   566 
       
   567         // Clear the printer name string from all formatting tabs & numbers
       
   568         TPtr ptr = stringholder->Des();
       
   569         TInt pos = stringholder->Find( KTabChar );
       
   570         if ( pos == 1 ) // 1st possible icon formatting tab is at pos 1
       
   571             {
       
   572             ptr.Delete( 0, 2 ); // delete the first icon tab and the number previous to it
       
   573             pos = stringholder->Find( KTabChar );
       
   574             }
       
   575         while ( pos != KErrNotFound &&
       
   576                 pos != stringholder->Length() - 2 )
       
   577             {
       
   578             ptr.Delete( pos, 1); // delete all middle tabs
       
   579             pos = stringholder->Find( KTabChar );
       
   580             }
       
   581         // 2nd possible iconformatting tab is 2nd last char
       
   582         if ( pos != KErrNotFound &&
       
   583              pos == stringholder->Length() - 2 )
       
   584             {
       
   585             // delete the 2nd icon formatting tab and the number next to it
       
   586             ptr.Delete( stringholder->Length() - 2, 2 );
       
   587             }
       
   588 
       
   589         err = iCRSession->Set( KDefaultPrinterName, *stringholder );
       
   590         LOG2("CSettingsManager::SetDefaultPrinterNameL: name: %S err: %d", &ptr, err);
       
   591         CleanupStack::PopAndDestroy( stringholder );
       
   592     return err;
       
   593     }
       
   594 
       
   595 HBufC* CSettingsManager::GetCurrentPrinterName()
       
   596     {
       
   597     TPtr ptr = iCurrentPrinterName->Des();
       
   598     LOG1("CSettingsManager::GetCurrentPrinterName: name: %S",  &ptr );
       
   599     return iCurrentPrinterName;
       
   600     }
       
   601 
       
   602 TInt CSettingsManager::SetCurrentPrinterName( const TDesC& aPrinterName )
       
   603     {
       
   604     if( iCurrentPrinterName )
       
   605         {
       
   606         delete iCurrentPrinterName;
       
   607         iCurrentPrinterName = NULL;
       
   608         }
       
   609     
       
   610     TInt err;
       
   611     HBufC* tmpBuf = aPrinterName.Alloc();
       
   612     if( !tmpBuf )
       
   613         {
       
   614         return KErrGeneral;
       
   615         }
       
   616     else
       
   617         {
       
   618         err = KErrNone;    
       
   619         iCurrentPrinterName = tmpBuf;
       
   620         }        
       
   621     
       
   622     // Clear the printer name string from all formatting tabs & numbers
       
   623     TPtr ptr = iCurrentPrinterName->Des();
       
   624     TInt pos = iCurrentPrinterName->Find( KTabChar );
       
   625     if ( pos == 1 ) // 1st possible icon formatting tab is at pos 1
       
   626         {
       
   627         ptr.Delete( 0, 2 ); // delete the first icon tab and the number previous to it
       
   628         pos = iCurrentPrinterName->Find( KTabChar );
       
   629         }
       
   630     while ( pos != KErrNotFound &&
       
   631             pos != iCurrentPrinterName->Length() - 2 )
       
   632         {
       
   633         ptr.Delete( pos, 1); // delete all middle tabs
       
   634         pos = iCurrentPrinterName->Find( KTabChar );
       
   635         }
       
   636     // 2nd possible iconformatting tab is 2nd last char
       
   637     if ( pos != KErrNotFound &&
       
   638          pos == iCurrentPrinterName->Length() - 2 )
       
   639         {
       
   640         // delete the 2nd icon formatting tab and the number next to it
       
   641         ptr.Delete( iCurrentPrinterName->Length() - 2, 2 );
       
   642         }
       
   643 
       
   644     LOG1("CSettingsManager::SetCurrentPrinterName: name: %S", &ptr );
       
   645     return err;
       
   646     }
       
   647     
       
   648 HBufC* CSettingsManager::GetCurrentPaperSizeTextL()
       
   649     {    
       
   650     HBufC* retValue = NULL;
       
   651     CListCapability* paperSizeCapab = NULL;
       
   652     // Searches the paper size capability from the capability list
       
   653     // Search the UID for paper size (= 4)
       
   654     TInt counter = iPrintSettings->iCapabilities.Count();
       
   655     for( TInt i = 0 ; i < counter ; i++ )
       
   656         {
       
   657 
       
   658         //Use the searched ListCapability
       
   659         if( iPrintSettings->iCapabilities[ i ]->iUid == EPrintCapabPaperSize )
       
   660             {
       
   661             paperSizeCapab = static_cast< CListCapability* >
       
   662                                    ( iPrintSettings->iCapabilities[ i ] );
       
   663             }
       
   664         }
       
   665     
       
   666     
       
   667     TBool found( EFalse );
       
   668 
       
   669     if ( paperSizeCapab )
       
   670         {
       
   671         const TInt expectedNumberOfStrings( 2 );
       
   672         CDesCArrayFlat* strings = 
       
   673             new ( ELeave ) CDesCArrayFlat( expectedNumberOfStrings );
       
   674         CleanupStack::PushL( strings );
       
   675 
       
   676         TInt i( 0 );
       
   677         TInt counter = paperSizeCapab->iEnumIDs.Count();
       
   678         for ( i = 0; i < counter && !found; i++ )
       
   679             {
       
   680             if ( paperSizeCapab->iEnumIDs[i] ==
       
   681                  paperSizeCapab->iValue )
       
   682                 {
       
   683                 retValue = paperSizeCapab->iTexts[i];
       
   684                 }
       
   685             }
       
   686         CleanupStack::PopAndDestroy();	// strings
       
   687         }
       
   688     return retValue;
       
   689     }
       
   690 
       
   691 //  End of File